billwillman
28-03-2007 11:37:57
#include "ExampleApplication.h"
#include "ExampleFrameListener.h"
#include "OgreNewt.h"
class MyFrameListener:public ExampleFrameListener
{
private:
OgreNewt::World *mworld;
public:
MyFrameListener(RenderWindow* win, Camera* cam,OgreNewt::World *w):ExampleFrameListener(win,cam)
{
mworld=w;
}
bool frameStarted(const FrameEvent& evt)
{
if(!ExampleFrameListener::frameStarted(evt))
return false;
mworld->update(60);
return true;
}
};
class MyApplication : public ExampleApplication
{
private:
OgreNewt::World *mworld;
public:
MyApplication() {
mworld=new OgreNewt::World();
}
~MyApplication() {
delete mworld;
OgreNewt::Debugger::getSingleton().deInit();
}
protected:
void createFrameListener(void)
{
mFrameListener=new MyFrameListener(mWindow,mCamera,mworld);
mFrameListener->showDebugOverlay(true);
mRoot->addFrameListener(mFrameListener);
}
// Just override the mandatory create scene method
void createScene(void)
{
//环境设置
Vector3 size=Vector3(1000,1000,1000);
mworld->setWorldSize(size,-size);
mSceneMgr->setAmbientLight(ColourValue(1,0.2,0));
Entity *sceneentity=mSceneMgr->createEntity("scneneEntity","Box01.mesh");
sceneentity->setNormaliseNormals(true);
SceneNode *scenenode=mSceneMgr->getRootSceneNode()->createChildSceneNode("sceneNode");
scenenode->attachObject(sceneentity);
OgreNewt::Collision *col=new OgreNewt::CollisionPrimitives::TreeCollision(mworld,scenenode,false);
OgreNewt::Body *body=new OgreNewt::Body(mworld,col);
delete col;
body->attachToNode(scenenode);
//åŠ å…¥ä¸€ä¸ªBOX模型
Entity *boxentity=mSceneMgr->createEntity("boxEntity","cube.mesh");
boxentity->setNormaliseNormals(true);
SceneNode *boxnode=mSceneMgr->getRootSceneNode()->createChildSceneNode("boxNode");
boxnode->attachObject(boxentity);
AxisAlignedBox boxsize=boxentity->getBoundingBox();
OgreNewt::Collision *boxcol=new OgreNewt::CollisionPrimitives::Box(mworld,boxsize.getSize());
OgreNewt::Body* boxbody=new OgreNewt::Body(mworld,boxcol);
delete boxcol;
boxbody->attachToNode(boxnode);
boxbody->setPositionOrientation(Vector3(0,500,0),Quaternion::IDENTITY);
Ogre::Real mass=boxsize.getSize().x*boxsize.getSize().y*boxsize.getSize().z*2.5;
Vector3 intertia=OgreNewt::MomentOfInertia::CalcBoxSolid(mass,boxsize.getSize());
boxbody->setMassMatrix(mass,intertia);
boxbody->setStandardForceCallback();
boxbody->setAutoFreeze(1);
}
};
#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
#define WIN32_LEAN_AND_MEAN
#include "windows.h"
#endif
#ifdef __cplusplus
extern "C" {
#endif
#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
INT WINAPI WinMain( HINSTANCE hInst, HINSTANCE, LPSTR strCmdLine, INT )
#else
int main(int argc, char **argv)
#endif
{
// Create application object
MyApplication app;
try {
app.go();
} catch( Exception& e ) {
#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
MessageBox( NULL, e.getFullDescription().c_str(), "An exception has occured!", MB_OK | MB_ICONERROR | MB_TASKMODAL);
#else
std::cerr << "An exception has occured: " << e.getFullDescription();
#endif
}
return 0;
}
#ifdef __cplusplus
}
#endif
When the project runs, I can't see the Box moved(it's still in the sky)
why?