|
From: julien r. <jul...@us...> - 2004-10-28 21:10:32
|
Update of /cvsroot/epfl/tgengine-0.1 In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31280 Modified Files: camera.cc glrenderer.cc md5instance.cc md5instance.h physicengine.cc physicnode.cc physicnode.h quaternion.cc quaternion.h scenemanager.cc scenenode.cc scenenode.h Log Message: rotation utilisent des quaternions Index: physicengine.cc =================================================================== RCS file: /cvsroot/epfl/tgengine-0.1/physicengine.cc,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** physicengine.cc 24 Oct 2004 16:56:20 -0000 1.13 --- physicengine.cc 28 Oct 2004 21:10:16 -0000 1.14 *************** *** 96,100 **** n->SetPosition(n->GetPosition()+n->GetVelocity()*eTime); ! n->SetRotation(n->GetRotation()+n->GetRotationVelocity()*eTime); n->UpdatePosition(); --- 96,101 ---- n->SetPosition(n->GetPosition()+n->GetVelocity()*eTime); ! //n->SetRotation(n->GetRotation()+n->GetRotationVelocity()*eTime); ! n->SetRotation(n->GetRotation()*n->GetRotationVelocity()*eTime); n->UpdatePosition(); *************** *** 185,190 **** n->SetOnGround(false); ! n->SetRotation(n->GetRotation()+n->GetRotationVelocity()*eTime); ! n->UpdatePosition(); } --- 186,199 ---- n->SetOnGround(false); ! //n->SetRotation(n->GetRotation()+n->GetRotationVelocity()*eTime); ! /*n->SetRotation(n->GetRotation()*n->GetRotationVelocity()*eTime);*/ ! /*static float angle =0 ; ! angle+=1; ! angle=0; ! Quaternion q(angle, Vector3(0,0,0));*/ ! Quaternion q = n->GetRotationVelocity()*eTime; ! q.Normalize(); ! n->SetRotation(n->GetRotation()*q); ! n->UpdatePosition(); } Index: scenemanager.cc =================================================================== RCS file: /cvsroot/epfl/tgengine-0.1/scenemanager.cc,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** scenemanager.cc 24 Oct 2004 16:56:20 -0000 1.10 --- scenemanager.cc 28 Oct 2004 21:10:16 -0000 1.11 *************** *** 59,62 **** --- 59,90 ---- pCamera->Update (frameInterval); pCamera->Look (); + + glPushMatrix(); + + Quaternion q = pCamera->GetRotation(); + Vector3 fwd, rgt, up; + fwd = q.GetXAxis(); + rgt = q.GetZAxis(); + up = q.GetYAxis(); + + fwd *= 10; + rgt *= 10; + up *= 10; + //glTranslatef(-13,-10,-20); + glDisable (GL_TEXTURE_2D); + 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 (); + glPopMatrix (); //Engine::pRenderer->RenderBBox(pCamera->pBBox); } Index: quaternion.h =================================================================== RCS file: /cvsroot/epfl/tgengine-0.1/quaternion.h,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** quaternion.h 24 Oct 2004 13:36:59 -0000 1.2 --- quaternion.h 28 Oct 2004 21:10:16 -0000 1.3 *************** *** 18,22 **** public: inline Quaternion () : r(1), x(0), y(0), z(0) {} //par defaut, on met le quaternion identite ! inline Quaternion (float f, float i, float j, float k) { SetRotation(f,i,j,k); } inline Quaternion (const Quaternion& q) : r(q.r), x(q.x), y(q.y), z(q.z) {} inline Quaternion (float f, Vector3 v) { SetRotation(f, v);} --- 18,22 ---- public: inline Quaternion () : r(1), x(0), y(0), z(0) {} //par defaut, on met le quaternion identite ! inline Quaternion (float f, float i, float j, float k) : r(f), x(i), y(j), z(k) {} inline Quaternion (const Quaternion& q) : r(q.r), x(q.x), y(q.y), z(q.z) {} inline Quaternion (float f, Vector3 v) { SetRotation(f, v);} *************** *** 39,42 **** --- 39,46 ---- float Magnitude (); + Vector3 GetXAxis() const; + Vector3 GetYAxis() const; + Vector3 GetZAxis() const; + /** * Trouve la valeure de R, utilise par les mesh au format md5 *************** *** 45,65 **** /** - * Utilise par le md5 lorsque des valeurs de quaternions semblent s'inverser - */ - /*inline void CheckCoSom () { float c = - - - float cosom = q1[0] * q2[0] + q1[1] * q2[1] + q1[2] * q2[2] + q1[3] * q2[3]; - if (cosom < 0.0f) - { - q2[0] = -q2[0]; - q2[1] = -q2[1]; - q2[2] = -q2[2]; - q2[3] = -q2[3]; - } */ - /** * Normalise le quaternion */ void Normalize (); Quaternion Inverse (); --- 49,57 ---- /** * Normalise le quaternion */ void Normalize (); + + void GetMatrix (float*) const; Quaternion Inverse (); *************** *** 77,80 **** --- 69,74 ---- */ float GetRotationAngle (); + + void FromEuler (float, float, float); /** Index: physicnode.cc =================================================================== RCS file: /cvsroot/epfl/tgengine-0.1/physicnode.cc,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** physicnode.cc 24 Oct 2004 13:36:59 -0000 1.2 --- physicnode.cc 28 Oct 2004 21:10:16 -0000 1.3 *************** *** 14,19 **** vPosition.Null(); vAccel.Null(); ! vEuler.Null(); ! vEulerVelocity.Null(); } --- 14,20 ---- vPosition.Null(); vAccel.Null(); ! ! //vEuler.Null(); ! //vEulerVelocity.Null(); } *************** *** 24,28 **** n = vNodes[i]; n->SetPosition(vPosition); ! n->SetRotation(vEuler); } } --- 25,29 ---- n = vNodes[i]; n->SetPosition(vPosition); ! n->SetRotation(qRotation); } } Index: physicnode.h =================================================================== RCS file: /cvsroot/epfl/tgengine-0.1/physicnode.h,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** physicnode.h 24 Oct 2004 13:36:59 -0000 1.2 --- physicnode.h 28 Oct 2004 21:10:16 -0000 1.3 *************** *** 6,9 **** --- 6,10 ---- #include "boundingbox.h" #include "scenenode.h" + #include "quaternion.h" *************** *** 86,90 **** /* Rotation */ ! inline Vector3 GetRotation () { return vEuler; } inline void SetRotation (const Vector3& v) { vEuler = v; } inline void AddRotation (const Vector3& v) { vEuler += v; } --- 87,93 ---- /* Rotation */ ! inline Quaternion GetRotation () { return qRotation; } ! inline void SetRotation (const Quaternion& q) { qRotation = q; } ! /*inline Vector3 GetRotation () { return vEuler; } inline void SetRotation (const Vector3& v) { vEuler = v; } inline void AddRotation (const Vector3& v) { vEuler += v; } *************** *** 97,104 **** inline void AddXRot (float f) { vEuler.x += f; } inline void AddYRot (float f) { vEuler.y += f; } ! inline void AddZRot (float f) { vEuler.z += f; } /* Vitesse de rotation */ ! inline Vector3 GetRotationVelocity () { return vEulerVelocity; } inline void SetRotationVelocity (const Vector3& v) { vEulerVelocity = v; } inline void AddRotVelocity (const Vector3& v) { vEulerVelocity += v; } --- 100,109 ---- inline void AddXRot (float f) { vEuler.x += f; } inline void AddYRot (float f) { vEuler.y += f; } ! inline void AddZRot (float f) { vEuler.z += f; }*/ /* Vitesse de rotation */ ! inline Quaternion GetRotationVelocity () { return qRotationVelocity; } ! inline void SetRotationVelocity (const Quaternion& q) { qRotationVelocity = q; } ! /*inline Vector3 GetRotationVelocity () { return vEulerVelocity; } inline void SetRotationVelocity (const Vector3& v) { vEulerVelocity = v; } inline void AddRotVelocity (const Vector3& v) { vEulerVelocity += v; } *************** *** 111,115 **** inline void AddXRotVelocity (float f) { vEulerVelocity.x += f; } inline void AddYRotVelocity (float f) { vEulerVelocity.y += f; } ! inline void AddZRotVelocity (float f) { vEulerVelocity.z += f; } void UpdatePosition (); --- 116,120 ---- inline void AddXRotVelocity (float f) { vEulerVelocity.x += f; } inline void AddYRotVelocity (float f) { vEulerVelocity.y += f; } ! inline void AddZRotVelocity (float f) { vEulerVelocity.z += f; }*/ void UpdatePosition (); *************** *** 122,127 **** Vector3 vAccel; Vector3 vVelocity; ! Vector3 vEuler; ! Vector3 vEulerVelocity; Vector3 vPosition; BoundingBox* pBBox; --- 127,134 ---- Vector3 vAccel; Vector3 vVelocity; ! //Vector3 vEuler; ! //Vector3 vEulerVelocity; ! Quaternion qRotation; ! Quaternion qRotationVelocity; Vector3 vPosition; BoundingBox* pBBox; Index: scenenode.h =================================================================== RCS file: /cvsroot/epfl/tgengine-0.1/scenenode.h,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** scenenode.h 24 Oct 2004 16:56:20 -0000 1.6 --- scenenode.h 28 Oct 2004 21:10:16 -0000 1.7 *************** *** 38,42 **** /* Rotation */ ! Vector3 GetRotation () { return vEuler; } virtual void SetRotation (const Vector3& v) { vEuler = v; } inline float GetXRot () { return vEuler.x; } --- 38,44 ---- /* 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; } *************** *** 48,52 **** 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 */ --- 50,54 ---- 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 */ *************** *** 63,67 **** //PhysicCallBack* pPhysicCallBack; bool bRender; ! Vector3 vEuler; Vector3 vPosition; --- 65,70 ---- //PhysicCallBack* pPhysicCallBack; bool bRender; ! //Vector3 vEuler; ! Quaternion qRotation; Vector3 vPosition; Index: quaternion.cc =================================================================== RCS file: /cvsroot/epfl/tgengine-0.1/quaternion.cc,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** quaternion.cc 26 Sep 2004 13:15:23 -0000 1.1.1.1 --- quaternion.cc 28 Oct 2004 21:10:16 -0000 1.2 *************** *** 78,81 **** --- 78,138 ---- } + Vector3 Quaternion::GetXAxis () const + { + //float tx = 2*x; + float ty = 2*y; + float tz = 2*z; + float twy = ty*r; + float twz = tz*r; + float txy = ty*x; + float txz = tz*x; + float tyy = ty*y; + float tzz = tz*z; + + return Vector3 (1.0f-(tyy+tzz), txy+twz, txz-twy); + } + + Vector3 Quaternion::GetYAxis () const + { + float tx = 2*x; + float ty = 2*y; + float tz = 2*z; + float twx = tx*r; + float twz = tz*r; + float txx = tx*x; + float txy = ty*x; + float tyz = tz*y; + float tzz = tz*z; + + return Vector3(txy-twz, 1.0f-(txx+tzz), tyz+twx); + } + + Vector3 Quaternion::GetZAxis () const + { + float tx = 2*x; + float ty = 2*y; + float tz = 2*z; + float twx = tx*r; + float twy = ty*r; + float txx = tx*x; + float txz = tz*x; + float tyy = ty*y; + float tyz = tz*y; + + return Vector3(txz+twy, tyz-twx, 1.0f-(txx+tyy)); + } + + void Quaternion::FromEuler(float x, float y, float z) + { + Quaternion qx (x, Vector3(1,0,0)); + Quaternion qy (y, Vector3(0,1,0)); + Quaternion qz (z, Vector3(0,0,1)); + Quaternion qt; + + qt = qx*qy; + *this = qt*qz; + } + + float Quaternion::Norm() { *************** *** 114,120 **** Vector3 Quaternion::Rotate (const Vector3& v) const { //nVidia SDK // trouve dans Ogre3d ! Vector3 uv, uuv; Vector3 qvec(x,y,z); uv = qvec%v; --- 171,184 ---- Vector3 Quaternion::Rotate (const Vector3& v) const { + Quaternion vec(0, v.x, v.y, v.z); + Quaternion q = *this; + Quaternion qinv = q.Conjugate(); + + Quaternion vec2 = q*vec*qinv; + + return Vector3 (vec2.x, vec2.y, vec2.z); //nVidia SDK // trouve dans Ogre3d ! /*Vector3 uv, uuv; Vector3 qvec(x,y,z); uv = qvec%v; *************** *** 122,134 **** uv *= (2.0f*r); uuv *= 2.0f; ! return v + uv + uuv; ! /* Quaternion qv(0, v.x, v.y, v.z); Quaternion qm = (*this)*qv*(this->Inverse()); return Vector3 (qm.x, qm.y, qm.z);*/ } void Quaternion::SetRotation (float a,const Vector3& tv) { Vector3 tmp = tv.Normalize (); float sin_a = sinf (a/2); float cos_a = cosf (a/2); --- 186,222 ---- uv *= (2.0f*r); uuv *= 2.0f; ! return v + uv + uuv;*/ ! /*Quaternion qv(0, v.x, v.y, v.z); Quaternion qm = (*this)*qv*(this->Inverse()); return Vector3 (qm.x, qm.y, qm.z);*/ } + void Quaternion::GetMatrix(float* m) const + { + m[0] = 1.0f - 2.0f * (y * y + z * z); + m[1] = 2.0f * (x * y + z * r); + m[2] = 2.0f * (x * z - y * r); + m[3] = 0.0f; + + m[4] = 2.0f * (x * y - z * r); + m[5] = 1.0f - 2.0f * (x * x + z * z); + m[6] = 2.0f * (z * y + x * r); + m[7] = 0.0f; + + m[8] = 2.0f * (x * z + y * r); + m[9] = 2.0f * (y * z - x * r); + m[10] = 1.0f - 2.0f * (x * x + y * y); + m[11] = 0.0f; + + m[12] = 0; + m[13] = 0; + m[14] = 0; + m[15] = 1.0f; + } + void Quaternion::SetRotation (float a,const Vector3& tv) { Vector3 tmp = tv.Normalize (); + a *= DEGTORAD; float sin_a = sinf (a/2); float cos_a = cosf (a/2); *************** *** 137,141 **** z = tmp.z*sin_a; r = cos_a; - this->Normalize(); } --- 225,228 ---- Index: md5instance.h =================================================================== RCS file: /cvsroot/epfl/tgengine-0.1/md5instance.h,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** md5instance.h 30 Sep 2004 09:23:16 -0000 1.4 --- md5instance.h 28 Oct 2004 21:10:16 -0000 1.5 *************** *** 49,53 **** void DrawVisibleEdges () {} protected: ! void _BuildBone (int, Joint*,const Quaternion&, const Vector3&); void _SkinMesh (); void _CalculateBBox (); --- 49,53 ---- void DrawVisibleEdges () {} protected: ! void _BuildBone (int, Joint*, const Quaternion&, const Vector3&); void _SkinMesh (); void _CalculateBBox (); Index: scenenode.cc =================================================================== RCS file: /cvsroot/epfl/tgengine-0.1/scenenode.cc,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** scenenode.cc 24 Oct 2004 16:56:20 -0000 1.6 --- scenenode.cc 28 Oct 2004 21:10:16 -0000 1.7 *************** *** 6,14 **** { vPosition.Null(); - // vVelocity.Null(); - // vAccel.Null(); pBBox = new BoundingBox (); ! vEuler.Null(); // bNoClip = false; --- 6,12 ---- { vPosition.Null(); pBBox = new BoundingBox (); ! //vEuler.Null(); // bNoClip = false; *************** *** 24,32 **** vPosition = p; - // vVelocity.Null(); - // vAccel.Null(); pBBox = new BoundingBox (); ! vEuler.Null(); // bNoClip = false; --- 22,28 ---- vPosition = p; pBBox = new BoundingBox (); ! //vEuler.Null(); // bNoClip = false; Index: glrenderer.cc =================================================================== RCS file: /cvsroot/epfl/tgengine-0.1/glrenderer.cc,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** glrenderer.cc 24 Oct 2004 14:51:54 -0000 1.10 --- glrenderer.cc 28 Oct 2004 21:10:16 -0000 1.11 *************** *** 776,782 **** void GLRenderer::_RotateNode (SceneNode* s) { ! glRotatef(s->GetRotation().x, 1, 0, 0); glRotatef(s->GetRotation().y, 0, 1, 0); ! glRotatef(s->GetRotation().z, 0, 0, 1); /*Vector3 axis = s->GetRotation().GetRotationAxis(); glRotatef(s->GetRotation().GetRotationAngle(),axis.x, axis.y, axis.z);*/ --- 776,785 ---- void GLRenderer::_RotateNode (SceneNode* s) { ! float matrix[16]; ! s->GetRotation().GetMatrix(matrix); ! glMultMatrixf (matrix); ! /*glRotatef(s->GetRotation().x, 1, 0, 0); glRotatef(s->GetRotation().y, 0, 1, 0); ! glRotatef(s->GetRotation().z, 0, 0, 1);*/ /*Vector3 axis = s->GetRotation().GetRotationAxis(); glRotatef(s->GetRotation().GetRotationAngle(),axis.x, axis.y, axis.z);*/ *************** *** 1062,1069 **** glTranslatef(mesh->GetPosition().x, mesh->GetPosition().y, mesh->GetPosition().z); - #ifdef DEBUG Vector3 fwd, rgt, up; ! mesh->GetRotation().ToAngleVectors(fwd, rgt, up); fwd *= 10; rgt *= 10; --- 1065,1077 ---- 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; *************** *** 1086,1105 **** _RotateNode(mesh); - glLineWidth(3.0f); - glBegin (GL_LINES); - glColor3f(1,0,0); - glVertex3f (0,0,0); - glVertex3f (10,0,0); - - glColor3f(0,0,1); - glVertex3f(0,0,0); - glVertex3f(0,0,10); - - glColor3f(0,1,0); - glVertex3f(0,0,0); - glVertex3f(0,10,0); - glEnd (); - glLineWidth(1.0f); - glScalef(mesh->fScale, mesh->fScale, mesh->fScale); --- 1094,1097 ---- Index: camera.cc =================================================================== RCS file: /cvsroot/epfl/tgengine-0.1/camera.cc,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** camera.cc 24 Oct 2004 14:51:54 -0000 1.5 --- camera.cc 28 Oct 2004 21:10:16 -0000 1.6 *************** *** 96,100 **** }*/ ! vRot.ToAngleVectors(vForward, vRight, vUp); //_AngleToVectors (); } --- 96,103 ---- }*/ ! //vRot.ToAngleVectors(vForward, vRight, vUp); ! vForward = qRotation.GetXAxis (); ! vRight = qRotation.GetZAxis (); ! vUp = qRotation.GetYAxis (); //_AngleToVectors (); } *************** *** 136,141 **** { glMatrixMode (GL_MODELVIEW); ! glRotatef(vEuler.x, 1.0f, 0.0f, 0.0f); ! glRotatef(vEuler.y, 0.0f, 1.0f, 0.0f); glTranslatef(-vPosition.x, -vPosition.y, -vPosition.z); frustum.Update(); --- 139,148 ---- { glMatrixMode (GL_MODELVIEW); ! //glRotatef (vEuler.z, 1.0f, 0.0f, 1.0f); ! //glRotatef(vEuler.x, 1.0f, 0.0f, 0.0f); ! //glRotatef(vEuler.y, 0.0f, 1.0f, 0.0f); ! float matrix[16]; ! qRotation.GetMatrix(matrix); ! glMultMatrixf (matrix); glTranslatef(-vPosition.x, -vPosition.y, -vPosition.z); frustum.Update(); Index: md5instance.cc =================================================================== RCS file: /cvsroot/epfl/tgengine-0.1/md5instance.cc,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** md5instance.cc 30 Sep 2004 09:23:16 -0000 1.5 --- md5instance.cc 28 Oct 2004 21:10:16 -0000 1.6 *************** *** 168,172 **** } ! 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; --- 168,172 ---- } ! 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; |