Changeset 10019 in orxonox.OLD for branches/playability
- Timestamp:
- Dec 5, 2006, 10:47:43 PM (18 years ago)
- Location:
- branches/playability/src/world_entities/space_ships
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/playability/src/world_entities/space_ships/space_ship.cc
r10017 r10019 90 90 */ 91 91 SpaceShip::SpaceShip(const std::string& fileName) 92 : secWeaponMan(this) ,93 supportedPlaymodes(Playable::Vertical) ,94 playmode(Playable::Vertical)92 : secWeaponMan(this) //, 93 //supportedPlaymodes(Playable::Vertical) , 94 //playmode(Playable::Vertical) 95 95 { 96 96 this->init(); … … 113 113 */ 114 114 SpaceShip::SpaceShip(const TiXmlElement* root) 115 : secWeaponMan(this) ,116 supportedPlaymodes(Playable::Vertical) ,117 playmode(Playable::Vertical)115 : secWeaponMan(this) //, 116 //supportedPlaymodes(Playable::Vertical) , 117 //playmode(Playable::Vertical) 118 118 { 119 119 this->init(); … … 129 129 void SpaceShip::init() 130 130 { 131 132 this->setSupportedPlaymodes(Playable::Vertical); 131 133 132 134 // this->setRelDir(Quaternion(M_PI, Vector(1,0,0))); … … 231 233 this->cameraNode.addNodeFlags(PNODE_PROHIBIT_CHILD_DELETE); 232 234 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 235 /* 239 236 this->velocity = this->getAbsDirX()*travelSpeed; … … 366 363 registerVar( new SynchronizeableVector( &velocity, &velocity, "velocity", PERMISSION_MASTER_SERVER ) ); 367 364 368 this->enterPlaymode(Playable::Vertical);369 365 //this->airFriction = 0.5f; 370 this->travelDistance = Vector2D(50.0, 50.0); 371 this->travelSpeed = 50; 366 this->travelDistancePlus = Vector2D(38.0, 43.0); 367 this->travelDistanceMinus = Vector2D(-38.0, -43.0); 368 this->travelSpeed = 80; 372 369 this->cameraSpeed = 40; 370 this->cameraLook = 0.0f; 371 this->acceleration = 120.0f; 372 //this->airFriction = 0.0f; 373 373 374 374 this->travelNode->debugDraw(); … … 404 404 */ 405 405 406 406 /* 407 407 void SpaceShip::setTravelDistance(const Vector2D& distance) 408 408 { … … 414 414 this->setTravelDistance(Vector2D(x, y)); 415 415 } 416 */ 416 417 417 418 … … 432 433 this->secWeaponMan.showCrosshair(); 433 434 //dynamic_cast<Element2D*>(this->secWeaponMan.getFixedTarget())->setVisibility( true); 434 this->attachCamera(); 435 if (!this->setPlaymode(Playable::Vertical)) 436 std::cout << "playmode not supported"; 437 //this->attachCamera(); 435 438 } 436 439 … … 439 442 this->secWeaponMan.hideCrosshair(); 440 443 //dynamic_cast<Element2D*>(this->secWeaponMan.getFixedTarget())->setVisibility( false); 441 this->detachCamera();444 //this->detachCamera(); 442 445 } 443 446 … … 786 789 787 790 State::getCameraNode()->setParentSoft(this->travelNode); 788 State::getCameraNode()->setRelCoorSoft( 0, 40,0);791 State::getCameraNode()->setRelCoorSoft(-0.01, 40,0); 789 792 State::getCameraTargetNode()->setParentSoft(this->travelNode); 790 State::getCameraTargetNode()->setRelCoorSoft( 5,0,0);793 State::getCameraTargetNode()->setRelCoorSoft(0,0,0); 791 794 792 795 this->debugNode(1); 793 796 this->travelNode->debugNode(1); 794 std::cout << "testprint";795 797 } 796 798 break; … … 799 801 PRINTF(2)("Playmode %s Not Implemented in %s\n", Playable::playmodeToString(this->getPlaymode()).c_str(), this->getClassCName()); 800 802 } 803 std::cout << Playable::playmodeToString(this->getPlaymode()); 801 804 } 802 805 … … 808 811 void SpaceShip::movement (float dt) 809 812 { 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 } 813 //by releasing the buttons, the velocity decreases with airCoeff*Acceleration. Should be strong enough so 814 //the ship doesn't slide too much. 815 float airCoeff = 2.5; 816 817 float pi = 3.14; 818 819 // these routines will change the travel movement into zero in a short amout of time, if the player 820 // doesn't press any buttons. 821 if (this->velocity.x >= 0) 822 { 823 if (this->velocity.x > airCoeff*this->acceleration * dt) 824 this->velocity.x -= airCoeff* this->acceleration * dt; 825 else 826 this->velocity.x = 0; 827 } 828 else 829 { 830 if (this->velocity.x < -airCoeff*this->acceleration * dt) 831 this->velocity.x += airCoeff* this->acceleration * dt; 832 else 833 this->velocity.x = 0; 834 } 835 if (this->velocity.z >= 0) 836 { 837 if (this->velocity.z > airCoeff*this->acceleration * dt) 838 this->velocity.z -= airCoeff* this->acceleration * dt; 839 else 840 this->velocity.z = 0; 841 } 842 else 843 { 844 if (this->velocity.z < -airCoeff*this->acceleration * dt) 845 this->velocity.z += airCoeff* this->acceleration * dt; 846 else 847 this->velocity.z = 0; 848 } 849 850 // this will evite, that the ship moves outside the travelDistance- borders,when the player releases all buttons 851 // and its continuing to slide a bit. 852 Vector oldCoor = this->getRelCoor(); 853 if (this->getRelCoor().x > this->travelDistancePlus.x) this->setRelCoor(this->travelDistancePlus.x, oldCoor.y, oldCoor.z); 854 if (this->getRelCoor().x < this->travelDistanceMinus.x) this->setRelCoor(this->travelDistanceMinus.x, oldCoor.y, oldCoor.z); 855 if (this->getRelCoor().z > this->travelDistancePlus.y) this->setRelCoor(oldCoor.x, oldCoor.y, this->travelDistancePlus.y); 856 if (this->getRelCoor().z < this->travelDistanceMinus.y) this->setRelCoor(oldCoor.x, oldCoor.y, this->travelDistanceMinus.y); 826 857 827 858 if( this->bForward ) 828 859 { 829 if(this->getRelCoor().x < this->travelDistance .x)860 if(this->getRelCoor().x < this->travelDistancePlus.x) 830 861 { 831 862 if (this->velocity.x < this->travelSpeed) 832 863 { 833 this->velocity.x += 3*this->acceleration*dt;864 this->velocity.x += (airCoeff + 1.0)*this->acceleration*dt; 834 865 } 835 866 else … … 846 877 if( this->bBackward ) 847 878 { 848 if(this->getRelCoor().x > -this->travelDistance.x)879 if(this->getRelCoor().x > this->travelDistanceMinus.x) 849 880 { 850 881 if (this->velocity.x > -this->travelSpeed) 851 882 { 852 this->velocity.x -= 3*this->acceleration*dt;883 this->velocity.x -= (airCoeff + 1.0)*this->acceleration*dt; 853 884 } 854 885 else … … 862 893 } 863 894 } 895 864 896 if( this->bLeft) 865 897 { 898 if(this->getRelCoor().z > this->travelDistanceMinus.y) 899 { 900 if (this->velocity.z > -this->travelSpeed) 901 { 902 this->velocity.z -= (airCoeff + 1.0)*this->acceleration*dt; 903 } 904 else 905 { 906 this->velocity.z = -this->travelSpeed; 907 } 908 } 909 else 910 { 911 this->velocity.z = 0.0f; 912 } 866 913 } 867 914 868 915 if( this->bRight) 869 916 { 870 } 871 917 if(this->getRelCoor().z < this->travelDistancePlus.y) 918 { 919 if (this->velocity.z < this->travelSpeed) 920 { 921 this->velocity.z += (airCoeff + 1.0)*this->acceleration*dt; 922 } 923 else 924 { 925 this->velocity.z = this->travelSpeed; 926 } 927 } 928 else 929 { 930 this->velocity.z = 0.0f; 931 } 932 } 933 934 this->travelNode->shiftCoor(Vector(this->cameraSpeed * dt, 0, 0)); 935 this->shiftCoor (this->velocity * dt); 936 937 float angle = this->velocity.z / travelSpeed * pi / 3; 938 if (angle > pi/3) angle = pi/3; 939 if (angle < -pi/3) angle = -pi/3; 940 this->setRelDirSoft(Quaternion(angle, Vector(1,0,0)), 5.0f); 941 942 /* 872 943 switch(this->getPlaymode()) 873 944 { 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 } 945 case Playable::Vertical: 899 946 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 else946 this->setRelDirSoft(Quaternion(this->velocity.z * 5, Vector(1,0,0)), 4.5f);947 */948 }949 break;950 951 947 default: 952 948 PRINTF(2)("Playmode %s Not Implemented in %s\n", Playable::playmodeToString(this->getPlaymode()).c_str(), this->getClassCName()); 953 949 } 954 } 955 950 */ 951 } 952 -
branches/playability/src/world_entities/space_ships/space_ship.h
r10017 r10019 31 31 virtual void setPlayDirection(const Quaternion& rot, float speed = 0.0f); 32 32 void setTravelSpeed(float travelSpeed); 33 /* 33 34 void setTravelHeight(float travelHeight); 34 35 void setTravelDistance(const Vector2D& distance); 35 36 void setTravelDistance(float x, float y); 37 */ 36 38 37 39 //void setAirFriction(float friction) { this->airFriction = friction; }; … … 150 152 PNode* travelNode; 151 153 float travelSpeed; //!< the current speed of the Ship (to make soft movement) 152 Vector2D travelDistance; //!< Travel-Distance away from the TravelNode 154 Vector2D travelDistancePlus; //!< Travel-Distance away from the TravelNode 155 Vector2D travelDistanceMinus; 153 156 154 157 // Camera
Note: See TracChangeset
for help on using the changeset viewer.