|
From: julien r. <jul...@us...> - 2004-10-21 21:21:14
|
Update of /cvsroot/epfl/tgengine-0.1 In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4017 Added Files: meshmanager.cc meshmanager.h physicnode.cc physicnode.h Log Message: ajout de physicnode et meshmanager --- NEW FILE: physicnode.cc --- #include "physicnode.h" namespace tg { PhysicNode::PhysicNode(SceneNode* n) { pBBox=n->GetBBox(); bClip=true; bOnGround = false; vNodes.clear(); vNodes.push_back(n); pPhysicCallBack = NULL; vVelocity.Null(); vPosition.Null(); vAccel.Null(); vEuler.Null(); vEulerVelocity.Null(); } void PhysicNode::UpdatePosition () { SceneNode* n; for (unsigned int i=0; i<vNodes.size(); i++) { n = vNodes[i]; n->SetPosition(vPosition); n->SetEuler(vEuler); } } void PhysicNode::CalculateBoundingVolume () { } } --- NEW FILE: physicnode.h --- #ifndef _TGPHYSICNODE_H #define _TGPHYSICNODE_H #include "defs.h" #include "vector3.h" #include "boundingbox.h" #include "scenenode.h" namespace tg { /** * représentation physique d'un ou plusieurs scenenode * les scenenode sont attachés à des physicnodes qui s'occupe de mettre à jour la position des éléments attachés * lors de l'appel à la méthode UpdatePosition du moteur physic */ class PhysicNode { public: PhysicNode (SceneNode* n); ~PhysicNode (); inline void AttachNode (SceneNode* s) { vNodes.push_back(s); } inline BoundingBox* GetBBox () { return pBBox; } /** * Retourne un pointeur sur la classe servant de callback en cas de collision * @return PhysicCallBack* un pointeur sur la classe contenant la méthode callback */ inline PhysicCallBack* GetPhysicCallBack() { return pPhysicCallBack; } /** * Change la classe contenant la méthode callback * @param PhysicCallBack un pointeur sur une instance d'une classe héritant de PhysicCallBack */ inline void SetPhysicCallBack (PhysicCallBack* p) { pPhysicCallBack = p; } /** * Doit-on considérer ce node comme un objet physique ? * @return bool true=physique, false=non-physique */ inline bool Clip () { return bClip; } inline void SetClip (bool b) { bClip = b; } /** * Informations sur la position de l'objet par rapport au sol * @return bool true=sur le sol, false=en l'air */ inline bool OnGround () { return bOnGround; } inline void SetOnGround (bool b) { bOnGround = b; } inline bool Trace (Vector3 Begin, Vector3 End, Vector3& colPoint, Vector3& colNormal) { return vNodes[0]->Trace(Begin, End, colPoint, colNormal); } /* Position */ inline void SetPosition (Vector3 v) { vPosition = v; } inline Vector3 GetPosition () { return vPosition; } /* Acceleration */ inline Vector3 GetAccel () { return vAccel; } inline void SetAccel (const Vector3& v) { vAccel = v; } inline float GetXAccel () { return vAccel.x; } inline float GetYAccel () { return vAccel.y; } inline float GetZAccel () { return vAccel.z; } inline void SetXAccel (float f) { vAccel.x = f; } inline void SetYAccel (float f) { vAccel.y = f; } inline void SetZAccel (float f) { vAccel.z = f; } inline void AddXAccel (float f) { vAccel.x += f; } inline void AddYAccel (float f) { vAccel.y += f; } inline void AddZAccel (float f) { vAccel.z += f; } /* Vitesse */ inline Vector3 GetVelocity () { return vVelocity; } inline void SetVelocity (const Vector3& v) { vVelocity = v; } inline void AddVelocity (const Vector3& v) { vVelocity = v; } inline float GetXVelocity () { return vVelocity.x; } inline float GetYVelocity () { return vVelocity.y; } inline float GetZVelocity () { return vVelocity.z; } inline void SetXVelocity (float f) { vVelocity.x = f; } inline void SetYVelocity (float f) { vVelocity.y = f; } inline void SetZVelocity (float f) { vVelocity.z = f; } inline void AddXVelocity (float f) { vVelocity.x += f; } inline void AddYVelocity (float f) { vVelocity.y += f; } inline void AddZVelocity (float f) { vVelocity.z += f; } /* Rotation */ inline Vector3 GetRot () { return vEuler; } inline void SetRot (const Vector3& v) { vEuler = v; } inline void AddRot (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; } /* Vitesse de rotation */ inline Vector3 GetRotVelocity () { return vEulerVelocity; } inline void SetRotVelocity (const Vector3& v) { vEulerVelocity = v; } inline void AddRotVelocity (const Vector3& v) { vEulerVelocity += v; } inline float GetXRotVelocity () { return vEulerVelocity.x; } inline float GetYRotVelocity () { return vEulerVelocity.y; } inline float GetZRotVelocity () { return vEulerVelocity.z; } inline void SetXRotVelocity (float f) { vEulerVelocity.x = f; } inline void SetYRotVelocity (float f) { vEulerVelocity.y = f; } inline void SetZRotVelocity (float f) { vEulerVelocity.z = f; } 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 (); void CalculateBoundingVolume (); protected: bool bClip; bool bOnGround; Vector3 vAccel; Vector3 vVelocity; Vector3 vEuler; Vector3 vEulerVelocity; Vector3 vPosition; BoundingBox* pBBox; PhysicCallBack* pPhysicCallBack; typedef std::vector<SceneNode*> SceneNodeList; SceneNodeList vNodes; }; } #endif --- NEW FILE: meshmanager.h --- #ifndef _TGMESHMANAGER_H #define _TGMESHMANAGER_H #include "md5instance.h" namespace tg { class MeshManager { public: MeshManager (); ~MeshManager (); MD5Instance* Load (const std::string& name); protected: typedef std::map<std::string, MD5Mesh10*> MeshesList; MeshesList mMeshes; }; } #endif --- NEW FILE: meshmanager.cc --- #include "meshmanager.h" namespace tg { MeshManager::MeshManager () { MD5Mesh10* m = new MD5Mesh10 (); m->LoadMesh("data/models/fish/fish.md5mesh"); mMeshes["nomesh"] = m; } MeshManager::~MeshManager () { delete mMeshes["nomesh"]; } MD5Instance* MeshManager::Load (const std::string& name) { MeshesList::iterator i = mMeshes.begin (); if((i=mMeshes.find(name)) == mMeshes.end()) //on doit charger le mesh { MD5Mesh10* m = new MD5Mesh10 (); if (m->LoadMesh((char*)name.data())) mMeshes[name] = m; else mMeshes[name] = mMeshes["nomesh"]; } return new MD5Instance(mMeshes[name]); } } |