jurgel
15-05-2010 09:09:53
I tried compile first steps with OgreODE from http://www.ogre3d.org/wiki/index.php/First_steps_with_OgreODE, but without exampleapplication.h,
compile and linking successfull, but error at start of program
here it's my code
what should I do?
sry for english ^^
thank you..
compile and linking successfull, but error at start of program
here it's my code
#include "Ogre.h"
#include "OgreFrameListener.h"
#include <OIS/OIS.h>
#include "OgreOde\OgreOde_Core.h"
using namespace Ogre;
class SimpleFrameListener : public FrameListener
{
public:
SimpleFrameListener(OIS::Keyboard* keyboard, OIS::Mouse* mouse, OgreOde::World* _world, OgreOde::StepHandler* _stepper)
{
mKeyboard = keyboard;
mMouse = mouse;
}
// This gets called before the next frame is beeing rendered.
bool frameStarted(const FrameEvent& evt)
{
//update the input devices
mKeyboard->capture();
mMouse->capture();
//exit if key KC_ESCAPE pressed
if(mKeyboard->isKeyDown(OIS::KC_ESCAPE))
return false;
return true;
}
// This gets called at the end of a frame.
bool frameEnded(const FrameEvent& evt)
{
Real time = evt.timeSinceLastFrame;
if ( mStepper->step(time) )
mWorld->synchronise();
return true;
}
private:
OIS::Keyboard* mKeyboard;
OIS::Mouse* mMouse;
OgreOde::World* mWorld;
OgreOde::StepHandler* mStepper;
};
class Application
{
public:
void go()
{
createRoot();
defineResources();
setupRenderSystem();
createRenderWindow();
initializeResourceGroups();
setupScene();
setupInputSystem();
createFrameListener();
startRenderLoop();
}
~Application()
{
mInputManager->destroyInputObject(mKeyboard);
mInputManager->destroyInputObject(mMouse);
OIS::InputManager::destroyInputSystem(mInputManager);
delete mListener;
delete mRoot;
}
private:
Root *mRoot;
OIS::Keyboard *mKeyboard;
OIS::Mouse *mMouse;
OIS::InputManager *mInputManager;
SimpleFrameListener *mListener;
SceneManager *mSceneMgr;
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;
void createRoot()
{
mRoot = new Root();
}
void defineResources()
{
String secName, typeName, archName;
ConfigFile cf;
cf.load("resources.cfg");
ConfigFile::SectionIterator seci = cf.getSectionIterator();
while (seci.hasMoreElements())
{
secName = seci.peekNextKey();
ConfigFile::SettingsMultiMap *settings = seci.getNext();
ConfigFile::SettingsMultiMap::iterator i;
for (i = settings->begin();i != settings->end(); ++i)
{
typeName = i->first;
archName = i->second;
ResourceGroupManager::getSingleton().addResourceLocation(archName, typeName, secName);
}
}
}
void setupRenderSystem()
{
if (!mRoot->restoreConfig() && !mRoot->showConfigDialog())
throw Exception(52, "User canceled the config dialog!", "Application::setupRenderSystem()");
}
void createRenderWindow()
{
mRoot->initialise(true, "Ogre Test Render Window");
}
void initializeResourceGroups()
{
TextureManager::getSingleton().setDefaultNumMipmaps(5);
ResourceGroupManager::getSingleton().initialiseAllResourceGroups();
}
void setupScene()
{
/** 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->setUserAny(Any(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->setUserAny(Any(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));
}
void setupInputSystem()
{
size_t windowHnd = 0;
std::ostringstream windowHndStr;
OIS::ParamList pl;
RenderWindow *win = mRoot->getAutoCreatedWindow();
win->getCustomAttribute("WINDOW", &windowHnd);
windowHndStr << windowHnd;
pl.insert(std::make_pair(std::string("WINDOW"), windowHndStr.str()));
mInputManager = OIS::InputManager::createInputSystem(pl);
try
{
mKeyboard = static_cast<OIS::Keyboard*>(mInputManager->createInputObject(OIS::OISKeyboard, false));
mMouse = static_cast<OIS::Mouse*>(mInputManager->createInputObject(OIS::OISMouse, false));
//mJoy = static_cast<OIS::JoyStick*>(mInputManager->createInputObject(OIS::OISJoyStick, false));
}
catch (const OIS::Exception &e)
{
throw new Exception(42, e.eText, "Application::setupInputSystem");
}
}
void createFrameListener()
{
mListener = new SimpleFrameListener(mKeyboard, mMouse, mWorld, mStepper);
mRoot->addFrameListener(mListener);
}
void startRenderLoop()
{
mRoot->startRendering();
}
};
#if OGRE_PLATFORM == PLATFORM_WIN32 || OGRE_PLATFORM == OGRE_PLATFORM_WIN32
#define WIN32_LEAN_AND_MEAN
#include "windows.h"
INT WINAPI WinMain(HINSTANCE hInst, HINSTANCE, LPSTR strCmdLine, INT)
#else
int main(int argc, char **argv)
#endif
{
try
{
Application app;
app.go();
}
catch(Exception& e)
{
#if OGRE_PLATFORM == PLATFORM_WIN32 || OGRE_PLATFORM == OGRE_PLATFORM_WIN32
MessageBoxA(NULL, e.getFullDescription().c_str(), "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;
}
what should I do?
sry for english ^^
thank you..