First Steps with OgreOde - Problems

niteenhatle

04-02-2009 18:16:46

Hi,

I am quite new to OgreOde. I was compiling the first tutorial. And I was stuck here

Now you have a crate hanging in the air. We need to update your world's time steps. Add the following code to your main loop or your gamestate::update or wherever your program increments the current frame:
Ogre::Real time = 0.1;
if (mStepper->step(time))
{
mWorld->synchronise();
}


The tutorial says to put this code in the main loop. But i am using the first Ogre tutorial with just createScene() in it. I guess this code should go in the ExampleApplication.go() function (I hope I am right). Should I override this method and add the above code to it?

If I comment out this code I can see the plane and the crate. If I put it in the createScene() the program gives me a error.

Please help.

Thanks.

Niteen

dermont

05-02-2009 10:37:53

If you are using the SampleFramework from the ogre tutorials you could either auto 'sync' your world using AutoMode_PostFrame or AutoMode_PreFrame.

mStepper->setAutomatic(OgreOde::StepHandler::AutoMode_PostFrame, mRoot);
//mStepper->setAutomatic(OgreOde::StepHandler::AutoMode_PreFrame, mRoot);


Alternatively you could create your own FrameListener and 'sync' manually in frameStarted or frameEnded, but this is exactly what the AutoMode_PreFrame(frameStarted) and AutoMode_PostFrame(frameEnded) methods do.


class TutorialFrameListener : public ExampleFrameListener
{
protected:
OgreOde::World* mWorld;
OgreOde::StepHandler* mStepper;

public:
TutorialFrameListener(RenderWindow* win, Camera* cam, OgreOde::World* _world, OgreOde::StepHandler* _stepper)
: ExampleFrameListener(win, cam), mWorld(_world), mStepper(_stepper)
{
}
//bool frameStarted(const FrameEvent& evt)
bool frameEnded(const FrameEvent& evt)
{
Real time = evt.timeSinceLastFrame;
if ( mStepper->step(time) )
mWorld->synchronise();
return ExampleFrameListener::frameEnded(evt);
//return ExampleFrameListener::frameStarted(evt);
}
};

and create the framelistener in your TutorialApplication class:

// Create new frame listener
void createFrameListener(void)
{
mFrameListener= new TutorialFrameListener(mWindow, mCamera, mWorld, mStepper);
mRoot->addFrameListener(mFrameListener);
}

niteenhatle

05-02-2009 16:14:51

Hi Dermont,

Thanks for the reply. I'll try it out tonight.

Thanks again.

Niteen

niteenhatle

06-02-2009 02:07:17

Hi,

I tried it. It compiles but it doesn't run properly. The program renders the scene but while moving the crate it gives an error.
Here is my complete code:

/** TutorialApplication.cpp */

/** Include example application headerfile */
#include "ExampleApplication.h"
//#include "OgreOde\OgreOde_Core.h"
#include "OgreOde_Core.h"

class TutorialFrameListener : public ExampleFrameListener
{
protected:
OgreOde::World* mWorld;
OgreOde::StepHandler* mStepper;

public:
TutorialFrameListener(RenderWindow* win, Camera* cam, OgreOde::World* _world, OgreOde::StepHandler* _stepper)
: ExampleFrameListener(win, cam), mWorld(_world), mStepper(_stepper)
{
}
//bool frameStarted(const FrameEvent& evt)
bool frameEnded(const FrameEvent& evt)
{
Real time = evt.timeSinceLastFrame;
if ( mStepper->step(time) )
mWorld->synchronise();
return ExampleFrameListener::frameEnded(evt);
//return ExampleFrameListener::frameStarted(evt);
}
};

