Update of /cvsroot/epfl/tggame In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27919 Modified Files: aicontroller.cc aicontroller.h controller.cc controller.h game.cc game.h pawn.h playercontroller.cc playercontroller.h Log Message: collisions Index: aicontroller.cc =================================================================== RCS file: /cvsroot/epfl/tggame/aicontroller.cc,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** aicontroller.cc 2 Nov 2004 15:41:43 -0000 1.7 --- aicontroller.cc 9 Nov 2004 18:19:02 -0000 1.8 *************** *** 16,21 **** --- 16,41 ---- int AIController::STRAFERIGHT = 1; + AIController::AIController(Pawn* p) : Controller(p) + { + pSphere = new DebugSphere (); + } + void AIController::Think (float eTime) { + //Test des tirs + { + Vector3 vTarget = pPawn->GetRotation().GetXAxis(); + Vector3 vPosition = pPawn->GetPosition()+vViewOffset; + vTarget = vPosition + vTarget*1000; + + CollisionResult cR = Game::pSelf->Trace(vPosition, vTarget, pPawn); + pSphere->vPosition = cR.EndPoint; + std::cout << cR.EndPoint << std::endl; + + if (cR.pNode != NULL && cR.pNode->GetPhysicCallBack() != NULL) + cR.pNode->GetPhysicCallBack()->Collide(NULL, cR.EndPoint, cR.Normal); + } + + /* if (!initialised) // A mettre ailleurs... mais je ne vais pas hacker tggame.. je laisse ca aux experts ;) *************** *** 45,50 **** void AIController::Collide (SceneNode* other, const Vector3& vPoint, const Vector3& vCollisionNormal) { ! // fYaw=rand()%360; ! // std::cout << vPoint << std::endl; } --- 65,69 ---- void AIController::Collide (SceneNode* other, const Vector3& vPoint, const Vector3& vCollisionNormal) { ! pPawn->SetAnimation("death"); } Index: pawn.h =================================================================== RCS file: /cvsroot/epfl/tggame/pawn.h,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** pawn.h 6 Nov 2004 17:05:51 -0000 1.9 --- pawn.h 9 Nov 2004 18:19:03 -0000 1.10 *************** *** 47,50 **** --- 47,51 ---- inline void SetMoveSpeed (float s) { fMoveSpeed = s; } + inline void SetAnimation (const std::string& s) { pModel->SetAnimation(s); } inline void Attach (SceneNode* s) { pPhysic->AttachNode(s); } *************** *** 56,60 **** inline void SetVisible (bool b) { pModel->SetRender(b); } ! //Model* GetModel () { return pModel; } protected: --- 57,63 ---- inline void SetVisible (bool b) { pModel->SetRender(b); } ! ! inline PhysicNode* GetPhysic() { return pPhysic; } ! //Model* GetModel () { return pModel; } protected: Index: game.h =================================================================== RCS file: /cvsroot/epfl/tggame/game.h,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** game.h 25 Oct 2004 20:04:14 -0000 1.8 --- game.h 9 Nov 2004 18:19:03 -0000 1.9 *************** *** 53,59 **** --- 53,62 ---- void PostFrame (); + CollisionResult Trace(const Vector3& vBegin, const Vector3& vEnd, Pawn* edict); + inline SceneManager* GetSceneManager () { return pSceneManager; } inline World* GetWorld () { return pWorld; } inline Engine* GetEngine () { return pEngine; } + inline PhysicEngine* GetPhysicEngine () { return pPhysicEngine; } inline Console* GetConsole () { return pConsole; } Index: aicontroller.h =================================================================== RCS file: /cvsroot/epfl/tggame/aicontroller.h,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** aicontroller.h 31 Oct 2004 11:40:44 -0000 1.4 --- aicontroller.h 9 Nov 2004 18:19:03 -0000 1.5 *************** *** 11,16 **** static int STRAFELEFT; static int STRAFERIGHT; public: ! AIController (Pawn* p) : Controller(p) {} virtual ~AIController() {} --- 11,18 ---- static int STRAFELEFT; static int STRAFERIGHT; + + DebugSphere* pSphere; public: ! AIController (Pawn* p); virtual ~AIController() {} Index: game.cc =================================================================== RCS file: /cvsroot/epfl/tggame/game.cc,v retrieving revision 1.27 retrieving revision 1.28 diff -C2 -d -r1.27 -r1.28 *** game.cc 7 Nov 2004 19:44:59 -0000 1.27 --- game.cc 9 Nov 2004 18:19:03 -0000 1.28 *************** *** 99,103 **** #endif Camera* cam = new Camera (0.025f,CAM_SPEED, Vector3 (0, 100,0)); - cam->SetViewOffset(Vector3(0,70,0)); //préchargement des meshes --- 99,102 ---- *************** *** 110,115 **** pEngine->pMeshManager->Load("pinky", "data/models/player/hazmat.md5mesh"); pEngine->pMeshManager->LoadAnim("pinky", "data/models/player/stand.md5anim"); ! MD5Instance* pModel = Engine::pMeshManager->LoadInstance("machinegun"); pModel->SetAnimation("idle"); --- 109,115 ---- pEngine->pMeshManager->Load("pinky", "data/models/player/hazmat.md5mesh"); pEngine->pMeshManager->LoadAnim("pinky", "data/models/player/stand.md5anim"); + pEngine->pMeshManager->LoadAnim("pinky", "data/models/player/death.md5anim"); ! //creation de l'arme MD5Instance* pModel = Engine::pMeshManager->LoadInstance("machinegun"); pModel->SetAnimation("idle"); *************** *** 118,125 **** q *= Quaternion(90, Vector3(0,1,0)); pModel->SetRotation(q); - pModel->SetPosition(Vector3(5,0,-5)); pSceneManager->AddWorldObject(pModel); Pawn* p = new Pawn(); pSceneManager->SetCamera(cam); --- 118,125 ---- q *= Quaternion(90, Vector3(0,1,0)); pModel->SetRotation(q); pModel->SetPosition(Vector3(5,0,-5)); pSceneManager->AddWorldObject(pModel); + //creation du joueur Pawn* p = new Pawn(); pSceneManager->SetCamera(cam); *************** *** 128,131 **** --- 128,134 ---- pLocalController = new PlayerController(p); vControllers.push_back(pLocalController); + cam->SetViewOffset(Vector3(0,70,0)); + pLocalController->SetViewOffset(Vector3(0,70,0)); + //p->SetPosition(pWorld->GetRandomStartPosition()+Vector3(20,80,20)); p->Attach (cam); *************** *** 145,149 **** p->SetRotation(Quaternion(-90, Vector3(1,0,0))); p->SetPosition(Vector3(0,70,0)); ! //p->SetRotationVelocity(Quaternion(10,Vector3(0,1,1))); //p->SetRotation(Quaternion(90,Vector3(0,1,0))); --- 148,153 ---- p->SetRotation(Quaternion(-90, Vector3(1,0,0))); p->SetPosition(Vector3(0,70,0)); ! c->SetViewOffset(Vector3(0,70,0)); ! //p->SetRotationVelocity(Quaternion(10,Vector3(0,1,1))); //p->SetRotation(Quaternion(90,Vector3(0,1,0))); *************** *** 152,155 **** --- 156,164 ---- } + CollisionResult Game::Trace(const Vector3& vBegin, const Vector3& vEnd, Pawn* edict) + { + return pPhysicEngine->Trace(vBegin, vEnd, edict->GetPhysic()); + } + void Game::PreFrame () { Index: controller.h =================================================================== RCS file: /cvsroot/epfl/tggame/controller.h,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** controller.h 28 Oct 2004 21:20:33 -0000 1.7 --- controller.h 9 Nov 2004 18:19:03 -0000 1.8 *************** *** 26,33 **** --- 26,36 ---- inline Pawn* GetPawn () { return pPawn; } + + void SetViewOffset (const Vector3& v) { vViewOffset = v; } protected: Pawn* pPawn; bool bDir[4]; + Vector3 vViewOffset; Vector3 vLastVel; //pour les mouvements Index: playercontroller.h =================================================================== RCS file: /cvsroot/epfl/tggame/playercontroller.h,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** playercontroller.h 31 Oct 2004 11:40:44 -0000 1.5 --- playercontroller.h 9 Nov 2004 18:19:03 -0000 1.6 *************** *** 18,21 **** --- 18,23 ---- static int STRAFELEFT; static int STRAFERIGHT; + + DebugSphere* pSphere; public: PlayerController (Pawn*); Index: playercontroller.cc =================================================================== RCS file: /cvsroot/epfl/tggame/playercontroller.cc,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** playercontroller.cc 31 Oct 2004 11:40:44 -0000 1.11 --- playercontroller.cc 9 Nov 2004 18:19:03 -0000 1.12 *************** *** 13,53 **** { Game::pSelf->GetConsole()->Register("clip", this, CLIP); } void PlayerController::Think (float eTime) { ! float fSensivity = 0.02; ! static float ry = 0; ! static float rx = 0; ! ! int mX, mY; ! int middleX, middleY; ! Game::pSelf->GetEngine()->GetMouseState(&mX,&mY); ! middleX = 320; ! middleY = 240; ! //si la souris reste au milieu, on a pas besoin de tourner ! if ((mX == middleX) && (mY == middleY)) ! return; ! //Vector3 mRot(0,0,0); ! ry -= ((float)mX-middleX)*6*fSensivity; ! rx -= ((float)mY-middleY)*6*fSensivity; ! Game::pSelf->GetEngine()->WarpMouse(middleX,middleY); ! Quaternion qY = Quaternion(ry, Vector3(0,1,0)); ! Quaternion qX = Quaternion(rx, Vector3(1,0,0)); ! Quaternion q = qY*qX; ! q.Normalize(); ! /*Quaternion q; ! q.FromEuler(rx, ry, 0); ! q.Normalize();*/ ! pPawn->SetRotation(q); } void PlayerController::Collide (SceneNode* other, const Vector3& vPoint, const Vector3& vCollisionNormal) { ! // std::cout << "playercontroller" << std::endl; } --- 13,74 ---- { Game::pSelf->GetConsole()->Register("clip", this, CLIP); + pSphere = new DebugSphere (); + Game::pSelf->GetSceneManager()->AddDebugSphere(pSphere); } void PlayerController::Think (float eTime) { ! //Test des tirs ! { ! Vector3 vTarget = pPawn->GetRotation().GetZAxis(); ! Vector3 vPosition = pPawn->GetPosition()+vViewOffset; ! vTarget = vPosition - vTarget*1000; ! CollisionResult cR = Game::pSelf->Trace(vPosition, vTarget, pPawn); ! pSphere->vPosition = cR.EndPoint; ! if (cR.pNode != NULL && cR.pNode->GetPhysicCallBack() != NULL) ! cR.pNode->GetPhysicCallBack()->Collide(NULL, cR.EndPoint, cR.Normal); ! } ! ! //Mouvement de la souris ! { ! float fSensivity = 0.02; ! static float ry = 0; ! static float rx = 0; ! ! int mX, mY; ! int middleX, middleY; ! Game::pSelf->GetEngine()->GetMouseState(&mX,&mY); ! middleX = 320; ! middleY = 240; ! //si la souris reste au milieu, on a pas besoin de tourner ! if ((mX == middleX) && (mY == middleY)) ! return; ! ! //Vector3 mRot(0,0,0); ! ry -= ((float)mX-middleX)*6*fSensivity; ! rx -= ((float)mY-middleY)*6*fSensivity; ! Game::pSelf->GetEngine()->WarpMouse(middleX,middleY); ! Quaternion qY = Quaternion(ry, Vector3(0,1,0)); ! Quaternion qX = Quaternion(rx, Vector3(1,0,0)); ! Quaternion q = qY*qX; ! q.Normalize(); ! ! /*Quaternion q; ! q.FromEuler(rx, ry, 0); ! q.Normalize();*/ ! pPawn->SetRotation(q); ! } ! ! ! } void PlayerController::Collide (SceneNode* other, const Vector3& vPoint, const Vector3& vCollisionNormal) { ! std::cerr << "playercontroller" << std::endl; } Index: controller.cc =================================================================== RCS file: /cvsroot/epfl/tggame/controller.cc,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** controller.cc 30 Oct 2004 17:46:47 -0000 1.8 --- controller.cc 9 Nov 2004 18:19:03 -0000 1.9 *************** *** 5,8 **** --- 5,10 ---- { pPawn = p; + p->GetPhysic()->SetPhysicCallBack(this); + vViewOffset.Null(); //iForward = iStrafe = 0; for (int i=0; i<4; i++) { |