abhinavxrai
21-03-2006 11:34:19
In the Ogre demos, there is a demo called Terrain. The code implemented in that demo for the camera to stick to the terrain is quite simple.
Now, I want to do exactly the same with more precision using RayCast method in OgreNewt
The major difference is that now my terrain is not a cfg file but a mesh file. How can this be achieved.
I have written the following code, but it doesn't seem to work. Any suggestions would be awesome!
This code doesnt work as required! Any suggestions where I am going wrong or any implementation error. I think there might be a problem with local and global points, etc.
Thanks for your help!
static Ray updateRay;
updateRay.setOrigin(mMainNode->getPosition());
updateRay.setDirection(Vector3::NEGATIVE_UNIT_Y);
raySceneQuery->setRay(updateRay);
RaySceneQueryResult& qryResult = raySceneQuery->execute();
RaySceneQueryResult::iterator i = qryResult.begin();
if (i != qryResult.end() && i->movable)
{
SceneQuery::WorldFragment* wf = i->worldFragment;
mCamera->setPosition(mCamera->getPosition().x, i->worldFragment->singleIntersection.y+10, mCamera->getPosition().z);
}
Now, I want to do exactly the same with more precision using RayCast method in OgreNewt
The major difference is that now my terrain is not a cfg file but a mesh file. How can this be achieved.
I have written the following code, but it doesn't seem to work. Any suggestions would be awesome!
Ogre::Vector3 start = mCamera->getPosition();
Ogre::Vector3 end = mCamera->getPosition() + (100 * Ogre::Vector3::NEGATIVE_UNIT_Y);
OgreNewt::BasicRaycast* ray = new OgreNewt::BasicRaycast(m_World, start, end);
OgreNewt::BasicRaycast::BasicRaycastInfo info = ray->getFirstHit();
Ogre::Vector3 point = start + ( (end-start) * info.mDistance);
if(info.mDistance != 0.015)
{
mCamera->setPosition(point.x, point.y+10, point.z)
mWindow->setDebugText("Something seems to be working");
}
This code doesnt work as required! Any suggestions where I am going wrong or any implementation error. I think there might be a problem with local and global points, etc.
Thanks for your help!