/** Class TutorialApplication */
class TutorialApplication : public ExampleApplication
{
protected:

public:
TutorialApplication(void)
{
}

~TutorialApplication(void)
{
}

protected:
void createScene(void)
{

/** Create ambient light */
mSceneMgr->setAmbientLight(ColourValue(1, 1, 1));

/** Create point light, set its type and position */
Light *light = mSceneMgr->createLight("Light1");
light->setType(Light::LT_POINT);
light->setPosition(Vector3(0, 150, 250));

/** set the diffuse and specular colour */
light->setDiffuseColour(1.0, 1.0, 1.0);
light->setSpecularColour(1.0, 1.0, 1.0);

/** Add physics to Ogre */
mWorld = new OgreOde::World(mSceneMgr);
mWorld->setGravity(Ogre::Vector3(0, -9.80665, 0));
mWorld->setCFM(10e-5);
mWorld->setERP(0.8);
mWorld->setAutoSleep(true);
mWorld->setAutoSleepAverageSamplesCount(10);
mWorld->setContactCorrectionVelocity(1.0);
mSpace = mWorld->getDefaultSpace();

const Ogre::Real _time_step = 0.5;
const Ogre::Real time_scale = Ogre::Real(1.7);
const Ogre::Real max_frame_time = Ogre::Real(1.0 / 4);

mGround = new OgreOde::InfinitePlaneGeometry(Plane(Ogre::Vector3(0,1,0),0), mWorld, mWorld->getDefaultSpace());

//load meshed
int i = 0;
StaticGeometry *s;
s = mSceneMgr->createStaticGeometry("StaticFloor");
s->setRegionDimensions(Ogre::Vector3(160.0, 100.0, 160.0));

//set the region origin so the center is at 0 world
s->setOrigin(Ogre::Vector3::ZERO);

for(Real z = -80.0; z <= 80.0; z += 20.0)
{
for(Real x = -80.0; x <= 80.0; x += 20.0)
{
String name = String("Ground") + StringConverter::toString(i++);
Entity *entity = mSceneMgr->createEntity(name, "plane.mesh");
entity->setQueryFlags(1<<4);
entity->setUserObject(mGround);
entity->setCastShadows(false);
s->addEntity(entity, Ogre::Vector3(x,0,z));
}
}
s->build();

mEntity = mSceneMgr->createEntity("crate", "crate.mesh");
mEntity->setQueryFlags(1<<2);
mNode = mSceneMgr->getRootSceneNode()->createChildSceneNode("crate");
mNode->attachObject(mEntity);
//mEntity->setNormaliseNormals(true);
mEntity->setCastShadows(true);

//create a body for our crate
//and "register" it in our world and the scene node
mBody = new OgreOde::Body(mWorld);
mNode->attachObject(mBody);

//set size and mass of the box
Vector3 size(10.0,10.0,10.0);
OgreOde::BoxMass mMass(0.5, size);
mMass.setDensity(5.0, size);
mGeom = (OgreOde::Geometry*) new OgreOde::BoxGeometry(size, mWorld, mSpace);
mNode->setScale(size.x * 0.1, size.y * 0.1, size.z * 0.1);
mBody->setMass(mMass);
mGeom->setBody(mBody);
mEntity->setUserObject(mGeom);

//set the orientation and position of the crate
mBody->setOrientation(Quaternion(Radian(5.0), Ogre::Vector3(0,0,0)));
mBody->setPosition(Vector3(0,120,-20));

//update your world's time steps
//Ogre::Real time = 0.1;
//if(mStepper->step(time))
//{
// mWorld->synchronise();
//}

//mStepper->setAutomatic(OgreOde::StepHandler::AutoMode_PostFrame, mRoot);
}

//create framelistener
void createFrameListener(void)
{
mFrameListener = new TutorialFrameListener(mWindow, mCamera, mWorld, mStepper);
mRoot->addFrameListener(mFrameListener);
}

private:
OgreOde::World *mWorld;
OgreOde::Space *mSpace;
OgreOde::StepHandler *mStepper;

OgreOde::InfinitePlaneGeometry *mGround;
OgreOde::Body *mBody;
OgreOde::Geometry *mGeom;
OgreOde::BoxMass *mMass;
Ogre::SceneNode *mNode;
Ogre::Entity *mEntity;
};

#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
#define WIN32_LEAN_AND_MEAN
#include "windows.h"

INT WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInstance, LPSTR lpCmdLine, INT nShowCmd)
#else
int main(int argc, char **argv)
#endif
{
/** Create application object */
TutorialApplication app;

try
{
app.go();
}
catch(Exception e)
{
#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
MessageBox(NULL, (LPWSTR)e.getFullDescription().c_str(), L"An Exception has occured.", MB_OK | MB_ICONERROR | MB_TASKMODAL);
#else
fprintf(stderr, "An exception has occured: %s\n", e.getFullDescription().c_str());
#endif
}

return 0;
}


