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:
I thought this error was shown because of this function:
Changing the value of the vector makes the program working but the box sticks to the ground.
Here is my Code:
What's wrong?
Plz I need help.
Florian from Germany
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