ray-trouble

Problems building or running the engine, queries about how to use features etc.
Post Reply
avatarbe
Gnoblar
Posts: 18
Joined: Wed Feb 23, 2005 5:57 pm

ray-trouble

Post by avatarbe »

i got some trouble with raySceneQuery.
i got some this as 'ground':

Code: Select all

mSceneMgr->setWorldGeometry("terrain.cfg");
i have now a unit mUnit, and i want him to clamp to the ground. this is he code i used for that (it is the code from the terrain sample, i just substituted the mCamera with my mUnit).
Problem: my unit just stays at 100 height.

Code: Select all

RaySceneQuery* raySceneQuery = mSceneMgr->createRayQuery(Ray(mCamera->getPosition(), Vector3::NEGATIVE_UNIT_Y));
	mUnit = new c3DObject(0.0f, 500,100,500);

        static Ray updateRay;
	updateRay.setOrigin(mUnit->getPosition());
	updateRay.setDirection(Vector3::NEGATIVE_UNIT_Y);
	raySceneQuery->setRay(updateRay);
	RaySceneQueryResult& qryResult = raySceneQuery->execute();
	RaySceneQueryResult::iterator i = qryResult.begin();


	if (i != qryResult.end() && i->worldFragment)
	{
		SceneQuery::WorldFragment* wf = i->worldFragment;
		//mUnit->setPosition(mUnit->getPosition().x+, i->worldFragment->singleIntersection.y + 10, mUnit->getPosition().z);
	}
	else
	{
		cGame::_visualEngine->debugTextToLog("Fail");
	}
	mUnit->draw();
can someone help plz? :)

thx
Avi
User avatar
tuan kuranes
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 2653
Joined: Wed Sep 24, 2003 8:07 am
Location: Haute Garonne, France
x 4
Contact:

Post by tuan kuranes »

easy ;)
remove the comment before mUnit->setposition ?
Mr. Turner
Halfling
Posts: 88
Joined: Sun Sep 05, 2004 7:01 pm
Location: Belgium

Post by Mr. Turner »

I don't know if the // are intentional, but you should remove them.
getPosition().x+ should be getPosition().x if it's inherited from the Ogre implantation.

Code: Select all

mUnit->setPosition(mUnit->getPosition().x, i->worldFragment->singleIntersection.y + 10, mUnit->getPosition().z);
User avatar
Wooden
Halfling
Posts: 58
Joined: Thu Feb 10, 2005 10:35 pm
Location: Arcachon, France
Contact:

Post by Wooden »

How can i get a vector for the ray direction from a quaternion? In fact i have a camera which lookAt() an objet and i want to cast a ray from this oject in the direction of the camera, i wanted to use the quaternion to set the ray direction, if it's not possible then i think i'll have to get a direction vector thanks to the position of the object and the camera's position?
User avatar
Clay
OGRE Community Helper
OGRE Community Helper
Posts: 518
Joined: Wed Mar 17, 2004 4:14 am
x 1
Contact:

Post by Clay »

I think this should be:

Code: Select all

Vector3 direction = quat * Vector3::[ORIGINAL_FACING];
Where [] is the direction the model originally faces, usually NEGATIVE_UNIT_Z. I could be completely off base though. Quaternions still give me fits.
avatarbe
Gnoblar
Posts: 18
Joined: Wed Feb 23, 2005 5:57 pm

Post by avatarbe »

ok, that // was just a copy paste mistake, i did try it without the // ;)

i found a stupid error:

Code: Select all

RaySceneQuery* raySceneQuery = mSceneMgr->createRayQuery(Ray(mCamera->getPosition(), Vector3::NEGATIVE_UNIT_Y));
should be

Code: Select all

RaySceneQuery* raySceneQuery = mSceneMgr->createRayQuery(Ray(mUnit->getPosition(), Vector3::NEGATIVE_UNIT_Y));
now my units moves along the surface, but after a few seconds it just stops following the surface :S. maybe it is just coincidence, but the unit stops folowing the suface when he has to go up. :S
User avatar
Wooden
Halfling
Posts: 58
Joined: Thu Feb 10, 2005 10:35 pm
Location: Arcachon, France
Contact:

Post by Wooden »

I must be doing something wrong with vectors...
What is the good way to manipulate the x y and z composant?
i'm using

Code: Select all

rep.x = sqrt( pow( cam.z - nod.z , 2 ) + pow( cam.x - nod.x , 2 ));
where rep nod and cam are Vector3
is it right? as i wasn't sure, i tried to cast to (double) but had no succes.
also i use

Code: Select all

cam = mCamera->getPosition();
and when i display the x and y thanks to

Code: Select all

sprintf(dbug,"cam.x= %d cam.y=%d",cam.x,cam.y);
the x and y are not the right one, (y is 0 and x is huge while i placed the camera to and other place and didnt moved it.

maybe it's a cast problem because x y and z are Real?
User avatar
tuan kuranes
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 2653
Joined: Wed Sep 24, 2003 8:07 am
Location: Haute Garonne, France
x 4
Contact:

Post by tuan kuranes »

if you're under the terrain use Vector3::UNIT_Y, not Vector3::NEGATIVE_UNIT_Y...

The trick is to set at 0 the unit height so that queries are always Vector3::UNIT_Y.

node.getSquaredViewDepth(cam); gives you distance to cam
User avatar
Wooden
Halfling
Posts: 58
Joined: Thu Feb 10, 2005 10:35 pm
Location: Arcachon, France
Contact:

Post by Wooden »

:oops: I'm stupid, i casted Real to double but Real are actually float :oops:
Post Reply