|
From: julien r. <jul...@us...> - 2004-11-09 18:19:34
|
Update of /cvsroot/epfl/tgengine-0.1 In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27910 Modified Files: boundingbox.cc glrenderer.cc physicengine.cc physicengine.h physicnode.h q3bsp.cc scenemanager.cc scenemanager.h Log Message: collisions Index: physicengine.cc =================================================================== RCS file: /cvsroot/epfl/tgengine-0.1/physicengine.cc,v retrieving revision 1.20 retrieving revision 1.21 diff -C2 -d -r1.20 -r1.21 *** physicengine.cc 7 Nov 2004 19:43:49 -0000 1.20 --- physicengine.cc 9 Nov 2004 18:19:04 -0000 1.21 *************** *** 228,232 **** //TODO: Les objets doivent être classés par leaf et cela doit etre utilise pour le trace (il faudrait extraire l'arbre BSP de la map et l'envoyer au moteur physique, qui s'occuperait d'y rajouter les objets & Co) ! CollisionResult PhysicEngine::Trace (Vector3 Begin, Vector3 End) { //on choppe le resultat du trace sur la map --- 228,232 ---- //TODO: Les objets doivent être classés par leaf et cela doit etre utilise pour le trace (il faudrait extraire l'arbre BSP de la map et l'envoyer au moteur physique, qui s'occuperait d'y rajouter les objets & Co) ! CollisionResult PhysicEngine::Trace (Vector3 Begin, Vector3 End, PhysicNode* edict) { //on choppe le resultat du trace sur la map *************** *** 244,248 **** --- 244,252 ---- for (unsigned int i=0; i<pNodes.size(); i++) { + if (edict == pNodes[i]) //on ne considere pas le node qui a appele le trace + continue; + if (pNodes[i]->GetBBox()->TraceRay(Begin, End, colPoint, colNormal)) { + result.pNode = pNodes[i]; d1 = (colPoint - Begin).Magnitude(); d2 = (result.EndPoint - Begin).Magnitude(); Index: scenemanager.cc =================================================================== RCS file: /cvsroot/epfl/tgengine-0.1/scenemanager.cc,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** scenemanager.cc 6 Nov 2004 17:05:39 -0000 1.13 --- scenemanager.cc 9 Nov 2004 18:19:04 -0000 1.14 *************** *** 96,100 **** ! Vector3 vTarget = pCamera->GetRotation().GetZAxis(); Vector3 vPosition = pCamera->GetPosition(); vTarget = vPosition - vTarget*10000; --- 96,100 ---- ! /*Vector3 vTarget = pCamera->GetRotation().GetZAxis(); Vector3 vPosition = pCamera->GetPosition(); vTarget = vPosition - vTarget*10000; *************** *** 111,116 **** --- 111,135 ---- GLUquadric* pquad = gluNewQuadric(); gluSphere( pquad, 10,10,10); + glPopMatrix();*/ + } + + (*_glActiveTextureARB)(GL_TEXTURE0); + glDisable (GL_TEXTURE_2D); + (*_glActiveTextureARB)(GL_TEXTURE1); + glDisable (GL_TEXTURE_2D); + for (int i=0; i<pDebugSpheres.size (); i++) + { + DebugSphere* s = pDebugSpheres[i]; + glPushMatrix(); + glColor3f(s->pColors[0], s->pColors[1], s->pColors[2]); + glTranslatef(s->vPosition.x, s->vPosition.y, s->vPosition.z); + gluSphere(s->q, s->fD, 10, 10); glPopMatrix(); } + (*_glActiveTextureARB)(GL_TEXTURE0); + glEnable (GL_TEXTURE_2D); + (*_glActiveTextureARB)(GL_TEXTURE1); + glEnable (GL_TEXTURE_2D); + Mesh* m = pFirstObject; Index: physicengine.h =================================================================== RCS file: /cvsroot/epfl/tgengine-0.1/physicengine.h,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** physicengine.h 21 Oct 2004 21:18:28 -0000 1.4 --- physicengine.h 9 Nov 2004 18:19:04 -0000 1.5 *************** *** 43,47 **** void UpdatePosition (); ! CollisionResult Trace(Vector3 Begin, Vector3 End); protected: std::vector<PhysicNode*> pNodes; --- 43,53 ---- void UpdatePosition (); ! /* ! * Lance un rayon a travers la map et les modeles et renvoie des informations de collision ! * @param Vector3 le point de debut du rayon ! * @param Vector3 le point de fin du rayon ! * @param PhysicNode le physicnode qui demande le trace -> le trace n'est pas bloqué par ce physicnode ! */ ! CollisionResult Trace(Vector3 Begin, Vector3 End, PhysicNode* edict=NULL); protected: std::vector<PhysicNode*> pNodes; Index: scenemanager.h =================================================================== RCS file: /cvsroot/epfl/tgengine-0.1/scenemanager.h,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** scenemanager.h 21 Oct 2004 21:18:28 -0000 1.4 --- scenemanager.h 9 Nov 2004 18:19:04 -0000 1.5 *************** *** 18,21 **** --- 18,31 ---- { + struct DebugSphere + { + DebugSphere () { vPosition.Null(); fD = 10.0f; pColors[0] = pColors[1] = pColors[2] = pColors[3] = 1.0f; q = gluNewQuadric();} + ~DebugSphere () { gluDeleteQuadric(q); } + GLUquadric* q; + Vector3 vPosition; + float fD; + float pColors[4]; + }; + class Engine; *************** *** 39,42 **** --- 49,54 ---- void AddPointLight (PointLight*); void RemovePointLight (PointLight*); + + void AddDebugSphere (DebugSphere* s) { pDebugSpheres.push_back(s); } /**Ajoute un objet qui sera detruit (delete) apres 'time' secondes * Cette fonction ne test PAS si l'objet existe deja dans la liste ! (-> risque de duplication) *************** *** 58,62 **** void _RenderLightedMesh (Mesh* m); void _RenderLight (PointLight*); ! Mesh* pFirstObject; Mesh* pCurrentObject; --- 70,76 ---- void _RenderLightedMesh (Mesh* m); void _RenderLight (PointLight*); ! ! std::vector<DebugSphere*> pDebugSpheres; ! Mesh* pFirstObject; Mesh* pCurrentObject; Index: q3bsp.cc =================================================================== RCS file: /cvsroot/epfl/tgengine-0.1/q3bsp.cc,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** q3bsp.cc 6 Nov 2004 17:05:39 -0000 1.9 --- q3bsp.cc 9 Nov 2004 18:19:04 -0000 1.10 *************** *** 1131,1135 **** void Q3Bsp::Render() { ! static float angle = 0.0f; angle += 0.01f; Vector3 vObjectLightPosition(300*cos(angle),50,300*sin(angle)); --- 1131,1135 ---- void Q3Bsp::Render() { ! /*static float angle = 0.0f; angle += 0.01f; Vector3 vObjectLightPosition(300*cos(angle),50,300*sin(angle)); *************** *** 1151,1155 **** glTranslatef(vObjectLightPosition2.x, vObjectLightPosition2.y, vObjectLightPosition2.z); gluSphere( pquad, 10,10,10); ! glPopMatrix(); (*_glActiveTextureARB)(GL_TEXTURE0); glEnable(GL_TEXTURE_2D); --- 1151,1155 ---- glTranslatef(vObjectLightPosition2.x, vObjectLightPosition2.y, vObjectLightPosition2.z); gluSphere( pquad, 10,10,10); ! glPopMatrix();*/ (*_glActiveTextureARB)(GL_TEXTURE0); glEnable(GL_TEXTURE_2D); *************** *** 1158,1162 **** RenderBSP (); ! if (*iBump) { glEnable(GL_BLEND); --- 1158,1162 ---- RenderBSP (); ! /*if (*iBump) { glEnable(GL_BLEND); *************** *** 1170,1174 **** glDisable (GL_BLEND); //_RenderLights (); ! } } --- 1170,1174 ---- glDisable (GL_BLEND); //_RenderLights (); ! }*/ } Index: glrenderer.cc =================================================================== RCS file: /cvsroot/epfl/tgengine-0.1/glrenderer.cc,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** glrenderer.cc 7 Nov 2004 11:27:47 -0000 1.14 --- glrenderer.cc 9 Nov 2004 18:19:04 -0000 1.15 *************** *** 1067,1070 **** --- 1067,1071 ---- #ifdef DEBUG if (!mesh->bCamera) { + glLineWidth(2.0f); Vector3 fwd, rgt, up; //mesh->GetRotation().ToAngleVectors(fwd, rgt, up); *************** *** 1091,1094 **** --- 1092,1096 ---- glVertex3fv (&up.x); glEnd (); + glLineWidth(1.0f); } #endif *************** *** 1869,1872 **** --- 1871,1884 ---- } glEnd (); + + + glPushMatrix(); + Vector3 vb = b->vWorldOrigin + b->vBSCenter; + glTranslatef(vb.x, vb.y, vb.z); + GLUquadric* pQ = gluNewQuadric(); + gluSphere(pQ, b->fBSRadius, 10, 10); + gluDeleteQuadric(pQ); + glPopMatrix(); + if (!bWireFrame) glPolygonMode (GL_FRONT_AND_BACK, GL_FILL); Index: physicnode.h =================================================================== RCS file: /cvsroot/epfl/tgengine-0.1/physicnode.h,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** physicnode.h 28 Oct 2004 21:10:16 -0000 1.3 --- physicnode.h 9 Nov 2004 18:19:04 -0000 1.4 *************** *** 44,48 **** inline bool Clip () { return bClip; } inline void SetClip (bool b) { bClip = b; } ! /** * Informations sur la position de l'objet par rapport au sol --- 44,48 ---- inline bool Clip () { return bClip; } inline void SetClip (bool b) { bClip = b; } ! /** * Informations sur la position de l'objet par rapport au sol *************** *** 124,127 **** --- 124,128 ---- bool bClip; bool bOnGround; + bool bBlockTrace; Vector3 vAccel; Index: boundingbox.cc =================================================================== RCS file: /cvsroot/epfl/tgengine-0.1/boundingbox.cc,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** boundingbox.cc 7 Nov 2004 19:43:48 -0000 1.3 --- boundingbox.cc 9 Nov 2004 18:19:04 -0000 1.4 *************** *** 126,130 **** //calcul de l'intersection Vector3 D = end.Normalize(); ! Vector3 EO = vWorldOrigin - begin; float v = EO*D; float disc = fBSRadius*fBSRadius - (EO*EO - v*v); --- 126,130 ---- //calcul de l'intersection Vector3 D = end.Normalize(); ! Vector3 EO = (vWorldOrigin+vBSCenter) - begin; float v = EO*D; float disc = fBSRadius*fBSRadius - (EO*EO - v*v); *************** *** 141,188 **** bool BoundingBox::TraceRay (Vector3 begin, Vector3 end, Vector3& colPoint, Vector3& colNormal) { ! float startFraction = -1.0f; ! float endFraction = 1.0f; ! bool startsOut = false; ! bool endsOut = false; ! ! for (unsigned int i=0; i<6; i++) ! { ! float startDistance = (begin*pPlanes[i].vNormal) - pPlanes[i].fD; ! float endDistance = (end*pPlanes[i].vNormal) - pPlanes[i].fD; ! ! if (startDistance > 0) startsOut = true; ! if (endDistance > 0) endsOut = true; ! ! if (startDistance > 0 && endDistance > 0) //les deux sont en dehors de la boite ! return false; ! if (startDistance <= 0 && endDistance <= 0) //les deux sont derriere ce plan ! continue; ! ! if (startDistance > endDistance) ! { ! float fraction = (startDistance - EPSILON) / (startDistance - endDistance); ! if (fraction > startFraction) ! { ! startFraction = fraction; ! } ! } ! else ! { ! float fraction = (startDistance + EPSILON) / (startDistance - endDistance); ! if (fraction < endFraction) ! { ! endFraction = fraction; ! } ! } ! } ! ! if (startFraction < endFraction) { ! if (startFraction > -1) ! { ! return true; ! } } ! return false; } --- 141,152 ---- bool BoundingBox::TraceRay (Vector3 begin, Vector3 end, Vector3& colPoint, Vector3& colNormal) { ! /*bool col = false; ! for (int i=0; i<6; i++) { ! if (pPlanes[i].IntersectRay(begin,end,colPoint)) ! col = true; } ! return col;*/ ! return TraceSphereRay(begin, end, colPoint); } |