Update of /cvsroot/epfl/tgengine-0.1 In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25577 Modified Files: Changelog glrenderer.cc md5instance.cc md5mesh10.cc md5mesh10.h physicengine.cc physicengine.h plane.cc q3bsp.cc q3bsp.h Log Message: bgfixes ! Index: physicengine.cc =================================================================== RCS file: /cvsroot/epfl/tgengine-0.1/physicengine.cc,v retrieving revision 1.29 retrieving revision 1.30 diff -C2 -d -r1.29 -r1.30 *** physicengine.cc 19 Nov 2004 18:54:42 -0000 1.29 --- physicengine.cc 22 Nov 2004 21:19:07 -0000 1.30 *************** *** 16,20 **** } ! #define MAXBUMPS 10 void PhysicEngine::StepSlideMove(PhysicNode* n, float eTime, Vector3& vVelocity, Vector3 origin) --- 16,20 ---- } ! #define MAX_CLIP_PLANES 6 void PhysicEngine::StepSlideMove(PhysicNode* n, float eTime, Vector3& vVelocity, Vector3 origin) *************** *** 24,29 **** int bumpcount = 0; //Vector3 origin = n->pBBox->vWorldOrigin; ! std::vector<Vector3> pPlanes; int iNumPlanes = 0; float time_left = eTime; --- 24,30 ---- int bumpcount = 0; //Vector3 origin = n->pBBox->vWorldOrigin; ! Plane pPlanes[5]; int iNumPlanes = 0; + Vector3 primal_velocity = vVelocity; float time_left = eTime; *************** *** 31,41 **** int i, j; ! ! while ((trace.Fraction < (1.0f - EPSILON)) && (bumpcount < MAXBUMPS)) //a chaque fois qu'on rencontre un plan, on relance un trace avec comme origine le Endpoint sur le plan précédent et on ajuste la vitesse de notre objet. MAXBUMPS permet simplement d'éviter des boucles infinies { //trace = pLevel->CheckRayMove(origin, origin+vVelocity*time_left, n->GetBBox()->vMin, n->GetBBox()->vMax); trace = Trace(origin, origin+vVelocity*time_left, n->GetBBox()->vMin, n->GetBBox()->vMax, n); ! //on trace avec une sphere, les mouvements sembles plus 'lisses' //trace = pLevel->CheckRayMove(origin+n->GetBBox()->vBSCenter, origin+n->GetBBox()->vBSCenter+vVelocity*time_left, TRACE_SPHERE, n->GetBBox()->fBSRadius); --- 32,42 ---- int i, j; ! ! for (bumpcount=0; bumpcount<8;bumpcount++) //a chaque fois qu'on rencontre un plan, on relance un trace avec comme origine le Endpoint sur le plan précédent et on ajuste la vitesse de notre objet. MAXBUMPS permet simplement d'éviter des boucles infinies { //trace = pLevel->CheckRayMove(origin, origin+vVelocity*time_left, n->GetBBox()->vMin, n->GetBBox()->vMax); trace = Trace(origin, origin+vVelocity*time_left, n->GetBBox()->vMin, n->GetBBox()->vMax, n); ! //on trace avec une sphere, les mouvements semblent plus 'lisses' //trace = pLevel->CheckRayMove(origin+n->GetBBox()->vBSCenter, origin+n->GetBBox()->vBSCenter+vVelocity*time_left, TRACE_SPHERE, n->GetBBox()->fBSRadius); *************** *** 48,54 **** return; } ! if (trace.Fraction > 0 ) { origin = trace.EndPoint; } if (trace.Fraction == 1) --- 49,56 ---- return; } ! if (trace.Fraction > EPSILON ) { origin = trace.EndPoint; + //iNumPlanes = 0; } if (trace.Fraction == 1) *************** *** 58,72 **** time_left -= time_left*trace.Fraction; ! pPlanes.push_back(trace.Normal); iNumPlanes++; for (i=0; i<iNumPlanes; i++) { ! ClipVelocity (vVelocity, trace.Normal); for (j=0; j<iNumPlanes; j++) if (j != i) { ! if (vVelocity*pPlanes[j] < 0) break; } --- 60,81 ---- time_left -= time_left*trace.Fraction; + + if (iNumPlanes >= MAX_CLIP_PLANES) + { + std::cerr << "[TGE] iNumPlanes >= MAX_CLIP_PLANES" << std::endl; + vVelocity.Set(0,0,0); + break; + } ! pPlanes[iNumPlanes] = Plane(trace.Normal, trace.ColPlane.fD); iNumPlanes++; for (i=0; i<iNumPlanes; i++) { ! ClipVelocity (vVelocity, pPlanes[i].vNormal); for (j=0; j<iNumPlanes; j++) if (j != i) { ! if (vVelocity*pPlanes[j].vNormal < 0) break; } *************** *** 82,95 **** if (iNumPlanes != 2) { ! vVelocity = origin; break; } ! Vector3 dir = pPlanes[0]%pPlanes[1]; float d = dir*vVelocity; vVelocity = dir/d; } ! ! ! bumpcount++; } } --- 91,106 ---- if (iNumPlanes != 2) { ! vVelocity.Set(0,0,0); break; } ! Vector3 dir = pPlanes[0].vNormal%pPlanes[1].vNormal; float d = dir*vVelocity; vVelocity = dir/d; } ! ! if ((primal_velocity*vVelocity) <= 0) ! { ! vVelocity = Vector3::ZERO; ! } } } *************** *** 107,110 **** --- 118,128 ---- Vector3 change = norm*backoff; vel -= change; + #define STOP_EPSILON 0.1 + if (vel.x > -STOP_EPSILON && vel.x < STOP_EPSILON) + vel.x = 0; + if (vel.y > -STOP_EPSILON && vel.y < STOP_EPSILON) + vel.y = 0; + if (vel.z > -STOP_EPSILON && vel.z < STOP_EPSILON) + vel.z = 0; } *************** *** 200,203 **** --- 218,222 ---- //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é { *************** *** 214,218 **** //std::cout << n->GetVelocity() << std::endl; n->SetVelocity(vVelocity); ! } //mise a jour des volumes englobants n->CalculateBoundingVolume(); --- 233,237 ---- //std::cout << n->GetVelocity() << std::endl; n->SetVelocity(vVelocity); ! }*/ //mise a jour des volumes englobants n->CalculateBoundingVolume(); *************** *** 254,257 **** --- 273,277 ---- result.Fraction = mapResult.Fraction; result.AllSolid = mapResult.AllSolid; + result.ColPlane = mapResult.ColPlane; //on trace sur les objets Vector3 colPoint(0,0,0); Index: q3bsp.cc =================================================================== RCS file: /cvsroot/epfl/tgengine-0.1/q3bsp.cc,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** q3bsp.cc 17 Nov 2004 23:12:39 -0000 1.15 --- q3bsp.cc 22 Nov 2004 21:19:07 -0000 1.16 *************** *** 8,11 **** --- 8,81 ---- { + /*bool Q3Bsp::IsPolygonInside (BspPolygonFace* pof,BoundingBox* pBBox ) + { + for (int k=0; k<6; k++) + { + bool out=true; + for (int l=0; l<pof->numOfVerts; l++) + { + if(pBBox->pPlanes[k].ClassifyPoint(pVerts[pof->startVertIndex+l].vPosition) != POINT_BEHIND_PLANE) + { + out = false; + break; + } + } + if (out) + return false; + } + return true; + } + + Vector3 Q3Bsp::CalculateCollision(BoundingBox* pBBox, Vector3 pos) + { + bool* pVisibleFaces = new bool[numOfFaces]; + memset (pVisibleFaces, 0, sizeof(bool)*numOfFaces); + + //std::cout << "pos : " << pos << "\tvWorldBSCenter :" << pBBox->vWorldBSCenter << "\tvBSCenter :" << pBBox->vBSCenter << std::endl; + Vector3 vNewPosition = pos; + + int iLeaf = FindLeaf(vNewPosition); + int iCluster = pLeafs[iLeaf].cluster; + + + for (int i=0; i<numOfLeafs; i++) + { + if (!IsClusterVisible(iCluster, pLeafs[i].cluster)) + continue; + //TODO:on devrait tester si la BoundingBox du leaf est dans notre bounding box + for (int j=0; j<pLeafs[i].numOfLeafFaces; j++) + pVisibleFaces[pLeafFaces[pLeafs[i].leafface+j]] = true; + } + + for (int i=0; i<numOfFaces; i++) + { + float distance, distanceOver; + BspPolygonFace* pof; + bool c; + if (!pVisibleFaces[i]) + continue; + switch (pDirectory[i].type) + { + case PolygonFace: + c=true; + pof = &pPolygonFaces[pDirectory[i].typeIndex]; + + if (IsPolygonInside(pof, pBBox)) + { + distance = pof->plane.GetDistance(vNewPosition); + std::cout << "Polygon distance : " << distance << std::endl; + distanceOver = pBBox->fBSRadius-distance; + if (distanceOver > 0) + vNewPosition+=distanceOver*pof->plane.vNormal; + } + break; + + default: + break; + + } + } + return vNewPosition; + }*/ void Q3Bsp::TesselateBiquadraticPatch (BspVertex* controlPoints, BspVertex* vertices, int tess) *************** *** 378,381 **** --- 448,455 ---- Vector3 vMin (-TG_INFINITY, -TG_INFINITY, -TG_INFINITY); Vector3 vMax (TG_INFINITY, TG_INFINITY, TG_INFINITY); + Vector3 points[3]; + points[0] = pVertices[pof->startVertIndex].vPosition; + points[1] = pVertices[pof->startVertIndex+1].vPosition; + points[2] = pVertices[pof->startVertIndex+2].vPosition; for (int j=pof->startVertIndex; j < pof->startVertIndex + pof->numOfVerts; j++) *************** *** 392,398 **** } pof->vCenter /= pof->numOfVerts; ! ! ! polyCount++; } --- 466,471 ---- } pof->vCenter /= pof->numOfVerts; ! ! pof->plane.SetFromPoints(points[0], points[2], points[1]); polyCount++; } *************** *** 521,525 **** for (int i=0; i<numOfPlanes; i++) { ! SWAPFLOAT(pPlanes[i].d) SWAPFLOAT(pPlanes[i].vNormal.x) SWAPFLOAT(pPlanes[i].vNormal.y) --- 594,598 ---- for (int i=0; i<numOfPlanes; i++) { ! SWAPFLOAT(pPlanes[i].fD) SWAPFLOAT(pPlanes[i].vNormal.x) SWAPFLOAT(pPlanes[i].vNormal.y) *************** *** 793,797 **** //on calcule la distance pos - plan et on regarde si on est devant ou derriere le plan ! if (plane.vNormal*pos - plane.d >= 0) index = node.front; else --- 866,870 ---- //on calcule la distance pos - plan et on regarde si on est devant ou derriere le plan ! if (plane.vNormal*pos - plane.fD >= 0) index = node.front; else *************** *** 1093,1096 **** --- 1166,1181 ---- //glDrawArrays(GL_TRIANGLE_FAN, pFace->startVertIndex, pFace->numOfVerts); glDrawElements (GL_TRIANGLES, pFace->numOfMeshVerts, GL_UNSIGNED_INT, &pMeshIndices[pFace->firstMeshIndex]); + + //BEGIN NORMALs + glBegin (GL_LINES); + Vector3 norm = pFace->plane.vNormal; + Vector3 v1 = pFace->plane.v[0]+pFace->plane.v[1]+pFace->plane.v[2]; + v1 /= 3; + Vector3 v2 = v1+norm*50; + glVertex3fv(&v1.x); + glVertex3fv(&v2.x); + glEnd (); + //END NORMALS + continue; } *************** *** 1266,1271 **** BspPlane *plane = &pPlanes[node->plane]; ! float startDistance = plane->vNormal*Start - plane->d; ! float endDistance = plane->vNormal*End - plane->d; float offset; --- 1351,1356 ---- BspPlane *plane = &pPlanes[node->plane]; ! float startDistance = plane->vNormal*Start - plane->fD; ! float endDistance = plane->vNormal*End - plane->fD; float offset; *************** *** 1370,1373 **** --- 1455,1459 ---- Vector3 CandidateToHitNormal; + Plane CandidateToHitPlane; // Go for every brush side *************** *** 1381,1391 **** if (traceType == TRACE_RAY) { ! startDistance = (MStart*plane->vNormal) - plane->d; ! endDistance = ( MEnd*plane->vNormal) - plane->d; } else if (traceType == TRACE_SPHERE) { ! startDistance = (MStart*plane->vNormal) - (plane->d + radius); ! endDistance = (MEnd*plane->vNormal) - (plane->d + radius); } else if (traceType == TRACE_BOX) --- 1467,1477 ---- if (traceType == TRACE_RAY) { ! startDistance = (MStart*plane->vNormal) - plane->fD; ! endDistance = ( MEnd*plane->vNormal) - plane->fD; } else if (traceType == TRACE_SPHERE) { ! startDistance = (MStart*plane->vNormal) - (plane->fD + radius); ! endDistance = (MEnd*plane->vNormal) - (plane->fD + radius); } else if (traceType == TRACE_BOX) *************** *** 1395,1400 **** offset.y = plane->vNormal.y < 0 ? vBoxMax.y : vBoxMin.y; offset.z = plane->vNormal.z < 0 ? vBoxMax.z : vBoxMin.z; ! startDistance = (MStart+offset)*plane->vNormal - plane->d; ! endDistance = (MEnd+offset)*plane->vNormal - plane->d; } --- 1481,1486 ---- offset.y = plane->vNormal.y < 0 ? vBoxMax.y : vBoxMin.y; offset.z = plane->vNormal.z < 0 ? vBoxMax.z : vBoxMin.z; ! startDistance = (MStart+offset)*plane->vNormal - plane->fD; ! endDistance = (MEnd+offset)*plane->vNormal - plane->fD; } *************** *** 1428,1431 **** --- 1514,1518 ---- startFraction = fraction; CandidateToHitNormal = plane->vNormal; + CandidateToHitPlane = Plane(plane->vNormal, plane->fD); } } *************** *** 1465,1468 **** --- 1552,1556 ---- result.Fraction = startFraction; result.CollisionNormal = CandidateToHitNormal; // The candidate gets postulate! + result.ColPlane = CandidateToHitPlane; } } Index: q3bsp.h =================================================================== RCS file: /cvsroot/epfl/tgengine-0.1/q3bsp.h,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** q3bsp.h 17 Nov 2004 23:12:39 -0000 1.7 --- q3bsp.h 22 Nov 2004 21:19:07 -0000 1.8 *************** *** 26,29 **** --- 26,30 ---- bool StartOut; bool AllSolid; + Plane ColPlane; }; *************** *** 39,42 **** --- 40,44 ---- { protected: + //BEGIN STRUCT enum BspFaceType *************** *** 110,114 **** { Vector3 vNormal; ! float d; }; --- 112,116 ---- { Vector3 vNormal; ! float fD; }; *************** *** 180,183 **** --- 182,186 ---- int firstMeshIndex; int numOfMeshVerts; + Plane plane; }; *************** *** 384,388 **** int* bLightMaps; int* iBump; ! public: Q3Bsp (); --- 387,392 ---- int* bLightMaps; int* iBump; ! ! public: Q3Bsp (); Index: md5mesh10.h =================================================================== RCS file: /cvsroot/epfl/tgengine-0.1/md5mesh10.h,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** md5mesh10.h 19 Nov 2004 12:04:04 -0000 1.8 --- md5mesh10.h 22 Nov 2004 21:19:07 -0000 1.9 *************** *** 66,71 **** inline int anim_GetNumJoints(int i) { return pAnimations[i].iNumJoints; } inline int anim_GetFrameRate(int i) { return pAnimations[i].iFrameRate; } ! 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; } --- 66,74 ---- inline int anim_GetNumJoints(int i) { return pAnimations[i].iNumJoints; } inline int anim_GetFrameRate(int i) { return pAnimations[i].iFrameRate; } ! inline Quaternion anim_GetQuaternion (int i, int j, int k) { return pAnimations[i].pQuaternions[j][k]; } ! inline Vector3 anim_GetPosition (int i, int j, int k) { return pAnimations[i].pPositions[j][k]; } ! ! //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; } *************** *** 80,84 **** inline int anim_joint_GetStartIndex (int i, int j) { return pAnimations[i].pJointInfos[j].iStartIndex; } ! inline float anim_joint_GetBaseFrameElement (int i, int j, int k) { return pAnimations[i].pBaseFrame[j][k]; } protected: --- 83,87 ---- inline int anim_joint_GetStartIndex (int i, int j) { return pAnimations[i].pJointInfos[j].iStartIndex; } ! //inline float anim_joint_GetBaseFrameElement (int i, int j, int k) { return pAnimations[i].pBaseFrame[j][k]; } protected: *************** *** 122,126 **** int iFrameRate; int iNumAnimatedComponents; ! float** pFrames; //un tableau de [iNumFrames][iNumAnimatedComponents] float** pBaseFrame; //un tableau de [iNumJoints][6], stockant, dans l'ordre, Tx, Ty, Tz, Qx, Qy, Qz a la frame de base de l'animation struct _MD5JointInfos --- 125,131 ---- int iFrameRate; int iNumAnimatedComponents; ! //float** pFrames; //un tableau de [iNumFrames][iNumAnimatedComponents] ! Quaternion** pQuaternions; //un tableau de [iNumFrames][iNumJoints] Qx,Qy,Qz ! Vector3** pPositions; //un tableau de [iNumFrames][iNumJoints] Tx,Ty,Tz float** pBaseFrame; //un tableau de [iNumJoints][6], stockant, dans l'ordre, Tx, Ty, Tz, Qx, Qy, Qz a la frame de base de l'animation struct _MD5JointInfos *************** *** 186,195 **** }; - void ChangeCoords(Vector3& v) - { - float temp = v.y; - v.y = v.z; - v.z = -temp; - } }; --- 191,194 ---- Index: glrenderer.cc =================================================================== RCS file: /cvsroot/epfl/tgengine-0.1/glrenderer.cc,v retrieving revision 1.23 retrieving revision 1.24 diff -C2 -d -r1.23 -r1.24 *** glrenderer.cc 19 Nov 2004 18:54:42 -0000 1.23 --- glrenderer.cc 22 Nov 2004 21:19:07 -0000 1.24 *************** *** 1224,1228 **** #endif //les axes sont inverses dans les trucs ID ! glRotatef(-90, 1, 0, 0); _RotateNode(mesh); --- 1224,1228 ---- #endif //les axes sont inverses dans les trucs ID ! // glRotatef(-90, 1, 0, 0); _RotateNode(mesh); Index: physicengine.h =================================================================== RCS file: /cvsroot/epfl/tgengine-0.1/physicengine.h,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** physicengine.h 17 Nov 2004 23:12:39 -0000 1.9 --- physicengine.h 22 Nov 2004 21:19:07 -0000 1.10 *************** *** 19,22 **** --- 19,23 ---- //le node qui a ete touche. NULL si c'est la carte qui est touche ou si rien n'est touche PhysicNode* pNode; + Plane ColPlane; }; *************** *** 54,57 **** --- 55,59 ---- protected: void _TryToStep (PhysicNode*, float); + std::vector<PhysicNode*> pNodes; Index: Changelog =================================================================== RCS file: /cvsroot/epfl/tgengine-0.1/Changelog,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** Changelog 17 Nov 2004 23:12:37 -0000 1.6 --- Changelog 22 Nov 2004 21:19:06 -0000 1.7 *************** *** 1,13 **** --------------- 27 septembre 2004 --------------- ! Krtek ! * code cleaning (plus de warnings à la compilation) ! * modification des Makefile Silver: ! * le moteur physique tente de faire monter les petits obstacles ! (escaliers & autres) ! * code cleaning --------------- --- 1,86 ---- --------------- + 20 novembre 2004 + --------------- + Seb: + * SoundManager Changelog + --------------- + 11 novembre 2004 + --------------- + Silver: + * Ajout d'une classe de capture vidéo. Rajouter le flag -DTGVIDEO pour avoir un video.mpg en sortie :) (pris sur le code de Engine_0.2 de www.frustum.org ) + + Seb: + * Sortie video portee sur OSX + --------------- + 10 novembre 2004 + --------------- + Silver: + * Pas mal de deverminage dans les collisions et ailleurs + --------------- + 2 novembre 2004 + --------------- + Silver: + * Animations des MD5 + --------------- + 30 octobre 2004 + --------------- + Silver: + * Camera utilisant les quaternions qui fonctionne. + --------------- + 28 octobre 2004 + --------------- + Silver: + * Rotations utilisant les quaternions + --------------- + 24 octobre 2004 + --------------- + Silver: + * Rajout d'une fonction ToAngleVectors dans Vector3, qui considère les composants x,y,z comme des rotations autour de x,y,z et les transforme en vecteurs forward, right, up. + * Quelques bugs supprimées, notamment dans la gestion des rotations + --------------- + 21 octobre 2004 + --------------- + Silver: + * Refonte de la gestion de la hiérarchie physique. Ajoute de PhysicNode + * Changement dans la manière d'enregistrer des fonctions auprès de la console + * Suppression d'un bug lors de l'affichage de niveau non-originaux pour q3 (notamment pas mal de niveau Defrag) + --------------- + 15 octobre 2004 + --------------- + Silver: + * Ajout de classes "interceptant" les messages de cout/cerr de façon à les rediriger vers la console/fichier/terminal + * Nettoyage du code, ajout d'accesseurs + --------------- + 13 octobre 2004 + --------------- + Seb: + * SoundManager Changelog + --------------- + 10 octobre 2004 + --------------- + Silver: + * Ajout des PhysicCallBack, mécanisme qui permet d'appeler des fonctions membres de classes héritant de PhysicCallBack lorsqu'un objet entre en collision avec la map ou un autre objet. + * Quelques modifs pour permettre à l'IA de savoir si une région de la map est accessible ou pas (Q3Bsp::FindCluster) + --------------- + 28 septembre 2004 + --------------- + Silver: + * Portage Win32 (compile sur OSX aussi) + -------------- 27 septembre 2004 --------------- ! Seb: ! * beaucoup de bugs réglés pour la version OSX -> version actuellement sur le cvs compile et se lance sous osx, mais aussi Linux ! (voir screenshots) ! ! Krtek: ! * code cleaning (plus de warnings à la compilation) ! * modification des Makefile (ajout des target : linux, linuxDebug, mac et macDebug) Silver: ! * le moteur physique tente de faire monter les petits obstacles ! (escaliers & autres) ! * code cleaning ! * affichage des fps ! * chargement jpg et png --------------- *************** *** 15,19 **** --------------- Silver: ! * gestion little/big endian via des classes LittleEndian/BigEndian (fichier endian.h) --- 88,92 ---- --------------- Silver: ! * gestion little/big endian via des classes LittleEndian/BigEndian (fichier endian.h) *************** *** 22,27 **** --------------- Silver: ! * update du cvs avec les dernieres sources ! * en vrac, support du bsp, des md5 version 10 (finale) de doom3 --------------- --- 95,100 ---- --------------- Silver: ! * update du cvs avec les dernieres sources ! * en vrac, support du bsp, des md5 version 10 (finale) de doom3 --------------- *************** *** 29,39 **** --------------- Silver ! * ajout d'un TextureManager. Evite qu'il y ait plusieurs fois la même texture chargée en mémoire. De même, si ! ladite texture ne peut pas être chargée, met une texture blanche à la place ! ! * debut du projet ! * support des textures au format TGA et BMP ! * support du MD5 (DOOM III) ! * support du dot3 bump-mapping ! * debut du support pour gui --- 102,111 ---- --------------- Silver ! * ajout d'un TextureManager. Evite qu'il y ait plusieurs fois la même texture chargée en mémoire. De même, si ! ladite texture ne peut pas être chargée, met une texture blanche à la place + * debut du projet + * support des textures au format TGA et BMP + * support du MD5 (DOOM III) + * support du dot3 bump-mapping + * debut du support pour gui Index: md5mesh10.cc =================================================================== RCS file: /cvsroot/epfl/tgengine-0.1/md5mesh10.cc,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** md5mesh10.cc 19 Nov 2004 12:04:04 -0000 1.9 --- md5mesh10.cc 22 Nov 2004 21:19:07 -0000 1.10 *************** *** 29,35 **** for (int j=0; j<pAnimations[i].iNumFrames; j++) ! delete [] pAnimations[i].pFrames[j]; ! delete [] pAnimations[i].pFrames; ! } pAnimations.clear(); --- 29,38 ---- for (int j=0; j<pAnimations[i].iNumFrames; j++) ! { ! delete [] pAnimations[i].pQuaternions[j]; ! delete [] pAnimations[i].pPositions[j]; ! } ! delete [] pAnimations[i].pQuaternions; ! delete [] pAnimations[i].pPositions; } pAnimations.clear(); *************** *** 89,104 **** 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]; --- 92,105 ---- pFD >> pJoints[i].vPosition.x >> pJoints[i].vPosition.y >> pJoints[i].vPosition.z; ! Util::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; } pMeshes = new _MD5Mesh[iNumMeshes]; *************** *** 177,181 **** NEXT("(") pFD >> w.vWeights.x >> w.vWeights.y >> w.vWeights.z; ! //Util::ChangeCoords(w.vWeights); } } --- 178,182 ---- NEXT("(") pFD >> w.vWeights.x >> w.vWeights.y >> w.vWeights.z; ! Util::ChangeCoords(w.vWeights); } } *************** *** 228,235 **** 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]; --- 229,237 ---- NEXT("numAnimatedComponents") pFD >> anim.iNumAnimatedComponents; ! ! float** pFrames; ! pFrames = new float*[anim.iNumFrames]; for (int i=0; i<anim.iNumFrames; i++) ! pFrames[i] = new float[anim.iNumAnimatedComponents]; anim.pJointInfos = new _MD5Anim::_MD5JointInfos[anim.iNumJoints]; *************** *** 254,260 **** --- 256,264 ---- NEXT("(") pFD >> anim.pBBox[i].vMin.x >> anim.pBBox[i].vMin.y >> anim.pBBox[i].vMin.z; + Util::ChangeCoords(anim.pBBox[i].vMin); NEXT(")") NEXT("(") pFD >> anim.pBBox[i].vMax.x >> anim.pBBox[i].vMax.y >> anim.pBBox[i].vMax.z; + Util::ChangeCoords(anim.pBBox[i].vMax); NEXT(")") *************** *** 283,289 **** 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; --- 287,372 ---- NEXT("{") for (int j=0; j<anim.iNumAnimatedComponents; j++) ! pFD >> pFrames[i][j]; NEXT("}") } + + anim.pQuaternions = new Quaternion*[anim.iNumFrames]; + for (int i=0; i<anim.iNumFrames; i++) + anim.pQuaternions[i] = new Quaternion[anim.iNumJoints]; + + anim.pPositions = new Vector3*[anim.iNumFrames]; + for (int i=0; i<anim.iNumFrames; i++) + anim.pPositions[i] = new Vector3[anim.iNumJoints]; + + for (int i=0; i<anim.iNumFrames; i++) + for (int j=0; j<anim.iNumJoints; j++) + { + int n = anim.pJointInfos[j].iStartIndex; + int flags = anim.pJointInfos[j].iFlags; + + //Tx + if (flags & 1) + { + anim.pPositions[i][j].x = pFrames[i][n]; + n++; + } + else + anim.pPositions[i][j].x = anim.pBaseFrame[j][0]; + + //Ty + if (flags & 2) + { + anim.pPositions[i][j].y = pFrames[i][n]; + n++; + } + else + anim.pPositions[i][j].y = anim.pBaseFrame[j][1]; + + //Tz + if (flags & 4) + { + anim.pPositions[i][j].z = pFrames[i][n]; + n++; + } + else + anim.pPositions[i][j].z = anim.pBaseFrame[j][2]; + + //Qx + if (flags & 8) + { + anim.pQuaternions[i][j].x = pFrames[i][n]; + n++; + } + else + anim.pQuaternions[i][j].x = anim.pBaseFrame[j][3]; + + //Qy + if (flags & 16) + { + anim.pQuaternions[i][j].y = pFrames[i][n]; + n++; + } + else + anim.pQuaternions[i][j].y = anim.pBaseFrame[j][4]; + + //Qz + if (flags & 32) + { + anim.pQuaternions[i][j].z = pFrames[i][n]; + n++; + } + else + anim.pQuaternions[i][j].z = anim.pBaseFrame[j][5]; + + Util::ChangeCoords(anim.pQuaternions[i][j].x, anim.pQuaternions[i][j].y, anim.pQuaternions[i][j].z); + Util::ChangeCoords(anim.pPositions[i][j]); + anim.pQuaternions[i][j].ComputeR(); + + } + + for (int i=0; i<anim.iNumFrames; i++) + delete [] pFrames[i]; + delete [] pFrames; + pAnimations.push_back(anim); std::cout << "[TGE] Chargement de " << str << " termine" << std::endl; Index: md5instance.cc =================================================================== RCS file: /cvsroot/epfl/tgengine-0.1/md5instance.cc,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** md5instance.cc 19 Nov 2004 18:54:42 -0000 1.15 --- md5instance.cc 22 Nov 2004 21:19:07 -0000 1.16 *************** *** 228,327 **** void MD5Instance::_BuildBone (int iFrame, Joint* pJoint,const Quaternion& q, const Vector3& v) { ! /*pJoint->vPosition.x = pData->anim_joint_GetBaseFrameElement(iCurrentAnimation, pJoint->iNumber, 0) + v.x; ! pJoint->vPosition.y = pData->anim_joint_GetBaseFrameElement(iCurrentAnimation, pJoint->iNumber, 1) + v.y; ! pJoint->vPosition.z = pData->anim_joint_GetBaseFrameElement(iCurrentAnimation, pJoint->iNumber, 2) + v.z; ! ! pJoint->qOrientation.x = pData->anim_joint_GetBaseFrameElement(iCurrentAnimation, pJoint->iNumber, 3) + v.x; ! pJoint->qOrientation.y = pData->anim_joint_GetBaseFrameElement(iCurrentAnimation, pJoint->iNumber, 4) + v.y; ! pJoint->qOrientation.z = pData->anim_joint_GetBaseFrameElement(iCurrentAnimation, pJoint->iNumber, 5) + v.z; ! ! float term = 1.0f - (pJoint->qOrientation.x*pJoint->qOrientation.x) - (pJoint->qOrientation.y*pJoint->qOrientation.y) - (pJoint->qOrientation.z*pJoint->qOrientation.z); ! if (term < 0.0f) ! pJoint->qOrientation.r = 0.0f; ! else ! pJoint->qOrientation.r = - (float) sqrt(term); */ ! Vector3 animatedPosition; ! animatedPosition.x = pData->anim_joint_GetBaseFrameElement(iCurrentAnimation, pJoint->iNumber, 0); ! animatedPosition.y = pData->anim_joint_GetBaseFrameElement(iCurrentAnimation, pJoint->iNumber, 1); ! animatedPosition.z = pData->anim_joint_GetBaseFrameElement(iCurrentAnimation, pJoint->iNumber, 2); ! ! Quaternion animatedOrientation; ! animatedOrientation.x = pData->anim_joint_GetBaseFrameElement(iCurrentAnimation, pJoint->iNumber, 3); ! animatedOrientation.y = pData->anim_joint_GetBaseFrameElement(iCurrentAnimation, pJoint->iNumber, 4); ! animatedOrientation.z = pData->anim_joint_GetBaseFrameElement(iCurrentAnimation, pJoint->iNumber, 5); ! ! ! int flags = pData->anim_joint_GetFlags(iCurrentAnimation, pJoint->iNumber); ! int n=0; ! int sIndex = pData->anim_joint_GetStartIndex(iCurrentAnimation, pJoint->iNumber); ! ! ! //glPushMatrix (); ! // std::cout << "flags : " << std::endl; ! //std::cout << "joint : " << pJoint->iNumber << std::endl; ! if (flags & 1) //Tx est anime ! { ! // std::cout << "Tx"; ! animatedPosition.x = pData->anim_GetFrameElement(iCurrentAnimation, iFrame, sIndex+n); ! n++; ! } ! if (flags & 2) //Ty est anime ! { ! // std::cout << " Ty"; ! animatedPosition.y = pData->anim_GetFrameElement(iCurrentAnimation, iFrame, sIndex+n); ! n++; ! } ! if (flags & 4) //Tz est anime ! { ! // std::cout << " Tz"; ! animatedPosition.z = pData->anim_GetFrameElement(iCurrentAnimation, iFrame, sIndex+n); ! n++; ! } ! if (flags & 8) //Qx est anime ! { ! // std::cout << " Qx"; ! animatedOrientation.x = pData->anim_GetFrameElement(iCurrentAnimation, iFrame, sIndex+n); ! n++; ! } ! if (flags & 16) //Qy est anime ! { ! // std::cout << " Qy"; ! animatedOrientation.y = pData->anim_GetFrameElement(iCurrentAnimation, iFrame, sIndex+n); ! n++; ! } ! if (flags & 32) //Qz est anime ! { ! // std::cout << " Qz"; ! animatedOrientation.z = pData->anim_GetFrameElement(iCurrentAnimation, iFrame, sIndex+n); ! n++; ! } ! //std::cout << std::endl; ! ! animatedOrientation.ComputeR(); ! if (pJoint->iParent < 0) //pas de parent ! { ! pJoint->vPosition = animatedPosition; ! pJoint->qOrientation = animatedOrientation; ! } ! else //parent ! { ! pJoint->vPosition = q.Rotate(animatedPosition); ! pJoint->vPosition += v; ! pJoint->qOrientation = q*animatedOrientation; ! } ! 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++) ! { ! _BuildBone(iFrame,pJoint->pChildrens[i], pJoint->qOrientation, pJoint->vPosition); ! } - //glPopMatrix (); } void MD5Instance::SetAnimation (const std::string& name) --- 228,257 ---- void MD5Instance::_BuildBone (int iFrame, Joint* pJoint,const Quaternion& q, const Vector3& v) { ! Vector3 animatedPosition = pData->anim_GetPosition(iCurrentAnimation, iFrame, pJoint->iNumber); ! Quaternion animatedOrientation = pData->anim_GetQuaternion(iCurrentAnimation, iFrame, pJoint->iNumber); ! if (pJoint->iParent < 0) //pas de parent ! { ! pJoint->vPosition = animatedPosition; ! pJoint->qOrientation = animatedOrientation; ! } ! else //parent ! { ! pJoint->vPosition = q.Rotate(animatedPosition); ! pJoint->vPosition += v; ! pJoint->qOrientation = q*animatedOrientation; ! } ! 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++) ! { ! _BuildBone(iFrame,pJoint->pChildrens[i], pJoint->qOrientation, pJoint->vPosition); ! } } void MD5Instance::SetAnimation (const std::string& name) Index: plane.cc =================================================================== RCS file: /cvsroot/epfl/tgengine-0.1/plane.cc,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** plane.cc 17 Nov 2004 23:12:39 -0000 1.3 --- plane.cc 22 Nov 2004 21:19:07 -0000 1.4 *************** *** 30,38 **** int Plane::ClassifyPoint (const Vector3& v) { ! float distance = v*vNormal + fD; ! if (distance > 0) return POINT_IN_FRONT_OF_PLANE; ! if (distance < 0) return POINT_BEHIND_PLANE; --- 30,38 ---- int Plane::ClassifyPoint (const Vector3& v) { ! float distance = GetDistance(v); ! if (distance > EPSILON) return POINT_IN_FRONT_OF_PLANE; ! if (distance < EPSILON) return POINT_BEHIND_PLANE; |