Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

PointHitTestResult.Visual

0 views
Skip to first unread message

casey chesnut

unread,
Oct 17, 2005, 10:59:32 PM10/17/05
to
i've got a Viewport3D with 4 GeometryModel3D.
when i do the VisualOperations.HitTest() i get a HitTestResult that i can
cast into a PointHitTestResult.
the PointHitTestResult has a Visual property.

my question is how can i use the Visual property to find out which of my 4
GeometryModel3D items was hit?
right now i can only tell that one of them was hit ... but not which one.

the samples i've been looking at show Ray3DHitTestResult ... which my
HitTest() call does not return.

Thanks,
casey


casey chesnut

unread,
Oct 18, 2005, 9:54:17 AM10/18/05
to
this is what my Viewport3D looks like.
its just 4 meshes spread out and facing the camera.
its parent container is a DockPanel.

my HitTest code is from the Carousel sample here
http://www.therhogue.com/WinFX/
so i'm not sure why i'm getting a PointHitTestResult instead of a
Ray3DHitTestResult?

<Window.Resources>
<MeshGeometry3D x:Key="PlaneMesh"
Positions="-10,-10,0 10,-10,0 -10,10,0 10,10,0"
Normals="0,0,1 0,0,1 0,0,1 0,0,1"
TextureCoordinates="0,1 1,1 0,0 1,0"
TriangleIndices="0 1 2 1 3 2" />
</Window.Resources>

<Viewport3D x:Name="myViewport3D">
<Viewport3D.Camera>
<PerspectiveCamera NearPlaneDistance="1" FarPlaneDistance="200"
LookAtPoint="0,0,-5" Up="0,1,0" Position="0,60,120" FieldOfView="45" />
</Viewport3D.Camera>
<Viewport3D.Models>
<Model3DGroup>
<Model3DGroup.Children>
<GeometryModel3D Geometry="{StaticResource PlaneMesh}">
<GeometryModel3D.Transform>
<TranslateTransform3D Offset="0,0,30" />
</GeometryModel3D.Transform>
<GeometryModel3D.Material>
<DiffuseMaterial>
<DiffuseMaterial.Brush>
<SolidColorBrush Color="Green" Opacity="1.0"/>
</DiffuseMaterial.Brush>
</DiffuseMaterial>
</GeometryModel3D.Material>
</GeometryModel3D>
<GeometryModel3D Geometry="{StaticResource PlaneMesh}">
<GeometryModel3D.Transform>
<TranslateTransform3D Offset="-30,0,0" />
</GeometryModel3D.Transform>
<GeometryModel3D.Material>
<DiffuseMaterial>
<DiffuseMaterial.Brush>
<SolidColorBrush Color="Red" Opacity="1.0"/>
</DiffuseMaterial.Brush>
</DiffuseMaterial>
</GeometryModel3D.Material>
</GeometryModel3D>
<GeometryModel3D Geometry="{StaticResource PlaneMesh}">
<GeometryModel3D.Transform>
<TranslateTransform3D Offset="0,0,-30" />
</GeometryModel3D.Transform>
<GeometryModel3D.Material>
<DiffuseMaterial>
<DiffuseMaterial.Brush>
<SolidColorBrush Color="Yellow" Opacity="1.0"/>
</DiffuseMaterial.Brush>
</DiffuseMaterial>
</GeometryModel3D.Material>
</GeometryModel3D>
<GeometryModel3D Geometry="{StaticResource PlaneMesh}">
<GeometryModel3D.Transform>
<TranslateTransform3D Offset="30,0,0" />
</GeometryModel3D.Transform>
<GeometryModel3D.Material>
<DiffuseMaterial>
<DiffuseMaterial.Brush>
<SolidColorBrush Color="Blue" Opacity="1.0"/>
</DiffuseMaterial.Brush>
</DiffuseMaterial>
</GeometryModel3D.Material>
</GeometryModel3D>
<AmbientLight Color="White" />
</Model3DGroup.Children>
</Model3DGroup>
</Viewport3D.Models>
</Viewport3D>


"casey chesnut" <casey@MORE_SPAMbrains-N-brawn.com> wrote in message
news:%23jyX4$40FHA...@tk2msftngp13.phx.gbl...

Bob Brown[MSFT]

unread,
Oct 18, 2005, 8:03:44 PM10/18/05
to
Thanks for sharing the sample.  What's happening is that you are using Viewport3D.Models (which is deprecated) to set up your 3D scene.  The old method requires you to cast the HitTestResult to an IHitTestResult3DContainer then iterate on the "Results" property.  Robert Hogue's samples are all using the new Visual3D API instead of Viewport3D.Models.  If you edit your Window.xaml file in the following way, you will start getting ray hit test results:
 
<Viewport3D>
   <Viewport3D.Models>
       <Model3DGroup>
          <!-- 3D stuff goes here -->
       </Model3DGroup>
   </Viewport3D.Models>
</Viewport3D>
 
to:
 
<Viewport3D>
   <ModelVisual3D>
       <ModelVisual3D.Content>
          <Model3DGroup>
             <!-- 3D stuff goes here -->
          </Model3DGroup>
      </ModelVisual3D.Content>
   </ModelVisual3D>
</Viewport3D>

--
Bob Brown [MSFT]
This posting is provided "AS IS" with no warranties, and confers no rights.
 
 
> here is a small sample attached.
> i would like to understand why it returns a PointHitTestResult ... when all
> the other samples i've modeled my Viewport3D after return a
> Ray3DHitTestResult.
> and if it is supposed to return a PointHitTestResult, then how can i use
> that to tell which of my 2 models was hit?
>
> Thanks,
> casey
>
> "casey chesnut" <
casey@MORE_SPAMbrains-N-brawn.com> wrote in message
>
news:uorjvt%230FH...@TK2MSFTNGP12.phx.gbl...
http://www.therhogue.com/WinFX/

casey chesnut

unread,
Oct 18, 2005, 10:26:06 PM10/18/05
to
Thanks for explaining that.
 
Could you explain the difference between ModelVisual3D.Content and ModelVisual3D.Children?
 
casey
 

TheRHogue

unread,
Oct 19, 2005, 11:39:05 PM10/19/05
to
ModelVisual3D's can have ModelVisual3D nested children an that is it. The
benefit of a ModelVisual3D is hittesting can be done on a specific
ModelVisual3D - thus eliminating hittest overhead if managed properly.

ModelVisual3D.Content can only have one child, and that is normally a
Model3DGroup which can have nested children.

If your question is why make this change at all, this change is an
architectural change to allow other fun stuff in the future that many of us
are requesting.

0 new messages