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
// Ogre3d Related members
// Debug overlay related members
// ODE Related Members
// OIS Input devices
// List of nodes in the scene for use by ODE
IScene(Ogre::Root *root, Ogre::RenderWindow* win);
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);
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.