- Timestamp:
- Dec 5, 2006, 7:14:05 PM (18 years ago)
- Location:
- branches/playability/src
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/playability/src/util/state.h
r9971 r10017 109 109 static inline int getMenuID() { return State::menuID;} 110 110 111 //////////////////////// 112 /// Scroller-Control /// 113 //////////////////////// 114 /** sets the scroller-travelnode (center of the screen) */ 115 static void setTravelNode(PNode* travelNode) {State::travelNode = travelNode;} 116 /** @returns the scroller-travelnode (center of the screen) */ 117 static PNode* getTravelNode() { return State::travelNode; } 118 111 119 112 120 private: … … 122 130 static GameRules* gameRules; //!< A reference to the GameRules 123 131 static Player* player; //!< A reference to the Player 132 static PNode* travelNode; //!< A reference to the scroller-travelnode 124 133 125 134 static SkyBox* skyBox; //!< The SkyBox used in the current world. -
branches/playability/src/world_entities/player.h
r9975 r10017 1 /*!1 /*! 2 2 * @file player.h 3 3 * Implements a basic playable WorldEntity -
branches/playability/src/world_entities/space_ships/space_ship.cc
r10016 r10017 74 74 ->addMethod("getAbsCoorY", Executor0ret<PNode, lua_State*, float>(&PNode::getAbsCoorY)) 75 75 ->addMethod("getAbsCoorZ", Executor0ret<PNode, lua_State*, float>(&PNode::getAbsCoorZ)) 76 //->addMethod("setCameraSpeed", Executor1<SpaceShip, lua_State*, float>(&SpaceShip::setCameraSpeed)) 76 77 ); 77 78 … … 90 91 SpaceShip::SpaceShip(const std::string& fileName) 91 92 : secWeaponMan(this), 92 supportedPlaymodes(Playable:: Full3D || Playable::Horizontal || Playable::Vertical),93 playmode(Playable:: Full3D)93 supportedPlaymodes(Playable::Vertical) , 94 playmode(Playable::Vertical) 94 95 { 95 96 this->init(); … … 113 114 SpaceShip::SpaceShip(const TiXmlElement* root) 114 115 : secWeaponMan(this), 115 supportedPlaymodes(Playable:: Full3D || Playable::Horizontal || Playable::Vertical),116 playmode(Playable:: Full3D)116 supportedPlaymodes(Playable::Vertical) , 117 playmode(Playable::Vertical) 117 118 { 118 119 this->init(); … … 205 206 206 207 this->loadModel("models/ships/mantawing.obj"); 207 208 bUp = bDown = bLeft = bRight = bAscend = bDescend = bRollL = bRollR = bFire = bSecFire = false; 209 208 //this->setVisibiliy(false); 209 210 bForward = bBackward = bLeft = bRight = bAscend = bDescend = bRollL = bRollR = bFire = bSecFire = false; 211 212 /* 210 213 xMouse = yMouse = 0; 211 214 yInvert = 1; … … 215 218 controlVelocityY = 150; 216 219 shipInertia = 1.5; 220 */ 217 221 // cycle = 0.0; 218 222 … … 220 224 this->setHealth(shieldCur); 221 225 222 travelSpeed = 0.0; 223 acceleration = 3; 226 this->travelNode = new PNode(); 227 228 // camera - issue 229 //this->cameraNode = State::getCameraNode(); 230 this->cameraNode.addNodeFlags(PNODE_PROHIBIT_DELETE_WITH_PARENT); 231 this->cameraNode.addNodeFlags(PNODE_PROHIBIT_CHILD_DELETE); 232 233 this->travelSpeed = 0.0; 234 this->cameraLook = 0.0f; 235 this->acceleration = 20.0f; 236 //this->airFriction = 0.0f; 237 this->cameraSpeed = 0.0; 238 /* 224 239 this->velocity = this->getAbsDirX()*travelSpeed; 225 240 this->mouseDir = this->getAbsDir(); 226 241 this->pitchDir = this->getAbsDir(); 242 */ 227 243 228 244 … … 329 345 this->burstSystem->setColor(1.0, .8,.8,.8,.0); 330 346 331 registerVar( new SynchronizeableVector( &velocity, &velocity, "velocity", PERMISSION_MASTER_SERVER ) );347 /* 332 348 registerVar( new SynchronizeableQuaternion( &mouseDir, &mouseDir, "mousedir", PERMISSION_OWNER ) ); 333 334 349 registerVar( new SynchronizeableBool( &bUp, &bUp, "bUp", PERMISSION_OWNER ) ); 335 350 registerVar( new SynchronizeableBool( &bDown, &bDown, "bDown", PERMISSION_OWNER ) ); … … 340 355 registerVar( new SynchronizeableBool( &bRollL, &bRollL, "bRollL", PERMISSION_OWNER ) ); 341 356 registerVar( new SynchronizeableBool( &bRollR, &bRollR, "bRollR", PERMISSION_OWNER ) ); 357 */ 358 359 registerVar( new SynchronizeableBool( &bForward, &bForward, "bForward", PERMISSION_OWNER ) ); 360 registerVar( new SynchronizeableBool( &bBackward, &bBackward, "bBackward", PERMISSION_OWNER ) ); 361 registerVar( new SynchronizeableBool( &bLeft, &bLeft, "bLeft", PERMISSION_OWNER ) ); 362 registerVar( new SynchronizeableBool( &bRight, &bRight, "bRight", PERMISSION_OWNER ) ); 363 registerVar( new SynchronizeableFloat( &cameraLook, &cameraLook, "cameraLook", PERMISSION_OWNER ) ); 364 registerVar( new SynchronizeableFloat( &rotation, &rotation, "rotation", PERMISSION_OWNER ) ); 365 366 registerVar( new SynchronizeableVector( &velocity, &velocity, "velocity", PERMISSION_MASTER_SERVER ) ); 367 368 this->enterPlaymode(Playable::Vertical); 369 //this->airFriction = 0.5f; 370 this->travelDistance = Vector2D(50.0, 50.0); 371 this->travelSpeed = 50; 372 this->cameraSpeed = 40; 373 374 this->travelNode->debugDraw(); 342 375 } 343 376 … … 352 385 } 353 386 354 void SpaceShip::setPlayDirection(const Quaternion& quat, float speed) 355 { 356 this->mouseDir = quat; 357 } 387 void SpaceShip::setPlayDirection(const Quaternion& rot, float speed) 388 { 389 this->direction = Quaternion (rot.getHeading(), Vector(0,1,0)); 390 } 391 392 void SpaceShip::setTravelSpeed(float travelSpeed) 393 { 394 this->travelSpeed = travelSpeed; 395 } 396 397 /* 398 void SpaceShip::setTravelHeight(float travelHeight) 399 { 400 if (this->toTravelHeight == NULL) 401 this->toTravelHeight = new float; 402 *this->toTravelHeight = travelHeight; 403 } 404 */ 405 406 407 void SpaceShip::setTravelDistance(const Vector2D& distance) 408 { 409 this->travelDistance = distance; 410 } 411 412 void SpaceShip::setTravelDistance(float x, float y) 413 { 414 this->setTravelDistance(Vector2D(x, y)); 415 } 416 358 417 359 418 360 419 void SpaceShip::reset() 361 420 { 362 b Up = bDown= bLeft = bRight = bAscend = bDescend = bRollL = bRollR = bFire = bSecFire = false;363 364 xMouse = yMouse = 0;421 bForward = bBackward = bLeft = bRight = bAscend = bDescend = bRollL = bRollR = bFire = bSecFire = false; 422 423 //xMouse = yMouse = 0; 365 424 366 425 this->setHealth(80); … … 452 511 453 512 454 513 /* 455 514 if( ( xMouse != 0 || yMouse != 0 ) && this->getOwner() == SharedNetworkData::getInstance()->getHostID() ) 456 515 { … … 465 524 xMouse = yMouse = 0; 466 525 } 467 468 469 470 471 // if( this != State::getPlayer()->getControllable()) 472 // return; 526 */ 473 527 474 528 // spaceship controlled movement fire(bool bF){ this->bFire = bF;} 475 529 //if (this->getOwner() == this->getHostID()) 476 this->calculateVelocity(time); 477 478 479 Vector move = velocity*time; 480 530 531 //is->calculateVelocity(time); 532 533 534 //vector move = velocity*time; 535 536 /* 481 537 //orient the velocity in the direction of the spaceship. 482 538 travelSpeed = velocity.len(); 483 539 velocity += ((this->getAbsDirX())*travelSpeed-velocity)*airViscosity; 484 540 velocity = (velocity.getNormalized())*travelSpeed; 541 */ 542 this->movement(time); 543 544 // TRYING TO FIX PNode. 545 this->cameraNode.setAbsCoorSoft(this->getAbsCoor() + Vector(0.0f, 5.0f, 0.0f), 30.0f); 546 this->cameraNode.setRelDirSoft(this->getAbsDir(), 30.0f); 547 485 548 this->burstEmitter->setEmissionRate(travelSpeed); 486 549 this->burstEmitter->setEmissionVelocity(travelSpeed*.5, travelSpeed *.1); 487 550 488 551 //orient the spaceship in direction of the mouse 552 /* 489 553 rotQuat = Quaternion::quatSlerp( this->getAbsDir(), mouseDir, 0.5);//fabsf(time)*shipInertia); 490 554 if (this->getAbsDir().distance(rotQuat) > 0.00000000000001) 491 555 this->setAbsDir( rotQuat); 492 556 //this->setAbsDirSoft(mouseDir,5); 557 */ 493 558 494 559 // this is the air friction (necessary for a smooth control) 560 /* 495 561 if(travelSpeed >= 120) velocity -= velocity.getNormalized()*travelSpeed*travelSpeed*0.0001; 496 562 else if (travelSpeed <= 80) velocity -= velocity.getNormalized()*travelSpeed*0.001; 563 */ 497 564 498 565 //other physics (gravity) … … 510 577 //SDL_WarpMouse(GraphicsEngine::getInstance()->getResolutionX()/2, GraphicsEngine::getInstance()->getResolutionY()/2); 511 578 579 /* 512 580 this->shiftCoor(move); 581 */ 513 582 514 583 // PRINTF(0)("id of %s is: %i\n", this->getName(), this->getOMListNumber()); … … 516 585 } 517 586 518 /** 519 * calculate the velocity 520 * @param time the timeslice since the last frame 587 /* 588 void SpaceShip::calculateVelocity (float time) 589 { 590 Vector accel(0.0, 0.0, 0.0); 591 /* calculate the direction in which the craft is heading */ 592 /* 593 if( this->bUp ) 594 { 595 accel += (this->getAbsDirX())*acceleration; 596 597 } 598 599 if( this->bDown ) 600 { 601 accel -= (this->getAbsDirX())*0.5*acceleration; 602 603 } 604 605 if( this->bLeft) 606 { 607 this->shiftDir(Quaternion(time, Vector(0,1,0))); 608 } 609 if( this->bRight) 610 { 611 this->shiftDir(Quaternion(-time, Vector(0,1,0))); 612 } 613 614 615 if( this->bRollL) 616 { 617 mouseDir *= Quaternion(-time*2, Vector(1,0,0)); 618 } 619 if( this->bRollR) 620 { 621 mouseDir *= Quaternion(time*2, Vector(1,0,0)); 622 623 } 624 if (this->bAscend ) 625 { 626 this->shiftDir(Quaternion(time, Vector(0,0,1))); 627 } 628 if (this->bDescend ) 629 { 630 this->shiftDir(Quaternion(-time, Vector(0,0,1))); 631 } 632 633 velocity += accel*time*10; 634 635 } 521 636 */ 522 void SpaceShip::calculateVelocity (float time)523 {524 Vector accel(0.0, 0.0, 0.0);525 /*526 Vector rot(0.0, 0.0, 0.0); // wird ben�igt fr Helicopter527 */528 //float rotVal = 0.0;529 /* FIXME: calculating the direction and orthDirection every timeSlice is redundant! save it somewhere */530 /* calculate the direction in which the craft is heading */531 532 //Plane plane(Vector(0,1,0), Vector(0,0,0));533 534 if( this->bUp )535 {536 //this->shiftCoor(this->getAbsDirX());537 //accel += (this->getAbsDirX())*2;538 accel += (this->getAbsDirX())*acceleration;539 540 }541 542 if( this->bDown )543 {544 //this->shiftCoor((this->getAbsDirX())*-1);545 //accel -= (this->getAbsDirX())*2;546 //if(velocity.len() > 50)547 accel -= (this->getAbsDirX())*0.5*acceleration;548 549 550 551 }552 553 if( this->bLeft/* > -this->getRelCoor().z*2*/)554 {555 this->shiftDir(Quaternion(time, Vector(0,1,0)));556 // accel -= rightDirection;557 //velocityDir.normalize();558 //rot +=Vector(1,0,0);559 //rotVal -= .4;560 }561 if( this->bRight /* > this->getRelCoor().z*2*/)562 {563 this->shiftDir(Quaternion(-time, Vector(0,1,0)));564 565 // accel += rightDirection;566 //velocityDir.normalize();567 //rot += Vector(1,0,0);568 //rotVal += .4;569 }570 571 572 if( this->bRollL /* > -this->getRelCoor().z*2*/)573 {574 mouseDir *= Quaternion(-time*2, Vector(1,0,0));575 // accel -= rightDirection;576 //velocityDir.normalize();577 //rot +=Vector(1,0,0);578 //rotVal -= .4;579 }580 if( this->bRollR /* > this->getRelCoor().z*2*/)581 {582 mouseDir *= Quaternion(time*2, Vector(1,0,0));583 584 // accel += rightDirection;585 //velocityDir.normalize();586 //rot += Vector(1,0,0);587 //rotVal += .4;588 }589 if (this->bAscend )590 {591 this->shiftDir(Quaternion(time, Vector(0,0,1)));592 593 // accel += upDirection;594 //velocityDir.normalize();595 //rot += Vector(0,0,1);596 //rotVal += .4;597 }598 if (this->bDescend )599 {600 this->shiftDir(Quaternion(-time, Vector(0,0,1)));601 602 // accel -= upDirection;603 //velocityDir.normalize();604 //rot += Vector(0,0,1);605 //rotVal -= .4;606 }607 608 velocity += accel*time*10;609 //rot.normalize();610 //this->setRelDirSoft(Quaternion(rotVal, rot), 5);611 612 }613 637 614 638 /** … … 620 644 621 645 if( event.type == KeyMapper::PEV_LEFT) 622 this->b RollL= event.bPressed;646 this->bLeft = event.bPressed; 623 647 else if( event.type == KeyMapper::PEV_RIGHT) 624 this->bR ollR= event.bPressed;648 this->bRight = event.bPressed; 625 649 else if( event.type == KeyMapper::PEV_FORWARD) 626 this->b Up= event.bPressed; //this->shiftCoor(0,.1,0);650 this->bForward = event.bPressed; //this->shiftCoor(0,.1,0); 627 651 else if( event.type == KeyMapper::PEV_BACKWARD) 628 this->b Down= event.bPressed; //this->shiftCoor(0,-.1,0);652 this->bBackward = event.bPressed; //this->shiftCoor(0,-.1,0); 629 653 else if( event.type == KeyMapper::PEV_FIRE2) 630 654 this->bSecFire = event.bPressed; 631 655 else if( event.type == KeyMapper::PEV_FIRE1) 632 656 this->bFire = event.bPressed; 657 658 659 /* 633 660 else if( event.type == EV_MOUSE_MOTION) 634 661 { … … 637 664 this->yMouse += event.yRel; 638 665 } 666 */ 639 667 } 640 668 … … 721 749 } 722 750 // weaponMan.increaseAmmunition( weapon, energy); 723 724 751 } 725 752 … … 727 754 void SpaceShip::enterPlaymode(Playable::Playmode playmode) 728 755 { 729 } 730 756 switch(playmode) 757 { 758 case Playable::Full3D: 759 /* 760 if (State::getCameraNode != NULL) 761 { 762 Vector absCoor = this->getAbsCoor(); 763 this->setParent(PNode::getNullParent()); 764 this->setAbsCoor(absCoor); 765 State::getCameraNode()->setParentSoft(&this->cameraNode); 766 State::getCameraNode()->setRelCoorSoft(-10, 0,0); 767 State::getCameraTargetNode()->setParentSoft(&this->cameraNode); 768 State::getCameraTargetNode()->setRelCoorSoft(100, 0,0); 769 770 } 771 */ 772 //break; 773 774 775 case Playable::Vertical: 776 if (State::getCameraNode != NULL) 777 { 778 this->debugNode(1); 779 this->travelNode->debugNode(1); 780 781 this->travelNode->setAbsCoor(this->getAbsCoor()); 782 this->travelNode->updateNode(0.01f); 783 784 this->setParent(this->travelNode); 785 this->setRelCoor(0,0,0); 786 787 State::getCameraNode()->setParentSoft(this->travelNode); 788 State::getCameraNode()->setRelCoorSoft(0, 40,0); 789 State::getCameraTargetNode()->setParentSoft(this->travelNode); 790 State::getCameraTargetNode()->setRelCoorSoft(5,0,0); 791 792 this->debugNode(1); 793 this->travelNode->debugNode(1); 794 std::cout << "testprint"; 795 } 796 break; 797 798 default: 799 PRINTF(2)("Playmode %s Not Implemented in %s\n", Playable::playmodeToString(this->getPlaymode()).c_str(), this->getClassCName()); 800 } 801 } 802 803 /** 804 * @brief calculate the velocity 805 * @param time the timeslice since the last frame 806 */ 731 807 732 808 void SpaceShip::movement (float dt) 733 809 { 734 } 810 // these routines will change the travel movement into zero in a short amout of time, if the player 811 // doesn't press any buttons. 812 if (this->velocity.x >= 0) 813 { 814 if (this->velocity.x > 2*this->acceleration * dt) 815 this->velocity.x -= 2* this->acceleration * dt; 816 else 817 this->velocity.x = 0; 818 } 819 else 820 { 821 if (this->velocity.x < -2*this->acceleration * dt) 822 this->velocity.x += 2* this->acceleration * dt; 823 else 824 this->velocity.x = 0; 825 } 826 827 if( this->bForward ) 828 { 829 if(this->getRelCoor().x < this->travelDistance.x) 830 { 831 if (this->velocity.x < this->travelSpeed) 832 { 833 this->velocity.x += 3*this->acceleration*dt; 834 } 835 else 836 { 837 this->velocity.x = this->travelSpeed; 838 } 839 } 840 else 841 { 842 this->velocity.x = 0.0f; 843 } 844 } 845 846 if( this->bBackward ) 847 { 848 if(this->getRelCoor().x > -this->travelDistance.x) 849 { 850 if (this->velocity.x > -this->travelSpeed) 851 { 852 this->velocity.x -= 3*this->acceleration*dt; 853 } 854 else 855 { 856 this->velocity.x = -this->travelSpeed; 857 } 858 } 859 else 860 { 861 this->velocity.x = 0.0f; 862 } 863 } 864 if( this->bLeft) 865 { 866 } 867 868 if( this->bRight) 869 { 870 } 871 872 switch(this->getPlaymode()) 873 { 874 case Playable::Full3D: 875 /* 876 { 877 Vector accelerationDir = this->getAbsDir().apply(accel * this->acceleration); 878 879 // this is the air friction (necessary for a smooth control) 880 Vector damping = (this->velocity * this->airFriction); 881 882 883 this->velocity += (accelerationDir - damping)* dt; 884 this->shiftCoor (this->velocity * dt); 885 886 // limit the maximum rotation speed. 887 if (this->rotation != 0.0f) 888 { 889 float maxRot = 10.0 * dt; 890 if (unlikely(this->rotation > maxRot)) this->rotation = maxRot; 891 if (unlikely(this->rotation < -maxRot)) this->rotation = -maxRot; 892 this->direction *= Quaternion(-M_PI/4.0*this->rotation, Vector(0,1,0)); 893 894 this->rotation = 0.0f; 895 } 896 897 this->setRelDirSoft(this->direction * Quaternion(-cameraLook, Vector(0,0,1)), 5); 898 } 899 break; 900 */ 901 case Playable::Vertical: 902 { 903 /* 904 if (this->toTravelHeight != NULL) 905 { 906 this->travelNode->shiftCoor(Vector(0, (*toTravelHeight - this->travelNode->getAbsCoor().y) * dt * 10.0, 0)); 907 if (fabsf(this->travelNode->getAbsCoor().y - *this->toTravelHeight) < .1) 908 { 909 delete this->toTravelHeight; 910 this->toTravelHeight = NULL; 911 } 912 } 913 */ 914 this->travelNode->shiftCoor(Vector(this->cameraSpeed * dt, 0, 0)); 915 916 /* 917 accel.y = 0.0; 918 919 Vector accelerationDir = this->getAbsDir().apply(accel * this->acceleration); 920 accelerationDir.y = 0.0; 921 922 // this is the air friction (necessary for a smooth control) 923 Vector damping = (this->velocity * this->airFriction); 924 925 926 this->velocity += (accelerationDir - damping)* dt; 927 928 if (this->getRelCoor().z > this->travelDistance.y && velocity.z > 0.0) 929 this->velocity.z = 0.0f; 930 if (this->getRelCoor().z < -this->travelDistance.y && velocity.z < 0.0) 931 this->velocity.z = 0.0f; 932 933 if (this->getRelCoor().x > this->travelDistance.x && velocity.x > 0.0) 934 this->velocity.x = 0.0f; 935 if (this->getRelCoor().x < -this->travelDistance.x && velocity.x < 0.0) 936 this->velocity.x = 0.0f; 937 938 */ 939 this->shiftCoor (this->velocity * dt); 940 941 942 /* 943 if (accel.z == 0) 944 this->setRelDirSoft(Quaternion(0, Vector(0,0,0)), 5.0f); 945 else 946 this->setRelDirSoft(Quaternion(this->velocity.z * 5, Vector(1,0,0)), 4.5f); 947 */ 948 } 949 break; 950 951 default: 952 PRINTF(2)("Playmode %s Not Implemented in %s\n", Playable::playmodeToString(this->getPlaymode()).c_str(), this->getClassCName()); 953 } 954 } 955 -
branches/playability/src/world_entities/space_ships/space_ship.h
r9975 r10017 35 35 void setTravelDistance(float x, float y); 36 36 37 void setAirFriction(float friction) { this->airFriction = friction; };37 //void setAirFriction(float friction) { this->airFriction = friction; }; 38 38 39 39 virtual void enter(); … … 121 121 int curWeaponSecondary; //!< current secondary weapon config 122 122 123 bool b Up; //!< up button pressed.124 bool b Down; //!< down button pressed.123 bool bForward; //!< up button pressed. 124 bool bBackward; //!< down button pressed. 125 125 bool bLeft; //!< left button pressed. 126 126 bool bRight; //!< right button pressed. … … 131 131 bool bRollR; //!< rolling button pressed (right) 132 132 133 /* 133 134 float xMouse; //!< mouse moved in x-Direction 134 135 float yMouse; //!< mouse moved in y-Direction … … 137 138 int controlVelocityX; 138 139 int controlVelocityY; 139 // float cycle; //!< hovercycle 140 */ 141 // float cycle; //!< hovercycle 142 140 143 141 144 Vector velocity; //!< the velocity of the player. 142 Vector oldVelocity; //!< the velocity the player had last synced 145 //Vector oldVelocity; //!< the velocity the player had last synced 146 147 143 148 144 149 // 2D-traveling 145 150 PNode* travelNode; 146 151 float travelSpeed; //!< the current speed of the Ship (to make soft movement) 152 Vector2D travelDistance; //!< Travel-Distance away from the TravelNode 147 153 148 154 // Camera … … 150 156 float cameraLook; 151 157 float rotation; 158 float cameraSpeed; 152 159 153 / / FIXME until other fixme removal needed160 /* 154 161 Quaternion mouseDir; //!< the direction where the player wants to fly 155 162 Quaternion oldMouseDir; //!< the direction where the player wanted to fly 156 163 float shipInertia; //!< the inertia of the ship(how fast the ship reacts to a mouse input) 157 158 164 Quaternion rotQuat; 159 165 Quaternion pitchDir; 160 166 float dogdeSpeed; //!< the dogde Speed of the ship. 161 // FIXME167 */ 162 168 163 169 Quaternion direction; //!< the direction of the ship. 164 170 float acceleration; //!< the acceleration of the ship. 165 float airFriction; //!< AirFriction.166 float airViscosity;171 //float airFriction; //!< AirFriction. 172 //float airViscosity; 167 173 168 174 byte oldMask; //!< used for synchronisation
Note: See TracChangeset
for help on using the changeset viewer.