Pick 
Author Message
 Pick

How can I use a 2D rectangle to do a pick in a 3D World.

Example - Scattergraph demo in SDK
When the mouse is over a sphere the program uses the
intersect fucntion to determine the intersect between a
mesh and a ray from the mouse/user's point of view.

How do you do that with an area instead of a single point.

The idea is for the user to draw a 2D rectangle
and "select" everithing within that rectangle, in the 3D
world.

I have code to do that in OpenGL, but I don't now how to
do that in DX.



Tue, 30 Nov 2004 03:00:00 GMT  
 Pick



Quote:
> I have code to do that in OpenGL, but I don't now how to
> do that in DX.

sorry i cant  help you with dx.. but :) cna you explain me how you perform
that in opengL?

usually i use gluPickMatrix.. but i would like to use the ray/instersaction
way...
how do you get the mouse coordinates in 3d ?

thanks

Davide



Tue, 30 Nov 2004 16:44:28 GMT  
 Pick
It should be very simular to view frustum testing.

The 2D rectangle defines a volume. You can then test rendered objects or
groups to see if their bounding volume is outside this volume. If not
outside you may want to conduct further testing for more precise results (in
case the bouding volume would be partially inside this volume but not the
actual object).

Before using a more analytical way to do things, using ProcessVertices and
ClipStatus should allow to implement a first version of these principles
quite easily.

For DX9, I'm working on a series that should illustrate most of these
principles with simplicity in mind. I'll probably add this 2D selection
stuff...

Patrice



Quote:
> How can I use a 2D rectangle to do a pick in a 3D World.

> Example - Scattergraph demo in SDK
> When the mouse is over a sphere the program uses the
> intersect fucntion to determine the intersect between a
> mesh and a ray from the mouse/user's point of view.

> How do you do that with an area instead of a single point.

> The idea is for the user to draw a 2D rectangle
> and "select" everithing within that rectangle, in the 3D
> world.

> I have code to do that in OpenGL, but I don't now how to
> do that in DX.



Tue, 30 Nov 2004 17:10:08 GMT  
 Pick
At second sight, I'm not sure what is taken into account when using
ProcessVertices. Changing the viewport may be enough but in the worst case
you would have to change the projection matrix.

Patrice



Quote:
> It should be very simular to view frustum testing.

> The 2D rectangle defines a volume. You can then test rendered objects or
> groups to see if their bounding volume is outside this volume. If not
> outside you may want to conduct further testing for more precise results
(in
> case the bouding volume would be partially inside this volume but not the
> actual object).

> Before using a more analytical way to do things, using ProcessVertices and
> ClipStatus should allow to implement a first version of these principles
> quite easily.

> For DX9, I'm working on a series that should illustrate most of these
> principles with simplicity in mind. I'll probably add this 2D selection
> stuff...

> Patrice



> > How can I use a 2D rectangle to do a pick in a 3D World.

> > Example - Scattergraph demo in SDK
> > When the mouse is over a sphere the program uses the
> > intersect fucntion to determine the intersect between a
> > mesh and a ray from the mouse/user's point of view.

> > How do you do that with an area instead of a single point.

> > The idea is for the user to draw a 2D rectangle
> > and "select" everithing within that rectangle, in the 3D
> > world.

> > I have code to do that in OpenGL, but I don't now how to
> > do that in DX.



Tue, 30 Nov 2004 17:21:28 GMT  
 Pick
At third sight changing the viewport won't work of course as it will just
shrink the whole scene !!!

I gave this a try and it seems something like this would work :
- unproject x,y,1
- unproject x,y,0
- unproject x,y+height,1

It gives 3 points that are defining the left clip plane.

Use Device.SetClipPlane to define this user clip plane and enable it using
the appropriate rendertstate (D3DRS_CLIPPLANEENABLE).

Use ProcessVertices on the bouding volume and read the ClipStatus to know if
all or at least one vertex is clipped by this plane.

Of course do this at once for all planes (this was just for a quick test).

