ColDetection only; Collision Shapes [SOLVED]

Toudinho

16-05-2008 22:03:11

Hi @ all,

i have a question about using OgreNewt only for collision detection. For this, i have to create collision shapes and check collisions between them.
Just tell me if im wrong with it!!!!!

I dont understand how this is working. I create the shape with an initial position and never change it again, so how can i check collsisions??
Or do i have to recreate it every time i want to check a collision???

micken

01-06-2008 05:30:44

OgreNewt checks collisions in it's world->update function. In OgreNewt you use these collision shapes to define the representation of your objects in the newton physical world. So you pretty much have to use the physics in order for the collision to work properly.

That's just how I see it though and I'm still relatively new to ogrenewt.

Vectrex

01-06-2008 06:16:28

There are special functions for just collision detection. They're in the CollisionTools bit of ogrenewt

Toudinho

09-06-2008 23:46:01

@ micken:
I want to use just the collisionTools without the physics.


In my Scene there are two characters. The first can move through the whole Scene, while the other is just standing (for testing).

My code so far:



//Get Size for the collisionshape
Ogre::Vector3 size = mWarrior2->getEntity()->getBoundingBox().getSize();

//Create the two collision shapes
mStickBodyShape2 = new OgreNewt::CollisionPrimitives::Box(mWorld, size,
mWarrior2->getNode()->getOrientation(),
mWarrior2->getNode()->getPosition());
mStickBodyShape1 = new OgreNewt::CollisionPrimitives::Box(mWorld, size,
mWarrior1->getNode()->getOrientation(),
mWarrior1->getNode()->getPosition());


Ogre::Vector3 norm = Ogre::Vector3::ZERO;
int id = -1;

//Perform raycast from moving character to the static one
//Works fine!!!!!
Ogre::Real rayHit = OgreNewt::CollisionTools::CollisionRayCast(
mStickBodyShape2,
mWarrior1->getNode()->getPosition(),
mWarrior1->getNode()->getPosition() + (mWarrior1->getNode()->getOrientation().yAxis() * 20),
norm,
id);

if(rayHit <= 1)
{
Ogre::Vector3 contPts;
Ogre::Vector3 normals2;
Ogre::Real penet;
int coll = -1;

//check for collision between the two chars
coll = OgreNewt::CollisionTools::CollisionCollide(
mWorld, 1,
mStickBodyShape2,
mWarrior2->getNode()->getOrientation(),
mWarrior2->getNode()->getPosition(),
mStickBodyShape1,
mWarrior1->getNode()->getOrientation(),
mWarrior1->getNode()->getPosition(),
&contPts,
&normals2,
&penet);

int bubu = 0;

if(coll > 0)
{
mWarrior1->getNode()->setPosition(mWarrior1->getNode()->getPosition());
}
}




Well, the raycast from the moving char to the static one works fine.
But collsision is never detected.
It seems that the change of position and orientation of the moving char is never updated.
Am I missing something????
Do I HAVE to create bodies and move the bodies around, even without using the physics????

Toudinho

12-06-2008 15:15:33

Ok, i solved it.

Seems like i only have to define the position and orientation once.
Either when I create the CollisionShape or when I call CollisionCollide().
But defining it twice doesnt work.

Maybe Wallaber knows why.

Greets @ all