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 | * 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->setVisibiliy(true); |
---|
41 | } |
---|
42 | |
---|
43 | /** |
---|
44 | * standard destructor |
---|
45 | */ |
---|
46 | WorldEntity::~WorldEntity () |
---|
47 | { |
---|
48 | // if( collisioncluster != NULL) delete collisioncluster; |
---|
49 | if (this->model) |
---|
50 | ResourceManager::getInstance()->unload(this->model); |
---|
51 | if( this->obbTree) |
---|
52 | delete this->obbTree; |
---|
53 | } |
---|
54 | |
---|
55 | void WorldEntity::loadParams(const TiXmlElement* root) |
---|
56 | { |
---|
57 | static_cast<PNode*>(this)->loadParams(root); |
---|
58 | // Model Loading |
---|
59 | LoadParam<WorldEntity>(root, "model", this, &WorldEntity::loadModel) |
---|
60 | .describe("the fileName of the model, that should be loaded onto this world-entity. (must be relative to the data-dir)") ; |
---|
61 | } |
---|
62 | |
---|
63 | /** |
---|
64 | * loads a Model onto a WorldEntity |
---|
65 | * @param fileName the name of the model to load |
---|
66 | */ |
---|
67 | void WorldEntity::loadModel(const char* fileName) |
---|
68 | { |
---|
69 | if (this->model) |
---|
70 | ResourceManager::getInstance()->unload(this->model, RP_LEVEL); |
---|
71 | if (fileName != NULL) |
---|
72 | { |
---|
73 | PRINTF(4)("loading %s\n", fileName); |
---|
74 | this->model = (Model*)ResourceManager::getInstance()->load(fileName, OBJ, RP_CAMPAIGN); |
---|
75 | } |
---|
76 | else |
---|
77 | this->model = NULL; |
---|
78 | } |
---|
79 | |
---|
80 | /** |
---|
81 | * sets the character attributes of a worldentity |
---|
82 | * @param character attributes |
---|
83 | * |
---|
84 | * these attributes don't have to be set, only use them, if you need them |
---|
85 | */ |
---|
86 | void WorldEntity::setCharacterAttributes(CharacterAttributes* charAttr) |
---|
87 | {} |
---|
88 | |
---|
89 | |
---|
90 | /** |
---|
91 | * gets the Character attributes of this worldentity |
---|
92 | * @returns character attributes |
---|
93 | */ |
---|
94 | CharacterAttributes* WorldEntity::getCharacterAttributes() |
---|
95 | {} |
---|
96 | |
---|
97 | /** |
---|
98 | * this function is called, when two entities collide |
---|
99 | * @param entity: the world entity with whom it collides |
---|
100 | * |
---|
101 | * Implement behaviour like damage application or other miscellaneous collision stuff in this function |
---|
102 | */ |
---|
103 | void WorldEntity::collideWith(WorldEntity* entity) |
---|
104 | { |
---|
105 | this->obbTree->collideWith(entity->obbTree, (PNode*)this, (PNode*)entity); |
---|
106 | } |
---|
107 | |
---|
108 | |
---|
109 | /** |
---|
110 | * this function is called, when the ship is hit by a waepon |
---|
111 | * @param weapon: the laser/rocket/shoot that hits. |
---|
112 | * @param loc: place where it is hit |
---|
113 | * |
---|
114 | * calculate the damage depending |
---|
115 | */ |
---|
116 | void WorldEntity::hit(WorldEntity* weapon, Vector* loc) {} |
---|
117 | |
---|
118 | |
---|
119 | /** |
---|
120 | * this is called immediately after the Entity has been constructed and initialized |
---|
121 | * |
---|
122 | * Put any initialisation code that requires knowledge of location (placement if the Entity is free) and owner of the entity here. |
---|
123 | * DO NOT place such code in the constructor, those variables are set AFTER the entity is constucted. |
---|
124 | */ |
---|
125 | void WorldEntity::postSpawn () |
---|
126 | { |
---|
127 | } |
---|
128 | |
---|
129 | |
---|
130 | /** |
---|
131 | * this method is called by the world if the WorldEntity leaves valid gamespace |
---|
132 | * |
---|
133 | * For free entities this means it left the Track boundaries. With bound entities it means its Location adresses a |
---|
134 | * place that is not in the world anymore. In both cases you might have to take extreme measures (a.k.a. call destroy). |
---|
135 | */ |
---|
136 | void WorldEntity::leftWorld () |
---|
137 | { |
---|
138 | } |
---|
139 | |
---|
140 | |
---|
141 | /** |
---|
142 | * this method is called every frame |
---|
143 | * @param time: the time in seconds that has passed since the last tick |
---|
144 | * |
---|
145 | * Handle all stuff that should update with time inside this method (movement, animation, etc.) |
---|
146 | */ |
---|
147 | void WorldEntity::tick(float time) |
---|
148 | { |
---|
149 | } |
---|
150 | |
---|
151 | /** |
---|
152 | * the entity is drawn onto the screen with this function |
---|
153 | * |
---|
154 | * This is a central function of an entity: call it to let the entity painted to the screen. |
---|
155 | * Just override this function with whatever you want to be drawn. |
---|
156 | */ |
---|
157 | void WorldEntity::draw() |
---|
158 | { |
---|
159 | glMatrixMode(GL_MODELVIEW); |
---|
160 | glPushMatrix(); |
---|
161 | float matrix[4][4]; |
---|
162 | |
---|
163 | /* translate */ |
---|
164 | glTranslatef (this->getAbsCoor ().x, |
---|
165 | this->getAbsCoor ().y, |
---|
166 | this->getAbsCoor ().z); |
---|
167 | /* rotate */ |
---|
168 | this->getAbsDir ().matrix (matrix); |
---|
169 | glMultMatrixf((float*)matrix); |
---|
170 | |
---|
171 | if (this->model) |
---|
172 | this->model->draw(); |
---|
173 | glPopMatrix(); |
---|
174 | } |
---|
175 | |
---|
176 | |
---|
177 | void WorldEntity::drawBVTree(int depth, int drawMode) |
---|
178 | { |
---|
179 | glMatrixMode(GL_MODELVIEW); |
---|
180 | glPushMatrix(); |
---|
181 | float matrix[4][4]; |
---|
182 | |
---|
183 | /* translate */ |
---|
184 | glTranslatef (this->getAbsCoor ().x, |
---|
185 | this->getAbsCoor ().y, |
---|
186 | this->getAbsCoor ().z); |
---|
187 | /* rotate */ |
---|
188 | this->getAbsDir ().matrix (matrix); |
---|
189 | glMultMatrixf((float*)matrix); |
---|
190 | |
---|
191 | if (this->obbTree) |
---|
192 | this->obbTree->drawBV(depth, drawMode); |
---|
193 | glPopMatrix(); |
---|
194 | } |
---|