Re: IntersectInformation Problem
From: ZMan (news-replies_at_thezbuffer)
Date: 10/10/04
- Next message: Ghazanfar Ali: "Getting error "REGDB_E_CLASSNOTREG" on some PCs"
- Previous message: smeagol: "October Update. AnimationController bug?"
- In reply to: Chris Anderson: "IntersectInformation Problem"
- Next in thread: Chris Anderson: "Re: IntersectInformation Problem"
- Reply: Chris Anderson: "Re: IntersectInformation Problem"
- Messages sorted by: [ date ] [ thread ]
Date: Sat, 9 Oct 2004 23:09:51 -0700
If you have a triangle v0, v1, v2 then u and v are barycentric coordinates
on that triangle. The point you want can be calculated by:
(1-u-v)*v0+u*v1+v*v2
(you may have to play with the order of v0, v1, v2 from the mesh to get the
ones that u and v are taken from)
I'll try to explain how it works but its kind of hard in a short email.
Imagine instead of X & Y being your axes that 2 of the sides of the triangle
v0,v1 and v0,v2 are your axes and u and v are distances along those axes.
You can see that you can represent any point in space. The scale of the
result happens to mean that u=0, v=0 means the point v0, u=1,v=0 means the
point v1 and u=0, v=1 means the point v2.
If you do an early DX9 (pre summer 04) install and just install the samples
there is one called 'pick' that illustrates this.
If you want to read more you can try Real Time Rendering
http://www.amazon.com/exec/obidos/tg/detail/-/1568811829/qid=1097388362/sr=8-1/ref=pd_csp_1/002-0679027-2088831?v=glance&s=books&n=507846
Sorry I don't have time to write your code for you but once you have the
face ID you should be able to extract the vertices for that face then apply
the above formula. This will give you what you want in object space and you
can then apply the relevant transforms to get what you want in world space.
ZMan
"Chris Anderson" <cmanders@nospamplease.swiftdsl.com.au> wrote in message
news:u4SsLqgrEHA.868@TK2MSFTNGP10.phx.gbl...
> Hi all
>
> I'm a relative newcomer to DirectX, and am having some troubles. I have
> two questions - both to do with the age old question of picking a mesh
> with the mouse. Going through old newsgroup posts, I can see this problem
> listed many times and many answers given, which have allowed me to
> actually work out what mesh the user has selected (by projecting a ray in
> the direction of the mouse coordinates and using the mesh.Intersect to
> determine whether a specified mesh intersects with this ray or not). So
> that isn't the actual problem I'm having. What I then need to be able to
> do (and this is my problem) is determine exactly at what point in 3D world
> space the intersection with the mesh was (ie. as a Vector3). Now the
> mesh.Intersect function returns an IntersectInformation structure (I'm
> programming in C# by the way), that returns a FaceIndex, intersection
> Distance along the ray, and the Bayesian coordinates U and V. Now these
> coordinates are probably what I need, but I don't know how to translate
> them into the world space. Then with the second problem I want to do the
> same sort of thing, picking a point in world space, but this time not
> necessarily on a mesh. However, I will have a reference point (the point
> from the previous question) as a ground reference.
>
> I'll give an example of what I am trying to do to maybe make it a bit
> clearer:
>
> I want the user to be able to select a point on a mesh representing the
> ground, using the mouse. That point is to be my launch point for a
> projectile. Ideally, I would then like the user to be able to select a
> point somewhere above this (ie. in the sky where there is no mesh)
> specifying a point which the projectile should pass through on its flight
> (I will then calculate its direction and launch velocity). While this is
> a 3D world, I will assume that the second point has the same z value as
> the first point, and I am merely specifying the x and y values.
>
> I think the second problem should fall into place if I can work out the
> first (hopefully at least anyway). My mathematics isn't so flash, so the
> more detailed your anwer is (code would be ideal), the better. I've
> pretty much exhausted all my knowledge on this one and searches on Google
> have also come up with nothing, so any help you can provide would be much
> appreciated.
>
> Thanks in advance
>
> Chris
>
- Next message: Ghazanfar Ali: "Getting error "REGDB_E_CLASSNOTREG" on some PCs"
- Previous message: smeagol: "October Update. AnimationController bug?"
- In reply to: Chris Anderson: "IntersectInformation Problem"
- Next in thread: Chris Anderson: "Re: IntersectInformation Problem"
- Reply: Chris Anderson: "Re: IntersectInformation Problem"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|