Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > Avalon

Vista - Hit Test Results

 
 
Old 03-02-2006   #1 (permalink)
Kevin Hoffman


 
 

Hit Test Results

I've got a quick question on hit test results.

I'm toying with the hit testing sample provided on MSDN, where you
basically trap the viewport's mousedown event and then use the
asynchronous HitResult method pattern. What I'm having trouble with is
I've got access to this HitResult structure that gives me access to a
VisualHit property.

What I can't figure out is how I determine _which_ visual was hit. How
do I get the name/ID of the element that was hit in that hit test? I've
tried using GetValue to get a "name" property, but I can't get the
syntax to work the same way it did in previous CTPs.

Here's the shell method I'm using for HTResult:
public HitTestResultBehavior
HTResult(System.Windows.Media.HitTestResult rawresult)
{
RayHitTestResult rayResult = rawresult as RayHitTestResult;

if (rayResult != null)
{
RayMeshGeometry3DHitTestResult rayMeshResult = rayResult as
RayMeshGeometry3DHitTestResult;

if (rayMeshResult != null)
{
GeometryModel3D hitgeo = rayMeshResult.ModelHit as
GeometryModel3D;

//tbHitCheck.Text = "You hit a mesh, " + ??????? ;

}

}

return HitTestResultBehavior.Continue;

}

The "You hit a mesh" is what I'm trying to accomplish, but can't figure
out from there how to figure out which model was hit.

Any thoughts?


My System SpecsSystem Spec
Old 03-03-2006   #2 (permalink)
Americo


 
 

RE: Hit Test Results

It's possible that this "lesson" helps you:
http://www.dmu.com/avalon3D/a3d10.html
Better to read all the lessons of:
http://www.dmu.com/avalon3D


"Kevin Hoffman" wrote:

> I've got a quick question on hit test results.
>
> I'm toying with the hit testing sample provided on MSDN, where you
> basically trap the viewport's mousedown event and then use the
> asynchronous HitResult method pattern. What I'm having trouble with is
> I've got access to this HitResult structure that gives me access to a
> VisualHit property.
>
> What I can't figure out is how I determine _which_ visual was hit. How
> do I get the name/ID of the element that was hit in that hit test? I've
> tried using GetValue to get a "name" property, but I can't get the
> syntax to work the same way it did in previous CTPs.
>
> Here's the shell method I'm using for HTResult:
> public HitTestResultBehavior
> HTResult(System.Windows.Media.HitTestResult rawresult)
> {
> RayHitTestResult rayResult = rawresult as RayHitTestResult;
>
> if (rayResult != null)
> {
> RayMeshGeometry3DHitTestResult rayMeshResult = rayResult as
> RayMeshGeometry3DHitTestResult;
>
> if (rayMeshResult != null)
> {
> GeometryModel3D hitgeo = rayMeshResult.ModelHit as
> GeometryModel3D;
>
> //tbHitCheck.Text = "You hit a mesh, " + ??????? ;
>
> }
>
> }
>
> return HitTestResultBehavior.Continue;
>
> }
>
> The "You hit a mesh" is what I'm trying to accomplish, but can't figure
> out from there how to figure out which model was hit.
>
> Any thoughts?
>
>

My System SpecsSystem Spec
Old 03-03-2006   #3 (permalink)
Kevin Hoffman


 
 

Re: Hit Test Results

I've already read the "lesson" you indicate here. The only thing your
"lesson" does is compare the geometry with geometry contained in the
resource dictionary. My issue is that I intend to have several dozen
cubes in my scene - all of which will have the same geometry. The only
thing that will differentiate them is their transformations (translated
for offset) and some form of identification.

There are two ways of doing hit testing here:

1. Hit test on the viewport - which is what I have shown in the
previous example. This works like a charm, and I know exactly when I
have hit the model, and I can start/stop storyboards as a result of
hitting that model. What I want to do is find out somehow _exactly
which_ of my models I hit.

2. I can iterate through every model in the scene and perform a hit
test specifically on that model. This seems fairly inefficient to me,
but if someone can make a good argument for it, that's the way I'll go.
I just know that using #1 seems really fast and efficient, I just need
some ideas on building a scheme whereby the hit testing can give me
some ID or unique differentiation between the model hit and all other
models in the scene.

My System SpecsSystem Spec
Old 03-03-2006   #4 (permalink)
Jordan Parker [MSFT]


 
 

Re: Hit Test Results

By "name" do you mean you assigned them x:Name values in your xaml? If so,
you won't be able to get that value back from the object you hit. Plus, we
don't have any Name properties on 3D elements. Some options include...

