Camera collisions

mistigrii33

04-12-2011 23:42:03

Hi,

I'm trying to implements a camera collision for a 3rd person game for it not to pass through the walls when my character is moving.
I have an AnimatedCharacter, which create a cameraNode that my camera is attached to.
Then, i try to folow these two posts http://www.ogre3d.org/addonforums/viewtopic.php?f=6&t=11126&p=63928&hilit=camera+camera+collision#p63928 and http://www.ogre3d.org/addonforums/viewtopic.php?t=7615, and create a BodyDescription, that i add my cameraNode and create a Body with that.
Unfortunately, the result isn't as expected and i'm dealing with a body (seen in the debugger) in the middle of my terrain which is not related in any way to my camera...

Why does the body i just created isn't at the same place than the camera node ? What am i missing ?

Here is my code (a quick rewrite to make it simple) (Using NxOgre 1.7) :


class MyCharacter : public AnimatedCharacter
{
public void attachCamera(Ogre::Camera* mCamera)
{
//create the cameraNode, place it just behind the character. mNode is the AnimatedCharacter node
cameraNode = mNode->createChildSceneNode();
cameraNode->setPosition(Ogre::Vector3(0, 8, -16));
cameraNode->attachObject(mCamera);

//create a critter::node to give it to the bodyDesc then it'll be related to cameraNode
Critter::Node* camNode = new Critter::Node(mSceneMgr, cameraNode, mRenderSystem);

Critter::BodyDescription bodyDesc;
bodyDesc.mMass = 1.0f;
bodyDesc.mDensity = 0.0f;
bodyDesc.mDynamicRigidbodyFlags |= NxOgre::DynamicRigidbodyFlags::FreezeRotation;
bodyDesc.mDynamicRigidbodyFlags |= NxOgre::DynamicRigidbodyFlags::DisableGravity;
bodyDesc.mNode = camNode;

NxOgre::SphereDescription sphereDesc;
sphereDesc.mRadius = 10.0;
sphereDesc.mMass = 1.0f;
sphereDesc.mDensity = 0.0f;

Critter::Body* b = mRenderSystem->createBody(sphereDesc, NxOgre::Vec3(0,1,0), "", bodyDesc);
}
}


Thanks !

mistigrii33

05-12-2011 21:33:37

Alight, after some tests i managed to get a Critter::Node moving with a Critter::body.

critterCamNode = new Critter::Node(mRenderSystem->getSceneManager(), mRenderSystem);

Critter::BodyDescription bodyDesc;
bodyDesc.mMass = 1.0f;
bodyDesc.mDensity = 0.0f;
bodyDesc.mGroup = Walls;
bodyDesc.mAngularDamping = 10;
bodyDesc.mLinearDamping = 10;
bodyDesc.mDynamicRigidbodyFlags |= NxOgre::DynamicRigidbodyFlags::FreezeRotation;
bodyDesc.mDynamicRigidbodyFlags |= NxOgre::DynamicRigidbodyFlags::DisableGravity;
bodyDesc.mNode = critterCamNode;

NxOgre::ShapeDescriptions s;

NxOgre::SphereDescription sphereDesc;
sphereDesc.mRadius = 10.0;
sphereDesc.mMass = 1.0f;
sphereDesc.mDensity = 0.0f;

s.push_back(&sphereDesc);

//sinbad as a mesh attached to the scene node, to see it
//cameraNode is a sceneNode attached to the player scene node where the camera should be
bodyCam = mRenderSystem->createBody(s, NxOgre::Vec3(cameraNode->_getDerivedPosition()), "sinbad.mesh", bodyDesc);

my body is at the good position at the beggining of my scene (the cameraNode position, which is good), but when i move it's not anymore. I would like to be able to do something like
cameraNode->addChild(critterCamNode);to make the critterCamNode follow the cameraNode, but i can't... how can i do that ?

I've also try to add force, but i didn't found anything to make the body perfectly following the cameraNode
Ogre::Vector3 v(0, 0, 1); //just a test, in my code, it's calculated with the camera orientation
bodyCam->addForce(v, NxOgre::Enums::ForceMode_Impulse, true);

Does anyone can put me in the right direction to do that ?

Thanks