Iteration #2
1,374
2
Advertisement
Not a whole lot of dev time this week but I succeeded in getting the basics of the ODE physics engine integrated with Ogre3D. There's actually an Ogre3D plugin that tackles this task but I could not find a successful mac build of it anywhere. After spending a day trying to get things building properly I just decided to write my own ODE integration. It really isn't that tough that you need to use an existing plug-in anyway.
To start things off I'm including my first screen shot to improve the sexyness factor of the journal entry. No one wants to just look at code. What you can't see in the screen grab is that the Ogre head is actually falling to the floor thanks to gravity. I don't have collision detection integrated yet so the head just goes straight through the floor but that's the goal for this week. I've found that since my "spare" time is limited having a job, wife and kid that I do best setting small goals for the week. That keeps me from getting overwhelmed about things or getting down on the lack of progress. Keeping yourself from giving up is something not enough people commit time to, which is why I think so many projects end up never getting completed.
As I started integrating ODE into the classes that I had from last time I quickly realized that things just weren't going to fit. As I was looking for a place to put the ODE update functions the natural place seemed to be in the frame listener. After all the frame listener gets called every frame. Nice match. The problem was that the frame listener didn't have access to the Ogre3D objects. This didn't show up last time since the frame listener was just dealing with the debug display and not really updating the data about the objects in the scene. This was going to be a problem.
The first solution that came to mind was passing a pointer to the scene objects to the listener or even passing a pointer to the whole scene to the listener. This straight off felt wrong. After all if the listener is a member of the scene then why does it need a pointer back to the scene? This is something that could be coded but the design is just so ugly that there had to be a better way.
The real answer ended up being far simpler. Just get rid of the Frame Listener and have the scene object derive from frame listener. This has the advantage of opening up access to all the scene objects in the frame callbacks and it also nicely encapsulates everything about a scene in one object. All of the scene objects and logic can be found in one place.
Once I got that design issue out of the way the actual implementation was a snap. I ended up abstracting the frame callbacks into a private and a virtual protected method in the base class. This let me hide all of the ODE updating in the base class where I don't have to deal with it anymore. Anyone implementing a new scene object gets all of the physics updating for free. I plan to do the same with the collision detection when I get there.
New class definition for IScene
Like last time I've included all source here for anyone interested.
To start things off I'm including my first screen shot to improve the sexyness factor of the journal entry. No one wants to just look at code. What you can't see in the screen grab is that the Ogre head is actually falling to the floor thanks to gravity. I don't have collision detection integrated yet so the head just goes straight through the floor but that's the goal for this week. I've found that since my "spare" time is limited having a job, wife and kid that I do best setting small goals for the week. That keeps me from getting overwhelmed about things or getting down on the lack of progress. Keeping yourself from giving up is something not enough people commit time to, which is why I think so many projects end up never getting completed.
As I started integrating ODE into the classes that I had from last time I quickly realized that things just weren't going to fit. As I was looking for a place to put the ODE update functions the natural place seemed to be in the frame listener. After all the frame listener gets called every frame. Nice match. The problem was that the frame listener didn't have access to the Ogre3D objects. This didn't show up last time since the frame listener was just dealing with the debug display and not really updating the data about the objects in the scene. This was going to be a problem.
The first solution that came to mind was passing a pointer to the scene objects to the listener or even passing a pointer to the whole scene to the listener. This straight off felt wrong. After all if the listener is a member of the scene then why does it need a pointer back to the scene? This is something that could be coded but the design is just so ugly that there had to be a better way.
The real answer ended up being far simpler. Just get rid of the Frame Listener and have the scene object derive from frame listener. This has the advantage of opening up access to all the scene objects in the frame callbacks and it also nicely encapsulates everything about a scene in one object. All of the scene objects and logic can be found in one place.
Once I got that design issue out of the way the actual implementation was a snap. I ended up abstracting the frame callbacks into a private and a virtual protected method in the base class. This let me hide all of the ODE updating in the base class where I don't have to deal with it anymore. Anyone implementing a new scene object gets all of the physics updating for free. I plan to do the same with the collision detection when I get there.
New class definition for IScene
class IScene : public Ogre::FrameListener, public Ogre::WindowEventListener{public: // Ogre3d Related members Ogre::Camera *m_Camera; Ogre::Root *m_Root; Ogre::RenderWindow *m_Window; Ogre::SceneManager *m_CurrentSceneMgr; // Debug overlay related members bool m_StatsOn; std::string m_DebugText; Ogre::Overlay *m_DebugOverlay; // ODE Related Members dWorldID m_dWorldID; Ogre::Timer *m_ElapsedTimer; Ogre::Real m_PhysicsUpdateRate; // OIS Input devices OIS::InputManager *m_InputManager; OIS::Mouse *m_Mouse; OIS::Keyboard *m_Keyboard; // List of nodes in the scene for use by ODE std::vector m_Nodes; public: IScene(Ogre::Root *root, Ogre::RenderWindow* win); virtual ~IScene(); void Initialize(void); protected: virtual void CreateViewports(void)=0; virtual void CreateScene(void)=0; virtual void CreateCamera(void)=0; virtual void ChooseSceneManager(void); virtual bool CustomFrameStarted(const Ogre::FrameEvent &evt)=0; virtual bool CustomFrameRenderingQueued(const Ogre::FrameEvent &evt)=0; virtual bool CustomFrameEnded(const Ogre::FrameEvent &evt)=0; void showDebugOverlay(bool show); virtual void windowResized(Ogre::RenderWindow* rw); virtual void windowClosed(Ogre::RenderWindow* rw); virtual void UpdateStats(void); void SetPhysicsUpdateRate(int FPS); CNode* CreateNode(Ogre::SceneNode *node); private: bool frameStarted (const Ogre::FrameEvent &evt); bool frameRenderingQueued(const Ogre::FrameEvent &evt); bool frameEnded(const Ogre::FrameEvent& evt); };Like last time I've included all source here for anyone interested.
Advertisement
Advertisement
Advertisement
Discussion