Need help with my first program

F-Wölkchen

24-03-2008 10:59:04

Hello.
I've a problem with my first program which I found on this site: http://www.ogre3d.org/wiki/index.php/First_steps_with_OgreODE

When I start it it says:
assertion "bNormalizationResult" failed in ...

I thought this error was shown because of this function:
mBody->setOrientation(Quaternion( Radian(5), Vector3(0,0,0) ));

Changing the value of the vector makes the program working but the box sticks to the ground.

Here is my Code:

#include "Wichtig.h"

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

OgreOde::InfinitePlaneGeometry *mGround; //Das ist die Map

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

//========================================Eventlistener==========================================
class EventListener : public ExampleFrameListener
{
public:
EventListener(RenderWindow* win, Camera* cam, SceneManager* sm)
: ExampleFrameListener(win, cam, true, true)
{
mSceneMgr=sm;
}

bool frameStarted(const FrameEvent &evt)
{
mMouse->capture();
mKeyboard->capture();

if(mKeyboard->isKeyDown(OIS::KC_ESCAPE))
return false;

if(mKeyboard->isKeyDown(OIS::KC_UP))
{
mBody->addForce(Vector3(0,200,0));
}
if(mKeyboard->isKeyDown(OIS::KC_F1))
{
mBody->setPosition(Vector3(0,200,0));
}

Ogre::Real time = evt.timeSinceLastFrame;
if (mStepper->step(time))
{
mWorld->synchronise();
}


return true;
}

protected:
SceneManager *mSceneMgr; // The current SceneManager
SceneNode *mCamNode; // The SceneNode the camera is currently attached to
};
//========================================Eventlistener==========================================



//=======================================Hauptklasse=============================================
class Program : public ExampleApplication
{
protected:
public:
Program()
{

}

~Program()
{

}
protected:

virtual void createCamera(void)
{
mCamera = mSceneMgr->createCamera("PlayerCam");
mCamera->setPosition(Vector3(0,100,100));
mCamera->lookAt(Vector3(0,0,0));
mCamera->setNearClipDistance(5);
}

virtual void createViewports(void)
{
Viewport* vp = mWindow->addViewport(mCamera);
vp->setBackgroundColour(ColourValue(0,0,0));
mCamera->setAspectRatio(Real(vp->getActualWidth()) / Real(vp->getActualHeight()));
}

void createScene(void)
{
mSceneMgr->setAmbientLight(ColourValue(0.25, 0.25, 0.25));
mSceneMgr->setShadowTechnique(SHADOWTYPE_STENCIL_ADDITIVE);

Light *light = mSceneMgr->createLight("Light1");
light->setType(Light::LT_POINT);
light->setPosition(Vector3(0, 150, 250));
light->setDiffuseColour(0.5, 0.5, 0.5);
light->setSpecularColour(1.0, 1.0, 1.0);


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());
// 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();

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

mBody = new OgreOde::Body(mWorld);
mNode->attachObject(mBody);

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.05,size.y * 0.05,size.z * 0.05);
mBody->setMass(mMass);
mGeom->setBody(mBody);
mEntity->setUserObject(mGeom);

mBody->setOrientation(Quaternion( Radian(5), Vector3(0,0,0) ));
mBody->setPosition(Vector3(0,220,-20));


}

void createFrameListener(void)
{
mFrameListener= new EventListener(mWindow, mCamera, mSceneMgr);
mFrameListener->showDebugOverlay(true);
mRoot->addFrameListener(mFrameListener);
}



};
//=======================================Hauptklasse=============================================














//=======================================Hauptfunktion===========================================
INT WINAPI WinMain( HINSTANCE hInst, HINSTANCE, LPSTR strCmdLine, INT )
{

Program app;

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


return 0;
}
//=======================================Hauptfunktion===========================================



What's wrong?

Plz I need help.

Florian from Germany

rewb0rn

24-03-2008 14:06:25

I ahve no idea what could be wrong. Have you tried the sample programs?

F-Wölkchen

24-03-2008 16:49:42

not yet.
I'll try to compile them.

However, the same warning was shown by this (http://tuan.kuranes.free.fr/OgreOde_Demo_Setup.exe) example program.

I think this is a general problem isn't it?

Florian

rewb0rn

24-03-2008 17:11:33

I don't remember that I ever faced that, but I only work with my project and haven't build any other programs for a while. Maybe it happens because ode has been updated, but honestly I don't know.

F-Wölkchen

24-03-2008 19:06:43

It's because of the odemaths.h .
I think normalizing a null vector is not possible.
There is a bug.

Unfortunally I do not find a smal sample programm.

Maybe I've to get ogreBullet. Maybe this works.

Thank you.

Florian

F-Wölkchen

25-03-2008 11:32:50

Hello again.
Bullet stinks.
I think ODE is much better.

Do anybody have OgreOde_Prefab_d.lib and dll.
Can somebody upload all libs and dlls from ogreode to rapidshare or something else.
I think quite a lot need them. Compiling it didn't work.

Need help.

plz.

Florian

rewb0rn

25-03-2008 12:35:59

Did you try this tutorial?

F-Wölkchen

25-03-2008 14:43:56

Yeah!!!
It works. No error... nothing.
I've compiled ogreode again and now it works.

Thank you very much.

Only one question:
The box is falling down. How can I add a Force to this box. I mean how can I make it fly again?
if(mKeyboard->isKeyDown(OIS::KC_F1))
{
mBody->addForce(Vector3(0,100,0));
}

This does not work.

Florian

rewb0rn

25-03-2008 18:06:02

It should, try a much higher value like 0, 100000, 0. If it works, best would be to shrink your scene, ode works best with forces and sizes about 1.