joaopccosta
21-10-2010 14:41:27
Hi there guys!
I'm totally new to NxOgre and i'm using it on my college thesis project.
So... first, i've built it successfuly and I've been following the 1st tutorial. I successfuly ran through it but i noticed that... the collision between the two cubes, does not occur at the cube's meshes but at the "object center" you might say. Meaning, there's mesh penetration Plus, when the cubes hit the ground, their meshes don't collide with the plane... again, it's their "object center" that collides
Thinking that this was abnormal, i move forward to the 2nd tutorial. Maybe the visual debugger would help to understand what was going wrong. Again, it was a breeze. But, when i run the app, I get no visual debugging
So my question is... what could be wrong with my approach?
Thanks for any help!
Here goes my code, just in case:
I've added some methods of mine so...
Application Code
Application FrameListener Code
I'm totally new to NxOgre and i'm using it on my college thesis project.
So... first, i've built it successfuly and I've been following the 1st tutorial. I successfuly ran through it but i noticed that... the collision between the two cubes, does not occur at the cube's meshes but at the "object center" you might say. Meaning, there's mesh penetration Plus, when the cubes hit the ground, their meshes don't collide with the plane... again, it's their "object center" that collides
Thinking that this was abnormal, i move forward to the 2nd tutorial. Maybe the visual debugger would help to understand what was going wrong. Again, it was a breeze. But, when i run the app, I get no visual debugging
So my question is... what could be wrong with my approach?
Thanks for any help!
Here goes my code, just in case:
I've added some methods of mine so...
Application Code
class NxOgre_testapp : public ExampleApplication
{
public:
NxOgre_tutorial1App()
{
createdObjects = 0;
}
~NxOgre_tutorial1App()
{
}
protected:
//NxOgre Vars
NxOgre::World* mWorld;
NxOgre::Scene* mScene;
OGRE3DRenderSystem* mRenderSystem;
//NxOgre Debugger vars
NxOgre::VisualDebugger* mVisualDebugger;
OGRE3DRenderable* mVisualDebuggerRenderable;
Ogre::SceneNode* mVisualDebuggerNode;
vector<OGRE3DBody*> bodies;
int createdObjects;
virtual void createCamera(void)
{
// Create the camera
mCamera = mSceneMgr->createCamera("PlayerCam");
// Position it at 500 in Z direction
mCamera->setPosition(Vector3(0,200,500));
// Look back along -Z
mCamera->lookAt(Vector3(0,0,0));
mCamera->setNearClipDistance(5);
}
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)
{
// Create Physics World
initNxOgre();
// Set ambient light
mSceneMgr->setAmbientLight(ColourValue(0.5f, 0.5f, 0.5f));
// Create a light
Light* l = mSceneMgr->createLight("MainLight");
l->setPosition(20, 80, 50);
l->setDiffuseColour(.20,.20,.20);
l->setSpecularColour(.20,.20,.20);
//basic world is now set...
//creating objects
createPlane("GrassFloor");
//createSphere(Vector3(-50,200,0),1,"RustySteel");
//createSphere(Vector3(50,200,0),2,"");
createCube(Vector3(0,200,0),10,"");
//createCube(Vector3(0,200,100),10,"");
addForceOnBody("Cube_1", NxOgre::Vec3(0,0,-1000));
//addForceOnBody("Sphere_1", NxOgre::Vec3(3000,0,0));
}
// Create new frame listener
void createFrameListener(void)
{
mFrameListener= new NxOgre_tutorial1FrameListener(mWindow, mCamera, mVisualDebugger, mVisualDebuggerNode);
mRoot->addFrameListener(mFrameListener);
}
void addForceOnBody(string bodyName, NxOgre::Vec3 force)
{
unsigned int i;
OGRE3DBody* tempbody;
for (i = 0; i<bodies.size(); i++){
tempbody = bodies.at(i);
string tempname = tempbody->getNxActor()->getName();
if(tempname.find(bodyName)!= -1)
tempbody->addForce(force);
}
}
void createSphere(Vector3 pos, float scale = 1, string name = "")
{
OGRE3DBody* mBody;
//this is a scale between Ogre and NxOgre
static const Real physics_scale = 0.1;
//incrase number of objects
createdObjects++;
//create the body
mBody = mRenderSystem->createBody(new NxOgre::Sphere(scale),pos,"sphere.mesh");
//set object name
char* temp = new char[sizeof(int)];
itoa(createdObjects,temp,10);
char* temp2= new char[20];
char *aux = "Sphere_";
memcpy(temp2,aux,strlen(aux));
strcat(temp2,temp);
mBody->getNxActor()->setName(temp2);
//scale adjust
mBody->getEntity()->getParentNode()->scale(scale*physics_scale ,scale*physics_scale ,scale*physics_scale);
if (name.compare("") !=0)
mBody->getEntity()->setMaterialName("Examples/"+name);
bodies.push_back(mBody);
}
void createCube(Vector3 pos, float scale = 1, string name = "")
{
OGRE3DBody* mBody;
//this is a scale between Ogre and NxOgre
static const Real physics_scale = 0.1;
scale = scale * physics_scale;
//incrase number of objects
createdObjects++;
//create the body
mBody = mRenderSystem->createBody(new NxOgre::Box(scale,scale,scale),pos,"cube.mesh");
//set object name
char* temp = new char[sizeof(int)];
itoa(createdObjects,temp,10);
char* temp2= new char[20];
char *aux = "Cube_";
memcpy(temp2,aux,strlen(aux));
strcat(temp2,temp);
mBody->getNxActor()->setName(temp2);
mBody->getEntity()->getParentNode()->scale(scale*physics_scale ,scale*physics_scale ,scale*physics_scale );
mBody->setMass(10);
if (name.compare("") !=0)
mBody->getEntity()->setMaterialName("Examples/"+name);
bodies.push_back(mBody);
}
void createPlane(string name)
{
mScene->createSceneGeometry(new NxOgre::PlaneGeometry(0, NxOgre::Vec3(0, 1, 0)), Matrix44_Identity);
MovablePlane *plane = new MovablePlane("Plane");
plane->d = 0;
plane->normal = Vector3::UNIT_Y;
Ogre::MeshManager::getSingleton().createPlane("PlaneMesh",
ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
*plane, 1200, 1200, 1, 1, true, 1, 3, 3, Vector3::UNIT_Z);
Entity *planeEnt = mSceneMgr->createEntity("PlaneEntity", "PlaneMesh");
planeEnt->setMaterialName("Examples/"+name);
planeEnt->setVisible(true);
Ogre::SceneNode* mPlaneNode = mSceneMgr->getRootSceneNode()->createChildSceneNode();
mPlaneNode->attachObject(planeEnt);
//mPlaneNode->scale(1, 1, 1);
}
void logActors()
{
//test to log all NxOgre Actors
unsigned int i;
OGRE3DBody* tempbody;
Ogre::LogManager::getSingleton().logMessage(LML_NORMAL,"Our Objects! \n");
for (i = 0; i<bodies.size(); i++){
tempbody = bodies.at(i);
string tempname = tempbody->getNxActor()->getName();
Ogre::LogManager::getSingleton().logMessage(LML_NORMAL,tempname);
}
}
private:
void initNxOgre()
{
//init NxOgre World
mWorld = NxOgre::World::createWorld();
//init NxOgre Visual Debugger
mVisualDebugger = mWorld->getVisualDebugger();
mVisualDebuggerRenderable = new OGRE3DRenderable(NxOgre::Enums::RenderableType_VisualDebugger);
mVisualDebugger->setRenderable(mVisualDebuggerRenderable);
mVisualDebuggerNode = mSceneMgr->getRootSceneNode()->createChildSceneNode();
mVisualDebuggerNode->attachObject(mVisualDebuggerRenderable);
mVisualDebugger->setVisualisationMode(NxOgre::Enums::VisualDebugger_ShowAll);
NxOgre::SceneDescription sceneDesc;
sceneDesc.mGravity = NxOgre::Vec3(0, -9.8f, 0);
sceneDesc.mName = "MyTestApp";
//attach scene to the world
mScene = mWorld->createScene(sceneDesc);
// Setup default physical attributes of the world
mScene->getMaterial(0)->setStaticFriction(0.5);
mScene->getMaterial(0)->setDynamicFriction(0.5);
mScene->getMaterial(0)->setRestitution(0.1);
// Declare rendering engine
mRenderSystem = new OGRE3DRenderSystem(mScene);
}
};
Application FrameListener Code
class NxOgre_testappFrameListener : public ExampleFrameListener
{
private:
SceneManager* mSceneMgr;
protected:
NxOgre::TimeController* mTimeController;
NxOgre::VisualDebugger* mVisualDebugger;
Ogre::SceneNode* mVisualDebuggerNode;
public:
NxOgre_tutorial1FrameListener(RenderWindow* win, Camera* cam, NxOgre::VisualDebugger* visualDebugger, Ogre::SceneNode* node)
: ExampleFrameListener(win, cam)
{
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);
return ret;
}
};