Properties HeightDirection and Normal in the PlaneVisual3D object
#1
Given the app shown the code as the end of this post, when I first execute I get shown in image1.png.  Then when I move the mouse around I get image2.png (see attachment).

What I need to know is how the PlaneVisual3D object is drawn.  For example, suppose in image1.png I wish to see the full rectangles, i.e. have the rectangle drawn along the x-y axis instead of the x-z axis.  How would I do that?  I assume that this has something to do with HeightDirection and Normal but I don't understand how these properties work.  Thanks for any help you can give.













Code:
<Window x:Class="Rectangles.MainWindow"
       xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
       xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
       xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
       xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
       xmlns:cameras="clr-namespace:Ab3d.Cameras;assembly=Ab3d.PowerToys"
       xmlns:ab3d="clr-namespace:Ab3d.Controls;assembly=Ab3d.PowerToys"  
       xmlns:visuals="clr-namespace:Ab3d.Visuals;assembly=Ab3d.PowerToys"
       xmlns:local="clr-namespace:Rectangles"
       mc:Ignorable="d"
       Title="MainWindow" Height="450" Width="800">
   
   <Grid Name="MainGrid">
       <Border Name="ViewportBorder">
           <Border.Background>
               <LinearGradientBrush StartPoint="0 0" EndPoint="0 1">
                   <GradientStop Offset="0" Color="#033C62"/>
                   <GradientStop Offset="1" Color="#01131F"/>
               </LinearGradientBrush>
           </Border.Background>

           <Viewport3D Name="MainViewport">
              <visuals:ColoredAxisVisual3D Length="50"/>

              <visuals:PlaneVisual3D CenterPosition="-150,50, -50" Size="100 100" HeightDirection="0 0 -1" Normal="0 -1 0" Material="Orange" />
              <visuals:PlaneVisual3D CenterPosition="-150,50.01,-50" Size="100 100" HeightDirection="0 0 -1" Normal="0  1 0" Material="Orange" />

               <visuals:PlaneVisual3D CenterPosition="-150,65, -50" Size="100 100" HeightDirection="0 0 -1" Normal="0 -1 0" Material="Yellow" />
               <visuals:PlaneVisual3D CenterPosition="-150,65.01,-50" Size="100 100" HeightDirection="0 0 -1" Normal="0  1 0" Material="Yellow" />
           </Viewport3D>
       </Border>

       <cameras:TargetPositionCamera Name="Camera1"
                                     TargetPosition="0 0 0"
                                     Heading="0" Attitude="-40" Bank="0"
                                     Distance="700"
                                     ShowCameraLight="Always"
                                     TargetViewport3D="{Binding ElementName=MainViewport}" />

       <ab3d:MouseCameraController Name="MouseCameraController1"
                                   RotateCameraConditions="LeftMouseButtonPressed"
                                   MoveCameraConditions="LeftMouseButtonPressed, ControlKey"
                                   TargetCamera="{Binding ElementName=Camera1}"
                                   EventsSourceElement="{Binding ElementName=ViewportBorder}"/>
     
   </Grid>
</Window>


Attached Files Thumbnail(s)
       
#2
The orientation of the PlaneVisual3D is defined by Normal and HeightDirection properties.

The Normal is a Vector3D that defined the normal vector which is perpendicular to the plane - for example for a horizontal plane it is defined as (0, 1, 0) - pointing up.

The HeightDirection is also a Vector3D and defines a direction of the plane's height - for example if plane's Size is defined as (width: 100, height: 10), then the HeightDirection defines in which direction the plane's height is drawn (defined by value 10).

You can see two samples of PlaneVisual3D in the "Standard 3D objects / 3D objects cheat sheet" sample. You can also dynamically change those two (and some other properties) of PlaneVisual3D in the "Standard 3D objects / PlaneVisual3D" sample.


The WPF 3D uses right handed coordinate system where x is pointing to the right, y up, and z to the viewer (away from the screen). You can visualize the axis orientation with adding ColoredAxisVisual3D (note that the axis colors are XYZ = RGB (x = red, y = green, z = blue). You can also add CameraAxisPanel on top of the 3D scene to see the orientation of the axes - see samples that come with Ab3d.PowerToys for many samples of CameraAxisPanel.


You can also change the Normal and HeightDirection properties with opened design window and the changes will be shown immediately.
Andrej Benedik
#3
Thanks.  This is exactly what I needed.  We can close this now.

For the benefit of other users, I want to point out that when you change the value of Normal, you may need to change the value of HeightDirection in order to see the PlaneVisual3D.  For example, suppose we start with the definition:

  <visuals:PlaneVisual3D CenterPosition="0,0, 0" Size="100 100" HeightDirection="0 0 1"  Normal="0 1 0" Material="Yellow" />

This gives us the result shown in the first attached image.   But if modify the above so that Normal is "0  0 1",
we get the result in the second image (no PlaneVisual3D is visible).  If we then modify the above so that HeightDirection = "0 1 0", we get the result in the third image (PlaneVisual3D is visible).

   

   

   
  


Forum Jump:


Users browsing this thread:
1 Guest(s)