Selection and Manipulation with mouse

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
General

Selection and Manipulation with mouse

Post by General »

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 ...
Guest

Post by Guest »

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.
Boogle
Posts: 162
Joined: Fri Nov 21, 2003 3:16 pm
Location: Toronto, Canada

Post by Boogle »

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);
wornaki
Posts: 54
Joined: Sat Aug 23, 2003 1:18 am
Location: Argentina, South America

Post by wornaki »

dumb I, anyway, would someone mind doing a how-to or tutorial about this? It seems pretty though for me, but from your answers everybody would say you have it clear.
Post Reply