A problem of getting XZ coordinates

Anything and everything that's related to OGRE or the wider graphics field that doesn't fit into the other forums.
yoyotvyoo
Gnoblar
Posts: 3
Joined: Fri Feb 19, 2016 11:37 am

A problem of getting XZ coordinates

Post by yoyotvyoo »

Hello,

I am trying the code in this tutorial http://www.ogre3d.org/tikiwiki/Get+XZ+coordinates and here is my code.

Code: Select all

MeshManager::getSingleton().createPlane(
		"ground", ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, 
		mPlane, 
		1500, 1500,
		20, 20,
		true,
		1,
		5, 5,
		Vector3::UNIT_Z
		);
Entity *planeEntity= mSceneMgr->createEntity("Ground", "ground"); 
mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(planeEntity); 

Code: Select all

mCamera = mSceneMgr->createCamera("Camera");
mCamera->setPosition(Ogre::Vector3(0, 700, 800));
mCamera->lookAt(Ogre::Vector3(0, 0, 0));
mCamera->setNearClipDistance(5);

Code: Select all

Ray mRay = mTrayMgr->getCursorRay(mCamera);
std::pair<bool, Real> result = mRay.intersects(mPlane);
 
	if (result.first)
	{
		Vector3 point= mRay.getPoint(result.second);
	}
The problem is that when I click out of the plane, I can still get the intersection result. It means 'result.first' returns true. One of my guess is that the plane is only rendered partly, so the cursor ray can intersect the plane even if we cannot see the plane there. But I am not too sure about this guess. How should I understand this code? Thanks.