My Project: openb3dlib.mod/openb3d/src/entity.h Source File

My Project

entity.h
Go to the documentation of this file.
1 /*
2 * entity.h
3 * iminib3d
4 *
5 * Created by Simon Harrison.
6 * Copyright Si Design. All rights reserved.
7 *
8 */
9
10 #ifndef ENTITY_H
11 #define ENTITY_H
12
13 #include "surface.h"
14 #include "matrix.h"
15 #include "brush.h"
16 #include "texture.h"
17 #include "collision2.h"
18
19 #include <vector>
20 #include <list>
21 #include <cmath>
22 #include <string>
23 using namespace std;
24
25 class CollisionImpact;
26
27 class Entity{
28
29 public:
30
31 // static entity list
32 static list<Entity*> entity_list;
33
34
35
36 // relations
37 list<Entity*> child_list;
38 Entity* parent;
39
40 // transform
41 Matrix mat;
42 Matrix rotmat;
43 float px,py,pz;
44 float sx,sy,sz;
45 float rx,ry,rz;
46 float qw,qx,qy,qz;
47
48 // material
49 Brush brush;
50
51 // visibility
52 int order;
53 float alpha_order;
54 int hide;
55 float cull_radius;
56
57 // properties
58 string name;
59 string class_name;
60
61 // anim
62 static list<Entity*> animate_list;
63 int anim; // true if mesh contains anim data
64 int anim_render; // true to render as anim mesh
65 int anim_mode;
66 float anim_time;
67 float anim_speed;
68 int anim_seq;
69 int anim_trans;
70 int anim_dir; // 1=forward, -1=backward
71 vector<int> anim_seqs_first;
72 vector<int> anim_seqs_last;
73 int no_seqs;
74 int anim_update;
75 int anim_list;
76
77 // collisions
78 int collision_type;
79 float radius_x,radius_y;
80 float box_x,box_y,box_z,box_w,box_h,box_d;
81 int no_collisions;
82 vector<CollisionImpact*> collision;
83 float old_x;
84 float old_y;
85 float old_z;
86 float old_pitch;
87 float old_yaw;
88 float old_roll;
89 float new_x;
90 float new_y;
91 float new_z;
92 int new_no;
93
94 Matrix old_mat;
95 int dynamic;
96 float dynamic_x,dynamic_y,dynamic_z,dynamic_yaw,dynamic_pitch,dynamic_roll;
97
98 // picking
99 int pick_mode;
100 int obscurer;
101
102 // tform
103 static float tformed_x;
104 static float tformed_y;
105 static float tformed_z;
106
107 Entity(){
108
109 // relations
110 parent=NULL;
111
112 // transform
113 mat.LoadIdentity();
114 rotmat.LoadIdentity();
115 px=0.0,py=0.0,pz=0.0;
116 sx=1.0,sy=1.0,sz=1.0;
117 rx=0.0,ry=0.0,rz=0.0;
118 qw=1.0,qx=0.0,qy=0.0,qz=0.0;
119
120 // material
121 //brush=NULL;
122
123 // visibility
124 order=0;
125 alpha_order=0.0;
126 hide=false;
127 cull_radius=0.0;
128
129 // properties
130 name="";
131 class_name="";
132
133 // anim
134 anim=false; // true if mesh contains anim data
135 anim_render=false; // true to render as anim mesh
136 anim_mode=0;
137 anim_time=0.0;
138 anim_speed=0.0;
139 anim_seq=0;
140 anim_trans=0;
141 anim_dir=1; // 1=forward, -1=backward
142 anim_seqs_first.push_back(0);
143 anim_seqs_last.push_back(0);
144 no_seqs=0;
145 anim_update=0;
146 anim_list=false;
147
148 // collision
149 radius_x=1.0,radius_y=1.0;
150 box_x=-1.0,box_y=-1.0,box_z=-1.0,box_w=2.0,box_h=2.0,box_d=2.0;
151 collision_type=0;
152 no_collisions=0;
153 old_x=0.0;
154 old_y=0.0;
155 old_z=0.0;
156 old_mat.LoadIdentity();
157 dynamic=false;
158 dynamic_x=0.0,dynamic_y=0.0,dynamic_z=0.0,dynamic_yaw=0.0,dynamic_pitch=0.0,dynamic_roll=0.0;
159 new_x=0.0;
160 new_y=0.0;
161 new_z=0.0;
162 new_no=0;
163
164 // picking
165 pick_mode=0;
166 obscurer=false;
167
168 }
169
170 //virtual ~Entity(){}; //Actually not needed, since no class derived from Entity has a destructor
171
172 virtual Entity* CopyEntity(Entity* ent)=0;
173 virtual void FreeEntity(void);
174 // relations
175 void EntityParent(Entity* parent_ent,int glob=true);
176 Entity* GetParent();
177 int CountChildren();
178 Entity* GetChild(int child_no);
179 Entity* FindChild(string child_name);
180 int CountAllChildren(int no_children=0);
181 Entity* GetChildFromAll(int child_no,int &no_children,Entity* ent=NULL);
182 void UpdateAllEntities(void(Update)(Entity* ent,Entity* ent2),Entity* ent2=NULL);
183 // position
184 void PositionEntity(float x,float y,float z,int glob=false);
185 void MoveEntity(float mx,float my,float mz);
186 void TranslateEntity(float tx,float ty,float tz,int glob=false);
187 void ScaleEntity(float x,float y,float z,int glob=false);
188 void RotateEntity(float x,float y,float z,int glob=false);
189 void TurnEntity(float x,float y,float z,int glob=false);
190 void PointEntity(Entity* target_ent,float roll=0.0);
191 float EntityX(int global=false);
192 float EntityY(int global=false);
193 float EntityZ(int global=false);
194 float EntityYaw(int global=false);
195 float EntityPitch(int global=false);
196 float EntityRoll(int global=false);
197 float EntityScaleX(int glob=false);
198 float EntityScaleY(int glob=false);
199 float EntityScaleZ(int glob=false);
200 // material
201 void EntityColor(float r,float g,float b,float a,int recursive=false);
202 void EntityColor(float r,float g,float b,int recursive=false);
203 void EntityRed(float r,int recursive=false);
204 void EntityGreen(float g,int recursive=false);
205 void EntityBlue(float b,int recursive=false);
206 void EntityAlpha(float a,int recursive=false);
207 void EntityShininess(float s,int recursive=false);
208 void EntityBlend(int blend_no,int recursive=false);
209 void EntityFX(int fx_no,int recursive=false);
210 void EntityTexture(Texture* texture,int frame=0,int index=0,int recursive=false);
211 void PaintEntity(Brush& bru,int recursive=false);
212 Brush* GetEntityBrush();
213 // visibility
214 void EntityOrder(int order_no,int recursive=false);
215 void ShowEntity();
216 void HideEntity();
217 int Hidden();
218 // properties
219 void NameEntity(string e_name);
220 string EntityName();
221 string EntityClass();
222 // anim
223 void Animate(int mode=1,float speed=1.0,int seq=0,int trans=0);
224 void SetAnimTime(float time,int seq=0);
225 int AnimLength();
226 float AnimTime();
227 int ExtractAnimSeq(int first_frame,int last_frame,int seq=0);
228 int LoadAnimSeq(string filename);
229 void SetAnimKey(float frame, int pos_key=true, int rot_key=true, int scale_key=true);
230 int AddAnimSeq(int length);
231 // collisions
232 void EntityType(int type_no,int recursive=false);
233 int GetEntityType();
234 void EntityRadius(float rx,float ry=0.0);
235 void EntityBox(float x,float y,float z,float w,float h,float d);
236 void ResetEntity();
237 Entity* EntityCollided(int type_no);
238 int CountCollisions();
239 float CollisionX(int index);
240 float CollisionY(int index);
241 float CollisionZ(int index);
242 float CollisionNX(int index);
243 float CollisionNY(int index);
244 float CollisionNZ(int index);
245 float CollisionTime(int index);
246 Entity* CollisionEntity(int index);
247 Surface* CollisionSurface(int index);
248 int CollisionTriangle(int index);
249 // picking
250 void EntityPickMode(int no,int obscure=true);
251 // distance
252 float EntityDistance(Entity* ent2);
253 float DeltaYaw(Entity* ent2);
254 float DeltaPitch(Entity* ent2);
255 void AlignToVector(float x,float y,float z, int axis, float rate);
256 // tform
257 static void TFormPoint(float x,float y,float z,Entity* src_ent,Entity* dest_ent);
258 static void TFormVector(float x,float y,float z,Entity* src_ent,Entity* dest_ent);
259 static void TFormNormal(float x,float y,float z,Entity* src_ent,Entity* dest_ent);
260 static float TFormedX();
261 static float TFormedY();
262 static float TFormedZ();
263 // helper funcs
264 void UpdateMat(bool load_identity=false);
265 void AddParent(Entity &parent_ent);
266 static void UpdateChildren(Entity* ent_p);
267 float EntityDistanceSquared(Entity* ent2);
268 // Quaternions
269 void MQ_Update();
270 void MQ_GetInvMatrix(Matrix &mat0);
271 void MQ_GetMatrix(Matrix &mat3);
272 //int MQ_SetMatrix(void);
273 void MQ_SetMatrix( Matrix &inputMatrix );
274 void MQ_GetScaleXYZ(float &width, float &height, float &depth);
275 void MQ_Turn( float ang, float vx, float vy, float vz, int glob=false);
276 // virtual
277 virtual void Update() {};
278 virtual void Render() {};
279
280 };
281
282 #endif
EntityClass
const char * EntityClass(Entity *ent)
Definition: functions.cpp:664
CollisionNZ
float CollisionNZ(Entity *ent, int index)
Definition: functions.cpp:358
EntityFX
void EntityFX(Entity *ent, int fx)
Definition: functions.cpp:692
Entity::old_x
float old_x
Definition: entity.h:83
Entity::alpha_order
float alpha_order
Definition: entity.h:53
Entity::cull_radius
float cull_radius
Definition: entity.h:55
Entity::anim_seqs_first
vector< int > anim_seqs_first
Definition: entity.h:71
PointEntity
void PointEntity(Entity *ent, Entity *target_ent, float roll)
Definition: functions.cpp:1250
Entity::anim_time
float anim_time
Definition: entity.h:66
EntityType
void EntityType(Entity *ent, int type_no, bool recursive)
Definition: functions.cpp:781
Entity::pick_mode
int pick_mode
Definition: entity.h:99
TFormedX
float TFormedX()
Definition: functions.cpp:1540
FindChild
Entity * FindChild(Entity *ent, char *child_name)
Definition: functions.cpp:830
Entity::new_x
float new_x
Definition: entity.h:89
UpdateChildren
void UpdateChildren(Entity *ent_p)
Definition: methods.cpp:117
Surface
Definition: surface.h:19
Entity::animate_list
static list< Entity * > animate_list
Definition: entity.h:62
Entity::new_no
int new_no
Definition: entity.h:92
Entity::Render
virtual void Render()
Definition: entity.h:278
ResetEntity
void ResetEntity(Entity *ent)
Definition: functions.cpp:1313
EntityRoll
float EntityRoll(Entity *ent, bool glob)
Definition: functions.cpp:759
CollisionY
float CollisionY(Entity *ent, int index)
Definition: functions.cpp:393
HideEntity
void HideEntity(Entity *ent)
Definition: functions.cpp:984
Entity::anim_update
int anim_update
Definition: entity.h:74
EntityOrder
void EntityOrder(Entity *ent, int order)
Definition: functions.cpp:713
ScaleEntity
void ScaleEntity(Entity *ent, float x, float y, float z, bool glob)
Definition: functions.cpp:1353
EntityPickMode
void EntityPickMode(Entity *ent, int pick_mode, bool obscurer)
Definition: functions.cpp:738
Entity::dynamic_z
float dynamic_z
Definition: entity.h:96
EntityAlpha
void EntityAlpha(Entity *ent, float alpha)
Definition: functions.cpp:636
MQ_GetScaleXYZ
void MQ_GetScaleXYZ(Entity *obj, float &width, float &height, float &depth)
Definition: methods.cpp:144
Matrix::LoadIdentity
void LoadIdentity()
Definition: matrix.h:30
Entity::tformed_y
static float tformed_y
Definition: entity.h:104
CopyEntity
Entity * CopyEntity(Entity *ent, Entity *parent)
Definition: functions.cpp:421
EntityCollided
Entity * EntityCollided(Entity *ent, int type_no)
Definition: functions.cpp:671
Entity::anim_dir
int anim_dir
Definition: entity.h:70
collision2.h
std
EntityScaleZ
float EntityScaleZ(Entity *ent, bool glob)
Definition: functions.cpp:1815
Entity::tformed_x
static float tformed_x
Definition: entity.h:103
Animate
void Animate(Entity *ent, int mode, float speed, int seq, int trans)
Definition: functions.cpp:145
Entity::anim_mode
int anim_mode
Definition: entity.h:65
CollisionEntity
Entity * CollisionEntity(Entity *ent, int index)
Definition: functions.cpp:330
EntityPitch
float EntityPitch(Entity *ent, bool glob)
Definition: functions.cpp:745
Entity::anim_seqs_last
vector< int > anim_seqs_last
Definition: entity.h:72
brush.h
Entity::rotmat
Matrix rotmat
Definition: entity.h:42
texture.h
DeltaPitch
float DeltaPitch(Entity *ent1, Entity *ent2)
Definition: functions.cpp:595
Entity::Update
virtual void Update()
Definition: entity.h:277
Entity::class_name
string class_name
Definition: entity.h:59
GetEntityType
int GetEntityType(Entity *ent)
Definition: functions.cpp:932
Entity::Entity
Entity()
Definition: entity.h:107
FreeEntity
void FreeEntity(Entity *ent)
Definition: functions.cpp:882
UpdateMat
void UpdateMat(Entity *obj, bool load_identity)
Definition: methods.cpp:109
Entity::anim
int anim
Definition: entity.h:63
EntityName
const char * EntityName(Entity *ent)
Definition: functions.cpp:706
Entity::old_roll
float old_roll
Definition: entity.h:88
EntityTexture
void EntityTexture(Entity *ent, Texture *tex, int frame, int index)
Definition: functions.cpp:773
CollisionTime
float CollisionTime(Entity *ent, int index)
Definition: functions.cpp:372
TranslateEntity
void TranslateEntity(Entity *ent, float x, float y, float z, bool glob)
Definition: functions.cpp:1582
MQ_GetInvMatrix
void MQ_GetInvMatrix(Entity *obj, Matrix &mat0)
Definition: methods.cpp:128
EntityYaw
float EntityYaw(Entity *ent, bool glob)
Definition: functions.cpp:809
GetChild
Entity * GetChild(Entity *ent, int child_no)
Definition: functions.cpp:918
MQ_GetMatrix
void MQ_GetMatrix(Entity *obj, Matrix &mat3)
Definition: methods.cpp:132
AnimLength
int AnimLength(Entity *ent)
Definition: functions.cpp:161
Entity::rz
float rz
Definition: entity.h:45
AddParent
void AddParent(Entity *obj, Entity &parent_ent)
Definition: methods.cpp:113
GetEntityBrush
Brush * GetEntityBrush(Entity *ent)
Definition: functions.cpp:925
Entity::sz
float sz
Definition: entity.h:44
MQ_SetMatrix
void MQ_SetMatrix(Entity *obj, Matrix &inputMatrix)
Definition: methods.cpp:140
CollisionNX
float CollisionNX(Entity *ent, int index)
Definition: functions.cpp:344
Entity::anim_speed
float anim_speed
Definition: entity.h:67
Entity
Definition: entity.h:27
CollisionX
float CollisionX(Entity *ent, int index)
Definition: functions.cpp:386
EntityDistanceSquared
float EntityDistanceSquared(Entity *obj, Entity *ent2)
Definition: methods.cpp:121
AnimTime
float AnimTime(Entity *ent)
Definition: functions.cpp:176
Entity::no_seqs
int no_seqs
Definition: entity.h:73
EntityDistance
float EntityDistance(Entity *ent1, Entity *ent2)
Definition: functions.cpp:685
CountAllChildren
int CountAllChildren(Entity *obj, int no_children)
Definition: methods.cpp:93
TFormedY
float TFormedY()
Definition: functions.cpp:1547
Entity::hide
int hide
Definition: entity.h:54
Entity::old_yaw
float old_yaw
Definition: entity.h:87
Entity::anim_seq
int anim_seq
Definition: entity.h:68
Entity::obscurer
int obscurer
Definition: entity.h:100
TFormedZ
float TFormedZ()
Definition: functions.cpp:1554
CollisionTriangle
int CollisionTriangle(Entity *ent, int index)
Definition: functions.cpp:379
CollisionZ
float CollisionZ(Entity *ent, int index)
Definition: functions.cpp:400
NameEntity
void NameEntity(Entity *ent, char *name)
Definition: functions.cpp:1129
matrix.h
Entity::anim_trans
int anim_trans
Definition: entity.h:69
EntityParent
void EntityParent(Entity *ent, Entity *parent_ent, bool glob)
Definition: functions.cpp:724
TFormVector
void TFormVector(float x, float y, float z, Entity *src_ent, Entity *dest_ent)
Definition: functions.cpp:1575
AddAnimSeq
int AddAnimSeq(Entity *ent, int length)
Definition: functions.cpp:103
Entity::pz
float pz
Definition: entity.h:43
GetChildFromAll
Entity * GetChildFromAll(Entity *obj, int child_no, int &no_children, Entity *ent)
Definition: methods.cpp:97
CollisionSurface
Surface * CollisionSurface(Entity *ent, int index)
Definition: functions.cpp:365
LoadAnimSeq
int LoadAnimSeq(Entity *ent, char *file)
Definition: functions.cpp:1027
EntityColor
void EntityColor(Entity *ent, float red, float green, float blue)
Definition: functions.cpp:678
Entity::tformed_z
static float tformed_z
Definition: entity.h:105
RotateEntity
void RotateEntity(Entity *ent, float x, float y, float z, bool glob)
Definition: functions.cpp:1325
ShowEntity
void ShowEntity(Entity *ent)
Definition: functions.cpp:1416
EntityScaleY
float EntityScaleY(Entity *ent, bool glob)
Definition: functions.cpp:1811
Entity::brush
Brush brush
Definition: entity.h:49
Entity::collision
vector< CollisionImpact * > collision
Definition: entity.h:82
Texture
Definition: texture.h:23
Entity::no_collisions
int no_collisions
Definition: entity.h:81
CollisionNY
float CollisionNY(Entity *ent, int index)
Definition: functions.cpp:351
AlignToVector
void AlignToVector(Entity *obj, float x, float y, float z, int axis, float rate)
Definition: methods.cpp:105
EntityScaleX
float EntityScaleX(Entity *ent, bool glob)
Definition: functions.cpp:1807
Matrix
Definition: matrix.h:18
EntityZ
float EntityZ(Entity *ent, bool glob)
Definition: functions.cpp:816
PaintEntity
void PaintEntity(Entity *ent, Brush *brush)
Definition: functions.cpp:1136
Entity::qz
float qz
Definition: entity.h:46
EntityBox
void EntityBox(Entity *ent, float x, float y, float z, float w, float h, float d)
Definition: functions.cpp:657
Entity::mat
Matrix mat
Definition: entity.h:41
surface.h
MQ_Update
void MQ_Update(Entity *obj)
Definition: methods.cpp:125
TFormNormal
void TFormNormal(float x, float y, float z, Entity *src_ent, Entity *dest_ent)
Definition: functions.cpp:1561
Entity::collision_type
int collision_type
Definition: entity.h:78
Entity::name
string name
Definition: entity.h:58
Entity::dynamic
int dynamic
Definition: entity.h:95
Entity::entity_list
static list< Entity * > entity_list
Definition: entity.h:32
EntityY
float EntityY(Entity *ent, bool glob)
Definition: functions.cpp:802
Entity::new_y
float new_y
Definition: entity.h:90
EntityShininess
void EntityShininess(Entity *ent, float shine)
Definition: functions.cpp:766
Entity::new_z
float new_z
Definition: entity.h:91
CountCollisions
int CountCollisions(Entity *ent)
Definition: functions.cpp:414
Entity::box_z
float box_z
Definition: entity.h:80
Entity::child_list
list< Entity * > child_list
Definition: entity.h:37
Entity::anim_list
int anim_list
Definition: entity.h:75
MQ_Turn
void MQ_Turn(Entity *obj, float ang, float vx, float vy, float vz, int glob)
Definition: methods.cpp:148
Entity::order
int order
Definition: entity.h:52
Brush
Definition: brush.h:21
TurnEntity
void TurnEntity(Entity *ent, float x, float y, float z, bool glob)
Definition: functions.cpp:1596
Entity::anim_render
int anim_render
Definition: entity.h:64
EntityX
float EntityX(Entity *ent, bool glob)
Definition: functions.cpp:795
DeltaYaw
float DeltaYaw(Entity *ent1, Entity *ent2)
Definition: functions.cpp:602
CollisionImpact
Definition: collision2.h:47
SetAnimTime
void SetAnimTime(Entity *ent, float time, int seq)
Definition: functions.cpp:1388
CountChildren
int CountChildren(Entity *ent)
Definition: functions.cpp:407
MoveEntity
void MoveEntity(Entity *ent, float x, float y, float z)
Definition: functions.cpp:1122
load3ds::texture
Texture * texture
Definition: 3ds.cpp:50
EntityBlend
void EntityBlend(Entity *ent, int blend)
Definition: functions.cpp:650
EntityRadius
void EntityRadius(Entity *ent, float radius_x, float radius_y)
Definition: functions.cpp:752
TFormPoint
void TFormPoint(float x, float y, float z, Entity *src_ent, Entity *dest_ent)
Definition: functions.cpp:1568
SetAnimKey
void SetAnimKey(Entity *ent, float frame, int pos_key=true, int rot_key=true, int scale_key=true)
Definition: functions.cpp:1381
PositionEntity
void PositionEntity(Entity *ent, float x, float y, float z, bool glob)
Definition: functions.cpp:1257
Entity::old_y
float old_y
Definition: entity.h:84
NULL
#define NULL
Definition: tree.cpp:4
Entity::old_pitch
float old_pitch
Definition: entity.h:86
Entity::old_z
float old_z
Definition: entity.h:85
Entity::radius_y
float radius_y
Definition: entity.h:79
Hidden
int Hidden(Entity *obj)
Definition: methods.cpp:101
Entity::parent
Entity * parent
Definition: entity.h:38
Entity::old_mat
Matrix old_mat
Definition: entity.h:94
ExtractAnimSeq
int ExtractAnimSeq(Entity *ent, int first_frame, int last_frame, int seq)
Definition: functions.cpp:823