Move node to given screen coords, same distance to cam.

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
cederron
Posts: 53
Joined: Thu Jul 13, 2006 11:35 pm

Move node to given screen coords, same distance to cam.

Post by cederron »

Hello all,
I want to move a node specyfing screen x, y coordinates, the dificult thing, for me, is that it has to conservate the distance to the camera.

I have tried a few variations of the following code, without succes:

Code: Select all

	line3d<f32> line = pDevice->getSceneManager()->getSceneCollisionManager()->
		getRayFromScreenCoordinates(position2d<s32>(ScreenX, ScreenY));
	vector3df lineStartPos = line.start;
	vector3df camPos = pDevice->getSceneManager()->getActiveCamera()->getPosition();
	vector3df nodePos = pNode->getPosition();
	vector3df nodeDist = nodePos - camPos;
	vector3df lineVec = line.getVector().normalize();
	vector3df sumVec = nodeDist*lineVec;
	vector3df destPos = lineStartPos + sumVec;
	pNode->setPosition(destPos);

I'm really bad at math so any help is apreciated, thank you.
raven_coda
Posts: 89
Joined: Thu Aug 17, 2006 8:11 pm
Location: Salt Lake City, UT, USA
Contact:

Post by raven_coda »

Try this

Code: Select all

line3df line = pDevice->getSceneManager()->getSceneCollisionManager()->
	getRayFromScreenCoordinates(position2d<s32>(ScreenX, ScreenY)); 
	vector3df camPos = pDevice->getSceneManager()->getActiveCamera()->getPosition(); 
    vector3df nodePos = pNode->getPosition(); 
    vector3df nodeDist = nodePos - camPos; 
    vector3df destPos=line.getVector();
    destPos.normalize();
    destPos*=nodeDist.getLength();
	pNode->setPosition(destPos+camPos); 
Definition of an Upgrade: Take old bugs out, put new ones in.
cederron
Posts: 53
Joined: Thu Jul 13, 2006 11:35 pm

Post by cederron »

raven_coda wrote:Try this

It Works! Amazing man, thank you!
Post Reply