1) Hit test each Model3D individually (which you mentioned later on)
2) Create a data structure that maps references -> names and index into it
with "hitgeo"
3) Create an attached property that stores the name
4) Make your own subclass of ModelVisual3D with whatever extra info on it
you want

#4 is probably the best from a design standpoint but it's certainly not the
quickest way to get it done

Jordan

> I've got a quick question on hit test results.
>
> I'm toying with the hit testing sample provided on MSDN, where you
> basically trap the viewport's mousedown event and then use the
> asynchronous HitResult method pattern. What I'm having trouble with is
> I've got access to this HitResult structure that gives me access to a
> VisualHit property.
>
> What I can't figure out is how I determine _which_ visual was hit. How
> do I get the name/ID of the element that was hit in that hit test? I've
> tried using GetValue to get a "name" property, but I can't get the
> syntax to work the same way it did in previous CTPs.
>
> Here's the shell method I'm using for HTResult:
> public HitTestResultBehavior
> HTResult(System.Windows.Media.HitTestResult rawresult)
> {
> RayHitTestResult rayResult = rawresult as RayHitTestResult;
>
> if (rayResult != null)
> {
> RayMeshGeometry3DHitTestResult rayMeshResult = rayResult as
> RayMeshGeometry3DHitTestResult;
>
> if (rayMeshResult != null)
> {
> GeometryModel3D hitgeo = rayMeshResult.ModelHit as
> GeometryModel3D;
>
> //tbHitCheck.Text = "You hit a mesh, " + ??????? ;
>
> }
>
> }
>
> return HitTestResultBehavior.Continue;
>
> }
>
> The "You hit a mesh" is what I'm trying to accomplish, but can't figure
> out from there how to figure out which model was hit.
>
> Any thoughts?
>



My System SpecsSystem Spec
Old 03-29-2006   #5 (permalink)
PT


 
 

Re: Hit Test Results

XAML:
<GeometryModel3D x:Name="geometry1"...

I was able to assign it a name and do a reference compare.

if ( hitgeo.Equals(geometry1) )
{
// Item hit
}

Is there a problem with this method?

"Jordan Parker [MSFT]" wrote:

> By "name" do you mean you assigned them x:Name values in your xaml? If so,
> you won't be able to get that value back from the object you hit. Plus, we
> don't have any Name properties on 3D elements. Some options include...
>
> 1) Hit test each Model3D individually (which you mentioned later on)
> 2) Create a data structure that maps references -> names and index into it
> with "hitgeo"
> 3) Create an attached property that stores the name
> 4) Make your own subclass of ModelVisual3D with whatever extra info on it
> you want
>
> #4 is probably the best from a design standpoint but it's certainly not the
> quickest way to get it done
>
> Jordan
>
> > I've got a quick question on hit test results.
> >
> > I'm toying with the hit testing sample provided on MSDN, where you
> > basically trap the viewport's mousedown event and then use the
> > asynchronous HitResult method pattern. What I'm having trouble with is
> > I've got access to this HitResult structure that gives me access to a
> > VisualHit property.
> >
> > What I can't figure out is how I determine _which_ visual was hit. How
> > do I get the name/ID of the element that was hit in that hit test? I've
> > tried using GetValue to get a "name" property, but I can't get the
> > syntax to work the same way it did in previous CTPs.
> >
> > Here's the shell method I'm using for HTResult:
> > public HitTestResultBehavior
> > HTResult(System.Windows.Media.HitTestResult rawresult)
> > {
> > RayHitTestResult rayResult = rawresult as RayHitTestResult;
> >
> > if (rayResult != null)
> > {
> > RayMeshGeometry3DHitTestResult rayMeshResult = rayResult as
> > RayMeshGeometry3DHitTestResult;
> >
> > if (rayMeshResult != null)
> > {
> > GeometryModel3D hitgeo = rayMeshResult.ModelHit as
> > GeometryModel3D;
> >
> > //tbHitCheck.Text = "You hit a mesh, " + ??????? ;
> >
> > }
> >
> > }
> >
> > return HitTestResultBehavior.Continue;
> >
> > }
> >
> > The "You hit a mesh" is what I'm trying to accomplish, but can't figure
> > out from there how to figure out which model was hit.
> >
> > Any thoughts?
> >

>
>
>

My System SpecsSystem Spec
 

Thread Tools


Similar Threads
Thread Forum
Errors while run DTM Test USB Address Description Test PowerShell
Some Pan/Zoom Test Results.... Vista's MM6 is best Vista music pictures video
Test results of 17 disk/file recovery programs on SD card Vista file management
very disconcerting test results Vista General


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46