You can always optimize later if possible with a mathematical method but it
should allow to have quickly a first implementation to start with....

Patrice



Quote:
> At second sight, I'm not sure what is taken into account when using
> ProcessVertices. Changing the viewport may be enough but in the worst case
> you would have to change the projection matrix.

> Patrice



> > It should be very simular to view frustum testing.

> > The 2D rectangle defines a volume. You can then test rendered objects or
> > groups to see if their bounding volume is outside this volume. If not
> > outside you may want to conduct further testing for more precise results
> (in
> > case the bouding volume would be partially inside this volume but not
the
> > actual object).

> > Before using a more analytical way to do things, using ProcessVertices
and
> > ClipStatus should allow to implement a first version of these principles
> > quite easily.

> > For DX9, I'm working on a series that should illustrate most of these
> > principles with simplicity in mind. I'll probably add this 2D selection
> > stuff...

> > Patrice



> > > How can I use a 2D rectangle to do a pick in a 3D World.

> > > Example - Scattergraph demo in SDK
> > > When the mouse is over a sphere the program uses the
> > > intersect fucntion to determine the intersect between a
> > > mesh and a ray from the mouse/user's point of view.

> > > How do you do that with an area instead of a single point.

> > > The idea is for the user to draw a 2D rectangle
> > > and "select" everithing within that rectangle, in the 3D
> > > world.

> > > I have code to do that in OpenGL, but I don't now how to
> > > do that in DX.



Tue, 30 Nov 2004 23:59:00 GMT  
 Pick
I think i mislead you. I have the code to do that usign
OpenGL - That meaning a 2D box selection....

I think I use the same method as you here is the code (or
part of it) ...

Private Sub DoPickFrustumDrag()
Dim w#, h#, CX#, cy#
Dim viewport&(0 To 3)

    glGetIntegerv GL_VIEWPORT, viewport(0)

    'get the rect center
    w = Abs(m_EndDragX - m_StartDragX)
    h = Abs(m_EndDragY - m_StartDragY)

    If m_EndDragX > m_StartDragX Then
        CX = m_EndDragX - w \ 2
    Else
        CX = m_StartDragX - w \ 2
    End If
    If m_EndDragY > m_StartDragY Then
        cy = m_EndDragY - h \ 2
    Else
        cy = m_StartDragY - h \ 2
    End If
    ' set up a pick region by modifying the projection
    CheckError
    glMatrixMode GL_PROJECTION
    glPushMatrix
    ' use mouse position in window & pick region size
    ' there are other approaches including gluPickMatrix
    glLoadIdentity
    CheckError
    'glFrustum xpick, xpick2, ypick, ypick2, 1, 1000
    gluPickMatrix CX, m_Height - cy, w, h, viewport(0)
    gluPerspective 30, m_Width / m_Height, 1, 1000
    glMatrixMode GL_MODELVIEW
End Sub

Hope this helps!!!

Quote:
>-----Original Message-----


messaggio

>> I have code to do that in OpenGL, but I don't now how to
>> do that in DX.

>sorry i cant  help you with dx.. but :) cna you explain
me how you perform
>that in opengL?

>usually i use gluPickMatrix.. but i would like to use the
ray/instersaction
>way...
>how do you get the mouse coordinates in 3d ?

>thanks

>Davide

>.



Thu, 02 Dec 2004 23:54:21 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. Pick Items like Pick Folders?

2. This is PICK (and Pick like)

3. Pick-a-month combo box?

4. Outlook GAL - Pick/Return email address

5. Utility to pick pictures into Access database and save its as file

6. Windows Explorer-like Mutiple picks in Access 97?

7. That darn calendar control, and dynamic pick lists

8. Macro for picking up stationary

9. Picking up when an e-mail is moved.

10. Pick from the list

11. Need Help: Trouble adding a custom menu pick to a custom popup menu in VBA

12. Dialog to Pick Harddrive Folder for Save

 

 
Powered by phpBB® Forum Software