Revision: 2554 http://rigsofrods.svn.sourceforge.net/rigsofrods/?rev=2554&view=rev Author: ulteq Date: 2012-05-14 11:07:03 +0000 (Mon, 14 May 2012) Log Message: ----------- -Feature: Enhanced character movement when running. fixed setAngle()
Modified Paths: -------------- trunk/source/main/gameplay/Character.cpp trunk/source/main/gameplay/Character.h Modified: trunk/source/main/gameplay/Character.cpp =================================================================== --- trunk/source/main/gameplay/Character.cpp 2012-05-14 08:27:39 UTC (rev 2553) +++ trunk/source/main/gameplay/Character.cpp 2012-05-14 11:07:03 UTC (rev 2554) @@ -242,9 +242,11 @@ return personode->getAttachedObject(0)->getVisible(); } -float Character::getAngle() +void Character::setAngle(float angle) { - return persoangle; + persoangle = angle; + personode->resetOrientation(); + personode->yaw(-Radian(persoangle)); } void Character::setCollisions(Collisions *c) @@ -311,7 +313,7 @@ Vector3 position3=position+Vector3(0, 0.25, 0); if (collisions->collisionCorrect(&position)) { - if (persovspeed<0) persovspeed=0.0; + if (persovspeed<0) persovspeed=0.0f; if (collisions->collisionCorrect(&position2) && !collisions->collisionCorrect(&position3)) persovspeed=2.0; //autojump else perso_canjump=true; } @@ -331,7 +333,7 @@ if (collisions->collisionCorrect(&cposition)) { position=cposition; - if (persovspeed<0) persovspeed=0.0; + if (persovspeed<0) persovspeed=0.0f; perso_canjump=true; /*if (collisions->collisionCorrect(&cposition2)) { @@ -351,7 +353,7 @@ if (position.y<pheight) { position.y=pheight; - persovspeed=0.0; + persovspeed=0.0f; perso_canjump=true; } //water stuff @@ -362,7 +364,7 @@ if (position.y<wheight-1.8) { position.y=wheight-1.8; - persovspeed=0.0; + persovspeed=0.0f; }; } @@ -382,7 +384,7 @@ } tmpJoy = INPUTENGINE.getEventValue(EV_CHARACTER_RIGHT); - if (tmpJoy > 0.0) + if (tmpJoy > 0.0f) { persoangle += dt * 2.0 * tmpJoy; personode->resetOrientation(); @@ -395,7 +397,7 @@ } tmpJoy = INPUTENGINE.getEventValue(EV_CHARACTER_LEFT); - if (tmpJoy > 0.0) + if (tmpJoy > 0.0f) { persoangle -= dt * 2.0 * tmpJoy; personode->resetOrientation(); @@ -406,32 +408,38 @@ idleanim=false; } } + + float tmpRun = INPUTENGINE.getEventValue(EV_CHARACTER_RUN); + float accel = 1.0f; - tmpJoy = INPUTENGINE.getEventValue(EV_CHARACTER_SIDESTEP_LEFT); - if (tmpJoy > 0.0) + tmpJoy = accel = INPUTENGINE.getEventValue(EV_CHARACTER_SIDESTEP_LEFT); + if (tmpJoy > 0.0f) { + if (tmpRun > 0.0f) accel = 3.0 * tmpRun; // animation missing for that - position+=dt*persospeed*1.5*tmpJoy*Vector3(cos(persoangle-Math::PI/2), 0.0, sin(persoangle-Math::PI/2)); + position+=dt*persospeed*1.5*accel*Vector3(cos(persoangle-Math::PI/2), 0.0f, sin(persoangle-Math::PI/2)); } - tmpJoy = INPUTENGINE.getEventValue(EV_CHARACTER_SIDESTEP_RIGHT); - if (tmpJoy > 0.0) + tmpJoy = accel = INPUTENGINE.getEventValue(EV_CHARACTER_SIDESTEP_RIGHT); + if (tmpJoy > 0.0f) { + if (tmpRun > 0.0f) accel = 3.0 * tmpRun; // animation missing for that - position+=dt*persospeed*1.5*tmpJoy*Vector3(cos(persoangle+Math::PI/2), 0.0, sin(persoangle+Math::PI/2)); + position+=dt*persospeed*1.5*accel*Vector3(cos(persoangle+Math::PI/2), 0.0f, sin(persoangle+Math::PI/2)); } - tmpJoy = INPUTENGINE.getEventValue(EV_CHARACTER_FORWARD) + INPUTENGINE.getEventValue(EV_CHARACTER_ROT_UP); - if(tmpJoy>1) tmpJoy = 1; - float tmpRun = INPUTENGINE.getEventValue(EV_CHARACTER_RUN); + tmpJoy = accel = INPUTENGINE.getEventValue(EV_CHARACTER_FORWARD) + INPUTENGINE.getEventValue(EV_CHARACTER_ROT_UP); float tmpBack = INPUTENGINE.getEventValue(EV_CHARACTER_BACKWARDS) + INPUTENGINE.getEventValue(EV_CHARACTER_ROT_DOWN); - if(tmpBack>1) tmpBack = 1; - if (tmpJoy > 0.0 || tmpRun > 0.0) + + tmpJoy = std::min(tmpJoy, 1.0f); + tmpBack = std::min(tmpBack, 1.0f); + + if (tmpJoy > 0.0f || tmpRun > 0.0f) { - float accel = 1.0 * tmpJoy; - float time = dt*accel*persospeed; - if (tmpRun > 0) - accel = 3.0 * tmpRun; + if (tmpRun > 0.0f) accel = 3.0 * tmpRun; + + float time = dt*tmpJoy*persospeed; + if(isswimming) { setAnimationMode("Swim_loop", time); @@ -450,7 +458,7 @@ } // 0.005f fixes character getting stuck on meshes position+=dt*persospeed*1.5*accel*Vector3(cos(persoangle), 0.01f, sin(persoangle)); - } else if (tmpBack > 0.0) + } else if (tmpBack > 0.0f) { float time = -dt*persospeed; if(isswimming) @@ -487,7 +495,7 @@ Vector3 rposition=position; if (collisions->collisionCorrect(&position) || collisions->collisionCorrect(&position2)) { - if (persovspeed<0) persovspeed=0.0; + if (persovspeed<0) persovspeed=0.0f; Vector3 corr=rposition-position; corr.y=0; if (corr.squaredLength()>0 && !collisions->collisionCorrect(&position3)) persovspeed=2.0; //autojump perso_canjump=true; @@ -506,9 +514,9 @@ int res = beamCoupling->calculateDriverPos(pos, rot); if(!res) { - setPosition(pos + rot * Vector3(0,-0.6f,-0.1f)); // hack to position the character right perfect on the default seat + setPosition(pos + rot * Vector3(0.0f,-0.6f,-0.1f)); // hack to position the character right perfect on the default seat setOrientation(rot); - setAnimationMode("driving", 0); + setAnimationMode("driving"); Real lenght = persoanim->getAnimationState("driving")->getLength(); float timePos = ((angle + 1.0f) * 0.5f) * lenght; //LOG("angle: " + TOSTRING(angle) + " / " + TOSTRING(timePos)); @@ -542,11 +550,6 @@ personode->translate(v); } -Ogre::SceneNode *Character::getSceneNode() -{ - return personode; -} - void Character::sendStreamSetup() { if(remote) return; Modified: trunk/source/main/gameplay/Character.h =================================================================== --- trunk/source/main/gameplay/Character.h 2012-05-14 08:27:39 UTC (rev 2553) +++ trunk/source/main/gameplay/Character.h 2012-05-14 11:07:03 UTC (rev 2554) @@ -44,9 +44,8 @@ void setOrientation(Ogre::Quaternion); Ogre::Quaternion getOrientation(); + void setPosition(Ogre::Vector3 pos); Ogre::Vector3 getPosition(); - void setPosition(Ogre::Vector3 pos); - float getAngle(); void updateNetLabel(); void updateCharacterColour(); @@ -55,9 +54,10 @@ int setBeamCoupling(bool enabled, Beam *truck=0); void update(float dt); - Ogre::SceneNode *getSceneNode(); + Ogre::SceneNode *getSceneNode() { return personode; }; - void setAngle(float angle) { persoangle = angle; }; + float getAngle() { return persoangle; }; + void setAngle(float angle); void setColour(int number) { this->colourNumber = number; }; static unsigned int characterCounter; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ------------------------------------------------------------------------------ Live Security Virtual Conference Exclusive live event will cover all the ways today's security and threat landscape has changed and how IT managers can respond. Discussions will include endpoint security, mobile security and the latest in malware threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/ _______________________________________________ Rigsofrods-devel mailing list Rigsofrods-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/rigsofrods-devel