Update of /cvsroot/epfl/tgengine-0.1 In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27717 Modified Files: defs.h glrenderer.cc glrenderernv15.cc mesh.cc physicengine.cc physicengine.h q3bsp.cc scenemanager.cc scenenode.cc scenenode.h Log Message: Code cleaning Index: physicengine.cc =================================================================== RCS file: /cvsroot/epfl/tgengine-0.1/physicengine.cc,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** physicengine.cc 10 Oct 2004 21:11:55 -0000 1.9 --- physicengine.cc 15 Oct 2004 13:59:04 -0000 1.10 *************** *** 11,15 **** Engine::pVarManager->AddVar("gravity", 800); ! fGravity = &Engine::pVarManager->GetVar("gravity")->floatValue; //pFirstNode = NULL; //pCurrentNode = NULL; --- 11,15 ---- Engine::pVarManager->AddVar("gravity", 800); ! pGravity = &Engine::pVarManager->GetVar("gravity")->floatValue; //pFirstNode = NULL; //pCurrentNode = NULL; *************** *** 90,96 **** //on ajoute la gravite if (!n->bOnGround && !n->bNoClip) ! n->vAccel.y -= (*fGravity); ! 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; --- 90,96 ---- //on ajoute la gravite if (!n->bOnGround && !n->bNoClip) ! n->AddYAccel(-(*pGravity)); ! else if (n->GetYAccel() < 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->SetYAccel(0.0f); /*std::cout << n << "\t" ; std::cout << n->bOnGround; *************** *** 98,102 **** //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 n->CalculateBoundingVolume(); --- 98,102 ---- //int red[]={1,0,0}; //Engine::pEngine->pRenderer->drawDebugArrow(n->vPosition, n->vPosition+n->vAccel*5, red); ! n->SetVelocity(n->GetAccel()*eTime); //mise a jour des volumes englobants n->CalculateBoundingVolume(); *************** *** 104,108 **** if (n->bNoClip) { ! n->SetPosition(n->GetPosition()+n->vVelocity*eTime); continue; } --- 104,108 ---- if (n->bNoClip) { ! n->SetPosition(n->GetPosition()+n->GetVelocity()*eTime); continue; } *************** *** 113,118 **** ////TODO: lorsqu'on monte les escaliers, ça se fait par petit saut (normal, on ajoute 10 a la position en un coup. //Il faudrait faire ça de manière à ce qu'on ait l'impression de glisser sur les escaliers ! Vector3 vVelocity = n->vVelocity; ! Vector3 vUpVelocity = n->vVelocity; Vector3 vPos = n->GetPosition(); Vector3 vNewPos = vPos; --- 113,118 ---- ////TODO: lorsqu'on monte les escaliers, ça se fait par petit saut (normal, on ajoute 10 a la position en un coup. //Il faudrait faire ça de manière à ce qu'on ait l'impression de glisser sur les escaliers ! Vector3 vVelocity = n->GetVelocity(); ! Vector3 vUpVelocity = n->GetVelocity(); Vector3 vPos = n->GetPosition(); Vector3 vNewPos = vPos; *************** *** 142,146 **** //std::cout << "time : " << eTime << "\t" << vUpNewPos << std::endl; n->SetPosition(vUpNewPos); ! if (vUpVelocity != n->vVelocity && n->GetPhysicCallBack() != NULL) { //std::cout << "callback" << std::endl; --- 142,146 ---- //std::cout << "time : " << eTime << "\t" << vUpNewPos << std::endl; n->SetPosition(vUpNewPos); ! if (vUpVelocity != n->GetVelocity() && n->GetPhysicCallBack() != NULL) { //std::cout << "callback" << std::endl; *************** *** 155,159 **** //std::cout << "time : " << eTime << "\t" << vNewPos << std::endl; n->SetPosition(vNewPos); ! if (vVelocity != n->vVelocity && n->GetPhysicCallBack() != NULL) { //std::cout << "callback" << std::endl; --- 155,159 ---- //std::cout << "time : " << eTime << "\t" << vNewPos << std::endl; n->SetPosition(vNewPos); ! if (vVelocity != n->GetVelocity() && n->GetPhysicCallBack() != NULL) { //std::cout << "callback" << std::endl; *************** *** 174,178 **** } ! n->vVelocity.Null(); } } --- 174,178 ---- } ! n->SetVelocity(Vector3::ZERO); } } Index: mesh.cc =================================================================== RCS file: /cvsroot/epfl/tgengine-0.1/mesh.cc,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** mesh.cc 26 Sep 2004 13:15:12 -0000 1.1.1.1 --- mesh.cc 15 Oct 2004 13:59:04 -0000 1.2 *************** *** 7,12 **** { _TG_INIT_DLINKEDNODE(NULL, NULL) - iPhysicFlags |= M_RIGIDBODY | M_BSPHERE; - iRenderFlags = 0; pColor[0] = 1; pColor[1] = 1; --- 7,10 ---- Index: scenemanager.cc =================================================================== RCS file: /cvsroot/epfl/tgengine-0.1/scenemanager.cc,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** scenemanager.cc 10 Oct 2004 20:49:09 -0000 1.5 --- scenemanager.cc 15 Oct 2004 13:59:04 -0000 1.6 *************** *** 66,71 **** { //on regarde si le nouveau point de collision est plus proche de la caméra que l'ancien point de collision ! d1 = (colPoint - pCamera->vPosition).Magnitude(); ! d2 = (result.EndPoint - pCamera->vPosition).Magnitude(); if ( d1 < d2 ) { --- 66,71 ---- { //on regarde si le nouveau point de collision est plus proche de la caméra que l'ancien point de collision ! d1 = (colPoint - pCamera->GetPosition()).Magnitude(); ! d2 = (result.EndPoint - pCamera->GetPosition()).Magnitude(); if ( d1 < d2 ) { *************** *** 174,178 **** m->pBBox->CalculatePlanes(); m->iLeaf = pLevel->FindLeaf(m->GetPosition()); ! if ((!(m->iRenderFlags & M_UNVISIBLE)) && (pLevel->IsVisible(m->iLeaf) || m->bCamera)) { --- 174,178 ---- m->pBBox->CalculatePlanes(); m->iLeaf = pLevel->FindLeaf(m->GetPosition()); ! if ((pLevel->IsVisible(m->iLeaf) || m->bCamera)) { *************** *** 196,200 **** do { ! if ((!(m->iRenderFlags & M_UNVISIBLE)) && pLevel->IsVisible(m->iLeaf)) { Engine::pRenderer->RenderMeshShadow(m); --- 196,200 ---- do { ! if (pLevel->IsVisible(m->iLeaf)) { Engine::pRenderer->RenderMeshShadow(m); *************** *** 242,246 **** p->PreRender(frameInterval); p->iLeaf = pLevel->FindLeaf(p->GetPosition()); ! if ((!(p->iRenderFlags & M_UNVISIBLE)) && pLevel->IsVisible(p->iLeaf)) { Engine::pRenderer->RenderParticles(p); --- 242,246 ---- p->PreRender(frameInterval); p->iLeaf = pLevel->FindLeaf(p->GetPosition()); ! if (pLevel->IsVisible(p->iLeaf)) { Engine::pRenderer->RenderParticles(p); Index: q3bsp.cc =================================================================== RCS file: /cvsroot/epfl/tgengine-0.1/q3bsp.cc,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** q3bsp.cc 10 Oct 2004 21:11:55 -0000 1.6 --- q3bsp.cc 15 Oct 2004 13:59:04 -0000 1.7 *************** *** 799,803 **** bool Q3Bsp::IsVisible(int leaf) { ! int iCamLeaf = FindLeaf(pCamera->vPosition); int iCamCluster = pLeafs[iCamLeaf].cluster; int iTestCluster = pLeafs[leaf].cluster; --- 799,803 ---- bool Q3Bsp::IsVisible(int leaf) { ! int iCamLeaf = FindLeaf(pCamera->GetPosition()); int iCamCluster = pLeafs[iCamLeaf].cluster; int iTestCluster = pLeafs[leaf].cluster; *************** *** 1002,1006 **** memset (pVisibleFaces, 0, sizeof(bool)*numOfFaces); ! int iCamLeaf = FindLeaf(pCamera->vPosition); int iCamCluster = pLeafs[iCamLeaf].cluster; for (int i=0; i<numOfLeafs; i++) --- 1002,1006 ---- memset (pVisibleFaces, 0, sizeof(bool)*numOfFaces); ! int iCamLeaf = FindLeaf(pCamera->GetPosition()); int iCamCluster = pLeafs[iCamLeaf].cluster; for (int i=0; i<numOfLeafs; i++) Index: scenenode.cc =================================================================== RCS file: /cvsroot/epfl/tgengine-0.1/scenenode.cc,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** scenenode.cc 10 Oct 2004 20:49:09 -0000 1.3 --- scenenode.cc 15 Oct 2004 13:59:04 -0000 1.4 *************** *** 9,18 **** vAccel.Null(); - iPhysicFlags = 0; - iRenderFlags = 0; - pBBox = new BoundingBox (); - qRotation.SetRotation(20,0,1,0); - matRotation.identity(); vEuler.Null(); --- 9,13 ---- *************** *** 30,39 **** vVelocity.Null(); vAccel.Null(); - iPhysicFlags = 0; - iRenderFlags = 0; pBBox = new BoundingBox (); - qRotation.SetRotation(0,0,1,0); - matRotation.identity(); vEuler.Null(); --- 25,30 ---- Index: glrenderer.cc =================================================================== RCS file: /cvsroot/epfl/tgengine-0.1/glrenderer.cc,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** glrenderer.cc 30 Sep 2004 09:23:16 -0000 1.6 --- glrenderer.cc 15 Oct 2004 13:59:04 -0000 1.7 *************** *** 789,795 **** #define __ROT_EULER #ifdef __ROT_EULER ! glRotatef(s->vEuler.x, 1, 0, 0); ! glRotatef(s->vEuler.y, 0, 1, 0); ! glRotatef(s->vEuler.z, 0, 0, 1); #else const Vector3& tmp = s->qRotation.GetRotationAxis(); --- 789,795 ---- #define __ROT_EULER #ifdef __ROT_EULER ! glRotatef(s->GetXRot(), 1, 0, 0); ! glRotatef(s->GetYRot(), 0, 1, 0); ! glRotatef(s->GetZRot(), 0, 0, 1); #else const Vector3& tmp = s->qRotation.GetRotationAxis(); Index: physicengine.h =================================================================== RCS file: /cvsroot/epfl/tgengine-0.1/physicengine.h,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** physicengine.h 10 Oct 2004 20:49:09 -0000 1.2 --- physicengine.h 15 Oct 2004 13:59:04 -0000 1.3 *************** *** 35,39 **** Q3Bsp* pLevel; float fOverBounce; ! float* fGravity; }; --- 35,39 ---- Q3Bsp* pLevel; float fOverBounce; ! float* pGravity; }; Index: scenenode.h =================================================================== RCS file: /cvsroot/epfl/tgengine-0.1/scenenode.h,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** scenenode.h 10 Oct 2004 20:49:09 -0000 1.2 --- scenenode.h 15 Oct 2004 13:59:04 -0000 1.3 *************** *** 28,57 **** virtual void PreRender (float ) = 0; virtual void SetPosition (Vector3 v); Vector3 GetPosition () { return vPosition; } virtual void CalculateBoundingVolume (); virtual bool Trace (Vector3 Begin, Vector3 End, Vector3& colPoint, Vector3& colNormal); - uint32 iPhysicFlags; - uint32 iRenderFlags; - BoundingBox* pBBox; - Quaternion qRotation; - mat3 matRotation; - Vector3 vEuler; - - Vector3 vVelocity; - Vector3 vAccel; - int iLeaf; //utilise par les noeuds a duree limite (SceneManager::AddTimed). Inferieur a 0 si noeud non-limite dans le temps float fTime; - //protected: - Vector3 vPosition; protected: PhysicCallBack* pPhysicCallBack; }; --- 28,92 ---- virtual void PreRender (float ) = 0; + /* Position */ virtual void SetPosition (Vector3 v); Vector3 GetPosition () { return vPosition; } + /* Acceleration */ + Vector3 GetAccel () { return vAccel; } + virtual void SetAccel (const Vector3& v) { vAccel = v; } + inline float GetXAccel () { return vAccel.x; } + inline float GetYAccel () { return vAccel.y; } + inline float GetZAccel () { return vAccel.z; } + inline void SetXAccel (float f) { vAccel.x = f; } + inline void SetYAccel (float f) { vAccel.y = f; } + inline void SetZAccel (float f) { vAccel.z = f; } + inline void AddXAccel (float f) { vAccel.x += f; } + inline void AddYAccel (float f) { vAccel.y += f; } + inline void AddZAccel (float f) { vAccel.z += f; } + + /* Rotation */ + Vector3 GetEuler () { return vEuler; } + virtual void SetEuler (const Vector3& v) { vEuler = v; } + inline float GetXRot () { return vEuler.x; } + inline float GetYRot () { return vEuler.y; } + inline float GetZRot () { return vEuler.z; } + inline void SetXRot (float f) { vEuler.x = f; } + inline void SetYRot (float f) { vEuler.y = f; } + inline void SetZRot (float f) { vEuler.z = f; } + inline void AddXRot (float f) { vEuler.x += f; } + inline void AddYRot (float f) { vEuler.y += f; } + inline void AddZRot (float f) { vEuler.z += f; } + + /* Vitesse */ + Vector3 GetVelocity () { return vVelocity; } + virtual void SetVelocity (const Vector3& v) { vVelocity = v; } + inline float GetXVelocity () { return vVelocity.x; } + inline float GetYVelocity () { return vVelocity.y; } + inline float GetZVelocity () { return vVelocity.z; } + inline void SetXVelocity (float f) { vVelocity.x = f; } + inline void SetYVelocity (float f) { vVelocity.y = f; } + inline void SetZVelocity (float f) { vVelocity.z = f; } + inline void AddXVelocity (float f) { vVelocity.x += f; } + inline void AddYVelocity (float f) { vVelocity.y += f; } + inline void AddZVelocity (float f) { vVelocity.z += f; } + + + /* Autres */ virtual void CalculateBoundingVolume (); virtual bool Trace (Vector3 Begin, Vector3 End, Vector3& colPoint, Vector3& colNormal); BoundingBox* pBBox; int iLeaf; //utilise par les noeuds a duree limite (SceneManager::AddTimed). Inferieur a 0 si noeud non-limite dans le temps float fTime; protected: PhysicCallBack* pPhysicCallBack; + + Vector3 vEuler; + Vector3 vPosition; + Vector3 vAccel; + Vector3 vVelocity; }; Index: defs.h =================================================================== RCS file: /cvsroot/epfl/tgengine-0.1/defs.h,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** defs.h 10 Oct 2004 20:49:09 -0000 1.4 --- defs.h 15 Oct 2004 13:59:03 -0000 1.5 *************** *** 63,79 **** enum { - M_RIGIDBODY = 1, //l'objet va être considéré comme ayant une présence physique - M_BSPHERE, //il est inscrit dans une Sphere - }; - - enum - { - M_BUMPMAPPED = 1, - M_UNVISIBLE = 2, - M_CAMERA = 3 - }; - - enum - { POINT_ON_PLANE = 1, POINT_IN_FRONT_OF_PLANE = 2, --- 63,66 ---- Index: glrenderernv15.cc =================================================================== RCS file: /cvsroot/epfl/tgengine-0.1/glrenderernv15.cc,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** glrenderernv15.cc 27 Sep 2004 21:34:05 -0000 1.4 --- glrenderernv15.cc 15 Oct 2004 13:59:04 -0000 1.5 *************** *** 59,65 **** glLoadIdentity(); ! glRotatef(-mesh->vEuler.x, 1, 0, 0); ! glRotatef(-mesh->vEuler.y, 0, 1, 0); ! glRotatef(-mesh->vEuler.z, 0, 0, 1); glTranslatef(-mesh->GetPosition().x, -mesh->GetPosition().y, -mesh->GetPosition().z); --- 59,65 ---- glLoadIdentity(); ! glRotatef(-mesh->GetXRot(), 1, 0, 0); ! glRotatef(-mesh->GetYRot(), 0, 1, 0); ! glRotatef(-mesh->GetZRot(), 0, 0, 1); glTranslatef(-mesh->GetPosition().x, -mesh->GetPosition().y, -mesh->GetPosition().z); |