Re: pick closest mesh by mouse
- From: "Samuel Sperling" <BUTCH_STOP_SPAM@xxxxxx>
- Date: Mon, 14 Nov 2005 16:47:05 +0100
Hi!
Sorry I missed the
vNear = new Vector3 (mouseX, mouseY, 0);
vFar = new Vector3 (mouseX, mouseY, 1);
but used it in my code.
So I guess this works correct.
But Let's say I found 2 Objects that intersect.
So I have 2 objects of type IntersectInformation, how do I figure which is
closest?
You said:
"[...] getting the vertices of the face and applying the barycentric
intersection coodinates to those vertices."
Can you tell how to practically do that?
(Sorry I'm pretty new to all this)
Thanks!!!
"ZMan" <zman@xxxxxxxxxxxxxx> schrieb im Newsbeitrag
news:u8yFuQv5FHA.636@xxxxxxxxxxxxxxxxxxxxxxx
> I'm not sure where you got the original vp vector from, but
> closesthit.distance does indeed give you the distance along that ray.
>
> You problem appears to be that vNear==vFar since you created them both
> with the same formula, then you subtract one from the other meaning the
> direction vector you pass to .Intersect is 0. SO my guess is that your
> intersection code isn't working at all.
>
> typically you would create your near/far as something like the unprojects
> of (mousex, mousey, 0) and (mousex, mousey, 1) (though I can never
> remember which should have 0 and which should have a 1.... worst case you
> get the distances backwards).
>
> Finding which triangle is hit where involves looking up the face from the
> intersectinformation, getting the vertices of the face and applying the
> barycentric intersection coodinates to those vertices.
>
> --
> Zman
> http://www.thezbuffer.com - News and information for Managed DirectX
>
>
>
> "Samuel Sperling" <BUTCH_STOP_SPAM@xxxxxx> wrote in message
> news:dl2cd6$up2$1@xxxxxxxxxxxxxxxxxxxxx
>> Hi!
>> And thanks a lot for this answer! I almost gave up looking for answers ;)
>>
>> I had this little hope there was a solution easyer than what you
>> explained!
>> But still I can now be confident in stop searching for easy methods.
>> And start thinking about how to aplly this to my projekt all this. ...and
>> implement ... :)
>>
>> Thanks for your effort!
>> - sam
>>
>> "Michel Walsh" <vanderghast@VirusAreFunnierThanSpam> schrieb im
>> Newsbeitrag news:OMOtsbj5FHA.2676@xxxxxxxxxxxxxxxxxxxxxxx
>>> Hi,
>>>
>>>
>>>
>>> If the meshes are convex, someone can take one of the mesh, to find its
>>> bounding sphere. Now, from the center of that sphere, issue a ray
>>> perpendicular to the first initial ray of selection (or picking ray, if
>>> you prefer). That ray intercept the mesh at a given point, which can now
>>> be used to compute the distance to the initial ray of selection. It
>>> seems that either this point is the point closest to the initial ray of
>>> selection, either one of the vertex making the triangle it belongs is
>>> the closest point to the initial ray of selection (but I have no proof
>>> for that).
>>>
>>>
>>> Let say we have found a such a distance for one mesh. We have then to
>>> consider the other meshes, one at a time. Meshes with "d", the distance
>>> of the center of their bounding sphere to the initial ray, less "r", the
>>> radius of the bounding sphere, larger than the minimum distance found up
>>> to know cannot be closer than the candidate found up to now and are not
>>> to be considered anyfurther. You can also use Bounding Box (parallel to
>>> axis) to further clip out more meshes.
>>>
>>>
>>> If the meshes are not convex, that is a much harder problem. Consider a
>>> thin wall tube, where the picking ray would be the axis of the tube...
>>> all the inner points of the tube are candidate as to be the closest one
>>> ! Sure, even with convex meshes, we can have more than a single one
>>> candidate.
>>>
>>>
>>> Hoping it may help,
>>> Vanderghast, Access MVP
>>>
>>>
>>> "Samuel Sperling" <butch77@xxxxxxxxxxxx> wrote in message
>>> news:dhhl5t$c6j$1@xxxxxxxxxxxxxxxxxxxxx
>>>> Hi!
>>>>
>>>> I now this question was here a few times, but I couldn' t really find
>>>> an answer appropriate to fit my problem.
>>>>
>>>> I managed picking a mesh. But I can not figure which of them is the
>>>> closest at mouse position.
>>>>
>>>>
>>>> vNear.Unproject (vp, ProjectionMatrix, ViewMatrix, World);
>>>>
>>>> vFar.Unproject (vp, ProjectionMatrix, ViewMatrix, World);
>>>>
>>>> vFar.Subtract (vNear);
>>>>
>>>> IntersectInformation closestHit = new IntersectInformation();
>>>>
>>>> return pMesh.Intersect(vNear, vFar, out closestHit);
>>>>
>>>>
>>>> At first I thought closestHit.Dist would bring me the distance to the
>>>> camera. but of course it's just the distance to the ray.
>>>>
>>>> So my question is how do I find out, at what exact position the mesh
>>>> gets hit from the ray? Or how do I find out what's the distance from
>>>> the camera at the mouse position? What mesh is closest? Can I use the
>>>> Z-Buffer for this?
>>>>
>>>> Many questions...
>>>>
>>>> I'd be very grateful if anyone could help me out with this!
>>>> Thanks!!
>>>>
>>>
>>>
>>
>>
>
>
.
- Follow-Ups:
- Re: pick closest mesh by mouse
- From: ZMan
- Re: pick closest mesh by mouse
- References:
- Re: pick closest mesh by mouse
- From: Michel Walsh
- Re: pick closest mesh by mouse
- From: Samuel Sperling
- Re: pick closest mesh by mouse
- From: ZMan
- Re: pick closest mesh by mouse
- Prev by Date: Re: HOWTO: Write a DirectShow filter in C# (follow up)
- Next by Date: Re: The Orbit Effect
- Previous by thread: Re: pick closest mesh by mouse
- Next by thread: Re: pick closest mesh by mouse
- Index(es):
Relevant Pages
|