[9971] | 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 "playership.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 "util/loading/load_param.h" |
---|
| 28 | #include "key_mapper.h" |
---|
| 29 | #include "state.h" |
---|
| 30 | |
---|
| 31 | #include "graphics_engine.h" |
---|
| 32 | #include "particles/dot_emitter.h" |
---|
| 33 | #include "particles/sprite_particles.h" |
---|
| 34 | |
---|
| 35 | #include "debug.h" |
---|
| 36 | |
---|
| 37 | #include "script_class.h" |
---|
| 38 | |
---|
| 39 | |
---|
| 40 | #include "class_id_DEPRECATED.h" |
---|
| 41 | ObjectListDefinitionID(PlayerShip, CL_PlayerShip); |
---|
| 42 | CREATE_FACTORY(PlayerShip); |
---|
| 43 | |
---|
| 44 | CREATE_SCRIPTABLE_CLASS(PlayerShip, |
---|
| 45 | addMethod("hasPlayer", Executor0ret<Playable, lua_State*,bool>(&Playable::hasPlayer)) |
---|
| 46 | //Coordinates |
---|
| 47 | ->addMethod("setAbsCoor", Executor3<PNode, lua_State*,float,float,float>(&PNode::setAbsCoor)) |
---|
| 48 | ->addMethod("getAbsCoorX", Executor0ret<PNode, lua_State*, float>(&PNode::getAbsCoorX)) |
---|
| 49 | ->addMethod("getAbsCoorY", Executor0ret<PNode, lua_State*, float>(&PNode::getAbsCoorY)) |
---|
| 50 | ->addMethod("getAbsCoorZ", Executor0ret<PNode, lua_State*, float>(&PNode::getAbsCoorZ)) |
---|
| 51 | ->addMethod("setAirFriction", Executor1<PlayerShip, lua_State*, float>(&PlayerShip::setAirFriction)) |
---|
| 52 | ); |
---|
| 53 | |
---|
| 54 | |
---|
| 55 | |
---|
| 56 | /** |
---|
| 57 | * @brief loads a PlayerShip information from a specified file. |
---|
| 58 | * @param fileName the name of the File to load the spacecraft_2d from (absolute path) |
---|
| 59 | */ |
---|
| 60 | PlayerShip::PlayerShip(const std::string& fileName) |
---|
| 61 | { |
---|
| 62 | this->init(); |
---|
| 63 | TiXmlDocument doc(fileName); |
---|
| 64 | |
---|
| 65 | if(!doc.LoadFile()) |
---|
| 66 | { |
---|
| 67 | PRINTF(2)("Loading file %s failed for PlayerShip.\n", fileName.c_str()); |
---|
| 68 | return; |
---|
| 69 | } |
---|
| 70 | |
---|
| 71 | this->loadParams(doc.RootElement()); |
---|
| 72 | } |
---|
| 73 | |
---|
| 74 | /** |
---|
| 75 | * @brief creates a new PlayerShip from Xml Data |
---|
| 76 | * @param root the xml element containing spaceship data |
---|
| 77 | |
---|
| 78 | @todo add more parameters to load |
---|
| 79 | */ |
---|
| 80 | PlayerShip::PlayerShip(const TiXmlElement* root) |
---|
| 81 | { |
---|
| 82 | this->init(); |
---|
| 83 | if (root != NULL) |
---|
| 84 | this->loadParams(root); |
---|
| 85 | |
---|
| 86 | |
---|
| 87 | |
---|
| 88 | //weapons: |
---|
| 89 | Weapon* wpRight = dynamic_cast<Weapon*>(Factory::fabricate("LaserCannon")); |
---|
| 90 | wpRight->setName("Cannon_Right"); |
---|
| 91 | Weapon* wpLeft = dynamic_cast<Weapon*>(Factory::fabricate("LaserCannon")); |
---|
| 92 | wpLeft->setName("Cannon_Left"); |
---|
| 93 | |
---|
| 94 | Weapon* turretLeft = dynamic_cast<Weapon*>(Factory::fabricate("BoomerangGun")); |
---|
| 95 | wpRight->setName("Turret_Left"); |
---|
| 96 | Weapon* turretRight = dynamic_cast<Weapon*>(Factory::fabricate("BoomerangGun")); |
---|
| 97 | wpLeft->setName("Turret_Right"); |
---|
| 98 | |
---|
| 99 | // cannon->setName("BFG"); |
---|
| 100 | |
---|
| 101 | this->addWeapon(wpLeft, 1, 0); |
---|
| 102 | this->addWeapon(wpRight,1 ,1); |
---|
| 103 | this->addWeapon(turretLeft, 1, 2); |
---|
| 104 | this->addWeapon(turretRight, 1, 3); |
---|
| 105 | |
---|
| 106 | //this->addWeapon(cannon, 0, 2); |
---|
| 107 | |
---|
| 108 | this->getWeaponManager().changeWeaponConfig(1); |
---|
| 109 | dynamic_cast<Element2D*>(this->getWeaponManager().getFixedTarget())->setVisibility( false); |
---|
| 110 | } |
---|
| 111 | |
---|
| 112 | |
---|
| 113 | /** |
---|
| 114 | * @brief destructs the ship, deletes alocated memory |
---|
| 115 | */ |
---|
| 116 | PlayerShip::~PlayerShip () |
---|
| 117 | { |
---|
| 118 | this->setPlayer(NULL); |
---|
| 119 | delete this->toTravelHeight; |
---|
| 120 | } |
---|
| 121 | |
---|
| 122 | |
---|
| 123 | /** |
---|
| 124 | * @brief initializes a PlayerShip |
---|
| 125 | */ |
---|
| 126 | void PlayerShip::init() |
---|
| 127 | { |
---|
| 128 | // this->setRelDir(Quaternion(M_PI, Vector(1,0,0))); |
---|
| 129 | this->registerObject(this, PlayerShip::_objectList); |
---|
| 130 | |
---|
| 131 | this->setSupportedPlaymodes(Playable::Full3D | Playable::Horizontal ); |
---|
| 132 | |
---|
| 133 | bForward = bBackward = bLeft = bRight = false; |
---|
| 134 | mouseSensitivity = 0.005; |
---|
| 135 | |
---|
| 136 | this->cameraLook = 0.0f; |
---|
| 137 | this->rotation = 0.0f; |
---|
| 138 | this->acceleration = 20.0f; |
---|
| 139 | this->airFriction = 0.0f; |
---|
| 140 | |
---|
| 141 | |
---|
| 142 | this->setHealthMax(1000); |
---|
| 143 | this->setHealth(1000); |
---|
| 144 | this->setDamage(100.0f); |
---|
| 145 | |
---|
| 146 | |
---|
| 147 | |
---|
| 148 | /// 2D-MODE |
---|
| 149 | this->toTravelHeight = NULL; |
---|
| 150 | this->travelSpeed = 0.0f; |
---|
| 151 | this->travelNode = new PNode(); |
---|
| 152 | |
---|
| 153 | this->loadModel("models/ships/mantawing.obj", 5.0f); |
---|
| 154 | |
---|
| 155 | // camera - issue |
---|
| 156 | this->cameraNode.addNodeFlags(PNODE_PROHIBIT_DELETE_WITH_PARENT); |
---|
| 157 | this->cameraNode.addNodeFlags(PNODE_PROHIBIT_CHILD_DELETE); |
---|
| 158 | //this->cameraNode.setParentMode(PNODE_ROTATE_MOVEMENT); |
---|
| 159 | //this->cameraNode.setParent(this); |
---|
| 160 | |
---|
| 161 | // PARTICLES |
---|
| 162 | this->burstEmitter = new DotEmitter(200, 5.0, .01); |
---|
| 163 | this->burstEmitter->setParent(this); |
---|
| 164 | this->burstEmitter->setRelCoor(0, -0.7, 0); |
---|
| 165 | this->burstEmitter->setRelDir(Quaternion(-M_PI, Vector(0,0,1))); |
---|
| 166 | this->burstEmitter->setName("PlayerShip_Burst_emitter_Left"); |
---|
| 167 | |
---|
| 168 | this->burstSystem = new SpriteParticles(1000); |
---|
| 169 | this->burstSystem->addEmitter(this->burstEmitter); |
---|
| 170 | this->burstSystem->setName("SpaceShip_Burst_System"); |
---|
| 171 | ((SpriteParticles*)this->burstSystem)->setMaterialTexture("maps/radial-trans-noise.png"); |
---|
| 172 | this->burstSystem->setLifeSpan(1.0, .3); |
---|
| 173 | this->burstSystem->setRadius(0.0, 1.5); |
---|
| 174 | this->burstSystem->setRadius(0.05, 1.8); |
---|
| 175 | this->burstSystem->setRadius(.5, .8); |
---|
| 176 | this->burstSystem->setRadius(1.0, 0); |
---|
| 177 | this->burstSystem->setColor(0.0, .7,.7,1,.5); |
---|
| 178 | this->burstSystem->setColor(0.2, 0,0,0.8,.5); |
---|
| 179 | this->burstSystem->setColor(0.5, .5,.5,.8,.3); |
---|
| 180 | this->burstSystem->setColor(1.0, .8,.8,.8,.0); |
---|
| 181 | |
---|
| 182 | |
---|
| 183 | //add events to the eventlist of the Playable |
---|
| 184 | this->registerEvent(KeyMapper::PEV_FORWARD); |
---|
| 185 | this->registerEvent(KeyMapper::PEV_BACKWARD); |
---|
| 186 | this->registerEvent(KeyMapper::PEV_LEFT); |
---|
| 187 | this->registerEvent(KeyMapper::PEV_RIGHT); |
---|
| 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(1.843, -0.335, 2.029) * 5.0); |
---|
| 199 | this->getWeaponManager().setSlotCapability(0, WTYPE_ALLDIRS | WTYPE_DIRECTIONAL); |
---|
| 200 | |
---|
| 201 | this->getWeaponManager().setSlotPosition(1, Vector(1.843, -0.335, -2.029) * 5.0); |
---|
| 202 | this->getWeaponManager().setSlotCapability(1, WTYPE_ALLDIRS | WTYPE_DIRECTIONAL); |
---|
| 203 | |
---|
| 204 | /// TODO: THESE ARE TOO MUCH |
---|
| 205 | this->getWeaponManager().setSlotPosition(2, Vector(-0.351, -.238, 1.406) * 5.0); |
---|
| 206 | this->getWeaponManager().setSlotDirection(2, Quaternion(-1.7, Vector(0,1,0))); |
---|
| 207 | |
---|
| 208 | this->getWeaponManager().setSlotPosition(3, Vector(-0.351, -.238, -1.406) * 5.0); |
---|
| 209 | this->getWeaponManager().setSlotDirection(3, Quaternion(1.7, Vector(0,1,0))); |
---|
| 210 | |
---|
| 211 | this->cameraNode.setRelCoor(1,5,0); |
---|
| 212 | this->getWeaponManager().getFixedTarget()->setParent(&this->cameraNode); |
---|
| 213 | this->getWeaponManager().getFixedTarget()->setRelCoor(1000,0,0); |
---|
| 214 | |
---|
| 215 | registerVar( new SynchronizeableBool( &bForward, &bForward, "bForward", PERMISSION_OWNER ) ); |
---|
| 216 | registerVar( new SynchronizeableBool( &bBackward, &bBackward, "bBackward", PERMISSION_OWNER ) ); |
---|
| 217 | registerVar( new SynchronizeableBool( &bLeft, &bLeft, "bLeft", PERMISSION_OWNER ) ); |
---|
| 218 | registerVar( new SynchronizeableBool( &bRight, &bRight, "bRight", PERMISSION_OWNER ) ); |
---|
| 219 | //registerVar( new SynchronizeableQuaternion( &direction, &direction, "direction", PERMISSION_OWNER ) ); |
---|
| 220 | registerVar( new SynchronizeableFloat( &cameraLook, &cameraLook, "cameraLook", PERMISSION_OWNER ) ); |
---|
| 221 | registerVar( new SynchronizeableFloat( &rotation, &rotation, "rotation", PERMISSION_OWNER ) ); |
---|
| 222 | |
---|
| 223 | |
---|
| 224 | |
---|
| 225 | } |
---|
| 226 | |
---|
| 227 | /** |
---|
| 228 | * @brief loads the Settings of a PlayerShip from an XML-element. |
---|
| 229 | * @param root the XML-element to load the Spaceship's properties from |
---|
| 230 | */ |
---|
| 231 | void PlayerShip::loadParams(const TiXmlElement* root) |
---|
| 232 | { |
---|
| 233 | Playable::loadParams(root); |
---|
| 234 | |
---|
| 235 | LoadParam(root, "travel-speed", this, PlayerShip, setTravelSpeed); |
---|
| 236 | LoadParam(root, "travel-height", this, PlayerShip, setTravelHeight); |
---|
| 237 | LoadParam(root, "travel-distance", this, PlayerShip, setTravelDistance); |
---|
| 238 | } |
---|
| 239 | |
---|
| 240 | void PlayerShip::setPlayDirection(const Quaternion& rot, float speed) |
---|
| 241 | { |
---|
| 242 | this->direction = Quaternion (rot.getHeading(), Vector(0,1,0)); |
---|
| 243 | } |
---|
| 244 | |
---|
| 245 | void PlayerShip::setTravelSpeed(float travelSpeed) |
---|
| 246 | { |
---|
| 247 | this->travelSpeed = travelSpeed; |
---|
| 248 | } |
---|
| 249 | |
---|
| 250 | |
---|
| 251 | void PlayerShip::setTravelHeight(float travelHeight) |
---|
| 252 | { |
---|
| 253 | if (this->toTravelHeight == NULL) |
---|
| 254 | this->toTravelHeight = new float; |
---|
| 255 | *this->toTravelHeight = travelHeight; |
---|
| 256 | } |
---|
| 257 | |
---|
| 258 | |
---|
| 259 | void PlayerShip::setTravelDistance(const Vector2D& distance) |
---|
| 260 | { |
---|
| 261 | this->travelDistance = distance; |
---|
| 262 | } |
---|
| 263 | |
---|
| 264 | void PlayerShip::setTravelDistance(float x, float y) |
---|
| 265 | { |
---|
| 266 | this->setTravelDistance(Vector2D(x, y)); |
---|
| 267 | } |
---|
| 268 | |
---|
| 269 | |
---|
| 270 | |
---|
| 271 | void PlayerShip::enter() |
---|
| 272 | { |
---|
| 273 | dynamic_cast<Element2D*>(this->getWeaponManager().getFixedTarget())->setVisibility( true); |
---|
| 274 | // this->setPlaymode(this->getPlaymode()); |
---|
| 275 | this->setPlaymode(Playable::Horizontal); |
---|
| 276 | this->setTravelSpeed(10.0f); |
---|
| 277 | } |
---|
| 278 | |
---|
| 279 | void PlayerShip::leave() |
---|
| 280 | { |
---|
| 281 | dynamic_cast<Element2D*>(this->getWeaponManager().getFixedTarget())->setVisibility( false); |
---|
| 282 | this->detachCamera(); |
---|
| 283 | |
---|
| 284 | } |
---|
| 285 | |
---|
| 286 | |
---|
| 287 | void PlayerShip::enterPlaymode(Playable::Playmode playmode) |
---|
| 288 | { |
---|
| 289 | switch(playmode) |
---|
| 290 | { |
---|
| 291 | case Playable::Full3D: |
---|
| 292 | if (State::getCameraNode != NULL) |
---|
| 293 | { |
---|
| 294 | Vector absCoor = this->getAbsCoor(); |
---|
| 295 | this->setParent(PNode::getNullParent()); |
---|
| 296 | this->setAbsCoor(absCoor); |
---|
| 297 | State::getCameraNode()->setParentSoft(&this->cameraNode); |
---|
| 298 | State::getCameraNode()->setRelCoorSoft(-10, 0,0); |
---|
| 299 | State::getCameraTargetNode()->setParentSoft(&this->cameraNode); |
---|
| 300 | State::getCameraTargetNode()->setRelCoorSoft(100, 0,0); |
---|
| 301 | |
---|
| 302 | } |
---|
| 303 | break; |
---|
| 304 | |
---|
| 305 | |
---|
| 306 | case Playable::Horizontal: |
---|
| 307 | if (State::getCameraNode != NULL) |
---|
| 308 | { |
---|
| 309 | this->debugNode(1); |
---|
| 310 | this->travelNode->debugNode(1); |
---|
| 311 | |
---|
| 312 | this->travelNode->setAbsCoor(this->getAbsCoor()); |
---|
| 313 | this->travelNode->updateNode(0.01f); |
---|
| 314 | |
---|
| 315 | this->setParent(this->travelNode); |
---|
| 316 | this->setRelCoor(0,0,0); |
---|
| 317 | |
---|
| 318 | State::getCameraNode()->setParentSoft(this->travelNode); |
---|
| 319 | State::getCameraNode()->setRelCoorSoft(-3, 100,0); |
---|
| 320 | State::getCameraTargetNode()->setParentSoft(this->travelNode); |
---|
| 321 | State::getCameraTargetNode()->setRelCoorSoft(5,0,1); |
---|
| 322 | |
---|
| 323 | |
---|
| 324 | this->debugNode(1); |
---|
| 325 | this->travelNode->debugNode(1); |
---|
| 326 | } |
---|
| 327 | break; |
---|
| 328 | |
---|
| 329 | default: |
---|
| 330 | PRINTF(2)("Playmode %s Not Implemented in %s\n", Playable::playmodeToString(this->getPlaymode()).c_str(), this->getClassCName()); |
---|
| 331 | } |
---|
| 332 | } |
---|
| 333 | |
---|
| 334 | |
---|
| 335 | |
---|
| 336 | /** |
---|
| 337 | * @brief effect that occurs after the PlayerShip is spawned |
---|
| 338 | */ |
---|
| 339 | void PlayerShip::postSpawn () |
---|
| 340 | { |
---|
| 341 | //setCollision(new CollisionCluster(1.0, Vector(0,0,0))); |
---|
| 342 | } |
---|
| 343 | |
---|
| 344 | /** |
---|
| 345 | * @brief the action occuring if the spacecraft_2d left the game |
---|
| 346 | */ |
---|
| 347 | void PlayerShip::leftWorld () |
---|
| 348 | {} |
---|
| 349 | |
---|
| 350 | /** |
---|
| 351 | * @brief this function is called, when two entities collide |
---|
| 352 | * @param entity: the world entity with whom it collides |
---|
| 353 | * |
---|
| 354 | * Implement behaviour like damage application or other miscellaneous collision stuff in this function |
---|
| 355 | */ |
---|
| 356 | void PlayerShip::collidesWith(WorldEntity* entity, const Vector& location) |
---|
| 357 | { |
---|
| 358 | Playable::collidesWith(entity, location); |
---|
| 359 | } |
---|
| 360 | |
---|
| 361 | |
---|
| 362 | |
---|
| 363 | /** |
---|
| 364 | * @brief the function called for each passing timeSnap |
---|
| 365 | * @param time The timespan passed since last update |
---|
| 366 | */ |
---|
| 367 | void PlayerShip::tick (float dt) |
---|
| 368 | { |
---|
| 369 | // this->debugNode(1); |
---|
| 370 | Playable::tick(dt); |
---|
| 371 | |
---|
| 372 | // spaceship controlled movement |
---|
| 373 | this->movement(dt); |
---|
| 374 | |
---|
| 375 | // TRYING TO FIX PNode. |
---|
| 376 | this->cameraNode.setAbsCoorSoft(this->getAbsCoor() + Vector(0.0f, 5.0f, 0.0f), 30.0f); |
---|
| 377 | this->cameraNode.setRelDirSoft(this->getAbsDir(), 30.0f); |
---|
| 378 | } |
---|
| 379 | |
---|
| 380 | /** |
---|
| 381 | * @brief calculate the velocity |
---|
| 382 | * @param time the timeslice since the last frame |
---|
| 383 | */ |
---|
| 384 | void PlayerShip::movement (float dt) |
---|
| 385 | { |
---|
| 386 | Vector accel(0.0, 0.0, 0.0); |
---|
| 387 | |
---|
| 388 | if( this->bForward ) |
---|
| 389 | { |
---|
| 390 | accel += Vector(this->acceleration, 0, 0); |
---|
| 391 | } |
---|
| 392 | |
---|
| 393 | if( this->bBackward ) |
---|
| 394 | { |
---|
| 395 | accel -= Vector(this->acceleration, 0, 0); |
---|
| 396 | } |
---|
| 397 | if( this->bLeft) |
---|
| 398 | { |
---|
| 399 | accel -= Vector(0, 0, this->acceleration); |
---|
| 400 | } |
---|
| 401 | |
---|
| 402 | if( this->bRight) |
---|
| 403 | { |
---|
| 404 | accel += Vector(0, 0, this->acceleration); |
---|
| 405 | } |
---|
| 406 | |
---|
| 407 | switch(this->getPlaymode()) |
---|
| 408 | { |
---|
| 409 | case Playable::Full3D: |
---|
| 410 | { |
---|
| 411 | Vector accelerationDir = this->getAbsDir().apply(accel * this->acceleration); |
---|
| 412 | |
---|
| 413 | // this is the air friction (necessary for a smooth control) |
---|
| 414 | Vector damping = (this->velocity * this->airFriction); |
---|
| 415 | |
---|
| 416 | |
---|
| 417 | this->velocity += (accelerationDir - damping)* dt; |
---|
| 418 | this->shiftCoor (this->velocity * dt); |
---|
| 419 | |
---|
| 420 | // limit the maximum rotation speed. |
---|
| 421 | if (this->rotation != 0.0f) |
---|
| 422 | { |
---|
| 423 | float maxRot = 10.0 * dt; |
---|
| 424 | if (unlikely(this->rotation > maxRot)) this->rotation = maxRot; |
---|
| 425 | if (unlikely(this->rotation < -maxRot)) this->rotation = -maxRot; |
---|
| 426 | this->direction *= Quaternion(-M_PI/4.0*this->rotation, Vector(0,1,0)); |
---|
| 427 | |
---|
| 428 | this->rotation = 0.0f; |
---|
| 429 | } |
---|
| 430 | |
---|
| 431 | this->setRelDirSoft(this->direction * Quaternion(-cameraLook, Vector(0,0,1)), 5); |
---|
| 432 | } |
---|
| 433 | break; |
---|
| 434 | |
---|
| 435 | case Playable::Horizontal: |
---|
| 436 | { |
---|
| 437 | |
---|
| 438 | if (this->toTravelHeight != NULL) |
---|
| 439 | { |
---|
| 440 | this->travelNode->shiftCoor(Vector(0, (*toTravelHeight - this->travelNode->getAbsCoor().y) * dt * 10.0, 0)); |
---|
| 441 | if (fabsf(this->travelNode->getAbsCoor().y - *this->toTravelHeight) < .1) |
---|
| 442 | { |
---|
| 443 | delete this->toTravelHeight; |
---|
| 444 | this->toTravelHeight = NULL; |
---|
| 445 | } |
---|
| 446 | } |
---|
| 447 | this->travelNode->shiftCoor(Vector(this->travelSpeed * dt, 0, 0)); |
---|
| 448 | |
---|
| 449 | accel.y = 0.0; |
---|
| 450 | |
---|
| 451 | Vector accelerationDir = this->getAbsDir().apply(accel * this->acceleration); |
---|
| 452 | accelerationDir.y = 0.0; |
---|
| 453 | |
---|
| 454 | // this is the air friction (necessary for a smooth control) |
---|
| 455 | Vector damping = (this->velocity * this->airFriction); |
---|
| 456 | |
---|
| 457 | |
---|
| 458 | this->velocity += (accelerationDir - damping)* dt; |
---|
| 459 | |
---|
| 460 | if (this->getRelCoor().z > this->travelDistance.y && velocity.z > 0.0) |
---|
| 461 | this->velocity.z = 0.0f; |
---|
| 462 | if (this->getRelCoor().z < -this->travelDistance.y && velocity.z < 0.0) |
---|
| 463 | this->velocity.z = 0.0f; |
---|
| 464 | |
---|
| 465 | if (this->getRelCoor().x > this->travelDistance.x && velocity.x > 0.0) |
---|
| 466 | this->velocity.x = 0.0f; |
---|
| 467 | if (this->getRelCoor().x < -this->travelDistance.x && velocity.x < 0.0) |
---|
| 468 | this->velocity.x = 0.0f; |
---|
| 469 | |
---|
| 470 | |
---|
| 471 | this->shiftCoor (this->velocity * dt); |
---|
| 472 | if (accel.z == 0) |
---|
| 473 | this->setRelDirSoft(Quaternion(0, Vector(0,0,0)), 5.0f); |
---|
| 474 | else |
---|
| 475 | this->setRelDirSoft(Quaternion(this->velocity.z * .004, Vector(1,0,0)), 4.5f); |
---|
| 476 | } |
---|
| 477 | break; |
---|
| 478 | |
---|
| 479 | default: |
---|
| 480 | PRINTF(2)("Playmode %s Not Implemented in %s\n", Playable::playmodeToString(this->getPlaymode()).c_str(), this->getClassCName()); |
---|
| 481 | } |
---|
| 482 | } |
---|
| 483 | |
---|
| 484 | |
---|
| 485 | void PlayerShip::draw() const |
---|
| 486 | { |
---|
| 487 | WorldEntity::draw(); |
---|
| 488 | } |
---|
| 489 | |
---|
| 490 | /** |
---|
| 491 | * @todo switch statement ?? |
---|
| 492 | */ |
---|
| 493 | void PlayerShip::process(const Event &event) |
---|
| 494 | { |
---|
| 495 | Playable::process(event); |
---|
| 496 | |
---|
| 497 | if( event.type == KeyMapper::PEV_LEFT) |
---|
| 498 | this->bLeft = event.bPressed; |
---|
| 499 | else if( event.type == KeyMapper::PEV_RIGHT) |
---|
| 500 | this->bRight = event.bPressed; |
---|
| 501 | else if( event.type == KeyMapper::PEV_FORWARD) |
---|
| 502 | this->bForward = event.bPressed; //this->shiftCoor(0,.1,0); |
---|
| 503 | else if( event.type == KeyMapper::PEV_BACKWARD) |
---|
| 504 | {this->bBackward = event.bPressed; printf(" %f, %f, %f \n",getAbsCoorX(),getAbsCoorY(),getAbsCoorZ());} //this->shiftCoor(0,-.1,0); |
---|
| 505 | else if( event.type == EV_MOUSE_MOTION) |
---|
| 506 | { |
---|
| 507 | |
---|
| 508 | |
---|
| 509 | |
---|
| 510 | if (this->getPlaymode() == Playable::Full3D) |
---|
| 511 | { |
---|
| 512 | float xMouse, yMouse; |
---|
| 513 | xMouse = event.xRel*mouseSensitivity; |
---|
| 514 | yMouse = event.yRel*mouseSensitivity; |
---|
| 515 | |
---|
| 516 | // rotate the Player around the y-axis |
---|
| 517 | this->rotation += xMouse; |
---|
| 518 | |
---|
| 519 | this->cameraLook += yMouse; |
---|
| 520 | // rotate the Camera around the z-axis |
---|
| 521 | if (cameraLook > M_PI_4) |
---|
| 522 | cameraLook = M_PI_4; |
---|
| 523 | else if (cameraLook < -M_PI_4) |
---|
| 524 | cameraLook = -M_PI_4; |
---|
| 525 | } |
---|
| 526 | } |
---|
| 527 | } |
---|