I could use some help with this little issue here... The problem I'm facing is the following :
fake a 2d movement ( on the screen ) of a 3d node based on the cameras rotation. e.g. camera looks down e.g. vec3df(0,-1,0) I click on my node and translate it towards the top/bottom of the screen, I want the node to stay at the same distance from the camera than it had originally
this means, the nodes movement should be restricted to x and z axis, which in this case is really easy.. but I want to be able to do this for every camera rotation not just "orthogonal" views.. So I thought of the following...
1. get the vec3df position of the node ( thing thats going to be moved )
2. get a ray from the camera through the destination screen coordinate ( using getRayFromScreenCoordinates(destination position, camera)
3. now get the closest position to the node position on the ray with getClosestPoint(nodePosition)
The closest position SHOULD be a straight line from the original node position, so that the distance to the camera stays the same...
This method works ok for "orthogonal" views, but as soon as the camera has a little bit of rotation the node gets closer and closer ( with every movement ) or further away (depending on the camera rotation ) .. So this method is not really "good" .
What I am trying now is the following
1. get position of the node ( vec3df )
2. build plane plane3df iPlane(nodePos,camera->getTarget())
3. get ray through screen coordinates ray = getRayFromScreenCoordinates(mouseReleasePosition,camera)
4. iPlane.getIntersectionWithLimitedLine(ray.start,ray.end,iPoint)
5. iPoint should be the new position of the node...
When I move the node towards the center of the screen it goes further away, when I move the node towards the side of the screen it comes closer..
Actually the first method worked better and thats strange because, thinking in a math way the second method should be absolutely failsafe
Thank you
Kind regards
TekniX




