1 | /* |
---|
2 | orxonox - the future of 3D-vertical-scrollers |
---|
3 | |
---|
4 | Copyright (C) 2004 orx |
---|
5 | |
---|
6 | This program is free software; you can redistribute it and/or modify |
---|
7 | it under the terms of the GNU General Public License as published by |
---|
8 | the Free Software Foundation; either version 2, or (at your option) |
---|
9 | any later version. |
---|
10 | |
---|
11 | ### File Specific: |
---|
12 | main-programmer: Benjamin Grauer |
---|
13 | co-programmer: ... |
---|
14 | |
---|
15 | */ |
---|
16 | |
---|
17 | #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WORLD_ENTITY |
---|
18 | |
---|
19 | #include "turbine_hover.h" |
---|
20 | |
---|
21 | #include "weapons/weapon_manager.h" |
---|
22 | #include "weapons/test_gun.h" |
---|
23 | #include "weapons/turret.h" |
---|
24 | #include "weapons/cannon.h" |
---|
25 | |
---|
26 | #include "util/loading/factory.h" |
---|
27 | #include "key_mapper.h" |
---|
28 | #include "state.h" |
---|
29 | |
---|
30 | #include "graphics_engine.h" |
---|
31 | #include "particles/dot_emitter.h" |
---|
32 | #include "particles/sprite_particles.h" |
---|
33 | |
---|
34 | #include "debug.h" |
---|
35 | |
---|
36 | |
---|
37 | ObjectListDefinition(TurbineHover); |
---|
38 | CREATE_FACTORY(TurbineHover); |
---|
39 | |
---|
40 | /** |
---|
41 | * destructs the turbine_hover, deletes alocated memory |
---|
42 | */ |
---|
43 | TurbineHover::~TurbineHover () |
---|
44 | { |
---|
45 | this->setPlayer(NULL); |
---|
46 | } |
---|
47 | |
---|
48 | /** |
---|
49 | * @brief loads a TurbineHover information from a specified file. |
---|
50 | * @param fileName the name of the File to load the turbine_hover from (absolute path) |
---|
51 | */ |
---|
52 | TurbineHover::TurbineHover(const std::string& fileName) |
---|
53 | { |
---|
54 | this->init(); |
---|
55 | TiXmlDocument doc(fileName); |
---|
56 | |
---|
57 | if(!doc.LoadFile()) |
---|
58 | { |
---|
59 | PRINTF(2)("Loading file %s failed for TurbineHover.\n", fileName.c_str()); |
---|
60 | return; |
---|
61 | } |
---|
62 | |
---|
63 | this->loadParams(doc.RootElement()); |
---|
64 | } |
---|
65 | |
---|
66 | /** |
---|
67 | * @brief creates a new Spaceship from Xml Data |
---|
68 | * @param root the xml element containing spaceship data |
---|
69 | |
---|
70 | @todo add more parameters to load |
---|
71 | */ |
---|
72 | TurbineHover::TurbineHover(const TiXmlElement* root) |
---|
73 | { |
---|
74 | this->init(); |
---|
75 | if (root != NULL) |
---|
76 | this->loadParams(root); |
---|
77 | |
---|
78 | //weapons: |
---|
79 | Weapon* wpRight = new TestGun(0); |
---|
80 | wpRight->setName("testGun Right"); |
---|
81 | Weapon* wpLeft = new TestGun(1); |
---|
82 | wpLeft->setName("testGun Left"); |
---|
83 | //Weapon* cannon = dynamic_cast<Weapon*>(Factory::fabricate(CL_HYPERBLASTER)); |
---|
84 | |
---|
85 | // cannon->setName("BFG"); |
---|
86 | |
---|
87 | this->addWeapon(wpLeft, 1, 0); |
---|
88 | this->addWeapon(wpRight,1 ,1); |
---|
89 | //this->addWeapon(cannon, 0, 2); |
---|
90 | |
---|
91 | this->getWeaponManager().changeWeaponConfig(1); |
---|
92 | dynamic_cast<Element2D*>(this->getWeaponManager().getFixedTarget())->setVisibility( false); |
---|
93 | |
---|
94 | this->loadModel("models/ships/hoverglider_mainbody.obj"); |
---|
95 | |
---|
96 | } |
---|
97 | |
---|
98 | |
---|
99 | /** |
---|
100 | * @brief initializes a TurbineHover |
---|
101 | */ |
---|
102 | void TurbineHover::init() |
---|
103 | { |
---|
104 | // this->setRelDir(Quaternion(M_PI, Vector(1,0,0))); |
---|
105 | this->registerObject(this, TurbineHover::_objectList); |
---|
106 | |
---|
107 | this->setSupportedPlaymodes(Playable::Full3D | Playable::Horizontal | Playable::Vertical); |
---|
108 | |
---|
109 | this->loadModel("models/ships/hoverglider_wing.obj", 1.0f, 3); |
---|
110 | this->loadModel("models/ships/hoverglider_turbine.obj", 1.0f, 4); |
---|
111 | this->loadModel("models/ships/hoverglider_turbine_rotors.obj", 1.0f, 5); |
---|
112 | |
---|
113 | bForward = bBackward = bLeft = bRight = bAscend = bDescend = false; |
---|
114 | mouseSensitivity = 0.005; |
---|
115 | |
---|
116 | this->rotorSpeed = 1000.0f; |
---|
117 | this->rotorCycle = 0.0f; |
---|
118 | this->cameraLook = 0.0f; |
---|
119 | this->rotation = 0.0f; |
---|
120 | this->acceleration = 10.0f; |
---|
121 | this->airFriction = 2.0f; |
---|
122 | |
---|
123 | this->setHealthMax(100); |
---|
124 | this->setHealth(100); |
---|
125 | |
---|
126 | |
---|
127 | // camera - issue |
---|
128 | this->cameraNode.addNodeFlags(PNODE_PROHIBIT_DELETE_WITH_PARENT); |
---|
129 | this->cameraNode.addNodeFlags(PNODE_PROHIBIT_CHILD_DELETE); |
---|
130 | //this->cameraNode.setParentMode(PNODE_ROTATE_MOVEMENT); |
---|
131 | this->cameraNode.setParent(this); |
---|
132 | this->cameraNode.setRelCoor(0,5,0); |
---|
133 | |
---|
134 | // rotors |
---|
135 | this->wingNodeLeft.addNodeFlags(PNODE_PROHIBIT_DELETE_WITH_PARENT ); |
---|
136 | this->wingNodeLeft.addNodeFlags(PNODE_PROHIBIT_CHILD_DELETE); |
---|
137 | this->wingNodeLeft.setParent(this); |
---|
138 | this->wingNodeLeft.setRelCoor(-1.5, -.3, -1.0); |
---|
139 | this->rotorNodeLeft.addNodeFlags(PNODE_PROHIBIT_DELETE_WITH_PARENT); |
---|
140 | this->rotorNodeLeft.setParent(&this->wingNodeLeft); |
---|
141 | this->rotorNodeLeft.setRelCoor(0, 1.0, -2.3); |
---|
142 | |
---|
143 | this->wingNodeRight.addNodeFlags(PNODE_PROHIBIT_DELETE_WITH_PARENT); |
---|
144 | this->wingNodeRight.addNodeFlags(PNODE_PROHIBIT_CHILD_DELETE); |
---|
145 | this->wingNodeRight.setParent(this); |
---|
146 | this->wingNodeRight.setRelCoor(-1.5, -0.3, 1.0); |
---|
147 | this->rotorNodeRight.addNodeFlags(PNODE_PROHIBIT_DELETE_WITH_PARENT); |
---|
148 | this->rotorNodeRight.setParent(&this->wingNodeRight); |
---|
149 | this->rotorNodeRight.setRelCoor(0, 1.0, 2.3); |
---|
150 | |
---|
151 | // PARTICLES |
---|
152 | this->burstEmitter[0] = new DotEmitter(200, 5.0, .01); |
---|
153 | this->burstEmitter[0]->setParent(&this->rotorNodeLeft); |
---|
154 | this->burstEmitter[0]->setRelCoor(0, -0.7, 0); |
---|
155 | this->burstEmitter[0]->setRelDir(Quaternion(-M_PI_2, Vector(0,0,1))); |
---|
156 | this->burstEmitter[0]->setName("TurbineHover_Burst_emitter_Left"); |
---|
157 | |
---|
158 | this->burstEmitter[1] = new DotEmitter(200, 5.0, .01); |
---|
159 | this->burstEmitter[1]->setParent(&this->rotorNodeRight); |
---|
160 | this->burstEmitter[1]->setRelCoor(0, -0.7, 0); |
---|
161 | this->burstEmitter[1]->setRelDir(Quaternion(-M_PI_2, Vector(0,0,1))); |
---|
162 | this->burstEmitter[1]->setName("TurbineHover_Burst_emitter_Right"); |
---|
163 | |
---|
164 | |
---|
165 | this->burstSystem = new SpriteParticles(1000); |
---|
166 | this->burstSystem->addEmitter(this->burstEmitter[0]); |
---|
167 | this->burstSystem->addEmitter(this->burstEmitter[1]); |
---|
168 | this->burstSystem->setName("SpaceShip_Burst_System"); |
---|
169 | ((SpriteParticles*)this->burstSystem)->setMaterialTexture("maps/radial-trans-noise.png"); |
---|
170 | this->burstSystem->setLifeSpan(1.0, .3); |
---|
171 | this->burstSystem->setRadius(0.0, 1.5); |
---|
172 | this->burstSystem->setRadius(0.05, 1.8); |
---|
173 | this->burstSystem->setRadius(.5, .8); |
---|
174 | this->burstSystem->setRadius(1.0, 0); |
---|
175 | this->burstSystem->setColor(0.0, .7,.7,1,.5); |
---|
176 | this->burstSystem->setColor(0.2, 0,0,0.8,.5); |
---|
177 | this->burstSystem->setColor(0.5, .5,.5,.8,.3); |
---|
178 | this->burstSystem->setColor(1.0, .8,.8,.8,.0); |
---|
179 | |
---|
180 | |
---|
181 | //add events to the eventlist of the Playable |
---|
182 | this->registerEvent(KeyMapper::PEV_FORWARD); |
---|
183 | this->registerEvent(KeyMapper::PEV_BACKWARD); |
---|
184 | this->registerEvent(KeyMapper::PEV_LEFT); |
---|
185 | this->registerEvent(KeyMapper::PEV_RIGHT); |
---|
186 | this->registerEvent(KeyMapper::PEV_UP); |
---|
187 | this->registerEvent(KeyMapper::PEV_DOWN); |
---|
188 | this->registerEvent(KeyMapper::PEV_FIRE1); |
---|
189 | this->registerEvent(KeyMapper::PEV_NEXT_WEAPON); |
---|
190 | this->registerEvent(KeyMapper::PEV_PREVIOUS_WEAPON); |
---|
191 | this->registerEvent(EV_MOUSE_MOTION); |
---|
192 | |
---|
193 | dynamic_cast<Element2D*>(this->getWeaponManager().getFixedTarget())->setVisibility( false); |
---|
194 | |
---|
195 | // WEAPON_MANAGER configuration |
---|
196 | this->getWeaponManager().setSlotCount(5); |
---|
197 | |
---|
198 | this->getWeaponManager().setSlotPosition(0, Vector(-0.28, 1.186, -2.750), &this->wingNodeLeft); |
---|
199 | this->getWeaponManager().setSlotCapability(0, WTYPE_ALLDIRS | WTYPE_DIRECTIONAL); |
---|
200 | |
---|
201 | this->getWeaponManager().setSlotPosition(1, Vector(-0.28, 1.186, 2.750), &this->wingNodeRight); |
---|
202 | this->getWeaponManager().setSlotCapability(1, WTYPE_ALLDIRS | WTYPE_DIRECTIONAL); |
---|
203 | |
---|
204 | this->getWeaponManager().setSlotPosition(2, Vector(-1.63, .809, -.003)); |
---|
205 | this->getWeaponManager().setSlotCapability(2, WTYPE_HEAVY); |
---|
206 | |
---|
207 | /// TODO: THESE ARE TOO MUCH |
---|
208 | this->getWeaponManager().setSlotPosition(3, Vector(-1.63, .678, -.652)); |
---|
209 | this->getWeaponManager().setSlotDirection(3, Quaternion(-24/180 * M_PI, Vector(1,0,0))); |
---|
210 | |
---|
211 | this->getWeaponManager().setSlotPosition(4, Vector(-1.63, .678, .652)); |
---|
212 | this->getWeaponManager().setSlotDirection(4, Quaternion(24/180 * M_PI, Vector(1,0,0))); |
---|
213 | |
---|
214 | this->cameraNode.setRelCoor(1,5,0); |
---|
215 | this->getWeaponManager().getFixedTarget()->setParent(&this->cameraNode); |
---|
216 | this->getWeaponManager().getFixedTarget()->setRelCoor(1000,0,0); |
---|
217 | |
---|
218 | registerVar( new SynchronizeableBool( &bForward, &bForward, "bForward", PERMISSION_OWNER ) ); |
---|
219 | registerVar( new SynchronizeableBool( &bBackward, &bBackward, "bBackward", PERMISSION_OWNER ) ); |
---|
220 | registerVar( new SynchronizeableBool( &bLeft, &bLeft, "bLeft", PERMISSION_OWNER ) ); |
---|
221 | registerVar( new SynchronizeableBool( &bRight, &bRight, "bRight", PERMISSION_OWNER ) ); |
---|
222 | registerVar( new SynchronizeableBool( &bAscend, &bAscend, "bAscend", PERMISSION_OWNER ) ); |
---|
223 | registerVar( new SynchronizeableBool( &bDescend, &bDescend, "bDescend", PERMISSION_OWNER ) ); |
---|
224 | registerVar( new SynchronizeableQuaternion( &direction, &direction, "direction", PERMISSION_OWNER ) ); |
---|
225 | registerVar( new SynchronizeableFloat( &cameraLook, &cameraLook, "cameraLook", PERMISSION_OWNER ) ); |
---|
226 | registerVar( new SynchronizeableFloat( &rotation, &rotation, "rotation", PERMISSION_OWNER ) ); |
---|
227 | |
---|
228 | if( State::isOnline()) |
---|
229 | toList( OM_PLAYERS ); |
---|
230 | } |
---|
231 | |
---|
232 | /** |
---|
233 | * @brief loads the Settings of a TurbineHover from an XML-element. |
---|
234 | * @param root the XML-element to load the Spaceship's properties from |
---|
235 | */ |
---|
236 | void TurbineHover::loadParams(const TiXmlElement* root) |
---|
237 | { |
---|
238 | Playable::loadParams(root); |
---|
239 | } |
---|
240 | |
---|
241 | |
---|
242 | void TurbineHover::setBoostColor(const Color& color) |
---|
243 | { |
---|
244 | this->burstSystem->setColor(0.0, color); |
---|
245 | this->burstSystem->setColor(0.2, color * 0.6); |
---|
246 | this->burstSystem->setColor(0.5, color * .3 + Color(0.5, 0.5, 0.8, 0.3)); |
---|
247 | this->burstSystem->setColor(1.0, 0.8, 0.8, 0.8, 0.0); |
---|
248 | |
---|
249 | printf(":::::::::::::::::::::::\n"); |
---|
250 | this->burstSystem->debug(); |
---|
251 | } |
---|
252 | |
---|
253 | void TurbineHover::setPlayDirection(const Quaternion& rot, float speed) |
---|
254 | { |
---|
255 | this->direction = Quaternion (rot.getHeading(), Vector(0,1,0)); |
---|
256 | } |
---|
257 | |
---|
258 | void TurbineHover::enter() |
---|
259 | { |
---|
260 | dynamic_cast<Element2D*>(this->getWeaponManager().getFixedTarget())->setVisibility( true); |
---|
261 | |
---|
262 | if (State::getCameraNode != NULL) |
---|
263 | { |
---|
264 | State::getCameraNode()->setParentSoft(&this->cameraNode); |
---|
265 | State::getCameraNode()->setRelCoorSoft(-10, 0,0); |
---|
266 | State::getCameraTargetNode()->setParentSoft(&this->cameraNode); |
---|
267 | } |
---|
268 | } |
---|
269 | |
---|
270 | void TurbineHover::leave() |
---|
271 | { |
---|
272 | dynamic_cast<Element2D*>(this->getWeaponManager().getFixedTarget())->setVisibility( false); |
---|
273 | this->detachCamera(); |
---|
274 | |
---|
275 | } |
---|
276 | |
---|
277 | void TurbineHover::setTeam(int teamID) |
---|
278 | { |
---|
279 | printf("::::::::::::::::: TEAM ::: %d\n", teamID); |
---|
280 | if (teamID == 0) |
---|
281 | { |
---|
282 | this->setBoostColor(Color::blue); |
---|
283 | } |
---|
284 | else if (teamID == 1) |
---|
285 | { |
---|
286 | this->setBoostColor(Color::red); |
---|
287 | } |
---|
288 | |
---|
289 | ///HACK this is very much hard coded.set the owner of the weapons |
---|
290 | this->getWeaponManager().getWeapon(0)->setOwner(this->getOwner()); |
---|
291 | this->getWeaponManager().getWeapon(1)->setOwner(this->getOwner()); |
---|
292 | |
---|
293 | //choose collision list |
---|
294 | if( State::isOnline()) |
---|
295 | { |
---|
296 | if( teamID == 0) |
---|
297 | toList( OM_GROUP_00 ); |
---|
298 | else if(teamID == 1) |
---|
299 | toList( OM_GROUP_01); |
---|
300 | } |
---|
301 | |
---|
302 | |
---|
303 | // set the local team id, very important |
---|
304 | this->setTeamId(teamID); |
---|
305 | } |
---|
306 | |
---|
307 | |
---|
308 | |
---|
309 | /** |
---|
310 | * @brief effect that occurs after the TurbineHover is spawned |
---|
311 | */ |
---|
312 | void TurbineHover::postSpawn () |
---|
313 | { |
---|
314 | //setCollision(new CollisionCluster(1.0, Vector(0,0,0))); |
---|
315 | } |
---|
316 | |
---|
317 | /** |
---|
318 | * @brief the action occuring if the turbine_hover left the game |
---|
319 | */ |
---|
320 | void TurbineHover::leftWorld () |
---|
321 | {} |
---|
322 | |
---|
323 | /** |
---|
324 | * @brief this function is called, when two entities collide |
---|
325 | * @param entity: the world entity with whom it collides |
---|
326 | * |
---|
327 | * Implement behaviour like damage application or other miscellaneous collision stuff in this function |
---|
328 | */ |
---|
329 | void TurbineHover::collidesWith(WorldEntity* entity, const Vector& location) |
---|
330 | { |
---|
331 | Playable::collidesWith(entity, location); |
---|
332 | } |
---|
333 | |
---|
334 | |
---|
335 | |
---|
336 | /** |
---|
337 | * @brief the function called for each passing timeSnap |
---|
338 | * @param time The timespan passed since last update |
---|
339 | */ |
---|
340 | void TurbineHover::tick (float dt) |
---|
341 | { |
---|
342 | // this->debugNode(1); |
---|
343 | Playable::tick(dt); |
---|
344 | |
---|
345 | // spaceship controlled movement |
---|
346 | |
---|
347 | // TRYING TO FIX PNode. |
---|
348 | //this->cameraNode.setRelCoor(Vector(0.0f, 5.0f, 0.0f));//, 30.0f); |
---|
349 | //this->cameraNode.setRelDir(Quaternion(this->smoothRotator *10.0, Vector(0,1,0))); |
---|
350 | |
---|
351 | this->movement(dt); |
---|
352 | this->rotorCycle += this->rotorSpeed * dt; |
---|
353 | } |
---|
354 | |
---|
355 | |
---|
356 | #include "shared_network_data.h" |
---|
357 | |
---|
358 | /** |
---|
359 | * @brief calculate the velocity |
---|
360 | * @param time the timeslice since the last frame |
---|
361 | */ |
---|
362 | void TurbineHover::movement (float dt) |
---|
363 | { |
---|
364 | Vector accel(0.0, 0.0, 0.0); |
---|
365 | |
---|
366 | if( this->bForward ) |
---|
367 | { |
---|
368 | accel += Vector(this->acceleration, 0, 0); |
---|
369 | } |
---|
370 | |
---|
371 | if( this->bBackward ) |
---|
372 | { |
---|
373 | accel -= Vector(this->acceleration, 0, 0); |
---|
374 | } |
---|
375 | if( this->bLeft) |
---|
376 | { |
---|
377 | accel -= Vector(0, 0, this->acceleration); |
---|
378 | } |
---|
379 | |
---|
380 | if( this->bRight) |
---|
381 | { |
---|
382 | accel += Vector(0, 0, this->acceleration); |
---|
383 | } |
---|
384 | |
---|
385 | if (this->bAscend ) |
---|
386 | { |
---|
387 | accel += Vector(0, this->acceleration, 0); |
---|
388 | } |
---|
389 | if (this->bDescend ) |
---|
390 | { |
---|
391 | accel -= Vector(0, this->acceleration, 0); |
---|
392 | } |
---|
393 | |
---|
394 | switch(this->getPlaymode()) |
---|
395 | { |
---|
396 | case Playable::Full3D: |
---|
397 | { |
---|
398 | Vector accelerationDir = this->getAbsDir().apply(accel * this->acceleration); |
---|
399 | |
---|
400 | // this is the air friction (necessary for a smooth control) |
---|
401 | Vector damping = (this->velocity * this->airFriction); |
---|
402 | |
---|
403 | |
---|
404 | this->velocity += (accelerationDir - damping)* dt; |
---|
405 | //if (this->getOwner() != SharedNetworkData::getInstance()->getHostID()) |
---|
406 | this->shiftCoor (this->velocity * dt); |
---|
407 | |
---|
408 | // limit the maximum rotation speed. |
---|
409 | if (this->rotation != 0.0f) |
---|
410 | { |
---|
411 | float maxRot = 10.0 * dt; |
---|
412 | if (unlikely(this->rotation > maxRot)) this->rotation = maxRot; |
---|
413 | if (unlikely(this->rotation < -maxRot)) this->rotation = -maxRot; |
---|
414 | this->direction *= Quaternion(-M_PI/4.0*this->rotation, Vector(0,1,0)); |
---|
415 | |
---|
416 | this->rotation = 0.0f; |
---|
417 | } |
---|
418 | |
---|
419 | //if (this->getOwner() != SharedNetworkData::getInstance()->getHostID()) |
---|
420 | this->setRelDirSoft(this->direction * Quaternion(-cameraLook, Vector(0,0,1)), 5); |
---|
421 | |
---|
422 | this->wingNodeLeft.setRelDirSoft(Quaternion(accel.z * .05 +this->rotation, Vector(1,0,0)), 5); |
---|
423 | this->rotorNodeLeft.setRelDirSoft(Quaternion(-accel.x * .07+this->rotation + cameraLook, Vector(0,0,1)), 5); |
---|
424 | |
---|
425 | this->wingNodeRight.setRelDirSoft(Quaternion(accel.z * .05 +this->rotation, Vector(1,0,0)), 5); |
---|
426 | this->rotorNodeRight.setRelDirSoft(Quaternion(-accel.x*.07 -this->rotation + cameraLook, Vector(0,0,1)), 5); |
---|
427 | } |
---|
428 | break; |
---|
429 | |
---|
430 | case Playable::Horizontal: |
---|
431 | { |
---|
432 | accel.y = 0.0; |
---|
433 | Vector accelerationDir = this->getAbsDir().apply(accel * this->acceleration); |
---|
434 | accelerationDir.y = 0.0; |
---|
435 | |
---|
436 | // this is the air friction (necessary for a smooth control) |
---|
437 | Vector damping = (this->velocity * this->airFriction); |
---|
438 | |
---|
439 | |
---|
440 | this->velocity += (accelerationDir - damping)* dt; |
---|
441 | this->shiftCoor (this->velocity * dt); |
---|
442 | |
---|
443 | // limit the maximum rotation speed. |
---|
444 | if (this->rotation != 0.0f) |
---|
445 | { |
---|
446 | float maxRot = 10.0 * dt; |
---|
447 | if (unlikely(this->rotation > maxRot)) this->rotation = maxRot; |
---|
448 | if (unlikely(this->rotation < -maxRot)) this->rotation = -maxRot; |
---|
449 | this->direction *= Quaternion(-M_PI/4.0*this->rotation, Vector(0,1,0)); |
---|
450 | |
---|
451 | this->rotation = 0.0f; |
---|
452 | } |
---|
453 | |
---|
454 | this->setRelDirSoft(this->direction, 5); |
---|
455 | |
---|
456 | this->wingNodeLeft.setRelDirSoft(Quaternion(accel.z * .05 +this->rotation, Vector(1,0,0)), 5); |
---|
457 | this->rotorNodeLeft.setRelDirSoft(Quaternion(-accel.x * .07+this->rotation, Vector(0,0,1)), 5); |
---|
458 | |
---|
459 | this->wingNodeRight.setRelDirSoft(Quaternion(accel.z * .05 +this->rotation, Vector(1,0,0)), 5); |
---|
460 | this->rotorNodeRight.setRelDirSoft(Quaternion(-accel.x*.07 -this->rotation, Vector(0,0,1)), 5); |
---|
461 | } |
---|
462 | break; |
---|
463 | |
---|
464 | case Playable::Vertical: |
---|
465 | { |
---|
466 | accel.z = 0; |
---|
467 | Vector accelerationDir = this->getAbsDir().apply(accel * this->acceleration); |
---|
468 | accelerationDir.z=0; |
---|
469 | |
---|
470 | // this is the air friction (necessary for a smooth control) |
---|
471 | Vector damping = (this->velocity * this->airFriction); |
---|
472 | |
---|
473 | this->velocity += (accelerationDir - damping)* dt; |
---|
474 | this->shiftCoor (this->velocity * dt); |
---|
475 | |
---|
476 | this->setRelDirSoft(this->direction * Quaternion(-cameraLook, Vector(0,0,1)), 5); |
---|
477 | |
---|
478 | this->wingNodeLeft.setRelDirSoft(Quaternion(accel.z * .05 +this->rotation, Vector(1,0,0)), 5); |
---|
479 | this->rotorNodeLeft.setRelDirSoft(Quaternion(-accel.x * .07+this->rotation + cameraLook, Vector(0,0,1)), 5); |
---|
480 | |
---|
481 | this->wingNodeRight.setRelDirSoft(Quaternion(accel.z * .05 +this->rotation, Vector(1,0,0)), 5); |
---|
482 | this->rotorNodeRight.setRelDirSoft(Quaternion(-accel.x*.07 -this->rotation + cameraLook, Vector(0,0,1)), 5); |
---|
483 | } |
---|
484 | break; |
---|
485 | default: |
---|
486 | PRINTF(2)("Playmode %s Not Implemented\n", Playable::playmodeToString(this->getPlaymode()).c_str()); |
---|
487 | } |
---|
488 | } |
---|
489 | |
---|
490 | |
---|
491 | void TurbineHover::draw() const |
---|
492 | { |
---|
493 | Vector tmpRot; |
---|
494 | WorldEntity::draw(); |
---|
495 | |
---|
496 | glPushMatrix(); |
---|
497 | /// LEFT SIDE |
---|
498 | glTranslatef (this->wingNodeLeft.getAbsCoor ().x, |
---|
499 | this->wingNodeLeft.getAbsCoor ().y, |
---|
500 | this->wingNodeLeft.getAbsCoor ().z); |
---|
501 | tmpRot = this->wingNodeLeft.getAbsDir().getSpacialAxis(); |
---|
502 | glRotatef (this->wingNodeLeft.getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z ); |
---|
503 | this->getModel(3)->draw(); |
---|
504 | glPopMatrix (); |
---|
505 | |
---|
506 | glPushMatrix(); |
---|
507 | glTranslatef (this->rotorNodeLeft.getAbsCoor ().x, |
---|
508 | this->rotorNodeLeft.getAbsCoor ().y, |
---|
509 | this->rotorNodeLeft.getAbsCoor ().z); |
---|
510 | tmpRot = this->rotorNodeLeft.getAbsDir().getSpacialAxis(); |
---|
511 | glRotatef (this->rotorNodeLeft.getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z ); |
---|
512 | this->getModel(4)->draw(); |
---|
513 | glRotatef(this->rotorCycle, 0,1,0); |
---|
514 | this->getModel(5)->draw(); |
---|
515 | glPopMatrix (); |
---|
516 | |
---|
517 | /// RIGHT SIDE |
---|
518 | glPushMatrix(); |
---|
519 | glTranslatef (this->wingNodeRight.getAbsCoor ().x, |
---|
520 | this->wingNodeRight.getAbsCoor ().y, |
---|
521 | this->wingNodeRight.getAbsCoor ().z); |
---|
522 | tmpRot = this->wingNodeRight.getAbsDir().getSpacialAxis(); |
---|
523 | glRotatef (this->wingNodeRight.getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z ); |
---|
524 | glScalef(1,1,-1); |
---|
525 | this->getModel(3)->draw(); |
---|
526 | glPopMatrix (); |
---|
527 | |
---|
528 | glPushMatrix(); |
---|
529 | glTranslatef (this->rotorNodeRight.getAbsCoor ().x, |
---|
530 | this->rotorNodeRight.getAbsCoor ().y, |
---|
531 | this->rotorNodeRight.getAbsCoor ().z); |
---|
532 | tmpRot = this->rotorNodeRight.getAbsDir().getSpacialAxis(); |
---|
533 | glRotatef (this->rotorNodeRight.getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z ); |
---|
534 | glScalef(1,1,-1); |
---|
535 | this->getModel(4)->draw(); |
---|
536 | glRotatef(this->rotorCycle, 0,1,0); |
---|
537 | this->getModel(5)->draw(); |
---|
538 | glPopMatrix (); |
---|
539 | } |
---|
540 | |
---|
541 | /** |
---|
542 | * @todo switch statement ?? |
---|
543 | */ |
---|
544 | void TurbineHover::process(const Event &event) |
---|
545 | { |
---|
546 | Playable::process(event); |
---|
547 | |
---|
548 | if( event.type == KeyMapper::PEV_LEFT) |
---|
549 | this->bLeft = event.bPressed; |
---|
550 | else if( event.type == KeyMapper::PEV_RIGHT) |
---|
551 | this->bRight = event.bPressed; |
---|
552 | else if( event.type == KeyMapper::PEV_UP) |
---|
553 | this->bAscend = event.bPressed; //this->shiftCoor(0,.1,0); |
---|
554 | else if( event.type == KeyMapper::PEV_DOWN) |
---|
555 | this->bDescend = event.bPressed; //this->shiftCoor(0,-.1,0); |
---|
556 | else if( event.type == KeyMapper::PEV_FORWARD) |
---|
557 | this->bForward = event.bPressed; //this->shiftCoor(0,.1,0); |
---|
558 | else if( event.type == KeyMapper::PEV_BACKWARD) |
---|
559 | this->bBackward = event.bPressed; //this->shiftCoor(0,-.1,0); |
---|
560 | else if( event.type == EV_MOUSE_MOTION) |
---|
561 | { |
---|
562 | float xMouse, yMouse; |
---|
563 | xMouse = event.xRel*mouseSensitivity; |
---|
564 | yMouse = event.yRel*mouseSensitivity; |
---|
565 | |
---|
566 | // rotate the Player around the y-axis |
---|
567 | this->rotation += xMouse; |
---|
568 | |
---|
569 | this->cameraLook += yMouse; |
---|
570 | // rotate the Camera around the z-axis |
---|
571 | if (cameraLook > M_PI_4) |
---|
572 | cameraLook = M_PI_4; |
---|
573 | else if (cameraLook < -M_PI_4) |
---|
574 | cameraLook = -M_PI_4; |
---|
575 | //this->cameraNode.setRelDirSoft(this->direction,10); |
---|
576 | } |
---|
577 | } |
---|
578 | |
---|
579 | |
---|
580 | /** |
---|
581 | * respawning function called by the GameRules |
---|
582 | */ |
---|
583 | void TurbineHover::respawn( ) |
---|
584 | { |
---|
585 | |
---|
586 | Playable::respawn(); |
---|
587 | } |
---|