Jump to content


mouse point and vertext buffer intersection


5 replies to this topic

#1 f1engineer

    New Member

  • Members
  • PipPip
  • 18 posts

Posted 31 July 2007 - 03:16 PM

Dear Sirs
How can I create functionality to determine is the mouse point is included in vertex buffer? Vertex buffers are rendered and I need after selecting one of them to know who is selected.

Sincerely Yours
Kamen

#2 Reedbeta

    DevMaster Staff

  • Administrators
  • 4782 posts
  • LocationBellevue, WA

Posted 31 July 2007 - 04:09 PM

The usual way to do this is construct a ray from the eye through the screen at the mouse pointer location and intersect it with your geometry using standard raytracing techniques.
reedbeta.com - developer blog, OpenGL demos, and other projects

#3 AndyDX

    New Member

  • Members
  • Pip
  • 7 posts

Posted 31 July 2007 - 04:25 PM

what you mean with mousepoint included ?
do you want to test if a mouse is over your 3d object that you stored in vertex buffers ?
do you want to have triangle intersection test ?
or just simply boundind boxes test for the 3d objects ?

first of all if your objects are stored in a static vertex buffer than it is better to have a copy of the 3d object or its boundind box in sytsem mem for testing.
locking a vertex buffer for testing if a mouse is over it is not a good idea.

a good idea is first to test if the bounding box of an object intersects with the mouse and than if you need test each triangle of the object for an intersection.

i cant give you any code because iam not sure what kind of intersections you need or how your data ist stored in the vertex buffers.

Andy

#4 f1engineer

    New Member

  • Members
  • PipPip
  • 18 posts

Posted 01 August 2007 - 06:24 AM

Thanks for the answers.
I want to test is the mouse selection point is in the vertex buffer (if it is possible to be done by triangles in vertex buffer - no problem).

I have vertex buffers created by model of my software and I use these vertex buffets to create scene. When I press left mouse button I want to determine which of these vertex buffers is selected. In this case I am able to determine which object of the model is selected.
I use the algorithm with ray i many other cases in the software but in this case with vertex buffers it is very difficult to be implemented.

One variant is to create mesh from model and use this mesh as parameter to D3DXIntersect(....);
But this variant make implementation more complex therefor I looking for variant that I can use vertex buffers.
Thank You

#5 AndyDX

    New Member

  • Members
  • Pip
  • 7 posts

Posted 01 August 2007 - 11:57 AM

if you want to test your vertex buffers if they intersect with the mouse i would do like this:
when you create a vertex buffer for a modell just have a copy in system mem. from the created vertex buffer.
you just need the vectors of the models. dont store informations like color, uv etc in system mem.
if you work with indices triangle save the indices to.
for simply testing create a bounding box of the stored data in system memory of the modell.
for creating a bounding box of your model you can use D3DXComputeBoundingBox function.

let say you have stored a copy of you modell in system mem with a simply vector array you can do like this.


D3DXComputeBoundingBox(&pMyObject[0], 

dwNumVerticesMyObject, sizeof(D3DXVECTOR3), 

&pMin, &pMax );


pMyObject: this is a copy of your modell that holds the vectors of your modell.
dwNumVerticesMyObject: number of vertices/vectors of you modell.
dwStride: sizeof(D3DXVECTOR3) : number of bytes for each vertices / vector used.
pMin - pMax: pointer to D3DXVECTOR3 objects that holds the min and max values of the bounding box.

now you can use the function D3DXBoxBoundProbe for intersection.

if there is an intersection next step is to use the function D3DXIntersectTri
for triangle test.

with this method you dont need any vertex buffers locks.
if you transform your modells / vertex buffers dont forget to transform the bounding box too.

this is just a simply untested example. but this should lead you in the right direction.

Andy

#6 f1engineer

    New Member

  • Members
  • PipPip
  • 18 posts

Posted 01 August 2007 - 01:16 PM

OK super.
Thank You a lot. I shall try it.
This is my favorite forum.

Kamen





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users