-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathObject.h
182 lines (165 loc) · 4.67 KB
/
Object.h
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
#ifndef OBJECT_H
#define OBJECT_H
#include "Texture.h"
#include "Shader.h"
#include <vector>
#include <string>
#include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include<Utilities.h>
class Triangle{
public:
glm::vec3* vd;
std::vector<int> g;
};
//template <class TYPE>
class Object
{
public:
Object();
Object(char *filename,bool NORMALIZE=true);
// ~Object();
Texture * color;
Texture * height;
std::string * colorFile;
std::string * heightFile;
std::vector<glm::vec3> * vertices;
std::vector<glm::vec3> * normals;
std::vector<glm::vec3> * tangents;
std::vector<glm::vec2> * texture;
int * numFaces;
glm::vec3 * position;
unsigned int* vbo_vertices, *vbo_normals, *vbo_tangents, *vbo_texture;
glm::mat4* model_matrix;
void Export(std::string filename);
void Import(std::string filename,bool NORMALIZE=true);
void draw(Shader* sh,bool draw=true);
glm::vec4 normalize();
virtual void traslate (float x, float y, float z);
virtual void traslate (glm::vec3 v);
virtual void scale (float s);
virtual void rotate (float x, float y, float z, float w);
virtual void rotate (glm::vec3 v);
virtual void rotate (glm::vec4 v);
void copy(Object* o);
void alloc();
void toBuffers();
void setColorFile (std::string filename);
void setHeightFile(std::string filename);
};
class DebugCube: public Object{
public:
DebugCube():Object("boneDebug"){
center=glm::vec3(0,0,0);
scale(0.5*std::sqrt(3.0));
}
DebugCube(glm::vec3 c):Object("boneDebug"){
center=glm::vec3(0,0,0);
scale(0.5*std::sqrt(3.0));
setCenter(c);
}
DebugCube(float size):Object("boneDebug"){
center=glm::vec3(0,0,0);
scale(0.5*std::sqrt(3.0));
scale(size);
}
DebugCube(float size,glm::vec3 c):Object("boneDebug"){
center=glm::vec3(0,0,0);
scale(0.5*std::sqrt(3.0));
scale(size);
setCenter(c);
}
~DebugCube(){}
glm::vec3 center;
int index;
void setCenter(glm::vec3 c){
traslate(c-center);
center=c;
}
void setIndex(int i){
index=i;
std::string filename(1,i+'0');
filename=filename+".png";
setColorFile(filename);
}
};
class Bone{
public:
Bone(){
center=glm::vec3(0,0,0);
parent=-1;
cube = new Object("boneDebug");
cube->scale(0.2);
cube->traslate(center);
}
~Bone(){}
glm::vec3 center;
std::vector<glm::vec3> axis;
std::vector<float> parameters;
glm::mat3 matrix;
glm::mat3 m;
glm::vec3 b;
int parent;
int index;
Object * cube;
void buildMatrix(){
glm::vec3 v(0,0,0);
for(int i=0;i<axis.size();i++) v+=parameters[i]*axis[i];
if(glm::length(v)>0)
matrix=glm::mat3(glm::rotate(glm::mat4(1.0f), (float)glm::length(v), glm::normalize(v)));
else matrix=glm::mat3(1.0);
}
void setCenter(glm::vec3 c){
cube->traslate(c-center);
center=c;
}
void setIndex(int i){
index=i;
std::string filename(1,i+'0');
filename=filename+".png";
cube->setColorFile(filename);
}
};
class Keyframe{
public:
Keyframe(){}
~Keyframe(){}
int time;
std::vector<float> parameters;
};
//template <class TYPE>
class AnimatedObject : public Object//<TYPE>
{
public:
AnimatedObject(){}
AnimatedObject(char *filename);
Timer timer;
std::vector<glm::vec4> * weights;
std::vector<glm::vec4> * weightindices;
std::vector<glm::vec3> * deform;
std::vector<Bone> * skeleton;
std::vector<Keyframe> * animation;
int time;
int * numBones;
int * numKeyframes;
unsigned int* vbo_deform, *vbo_weights,*vbo_weightindices;
void Export(std::string filename);
void Import(std::string filename);
void draw(Shader* sh, bool drawSkeleton=false);
virtual void traslate (float x, float y, float z);
virtual void traslate (glm::vec3 v);
virtual void scale (float s);
virtual void rotate (float x, float y, float z, float w);
virtual void rotate (glm::vec3 v);
virtual void rotate (glm::vec4 v);
void toBuffers();
void buildMatrices(){
for(int i=0;i<skeleton->size();i++)
skeleton->at(i).buildMatrix();}
virtual void animate(bool calcDeforms=true);
void copy(AnimatedObject* o);
void alloc();
virtual void setup();
virtual void setup(int x,int y, int side);
};
#endif //OBJECT