misiek
05-04-2009 19:18:13
I have the code:OGRE3DBody *box1, *box2;
box1 = mRenderSystem->createBody(new NxOgre::Box(1, 1, 1), NxOgre::Real3(0, 7, 0), "box.mesh");
box2 = mRenderSystem->createBody(new NxOgre::Box(2, 2, 6), NxOgre::Real3(0, 4, 0), "box2.mesh");
NxRevoluteJointDesc revJointDesc;
revJointDesc.setToDefault();
revJointDesc.actor[0] = box1->getNxActor();
revJointDesc.actor[1] = box2->getNxActor();
revJointDesc.setGlobalAnchor(NxVec3(0, 5.5, 0));
revJointDesc.setGlobalAxis(NxVec3(0, 0, -1));
mScene->getScene()->createJoint(revJointDesc);
It crashes :/ If I don't create joint - it works. I've used debugger and while debugging, for a wonder - there is no problem.
ps. I'm little confused with lack of doc.
misiek
06-04-2009 21:10:40
Could somebody check if this code work:
#include "ExampleApplication.h"
#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
#include "../res/resource.h"
#endif
#include <CEGUI.h>
#include <CEGUISystem.h>
#include <CEGUISchemeManager.h>
#include <OgreCEGUIRenderer.h>
#include <NxOgre.h>
#include <NxOgreOGRE3D.h>
#include <NxRevoluteJointDesc.h>
#include <NxScene.h>
OGRE3DBody *box1, *box2;
CEGUI::MouseButton convertOISMouseButtonToCegui(int buttonID)
{
switch (buttonID)
{
case 0: return CEGUI::LeftButton;
case 1: return CEGUI::RightButton;
case 2: return CEGUI::MiddleButton;
case 3: return CEGUI::X1Button;
default: return CEGUI::LeftButton;
}
}
class NxHeliFrameListener : public ExampleFrameListener, public OIS::KeyListener, public OIS::MouseListener
{
private:
SceneManager* mSceneMgr;
CEGUI::Renderer* mGUIRenderer;
bool mShutdownRequested;
bool mUseBufferedInputKeys, mUseBufferedInputMouse, mInputTypeSwitchingOn;
public:
NxHeliFrameListener(SceneManager *sceneMgr, RenderWindow* win, Camera* cam, CEGUI::Renderer* renderer, NxOgre::VisualDebugger* visualDebugger, Ogre::SceneNode* node)
: ExampleFrameListener(win, cam, true, true),
mGUIRenderer(renderer),
mShutdownRequested(false),
mUseBufferedInputKeys(true),
mUseBufferedInputMouse(true),
mSceneMgr(sceneMgr)
{
mMouse->setEventCallback(this);
mKeyboard->setEventCallback(this);
mInputTypeSwitchingOn = mUseBufferedInputKeys || mUseBufferedInputMouse;
mTimeController = NxOgre::TimeController::getSingleton();
mVisualDebugger = visualDebugger;
mVisualDebuggerNode = node;
}
bool frameStarted(const FrameEvent& evt)
{
mTimeController->advance(evt.timeSinceLastFrame);
mVisualDebugger->draw();
mVisualDebuggerNode->needUpdate();
bool ret = ExampleFrameListener::frameStarted(evt);
if(mUseBufferedInputMouse)
{
CEGUI::MouseCursor::getSingleton().show( );
}
else
{
CEGUI::MouseCursor::getSingleton().hide( );
}
return ret;
}
bool processUnbufferedKeyInput(const FrameEvent& evt)
{
bool ret = ExampleFrameListener::processUnbufferedKeyInput(evt);
// see if switching is on, and you want to toggle
if (mInputTypeSwitchingOn && mKeyboard->isKeyDown(OIS::KC_M) && mTimeUntilNextToggle <= 0)
{
switchMouseMode();
mTimeUntilNextToggle = 1;
}
if (mInputTypeSwitchingOn && mKeyboard->isKeyDown(OIS::KC_K) && mTimeUntilNextToggle <= 0)
{
// must be going from immediate keyboard to buffered keyboard
switchKeyMode();
mTimeUntilNextToggle = 1;
}
return ret;
}
void requestShutdown(void)
{
mShutdownRequested = true;
}
void switchMouseMode()
{
mUseBufferedInputMouse = !mUseBufferedInputMouse;
mMouse->setBuffered(mUseBufferedInputMouse);
}
//-------------------------------------------------------------------------------------
void switchKeyMode()
{
mUseBufferedInputKeys = !mUseBufferedInputKeys;
mKeyboard->setBuffered(mUseBufferedInputKeys);
}
bool frameEnded(const FrameEvent& evt)
{
if (mShutdownRequested)
return false;
else
return ExampleFrameListener::frameEnded(evt);
}
//----------------------------------------------------------------//
bool mouseMoved( const OIS::MouseEvent &arg )
{
CEGUI::System::getSingleton().injectMouseMove( arg.state.X.rel, arg.state.Y.rel );
return true;
}
//----------------------------------------------------------------//
bool mousePressed( const OIS::MouseEvent &arg, OIS::MouseButtonID id )
{
CEGUI::System::getSingleton().injectMouseButtonDown(convertOISMouseButtonToCegui(id));
return true;
}
//----------------------------------------------------------------//
bool mouseReleased( const OIS::MouseEvent &arg, OIS::MouseButtonID id )
{
CEGUI::System::getSingleton().injectMouseButtonUp(convertOISMouseButtonToCegui(id));
return true;
}
//----------------------------------------------------------------//
bool keyPressed( const OIS::KeyEvent &arg )
{
if( arg.key == OIS::KC_ESCAPE )
mShutdownRequested = true;
CEGUI::System::getSingleton().injectKeyDown( arg.key );
CEGUI::System::getSingleton().injectChar( arg.text );
return true;
}
//----------------------------------------------------------------//
bool keyReleased( const OIS::KeyEvent &arg )
{
if( arg.key == OIS::KC_M )
mMouse->setBuffered( !mMouse->buffered() );
else if( arg.key == OIS::KC_K )
mKeyboard->setBuffered( !mKeyboard->buffered() );
CEGUI::System::getSingleton().injectKeyUp( arg.key );
return true;
}
protected:
NxOgre::TimeController* mTimeController;
NxOgre::VisualDebugger* mVisualDebugger;
Ogre::SceneNode* mVisualDebuggerNode;
};
class NxHeliApp : public ExampleApplication
{
private:
CEGUI::OgreCEGUIRenderer* mGUIRenderer;
CEGUI::System* mGUISystem;
NxOgre::World* mWorld;
NxOgre::Scene* mScene;
NxOgre::TimeController* mTimeController;
OGRE3DRenderSystem* mRenderSystem;
NxOgre::SceneGeometry* mFloor;
NxOgre::VisualDebugger* mVisualDebugger;
OGRE3DRenderable* mVisualDebuggerRenderable;
Ogre::SceneNode* mVisualDebuggerNode;
public:
NxHeliApp()
: mGUIRenderer(0),
mGUISystem(0)
{}
~NxHeliApp()
{
if(mGUISystem)
{
delete mGUISystem;
mGUISystem = 0;
}
if(mGUIRenderer)
{
delete mGUIRenderer;
mGUIRenderer = 0;
}
}
protected:
virtual void createCamera(void)
{
// Create the camera
mCamera = mSceneMgr->createCamera("PlayerCam");
// Position it at 500 in Z direction
mCamera->setPosition(Vector3(0,10,20));
// Look back along -Z
mCamera->lookAt(Vector3(0,0,0));
mCamera->setNearClipDistance(1);
}
virtual bool configure(void)
{
// Show the configuration dialog and initialise the system
// You can skip this and use root.restoreConfig() to load configuration
// settings if you were sure there are valid ones saved in ogre.cfg
if(mRoot->showConfigDialog())
{
// If returned true, user clicked OK so initialise
// Here we choose to let the system create a default rendering window by passing 'true'
mWindow = mRoot->initialise(true);
// Let's add a nice window icon
#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
HWND hwnd;
mWindow->getCustomAttribute("WINDOW", (void*)&hwnd);
LONG iconID = (LONG)LoadIcon( GetModuleHandle(0), MAKEINTRESOURCE(IDI_APPICON) );
SetClassLong( hwnd, GCL_HICON, iconID );
#endif
return true;
}
else
{
return false;
}
}
// Just override the mandatory create scene method
virtual void createScene(void)
{
// setup GUI system
mGUIRenderer = new CEGUI::OgreCEGUIRenderer(mWindow,
Ogre::RENDER_QUEUE_OVERLAY, false, 3000, mSceneMgr);
mGUISystem = new CEGUI::System(mGUIRenderer);
CEGUI::Logger::getSingleton().setLoggingLevel(CEGUI::Informative);
// load scheme and set up defaults
CEGUI::SchemeManager::getSingleton().loadScheme(
(CEGUI::utf8*)"TaharezLookSkin.scheme");
mGUISystem->setDefaultMouseCursor(
(CEGUI::utf8*)"TaharezLook", (CEGUI::utf8*)"MouseArrow");
mGUISystem->setDefaultFont((CEGUI::utf8*)"BlueHighway-12");
CEGUI::MouseCursor::getSingleton().setImage("TaharezLook", "MouseArrow");
CEGUI::MouseCursor::getSingleton().show( );
setupEventHandlers();
// Set ambient light
mSceneMgr->setAmbientLight(ColourValue(0.5, 0.5, 0.5));
// Create a light
Light* l = mSceneMgr->createLight("MainLight");
l->setPosition(20,80,50);
// Create the world
mWorld = NxOgre::World::createWorld();
mVisualDebugger = mWorld->getVisualDebugger();
// Create scene description
NxOgre::SceneDescription sceneDesc;
sceneDesc.mGravity = NxOgre::Real3(0, -9.8f, 0);
sceneDesc.mName = "DemoScene";
// Create scene
mScene = mWorld->createScene(sceneDesc);
// Set some physical scene values
mScene->getMaterial(0)->setStaticFriction(0.5);
mScene->getMaterial(0)->setDynamicFriction(0.5);
mScene->getMaterial(0)->setRestitution(0.1);
// Create render system
mRenderSystem = new OGRE3DRenderSystem(mScene);
//Create time controller
mTimeController = NxOgre::TimeController::getSingleton();
// Add objects
box1 = mRenderSystem->createBody(new NxOgre::Box(1, 1, 1), NxOgre::Real3(0, 7, 0), "box.mesh");
box2 = mRenderSystem->createBody(new NxOgre::Box(1, 1, 1), NxOgre::Real3(0, 4, 0), "box.mesh");
// my joint ;)
NxRevoluteJointDesc revJointDesc;
revJointDesc.setToDefault();
revJointDesc.actor[0] = box1->getNxActor();
revJointDesc.actor[1] = box2->getNxActor();
revJointDesc.setGlobalAnchor(NxVec3(0, 5.5, 0));
revJointDesc.setGlobalAxis(NxVec3(0, 0, -1));
mScene->getScene()->createJoint(revJointDesc);
box1->addForce(NxOgre::Real3(0, 0, 0.2), NxOgre::Enums::ForceMode_Impulse, true);
// Create floor plane (BloodyMess)
mScene->createSceneGeometry(new NxOgre::PlaneGeometry(0, NxOgre::Real3(0, 1, 0)), NxOgre::Matrix44(NxOgre::Matrix44::T_Identity));
// Create floor plane (Ogre)
MovablePlane *plane = new MovablePlane("Plane");
plane->d = 0;
plane->normal = Vector3::UNIT_Y;
Ogre::MeshManager::getSingleton().createPlane("PlaneMesh",
ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
*plane, 120, 120, 1, 1, true, 1, 3, 3, Vector3::UNIT_Z);
Entity *planeEnt = mSceneMgr->createEntity("PlaneEntity", "PlaneMesh");
planeEnt->setMaterialName("PlaneMat");
Ogre::SceneNode* mPlaneNode = mSceneMgr->getRootSceneNode()->createChildSceneNode();
mPlaneNode->attachObject(planeEnt);
mVisualDebuggerRenderable = new OGRE3DRenderable(NxOgre::Enums::RenderableType_VisualDebugger);
mVisualDebugger->setRenderable(mVisualDebuggerRenderable);
mVisualDebuggerNode = mSceneMgr->getRootSceneNode()->createChildSceneNode();
mVisualDebuggerNode->attachObject(mVisualDebuggerRenderable);
mVisualDebugger->setVisualisationMode(NxOgre::Enums::VisualDebugger_ShowAll);
}
// Create new frame listener
void createFrameListener(void)
{
mFrameListener= new NxHeliFrameListener(mSceneMgr, mWindow, mCamera, mGUIRenderer, mVisualDebugger, mVisualDebuggerNode);
mRoot->addFrameListener(mFrameListener);
}
void setupEventHandlers(void)
{
}
bool handleQuit(const CEGUI::EventArgs& e)
{
static_cast<NxHeliFrameListener*>(mFrameListener)->requestShutdown();
return true;
}
};
#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
NxHeliApp app;
try {
app.go();
} catch( Ogre::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().c_str() << std::endl;
#endif
}
return 0;
}
#ifdef __cplusplus
}
#endif
This is whole program code. box.mesh is standard 1m cube.
TIA.
Please, just compile that code and tell me if it works. Two days wasted and I dont know what to do