What am I doing wrong?

Thanks.

Niteen.

dermont

06-02-2009 03:36:54

From the tutorial you don't appear to be creating the stepper:

mStepper = new OgreOde::StepHandler(mWorld, OgreOde::StepHandler::QuickStep,_time_step, max_frame_time,
time_scale);

niteenhatle

06-02-2009 15:55:12

Damn!

Thanks Dermont.

I feel like a fool! :shock:

Thanks I have this forum.

Thanks again. I'll try it tonight.

Niteen

niteenhatle

07-02-2009 01:57:36

Eureka! Eureka! It works!

Thanks Dermont, the program works properly.

Here is a complete code for the program (Hope somebody finds it helpful) :

/** TutorialApplication.cpp */

/** Include example application headerfile */
#include "ExampleApplication.h"
//#include "OgreOde\OgreOde_Core.h"
#include "OgreOde_Core.h"

class TutorialFrameListener : public ExampleFrameListener
{
protected:
OgreOde::World* mWorld;
OgreOde::StepHandler* mStepper;

public:
TutorialFrameListener(RenderWindow* win, Camera* cam, OgreOde::World* _world, OgreOde::StepHandler* _stepper)
: ExampleFrameListener(win, cam), mWorld(_world), mStepper(_stepper)
{
}
//bool frameStarted(const FrameEvent& evt)
bool frameEnded(const FrameEvent& evt)
{
Real time = evt.timeSinceLastFrame;
if ( mStepper->step(time) )
mWorld->synchronise();
return ExampleFrameListener::frameEnded(evt);
//return ExampleFrameListener::frameStarted(evt);
}
};

/** Class TutorialApplication */
class TutorialApplication : public ExampleApplication
{
protected:

public:
TutorialApplication(void)
{
}

~TutorialApplication(void)
{
}

protected:
void createScene(void)
{

/** Create ambient light */
mSceneMgr->setAmbientLight(ColourValue(1, 1, 1));

/** Create point light, set its type and position */
Light *light = mSceneMgr->createLight("Light1");
light->setType(Light::LT_POINT);
light->setPosition(Vector3(0, 150, 250));

/** set the diffuse and specular colour */
light->setDiffuseColour(1.0, 1.0, 1.0);
light->setSpecularColour(1.0, 1.0, 1.0);

/** Add physics to Ogre */
mWorld = new OgreOde::World(mSceneMgr);
mWorld->setGravity(Ogre::Vector3(0, -9.80665, 0));
mWorld->setCFM(10e-5);
mWorld->setERP(0.8);
mWorld->setAutoSleep(true);
mWorld->setAutoSleepAverageSamplesCount(10);
mWorld->setContactCorrectionVelocity(1.0);
mSpace = mWorld->getDefaultSpace();

const Ogre::Real _time_step = 0.5;
const Ogre::Real time_scale = Ogre::Real(1.7);
const Ogre::Real max_frame_time = Ogre::Real(1.0 / 4);

mStepper = new OgreOde::StepHandler(mWorld, OgreOde::StepHandler::QuickStep, _time_step, max_frame_time, time_scale);

mGround = new OgreOde::InfinitePlaneGeometry(Plane(Ogre::Vector3(0,1,0),0), mWorld, mWorld->getDefaultSpace());

//load meshed
int i = 0;
StaticGeometry *s;
s = mSceneMgr->createStaticGeometry("StaticFloor");
s->setRegionDimensions(Ogre::Vector3(160.0, 100.0, 160.0));

//set the region origin so the center is at 0 world
s->setOrigin(Ogre::Vector3::ZERO);

for(Real z = -80.0; z <= 80.0; z += 20.0)
{
for(Real x = -80.0; x <= 80.0; x += 20.0)
{
String name = String("Ground") + StringConverter::toString(i++);
Entity *entity = mSceneMgr->createEntity(name, "plane.mesh");
entity->setQueryFlags(1<<4);
entity->setUserObject(mGround);
entity->setCastShadows(false);
s->addEntity(entity, Ogre::Vector3(x,0,z));
}
}
s->build();

mEntity = mSceneMgr->createEntity("crate", "crate.mesh");
mEntity->setQueryFlags(1<<2);
mNode = mSceneMgr->getRootSceneNode()->createChildSceneNode("crate");
mNode->attachObject(mEntity);
//mEntity->setNormaliseNormals(true);
mEntity->setCastShadows(true);

//create a body for our crate
//and "register" it in our world and the scene node
mBody = new OgreOde::Body(mWorld);
mNode->attachObject(mBody);

//set size and mass of the box
Vector3 size(10.0,10.0,10.0);
OgreOde::BoxMass mMass(0.5, size);
mMass.setDensity(5.0, size);
mGeom = (OgreOde::Geometry*) new OgreOde::BoxGeometry(size, mWorld, mSpace);
mNode->setScale(size.x * 0.1, size.y * 0.1, size.z * 0.1);
mBody->setMass(mMass);
mGeom->setBody(mBody);
mEntity->setUserObject(mGeom);

//set the orientation and position of the crate
mBody->setOrientation(Quaternion(Radian(5.0), Ogre::Vector3(0,0,0)));
mBody->setPosition(Vector3(0,120,-20));
}

//create framelistener
void createFrameListener(void)
{
mFrameListener = new TutorialFrameListener(mWindow, mCamera, mWorld, mStepper);
mRoot->addFrameListener(mFrameListener);
}

private:
OgreOde::World *mWorld;
OgreOde::Space *mSpace;
OgreOde::StepHandler *mStepper;

OgreOde::InfinitePlaneGeometry *mGround;
OgreOde::Body *mBody;
OgreOde::Geometry *mGeom;
OgreOde::BoxMass *mMass;
Ogre::SceneNode *mNode;
Ogre::Entity *mEntity;
};

