|
From: julien r. <jul...@us...> - 2004-11-06 18:19:55
|
Update of /cvsroot/epfl/tgengine-0.1 In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24841 Modified Files: boundingbox.cc boundingbox.h engine.cc glrenderer.cc material.h md5instance.cc md5mesh10.cc md5mesh10.h physicengine.cc physicnode.cc q3bsp.cc q3bsp.h scenemanager.cc Log Message: backup Index: boundingbox.h =================================================================== RCS file: /cvsroot/epfl/tgengine-0.1/boundingbox.h,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** boundingbox.h 26 Sep 2004 13:15:22 -0000 1.1.1.1 --- boundingbox.h 6 Nov 2004 17:05:39 -0000 1.2 *************** *** 4,7 **** --- 4,8 ---- #include "vector3.h" #include "plane.h" + #include "quaternion.h" namespace tg *************** *** 26,29 **** --- 27,31 ---- Vector3 vWorldBSCenter; Vector3 vBSCenter; + Quaternion qRotation; float fBSRadius; *************** *** 42,46 **** * Trace un rayon à travers la BBox */ ! bool TraceRay (Vector3 begin, Vector3 end, Vector3& colPoint); --- 44,48 ---- * Trace un rayon à travers la BBox */ ! bool TraceRay (Vector3 begin, Vector3 end, Vector3& colPoint, Vector3& colNormal); Index: physicengine.cc =================================================================== RCS file: /cvsroot/epfl/tgengine-0.1/physicengine.cc,v retrieving revision 1.17 retrieving revision 1.18 diff -C2 -d -r1.17 -r1.18 *** physicengine.cc 1 Nov 2004 08:57:10 -0000 1.17 --- physicengine.cc 6 Nov 2004 17:05:39 -0000 1.18 *************** *** 153,157 **** float updist = sqrt(distx+distz); ! if (updist > dist) //on passe l'obstacle { //std::cout << "time : " << eTime << "\t" << vUpNewPos << std::endl; --- 153,157 ---- float updist = sqrt(distx+distz); ! /*if (updist > dist) //on passe l'obstacle { //std::cout << "time : " << eTime << "\t" << vUpNewPos << std::endl; *************** *** 165,172 **** } else //l'obstacle est trop haut ! { //std::cout << "time : " << eTime << "\t" << vNewPos << std::endl; n->SetPosition(vNewPos); ! if (vVelocity != n->GetVelocity() && n->GetPhysicCallBack() != NULL) { //std::cout << "callback" << std::endl; --- 165,172 ---- } else //l'obstacle est trop haut ! {*/ //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->GetPhysicCallBack()->Collide(NULL, Vector3(0,0,0), Vector3(0,0,0)); } ! } //Classification de la position --- 174,178 ---- n->GetPhysicCallBack()->Collide(NULL, Vector3(0,0,0), Vector3(0,0,0)); } ! }*/ //Classification de la position *************** *** 180,184 **** n->GetBBox()->vMin, n->GetBBox()->vMax); //si on met le allsolid, ca foire les mouvements sur les y ! if (col.Fraction < 1.0f /*|| col.AllSolid*/) n->SetOnGround(true); else --- 180,184 ---- n->GetBBox()->vMin, n->GetBBox()->vMax); //si on met le allsolid, ca foire les mouvements sur les y ! if (col.Fraction < 1.0f || col.AllSolid) n->SetOnGround(true); else *************** *** 204,208 **** result.EndPoint = mapResult.EndPoint; result.Normal = mapResult.CollisionNormal; ! //on trace ensuite sur les objets (mObjects) Vector3 colPoint(0,0,0); Vector3 colNormal(0,0,0); --- 204,208 ---- result.EndPoint = mapResult.EndPoint; result.Normal = mapResult.CollisionNormal; ! //on trace sur les objets Vector3 colPoint(0,0,0); Vector3 colNormal(0,0,0); *************** *** 211,215 **** for (unsigned int i=0; i<pNodes.size(); i++) { ! if (pNodes[i]->Trace(Begin, End, colPoint, colNormal)) { d1 = (colPoint - Begin).Magnitude(); d2 = (result.EndPoint - Begin).Magnitude(); --- 211,215 ---- for (unsigned int i=0; i<pNodes.size(); i++) { ! if (pNodes[i]->GetBBox()->TraceRay(Begin, End, colPoint, colNormal)) { d1 = (colPoint - Begin).Magnitude(); d2 = (result.EndPoint - Begin).Magnitude(); *************** *** 221,243 **** } } - /* Mesh* m = pFirstObject; - if (m != NULL) - { - do - { - if (m->Trace(Begin, End, colPoint, colNormal)) - { - //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 ) - { - result.EndPoint = colPoint; - result.Normal = colNormal; - result.pNode = m; - } - } - } while((m=m->GetNext()) != NULL); - }*/ return result; --- 221,224 ---- Index: scenemanager.cc =================================================================== RCS file: /cvsroot/epfl/tgengine-0.1/scenemanager.cc,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** scenemanager.cc 2 Nov 2004 15:32:16 -0000 1.12 --- scenemanager.cc 6 Nov 2004 17:05:39 -0000 1.13 *************** *** 96,103 **** ! //Vector3 Target = pCamera->GetForward(); ! Vector3 Target = Vector3::UNIT_X; ! Target = pCamera->GetForward()+Target*100000; ! CollisionResult myResult = pPhysicEngine->Trace(pCamera->GetForward(), Target); glPointSize(5.0f); --- 96,104 ---- ! Vector3 vTarget = pCamera->GetRotation().GetZAxis(); ! Vector3 vPosition = pCamera->GetPosition(); ! vTarget = vPosition - vTarget*10000; ! ! CollisionResult myResult = pPhysicEngine->Trace(vPosition, vTarget); glPointSize(5.0f); *************** *** 130,134 **** #endif #ifdef DEBUG ! //Engine::pRenderer->RenderBBox(m->GetBBox()); #endif } --- 131,135 ---- #endif #ifdef DEBUG ! Engine::pRenderer->RenderBBox(m->GetBBox()); #endif } Index: q3bsp.h =================================================================== RCS file: /cvsroot/epfl/tgengine-0.1/q3bsp.h,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** q3bsp.h 21 Oct 2004 21:18:28 -0000 1.3 --- q3bsp.h 6 Nov 2004 17:05:39 -0000 1.4 *************** *** 431,434 **** --- 431,436 ---- bool IsVisible (int leaf); + + /** * CheckRayMove Index: physicnode.cc =================================================================== RCS file: /cvsroot/epfl/tgengine-0.1/physicnode.cc,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** physicnode.cc 28 Oct 2004 21:10:16 -0000 1.3 --- physicnode.cc 6 Nov 2004 17:05:39 -0000 1.4 *************** *** 31,35 **** void PhysicNode::CalculateBoundingVolume () { ! } --- 31,35 ---- void PhysicNode::CalculateBoundingVolume () { ! pBBox = vNodes[0]->GetBBox(); } Index: engine.cc =================================================================== RCS file: /cvsroot/epfl/tgengine-0.1/engine.cc,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** engine.cc 31 Oct 2004 22:15:40 -0000 1.6 --- engine.cc 6 Nov 2004 17:05:39 -0000 1.7 *************** *** 196,200 **** while (!done) { - //TODO: Remove this ugly hack and code a real event manager :-P while(SDL_PollEvent(&event)) { --- 196,199 ---- Index: md5mesh10.h =================================================================== RCS file: /cvsroot/epfl/tgengine-0.1/md5mesh10.h,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** md5mesh10.h 2 Nov 2004 15:32:16 -0000 1.4 --- md5mesh10.h 6 Nov 2004 17:05:39 -0000 1.5 *************** *** 8,11 **** --- 8,12 ---- #include "quaternion.h" #include "material.h" + #include "boundingbox.h" namespace tg *************** *** 65,69 **** inline int anim_GetNumAnimatedComponents(int i) { return pAnimations[i].iNumAnimatedComponents; } inline float anim_GetFrameElement (int i, int j, int k) { return pAnimations[i].pFrames[j][k]; } ! inline int anim_joint_GetParent (int i, int j) { return pAnimations[i].pJointInfos[j].iParent; } inline int anim_joint_GetFlags (int i, int j) { return pAnimations[i].pJointInfos[j].iFlags; } --- 66,70 ---- inline int anim_GetNumAnimatedComponents(int i) { return pAnimations[i].iNumAnimatedComponents; } inline float anim_GetFrameElement (int i, int j, int k) { return pAnimations[i].pFrames[j][k]; } ! inline BoundingBox* anim_GetBBox(int i,int j) { return &pAnimations[i].pBBox[j]; } inline int anim_joint_GetParent (int i, int j) { return pAnimations[i].pJointInfos[j].iParent; } inline int anim_joint_GetFlags (int i, int j) { return pAnimations[i].pJointInfos[j].iFlags; } *************** *** 129,132 **** --- 130,135 ---- }; _MD5JointInfos* pJointInfos; //un tableau de iNumJoints + + BoundingBox* pBBox; //un tableau de [iNumFrames] BoundingBox, une pour chaque frame }; Index: q3bsp.cc =================================================================== RCS file: /cvsroot/epfl/tgengine-0.1/q3bsp.cc,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** q3bsp.cc 21 Oct 2004 21:18:28 -0000 1.8 --- q3bsp.cc 6 Nov 2004 17:05:39 -0000 1.9 *************** *** 1542,1693 **** } - /*void Q3Bsp::Trace (Vector3 vStart, Vector3 vEnd, float* fFraction, Vector3* vTraceEnd, bool* bStartsOut, bool* bAllSolid) - { - (*bStartsOut) = true; - (*bAllSolid) = false; - (*fFraction) = 1.0f; - - vInputStart = vStart; - vInputEnd = vEnd; - - CheckNode (0, 0.0f, 1.0f, vStart, vEnd, bStartsOut, bAllSolid, fFraction); - if ((*fFraction) == 1.0f) - (*vTraceEnd) = vEnd; - else - (*vTraceEnd) = vStart + (*fFraction)*(vEnd-vStart); - } - - void Q3Bsp::CheckNode (int iNodeIndex, float fStartFraction, float fEndFraction, Vector3 vStart, Vector3 vEnd, bool* bStartsOut, bool* bAllSolid, float* fFraction) - { - if ((*fFraction) < fStartFraction) - return; - - if (iNodeIndex < 0) // c'est une leaf - { - BspLeaf* leaf = &pLeafs[~iNodeIndex]; - for (int i=0; i<leaf->numOfLeafBrushes; i++) - { - BspBrush* brush = &pBrushes[pLeafBrushes[leaf->leafBrush + i]]; - if (brush->brushSides > 0) //il manque une verification des contents flags des textures - CheckBrush(brush, bStartsOut, bAllSolid, fFraction); - } - return; - } - //sinon, c'est un noeud - - BspNode* node=&pNodes[iNodeIndex]; - BspPlane* plane=&pPlanes[node->plane]; - //on cherche les distances au plan des points de départ et d'arrivée - float startDist = ( vStart*plane->vNormal ) - plane->d; - float endDist = ( vEnd*plane->vNormal ) - plane->d; - - if ( startDist >= 0 && endDist >= 0) //les points sont devant le plan - CheckNode( node->front, fStartFraction, fEndFraction, vStart, vEnd, bStartsOut, bAllSolid, fFraction ); - else if (startDist < 0 && endDist < 0) //les points sont derriere le plan - CheckNode( node->back, fStartFraction, fEndFraction, vStart, vEnd, bStartsOut, bAllSolid, fFraction ); - else //la ligne passe a travers le plan - { - int side1, side2; - float f1, f2, fm; - Vector3 vMid; - float invDist = 1.0f / (startDist - endDist); - //on choisit la portion du segment dont on va s'occuper en premier - if (startDist < endDist) //le point de depart est derriere le plan - { - side1 = node->back; - side2 = node->front; - f1 = (startDist - EPSILON)*invDist; - f2 = (startDist + EPSILON)*invDist; - } - else if (endDist < startDist) //c'est le point d'arrive qui est derrier le plan - { - side1 = node->front; - side2 = node->back; - f1 = (startDist + EPSILON)*invDist; - f2 = (startDist - EPSILON)*invDist; - } - else - { - side1 = node->front; - side2 = node->back; - f1 = 1.0f; - f2 = 0.0f; - } - - - if ( f1 < 0.0f ) f1 = 0.0f; - else if ( f1 > 1.0f ) f1 = 1.0f; - if ( f2 < 0.0f ) f2 = 0.0f; - else if ( f2 > 1.0f ) f2 = 1.0f; - - //on calcul le point milieu du premier cote - fm = fStartFraction + f1*(fEndFraction - fStartFraction); - vMid = vStart + f1*(vEnd-vStart); - - CheckNode(side1, fStartFraction, fm, vStart, vMid, bStartsOut, bAllSolid, fFraction); - - //on calcul le point milieu du second cote - fm = fStartFraction + f2*(fEndFraction - fStartFraction); - vMid = vStart + f2*(vEnd-vStart); - - CheckNode(side2, fm, fEndFraction, vMid, vEnd, bStartsOut, bAllSolid, fFraction); - - } - } - - void Q3Bsp::CheckBrush (BspBrush* brush, bool* bStartsOut, bool* bAllSolid, float* fFraction) - { - float startFraction = -1.0f; - float endFraction = 1.0f; - bool startsOut = false; - bool endsOut = false; - - for (int i=0; i<brush->numOfBrushSides; i++) - { - BspBrushSide* brushSide = &pBrushSides[brush->brushSides + i]; - BspPlane* plane = &pPlanes[brushSide->plane]; - //calcul des distances au plan - float startDist = vInputStart*plane->vNormal - plane->d; - float endDist = vInputEnd*plane->vNormal - plane->d; - - if (startDist > 0 ) - startsOut = true; - if (endDist > 0 ) - endsOut = true; - - if (startsOut && endsOut) //le rayon n'est pas sur ce brush - return; - if (startDist <= 0 && endDist <= 0) //le rayon est derriere ce plan, il sera en collision avec d'autres plans du meme brush - continue; - - if (startDist > endDist) //le rayon entre dans le brush - { - float fraction = (startDist - EPSILON) / (startDist - endDist); - if (fraction > startFraction) - startFraction = fraction; - } - else //le rayon sort du brush - { - float fraction = (startDist + EPSILON) / (startDist - endDist); - if (fraction < endFraction) - endFraction = fraction; - } - } - - if (!startsOut) - { - (*bStartsOut) = false; - if (!endsOut) - (*bAllSolid) = true; - return; - } - - if (startFraction < endFraction) - if (startFraction > -1 && startFraction < (*fFraction)) - { - if (startFraction < 0) startFraction = 0; - (*fFraction = startFraction); - } - }*/ - }//END tg --- 1542,1544 ---- Index: material.h =================================================================== RCS file: /cvsroot/epfl/tgengine-0.1/material.h,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** material.h 26 Sep 2004 13:15:12 -0000 1.1.1.1 --- material.h 6 Nov 2004 17:05:39 -0000 1.2 *************** *** 11,15 **** { public: ! Material (); void SetFirstTexture (Texture* p) { pTex1 = p; } void SetSecondTexture (Texture* p) { pTex2 = p; } --- 11,15 ---- { public: ! Material () { pTex1 = pTex2 = pNormal = NULL; } void SetFirstTexture (Texture* p) { pTex1 = p; } void SetSecondTexture (Texture* p) { pTex2 = p; } Index: glrenderer.cc =================================================================== RCS file: /cvsroot/epfl/tgengine-0.1/glrenderer.cc,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** glrenderer.cc 2 Nov 2004 15:32:15 -0000 1.12 --- glrenderer.cc 6 Nov 2004 17:05:39 -0000 1.13 *************** *** 1066,1093 **** glTranslatef(mesh->GetPosition().x, mesh->GetPosition().y, mesh->GetPosition().z); #ifdef DEBUG ! Vector3 fwd, rgt, up; ! //mesh->GetRotation().ToAngleVectors(fwd, rgt, up); ! //fwd = mesh->GetRotation().GetXAxis(); ! //rgt = mesh->GetRotation().GetZAxis(); ! //up = mesh->GetRotation().GetYAxis(); ! fwd = mesh->GetRotation().Rotate(Vector3::UNIT_X); ! rgt = mesh->GetRotation().Rotate(Vector3::UNIT_Z); ! up = mesh->GetRotation().Rotate(Vector3::UNIT_Y); ! fwd *= 10; ! rgt *= 10; ! up *= 10; ! glBegin (GL_LINES); ! glColor3f (1,0,0); ! glVertex3f (0,0,0); ! glVertex3fv (&fwd.x); ! ! glColor3f(0,0,1); ! glVertex3f (0,0,0); ! glVertex3fv (&rgt.x); ! ! glColor3f(0,1,0); ! glVertex3f (0,0,0); ! glVertex3fv (&up.x); ! glEnd (); #endif --- 1066,1095 ---- glTranslatef(mesh->GetPosition().x, mesh->GetPosition().y, mesh->GetPosition().z); #ifdef DEBUG ! if (!mesh->bCamera) { ! Vector3 fwd, rgt, up; ! //mesh->GetRotation().ToAngleVectors(fwd, rgt, up); ! //fwd = mesh->GetRotation().GetXAxis(); ! //rgt = mesh->GetRotation().GetZAxis(); ! //up = mesh->GetRotation().GetYAxis(); ! fwd = mesh->GetRotation().Rotate(Vector3::UNIT_X); ! rgt = mesh->GetRotation().Rotate(Vector3::UNIT_Z); ! up = mesh->GetRotation().Rotate(Vector3::UNIT_Y); ! fwd *= 10; ! rgt *= 10; ! up *= 10; ! glBegin (GL_LINES); ! glColor3f (1,0,0); ! glVertex3f (0,0,0); ! glVertex3fv (&fwd.x); ! ! glColor3f(0,0,1); ! glVertex3f (0,0,0); ! glVertex3fv (&rgt.x); ! ! glColor3f(0,1,0); ! glVertex3f (0,0,0); ! glVertex3fv (&up.x); ! glEnd (); ! } #endif *************** *** 1849,1852 **** --- 1851,1860 ---- glLineWidth (1); + glPushMatrix (); + float matrix[16]; + b->qRotation.GetMatrix(matrix); + glMultMatrixf (matrix); + + glColor3f(0,1,0); glPointSize(5); *************** *** 1871,1874 **** --- 1879,1883 ---- glEnable(GL_CULL_FACE); //RenderBSphere (b->vWorldBSCenter, b->fBSRadius); + glPopMatrix (); } Index: md5mesh10.cc =================================================================== RCS file: /cvsroot/epfl/tgengine-0.1/md5mesh10.cc,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** md5mesh10.cc 2 Nov 2004 15:32:16 -0000 1.5 --- md5mesh10.cc 6 Nov 2004 17:05:39 -0000 1.6 *************** *** 1 **** ! #include "md5mesh10.h" #include "quaternion.h" namespace tg { MD5Mesh10::MD5Mesh10 () { pAnimations.clear(); } MD5Mesh10::~ MD5Mesh10() { delete [] pJoints; for (int i=0; i<iNumMeshes; i++) { delete [] pMeshes[i].pVerts; delete [] pMeshes[i].pTriangles; delete [] pMeshes[i].pIndexes; delete [] pMeshes[i].pWeights; } delete [] pMeshes; for (unsigned int i=0; i<pAnimations.size(); i++) { for (int j=0; j<pAnimations[i].iNumJoints; j++) delete [] pAnimations[i].pBaseFrame[j]; delete [] pAnimations[i].pBaseFrame; delete [] pAnimations[i].pJointInfos; for (int j=0; j<pAnimations[i].iNumFrames; j++) delete [] pAnimations[i].pFrames[j]; delete [] pAnimations[i].pFrames; } pAnimations.clear(); } #define NEXT(str) while(buffer.find(str)==std::string::npos) \ pFD >> buffer; bool MD5Mesh10::LoadMesh(char* str) { std::ifstream pFD; std::string buffer; int version; std::cout << "[TGE] Chargement de " << str << std::endl; pFD.open(str, std::ios::in); if (pFD.fail()) { std::cerr << "[TGE] Erreur lors de l'ouverture de " << str << std::endl; return false; } pFD >> buffer; pFD >> version; if (version != 10) { std::cerr << "[TGE] Mauvaise version : " << version << std::endl; return false; } NEXT("numJoints") pFD >> iNumJoints; NEXT("numMeshes") pFD >> iNumMeshes; iNumBaseJoints = 0; pJoints = new _MD5Joint[iNumJoints]; for (int i=0; i<iNumJoints; i++) { NEXT("\"") pJoints[i].sName = buffer; //std::cout << pJoints[i].sName << std::endl; Quaternion q; //pFD >> pJoints[i].iNumber; pFD >> pJoints[i].iParent; if (pJoints[i].iParent < 0) iNumBaseJoints++; NEXT("(") pFD >> pJoints[i].vPosition.x >> pJoints[i].vPosition.y >> pJoints[i].vPosition.z; //Util::ChangeCoords(pJoints[i].vPosition); //ChangeCoords(pJoints[i].vPosition); NEXT(")") NEXT("(") pFD >> q.x >> q.y >> q.z; //Util::ChangeCoords(q.x, q.y, q.z); q.ComputeR(); pJoints[i].qOrientation = q; //Util::QuaternionToMatrix33(q,pJoints[i].mOrientation); } pMeshes = new _MD5Mesh[iNumMeshes]; for (int i=0; i<iNumMeshes; i++) { NEXT("shader") std::string sTmp; pFD >> sTmp; int iLastSlash = sTmp.find_last_of("/"); int iLastQuote = sTmp.find_last_of("\""); iLastSlash += 1; //on veut le caractere juste apres le dernier slash sTmp.erase(iLastQuote); pMeshes[i].sNormal = "data/textures/models/"+sTmp.substr(iLastSlash); pMeshes[i].sColor = pMeshes[i].sNormal+"_color.bmp"; pMeshes[i].sNormal += ".bmp"; //pMeshes[i].sNormal = "data/notexture.bmp"; //pMeshes[i].sColor = "data/notexture.bmp"; pMeshes[i].pMaterial = new Material (); Texture* tmpTex = new Texture (); tmpTex->LoadBMP((char*)pMeshes[i].sNormal.data(), TG_TEXTURE_2D); pMeshes[i].pMaterial->SetNormalTexture(tmpTex); tmpTex = new Texture(); tmpTex->LoadBMP((char*)pMeshes[i].sColor.data(), TG_TEXTURE_2D); pMeshes[i].pMaterial->SetFirstTexture(tmpTex); NEXT("numverts") pFD >> pMeshes[i].iNumVerts; pFD >> buffer; //sans ca, le NEXT("vert") ne va pas bouger car vert est deja dans numverts pMeshes[i].pVerts = new _MD5Vert[pMeshes[i].iNumVerts]; for (int j=0; j<pMeshes[i].iNumVerts; j++) { _MD5Vert& vert = pMeshes[i].pVerts[j]; NEXT("vert") NEXT("(") pFD >> vert.pTexCoords[0] >>vert.pTexCoords[1]; vert.pTexCoords[1] = 1 - vert.pTexCoords[1]; NEXT(")") pFD >> vert.iWeightIndex >> vert.iNumWeights; } NEXT("numtris") pFD >> pMeshes[i].iNumTris; pMeshes[i].pTriangles = new _MD5Triangle[pMeshes[i].iNumTris]; pMeshes[i].pIndexes = new unsigned int[pMeshes[i].iNumTris*3]; int iC = 0; pFD >> buffer; //sans ca, le NEXT("tri") ne va pas bouger car tri est deja dans numtris for (int j=0; j<pMeshes[i].iNumTris; j++) { _MD5Triangle& tri = pMeshes[i].pTriangles[j]; NEXT("tri") pFD >> buffer; pFD >> tri.pIndex[0] >> tri.pIndex[1] >> tri.pIndex[2]; pMeshes[i].pIndexes[iC] = pMeshes[i].pTriangles[j].pIndex[0]; iC++; pMeshes[i].pIndexes[iC] = pMeshes[i].pTriangles[j].pIndex[1]; iC++; pMeshes[i].pIndexes[iC] = pMeshes[i].pTriangles[j].pIndex[2]; iC++; } NEXT("numweights") pFD >> pMeshes[i].iNumWeights; pFD >> buffer; // sans ca, le NEXT("weight") foire pMeshes[i].pWeights = new _MD5Weight[pMeshes[i].iNumWeights]; for (int j=0; j<pMeshes[i].iNumWeights; j++) { _MD5Weight& w = pMeshes[i].pWeights[j]; NEXT("weight") pFD >> buffer; pFD >> w.iBoneIndex >> w.fBias; NEXT("(") pFD >> w.vWeights.x >> w.vWeights.y >> w.vWeights.z; //Util::ChangeCoords(w.vWeights); } } std::cout << "[TGE] Chargement de " << str << " termine" << std::endl; return true; } bool MD5Mesh10::LoadAnim(char* str) { _MD5Anim anim; //on garde juste le nom de l'animation std::string sTemp = std::string(str); int iLastSlash = sTemp.find_last_of("/"); int iLastPoint = sTemp.find_last_of("."); sTemp.erase(iLastPoint); anim.sName = sTemp.substr(iLastSlash+1); std::cout << "[TGE] anim name : " << anim.sName << std::endl; std::ifstream pFD; std::string buffer; int version; std::cout << "[TGE] Chargement de " << str << std::endl; pFD.open(str, std::ios::in); if (pFD.fail()) { std::cerr << "[TGE] Erreur lors de l'ouverture de " << str << std::endl; return false; } pFD >> buffer; pFD >> version; if (version != 10) { std::cerr << "[TGE] Mauvaise version : " << version << std::endl; return false; } NEXT("numFrames") pFD >> anim.iNumFrames; NEXT("numJoints") pFD >> anim.iNumJoints; NEXT("frameRate") pFD >> anim.iFrameRate; NEXT("numAnimatedComponents") pFD >> anim.iNumAnimatedComponents; anim.pFrames = new float*[anim.iNumFrames]; for (int i=0; i<anim.iNumFrames; i++) anim.pFrames[i] = new float[anim.iNumAnimatedComponents]; anim.pJointInfos = new _MD5Anim::_MD5JointInfos[anim.iNumJoints]; anim.pBaseFrame = new float*[anim.iNumJoints]; //FIXME: a priori, il n'y a pas de md5mesh ou la hierarchie de l'anim est different du md5mesh. Ceci dit, on peut peut-etre utiliser ca pour demembrer ou autre NEXT("hierarchy") for (int i=0; i<anim.iNumJoints; i++) { NEXT("\"") buffer = ""; pFD >> anim.pJointInfos[i].iParent; pFD >> anim.pJointInfos[i].iFlags; pFD >> anim.pJointInfos[i].iStartIndex; } //chargement de baseframe NEXT("baseframe") for (int i=0; i<anim.iNumJoints; i++) { anim.pBaseFrame[i] = new float[6]; NEXT("(") pFD >> anim.pBaseFrame[i][0]; pFD >> anim.pBaseFrame[i][1]; pFD >> anim.pBaseFrame[i][2]; NEXT(")") NEXT("(") pFD >> anim.pBaseFrame[i][3]; pFD >> anim.pBaseFrame[i][4]; pFD >> anim.pBaseFrame[i][5]; NEXT(")") } //chargement des frames for (int i=0; i<anim.iNumFrames; i++) { NEXT("frame") NEXT("{") for (int j=0; j<anim.iNumAnimatedComponents; j++) pFD >> anim.pFrames[i][j]; NEXT("}") } pAnimations.push_back(anim); std::cout << "[TGE] Chargement de " << str << " termine" << std::endl; return true; } int MD5Mesh10::GetAnimIndex(const std::string& name) { int size = pAnimations.size(); for (int i=0; i<size; i++) { if (pAnimations[i].sName == name) return i; } return -1; } } \ No newline at end of file --- 1,300 ---- ! #include "md5mesh10.h" ! #include "quaternion.h" ! ! namespace tg ! { ! ! MD5Mesh10::MD5Mesh10 () ! { ! pAnimations.clear(); ! } ! ! MD5Mesh10::~ MD5Mesh10() ! { ! delete [] pJoints; ! for (int i=0; i<iNumMeshes; i++) ! { ! delete [] pMeshes[i].pVerts; ! delete [] pMeshes[i].pTriangles; ! delete [] pMeshes[i].pIndexes; ! delete [] pMeshes[i].pWeights; ! } ! delete [] pMeshes; ! for (unsigned int i=0; i<pAnimations.size(); i++) ! { ! for (int j=0; j<pAnimations[i].iNumJoints; j++) ! delete [] pAnimations[i].pBaseFrame[j]; ! delete [] pAnimations[i].pBaseFrame; ! delete [] pAnimations[i].pJointInfos; ! ! for (int j=0; j<pAnimations[i].iNumFrames; j++) ! delete [] pAnimations[i].pFrames[j]; ! delete [] pAnimations[i].pFrames; ! ! } ! pAnimations.clear(); ! } ! ! #define NEXT(str) while(buffer.find(str)==std::string::npos) \ ! pFD >> buffer; ! ! bool MD5Mesh10::LoadMesh(char* str) ! { ! std::ifstream pFD; ! std::string buffer; ! int version; ! ! std::cout << "[TGE] Chargement de " << str << std::endl; ! ! pFD.open(str, std::ios::in); ! ! if (pFD.fail()) ! { ! std::cerr << "[TGE] Erreur lors de l'ouverture de " << str << std::endl; ! return false; ! } ! ! pFD >> buffer; ! pFD >> version; ! ! if (version != 10) ! { ! std::cerr << "[TGE] Mauvaise version : " << version << std::endl; ! return false; ! } ! ! NEXT("numJoints") ! pFD >> iNumJoints; ! ! NEXT("numMeshes") ! pFD >> iNumMeshes; ! ! iNumBaseJoints = 0; ! pJoints = new _MD5Joint[iNumJoints]; ! ! for (int i=0; i<iNumJoints; i++) ! { ! NEXT("\"") ! pJoints[i].sName = buffer; ! //std::cout << pJoints[i].sName << std::endl; ! Quaternion q; ! //pFD >> pJoints[i].iNumber; ! pFD >> pJoints[i].iParent; ! if (pJoints[i].iParent < 0) ! iNumBaseJoints++; ! NEXT("(") ! pFD >> pJoints[i].vPosition.x >> pJoints[i].vPosition.y >> pJoints[i].vPosition.z; ! ! //Util::ChangeCoords(pJoints[i].vPosition); ! //ChangeCoords(pJoints[i].vPosition); ! ! NEXT(")") ! NEXT("(") ! pFD >> q.x >> q.y >> q.z; ! //Util::ChangeCoords(q.x, q.y, q.z); ! ! q.ComputeR(); ! ! pJoints[i].qOrientation = q; ! //Util::QuaternionToMatrix33(q,pJoints[i].mOrientation); ! } ! pMeshes = new _MD5Mesh[iNumMeshes]; ! for (int i=0; i<iNumMeshes; i++) ! { ! NEXT("shader") ! std::string sTmp; ! pFD >> sTmp; ! int iLastSlash = sTmp.find_last_of("/"); ! int iLastQuote = sTmp.find_last_of("\""); ! iLastSlash += 1; //on veut le caractere juste apres le dernier slash ! sTmp.erase(iLastQuote); ! pMeshes[i].sNormal = "data/textures/models/"+sTmp.substr(iLastSlash); ! pMeshes[i].sColor = pMeshes[i].sNormal+"_color.bmp"; ! pMeshes[i].sNormal += ".bmp"; ! //pMeshes[i].sNormal = "data/notexture.bmp"; ! //pMeshes[i].sColor = "data/notexture.bmp"; ! ! pMeshes[i].pMaterial = new Material (); ! Texture* tmpTex = new Texture (); ! tmpTex->LoadBMP((char*)pMeshes[i].sNormal.data(), TG_TEXTURE_2D); ! pMeshes[i].pMaterial->SetNormalTexture(tmpTex); ! tmpTex = new Texture(); ! tmpTex->LoadBMP((char*)pMeshes[i].sColor.data(), TG_TEXTURE_2D); ! pMeshes[i].pMaterial->SetFirstTexture(tmpTex); ! ! ! NEXT("numverts") ! pFD >> pMeshes[i].iNumVerts; ! pFD >> buffer; //sans ca, le NEXT("vert") ne va pas bouger car vert est deja dans numverts ! ! pMeshes[i].pVerts = new _MD5Vert[pMeshes[i].iNumVerts]; ! for (int j=0; j<pMeshes[i].iNumVerts; j++) ! { ! _MD5Vert& vert = pMeshes[i].pVerts[j]; ! NEXT("vert") ! NEXT("(") ! pFD >> vert.pTexCoords[0] >>vert.pTexCoords[1]; ! vert.pTexCoords[1] = 1 - vert.pTexCoords[1]; ! NEXT(")") ! pFD >> vert.iWeightIndex >> vert.iNumWeights; ! ! } ! NEXT("numtris") ! pFD >> pMeshes[i].iNumTris; ! ! pMeshes[i].pTriangles = new _MD5Triangle[pMeshes[i].iNumTris]; ! pMeshes[i].pIndexes = new unsigned int[pMeshes[i].iNumTris*3]; ! int iC = 0; ! pFD >> buffer; //sans ca, le NEXT("tri") ne va pas bouger car tri est deja dans numtris ! for (int j=0; j<pMeshes[i].iNumTris; j++) ! { ! _MD5Triangle& tri = pMeshes[i].pTriangles[j]; ! NEXT("tri") ! pFD >> buffer; ! pFD >> tri.pIndex[0] >> tri.pIndex[1] >> tri.pIndex[2]; ! ! pMeshes[i].pIndexes[iC] = pMeshes[i].pTriangles[j].pIndex[0]; ! iC++; ! pMeshes[i].pIndexes[iC] = pMeshes[i].pTriangles[j].pIndex[1]; ! iC++; ! pMeshes[i].pIndexes[iC] = pMeshes[i].pTriangles[j].pIndex[2]; ! iC++; ! } ! ! NEXT("numweights") ! pFD >> pMeshes[i].iNumWeights; ! pFD >> buffer; // sans ca, le NEXT("weight") foire ! pMeshes[i].pWeights = new _MD5Weight[pMeshes[i].iNumWeights]; ! for (int j=0; j<pMeshes[i].iNumWeights; j++) ! { ! _MD5Weight& w = pMeshes[i].pWeights[j]; ! NEXT("weight") ! pFD >> buffer; ! pFD >> w.iBoneIndex >> w.fBias; ! NEXT("(") ! pFD >> w.vWeights.x >> w.vWeights.y >> w.vWeights.z; ! //Util::ChangeCoords(w.vWeights); ! } ! } ! ! std::cout << "[TGE] Chargement de " << str << " termine" << std::endl; ! return true; ! ! } ! ! bool MD5Mesh10::LoadAnim(char* str) ! { ! _MD5Anim anim; ! //on garde juste le nom de l'animation ! std::string sTemp = std::string(str); ! int iLastSlash = sTemp.find_last_of("/"); ! int iLastPoint = sTemp.find_last_of("."); ! sTemp.erase(iLastPoint); ! anim.sName = sTemp.substr(iLastSlash+1); ! std::cout << "[TGE] anim name : " << anim.sName << std::endl; ! ! std::ifstream pFD; ! std::string buffer; ! int version; ! ! std::cout << "[TGE] Chargement de " << str << std::endl; ! ! pFD.open(str, std::ios::in); ! ! if (pFD.fail()) ! { ! std::cerr << "[TGE] Erreur lors de l'ouverture de " << str << std::endl; ! return false; ! } ! ! pFD >> buffer; ! pFD >> version; ! ! if (version != 10) ! { ! std::cerr << "[TGE] Mauvaise version : " << version << std::endl; ! return false; ! } ! ! NEXT("numFrames") ! pFD >> anim.iNumFrames; ! NEXT("numJoints") ! pFD >> anim.iNumJoints; ! NEXT("frameRate") ! pFD >> anim.iFrameRate; ! NEXT("numAnimatedComponents") ! pFD >> anim.iNumAnimatedComponents; ! ! anim.pFrames = new float*[anim.iNumFrames]; ! for (int i=0; i<anim.iNumFrames; i++) ! anim.pFrames[i] = new float[anim.iNumAnimatedComponents]; ! ! anim.pJointInfos = new _MD5Anim::_MD5JointInfos[anim.iNumJoints]; ! ! anim.pBaseFrame = new float*[anim.iNumJoints]; ! ! //FIXME: a priori, il n'y a pas de md5mesh ou la hierarchie de l'anim est different du md5mesh. Ceci dit, on peut peut-etre utiliser ca pour demembrer ou autre ! NEXT("hierarchy") ! for (int i=0; i<anim.iNumJoints; i++) ! { ! NEXT("\"") ! buffer = ""; ! pFD >> anim.pJointInfos[i].iParent; ! pFD >> anim.pJointInfos[i].iFlags; ! pFD >> anim.pJointInfos[i].iStartIndex; ! } ! ! anim.pBBox = new BoundingBox[anim.iNumFrames]; ! NEXT("bounds") ! for (int i=0; i<anim.iNumFrames; i++) ! { ! NEXT("(") ! pFD >> anim.pBBox[i].vMin.x >> anim.pBBox[i].vMin.y >> anim.pBBox[i].vMin.z; ! NEXT(")") ! NEXT("(") ! pFD >> anim.pBBox[i].vMax.x >> anim.pBBox[i].vMax.y >> anim.pBBox[i].vMax.z; ! NEXT(")") ! ! } ! ! //chargement de baseframe ! NEXT("baseframe") ! for (int i=0; i<anim.iNumJoints; i++) ! { ! anim.pBaseFrame[i] = new float[6]; ! NEXT("(") ! pFD >> anim.pBaseFrame[i][0]; ! pFD >> anim.pBaseFrame[i][1]; ! pFD >> anim.pBaseFrame[i][2]; ! NEXT(")") ! NEXT("(") ! pFD >> anim.pBaseFrame[i][3]; ! pFD >> anim.pBaseFrame[i][4]; ! pFD >> anim.pBaseFrame[i][5]; ! NEXT(")") ! } ! //chargement des frames ! for (int i=0; i<anim.iNumFrames; i++) ! { ! NEXT("frame") ! NEXT("{") ! for (int j=0; j<anim.iNumAnimatedComponents; j++) ! pFD >> anim.pFrames[i][j]; ! NEXT("}") ! } ! pAnimations.push_back(anim); ! std::cout << "[TGE] Chargement de " << str << " termine" << std::endl; ! return true; ! } ! ! int MD5Mesh10::GetAnimIndex(const std::string& name) ! { ! int size = pAnimations.size(); ! for (int i=0; i<size; i++) { ! if (pAnimations[i].sName == name) ! return i; ! } ! return -1; ! } ! ! } Index: md5instance.cc =================================================================== RCS file: /cvsroot/epfl/tgengine-0.1/md5instance.cc,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** md5instance.cc 2 Nov 2004 16:30:54 -0000 1.8 --- md5instance.cc 6 Nov 2004 17:05:39 -0000 1.9 *************** *** 139,142 **** --- 139,146 ---- } _SkinMesh(); + + //Doit-on le faire ici ?? + pBBox = pData->anim_GetBBox(iCurrentAnimation, iFrame); + pBBox->qRotation = qRotation; } Index: boundingbox.cc =================================================================== RCS file: /cvsroot/epfl/tgengine-0.1/boundingbox.cc,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** boundingbox.cc 26 Sep 2004 13:15:22 -0000 1.1.1.1 --- boundingbox.cc 6 Nov 2004 17:05:39 -0000 1.2 *************** *** 93,97 **** } ! bool BoundingBox::TraceRay (Vector3 begin, Vector3 end, Vector3& colPoint) { float startFraction = -1.0f; --- 93,97 ---- } ! bool BoundingBox::TraceRay (Vector3 begin, Vector3 end, Vector3& colPoint, Vector3& colNormal) { float startFraction = -1.0f; *************** *** 139,160 **** } return false; - - /*bool b_inside=true; //le point de depart est dedans - bool e_inside=true; //le point d'arrive est dedans - - for (unsigned int i=0; i<6; i++) - { - int b = pPlanes[i].ClassifyPoint(begin); - int e = pPlanes[i].ClassifyPoint(end); - if (b != POINT_BEHIND_PLANE) //si le point n'est pas derriere l'un des plans, il est en dehors de la boite - b_inside = false; - if (e != POINT_BEHIND_PLANE) - e_inside = false; - - } - - if (!b_inside && !e_inside) - return false; - return true;*/ } --- 139,142 ---- |