[6443] | 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 | |
---|
[6799] | 19 | #include "hover.h" |
---|
[6443] | 20 | |
---|
| 21 | #include "weapons/weapon_manager.h" |
---|
| 22 | #include "weapons/test_gun.h" |
---|
| 23 | #include "weapons/turret.h" |
---|
| 24 | #include "weapons/cannon.h" |
---|
| 25 | |
---|
[7193] | 26 | #include "util/loading/factory.h" |
---|
[9235] | 27 | //#include "util/loading/resource_manager.h" |
---|
| 28 | |
---|
[6443] | 29 | #include "key_mapper.h" |
---|
| 30 | #include "state.h" |
---|
| 31 | |
---|
| 32 | #include "graphics_engine.h" |
---|
| 33 | |
---|
[8362] | 34 | #include "debug.h" |
---|
[10355] | 35 | #include "bsp_entity.h" |
---|
| 36 | #include "terrain.h" |
---|
| 37 | #include "state.h" |
---|
| 38 | #include "camera.h" |
---|
[6443] | 39 | |
---|
[10114] | 40 | |
---|
| 41 | ObjectListDefinition(Hover); |
---|
[9869] | 42 | CREATE_FACTORY(Hover); |
---|
[6443] | 43 | |
---|
[9235] | 44 | #include "script_class.h" |
---|
[9869] | 45 | CREATE_SCRIPTABLE_CLASS(Hover, |
---|
| 46 | addMethod("hasPlayer", Executor0ret<Playable, lua_State*,bool>(&Playable::hasPlayer)) |
---|
[9235] | 47 | //Coordinates |
---|
[9869] | 48 | ->addMethod("setAbsCoor", Executor3<PNode, lua_State*,float,float,float>(&PNode::setAbsCoor)) |
---|
| 49 | ->addMethod("getAbsCoorX", Executor0ret<PNode, lua_State*, float>(&PNode::getAbsCoorX)) |
---|
| 50 | ->addMethod("getAbsCoorY", Executor0ret<PNode, lua_State*, float>(&PNode::getAbsCoorY)) |
---|
| 51 | ->addMethod("getAbsCoorZ", Executor0ret<PNode, lua_State*, float>(&PNode::getAbsCoorZ)) |
---|
[9235] | 52 | ); |
---|
| 53 | |
---|
[6443] | 54 | /** |
---|
[6799] | 55 | * destructs the hover, deletes alocated memory |
---|
[6443] | 56 | */ |
---|
[6799] | 57 | Hover::~Hover () |
---|
[6986] | 58 | { |
---|
| 59 | this->setPlayer(NULL); |
---|
[9235] | 60 | |
---|
| 61 | //if (this->hoverBuffer != NULL) |
---|
| 62 | // ResourceManager::getInstance()->unload(this->hoverBuffer); |
---|
[6986] | 63 | } |
---|
[6443] | 64 | |
---|
| 65 | /** |
---|
[6799] | 66 | * loads a Hover information from a specified file. |
---|
| 67 | * @param fileName the name of the File to load the hover from (absolute path) |
---|
[6443] | 68 | */ |
---|
[7221] | 69 | Hover::Hover(const std::string& fileName) |
---|
[6443] | 70 | { |
---|
| 71 | this->init(); |
---|
| 72 | TiXmlDocument doc(fileName); |
---|
| 73 | |
---|
| 74 | if(!doc.LoadFile()) |
---|
| 75 | { |
---|
[7221] | 76 | PRINTF(2)("Loading file %s failed for Hover.\n", fileName.c_str()); |
---|
[6443] | 77 | return; |
---|
| 78 | } |
---|
| 79 | |
---|
| 80 | this->loadParams(doc.RootElement()); |
---|
[9235] | 81 | |
---|
| 82 | //load sound |
---|
| 83 | //if (this->hoverBuffer != NULL) |
---|
| 84 | // ResourceManager::getInstance()->unload(this->hoverBuffer); |
---|
| 85 | //this->hoverBuffer = (OrxSound::SoundBuffer*)ResourceManager::getInstance()->load("sound/engine/hover.wav", WAV); |
---|
| 86 | |
---|
[6443] | 87 | } |
---|
| 88 | |
---|
| 89 | /** |
---|
| 90 | * creates a new Spaceship from Xml Data |
---|
| 91 | * @param root the xml element containing spaceship data |
---|
| 92 | |
---|
| 93 | @todo add more parameters to load |
---|
| 94 | */ |
---|
[6799] | 95 | Hover::Hover(const TiXmlElement* root) |
---|
[6443] | 96 | { |
---|
| 97 | this->init(); |
---|
| 98 | if (root != NULL) |
---|
| 99 | this->loadParams(root); |
---|
| 100 | |
---|
| 101 | //weapons: |
---|
| 102 | Weapon* wpRight = new TestGun(0); |
---|
| 103 | wpRight->setName("testGun Right"); |
---|
| 104 | Weapon* wpLeft = new TestGun(1); |
---|
| 105 | wpLeft->setName("testGun Left"); |
---|
[9869] | 106 | Weapon* cannon = dynamic_cast<Weapon*>(Factory::fabricate("Hyperblaster")); |
---|
[6443] | 107 | |
---|
| 108 | cannon->setName("BFG"); |
---|
| 109 | |
---|
| 110 | this->addWeapon(wpLeft, 1, 0); |
---|
| 111 | this->addWeapon(wpRight,1 ,1); |
---|
[6803] | 112 | this->addWeapon(cannon, 0, 2); |
---|
[6443] | 113 | |
---|
[7337] | 114 | this->getWeaponManager().changeWeaponConfig(1); |
---|
| 115 | dynamic_cast<Element2D*>(this->getWeaponManager().getFixedTarget())->setVisibility( false); |
---|
[6800] | 116 | |
---|
| 117 | this->loadModel("models/ships/hoverglider_mainbody.obj"); |
---|
[6443] | 118 | } |
---|
| 119 | |
---|
| 120 | |
---|
| 121 | /** |
---|
[6799] | 122 | * initializes a Hover |
---|
[6443] | 123 | */ |
---|
[6799] | 124 | void Hover::init() |
---|
[6443] | 125 | { |
---|
[9235] | 126 | |
---|
| 127 | //this->hitEntity = NULL; |
---|
| 128 | //this->hoverBuffer = NULL; |
---|
| 129 | |
---|
[6805] | 130 | // this->setRelDir(Quaternion(M_PI, Vector(1,0,0))); |
---|
[9869] | 131 | this->registerObject(this, Hover::_objectList); |
---|
[8719] | 132 | this->toReflectionList(); |
---|
[6443] | 133 | |
---|
[6807] | 134 | this->loadModel("models/ships/hoverglider_wing.obj", 1.0f, 3); |
---|
| 135 | this->loadModel("models/ships/hoverglider_rotor.obj", 1.0f, 4); |
---|
| 136 | this->loadModel("models/ships/rotor.obj", .45f, 5); |
---|
[6443] | 137 | |
---|
[6805] | 138 | bForward = bBackward = bLeft = bRight = bAscend = bDescend = false; |
---|
[6807] | 139 | mouseSensitivity = 0.005; |
---|
[6443] | 140 | |
---|
[6806] | 141 | this->rotorSpeed = 1000.0f; |
---|
| 142 | this->rotorCycle = 0.0f; |
---|
[6807] | 143 | this->cameraLook = 0.0f; |
---|
| 144 | this->rotation = 0.0f; |
---|
[9235] | 145 | this->acceleration = 15.0f; |
---|
[6999] | 146 | this->airFriction = 3.0f; |
---|
[6799] | 147 | |
---|
[6806] | 148 | // camera - issue |
---|
[6800] | 149 | this->cameraNode.addNodeFlags(PNODE_PROHIBIT_DELETE_WITH_PARENT); |
---|
[6806] | 150 | this->cameraNode.addNodeFlags(PNODE_PROHIBIT_CHILD_DELETE); |
---|
[6880] | 151 | //this->cameraNode.setParentMode(PNODE_ROTATE_MOVEMENT); |
---|
[6724] | 152 | this->cameraNode.setParent(this); |
---|
[6799] | 153 | |
---|
[6724] | 154 | // rotors |
---|
[6803] | 155 | this->wingNodeLeft.addNodeFlags(PNODE_PROHIBIT_DELETE_WITH_PARENT ); |
---|
| 156 | this->wingNodeLeft.addNodeFlags(PNODE_PROHIBIT_CHILD_DELETE); |
---|
[6801] | 157 | this->wingNodeLeft.setParent(this); |
---|
| 158 | this->wingNodeLeft.setRelCoor(-1.5, -.3, -1.0); |
---|
[6800] | 159 | this->rotorNodeLeft.addNodeFlags(PNODE_PROHIBIT_DELETE_WITH_PARENT); |
---|
[6801] | 160 | this->rotorNodeLeft.setParent(&this->wingNodeLeft); |
---|
| 161 | this->rotorNodeLeft.setRelCoor(0, 1.0, -2.3); |
---|
[6799] | 162 | |
---|
[6801] | 163 | this->wingNodeRight.addNodeFlags(PNODE_PROHIBIT_DELETE_WITH_PARENT); |
---|
[6803] | 164 | this->wingNodeRight.addNodeFlags(PNODE_PROHIBIT_CHILD_DELETE); |
---|
[6800] | 165 | this->wingNodeRight.setParent(this); |
---|
[6801] | 166 | this->wingNodeRight.setRelCoor(-1.5, -0.3, 1.0); |
---|
| 167 | this->rotorNodeRight.addNodeFlags(PNODE_PROHIBIT_DELETE_WITH_PARENT); |
---|
[6800] | 168 | this->rotorNodeRight.setParent(&this->wingNodeRight); |
---|
[6801] | 169 | this->rotorNodeRight.setRelCoor(0, 1.0, 2.3); |
---|
[6443] | 170 | |
---|
[7337] | 171 | dynamic_cast<Element2D*>(this->getWeaponManager().getFixedTarget())->setVisibility( false); |
---|
[6803] | 172 | |
---|
[6800] | 173 | |
---|
[6443] | 174 | //add events to the eventlist |
---|
[6997] | 175 | registerEvent(KeyMapper::PEV_FORWARD); |
---|
| 176 | registerEvent(KeyMapper::PEV_BACKWARD); |
---|
[6637] | 177 | registerEvent(KeyMapper::PEV_LEFT); |
---|
| 178 | registerEvent(KeyMapper::PEV_RIGHT); |
---|
[6998] | 179 | registerEvent(KeyMapper::PEV_UP); |
---|
| 180 | registerEvent(KeyMapper::PEV_DOWN); |
---|
[6443] | 181 | registerEvent(KeyMapper::PEV_FIRE1); |
---|
| 182 | registerEvent(KeyMapper::PEV_NEXT_WEAPON); |
---|
| 183 | registerEvent(KeyMapper::PEV_PREVIOUS_WEAPON); |
---|
| 184 | registerEvent(EV_MOUSE_MOTION); |
---|
| 185 | |
---|
| 186 | |
---|
[6803] | 187 | // WEAPON_MANAGER configuration |
---|
[7337] | 188 | this->getWeaponManager().setSlotCount(5); |
---|
[6803] | 189 | |
---|
[7337] | 190 | this->getWeaponManager().setSlotPosition(0, Vector(-0.28, 1.186, -2.750), &this->wingNodeLeft); |
---|
| 191 | this->getWeaponManager().setSlotCapability(0, WTYPE_ALLDIRS | WTYPE_DIRECTIONAL); |
---|
[6443] | 192 | |
---|
[7337] | 193 | this->getWeaponManager().setSlotPosition(1, Vector(-0.28, 1.186, 2.750), &this->wingNodeRight); |
---|
| 194 | this->getWeaponManager().setSlotCapability(1, WTYPE_ALLDIRS | WTYPE_DIRECTIONAL); |
---|
[6443] | 195 | |
---|
[7337] | 196 | this->getWeaponManager().setSlotPosition(2, Vector(-1.63, .809, -.003)); |
---|
| 197 | this->getWeaponManager().setSlotCapability(2, WTYPE_HEAVY); |
---|
[6443] | 198 | |
---|
[6803] | 199 | /// TODO: THESE ARE TOO MUCH |
---|
[7337] | 200 | this->getWeaponManager().setSlotPosition(3, Vector(-1.63, .678, -.652)); |
---|
| 201 | this->getWeaponManager().setSlotDirection(3, Quaternion(-24/180 * M_PI, Vector(1,0,0))); |
---|
[6443] | 202 | |
---|
[7337] | 203 | this->getWeaponManager().setSlotPosition(4, Vector(-1.63, .678, .652)); |
---|
| 204 | this->getWeaponManager().setSlotDirection(4, Quaternion(24/180 * M_PI, Vector(1,0,0))); |
---|
[6443] | 205 | |
---|
[6807] | 206 | this->cameraNode.setRelCoor(1,5,0); |
---|
[7337] | 207 | this->getWeaponManager().getFixedTarget()->setParent(&this->cameraNode); |
---|
| 208 | this->getWeaponManager().getFixedTarget()->setRelCoor(1000,0,0); |
---|
[8316] | 209 | |
---|
[7954] | 210 | // NETWORK THINGS |
---|
[8316] | 211 | |
---|
[7954] | 212 | registerVar( new SynchronizeableBool( &bForward, &bForward, "bForward", PERMISSION_OWNER ) ); |
---|
| 213 | registerVar( new SynchronizeableBool( &bBackward, &bBackward, "bBackward", PERMISSION_OWNER ) ); |
---|
| 214 | registerVar( new SynchronizeableBool( &bLeft, &bLeft, "bLeft", PERMISSION_OWNER ) ); |
---|
| 215 | registerVar( new SynchronizeableBool( &bRight, &bRight, "bRight", PERMISSION_OWNER ) ); |
---|
| 216 | registerVar( new SynchronizeableBool( &bAscend, &bAscend, "bAscend", PERMISSION_OWNER ) ); |
---|
| 217 | registerVar( new SynchronizeableBool( &bDescend, &bDescend, "bDescend", PERMISSION_OWNER ) ); |
---|
[8316] | 218 | |
---|
[7954] | 219 | registerVar( new SynchronizeableFloat( &rotation, &rotation, "rotation", PERMISSION_OWNER ) ); |
---|
[10355] | 220 | |
---|
| 221 | //this->subscribeReaction(CoRe::CREngine::CR_PHYSICS_FULL_WALK, BspEntity::staticClassID()); |
---|
| 222 | this->subscribeReaction(CoRe::CREngine::CR_PHYSICS_FULL_WALK, WorldEntity::staticClassID()); |
---|
[6443] | 223 | } |
---|
| 224 | |
---|
| 225 | /** |
---|
[6799] | 226 | * loads the Settings of a Hover from an XML-element. |
---|
[6443] | 227 | * @param root the XML-element to load the Spaceship's properties from |
---|
| 228 | */ |
---|
[6799] | 229 | void Hover::loadParams(const TiXmlElement* root) |
---|
[6443] | 230 | { |
---|
[6512] | 231 | WorldEntity::loadParams(root); |
---|
[6443] | 232 | } |
---|
| 233 | |
---|
| 234 | |
---|
[6799] | 235 | void Hover::enter() |
---|
[6443] | 236 | { |
---|
[7337] | 237 | dynamic_cast<Element2D*>(this->getWeaponManager().getFixedTarget())->setVisibility( true); |
---|
[6443] | 238 | |
---|
[7014] | 239 | State::getCameraNode()->setParentSoft(&this->cameraNode); |
---|
| 240 | State::getCameraNode()->setRelCoorSoft(-10, 0,0); |
---|
| 241 | State::getCameraTargetNode()->setParentSoft(&this->cameraNode); |
---|
[9235] | 242 | |
---|
| 243 | //this->soundSource.play(this->hoverBuffer, 0.3f, true); |
---|
| 244 | |
---|
[6443] | 245 | } |
---|
| 246 | |
---|
[6799] | 247 | void Hover::leave() |
---|
[6443] | 248 | { |
---|
[7337] | 249 | dynamic_cast<Element2D*>(this->getWeaponManager().getFixedTarget())->setVisibility( false); |
---|
[6443] | 250 | this->detachCamera(); |
---|
| 251 | |
---|
| 252 | } |
---|
| 253 | |
---|
| 254 | |
---|
| 255 | /** |
---|
[6799] | 256 | * effect that occurs after the Hover is spawned |
---|
[6443] | 257 | */ |
---|
[6799] | 258 | void Hover::postSpawn () |
---|
[6443] | 259 | { |
---|
| 260 | //setCollision(new CollisionCluster(1.0, Vector(0,0,0))); |
---|
| 261 | } |
---|
| 262 | |
---|
| 263 | /** |
---|
[6799] | 264 | * the action occuring if the hover left the game |
---|
[6443] | 265 | */ |
---|
[6799] | 266 | void Hover::leftWorld () |
---|
[6443] | 267 | {} |
---|
| 268 | |
---|
| 269 | /** |
---|
| 270 | * this function is called, when two entities collide |
---|
| 271 | * @param entity: the world entity with whom it collides |
---|
| 272 | * |
---|
| 273 | * Implement behaviour like damage application or other miscellaneous collision stuff in this function |
---|
| 274 | */ |
---|
[6799] | 275 | void Hover::collidesWith(WorldEntity* entity, const Vector& location) |
---|
[7072] | 276 | { |
---|
| 277 | Playable::collidesWith(entity, location); |
---|
| 278 | } |
---|
[6443] | 279 | |
---|
| 280 | |
---|
| 281 | |
---|
| 282 | /** |
---|
| 283 | * the function called for each passing timeSnap |
---|
| 284 | * @param time The timespan passed since last update |
---|
| 285 | */ |
---|
[6804] | 286 | void Hover::tick (float dt) |
---|
[6443] | 287 | { |
---|
[6804] | 288 | Playable::tick(dt); |
---|
| 289 | |
---|
[6443] | 290 | // spaceship controlled movement |
---|
[6805] | 291 | this->movement(dt); |
---|
[6806] | 292 | this->rotorCycle += this->rotorSpeed * dt; |
---|
[6443] | 293 | } |
---|
| 294 | |
---|
| 295 | /** |
---|
| 296 | * calculate the velocity |
---|
| 297 | * @param time the timeslice since the last frame |
---|
| 298 | */ |
---|
[6806] | 299 | void Hover::movement (float dt) |
---|
[6443] | 300 | { |
---|
| 301 | Vector accel(0.0, 0.0, 0.0); |
---|
| 302 | |
---|
[6814] | 303 | if( this->bForward ) |
---|
| 304 | { |
---|
[6879] | 305 | accel += Vector(this->acceleration, 0, 0); |
---|
[6443] | 306 | } |
---|
| 307 | |
---|
[6814] | 308 | if( this->bBackward ) |
---|
| 309 | { |
---|
[6879] | 310 | accel -= Vector(this->acceleration, 0, 0); |
---|
[6443] | 311 | } |
---|
[6814] | 312 | if( this->bLeft) |
---|
| 313 | { |
---|
[6879] | 314 | accel -= Vector(0, 0, this->acceleration); |
---|
[6443] | 315 | } |
---|
[6807] | 316 | |
---|
[6814] | 317 | if( this->bRight) |
---|
| 318 | { |
---|
[6879] | 319 | accel += Vector(0, 0, this->acceleration); |
---|
[6443] | 320 | } |
---|
| 321 | |
---|
[6814] | 322 | if (this->bAscend ) |
---|
| 323 | { |
---|
[6879] | 324 | accel += Vector(0, this->acceleration, 0); |
---|
[6443] | 325 | } |
---|
[6814] | 326 | if (this->bDescend ) |
---|
| 327 | { |
---|
[6879] | 328 | accel -= Vector(0, this->acceleration, 0); |
---|
[6807] | 329 | } |
---|
[6443] | 330 | |
---|
[6999] | 331 | Vector accelerationDir = this->getAbsDir().apply(accel * this->acceleration); |
---|
[6814] | 332 | |
---|
[6879] | 333 | // this is the air friction (necessary for a smooth control) |
---|
[6999] | 334 | Vector damping = (this->velocity * this->airFriction); |
---|
| 335 | |
---|
| 336 | |
---|
| 337 | this->velocity += (accelerationDir - damping)* dt; |
---|
| 338 | |
---|
| 339 | this->shiftCoor (this->velocity * dt); |
---|
[6879] | 340 | |
---|
[9656] | 341 | // limit the maximum rotation speed. |
---|
[7327] | 342 | if (this->rotation != 0.0f) |
---|
| 343 | { |
---|
| 344 | float maxRot = 10.0 * dt; |
---|
| 345 | if (unlikely(this->rotation > maxRot)) this->rotation = maxRot; |
---|
| 346 | if (unlikely(this->rotation < -maxRot)) this->rotation = -maxRot; |
---|
| 347 | this->direction *= Quaternion(-M_PI/4.0*this->rotation, Vector(0,1,0)); |
---|
| 348 | this->rotation = 0.0f; |
---|
| 349 | } |
---|
| 350 | |
---|
[6880] | 351 | this->setRelDirSoft(this->direction * Quaternion(-cameraLook, Vector(0,0,1)), 5); |
---|
[6805] | 352 | |
---|
[6999] | 353 | this->wingNodeLeft.setRelDirSoft(Quaternion(accel.z * .03 +this->rotation, Vector(1,0,0)), 5); |
---|
| 354 | this->rotorNodeLeft.setRelDirSoft(Quaternion(-accel.x * .05+this->rotation + cameraLook, Vector(0,0,1)), 5); |
---|
[6805] | 355 | |
---|
[6999] | 356 | this->wingNodeRight.setRelDirSoft(Quaternion(accel.z * .03 +this->rotation, Vector(1,0,0)), 5); |
---|
| 357 | this->rotorNodeRight.setRelDirSoft(Quaternion(-accel.x*.05 -this->rotation + cameraLook, Vector(0,0,1)), 5); |
---|
[6443] | 358 | } |
---|
| 359 | |
---|
| 360 | |
---|
[6799] | 361 | void Hover::draw() const |
---|
[10355] | 362 | { |
---|
[6801] | 363 | Vector tmpRot; |
---|
[6443] | 364 | WorldEntity::draw(); |
---|
[6799] | 365 | |
---|
[6801] | 366 | glPushMatrix(); |
---|
| 367 | /// LEFT SIDE |
---|
| 368 | glTranslatef (this->wingNodeLeft.getAbsCoor ().x, |
---|
| 369 | this->wingNodeLeft.getAbsCoor ().y, |
---|
| 370 | this->wingNodeLeft.getAbsCoor ().z); |
---|
| 371 | tmpRot = this->wingNodeLeft.getAbsDir().getSpacialAxis(); |
---|
| 372 | glRotatef (this->wingNodeLeft.getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z ); |
---|
| 373 | this->getModel(3)->draw(); |
---|
| 374 | glPopMatrix (); |
---|
[6443] | 375 | |
---|
[6801] | 376 | glPushMatrix(); |
---|
| 377 | glTranslatef (this->rotorNodeLeft.getAbsCoor ().x, |
---|
| 378 | this->rotorNodeLeft.getAbsCoor ().y, |
---|
| 379 | this->rotorNodeLeft.getAbsCoor ().z); |
---|
| 380 | tmpRot = this->rotorNodeLeft.getAbsDir().getSpacialAxis(); |
---|
| 381 | glRotatef (this->rotorNodeLeft.getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z ); |
---|
| 382 | this->getModel(4)->draw(); |
---|
[6806] | 383 | glTranslatef(0,-1,0); |
---|
| 384 | glRotatef(this->rotorCycle, 0,1,0); |
---|
| 385 | this->getModel(5)->draw(); |
---|
[6801] | 386 | glPopMatrix (); |
---|
[6724] | 387 | |
---|
[6801] | 388 | /// RIGHT SIDE |
---|
| 389 | glPushMatrix(); |
---|
| 390 | glTranslatef (this->wingNodeRight.getAbsCoor ().x, |
---|
| 391 | this->wingNodeRight.getAbsCoor ().y, |
---|
| 392 | this->wingNodeRight.getAbsCoor ().z); |
---|
| 393 | tmpRot = this->wingNodeRight.getAbsDir().getSpacialAxis(); |
---|
| 394 | glRotatef (this->wingNodeRight.getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z ); |
---|
| 395 | glScalef(1,1,-1); |
---|
| 396 | this->getModel(3)->draw(); |
---|
| 397 | glPopMatrix (); |
---|
[6724] | 398 | |
---|
[6801] | 399 | glPushMatrix(); |
---|
| 400 | glTranslatef (this->rotorNodeRight.getAbsCoor ().x, |
---|
| 401 | this->rotorNodeRight.getAbsCoor ().y, |
---|
| 402 | this->rotorNodeRight.getAbsCoor ().z); |
---|
| 403 | tmpRot = this->rotorNodeRight.getAbsDir().getSpacialAxis(); |
---|
| 404 | glRotatef (this->rotorNodeRight.getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z ); |
---|
| 405 | glScalef(1,1,-1); |
---|
| 406 | this->getModel(4)->draw(); |
---|
[6806] | 407 | glTranslatef(0,-1,0); |
---|
| 408 | glRotatef(this->rotorCycle, 0,1,0); |
---|
| 409 | this->getModel(5)->draw(); |
---|
[10355] | 410 | |
---|
[6801] | 411 | glPopMatrix (); |
---|
[10355] | 412 | |
---|
| 413 | glPushMatrix(); |
---|
| 414 | glTranslatef (this->getAbsCoor ().x, |
---|
| 415 | this->getAbsCoor ().y-2.0, |
---|
| 416 | this->getAbsCoor ().z); |
---|
| 417 | |
---|
| 418 | /* glBegin(GL_QUADS); |
---|
| 419 | glColor4f(0.9,0.9,0.2,0.33); |
---|
| 420 | glNormal3f( 0.0f, 1.0f, 0.0f); // Normal Pointing Up |
---|
| 421 | glTexCoord2f(0.0f, 1.0f); glVertex3f(-10.0f, - 2.0f, -1.00f); // Point 1 (Top) |
---|
| 422 | glTexCoord2f(0.0f, 0.0f); glVertex3f(-10.0f, -2.0f, 10.0f); // Point 2 (Top) |
---|
| 423 | glTexCoord2f(1.0f, 0.0f); glVertex3f( 10.0f, -2.0f, 10.0f); // Point 3 (Top) |
---|
| 424 | glTexCoord2f(1.0f, 1.0f); glVertex3f( 10.0f, -2.0f, -10.0f); // Point 4 (Top) |
---|
| 425 | glEnd(); */ |
---|
| 426 | |
---|
| 427 | //this->getModel(0)->draw(); |
---|
| 428 | // glMatrixMode(GL_MODELVIEW); |
---|
| 429 | |
---|
| 430 | // Vector tmpRot = this->getAbsDir().getSpacialAxis(); |
---|
| 431 | // glRotatef (this->getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z ); |
---|
| 432 | |
---|
| 433 | Vector a = Vector(0.0,0.0,-10.0); |
---|
| 434 | |
---|
| 435 | |
---|
| 436 | // drawDebugCube( &a); |
---|
| 437 | // Experiment |
---|
| 438 | |
---|
| 439 | |
---|
| 440 | |
---|
| 441 | glPushAttrib( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_ENABLE_BIT | GL_POLYGON_BIT | GL_STENCIL_BUFFER_BIT ); |
---|
| 442 | glDepthMask(GL_FALSE); |
---|
| 443 | //glClear( GL_STENCIL_BUFFER_BIT); |
---|
| 444 | glDisable(GL_TEXTURE_2D); |
---|
| 445 | glActiveTextureARB(GL_TEXTURE0_ARB); |
---|
| 446 | glDisable(GL_TEXTURE_2D); |
---|
| 447 | // drawDebugCube( &a); |
---|
| 448 | |
---|
| 449 | |
---|
| 450 | //glEnable(GL_CULL_FACE); |
---|
| 451 | glEnable(GL_STENCIL_TEST); |
---|
| 452 | //glEnable(GL_POLYGON_OFFSET_FILL); |
---|
| 453 | //glPolygonOffset(0.0f, 100.0f); |
---|
| 454 | //drawDebugCube( &a); |
---|
| 455 | |
---|
| 456 | |
---|
| 457 | |
---|
| 458 | glDisable( GL_LIGHTING ); // Turn Off Lighting |
---|
| 459 | glDepthMask( GL_FALSE ); // Turn Off Writing To The Depth-Buffer |
---|
| 460 | //glDepthFunc( GL_LEQUAL ); |
---|
| 461 | glEnable( GL_STENCIL_TEST ); // Turn On Stencil Buffer Testing |
---|
| 462 | //glColorMask( GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE ); // Don't Draw Into The Colour Buffer |
---|
| 463 | //glStencilFunc( GL_ALWAYS, 1, 0xFFFFFFFFL ); |
---|
| 464 | |
---|
| 465 | |
---|
| 466 | glColorMask(0, 0, 0, 0); |
---|
| 467 | glStencilFunc(GL_ALWAYS, 1, 0xffffffff); |
---|
| 468 | |
---|
| 469 | // First Pass. Increase Stencil Value In The Shadow |
---|
| 470 | |
---|
| 471 | glFrontFace( GL_CCW ); |
---|
| 472 | glStencilOp( GL_KEEP, GL_KEEP, GL_INCR ); |
---|
| 473 | //doShadowPass( object, lightPosition ); |
---|
| 474 | //drawDebugCube(&(State::getCamera()->getAbsCoor() + State::getCamera()->getAbsDirV()*3.0f) ); |
---|
| 475 | drawDebugCube( &a); |
---|
| 476 | this->getModel(0)->draw(); |
---|
| 477 | //WorldEntity::draw(); |
---|
| 478 | |
---|
| 479 | // Second Pass. Decrease Stencil Value In The Shadow |
---|
| 480 | glFrontFace( GL_CW ); |
---|
| 481 | glStencilOp( GL_KEEP, GL_KEEP, GL_DECR ); |
---|
| 482 | //doShadowPass( object, lightPosition ); |
---|
| 483 | //drawDebugCube(&(State::getCamera()->getAbsCoor() ) ); |
---|
| 484 | drawDebugCube( &a); |
---|
| 485 | this->getModel(0)->draw(); |
---|
| 486 | //WorldEntity::draw(); |
---|
| 487 | |
---|
| 488 | glFrontFace( GL_CCW ); |
---|
| 489 | |
---|
| 490 | glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); |
---|
| 491 | glDepthMask(GL_TRUE); |
---|
| 492 | |
---|
| 493 | |
---|
| 494 | glColor4f( 0.0f, 0.9f, 0.0f, 0.4f ); |
---|
| 495 | glDisable(GL_POLYGON_OFFSET_FILL); |
---|
| 496 | glDisable(GL_DEPTH_TEST); |
---|
| 497 | glDisable(GL_CULL_FACE); |
---|
| 498 | //glEnable( GL_BLEND ); |
---|
| 499 | //glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ); |
---|
| 500 | //glStencilFunc( GL_NOTEQUAL, 0, 0xffffffff ); |
---|
| 501 | //glStencilOp( GL_KEEP, GL_KEEP, GL_KEEP ); |
---|
| 502 | ////glStencilOp(GL_REPLACE, GL_REPLACE, GL_REPLACE); |
---|
| 503 | |
---|
| 504 | glPushMatrix(); |
---|
| 505 | glLoadIdentity(); |
---|
| 506 | glBegin( GL_TRIANGLE_STRIP ); |
---|
| 507 | glVertex3f( -1.1f, 1.1f, -5.5f ); |
---|
| 508 | glVertex3f( -1.1f, -1.1f, -5.5f ); |
---|
| 509 | glVertex3f( 1.1f, 1.1f, -5.5f ); |
---|
| 510 | glVertex3f( 1.1f, -1.1f, -5.5f ); |
---|
| 511 | glEnd(); |
---|
| 512 | glPopMatrix (); |
---|
| 513 | |
---|
| 514 | /* |
---|
| 515 | glPushMatrix(); |
---|
| 516 | glLoadIdentity(); |
---|
| 517 | glMatrixMode(GL_PROJECTION); |
---|
| 518 | glPushMatrix(); |
---|
| 519 | glLoadIdentity(); |
---|
| 520 | glOrtho(0, 1, 1, 0, 0, 1); |
---|
| 521 | |
---|
| 522 | |
---|
| 523 | glColor4f(0.0f, 0.0f, 0.0f, 0.4f); |
---|
| 524 | glBegin(GL_QUADS); |
---|
| 525 | glVertex2i(0, 0); |
---|
| 526 | glVertex2i(0, 1); |
---|
| 527 | glVertex2i(1, 1); |
---|
| 528 | glVertex2i(1, 0); |
---|
| 529 | glEnd(); |
---|
| 530 | |
---|
| 531 | glEnable(GL_DEPTH_TEST); |
---|
| 532 | |
---|
| 533 | glPopMatrix(); |
---|
| 534 | glMatrixMode(GL_MODELVIEW); |
---|
| 535 | */ |
---|
| 536 | |
---|
| 537 | glPopAttrib(); |
---|
| 538 | glPopMatrix (); |
---|
[6443] | 539 | } |
---|
| 540 | |
---|
| 541 | /** |
---|
| 542 | * @todo switch statement ?? |
---|
| 543 | */ |
---|
[6799] | 544 | void Hover::process(const Event &event) |
---|
[6443] | 545 | { |
---|
[6804] | 546 | Playable::process(event); |
---|
[6443] | 547 | |
---|
[6637] | 548 | if( event.type == KeyMapper::PEV_LEFT) |
---|
[6805] | 549 | this->bLeft = event.bPressed; |
---|
[6637] | 550 | else if( event.type == KeyMapper::PEV_RIGHT) |
---|
[6805] | 551 | this->bRight = event.bPressed; |
---|
[6998] | 552 | else if( event.type == KeyMapper::PEV_UP) |
---|
[6443] | 553 | this->bAscend = event.bPressed; //this->shiftCoor(0,.1,0); |
---|
[6998] | 554 | else if( event.type == KeyMapper::PEV_DOWN) |
---|
[6443] | 555 | this->bDescend = event.bPressed; //this->shiftCoor(0,-.1,0); |
---|
[6997] | 556 | else if( event.type == KeyMapper::PEV_FORWARD) |
---|
[6805] | 557 | this->bForward = event.bPressed; //this->shiftCoor(0,.1,0); |
---|
[6997] | 558 | else if( event.type == KeyMapper::PEV_BACKWARD) |
---|
[6805] | 559 | this->bBackward = event.bPressed; //this->shiftCoor(0,-.1,0); |
---|
[6443] | 560 | else if( event.type == EV_MOUSE_MOTION) |
---|
| 561 | { |
---|
[6807] | 562 | float xMouse, yMouse; |
---|
| 563 | xMouse = event.xRel*mouseSensitivity; |
---|
| 564 | yMouse = event.yRel*mouseSensitivity; |
---|
[6443] | 565 | |
---|
[6805] | 566 | // rotate the Player around the y-axis |
---|
[6807] | 567 | this->rotation += xMouse; |
---|
[6799] | 568 | |
---|
[6807] | 569 | this->cameraLook += yMouse; |
---|
[6805] | 570 | // rotate the Camera around the z-axis |
---|
[6807] | 571 | if (cameraLook > M_PI_4) |
---|
| 572 | cameraLook = M_PI_4; |
---|
[6880] | 573 | else if (cameraLook < -M_PI_4) |
---|
| 574 | cameraLook = -M_PI_4; |
---|
| 575 | //this->cameraNode.setRelDirSoft(this->direction,10); |
---|
[6805] | 576 | } |
---|
[6443] | 577 | } |
---|
[10355] | 578 | |
---|
| 579 | void drawDebugCube(const Vector* cam) |
---|
| 580 | { |
---|
| 581 | glBegin(GL_QUADS); |
---|
| 582 | // Front Face |
---|
| 583 | glNormal3f( 0.0f, 0.0f, 1.0f); // Normal Pointing Towards Viewer |
---|
| 584 | glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -10.0f, 1.0f); // Point 1 (Front) |
---|
| 585 | glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -10.0f, 1.0f); // Point 2 (Front) |
---|
| 586 | glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, 10.0f, 1.0f); // Point 3 (Front) |
---|
| 587 | glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 10.0f, 1.0f); // Point 4 (Front) |
---|
| 588 | // Back Face |
---|
| 589 | glNormal3f( 0.0f, 0.0f,-1.0f); // Normal Pointing Away From Viewer |
---|
| 590 | glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -10.0f, -1.0f); // Point 1 (Back) |
---|
| 591 | glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f, 10.0f, -1.0f); // Point 2 (Back) |
---|
| 592 | glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f, 10.0f, -1.0f); // Point 3 (Back) |
---|
| 593 | glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -10.0f, -1.0f); // Point 4 (Back) |
---|
| 594 | // Top Face |
---|
| 595 | glNormal3f( 0.0f, 1.0f, 0.0f); // Normal Pointing Up |
---|
| 596 | glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 10.0f, -1.0f); // Point 1 (Top) |
---|
| 597 | glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, 10.0f, 1.0f); // Point 2 (Top) |
---|
| 598 | glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, 10.0f, 1.0f); // Point 3 (Top) |
---|
| 599 | glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, 10.0f, -1.0f); // Point 4 (Top) |
---|
| 600 | // Bottom Face |
---|
| 601 | glNormal3f( 0.0f,-1.0f, 0.0f); // Normal Pointing Down |
---|
| 602 | glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f, -10.0f, -1.0f); // Point 1 (Bottom) |
---|
| 603 | glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f, -10.0f, -1.0f); // Point 2 (Bottom) |
---|
| 604 | glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -10.0f, 1.0f); // Point 3 (Bottom) |
---|
| 605 | glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -10.0f, 1.0f); // Point 4 (Bottom) |
---|
| 606 | // Right face |
---|
| 607 | glNormal3f( 1.0f, 0.0f, 0.0f); // Normal Pointing Right |
---|
| 608 | glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -10.0f, -1.0f); // Point 1 (Right) |
---|
| 609 | glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, 10.0f, -1.0f); // Point 2 (Right) |
---|
| 610 | glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f, 10.0f, 1.0f); // Point 3 (Right) |
---|
| 611 | glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -10.0f, 1.0f); // Point 4 (Right) |
---|
| 612 | // Left Face |
---|
| 613 | glNormal3f(-1.0f, 0.0f, 0.0f); // Normal Pointing Left |
---|
| 614 | glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -10.0f, -1.0f); // Point 1 (Left) |
---|
| 615 | glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -10.0f, 1.0f); // Point 2 (Left) |
---|
| 616 | glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f, 10.0f, 1.0f); // Point 3 (Left) |
---|
| 617 | glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 10.0f, -1.0f); // Point 4 (Left) |
---|
| 618 | glEnd(); // Done Drawing Quads |
---|
| 619 | |
---|
| 620 | |
---|
| 621 | glBegin(GL_QUADS); |
---|
| 622 | |
---|
| 623 | return; |
---|
| 624 | // Bottom Face. Red, 75% opaque, magnified texture |
---|
| 625 | |
---|
| 626 | //glNormal3f( 0.0f, -1.0f, 0.0f); // Needed for lighting |
---|
| 627 | // glColor4f(0.9,0.2,0.2,.75); // Basic polygon color |
---|
| 628 | |
---|
| 629 | //glTexCoord2f(0.800f, 0.800f); |
---|
| 630 | glVertex3f(cam->x-5.0f, cam->y-100.0f,cam->z -5.0f); |
---|
| 631 | // glTexCoord2f(0.200f, 0.800f); |
---|
| 632 | glVertex3f(cam->x+5.0f, cam->y-100.0f,cam->z -5.0f); |
---|
| 633 | //glTexCoord2f(0.200f, 0.200f); |
---|
| 634 | glVertex3f(cam->x+ 5.0f,cam->y -100.0f,cam->z + 5.0f); |
---|
| 635 | //glTexCoord2f(0.800f, 0.200f); |
---|
| 636 | glVertex3f(cam->x-5.0f, cam->y-100.0f, cam->z + 5.0f); //OK |
---|
| 637 | |
---|
| 638 | |
---|
| 639 | // Top face; offset. White, 50% opaque. |
---|
| 640 | |
---|
| 641 | // glNormal3f( 0.0f, 5.0f, 0.0f); glColor4f(0.5,0.5,0.5,.5); |
---|
| 642 | |
---|
| 643 | //glTexCoord2f(0.005f, 5.995f); |
---|
| 644 | glVertex3f(cam->x-5.0f, cam->y+ 100.0f, cam->z -5.0f); |
---|
| 645 | //glTexCoord2f(0.005f, 0.005f); |
---|
| 646 | glVertex3f(cam->x-5.0f, cam->y+ 100.0f, cam->z +5.0f); |
---|
| 647 | //glTexCoord2f(5.995f, 0.005f); |
---|
| 648 | glVertex3f(cam->x+ 5.0f, cam->y+100.0f, cam->z +5.0f); |
---|
| 649 | //glTexCoord2f(5.995f, 5.995f); |
---|
| 650 | glVertex3f(cam->x+ 5.0f, cam->y+ 100.0f, cam->z -5.0f); //OKQUAD_STRI |
---|
| 651 | |
---|
| 652 | |
---|
| 653 | // Far face. Green, 50% opaque, non-uniform texture cooridinates. |
---|
| 654 | |
---|
| 655 | //glNormal3f( 0.0f, 0.0f,-5.0f); glColor4f(0.2,0.9,0.2,.5); |
---|
| 656 | |
---|
| 657 | // glTexCoord2f(0.995f, 0.005f); |
---|
| 658 | glVertex3f(cam->x-5.0f, cam->y-100.0f, cam->z -5.0f); |
---|
| 659 | // glTexCoord2f(2.995f, 2.995f); |
---|
| 660 | glVertex3f(cam->x-5.0f, cam->y+ 100.0f, cam->z -5.0f); |
---|
| 661 | // glTexCoord2f(0.005f, 0.995f); |
---|
| 662 | glVertex3f(cam->x+ 5.0f,cam->y+ 100.0f, cam->z -5.0f); |
---|
| 663 | //glTexCoord2f(0.005f, 0.005f); |
---|
| 664 | glVertex3f( cam->x+5.0f,cam->y -100.0f, cam->z -5.0f); |
---|
| 665 | |
---|
| 666 | |
---|
| 667 | // Right face. Blue; 25% opaque |
---|
| 668 | |
---|
| 669 | // glNormal3f( 5.0f, 0.0f, 0.0f); glColor4f(0.2,0.2,0.9,.25); |
---|
| 670 | |
---|
| 671 | // glTexCoord2f(0.995f, 0.005f); |
---|
| 672 | glVertex3f(cam->x+ 5.0f, cam->y -100.0f, cam->z -5.0f); |
---|
| 673 | // glTexCoord2f(0.995f, 0.995f); |
---|
| 674 | glVertex3f(cam->x+ 5.0f, cam->y+ 100.0f, cam->z -5.0f); |
---|
| 675 | // glTexCoord2f(0.005f, 0.995f); |
---|
| 676 | glVertex3f(cam->x+ 5.0f, cam->y+ 100.0f, cam->z + 5.0f); |
---|
| 677 | // glTexCoord2f(0.005f, 0.005f); |
---|
| 678 | glVertex3f(cam->x+ 5.0f, cam->y-100.0f, cam->z +5.0f); |
---|
| 679 | |
---|
| 680 | |
---|
| 681 | // Front face; offset. Multi-colored, 50% opaque. |
---|
| 682 | |
---|
| 683 | // glNormal3f( 0.0f, 0.0f, 5.0f); |
---|
| 684 | |
---|
| 685 | // glColor4f( 0.9f, 0.2f, 0.2f, 0.5f); |
---|
| 686 | // glTexCoord2f( 0.005f, 0.005f); |
---|
| 687 | glVertex3f(cam->x-5.0f, cam->y-100.0f, cam->z +5.0f); |
---|
| 688 | // glColor4f( 0.2f, 0.9f, 0.2f, 0.5f); |
---|
| 689 | // glTexCoord2f( 0.995f, 0.005f); |
---|
| 690 | glVertex3f(cam->x+ 5.0f, cam->y-100.0f, cam->z +5.0f); |
---|
| 691 | // glColor4f( 0.2f, 0.2f, 0.9f, 0.5f); |
---|
| 692 | // glTexCoord2f( 0.995f, 0.995f); |
---|
| 693 | glVertex3f( cam->x+5.0f, cam->y+100.0f, cam->z +5.0f); |
---|
| 694 | // glColor4f( 0.5f, 0.5f, 0.5f, 0.5f); |
---|
| 695 | // glTexCoord2f( 0.005f, 0.995f); g |
---|
| 696 | glVertex3f(cam->x-5.0f, cam->y+ 100.0f, cam->z +5.0f); |
---|
| 697 | |
---|
| 698 | |
---|
| 699 | // Left Face; offset. Yellow, varying levels of opaque. |
---|
| 700 | |
---|
| 701 | // glNormal3f(-5.0f, 0.0f, 0.0f); |
---|
| 702 | |
---|
| 703 | // glColor4f(0.9,0.9,0.2,0.0); |
---|
| 704 | // glTexCoord2f(0.005f, 0.005f); |
---|
| 705 | glVertex3f(cam->x-5.0f, cam->y-100.0f, cam->z -5.0f); |
---|
| 706 | //glColor4f(0.9,0.9,0.2,0.66); |
---|
| 707 | // glTexCoord2f(0.995f, 0.005f); |
---|
| 708 | glVertex3f(cam->x-5.0f,cam->y -100.0f, cam->z +5.0f); |
---|
| 709 | // glColor4f(0.9,0.9,0.2,5.0); |
---|
| 710 | // glTexCoord2f(0.995f, 0.995f); |
---|
| 711 | glVertex3f(cam->x-5.0f, cam->y+ 100.0f, cam->z +5.0f); |
---|
| 712 | // glColor4f(0.9,0.9,0.2,0.33); |
---|
| 713 | // glTexCoord2f(0.005f, 0.995f); |
---|
| 714 | glVertex3f(cam->x-5.0f, cam->y+ 100.0f, cam->z -5.0f); |
---|
| 715 | |
---|
| 716 | glEnd(); |
---|
| 717 | } |
---|