|
From: julien r. <jul...@us...> - 2004-10-10 20:50:29
|
Update of /cvsroot/epfl/tgengine-0.1 In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15116 Modified Files: Makefile camera.cc defs.h engine.cc physicengine.cc physicengine.h scenemanager.cc scenenode.cc scenenode.h vector3.h Removed Files: SoundManager.cc SoundManager.h Log Message: PhysicCallBack Index: physicengine.cc =================================================================== RCS file: /cvsroot/epfl/tgengine-0.1/physicengine.cc,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** physicengine.cc 27 Sep 2004 16:18:40 -0000 1.7 --- physicengine.cc 10 Oct 2004 20:49:09 -0000 1.8 *************** *** 46,55 **** time_left -= time_left*trace.Fraction; ! vVelocity = ClipVelocity (vVelocity, trace.CollisionNormal); } } ! Vector3 PhysicEngine::ClipVelocity (const Vector3& vel, const Vector3 norm) { /* le produit scalaire entre la vitesse et la normale nous donne --- 46,55 ---- time_left -= time_left*trace.Fraction; ! ClipVelocity (vVelocity, trace.CollisionNormal); } } ! void PhysicEngine::ClipVelocity (Vector3& vel, const Vector3 norm) { /* le produit scalaire entre la vitesse et la normale nous donne *************** *** 62,66 **** float backoff = vel*norm*fOverBounce; Vector3 change = norm*backoff; ! return (vel - change); } --- 62,67 ---- float backoff = vel*norm*fOverBounce; Vector3 change = norm*backoff; ! vel -= change; ! //return (vel - change); } *************** *** 70,74 **** --- 71,78 ---- * Code inspiré de celui de Quake 2 (fichier qcommon/pmove.c) */ + //ugly hackpour que le bOnGround ne bug pas sur les monstres + //-> on différenci la taille du joueur et des autres objets pour être sur le sol #define PLAYER_HEIGHT 80 + #define BASE_HEIGHT 5 #define STEPSIZE 10 void PhysicEngine::Move (float eTime) *************** *** 89,92 **** --- 93,101 ---- else if (n->vAccel.y < 0) //si l'objet touche le sol, il faut ramener la gravité à zéro, sinon, l'objet va se retrouver avec une gravité négative très grande (ça l'empeche de sauter notamment) n->vAccel.y = 0; + /*std::cout << n << "\t" ; + std::cout << n->bOnGround; + std::cout << "\t" << n->vAccel << std::endl;*/ + //int red[]={1,0,0}; + //Engine::pEngine->pRenderer->drawDebugArrow(n->vPosition, n->vPosition+n->vAccel*5, red); n->vVelocity = n->vAccel*eTime; //mise a jour des volumes englobants *************** *** 112,116 **** float distx, distz; - StepSlideMove (n, eTime, vVelocity, vPos); vNewPos += vVelocity*eTime; --- 121,124 ---- *************** *** 120,139 **** distz *= distz; float dist = sqrt(distx+distz); ! ! StepSlideMove (n, eTime, vUpVelocity, vUpPos); ! vUpNewPos += vUpVelocity*eTime; ! distx = (vUpNewPos.x - vUpPos.x); ! distx *= distx; ! distz = (vUpNewPos.z - vUpPos.z); ! distz *= distz; ! float updist = sqrt(distx+distz); ! ! if (updist > dist) //on passe l'obstacle ! n->SetPosition(vUpNewPos); ! else //l'obstacle est trop haut ! n->SetPosition(vNewPos); ! //Classification de la position ! if (pLevel->CheckRayMove(n->GetPosition(), n->GetPosition()+Vector3::NEGATIVE_UNIT_Y*PLAYER_HEIGHT, TRACE_RAY, 0).Fraction < 1.0f) n->bOnGround = true; else --- 128,172 ---- distz *= distz; float dist = sqrt(distx+distz); ! ! StepSlideMove (n, eTime, vUpVelocity, vUpPos); ! vUpNewPos += vUpVelocity*eTime; ! distx = (vUpNewPos.x - vUpPos.x); ! distx *= distx; ! distz = (vUpNewPos.z - vUpPos.z); ! distz *= distz; ! float updist = sqrt(distx+distz); ! ! ! if (updist > dist) //on passe l'obstacle ! { ! //std::cout << "time : " << eTime << "\t" << vUpNewPos << std::endl; ! n->SetPosition(vUpNewPos); ! if (vUpVelocity != n->vVelocity && n->GetPhysicCallBack() != NULL) ! { ! //std::cout << "callback" << std::endl; ! //ce ne sont pas les memes, donc il y a eu collision -> appelle de la callback ! n->GetPhysicCallBack()->Collide(NULL, Vector3(0,0,0), Vector3(0,0,0)); ! } ! ! ! } ! else //l'obstacle est trop haut ! { ! //std::cout << "time : " << eTime << "\t" << vNewPos << std::endl; ! n->SetPosition(vNewPos); ! if (vVelocity != n->vVelocity && n->GetPhysicCallBack() != NULL) ! { ! //std::cout << "callback" << std::endl; ! //ce ne sont pas les memes, donc il y a eu collision -> appelle de la callback ! n->GetPhysicCallBack()->Collide(NULL, Vector3(0,0,0), Vector3(0,0,0)); ! } ! ! } ! //Classification de la position ! //FIXME:on fait une differenciation entre le joueur et les autres scenenode. il ne faudrait pas! ! if (n->bIsCamera && pLevel->CheckRayMove(n->GetPosition(), n->GetPosition()+Vector3::NEGATIVE_UNIT_Y*PLAYER_HEIGHT, TRACE_RAY, 0).Fraction < 1.0f) ! n->bOnGround = true; ! else if (!n->bIsCamera && pLevel->CheckRayMove(n->GetPosition(), n->GetPosition()+Vector3::NEGATIVE_UNIT_Y*BASE_HEIGHT, n->pBBox->vMin, n->pBBox->vMax).Fraction < 1.0f) n->bOnGround = true; else Index: scenemanager.cc =================================================================== RCS file: /cvsroot/epfl/tgengine-0.1/scenemanager.cc,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** scenemanager.cc 1 Oct 2004 21:30:28 -0000 1.4 --- scenemanager.cc 10 Oct 2004 20:49:09 -0000 1.5 *************** *** 83,91 **** void SceneManager::_ProcessTimedObject (Mesh* s, float t) { ! if (s->fTime < 0) //l'objet ne tient pas compte du temps return; s->fTime -= t; ! if (s->fTime < 0) //l'objet est arrive en fin de vie { RemoveWorldObject(s); --- 83,91 ---- void SceneManager::_ProcessTimedObject (Mesh* s, float t) { ! if (s->fTime == -1) //l'objet ne tient pas compte du temps return; s->fTime -= t; ! if (s->fTime <= 0) //l'objet est arrive en fin de vie { RemoveWorldObject(s); *************** *** 96,104 **** void SceneManager::_ProcessTimedObject (ParticleEmitter* s, float t) { ! if (s->fTime < 0) //l'objet ne tient pas compte du temps return; s->fTime -= t; ! if (s->fTime < 0) //l'objet est arrive en fin de vie { RemoveParticlesEmitter(s); --- 96,104 ---- void SceneManager::_ProcessTimedObject (ParticleEmitter* s, float t) { ! if (s->fTime < -1) //l'objet ne tient pas compte du temps return; s->fTime -= t; ! if (s->fTime <= 0) //l'objet est arrive en fin de vie { RemoveParticlesEmitter(s); *************** *** 109,120 **** void SceneManager::Render () { - /* next variables are unused - Mesh* obj; - */ float frameInterval = pTimer->GetFrameInterval (); if (pPhysicEngine) pPhysicEngine->Move(frameInterval); ! if(pCamera) { --- 109,117 ---- void SceneManager::Render () { float frameInterval = pTimer->GetFrameInterval (); if (pPhysicEngine) pPhysicEngine->Move(frameInterval); ! if(pCamera) { *************** *** 128,132 **** pLevel->SetCamera(pCamera); pLevel->Render(); ! /*Vector3 Target = pCamera->GetForward(); --- 125,129 ---- pLevel->SetCamera(pCamera); pLevel->Render(); ! /*Vector3 Target = pCamera->GetForward(); *************** *** 256,259 **** --- 253,257 ---- Engine::pRenderer->Render (); #endif + } Index: defs.h =================================================================== RCS file: /cvsroot/epfl/tgengine-0.1/defs.h,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** defs.h 28 Sep 2004 09:44:26 -0000 1.3 --- defs.h 10 Oct 2004 20:49:09 -0000 1.4 *************** *** 11,14 **** --- 11,15 ---- #include <map> #include <sstream> + #include <iomanip> #ifdef TGWIN32 Index: physicengine.h =================================================================== RCS file: /cvsroot/epfl/tgengine-0.1/physicengine.h,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** physicengine.h 26 Sep 2004 13:15:03 -0000 1.1.1.1 --- physicengine.h 10 Oct 2004 20:49:09 -0000 1.2 *************** *** 29,33 **** void Move (float eTime); void StepSlideMove (SceneNode*, float, Vector3&,Vector3); ! Vector3 ClipVelocity (const Vector3& vel, const Vector3 norm); protected: --- 29,33 ---- void Move (float eTime); void StepSlideMove (SceneNode*, float, Vector3&,Vector3); ! void ClipVelocity (Vector3& vel, const Vector3 norm); protected: Index: Makefile =================================================================== RCS file: /cvsroot/epfl/tgengine-0.1/Makefile,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** Makefile 1 Oct 2004 20:24:04 -0000 1.7 --- Makefile 10 Oct 2004 20:49:08 -0000 1.8 *************** *** 3,7 **** ## ! all: linux clean: --- 3,7 ---- ## ! all: linuxDebug clean: --- SoundManager.cc DELETED --- --- SoundManager.h DELETED --- Index: engine.cc =================================================================== RCS file: /cvsroot/epfl/tgengine-0.1/engine.cc,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** engine.cc 30 Sep 2004 10:46:16 -0000 1.2 --- engine.cc 10 Oct 2004 20:49:09 -0000 1.3 *************** *** 263,268 **** if (pGuiManager != NULL || pConsole->GetState()) //on regarde si on a active la 2d pRenderer->End2D(); - - } --- 263,266 ---- Index: scenenode.cc =================================================================== RCS file: /cvsroot/epfl/tgengine-0.1/scenenode.cc,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** scenenode.cc 30 Sep 2004 09:23:16 -0000 1.2 --- scenenode.cc 10 Oct 2004 20:49:09 -0000 1.3 *************** *** 20,23 **** --- 20,25 ---- fTime = -1.0f; bOnGround = false; + bIsCamera = false; + pPhysicCallBack = NULL; } *************** *** 39,42 **** --- 41,46 ---- fTime = -1.0f; bOnGround = false; + bIsCamera = false; + pPhysicCallBack = NULL; } *************** *** 47,50 **** --- 51,59 ---- } + void SceneNode::SetPhysicCallBack(PhysicCallBack* p) + { + pPhysicCallBack = p; + } + void SceneNode::CalculateBoundingVolume () { Index: camera.cc =================================================================== RCS file: /cvsroot/epfl/tgengine-0.1/camera.cc,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** camera.cc 26 Sep 2004 13:15:05 -0000 1.1.1.1 --- camera.cc 10 Oct 2004 20:49:09 -0000 1.2 *************** *** 20,23 **** --- 20,24 ---- bShift = false; + bIsCamera = true; } Index: scenenode.h =================================================================== RCS file: /cvsroot/epfl/tgengine-0.1/scenenode.h,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** scenenode.h 26 Sep 2004 13:15:15 -0000 1.1.1.1 --- scenenode.h 10 Oct 2004 20:49:09 -0000 1.2 *************** *** 9,12 **** --- 9,13 ---- #include "matrice3.h" #include "dlinkednode.h" + #include "physiccallback.h" namespace tg *************** *** 17,25 **** public: bool bNoClip; ! bool bOnGround; SceneNode (); SceneNode (Vector3 p); virtual ~SceneNode () {} virtual void PreRender (float ) = 0; --- 18,28 ---- public: bool bNoClip; ! bool bIsCamera; bool bOnGround; SceneNode (); SceneNode (Vector3 p); + void SetPhysicCallBack(PhysicCallBack*); + inline PhysicCallBack* GetPhysicCallBack() { return pPhysicCallBack; } virtual ~SceneNode () {} virtual void PreRender (float ) = 0; *************** *** 49,52 **** --- 52,58 ---- //protected: Vector3 vPosition; + protected: + PhysicCallBack* pPhysicCallBack; + }; Index: vector3.h =================================================================== RCS file: /cvsroot/epfl/tgengine-0.1/vector3.h,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** vector3.h 26 Sep 2004 13:15:17 -0000 1.1.1.1 --- vector3.h 10 Oct 2004 20:49:09 -0000 1.2 *************** *** 42,47 **** inline float operator [] (int n) { switch (n) { case 0: return x; case 1: return y; case 2: return z;}} ! ! inline friend Vector3 operator+(const Vector3 &v1, const Vector3 &v2) { --- 42,56 ---- inline float operator [] (int n) { switch (n) { case 0: return x; case 1: return y; case 2: return z;}} ! ! inline bool operator != (const Vector3& v) { return (v.x==x&&v.y==y&&v.z==z); } ! ! inline bool equals (const Vector3& v) { ! if ( ((v.x-EPSILON<x) && (v.x+EPSILON>x)) && ! ((v.y-EPSILON<y) && (v.y+EPSILON>y)) && ! ((v.z-EPSILON<z) && (v.y+EPSILON>y))) ! return true; ! return false; ! } ! inline friend Vector3 operator+(const Vector3 &v1, const Vector3 &v2) { |