-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathObjectModel.h
More file actions
103 lines (78 loc) · 2.42 KB
/
ObjectModel.h
File metadata and controls
103 lines (78 loc) · 2.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#ifndef OBJECT_H_
#define OBJECT_H_
#include "Graphics.h"
#include "MatrixVector.h"
#include "Transform.h"
#include <vector>
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <list>
using namespace std;
//The vertex has a vertex and vertex normal
struct Vertex{
Vec3 v; //the 3d point of the normal
Vec3 norm; // The vertex normal
int cnt = 0;
Vertex(){
v = Vec3(0,0,0);
norm = Vec3(0,0,0);
}
Vertex(const Vec3& input){
v = input;
norm = Vec3(0,0,0);
}
};
//Edge is used in scanline filling algorithm
struct Edge{
Vec2 *v1,*v2; //we have two vertices
//the initializer function
Edge(){
v1 = NULL;
v2 = NULL;
}
Edge(Vec2* a, Vec2* b):v1(a),v2(b){
//make sure v1 has small y and v2 has larger y value
//if not so swap them
if (v1->y > v2->y){
Vec2 *temp = v1;
v1 = v2;
v2 = temp;
}
}
//simply a copy overloaded with =
void operator = (Edge Ed){
v1 = Ed.v1; v2 = Ed.v2;
}
};
class Object3d{
private:
vector <Vertex> vertBuffer; //List of Vertices
vector <Vec2> textureBuffer; //List of textures
vector <Vec3> normBuffer; //List of normals
vector <Vec3> surfaceBuffer; //list of Surfaces(vert,texture,norm)
vector <Vec3> vertexNorm; //List of vertex normal
bool texture;
int xoffset,yoffset; //to move the object by some distance in x
//adders
public:
Object3d(int xffset = 0,int yffset = 0){texture = false;xoffset = xffset;yoffset = yffset;}
void addVertex(Vec3& v){vertBuffer.push_back(Vertex(v));}
void addSurface(Vec3& v){surfaceBuffer.push_back(v);}
void addNormal(Vec3& v){normBuffer.push_back(v);}
void addTexture(Vec2& v){textureBuffer.push_back(v);}
//file manipulators
public:
void SaveObject(string filename);
void LoadObject(string filename);
//Object fillers
public:
void drawWire(Screen* S,Vec3& camera,Vec3& LookTo,float pWidth,float pHeight);
void render(Screen* S,Vec3& camera,Vec3& LookTo,vector<Vec3> LightPos,float pWidth,float pHeight, int color, float intensityValue);
void drawSpan(Screen* S,Edge& E1, Edge& E2, int color);
//calculators
public:
void calculateNorm();
};
#endif // OBJECT_H_