Not logged in, Join Here! or Log In Below:  
 
News Articles Search    
 

 Home / 3D Theory & Graphics / intersection problem: dynamic mesh vs. vertex Account Manager
 
Archive Notice: This thread is old and no longer active. It is here for reference purposes. This thread was created on an older version of the flipcode forums, before the site closed in 2005. Please keep that in mind as you view this thread, as many of the topics and opinions may be outdated.
 
shine

April 25, 2005, 03:44 AM

Hi!

Right now I'm implementing a dynamic mesh based on spring physics. The simulation works quite fine but the following problem keeps me away from sleeping: I manipulate the mesh by moving a mouse cursor. The position of the cursor is given by a single vertex. Just before a simulation step this vertex can be "inside" the model - after applying physics it can be found outside the model caused by the shrinkage of the mesh. What I want is to find the face of the mesh that would have collided with the mouse pointer in order to reposition this face to the location of the mouse cursor.

Any ideas?!

Thanks in advance,
shine

 
PixelClear

April 25, 2005, 10:12 AM

Hi,

I don't know exactly what you mean by a vertex that is "inside" your mesh. Though you should consider casting a ray into your mesh to obtain the barycentric coordinates of your mouse cursor in the first intersected triangle. With these information you will easily be able to track back where your anchor point is gone after your physic integration step and then somehow correct the object's position.

You may find the necessary math in here :
http://tom.cs.byu.edu/~455/rt.pdf

Phil

 
shine

April 25, 2005, 06:04 PM

Hi Phil!

Thanks for your answer! I cannot imagine how ray casting should solve my problem since I neither have a starting point of the ray nor a direction for it!
Maybe I should describe the problem a bit in more detail. Imagine a simple sphere and your mouse pointer is inside this sphere - in such a way that it is not visible to you (that's what I meant by "inside" the mesh). After a simulation step the mouse pointer is outside the sphere (and is visible). My problem is to detect the triangle which would have collided with the mouse pointer. I hope, this helps.

 
PixelClear

April 26, 2005, 08:19 PM

Hi,

Here is a good article on how to define a ray from your mouse position and your view/projection matrices :

http://www.mvps.org/directx/articles/rayproj.htm
You should also have a look at his DirectX picking demo.

Note that if you are working directX you should definately have a look at the D3DXIntersect function. With openGL I'm afraid you'll have to program your ray triangle intersections yourself.

You must consider that your mouse pointer is on the near plane of your view frustum and it's interaction position is the first hit of the ray it casts in the scene (the same way you would setup your rays for ray tracing). By doing so you will define a point of your surface that you'll be able to track whatever the transforms applied to the mesh are.

Testing all the polygons for intersection might seem a bit brute force but it should be okay if you only do it at the mousedown event and keep track of the triangle you hit and the barycentric coordinates of your hitting point on that triangle.

I hope this helps.
Phil

 
This thread contains 4 messages.
 
 
Hosting by Solid Eight Studios, maker of PhotoTangler Collage Maker.