MFC + OgreOde problem
Posted: Thu Feb 24, 2005 3:20 pm
Hi,
I try to get OgreOde a MFC/Ogre application, I tried to do this like I do it in standard "exampleapplication based" applications, but it does not work.
The OgreOde objects appear in my Ogre render window but it looks like there is no gravity or collision.
I'm really confused.
Here is my code (excluding unimportant parts):
OgreFramework.cpp
OgreFramework.h
Thanks, stoneCold
I try to get OgreOde a MFC/Ogre application, I tried to do this like I do it in standard "exampleapplication based" applications, but it does not work.
The OgreOde objects appear in my Ogre render window but it looks like there is no gravity or collision.
I'm really confused.
Here is my code (excluding unimportant parts):
OgreFramework.cpp
Code: Select all
#include "stdafx.h"
#include "OgreFramework.h"
COgreFramework* COgreFramework::m_Inst = NULL; // Global instance
COgreFramework::COgreFramework()
{
m_bIsOgreInit = false;
}
COgreFramework::~COgreFramework()
{
}
void COgreFramework::InitOgre(HWND hwnd)
{
/*
.
.
Add visual objects
.
.
*/
//SETTING OGRE ODE PARAMETERS
_time_step = 0.005;
_world = new OgreOde::World(mSceneMgr);
_world->setCollisionListener(this);
_space = _world->getDefaultSpace();
_world->setGravity(Vector3(0,-9.80665,0));
_world->setCFM(10e-5);
_world->setERP(0.8);
_world->setAutoSleep(true);
_world->setContactCorrectionVelocity(10.0);
/*
.
.
Add OgreOde objects
.
.
*/
//OGRE ODE STEPPER
_stepper = new OgreOde::ForwardFixedQuickStepper(_time_step);
_stepper->setAutomatic(OgreOde::Stepper::AutoMode_PostFrame,mRoot);
//DEBUG OGREODE OBJECTS
_world->setShowDebugObjects(1);
}
Code: Select all
#pragma once
#include "Ogre.h"
#include "ogreode.h"
#include "OgreConfigFile.h"
#include "..\..\RenderSystems\Direct3D9\include\OgreD3D9RenderWindow.h"
#include "..\..\RenderSystems\Direct3D9\include\OgreD3D9RenderSystem.h"
#include "OgreWireBoundingBox.h"
#include <cassert>
using namespace Ogre;
class COgreFramework : public OgreOde::CollisionListener
{
virtual bool collision(OgreOde::Contact* contact)
{
OgreOde::Geometry* g1 = contact->getFirstGeometry();
OgreOde::Geometry* g2 = contact->getSecondGeometry();
if(g1 && g2)
{
OgreOde::Body* b1 = g1->getBody();
OgreOde::Body* b2 = g2->getBody();
if(b1 && b2) if(OgreOde::Joint::areConnected(b1,b2)) return false;
}
contact->setCoulombFriction(OgreOde::Utility::Infinity);
return true;
}
public:
// Constructors/destructors
COgreFramework();
virtual ~COgreFramework();
// Init OGRE to render to a given HWND
void InitOgre(HWND hwnd);
/*
.
.
.
.
.*/
private:
/*
.
.
.
.
.*/
protected:
OgreOde::Space* _space;
OgreOde::World* _world;
OgreOde::Stepper* _stepper;
Real _time_step;
};