1 | |
---|
2 | |
---|
3 | /* |
---|
4 | orxonox - the future of 3D-vertical-scrollers |
---|
5 | |
---|
6 | Copyright (C) 2004 orx |
---|
7 | |
---|
8 | This program is free software; you can redistribute it and/or modify |
---|
9 | it under the terms of the GNU General Public License as published by |
---|
10 | the Free Software Foundation; either version 2, or (at your option) |
---|
11 | any later version. |
---|
12 | |
---|
13 | ### File Specific: |
---|
14 | main-programmer: Patrick Boenzli |
---|
15 | co-programmer: Christian Meyer |
---|
16 | */ |
---|
17 | |
---|
18 | #include <iostream> |
---|
19 | |
---|
20 | #include "world_entity.h" |
---|
21 | #include "list.h" |
---|
22 | #include "vector.h" |
---|
23 | #include "obb_tree.h" |
---|
24 | |
---|
25 | using namespace std; |
---|
26 | |
---|
27 | /** |
---|
28 | \brief Loads the WordEntity-specific Part of any derived Class |
---|
29 | */ |
---|
30 | WorldEntity::WorldEntity(const TiXmlElement* root) |
---|
31 | { |
---|
32 | this->setClassID(CL_WORLD_ENTITY, "WorldEntity"); |
---|
33 | |
---|
34 | this->model = NULL; |
---|
35 | this->obbTree = NULL; |
---|
36 | |
---|
37 | if (root) |
---|
38 | this->loadParams(root); |
---|
39 | |
---|
40 | this->bDraw = true; |
---|
41 | } |
---|
42 | |
---|
43 | /** |
---|
44 | \brief standard destructor |
---|
45 | */ |
---|
46 | WorldEntity::~WorldEntity () |
---|
47 | { |
---|
48 | // if( collisioncluster != NULL) delete collisioncluster; |
---|
49 | if (this->model) |
---|
50 | ResourceManager::getInstance()->unload(this->model); |
---|
51 | } |
---|
52 | |
---|
53 | void WorldEntity::loadParams(const TiXmlElement* root) |
---|
54 | { |
---|
55 | static_cast<PNode*>(this)->loadParams(root); |
---|
56 | // Model Loading |
---|
57 | LoadParam<WorldEntity>(root, "model", this, &WorldEntity::loadModel) |
---|
58 | .describe("the fileName of the model, that should be loaded onto this world-entity. (must be relative to the data-dir)") ; |
---|
59 | } |
---|
60 | |
---|
61 | /** |
---|
62 | \brief loads a Model onto a WorldEntity |
---|
63 | \param fileName the name of the model to load |
---|
64 | */ |
---|
65 | void WorldEntity::loadModel(const char* fileName) |
---|
66 | { |
---|
67 | if (this->model) |
---|
68 | ResourceManager::getInstance()->unload(this->model, RP_LEVEL); |
---|
69 | this->model = (Model*)ResourceManager::getInstance()->load(fileName, OBJ, RP_CAMPAIGN); |
---|
70 | } |
---|
71 | |
---|
72 | /** |
---|
73 | \brief sets the character attributes of a worldentity |
---|
74 | \param character attributes |
---|
75 | |
---|
76 | these attributes don't have to be set, only use them, if you need them |
---|
77 | */ |
---|
78 | void WorldEntity::setCharacterAttributes(CharacterAttributes* charAttr) |
---|
79 | {} |
---|
80 | |
---|
81 | |
---|
82 | /** |
---|
83 | \brief gets the Character attributes of this worldentity |
---|
84 | \returns character attributes |
---|
85 | */ |
---|
86 | CharacterAttributes* WorldEntity::getCharacterAttributes() |
---|
87 | {} |
---|
88 | |
---|
89 | |
---|
90 | /** |
---|
91 | \brief set the WorldEntity's collision hull |
---|
92 | \param newhull: a pointer to a completely assembled CollisionCluster |
---|
93 | |
---|
94 | Any previously assigned collision hull will be deleted on reassignment |
---|
95 | */ |
---|
96 | /* |
---|
97 | void WorldEntity::setCollision (CollisionCluster* newhull) |
---|
98 | { |
---|
99 | if( newhull == NULL) return; |
---|
100 | if( collisioncluster != NULL) delete collisioncluster; |
---|
101 | collisioncluster = newhull; |
---|
102 | } |
---|
103 | */ |
---|
104 | |
---|
105 | |
---|
106 | /** |
---|
107 | \brief process draw function |
---|
108 | */ |
---|
109 | void WorldEntity::processDraw () |
---|
110 | { |
---|
111 | |
---|
112 | } |
---|
113 | |
---|
114 | /** |
---|
115 | \brief sets the drawable state of this entity. |
---|
116 | \param bDraw TRUE if draweable, FALSE otherwise |
---|
117 | */ |
---|
118 | void WorldEntity::setDrawable (bool bDraw) |
---|
119 | { |
---|
120 | this->bDraw = bDraw; |
---|
121 | } |
---|
122 | |
---|
123 | |
---|
124 | /** |
---|
125 | \brief this function is called, when two entities collide |
---|
126 | \param entity: the world entity with whom it collides |
---|
127 | |
---|
128 | Implement behaviour like damage application or other miscellaneous collision stuff in this function |
---|
129 | */ |
---|
130 | void WorldEntity::collideWith(WorldEntity* entity) |
---|
131 | { |
---|
132 | this->obbTree->collideWith(entity->obbTree); |
---|
133 | } |
---|
134 | |
---|
135 | |
---|
136 | /** |
---|
137 | \brief this function is called, when the ship is hit by a waepon |
---|
138 | \param weapon: the laser/rocket/shoot that hits. |
---|
139 | \param loc: place where it is hit |
---|
140 | |
---|
141 | calculate the damage depending |
---|
142 | */ |
---|
143 | void WorldEntity::hit(WorldEntity* weapon, Vector* loc) {} |
---|
144 | |
---|
145 | |
---|
146 | /** |
---|
147 | \brief this is called immediately after the Entity has been constructed and initialized |
---|
148 | |
---|
149 | Put any initialisation code that requires knowledge of location (placement if the Entity is free) and owner of the entity here. |
---|
150 | DO NOT place such code in the constructor, those variables are set AFTER the entity is constucted. |
---|
151 | */ |
---|
152 | void WorldEntity::postSpawn () |
---|
153 | { |
---|
154 | } |
---|
155 | |
---|
156 | |
---|
157 | /** |
---|
158 | \brief this method is called by the world if the WorldEntity leaves valid gamespace |
---|
159 | |
---|
160 | For free entities this means it left the Track boundaries. With bound entities it means its Location adresses a |
---|
161 | place that is not in the world anymore. In both cases you might have to take extreme measures (a.k.a. call destroy). |
---|
162 | */ |
---|
163 | void WorldEntity::leftWorld () |
---|
164 | { |
---|
165 | } |
---|
166 | |
---|
167 | |
---|
168 | /** |
---|
169 | \brief this method is called every frame |
---|
170 | \param time: the time in seconds that has passed since the last tick |
---|
171 | |
---|
172 | Handle all stuff that should update with time inside this method (movement, animation, etc.) |
---|
173 | */ |
---|
174 | void WorldEntity::tick(float time) |
---|
175 | { |
---|
176 | } |
---|
177 | |
---|
178 | |
---|
179 | /** |
---|
180 | \brief the entity is drawn onto the screen with this function |
---|
181 | |
---|
182 | This is a central function of an entity: call it to let the entity painted to the screen. Just override this function with whatever you want to be drawn. |
---|
183 | */ |
---|
184 | void WorldEntity::draw() |
---|
185 | { |
---|
186 | glMatrixMode(GL_MODELVIEW); |
---|
187 | glPushMatrix(); |
---|
188 | float matrix[4][4]; |
---|
189 | |
---|
190 | /* translate */ |
---|
191 | glTranslatef (this->getAbsCoor ().x, |
---|
192 | this->getAbsCoor ().y, |
---|
193 | this->getAbsCoor ().z); |
---|
194 | /* rotate */ |
---|
195 | this->getAbsDir ().matrix (matrix); |
---|
196 | glMultMatrixf((float*)matrix); |
---|
197 | |
---|
198 | if (this->model) |
---|
199 | this->model->draw(); |
---|
200 | glPopMatrix(); |
---|
201 | } |
---|
202 | |
---|
203 | |
---|
204 | void WorldEntity::drawBVTree(int depth, int drawMode) |
---|
205 | { |
---|
206 | glMatrixMode(GL_MODELVIEW); |
---|
207 | glPushMatrix(); |
---|
208 | float matrix[4][4]; |
---|
209 | |
---|
210 | /* translate */ |
---|
211 | glTranslatef (this->getAbsCoor ().x, |
---|
212 | this->getAbsCoor ().y, |
---|
213 | this->getAbsCoor ().z); |
---|
214 | /* rotate */ |
---|
215 | this->getAbsDir ().matrix (matrix); |
---|
216 | glMultMatrixf((float*)matrix); |
---|
217 | |
---|
218 | if (this->obbTree) |
---|
219 | this->obbTree->drawBV(depth, drawMode); |
---|
220 | glPopMatrix(); |
---|
221 | } |
---|
222 | |
---|
223 | /** |
---|
224 | \brief this handles incoming command messages |
---|
225 | \param cmd: a pointer to the incoming Command structure |
---|
226 | |
---|
227 | Put all code that handles Command messages here, this will mainly be called by the assigned CommandNode but can also be used |
---|
228 | to send commands from one WorldEntity to another. |
---|
229 | */ |
---|
230 | void WorldEntity::command (Command* cmd) |
---|
231 | { |
---|
232 | } |
---|