advancer_zjg
02-06-2008 13:56:32
hi~~
i have one question about camera and collision?
how i can implemet the camera with collison.
thank you very much.
scanmaster_k
02-06-2008 18:48:19
Hi, to begin with you attach a body to a node wich also hold your camera.
Good luck
// Scanmaster_K
advancer_zjg
04-06-2008 05:36:27
can you post some code for me?
i am a newbie
thank you very much
nord666
14-06-2008 05:33:12
So, here a bit of code to have a camera that can use collision detection:
//Creating the camera and the viewport. You should declare "cam" and "vp" somewhere else
Ogre::Camera * cam = mSceneMgr->createCamera("PlayerCam");
Ogre::Viewport * vp = mRoot->getAutoCreatedWindow()->addViewport(cam);
vp->setBackgroundColour(Ogre::ColourValue(1, 1, 1));
cam->setAspectRatio(Ogre::Real(vp->getActualWidth()) / Ogre::Real(vp->getActualHeight()));
cam->setNearClipDistance(5);
//Adding a body for collision
Ogre::Vector3 size(0.1, 0.1, 0.1); //I think that will be enough small
OgreNewt::Collision * col = new OgreNewt::CollisionPrimitives::Box(mWorld, size);
body = new OgreNewt::Body(mWorld, col);
body->attachToNode(camNode);
delete col;
Ogre::Real mass = 1.0; //I think the weight is okay
Ogre::Vector3 inertia = OgreNewt::MomentOfInertia::CalcBoxSolid(mass, size);
body->setMassMatrix(mass, inertia);
body->setAutoFreeze(0); //To be able to move the body without calling ->unFreeze()
But now, you can't move the camera by simply moving the SceneNode. You must use Callback function:
body->setCustomForceAndTorqueCallback(camCallback);
Here is the Callback fonction declaration:
void camCallback(OgreNewt::Body * _body)
{
/* Some code here to move the body. Like _body->setForce(...)
}
_body can be named differently. And you should declare it before the first code part.
I hope this code will work correctly or even compile
If you have any other question just ask!
Have a good day!
advancer_zjg
14-06-2008 13:09:25
thank you nord666 very much
i'll try this code .
-------------------------------------------------------------------------
i implemented with the ray.but i wish i can do with ogrenewt.
thank you nord666 again~~~