marc_antoine
14-05-2009 22:10:00
first of all, i will try to xplain what i have been doing..
I'm new to this physics stuff so i'm trying ogre ODE for the first time, and after having a hard time trying to compile ogrOde i finally got it and srtarted reading the WIKI tut. http://www.ogre3d.org/wiki/index.php/First_steps_with_OgreODE everything went fine i got the program running, but i got somehow confusing, since at the beginning of the tutorial i thought that the crate will collide with my floor... so the crate will stop falling right when it hits the floor, but for my surprise i didn't. almost at the end, rewb0rn says the the crate will get through the floor, so ok, i move on to the collision tutorial http://www.ogre3d.org/wiki/index.php/OgreOde_Collision_Handling , i found interesting but is not a clear example of how to hanlde collision....what i got from that example is that i have to do a clas that implemests the collision callback in it so o came to this code...
myOgreOde.h
myOgreOde.cpp---- i'm posting only the the two methods that has ogreOde code, to keep it easy to read... also i'm not loading the mesh directly, since i'm using the OFusion plugin to create my Meshes i have to use the Ofusion Loader.
I'm new to this physics stuff so i'm trying ogre ODE for the first time, and after having a hard time trying to compile ogrOde i finally got it and srtarted reading the WIKI tut. http://www.ogre3d.org/wiki/index.php/First_steps_with_OgreODE everything went fine i got the program running, but i got somehow confusing, since at the beginning of the tutorial i thought that the crate will collide with my floor... so the crate will stop falling right when it hits the floor, but for my surprise i didn't. almost at the end, rewb0rn says the the crate will get through the floor, so ok, i move on to the collision tutorial http://www.ogre3d.org/wiki/index.php/OgreOde_Collision_Handling , i found interesting but is not a clear example of how to hanlde collision....what i got from that example is that i have to do a clas that implemests the collision callback in it so o came to this code...
myOgreOde.h
#include <Ogre.h>
#include <OIS/OIS.h>
#include "marcBasicFrameListener.h"
#include "OgreOSMScene.h"
#include "OgreOde_Core.h"
using namespace Ogre;
class Application: public OgreOde::CollisionListener
{
public:
void go();
~Application();
private:
Root *mRoot;
OIS::Keyboard *mKeyboard;
OIS::Mouse *mMouse;
OIS::InputManager *mInputManager;
ExitListener *mListener;
Ogre::RenderWindow *mWindow;
Ogre::Camera *mCamera;
Ogre::SceneManager *mSceneMgr;
Ogre::Viewport *vp;
Ogre::SceneNode* nodoMyCamera;
Ogre::SceneNode* nodoModelo;
///Ogre ODE/////////////////////////////////////
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();
void defineResources();
void setupRenderSystem();
void createRenderWindow();
void initializeResourceGroups();
void setupScene();
void setupInputSystem();
void createFrameListener();
void startRenderLoop();
void cargarOSM();
void setupPhysics();
bool collision(OgreOde::Contact *);
};
myOgreOde.cpp---- i'm posting only the the two methods that has ogreOde code, to keep it easy to read... also i'm not loading the mesh directly, since i'm using the OFusion plugin to create my Meshes i have to use the Ofusion Loader.
#include "myOgreOde.h"
void Application::setupPhysics()
{
mWorld = new OgreOde::World(mSceneMgr);
mWorld->setGravity(Ogre::Vector3(0,-980.665,0));
mWorld->setCFM(10e-5);
mWorld->setERP(0.8);
mWorld->setAutoSleep(true);
mWorld->setAutoSleepAverageSamplesCount(10);
mWorld->setContactCorrectionVelocity(1.0);
mSpace = mWorld->getDefaultSpace();
mSpace->setInternalCollisions(true);
mWorld->setCollisionListener(this); //<-------since class Application: public OgreOde::CollisionListener
mWorld->setShowDebugGeometries(true);
////*/////////*/*/*//*/*/*/*/*/*/*/*/*/*/*////
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),10), mWorld, mWorld->getDefaultSpace());
//*/**//*//*//*//*//*//*//*//*//*//*//*//*//*//*//*//*//
mBody = new OgreOde::Body(mWorld);
mNode=mSceneMgr->getSceneNode("caja"); //<----i get the crate like this becouse i'm using oFusion loader
mEntity=mSceneMgr->getEntity("caja"); //<----so i gotta get the entity liek this.... for the same reason...
mNode->attachObject(mBody);
Vector3 size(mEntity->getBoundingBox().getSize());//the model size is in cm, and is 1000, 1000,1000
OgreOde::BoxMass mMass(0.5,size);
mMass.setDensity(0.05,size);
mGeom = (OgreOde::Geometry*)new OgreOde::BoxGeometry(size, mWorld, mSpace);
mBody->setMass(mMass);
mGeom->setBody(mBody);
mEntity->setUserObject(mGeom);
}
bool Application::collision(OgreOde::Contact *contact)
{
MessageBoxA(NULL, "colision!!", "colision!!", MB_OK);
return false;
}
- so when the crate hits the floor, i get a collision callback but anyway it continues it way through the floor... [/list:u]
- also the collision box seems to be like in the middle of the crate?.. why's so? it is normal?[/list:u]
- even if the crate has gone through the floor, and it is no colliding anymore... the collision() is been called again, and again , and again, and never stops i have to kill the program...[/list:u]
[attachment=1]colissionDoubt.jpg[/attachment]
box continuing it's free fall, and the collision messageBox still appearing indicating that the collision() is still been called
[attachment=0]colissionDoubt2.jpg[/attachment]
any clues?, any clear simple way of how to implement this?. the ogreOde examples are fine, but they are an all topics in one example, project, PLEAAASEEEE!!!!...
i'm sorry for bothering you guys...
cheers!
- even if the crate has gone through the floor, and it is no colliding anymore... the collision() is been called again, and again , and again, and never stops i have to kill the program...[/list:u]
- also the collision box seems to be like in the middle of the crate?.. why's so? it is normal?[/list:u]