Question about transformations

Started by
1 comment, last by Niddles 14 years, 10 months ago
Alright, I have an openGL scene set up, in very much the same way a blender modeling window would look like. The camera is at a set position, and you can rotate the world around by holding down the right mouse button and moving the mouse. In the same way, I want to be able to click on an object, and move it accordingly. I want it to move in 1 to 1 proportion with the mouse, no matter what way the world is rotated. Seems easy enough, until the maths come up. The way I figured you would do it is multiply the vector with the mouse coordinates by the x, y, and z world rotation matrices, and then translate the objects using the vector that comes out of that. Is this the correct way to do this? It seems like it works sometimes, but then other times it seems like the coordinates get reflected, so I move the mouse left and the object goes right, Or up/down. Please show me the way in how to do this. Also: If I have a perspective projection will this effect it? Thanks for any help.
Advertisement
Do you know how to do mouse/ray picking? What I would do is that when you grab on the object, I'd compute the mouse ray in world coordinates and find the distance and point A at which the ray hits the object. Then, when dragging the mouse around, I would compute a new mouse ray each frame and find the point B along that ray that is at the same distance at which the first pick occurred. Then I'd translate the object so that A now is moved to coincide with B.

Another way to think of this is that when you press the mouse button down the first time on the object, you compute the hit point P and the mouse ray R and form a plane that is orthogonal to the mouse ray R and so that the point P lies on that plane. Then you translate the object along that plane only according to the mouse drag events.

I've no idea if this is what commercial DCC packages do, but I would assume it is something very similar.
Yeah, I am using mouse picking, and have fixed it so hopefully it will continue to work correctly now. The ray casting however, I am not doing. I am actually not so sure on how to do... I guess I will look that up.

This topic is closed to new replies.

Advertisement