1 /***************************************************************************
2  *   Copyright (C) 2004 by Murray Evans                                    *
3  *   m.evans@rdg.ac.uk                                                     *
4  *                                                                         *
5  *   This program is free software; you can redistribute it and/or modify  *
6  *   it under the terms of the GNU General Public License as published by  *
7  *   the Free Software Foundation; either version 2 of the License, or     *
8  *   (at your option) any later version.                                   *
9  *                                                                         *
10  *   This program is distributed in the hope that it will be useful,       *
11  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
12  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
13  *   GNU General Public License for more details.                          *
14  *                                                                         *
15  *   You should have received a copy of the GNU General Public License     *
16  *   along with this program; if not, write to the                         *
17  *   Free Software Foundation, Inc.,                                       *
18  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
19  ***************************************************************************/
20 #include "Entity.h"
21 
22 /********************************************************************
23  *								 Dazzle								*
24  *							Base entity class						*
25  *																	*
26  *							   Murray Evans							*
27  ********************************************************************/
28 
CEntity(void)29 CEntity::CEntity(void)
30 {
31 }
32 
~CEntity(void)33 CEntity::~CEntity(void)
34 {
35 }
36 
37 // change the position of the entity
SetPos(float in_X_f,float in_Y_f,float in_Z_f)38 void CEntity::SetPos(float in_X_f, float in_Y_f, float in_Z_f)
39 {
40 	pos_v4f.SetXYZW(in_X_f, in_Y_f, in_Z_f, 1.0f);
41 	return;
42 }
43 
44 // Set the velocity vector using x, y, z
SetVelocity(float in_Xvel_f,float in_Yvel_f,float in_Zvel_f)45 void CEntity::SetVelocity(float in_Xvel_f, float in_Yvel_f, float in_Zvel_f)
46 {
47 	vel_v4f.SetXYZW(in_Xvel_f, in_Yvel_f, in_Zvel_f, 1.0f);
48 	return;
49 }
50 
51 // Set the velocity vector using a vec4f
SetPos(CVec4f in_v4f)52 void CEntity::SetPos(CVec4f in_v4f)
53 {
54 	vel_v4f = in_v4f;
55 }
56 
57 // Set rotation of entity by axis rotations (x,y,z) in degrees
SetRotation(float in_Xrot_f,float in_Yrot_f,float in_Zrot_f)58 void CEntity::SetRotation(float in_Xrot_f, float in_Yrot_f, float in_Zrot_f)
59 {
60 	rot_v3f.SetXYZ(in_Xrot_f, in_Yrot_f, in_Zrot_f);
61 }
62 
63 
64 
65 // return x position
X(void)66 float CEntity::X(void)
67 {
68 	return pos_v4f.X();
69 }
70 
71 // return y position
Y(void)72 float CEntity::Y(void)
73 {
74 	return pos_v4f.Y();
75 }
76 
77 // return z position
Z(void)78 float CEntity::Z(void)
79 {
80 	return pos_v4f.Z();
81 }
82 
83 // return x rotation
XRot(void)84 float CEntity::XRot(void)
85 {
86 	return rot_v3f.X();
87 }
88 // return y rotation
YRot(void)89 float CEntity::YRot(void)
90 {
91 	return rot_v3f.Y();
92 }
93 // return z rotation
ZRot(void)94 float CEntity::ZRot(void)
95 {
96 	return rot_v3f.Z();
97 }
Update(void)98 void CEntity::Update(void)
99 {
100 	pos_v4f = vel_v4f + pos_v4f;
101 	pos_v4f.SetW(1);
102 }
103 
104 // put position data into the array pointed to by io_paf. Array should be float[3] for (x,y,z)
GetPos(float * io_paf)105 void CEntity::GetPos(float* io_paf)
106 {
107 	io_paf[0] = pos_v4f.X();
108 	io_paf[1] = pos_v4f.Y();
109 	io_paf[2] = pos_v4f.Z();
110 }
GetPos()111 CVec4f CEntity::GetPos()
112 {
113 	return pos_v4f;
114 }
GetVelocity()115 CVec4f CEntity::GetVelocity()
116 {
117 	return vel_v4f;
118 }
119 
120 
121 // Rendering function. Mostly it will be more evolved entities which actually have anythin happen here
Render(void)122 void CEntity::Render(void)
123 {
124 }
125 
PrepareForDestruction()126 void CEntity::PrepareForDestruction()
127 {
128 	for(int sc_i = 0; sc_i < sub_ents.Size(); sc_i++)
129 	{
130 		sub_ents[sc_i]->PrepareForDestruction();
131 	}
132 	sub_ents.Clear();
133 }
134 
SetRotVel(float in_Xrot_f,float in_Yrot_f,float in_Zrot_f)135 void CEntity::SetRotVel(float in_Xrot_f, float in_Yrot_f, float in_Zrot_f)
136 {
137 	rv_v3f.SetXYZ(in_Xrot_f, in_Yrot_f,in_Zrot_f);
138 }
139 
GetRotVel()140 CVec3f CEntity::GetRotVel()
141 {
142 	return rv_v3f;
143 }
144