rewb0rn
07-11-2007 17:07:42
As promised I wrote a tutorial on how to handle collisions the easy way. You find it here. Please give me some feedback, especially point out any mistakes with my English
rewb0rn
07-11-2007 17:07:42
kungfoomasta
07-11-2007 18:18:57
//we have 2 collidable objects from our object system
//PATH1 if (g1->getUserObject())
if (!static_cast<CollisionTestedObject*>(g1->getUserObject())->Collide(true, Contact))
return false;
//PATH2 if (g2->getUserObject())
if (!static_cast<CollisionTestedObject*>(g2->getUserObject())->Collide(false, Contact))
return false;
rewb0rn
07-11-2007 18:31:26
bool Return = true;
if (g1->getUserObject())
if (!static_cast<CollisionTestedObject*>(g1->getUserObject())->Collide(true, Contact))
Return = false;
if (g2->getUserObject())
if (!static_cast<CollisionTestedObject*>(g2->getUserObject())->Collide(false, Contact))
Return = false;
return Return;kungfoomasta
07-11-2007 18:37:53
rewb0rn
07-11-2007 18:46:26
kungfoomasta
07-11-2007 19:03:41
rewb0rn
07-11-2007 19:07:40
kungfoomasta
07-11-2007 19:59:22
Aquatix
07-11-2007 20:05:15
rewb0rn
07-11-2007 21:12:45
Aquatix
07-11-2007 21:29:11
F-Wölkchen
25-03-2008 19:02:55
rewb0rn
25-03-2008 19:53:03
F-Wölkchen
26-03-2008 19:53:44
class Program : public ExampleApplication
{
public:
Program()
{
}
~Program()
{
}
class Collision : public OgreOde::CollisionListener {
public:
bool collision(OgreOde::Contact* contact)
{
OgreOde::Geometry * const g1 = contact->getFirstGeometry();
OgreOde::Geometry * const g2 = contact->getSecondGeometry();
if (g1 && g2)
{
const OgreOde::Body * const b1 = g1->getBody();
const OgreOde::Body * const b2 = g2->getBody();
if (b1 && b2 && OgreOde::Joint::areConnected(b1, b2))
return false;
}
contact->setBouncyness(0.1);
contact->setCoulombFriction(OgreOde::Utility::Infinity);
return true;
}
};
protected:
virtual void createCamera(void)
{
mCamera = mSceneMgr->createCamera("PlayerCam");
mCamera->setPosition(Vector3(0,10,500));
mCamera->lookAt(Vector3(0,0,0));
mCamera->setNearClipDistance(1);
}
virtual void createViewports(void)
{
Viewport* vp = mWindow->addViewport(mCamera);
vp->setBackgroundColour(ColourValue(0,0,0));
mCamera->setAspectRatio(Real(vp->getActualWidth()) / Real(vp->getActualHeight()));
}
void createScene(void)
{
mSceneMgr->setAmbientLight(ColourValue(0.25, 0.25, 0.25));
mSceneMgr->setShadowTechnique(SHADOWTYPE_STENCIL_MODULATIVE);
mSceneMgr->setShadowColour(ColourValue(0.5,0.5,0.5));
Light *light = mSceneMgr->createLight("Light1");
light->setType(Light::LT_POINT);
light->setPosition(Vector3(0, 150, 250));
light->setDiffuseColour(0.5, 0.5, 0.5);
light->setSpecularColour(1.0, 1.0, 1.0);
light->setCastShadows(true);
mSceneMgr->setSkyDome(true, "Examples/CloudySky", 5, 8);
//---------------Welt wird definiert---------------
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();
mWorld->setCollisionListener(new Program::Collision());
//mWorld->setCollisionListener(this);
//---------------Welt wird definiert---------------
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::BasicStep,_time_step, max_frame_time,time_scale);
mGround = new OgreOde::InfinitePlaneGeometry(Plane(Ogre::Vector3(0,1,0),0), mWorld, mWorld->getDefaultSpace());
// Use a load of meshes to represent the floor
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->setUserObject(mGround);
entity->setCastShadows(false);
s->addEntity(entity, Ogre::Vector3(x,0,z));
}
}
s->build();
}
void chooseSceneManager(void)
{
mSceneMgr = mRoot->createSceneManager( ST_GENERIC, "ExampleGrandTurismo" );
}
void createFrameListener(void)
{
mFrameListener= new EventListener(mWindow, mCamera, mSceneMgr);
mFrameListener->showDebugOverlay(true);
mRoot->addFrameListener(mFrameListener);
mFrameListener= new ExampleFrameListener(mWindow, mCamera);
mFrameListener->showDebugOverlay(true);
mRoot->addFrameListener(mFrameListener);
}
};
//=======================================Hauptklasse=============================================
rewb0rn
27-03-2008 12:36:22
marc_antoine
13-05-2009 22:51:22
nfalcon
06-10-2009 21:55:20
Player::Player(Entity* entity, const String& name, World* world, Space* space) : EntityBase(entity, name, world, space)
{
// Setup basic node structure to handle 3rd person cameras
mSightNode = EntityBase::mMainNode->createChildSceneNode(EntityBase::mName + "_sight", Vector3(0, 0, 100));
mCameraNode = EntityBase::mMainNode->createChildSceneNode(EntityBase::mName + "_camera", Vector3(0, 50, -200));
RigidBody::setBoxPhysics(0.5, Vector3(10.0f, 10.0f, 10.0f));
RigidBody::mGeometry->setUserObject(static_cast<CollisionBase*>(this));
}inline void setBoxPhysics(const Ogre::Real mass, const Ogre::Vector3& size)
{
mOdeNode->setScale(size.x * 0.1, size.y * 0.1, size.z * 0.1);
OgreOde::BoxMass boxMass(mass, size);
mGeometry = (OgreOde::Geometry*)new OgreOde::BoxGeometry(size, mWorld, mSpace);
mBody->setMass(boxMass);
mGeometry->setBody(mBody);
mOdeNode->attachObject(mBody);
} Dummy(Ogre::Entity* entity, const Ogre::String& name, OgreOde::World* world, OgreOde::Space* space) : EntityBase(entity, name, world, space)
{
RigidBody::mGeometry = (OgreOde::Geometry*)new OgreOde::BoxGeometry(Ogre::Vector3(10.0f, 10.0f, 10.0f), mWorld, mSpace);
RigidBody::mGeometry->setUserObject(static_cast<CollisionBase*>(this));
mEntity->setUserObject(RigidBody::mGeometry);
}