![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
|
Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
br> br> |
| |||||||
![]() |
| | Thread Tools | Display Modes |
| | #1 (permalink) |
| Guest | 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 Specs![]() |
| | #2 (permalink) |
| Guest | 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 Specs![]() |
| | #3 (permalink) |
| Guest | 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 Specs![]() |
| | #4 (permalink) |
| Guest | 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 Specs![]() |
| | #5 (permalink) |
| Guest | 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 Specs![]() |
![]() |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Some Pan/Zoom Test Results.... Vista's MM6 is best | PapaJohn | Vista music pictures video | 0 | 07-28-2008 12:45 AM |
| Test results of 17 disk/file recovery programs on SD card | a.k.a. | Vista file management | 0 | 12-30-2007 06:39 PM |
| very disconcerting test results | Richard Urban | Vista General | 12 | 08-25-2007 03:05 PM |
| How to test file-filter-driver in Driver Test Manager(DTM)? | Cui Wei | Vista General | 8 | 01-18-2007 07:59 AM |
| Camera transform affects hit test results | viliescu | Avalon | 3 | 01-10-2006 03:54 PM |