PDA

View Full Version : 3D Mouse Drag



bobGL
11-18-2008, 02:43 AM
Hi!,

Im creating a small 3D editor, and Im trying to reproduce the same behavior like in Blender to drag, rotate, scale the object my rendering code of the axis and picking is all done... I check the Blender source but I don't understand what they are doing :(
and Im having a hard time coding a smooth translation etc...

Does anyone have some source code, or can redirect me to some examples / resources that can help me to understand the math behind theses operations (from 2D to 3D etc...)

Tks in advance,

Steven Katic
11-27-2008, 11:00 AM
I don't know exactly what's in the blender source but:

There is an XNA sample here:

http://www.ziggyware.com/readarticle.php?article_id=189

that should help (It can also be simplfied/made more efficient e.g. you can obtain a robust translation along a single axis still using the ray-plane

intersection test and do 2d to 3d projection once as the mouse moves instead of twice as in that sample).

There is also a bit of info here (re: translations):

http://www.gamedev.net/community/forums/topic.asp?topic_id=507797

That can also be simplified/made more efficient.
Basically ray-plane intersection testing is powerful and efficient for translations ( and a type of quaternion based virtual trackball, with constraints,

for object rotations).

e.g. briefly translations can be handled simply by
(1) encapsulating a ray and virtual axes aligned plane into a 'translationcontroller' class. Then

(2) In 'MoveObject mode' initialize the controller by
(a) Using the 3d point you 'picked on the object' to help define the virtual plane
(b) orienting the (axes aligned) virtual plane based on the user's translation constraint (i.e. set the normal that defines the virtual plane).
(c) perform the (mouse)ray-(virtual)plane intersection test as the mouse moves to incrementally generate the displacement vector
used to translate the object(e.g. where a frame may take 1.67 ms to render [approx 60fps] and vary, the intersection test can take 0.06 ms ).

Depending on your requirements(i.e. camera/viewing plane has say 6DOF) you may have to handle the special case where the viewing plane is orthogonal to the 'plane of translation constraint' (presumably selected by the user). The ray-plane intersection test will fail in this case(e.g. when viewing from say the front viewpoint and translating in the XY plane you would still want the mouse to move the object along the x axis-yeah?). All you need to do is check to see if the viewing plane is in (one of these 12) special case states and orientate the virtual plane appropriately (on initialization) to ensure (ray-plane intersection does not fail and) you get the behaviour you expect(You can check your camera's state [if you have one] or at most 3 elements in the opengl modelview matrix for the state of the viewing plane in these special cases)

You never know... these things might help make sense of the blender source for you?.

The widgets(triads, skitters, manipulators,gizmos,rings and whatever) you see in the well known modelling packages help too! But thats' a different story (searching on terms like direct manipulation, 2d ui 3d interaction/interactive, 'Robust mapping of 2D cursor motion onto 3D lines and planes' and 3d widgets should provide more info).

There may be many ways to skin a cat, but I imagine this cat gets skinned in a very similar fashion in '3d interactive tool land'.

hopefully this info should give you some ideas to start.