Doing mouse drag on 3d objects accurately

Doing mouse drag on 3d objects accurately

Post by v » Thu, 06 Apr 2000 04:00:00



Hi does anyone know how to make dragging of objects accurate....The problem
I'm facing is that  the object moves but it doesn't stop directly under the
mouse cursor.....Probably because an object in 3d space when mapped to 2d
screen coordinates varies  when the camera distance changes or perspective
changes.
So I like to find out if there is a way of mapping each screen X,Y into
world X,Y....

Thanks in advanced

 
 
 

Doing mouse drag on 3d objects accurately

Post by Marc Hernand » Thu, 06 Apr 2000 04:00:00


: Hi does anyone know how to make dragging of objects accurate....The problem
: I'm facing is that  the object moves but it doesn't stop directly under the
: mouse cursor.....Probably because an object in 3d space when mapped to 2d
: screen coordinates varies  when the camera distance changes or perspective
: changes.
: So I like to find out if there is a way of mapping each screen X,Y into
: world X,Y....

        The mouse forms a ray between your eye and the world.  Calculate
where this ray intersects some plane in your world and place your object
there.

Marc Hernandez

 
 
 

Doing mouse drag on 3d objects accurately

Post by Vinc » Fri, 07 Apr 2000 04:00:00


I need a couple more pointers.....I assume the middle of the screen is the
camera position....so if the cursor is at the middle i can project a ray.
But how do i project a ray when the cursor is not in the middle.

Also how do i determine which plane is most accurate to place my model
against...I guess that this plane must be pependicular at the point where
the camera ray hits it....

Thanks

Quote:> The mouse forms a ray between your eye and the world.  Calculate
> where this ray intersects some plane in your world and place your object
> there.

> Marc Hernandez

 
 
 

Doing mouse drag on 3d objects accurately

Post by Marc Hernand » Fri, 07 Apr 2000 04:00:00


: I need a couple more pointers.....I assume the middle of the screen is the
: camera position....so if the cursor is at the middle i can project a ray.
: But how do i project a ray when the cursor is not in the middle.

        The middle of the screen is actually:
Pc : camera position
La : camera vector (where the camera is pointing)
F  : front clipping plane distance

Pc+La*F

        The details of what ray the mouse<->camera pos forms is dependant
on the API you are using.  The maths are fairly simple.  Take your matrix
that take World->screen and invert it.  This matrix * your mouse point is
the point is world space.  This point - camera point is the ray vector
(you will probably want to normalize this). The camera point and this
vector form the ray.  

        With this ray you can do a lot.  Intersect with arbitrary planes
or objects (although for many objects you will probably want to put the
ray into object space).  

: Also how do i determine which plane is most accurate to place my model
: against...I guess that this plane must be pependicular at the point where
: the camera ray hits it....

        Interesting question.  I project down to the y=0 plane.  

Marc Hernandez

 
 
 

Doing mouse drag on 3d objects accurately

Post by Paul Mart » Fri, 07 Apr 2000 04:00:00



Quote:> I need a couple more pointers.....I assume the middle of the screen is the
> camera position....so if the cursor is at the middle i can project a ray.
> But how do i project a ray when the cursor is not in the middle.

If (x,y) is the device coordinate point under the cursor, then:

   GLdouble x, y, nx, ny, nz, fx, fy, fz, vecx, vecy, vecz;
   GLdouble m[16], p[16];
   GLint vp[4];

   // First, get m, p, and vp using glGet functions
      ...

   // Now compute the ray
   gluUnProject(x,y,0.,m,p,vp,&nx,&ny,&nz);
   gluUnProject(x,y,1.,m,p,vp,&fx,&fy,&fz);
   vecx=fx-nx; vecy=fy-ny; vecz=fz-nz;

(vecx,vecy,vecz) is the ray under the mouse cursor pointing away from the
viewer.

BTW, that code is off the top of my head. I wouldn't be surprised if it
doesn't compile as-is. But the concept should be right. Just unproject the
point under the cursor at the near and far planes, and compute a ray from
the unprojected values.

Quote:> Also how do i determine which plane is most accurate to place my model
> against...I guess that this plane must be pependicular at the point where
> the camera ray hits it....

This is application dependant. Any plane will work. Which plane do you want
your object to move along in response to user input? Use that plane. It
doesn't have to be perpendicular to the ray.
--

    Hewlett Packard Technical Solutions Lab
    OpenGL FAQ: http://www.frii.com/~martz/oglfaq
 
 
 

Doing mouse drag on 3d objects accurately

Post by Vincen » Sat, 08 Apr 2000 04:00:00


Alritey......a thank you note for the nice folks who helped.
Really appreciated :)

Cya

 
 
 

Doing mouse drag on 3d objects accurately

Post by V-ma » Sun, 09 Apr 2000 04:00:00


sure, you may want to keep the mapping linear. In that case, 1 unit in
window coordinate might mean 0.1 in object coordinates. You can adjust
those numbers, and even find an equation to make it non linear.

easy enough

V-man


> Hi does anyone know how to make dragging of objects accurate....The problem
> I'm facing is that  the object moves but it doesn't stop directly under the
> mouse cursor.....Probably because an object in 3d space when mapped to 2d
> screen coordinates varies  when the camera distance changes or perspective
> changes.
> So I like to find out if there is a way of mapping each screen X,Y into
> world X,Y....

> Thanks in advanced

 
 
 

1. Doing mouse drag on 3d objects accurately

Hi does anyone know how to make dragging of objects accurate....The problem
I'm facing is that  the object moves but it doesn't stop directly under the
mouse cursor.....Probably because an object in 3d space when mapped to 2d
screen coordinates varies  when the camera distance changes or perspective
changes.
So I like to find out if there is a way of mapping each screen X,Y into
world X,Y....

Thanks in advanced

2. Windows 2000 or XP?

3. Software Question

4. Unable to rotate object using click'n drag with the mouse

5. Antique effect

6. example: dragging points in 3D with mouse

7. SiMPLE'97 - DemoCompo

8. Dragging an object into a 3D scene.

9. Dragging Objects in 3D world...

10. Moving objects accurately

11. rotating 3D object with mouse

12. 3D Object should follow Mouse exact on its position HOWTO