-
Notifications
You must be signed in to change notification settings - Fork 0
/
object.h
153 lines (106 loc) · 3.24 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
#ifndef OBJECT_H
#define OBJECT_H
#include <vector>
#include "texture.h"
#include "geometry.h"
// mesh flags
#define MF_NORMALS 1
// object flags
#define OF_LIGHTING 1
#define OF_TEXTURED 2
#define OF_LIGHTMAPS 4
#define OF_BOUNCE 8
#define OF_ALWAYS_COLLIDE 16
#define OF_EXPLODED 32 //
using namespace std;
struct Material
{
sgVec4 ambient;
sgVec4 diffuse;
sgVec4 specular;
float shininess;
};
class DynamicLight
{
public:
int id;
bool enabled;
sgVec3 pos;
sgVec3 color;
float intensity;
void light_environment();
};
// vertex and face data
class Mesh
{
public:
int flags;
int gl_disp_list;
float radius;
unsigned int nr_verts, nr_faces, nr_norms, nr_uvs;
sgVec3 *vertices;
sgVec3 *normals;
Face *faces;
// constructor
Mesh() {
vertices = NULL; normals = NULL; faces = NULL;
gl_disp_list = -1;
}
// functions for loading Wavefront OBJ data
Face *load_OBJ_face(char *fstr, bool normals, bool tcoords);
bool load_OBJ_file(const char *fname);
bool load_OBJ_file(FILE *f);
static Mesh* create_from_OBJ_file(const char *fname);
void scale(float scale);
float update_bsphere();
// static vector<Object *> load_objects(const char *fname);
};
// object class
class Object
{
protected:
int id;
char name[32];
public:
Mesh *mesh;
int flags, type, age;
sgVec3 old_pos, pos;
sgVec3 velocity;
sgMat4 orient;
long collided_at_frame;
long moved_at_frame;
// mass used in object-object collision response
float mass;
class Room *in_room;
int light_id;
public:
Object *last_object_hit;
Object();
char *get_name() { return name; }
void set_name(const char *n) { strncpy(name, n, 32); }
int get_id() { return id; }
void set_id(int _id) { id = _id; }
// void alloc_disp_list();
// spatial manipulation
void set_pos(sgVec3 _pos) { sgCopyVec3(pos, _pos); }
void set_pos(float x, float y, float z) { sgSetVec3(pos, x, y, z); }
void set_velocity(sgVec3 vel) { sgCopyVec3(velocity, vel); }
void set_velocity(float x, float y, float z) { sgSetVec3(velocity, x, y, z); }
void translate(float dx, float dy, float dz) {
}
void rotate(float angle, sgVec3 axis);
bool move(sgVec3 move, float time);
void reset_orientation() {sgMakeIdentMat4(orient); }
void set_orientation(sgMat4 tmat) { sgCopyMat4(orient, tmat); }
// void update_bsphere() { radius = mesh->update_bsphere(); }
void bounce_objects(Object *obj_b, sgVec3 move_a, sgVec3 move_b,
sgVec3 hit_point, float hit_time);
void update();
bool check_wall_collisions(sgVec3 hit_point);
void draw();
void draw_shot();
void draw_diamond();
// apply dynamic lighting
void light_environment();
};
#endif