Bonjour tous le monde:
J'ai suivit la partie Suivez le chemin de chapitre Animer les meshes, J'ai un problème (Je n'est pas de message d'erreur), Le problème est que le robot ne bouge pas de sa position, il reste toujours a sa position initiale.
Voici les fichier :
AppDemarrage.h
AppDemarrage.cpp
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38 #ifndef APPDEMARRAGE_H_INCLUDED #define APPDEMARRAGE_H_INCLUDED #include <Ogre.h> #include "InputListener.h" class AppDemarrage { public: AppDemarrage(); ~AppDemarrage(); bool start(); private: void createFrameListener(); bool nextDestination(); void createScene(); InputListener *mInputListener; Ogre::Root *mRoot; Ogre::Camera* mCamera; Ogre::SceneManager* mSceneMgr; Ogre::RenderWindow *mWindow; Ogre::SceneNode* mRobotNode; Ogre::Entity* mRobot; Ogre::AnimationState* mAnimationState; std::queue<Ogre::Vector3> mCheckpointList; Ogre::Vector3 mDestination; Ogre::Vector3 mDirection; Ogre::Real mSpeed; Ogre::Real mDistance; }; #endif
InputListener.h
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141 #include "AppDemarrage.h" AppDemarrage::AppDemarrage() : mRoot(0), mSceneMgr(0), mWindow(0), mRobot(0) { mRoot = new Ogre::Root("plugins.cfg", "ogre.cfg", "Ogre.log"); mSceneMgr = mRoot->createSceneManager("DefaultSceneManager", "Mon Scene Manager"); mSpeed = 50.0f; mDestination = Ogre::Vector3::ZERO; mDistance = 0.0f; } bool AppDemarrage::start() { Ogre::ConfigFile configFile; configFile.load("resources.cfg"); Ogre::ConfigFile::SectionIterator seci = configFile.getSectionIterator(); Ogre::String secName, typeName, archName; while (seci.hasMoreElements()) { secName = seci.peekNextKey(); Ogre::ConfigFile::SettingsMultiMap *settings = seci.getNext(); Ogre::ConfigFile::SettingsMultiMap::iterator i; for (i = settings->begin(); i != settings->end(); ++i) { typeName = i->first; archName = i->second; Ogre::ResourceGroupManager::getSingleton().addResourceLocation( archName, typeName, secName); } } if(!(mRoot->restoreConfig() || mRoot->showConfigDialog())) { return false; } if (mRoot->showConfigDialog()) { mWindow = mRoot->initialise(true, "Ogre3D"); } Ogre::TextureManager::getSingleton().setDefaultNumMipmaps(5); Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups(); mSceneMgr->setAmbientLight(Ogre::ColourValue(1.0f, 1.0f, 1.0f)); mCamera = mSceneMgr->createCamera("PlayerCam"); mCamera->setPosition(Ogre::Vector3(0,0,100)); mCamera->lookAt(Ogre::Vector3(0,0,0)); mCamera->setNearClipDistance(5); Ogre::Viewport* vp = mWindow->addViewport(mCamera); vp->setBackgroundColour(Ogre::ColourValue(0,0,0)); mCamera->setAspectRatio(Ogre::Real(vp->getActualWidth()) / Ogre::Real(vp->getActualHeight())); mRobot = mSceneMgr->createEntity("Robot", "robot.mesh"); mRobotNode = mSceneMgr->getRootSceneNode()->createChildSceneNode("RobotNode"); mRobotNode->attachObject(mRobot); mRobot->setMaterialName("Robot"); mCheckpointList.push(Ogre::Vector3(300, 0, 600)); mCheckpointList.push(Ogre::Vector3(100, 0, -200)); mCheckpointList.push(Ogre::Vector3(-400, 0, 100)); nextDestination(); createFrameListener(); const Ogre::FrameEvent evt; if (mDestination == Ogre::Vector3::ZERO) { nextDestination(); } else { Ogre::Real move = evt.timeSinceLastFrame * mSpeed; mRobotNode->translate(mDirection * move); mDistance -= move; if (mDistance < 0.001) { mRobotNode->setPosition(mDestination); mDestination = Ogre::Vector3::ZERO; } } mRoot->startRendering(); while(true) { Ogre::WindowEventUtilities::messagePump(); if(mWindow->isClosed()) return false; if(!mRoot->renderOneFrame()) return false; } } void AppDemarrage::createFrameListener() { mAnimationState = mRobot->getAnimationState("Walk"); mAnimationState->setLoop(true); mAnimationState->setEnabled(true); mInputListener = new InputListener(mWindow, mCamera, mSceneMgr, mAnimationState); mRoot->addFrameListener(mInputListener); } bool AppDemarrage::nextDestination() { if (mCheckpointList.empty()) return false; mDestination = mCheckpointList.front(); mCheckpointList.pop(); mCheckpointList.push(mDestination); mDirection = mDestination - mRobotNode->getPosition(); mDistance = mDirection.normalise(); return true; } void AppDemarrage::createScene() { } AppDemarrage::~AppDemarrage() { OGRE_DELETE mRoot; OGRE_DELETE mCamera; OGRE_DELETE mSceneMgr; OGRE_DELETE mWindow; OGRE_DELETE mRobot; OGRE_DELETE mRobotNode; OGRE_DELETE mAnimationState; delete mInputListener; delete mRoot; }
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37 #define INPUTLISTENER_H_INCLUDED #include <Ogre.h> #include <OIS/OIS.h> class InputListener : public Ogre::FrameListener, public Ogre::WindowEventListener { public: InputListener(Ogre::RenderWindow *wnd, Ogre::Camera *camera, Ogre::SceneManager *sceneMgr, Ogre::AnimationState* mAnim); ~InputListener(); private: bool frameRenderingQueued(const Ogre::FrameEvent& evt); void startOIS(); virtual void windowResized(Ogre::RenderWindow* rw); virtual void windowClosed(Ogre::RenderWindow* rw); Ogre::SceneManager *mSceneMgr; Ogre::RenderWindow* mWindow; Ogre::Camera* mCamera; bool mToucheAppuyer; Ogre::Real mMouvement; Ogre::Real mVitesse; Ogre::Real mVitesseRotation; Ogre::Radian mRotationX; Ogre::Radian mRotationY; OIS::InputManager* mInputManager; OIS::Mouse* mMouse; OIS::Keyboard* mKeyboard; Ogre::Entity* mRobot; Ogre::AnimationState* mAnimationState; }; #endifDonc dans la fichier AppDemarrage, les fichier que j'ai ajouter :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110 #include "InputListener.h" InputListener::InputListener(Ogre::RenderWindow *wnd, Ogre::Camera *camera, Ogre::SceneManager *sceneMgr, Ogre::AnimationState* mAnim) { mSceneMgr = sceneMgr; mWindow = wnd; mCamera = camera; mAnimationState = mAnim; mVitesse = 100; mVitesseRotation = 0.1; mToucheAppuyer = false; startOIS(); } bool InputListener::frameRenderingQueued(const Ogre::FrameEvent& evt) { mAnimationState->addTime(evt.timeSinceLastFrame); if(mWindow->isClosed()) return false; if(mMouse) mKeyboard->capture(); if(mKeyboard) mMouse->capture(); if(mKeyboard->isKeyDown(OIS::KC_ESCAPE)) return false; Ogre::Vector3 deplacement = Ogre::Vector3::ZERO; mMouvement = mVitesse * evt.timeSinceLastFrame; if(mKeyboard->isKeyDown(OIS::KC_LEFT) || mKeyboard->isKeyDown(OIS::KC_A)) deplacement.x -= mMouvement; if(mKeyboard->isKeyDown(OIS::KC_RIGHT) || mKeyboard->isKeyDown(OIS::KC_D)) deplacement.x += mMouvement; if(mKeyboard->isKeyDown(OIS::KC_UP) || mKeyboard->isKeyDown(OIS::KC_W)) deplacement.z -= mMouvement; if(mKeyboard->isKeyDown(OIS::KC_DOWN) || mKeyboard->isKeyDown(OIS::KC_S)) deplacement.z += mMouvement; if(mKeyboard->isKeyDown(OIS::KC_Q)) deplacement.y -= mMouvement; if(mKeyboard->isKeyDown(OIS::KC_E)) deplacement.y += mMouvement; const OIS::MouseState &mouseState = mMouse->getMouseState(); mRotationX = Ogre::Degree(-mouseState.Y.rel * mVitesseRotation); mRotationY = Ogre::Degree(-mouseState.X.rel * mVitesseRotation); mCamera->yaw(mRotationY); mCamera->pitch(mRotationX); mCamera->moveRelative(deplacement); return true; } void InputListener::startOIS() { Ogre::LogManager::getSingletonPtr()->logMessage("*** Initializing OIS ***"); OIS::ParamList pl; size_t windowHnd = 0; std::ostringstream windowHndStr; mWindow->getCustomAttribute("WINDOW", &windowHnd); windowHndStr << windowHnd; pl.insert(std::make_pair(std::string("WINDOW"), windowHndStr.str())); mInputManager = OIS::InputManager::createInputSystem( pl ); mMouse = static_cast<OIS::Mouse*>(mInputManager->createInputObject( OIS::OISMouse, false )); mKeyboard = static_cast<OIS::Keyboard*>(mInputManager->createInputObject( OIS::OISKeyboard, false )); windowResized(mWindow); Ogre::WindowEventUtilities::removeWindowEventListener(mWindow, this); } void InputListener::windowResized(Ogre::RenderWindow* wnd) { unsigned int width, height, depth; int left, top; wnd->getMetrics(width, height, depth, left, top); const OIS::MouseState &ms = mMouse->getMouseState(); ms.width = width; ms.width = height; } void InputListener::windowClosed(Ogre::RenderWindow* wnd) { if( wnd == mWindow ) { if( mInputManager ) { mInputManager->destroyInputObject( mMouse ); mInputManager->destroyInputObject( mKeyboard ); OIS::InputManager::destroyInputSystem(mInputManager); mInputManager = 0; } } } InputListener::~InputListener() { Ogre::WindowEventUtilities::removeWindowEventListener(mWindow, this); windowClosed(mWindow); }
et
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 mCheckpointList.push(Ogre::Vector3(300, 0, 600)); mCheckpointList.push(Ogre::Vector3(100, 0, -200)); mCheckpointList.push(Ogre::Vector3(-400, 0, 100)); nextDestination(); createFrameListener(); const Ogre::FrameEvent evt; if (mDestination == Ogre::Vector3::ZERO) { nextDestination(); } else { Ogre::Real move = evt.timeSinceLastFrame * mSpeed; mRobotNode->translate(mDirection * move); mDistance -= move; if (mDistance < 0.001) { mRobotNode->setPosition(mDestination); mDestination = Ogre::Vector3::ZERO; } }
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14 bool AppDemarrage::nextDestination() { if (mCheckpointList.empty()) return false; mDestination = mCheckpointList.front(); mCheckpointList.pop(); mCheckpointList.push(mDestination); mDirection = mDestination - mRobotNode->getPosition(); mDistance = mDirection.normalise(); return true; }
Son en ce moment a cette position, mais j'ai essayer plein de position différente. Soit c'est le script qui ne marche pas soit c'est les point qui ne son pas ajouter au tableau.
Pouvez-vous m'aidez, S'il-vous-plait.
Merci d'avance pour vos réponse.
Erwan28250
Partager