|
From: julien r. <jul...@us...> - 2004-11-19 12:04:14
|
Update of /cvsroot/epfl/tgengine-0.1 In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5723 Modified Files: camera.h glrenderer.cc md5instance.cc md5instance.h md5mesh10.cc md5mesh10.h mesh.h particleemitter.cc particleemitter.h physicengine.cc physicnode.cc physicnode.h scenemanager.cc scenenode.h Log Message: rockets Index: physicengine.cc =================================================================== RCS file: /cvsroot/epfl/tgengine-0.1/physicengine.cc,v retrieving revision 1.27 retrieving revision 1.28 diff -C2 -d -r1.27 -r1.28 *** physicengine.cc 17 Nov 2004 23:21:42 -0000 1.27 --- physicengine.cc 19 Nov 2004 12:04:04 -0000 1.28 *************** *** 42,46 **** if (trace.AllSolid) { ! vVelocity.y = 0; return; } --- 42,49 ---- if (trace.AllSolid) { ! //vVelocity.y = 0; ! //FIXME: ça ne semble plus poser problème et ça évite les objets traversant les murs ! //en fait, on devrait plutot tenter de renvoyer les objets en arriere jusqu'a ce que AllSolid devienne faux (en stockant la position précédente des objets et en y revenant par exemple ! vVelocity.Null(); return; } *************** *** 143,149 **** if (trace.AllSolid) vUpNewPos = trace.EndPoint; - //appel de la callback pour les collisions avec la map. Ca permet aux objets style rockets de savoir s'ils doivent exploser - if (trace.Fraction < 1.0f && n->GetPhysicCallBack() != NULL) - n->GetPhysicCallBack()->Collide(trace.pNode, trace.EndPoint, trace.Normal); if (updist > dist) //on passe l'obstacle --- 146,149 ---- *************** *** 200,214 **** //on a un objet qui doit subir les forces et les collisions ! Vector3 vVelocity = n->GetVelocity(); ! if (!n->OnGround()) ! vVelocity.y = -(*pGravity); ! else if (vVelocity.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) ! vVelocity.y = 0; ! //std::cout << "OnGround : " << n->OnGround(); ! //std::cout << "Accel : \t" << n->GetAccel() << std::endl; ! //int red[]={1,0,0}; ! //Engine::pEngine->pRenderer->drawDebugArrow(n->vPosition, n->vPosition+n->vAccel*5, red); ! //std::cout << n->GetVelocity() << std::endl; ! n->SetVelocity(vVelocity); //mise a jour des volumes englobants n->CalculateBoundingVolume(); --- 200,218 ---- //on a un objet qui doit subir les forces et les collisions ! if (n->GetGravityFactor() > EPSILON) //on évite de s'amuser si l'objet se fout de la gravité ! { ! Vector3 vVelocity = n->GetVelocity(); ! if (!n->OnGround()) ! vVelocity.y = -(*pGravity)*n->GetGravityFactor(); ! else if (vVelocity.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) ! vVelocity.y = 0; ! ! //std::cout << "OnGround : " << n->OnGround(); ! //std::cout << "Accel : \t" << n->GetAccel() << std::endl; ! //int red[]={1,0,0}; ! //Engine::pEngine->pRenderer->drawDebugArrow(n->vPosition, n->vPosition+n->vAccel*5, red); ! //std::cout << n->GetVelocity() << std::endl; ! n->SetVelocity(vVelocity); ! } //mise a jour des volumes englobants n->CalculateBoundingVolume(); *************** *** 217,222 **** --- 221,234 ---- if (pLevel) { + //appel de la callback pour les collisions avec la map. Ca permet aux objets style rockets de savoir s'ils doivent exploser + CollisionResult trace = Trace(n->GetPosition(), n->GetPosition()+n->GetVelocity()*eTime, n->GetBBox()->vMin, n->GetBBox()->vMax, n); + if ((trace.Fraction < 1.0f || trace.AllSolid) && n->GetPhysicCallBack() != NULL) + n->GetPhysicCallBack()->Collide(trace.pNode, trace.EndPoint, trace.Normal); + + if (n==NULL) //il est possible que l'appel a la callback entraine la suppression de l'objet (la rocket explose), on doit donc verifier que le pointeur soit toujours valide avant de continuer + continue; _TryToStep(n, eTime); + Quaternion q = n->GetRotationVelocity()*eTime; q.Normalize(); Index: particleemitter.cc =================================================================== RCS file: /cvsroot/epfl/tgengine-0.1/particleemitter.cc,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** particleemitter.cc 17 Nov 2004 23:12:38 -0000 1.3 --- particleemitter.cc 19 Nov 2004 12:04:04 -0000 1.4 *************** *** 4,10 **** { ! ParticleEmitter::ParticleEmitter (int numParticles, Vector3 vOrig, Material* m, float s) : SceneNode (vOrig) { _TG_INIT_DLINKEDNODE(NULL, NULL) iNumParticles = numParticles; --- 4,12 ---- { ! ParticleEmitter::ParticleEmitter (int numParticles, Vector3 vOrig, Texture* m, float s) : SceneNode (vOrig) { _TG_INIT_DLINKEDNODE(NULL, NULL) + + fTime = -1; iNumParticles = numParticles; *************** *** 23,31 **** fRandomMultiplier = 1.0f; ! pMat = m; ! for(int i=0; i<iNumParticles; i++) { ! pQuads[i] = new float[7]; pPartArray[i].active = true; pPartArray[i].life = fLife; --- 25,40 ---- fRandomMultiplier = 1.0f; ! pTex = m; ! ! bInitialized = false; ! } ! ! void ParticleEmitter::Initialize () ! { for(int i=0; i<iNumParticles; i++) { ! if (!bInitialized) //on ne recrée pas le tableau si ça a déjà été fait ! pQuads[i] = new float[7]; ! pPartArray[i].active = true; pPartArray[i].life = fLife; *************** *** 52,61 **** pPartArray[i].vPosition = vPosition; } ! } void ParticleEmitter::PreRender (float elapsedTime) { ! static Particle* pTemp; vPosition += vSpeed*elapsedTime; --- 61,72 ---- pPartArray[i].vPosition = vPosition; } ! bInitialized = true; } void ParticleEmitter::PreRender (float elapsedTime) { ! if (!bInitialized) ! return; ! Particle* pTemp; vPosition += vSpeed*elapsedTime; *************** *** 67,71 **** { pTemp->vPosition += pPartArray[i].vSpeed*elapsedTime; - pTemp->life -= pTemp->fade*elapsedTime; --- 78,81 ---- Index: scenemanager.cc =================================================================== RCS file: /cvsroot/epfl/tgengine-0.1/scenemanager.cc,v retrieving revision 1.19 retrieving revision 1.20 diff -C2 -d -r1.19 -r1.20 *** scenemanager.cc 17 Nov 2004 23:12:39 -0000 1.19 --- scenemanager.cc 19 Nov 2004 12:04:04 -0000 1.20 *************** *** 39,43 **** void SceneManager::_ProcessTimedObject (ParticleEmitter* s, float t) { ! if (s->fTime < -1) //l'objet ne tient pas compte du temps return; --- 39,43 ---- void SceneManager::_ProcessTimedObject (ParticleEmitter* s, float t) { ! if (s->fTime == -1) //l'objet ne tient pas compte du temps return; *************** *** 46,50 **** { RemoveParticlesEmitter(s); ! //delete s; } } --- 46,50 ---- { RemoveParticlesEmitter(s); ! delete s; } } *************** *** 196,200 **** Engine::pRenderer->End2D(); #endif - ParticleEmitter* p = pFirstEmitter; if (p != NULL) --- 196,199 ---- Index: physicnode.cc =================================================================== RCS file: /cvsroot/epfl/tgengine-0.1/physicnode.cc,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** physicnode.cc 17 Nov 2004 23:12:39 -0000 1.10 --- physicnode.cc 19 Nov 2004 12:04:04 -0000 1.11 *************** *** 14,17 **** --- 14,18 ---- vPosition.Null(); vAccel.Null(); + fGravityFactor = 1.0f; //vEuler.Null(); Index: physicnode.h =================================================================== RCS file: /cvsroot/epfl/tgengine-0.1/physicnode.h,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** physicnode.h 17 Nov 2004 23:12:39 -0000 1.8 --- physicnode.h 19 Nov 2004 12:04:04 -0000 1.9 *************** *** 31,34 **** --- 31,37 ---- SceneNode* GetSceneNode (int i = 0) { return vNodes[i]; } + inline float GetGravityFactor () { return fGravityFactor; } + inline void SetGravityFactor (float f) { fGravityFactor = f; } + /** * Retourne un pointeur sur la classe servant de callback en cas de collision *************** *** 129,132 **** --- 132,137 ---- bool bOnGround; bool bBlockTrace; + /* Comment cet objet est-il influencé par la gravité */ + float fGravityFactor; Vector3 vAccel; Index: particleemitter.h =================================================================== RCS file: /cvsroot/epfl/tgengine-0.1/particleemitter.h,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** particleemitter.h 17 Nov 2004 23:12:38 -0000 1.3 --- particleemitter.h 19 Nov 2004 12:04:04 -0000 1.4 *************** *** 19,26 **** public: ! ParticleEmitter (int numParticles, Vector3 vOrig, Material*, float s); virtual ~ParticleEmitter() {} void PreRender (float ); void SetPosition (Vector3 pos) { vPosition = pos; } --- 19,28 ---- public: ! ParticleEmitter (int numParticles, Vector3 vOrig, Texture*, float s); virtual ~ParticleEmitter() {} void PreRender (float ); + + void Initialize (); void SetPosition (Vector3 pos) { vPosition = pos; } *************** *** 53,57 **** void SetShape (EmitterShape* s) { pShape = s; } ! Material* GetMaterial () { return pMat; } protected: int iNumParticles; --- 55,59 ---- void SetShape (EmitterShape* s) { pShape = s; } ! Texture* GetTexture () { return pTex; } protected: int iNumParticles; *************** *** 63,71 **** float** pQuads; //les quads qui doivent être rendus ! Particle* pPartArray; EmitterShape* pShape; ! Material* pMat; Vector3 vSpeed; --- 65,74 ---- float** pQuads; //les quads qui doivent être rendus ! ! bool bInitialized; Particle* pPartArray; EmitterShape* pShape; ! Texture* pTex; Vector3 vSpeed; Index: mesh.h =================================================================== RCS file: /cvsroot/epfl/tgengine-0.1/mesh.h,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** mesh.h 17 Nov 2004 23:12:38 -0000 1.3 --- mesh.h 19 Nov 2004 12:04:04 -0000 1.4 *************** *** 70,73 **** --- 70,79 ---- virtual void DrawVisibleEdges () = 0; + + /** + * Permet d'attacher des scenode à des joints ou a des mesh + * Ne __pas__ attacher de scenenode étant déjà attaché à un physicnode + */ + virtual void Attach (const std::string& jointName, SceneNode* s) = 0; *************** *** 86,89 **** --- 92,96 ---- float** pTexCoordList; Face* pTrianglesList; + std::vector<SceneNode*> vNodes; }; Index: md5mesh10.h =================================================================== RCS file: /cvsroot/epfl/tgengine-0.1/md5mesh10.h,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** md5mesh10.h 17 Nov 2004 23:12:38 -0000 1.7 --- md5mesh10.h 19 Nov 2004 12:04:04 -0000 1.8 *************** *** 44,47 **** --- 44,48 ---- inline Quaternion& GetJointOrientation(int i) { return pJoints[i].qOrientation; } inline int GetNumBaseJoints() { return iNumBaseJoints; } + inline std::string GetJointName(int i) { return pJoints[i].sName; } //Meshes informations Index: camera.h =================================================================== RCS file: /cvsroot/epfl/tgengine-0.1/camera.h,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** camera.h 17 Nov 2004 23:12:37 -0000 1.5 --- camera.h 19 Nov 2004 12:04:04 -0000 1.6 *************** *** 41,47 **** bool bShift; ! Vector3 GetForward () { return vForward; } ! Vector3 GetUp () { return vUp; } ! Vector3 GetRight () { return vRight; } Frustum frustum; --- 41,47 ---- bool bShift; ! Vector3 GetForward () { return -qRotation.GetZAxis(); } ! Vector3 GetUp () { return qRotation.GetYAxis(); } ! Vector3 GetRight () { return qRotation.GetXAxis(); } Frustum frustum; Index: md5instance.h =================================================================== RCS file: /cvsroot/epfl/tgengine-0.1/md5instance.h,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** md5instance.h 17 Nov 2004 23:12:38 -0000 1.9 --- md5instance.h 19 Nov 2004 12:04:04 -0000 1.10 *************** *** 46,50 **** /*bool Trace (Vector3 Begin, Vector3 End, Vector3& colPoint, Vector3& colNormal); bool TriangleTrace(Vector3 Begin, Vector3 End, Vector3& colPoint, Vector3& colNormal);*/ ! int GetVertexStride () { return 0; } --- 46,51 ---- /*bool Trace (Vector3 Begin, Vector3 End, Vector3& colPoint, Vector3& colNormal); bool TriangleTrace(Vector3 Begin, Vector3 End, Vector3& colPoint, Vector3& colNormal);*/ ! ! void Attach (const std::string& jointName, SceneNode* s); int GetVertexStride () { return 0; } *************** *** 81,84 **** --- 82,86 ---- struct Joint { + std::string sName; int iNumber; int iParent; *************** *** 89,92 **** --- 91,95 ---- Joint** pChildrens; int iNumChildrens; + std::vector<SceneNode*> vNodes; }; Index: glrenderer.cc =================================================================== RCS file: /cvsroot/epfl/tgengine-0.1/glrenderer.cc,v retrieving revision 1.21 retrieving revision 1.22 diff -C2 -d -r1.21 -r1.22 *** glrenderer.cc 17 Nov 2004 23:12:37 -0000 1.21 --- glrenderer.cc 19 Nov 2004 12:04:04 -0000 1.22 *************** *** 73,78 **** ! Vector3 horiz=0.5*axis[1]*10; ! Vector3 vert=0.5*axis[2]*10; (*_glActiveTextureARB)(GL_TEXTURE0); glEnable (GL_TEXTURE_2D); --- 73,78 ---- ! Vector3 horiz=0.5*axis[1]*d->fSizeX; ! Vector3 vert=0.5*axis[2]*d->fSizeY; (*_glActiveTextureARB)(GL_TEXTURE0); glEnable (GL_TEXTURE_2D); *************** *** 601,605 **** glBlendFunc( GL_SRC_ALPHA, GL_ONE ); ! BindMaterial (p->GetMaterial()); for (int i=0; i<p->GetParticlesCount();i++) --- 601,608 ---- glBlendFunc( GL_SRC_ALPHA, GL_ONE ); ! //BindMaterial (p->GetMaterial()); ! (*_glActiveTextureARB)(GL_TEXTURE0); ! glEnable (GL_TEXTURE_2D); ! glBindTexture(GL_TEXTURE_2D, p->GetTexture()->iId); for (int i=0; i<p->GetParticlesCount();i++) *************** *** 902,906 **** { float matrix[16]; ! s->GetRotation().GetMatrix(matrix); glMultMatrixf (matrix); /*glRotatef(s->GetRotation().x, 1, 0, 0); --- 905,909 ---- { float matrix[16]; ! s->GetFinalRotation().GetMatrix(matrix); glMultMatrixf (matrix); /*glRotatef(s->GetRotation().x, 1, 0, 0); *************** *** 1189,1193 **** glLoadIdentity (); ! glTranslatef(mesh->GetPosition().x, mesh->GetPosition().y, mesh->GetPosition().z); #ifdef DEBUG if (!mesh->bCamera) { --- 1192,1196 ---- glLoadIdentity (); ! glTranslatef(mesh->GetFinalPosition().x, mesh->GetFinalPosition().y, mesh->GetFinalPosition().z); #ifdef DEBUG if (!mesh->bCamera) { Index: md5instance.cc =================================================================== RCS file: /cvsroot/epfl/tgengine-0.1/md5instance.cc,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** md5instance.cc 17 Nov 2004 23:12:38 -0000 1.13 --- md5instance.cc 19 Nov 2004 12:04:04 -0000 1.14 *************** *** 26,29 **** --- 26,30 ---- for (int i=0; i<iNumJoints; i++) { + pJoints[i].sName = pData->GetJointName(i); pJoints[i].iNumber = i; pJoints[i].iParent = pData->GetJointParent(i); *************** *** 120,124 **** --- 121,133 ---- void MD5Instance::PreRender(float fTime) { + _ComputeFinalPosAndRot (); + fCurrentTime += fTime; + for (unsigned int i=0; i<vNodes.size(); i++) + { + vNodes[i]->SetPosition(vFinalPosition); + vNodes[i]->SetRotation(qFinalRotation); + } + if (iCurrentAnimation < 0) return; *************** *** 146,149 **** --- 155,173 ---- } + void MD5Instance::Attach (const std::string& jointName, SceneNode* s) + { + if (jointName == "") //on l'attache au mesh + { + vNodes.push_back(s); + return; + } + for (int i=0; i<iNumJoints; i++) + { + if (pJoints[i].sName == jointName) + pJoints[i].vNodes.push_back(s); + } + vNodes.push_back(s); //si on ne trouve pas de joint, on l'attache au mesh + } + void MD5Instance::_SkinMesh () { *************** *** 258,261 **** --- 282,291 ---- } + for (unsigned int i=0; i<pJoint->vNodes.size(); i++) + { + pJoint->vNodes[i]->SetPosition(vFinalPosition+pJoint->vPosition); + pJoint->vNodes[i]->SetRotation(qFinalRotation*pJoint->qOrientation); + } + //std::cout << pJoint->vPosition << std::endl; for (int i = 0; i < pJoint->iNumChildrens; i++) Index: md5mesh10.cc =================================================================== RCS file: /cvsroot/epfl/tgengine-0.1/md5mesh10.cc,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** md5mesh10.cc 17 Nov 2004 23:12:38 -0000 1.8 --- md5mesh10.cc 19 Nov 2004 12:04:04 -0000 1.9 *************** *** 77,80 **** --- 77,83 ---- NEXT("\"") pJoints[i].sName = buffer; + pJoints[i].sName.erase(0,1); //on efface le premier " + int last = pJoints[i].sName.find_last_of('\"'); + pJoints[i].sName.erase(last); //std::cout << pJoints[i].sName << std::endl; Quaternion q; Index: scenenode.h =================================================================== RCS file: /cvsroot/epfl/tgengine-0.1/scenenode.h,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** scenenode.h 17 Nov 2004 23:12:39 -0000 1.9 --- scenenode.h 19 Nov 2004 12:04:04 -0000 1.10 *************** *** 36,57 **** virtual void SetPosition (Vector3 v); Vector3 GetPosition () { return vPosition; } /* Rotation */ inline Quaternion GetRotation () { return qRotation; } inline void SetRotation (const Quaternion& q) { qRotation=q; } ! /*Vector3 GetRotation () { return vEuler; } ! virtual void SetRotation (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; }*/ /* Autres */ //virtual void CalculateBoundingVolume (); virtual bool Trace (Vector3 Begin, Vector3 End, Vector3& colPoint, Vector3& colNormal); --- 36,63 ---- virtual void SetPosition (Vector3 v); Vector3 GetPosition () { return vPosition; } + /** + * SetLocalPosition permet de décaler l'objet par rapport a son propre systeme de coordonnes + */ + inline void SetLocalPosition (const Vector3& v) { vLocalPosition = v; } + inline Vector3 GetLocalPosition () { return vLocalPosition; } + + /** + * Retourne la position 'finale', c'est à dire vLocalPosition + vPosition + */ + inline Vector3 GetFinalPosition () { return vFinalPosition; } /* Rotation */ inline Quaternion GetRotation () { return qRotation; } inline void SetRotation (const Quaternion& q) { qRotation=q; } ! inline void SetLocalRotation (const Quaternion& q) { qLocalRotation = q; } ! inline Quaternion GetLocalRotation () { return qLocalRotation; } + /** + * Retourne la rotation 'finale', c'est à dire qRotation*qLocalRotation + */ + inline Quaternion GetFinalRotation () { return qFinalRotation; } /* Autres */ //virtual void CalculateBoundingVolume (); + // virtual bool Trace (Vector3 Begin, Vector3 End, Vector3& colPoint, Vector3& colNormal); *************** *** 63,66 **** --- 69,74 ---- float fTime; protected: + inline void _ComputeFinalPosAndRot () { vFinalPosition = vPosition+vLocalPosition; qFinalRotation = qRotation*qLocalRotation; } + //PhysicCallBack* pPhysicCallBack; bool bRender; *************** *** 68,71 **** --- 76,83 ---- Quaternion qRotation; Vector3 vPosition; + Vector3 vLocalPosition; + Quaternion qLocalRotation; + Vector3 vFinalPosition; + Quaternion qFinalRotation; BoundingBox* pBBox; |