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.