#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
#define WIN32_LEAN_AND_MEAN
#include "windows.h"

INT WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInstance, LPSTR lpCmdLine, INT nShowCmd)
#else
int main(int argc, char **argv)
#endif
{
/** Create application object */
TutorialApplication app;

try
{
app.go();
}
catch(Exception e)
{
#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
MessageBox(NULL, (LPWSTR)e.getFullDescription().c_str(), L"An Exception has occured.", MB_OK | MB_ICONERROR | MB_TASKMODAL);
#else
fprintf(stderr, "An exception has occured: %s\n", e.getFullDescription().c_str());
#endif
}

return 0;
}


Thanks again.

I'll put it in the tutorial page as well. First Steps with OgreOde.

Thanks.

Niteen

niteenhatle

23-02-2009 17:47:39

Hi,

Although the first steps tutorial runs properly for me. (After some help by Dermont) I have some questions.

What is OgreOde::StepHandler? And what does it do?

And what does this code do in the first tutorial?

mGround = new OgreOde::InfinitePlaneGeometry(Plane(Ogre::Vector3(0,1,0),0), mWorld, mWorld->getDefaultSpace());
// Use a load of meshes to represent the floor
int i = 0;
StaticGeometry* s;
s = mSceneMgr->createStaticGeometry("StaticFloor");
s->setRegionDimensions(Ogre::Vector3(160.0, 100.0, 160.0));
// Set the region origin so the center is at 0 world
s->setOrigin(Ogre::Vector3::ZERO);
for (Real z = -80.0;z <= 80.0;z += 20.0)
{
for (Real x = -80.0;x <= 80.0;x += 20.0)
{
String name = String("Ground") + StringConverter::toString(i++);
Entity* entity = mSceneMgr->createEntity(name, "plane.mesh");
entity->setQueryFlags (1<<4);
entity->setUserObject(mGround);
entity->setCastShadows(false);
s->addEntity(entity, Ogre::Vector3(x,0,z));
}
}
s->build();

Particularly, what is happening in the two nested for loops?

I hope someone knows the answers.

Thanks.

Niteen

Anonymous

24-05-2009 04:52:56

If you’re wondering about specific zones to search for ore to mine wow gold, when you’re at lower levels, you should hit Strangle thorn Vale, followed by Burning Steppes and Un’Goro Crater and in Outland in Nagrand and later Netherstorm. This progression will lead you to higher-value nodes over time as your character becomes able to survive in them.