Moving object with mouse

i’m newbie in 3D graphics…i’m programming application for showing medical data in WebGL. Everything works fine, but i would like to implement moving object with mouse (concrete moving with concrete object in x,y,z axis).
My idea is:
I have succesfully calculated the normal of cut (with i want moving). Then i calculate vector of clicked position and my current(mouse move) position (this is vector of new direction). Then i’m trying to calculate angle between normal and vector direction and get the real distance to move.

But it’s not working. It seems to be good, but it reacts after about 1cm of dragging…(then it reacts good). But i need immediately reaction.

I might calculate direction vector wrong, because i’m not sure, how can i get point in 3D space. Point on object(where i catch object) is obvious. I’m using framework O3D, but i haven’t found any amthod to moving object. I would like to write it in webgl. In O3D is function to pick object and get the position of click in object.

Is my method ok?Help please.

Thank you.
Tomáš Sychra

How about don’t move, just position the object in your desired new position. The new position can be calculated by get the intersecting point of the moving line and mouse pick ray.

theres heaps of ways

find vector that the cursor passes through
var worldS = camera.From_window_to_world_space( [mousePosX,mousePosY,0] );
var worldE = camera.From_window_to_world_space( [mousePosX,mousePosY,1] );
var LS = LINESEGMENT( worldS, worldE );

now u need to find where on this linesegment you want to position the object,
heres one method, though most likely u would want to construct a plane perpindicular to the viewfrustum

var plane = PLANE( [0,0,1], 0, [0,0,0] ); // plane is constructed from normal,distance + point
cursorposWS = return_intersection_point_of_PLANE_LINESEGMENT( plane, LS );

read the pixels z value under the cursor (do this before u draw the object)

  • then do an unproject with winx,winy + that pixelsZ … ct.3G.html

i haven’t solved my problem yet.
I have made some progress, but it’s still not OK. When i click, i get intersection point of mouse and object in 3D. Then i calculate normal of cut, which i collapse to screen. So i get two vectors
Normal of cut and mouse vector on screen. Then i calculate scalar product (dot) of these vectors and it should be a direction, where should i move cut. Cut is moving to right direction, but it all depend on zoom of scene. If zoom is 1 everthing is ok…but, if it’s another, the cuts are moving to quick or too slow…(mouse is quickier or slower)…I think, it can be resolved by converting ratio between screen distance and scene distance…but i dont’t know how…
I’m attaching screenshot of my app in hope to help you with understanding to my problem.
Thanks a lot.