I want to be able to select a mesh with throught the screencoods and the be able to move it. I realise I can do this though the getScreneNodeFromScreenCoods() method, but the manipulation is more difficult.
I am presented with the following problem though. What I did do is calculate the difference of the old mouse pos to the new mouse pos, and then add it to the ScreenNode.X and ScreenNode.Y positions. This does move it perfectly when I am looking at the node from the right camera angle. But obviously when I change the camera angle (let's say camera looks at object directly from opposite side), moving my mouse to the left, now means object moves to the right (when it should move to the left).
Obviously it is a simple mathematical problem (would have to take camera position and view in consideration)
Anyone with any suggestions for this math problem ...
Selection and Manipulation with mouse
This is not Irrlicht-specific, as I am new, but:
assuming Camera { vect3d up, right, pos; }
When you get the mouse coords, you figure out where that is on the plane denoted by Camera.up and Camera.right (this requires figuring out the relationship between your resolution, and your FOV).
this gives you Camera-local coordinates (still in 2D). Create a new vector from (x*Camera.right, y*Camera.up, 0), to get Camera-local coordinates (in 3D).
Now add that vector to your Camera.pos vector to get Global coordinates of the mouse click. Extend the ray forward according to the Camera.forward*1000.0 code as in the Collision-Detection demo.
assuming Camera { vect3d up, right, pos; }
When you get the mouse coords, you figure out where that is on the plane denoted by Camera.up and Camera.right (this requires figuring out the relationship between your resolution, and your FOV).
this gives you Camera-local coordinates (still in 2D). Create a new vector from (x*Camera.right, y*Camera.up, 0), to get Camera-local coordinates (in 3D).
Now add that vector to your Camera.pos vector to get Global coordinates of the mouse click. Extend the ray forward according to the Camera.forward*1000.0 code as in the Collision-Detection demo.
If you would like it to always move perpendicular to the current camera view, I would use:
vector3df movement(0,0,0);
movement += upVector*(mouseY*speed);
movement += rightVector*(mouseX*speed);
ScreenNode.setPosition(ScreenNode.getPosition()+movement);
This means if you are looking at it 90 degrees to the angle you started you will move it along the z axis rather then the x-axis, etc.
Also note that irrlicht cameras cannot give you a right vector, so you will have to create it yourself using something like:
vector3df targetVector = camera.getTarget()-camera.getPosition();
vector3df upVector = camera.getUpVector();
vector3df rightVector = targetVector.crossProduct(upVector);
vector3df movement(0,0,0);
movement += upVector*(mouseY*speed);
movement += rightVector*(mouseX*speed);
ScreenNode.setPosition(ScreenNode.getPosition()+movement);
This means if you are looking at it 90 degrees to the angle you started you will move it along the z axis rather then the x-axis, etc.
Also note that irrlicht cameras cannot give you a right vector, so you will have to create it yourself using something like:
vector3df targetVector = camera.getTarget()-camera.getPosition();
vector3df upVector = camera.getUpVector();
vector3df rightVector = targetVector.crossProduct(upVector);