|
From: julien r. <jul...@us...> - 2005-12-10 23:58:31
|
Update of /cvsroot/epfl/game In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19582 Modified Files: game.cc physic_engine.cc physic_node_entity.cc physic_node_entity.h Log Message: stepslidemove Index: physic_node_entity.cc =================================================================== RCS file: /cvsroot/epfl/game/physic_node_entity.cc,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** physic_node_entity.cc 7 Dec 2005 22:23:51 -0000 1.3 --- physic_node_entity.cc 10 Dec 2005 23:58:23 -0000 1.4 *************** *** 155,161 **** /*tgVector3 org(0,1,0); vVelocity = ClipVelocity(vVelocity, org, OVERCLIP);*/ ! // _StepSlideMove(eTime); ! vPosition += vVelocity*eTime; ! // cout << "--> Velocity " << vVelocity.x << " : " << vVelocity.y << " : " << vVelocity.z << std::endl; // cout << "===========================================" << std::endl; --- 155,162 ---- /*tgVector3 org(0,1,0); vVelocity = ClipVelocity(vVelocity, org, OVERCLIP);*/ ! _StepSlideMove(eTime); ! // _MyStepSlideMove(eTime); ! // vPosition += vVelocity*eTime; ! // cout << "--> Velocity " << vVelocity.x << " : " << vVelocity.y << " : " << vVelocity.z << std::endl; // cout << "===========================================" << std::endl; *************** *** 166,171 **** } ! #define STEPSIZE 18 ! tgVector3 tgPhysicNodeEntity::ClipVelocity(tgVector3& in, tgVector3& normal, float overbounce) { float backoff; backoff = in*normal; --- 167,218 ---- } ! #define STEPSIZE 20/* ! void tgPhysicNodeEntity::_MyStepSlideMove(float eTime) ! { ! tgVector3 tempVel = vVelocity; ! if(!_TraceNAjust(eTime, tempVel, vPosition)) { ! vPosition += tempVel*eTime; ! return; ! } ! ! //---position initiales ! tgVector3 headPos_o = vPosition + tgVector3(0,STEPSIZE,0); ! // tgVector3 headVel_o = vVelocity; ! ! tgVector3 feetPos_o = vPosition; ! // tgVector3 feetVel_o = vVelocity; ! //--- ! ! //---calcul des nouvelles vitesses ! tgVector3 headVel_e = vVelocity; ! _TraceNAjust(eTime, headVel_e, headPos_o); ! ! tgVector3 feetVel_e = vVelocity; ! _TraceNAjust(eTime, feetVel_e, feetPos_o); ! //--- ! ! //---calcul des nouvelles positions ! tgVector3 headPos_e = headPos_o+headVel_e*eTime; ! tgVector3 feetPos_e = feetPos_o+feetVel_e*eTime; ! cout << feetVel_e << endl; ! //--- ! ! //---calcul des distances ! float headDist = headVel_e.x*headVel_e.x + headVel_e.z*headVel_e.z; ! float feetDist = feetVel_e.x*feetVel_e.x + feetVel_e.z*feetVel_e.z; ! //--- ! ! //---comparaison et montage eventuel des marches ! if(headDist > feetDist) { //on doit monter ! vPosition = feetPos_e; ! } else { ! vPosition = feetPos_e; ! } ! //--- ! }*/ ! ! ! ! tgVector3 tgPhysicNodeEntity::ClipVelocity(tgVector3& in, tgVector3& normal, float overbounce) const{ float backoff; backoff = in*normal; *************** *** 177,181 **** return tgVector3(in.x-normal.x*backoff, in.y-normal.y*backoff,in.z-normal.z*backoff); } ! void tgPhysicNodeEntity::_StepSlideMove(float eTime) { tgVector3 start_o, start_v; --- 224,228 ---- return tgVector3(in.x-normal.x*backoff, in.y-normal.y*backoff,in.z-normal.z*backoff); } ! #if 0 void tgPhysicNodeEntity::_StepSlideMove(float eTime) { tgVector3 start_o, start_v; *************** *** 187,194 **** start_o = vPosition; start_v = vVelocity; - if (!_TraceNAjust(eTime)) - return; //pas de collision, pas besoin de monter des escaliers :) - down = start_o; down.y -= STEPSIZE; --- 234,240 ---- start_o = vPosition; start_v = vVelocity; + if (!_TraceNAjust(eTime, vVelocity,vPosition)) + return; //pas de collision, pas besoin de monter des escaliers :) down = start_o; down.y -= STEPSIZE; *************** *** 216,243 **** vVelocity = start_v; ! _TraceNAjust(eTime); down = vPosition; down.y -= stepSize; trace = pWorldManager->Trace(vPosition, down, pBVolume); ! if(!trace.bAllSolid) vPosition = trace.vEndPoint; ! if(trace.fFraction < 1.0f) vVelocity = ClipVelocity(vVelocity, trace.vColNormal, OVERCLIP); } #define MAX_CLIP_PLANES 5 #define EPSILON 0.0001f ! bool tgPhysicNodeEntity::_TraceNAjust(float eTime) { //quake3 source : code/game/bg_slidemove.c:50 tgVector3 pPlanes[MAX_CLIP_PLANES]; float timeLeft =eTime; ! tgVector3 origin(vPosition); tgVector3 vNewPosition; ! tgVector3 initialVelocity(vVelocity); int bumpcount; ! tgVector3 endVelocity = vVelocity;; tgVector3 clipVelocity; tgVector3 endClipVelocity; --- 262,347 ---- vVelocity = start_v; ! _TraceNAjust(eTime,vVelocity,vPosition); down = vPosition; down.y -= stepSize; trace = pWorldManager->Trace(vPosition, down, pBVolume); ! if(!trace.bAllSolid) { vPosition = trace.vEndPoint; ! } ! if(trace.fFraction < 1.0f) { vVelocity = ClipVelocity(vVelocity, trace.vColNormal, OVERCLIP); + } + vPosition += vVelocity*eTime; } + #else + void tgPhysicNodeEntity::_StepSlideMove(float eTime) { + tgVector3 start_o, start_v; + tgVector3 down_o, down_v; + tgCollisionResult trace; + tgVector3 up, down; + float stepSize; + + start_o = vPosition; + start_v = vVelocity; + + if (!_TraceNAjust(eTime, vVelocity,vPosition)) + return; //pas de collision, pas besoin de monter des escaliers :) + down = start_o; + down.y -= STEPSIZE; + + trace = pWorldManager->Trace(start_o, down, pBVolume); + up.Set(0,1,0); + + //on ne monte pas si on a encore une vitesse ou si on peut encore descendre (si fFraction == 1.0, on a rien en-dessous de nous) + //trace.vColNormal est de longueur 1, up aussi -> trace.vColNormal*up = ||trace.vColNormal||*||up||*cos(angle) -> si cos(angle)<0.7, angle>45, pente trop raide + if(vVelocity.y < 0 && (trace.fFraction == 1.0 || trace.vColNormal*up < 0.7)) + return; + + down_o = vPosition; + down_v = vVelocity; + + up = start_o; + up.y += STEPSIZE; + + //on trace entre la position du joueur et la position STEPSIZE plus haut, pour éviter de monter à travers un plafond + trace = pWorldManager->Trace(start_o, up, pBVolume); + if(trace.bAllSolid) + return; + + stepSize = trace.vEndPoint.y-start_o.y; + vPosition = trace.vEndPoint; + vVelocity = start_v; + + _TraceNAjust(eTime,vVelocity,vPosition); + // + down = vPosition; + down.y -= stepSize; + trace = pWorldManager->Trace(vPosition, down, pBVolume); + if(!trace.bAllSolid) { + vPosition = trace.vEndPoint; + } + if(trace.fFraction < 1.0f) { + vVelocity = ClipVelocity(vVelocity, trace.vColNormal, OVERCLIP); + } + // vPosition += vVelocity*eTime; + } + #endif + + #define MAX_CLIP_PLANES 5 #define EPSILON 0.0001f ! bool tgPhysicNodeEntity::_TraceNAjust(float eTime, tgVector3& vel, const tgVector3& pos) { //quake3 source : code/game/bg_slidemove.c:50 tgVector3 pPlanes[MAX_CLIP_PLANES]; float timeLeft =eTime; ! tgVector3 origin(pos); tgVector3 vNewPosition; ! tgVector3 initialVelocity(vel); int bumpcount; ! tgVector3 endVelocity = vel; tgVector3 clipVelocity; tgVector3 endClipVelocity; *************** *** 246,261 **** int i; //ne jamais revenir contre la vitesse ! pPlanes[numPlanes] = vVelocity.GetNormalized(); for(bumpcount = 0; bumpcount <4; bumpcount++) { ! vNewPosition = origin+vVelocity * timeLeft; ! cr = pWorldManager->Trace(origin, vNewPosition, pBVolume); if(cr.bAllSolid) { ! vVelocity.y = 0; return true; } if(cr.fFraction > 0) { ! origin = cr.vEndPoint; } --- 350,366 ---- int i; //ne jamais revenir contre la vitesse ! pPlanes[numPlanes] = vel.GetNormalized(); for(bumpcount = 0; bumpcount <4; bumpcount++) { ! vNewPosition = /*origin*/vPosition+vel * timeLeft; ! cr = pWorldManager->Trace(/*origin*/vPosition, vNewPosition, pBVolume); if(cr.bAllSolid) { ! vel.y = 0; return true; } if(cr.fFraction > 0) { ! // origin = cr.vEndPoint; ! vPosition = cr.vEndPoint; } *************** *** 267,271 **** if(numPlanes > MAX_CLIP_PLANES) { ! vVelocity.Set(0,0,0); return true; } --- 372,376 ---- if(numPlanes > MAX_CLIP_PLANES) { ! vel.Set(0,0,0); return true; } *************** *** 274,278 **** for(i=0; i<numPlanes;i++) { if (cr.vColNormal*pPlanes[i] > 0.99 ) { ! vVelocity = cr.vColNormal + vVelocity; break; } --- 379,383 ---- for(i=0; i<numPlanes;i++) { if (cr.vColNormal*pPlanes[i] > 0.99 ) { ! vel = cr.vColNormal + vel; break; } *************** *** 289,298 **** for(i=0; i<numPlanes;i++) { ! float into = vVelocity*pPlanes[i]; if(into >= 0.01) continue; ! clipVelocity = ClipVelocity(vVelocity, pPlanes[i], OVERCLIP); endClipVelocity = ClipVelocity(endVelocity, pPlanes[i], OVERCLIP); --- 394,403 ---- for(i=0; i<numPlanes;i++) { ! float into = vel*pPlanes[i]; if(into >= 0.01) continue; ! clipVelocity = ClipVelocity(vel, pPlanes[i], OVERCLIP); endClipVelocity = ClipVelocity(endVelocity, pPlanes[i], OVERCLIP); *************** *** 313,317 **** dir = pPlanes[i]%pPlanes[j]; dir.Normalize(); ! d = dir*vVelocity; clipVelocity = dir*d; --- 418,422 ---- dir = pPlanes[i]%pPlanes[j]; dir.Normalize(); ! d = dir*vel; clipVelocity = dir*d; *************** *** 326,334 **** if(clipVelocity*pPlanes[k] >= 0.01) continue; ! vVelocity.Set(0,0,0); return true; } } ! vVelocity = clipVelocity; endVelocity = endClipVelocity; break; --- 431,439 ---- if(clipVelocity*pPlanes[k] >= 0.01) continue; ! vel.Set(0,0,0); return true; } } ! vel = clipVelocity; endVelocity = endClipVelocity; break; Index: game.cc =================================================================== RCS file: /cvsroot/epfl/game/game.cc,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** game.cc 7 Dec 2005 22:23:51 -0000 1.2 --- game.cc 10 Dec 2005 23:58:23 -0000 1.3 *************** *** 97,101 **** pBindManager->Bind(TGKEY_s, tgMakeFunctor((tgFunctor1<int>*)0, *pPlayer, &tgPlayer::MoveBackward)); ! pTestPlayer = new tgPlayer (pWorldManager, pModelManager, tgVector3(-750,80,271)); pTestPlayer->SetInactive(); /*pBindManager->Bind(TGKEY_LEFT, tgMakeFunctor((tgFunctor1<int>*)0, *pTestPlayer, &tgPlayer::StrafeLeft)); --- 97,101 ---- pBindManager->Bind(TGKEY_s, tgMakeFunctor((tgFunctor1<int>*)0, *pPlayer, &tgPlayer::MoveBackward)); ! pTestPlayer = new tgPlayer (pWorldManager, pModelManager, tgVector3(-570,30,-650)); pTestPlayer->SetInactive(); /*pBindManager->Bind(TGKEY_LEFT, tgMakeFunctor((tgFunctor1<int>*)0, *pTestPlayer, &tgPlayer::StrafeLeft)); *************** *** 230,234 **** // moteur physique ! /*pPhysicEngine->MoveObjects(eTime); std::ostringstream* streamPh = new std::ostringstream(); (*streamPh) << "Position pTestPlayer: " << pTestPlayer->GetEntity()->GetPosition().x << " # " --- 230,234 ---- // moteur physique ! pPhysicEngine->MoveObjects(eTime); std::ostringstream* streamPh = new std::ostringstream(); (*streamPh) << "Position pTestPlayer: " << pTestPlayer->GetEntity()->GetPosition().x << " # " *************** *** 239,243 **** (*stream) << pTimer->GetFPS() << std::endl; pCanvas->DisplayText(stream->str()); ! delete stream;*/ } --- 239,243 ---- (*stream) << pTimer->GetFPS() << std::endl; pCanvas->DisplayText(stream->str()); ! delete stream; } Index: physic_node_entity.h =================================================================== RCS file: /cvsroot/epfl/game/physic_node_entity.h,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** physic_node_entity.h 7 Dec 2005 22:23:51 -0000 1.2 --- physic_node_entity.h 10 Dec 2005 23:58:23 -0000 1.3 *************** *** 83,89 **** * true -> collision, false -> aucune collision */ ! bool _TraceNAjust(float eTime); void _StepSlideMove(float eTime); ! tgVector3 ClipVelocity(tgVector3& in, tgVector3& normal, float overbounce); bool onAir; --- 83,90 ---- * true -> collision, false -> aucune collision */ ! bool _TraceNAjust(float eTime, tgVector3& vel, const tgVector3& pos); ! void _MyStepSlideMove(float eTime); void _StepSlideMove(float eTime); ! tgVector3 ClipVelocity(tgVector3& in, tgVector3& normal, float overbounce) const; bool onAir; Index: physic_engine.cc =================================================================== RCS file: /cvsroot/epfl/game/physic_engine.cc,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** physic_engine.cc 7 Dec 2005 22:23:51 -0000 1.2 --- physic_engine.cc 10 Dec 2005 23:58:23 -0000 1.3 *************** *** 93,95 **** (*i)->removeForce(force); } ! } \ No newline at end of file --- 93,96 ---- (*i)->removeForce(force); } ! } ! |