Click or drag to resize
AB4D logo

TargetPositionCamera Class

TargetPositionCamera is a camera that is looking at the specified position from the specified angle and distance.
Inheritance Hierarchy
SystemObject
  System.Windows.ThreadingDispatcherObject
    System.WindowsDependencyObject
      System.Windows.MediaVisual
        System.WindowsUIElement
          System.WindowsFrameworkElement
            Ab3d.CamerasBaseCamera
              Ab3d.CamerasSphericalCamera
                Ab3d.CamerasBaseTargetPositionCamera
                  Ab3d.CamerasTargetPositionCamera

Namespace: Ab3d.Cameras
Assembly: Ab3d.PowerToys (in Ab3d.PowerToys.dll) Version: 11.1.8864.1045
Syntax
C#
public class TargetPositionCamera : BaseTargetPositionCamera, 
	IMovableCamera

The TargetPositionCamera type exposes the following members.

Constructors
 NameDescription
Public methodTargetPositionCamera Constructor
Top
Properties
 NameDescription
Public propertyRotationCenterPosition Gets or sets a nullable Point3D that can specify a custom 3D position around which this TargetPositionCamera is rotated. Rotation around custom center position changes the camera angles (Heading and Attitude) and also TargetPosition. When RotationCenterPosition is null, the rotation is done with changing only Heading and Attitude properties.
Public propertyTargetPosition Gets or sets a Point3D that defines the position on which the camera is looking.
Top
Methods
 NameDescription
Public methodAnimateTo Animates the TargetPosition, Distance and CameraWidth to the specified values. The animation takes animationDurationInMilliseconds and uses the specified easingFunction.
Protected methodBaseCreateFrom This method is called from CreateFrom method and actually sets the properties on this camera.
(Overrides SphericalCameraBaseCreateFrom(Camera))
Public methodMoveBackward Moves the camera backward (in the opposite as look direction)
Public methodMoveCamera Moves the camera for the moveVector (regardless of the current camera's LookDirection and UpDirection)
Public methodMoveDown Moves the camera down (in the opposite up direction)
Public methodMoveForward Moves the camera forward (in the look direction)
Public methodMoveLeft Moves the camera left (strafe)
Public methodMoveRight Moves the camera right (strafe)
Public methodMoveTargetPositionTo Animates the TargetPosition to the finalTargetPosition. The animation takes animationDurationInMilliseconds and uses the specified easingFunction.
Public methodMoveUp Moves the camera up (in the up direction)
Public methodRotateCamera Rotates this camera for the specified heading and attitude. When RotationCenterPosition is set, the camera rotates around RotationCenterPosition which can change Heading, Attitude, TargetPosition and Distance.
(Overrides SphericalCameraRotateCamera(Double, Double))
Protected methodStrafeCamera Calculates the moveVector based on the current camera's LookDirection and UpDirection
Top
Fields
 NameDescription
Public fieldStatic memberRotationCenterPositionProperty RotationCenterPositionProperty
Top
Remarks

TargetPositionCamera is a camera that is looking at the TargetPosition from the specified angle and distance.


The angle is specified by Heading, Attitude and Bank properties.

The distance from the camera to the TargetPosition is defined by the Distance property.


TargetPositionCamera also has some other properties that are common to all cameras that derive from SphericalCamera class.


The ShowCameraLight and the CameraLight properties can be used to add a lights to the Viewport3D that is positioned at the same position as the camera and is looking at the cameras direction. In the real world this would be a light that is mounted to the camera. This way the 3D objects that are viewed with the camera are always illuminated regardless of the cameras position.

The ShowCameraLight defines when the camera light is shown. The possible values are:

  • Never – Never add additional camera light
  • Auto – (Default value) Show camera light only if there is no other light defined in the Viewport3D controlled by the camera.
  • Always – Always add a camera light

The CameraLight property is by default a DirectionalLight with White color. The value can be set to a new DirectionalLight with some other color. Other types of Lights are not supported - will not change according to the camera's changed.


Because SphericalCamera is derived from BaseCamera, the TargetPositionCamera also contains properties that are defined in BaseCamera and therefore common to all the cameras:

The Viewport3D that is controlled by this camera is defined by IsAutoViewport3DFindingEnabled, TargetViewport3D and TargetViewport3DName properties.

If the Window, Page or UserControl has only one Viewport3D, there is no need to set and of the above properties on the camera. By default the IsAutoViewport3DFindingEnabled is set to true and that means, that the Viewport3D is automatically find from the current UserControl, Page or Window and it is set to a TargetViewport3D property.

But if there are more Viewport3D objects defined, than by default the first Viewport3D will be used by the camera. With setting the TargetViewport3D or TargetViewport3DName it is possible to specify which Viewport3D will be controlled by the camera.

Example

The following xaml creates a Viewport3D with a 3D Box and a TargetPositionCamera that is looking at the bottom of the Box from above. The Distance from the camera to the TargetPosition is 100. Because there is no light defined in the Viewport3D and the default value of the camera's ShowCameraLight property is true, the cameras adds a light that is illuminating the scene.

The sample also defines a MouseCameraController to control the camera with the mouse and a CameraControlPanel that shows some nice buttons that can be also used to control the camera.

XAML
<Page x:Class="PowerToysSamples"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:visuals="clr-namespace:Ab3d.Visuals;assembly=Ab3d.PowerToys"
    xmlns:ab3dControls="clr-namespace:Ab3d.Controls;assembly=Ab3d.PowerToys"  
    xmlns:cameras="clr-namespace:Ab3d.Cameras;assembly=Ab3d.PowerToys">
    <Grid>
        <Viewport3D>
            <visuals:BoxVisual3D CenterPosition="50 100 0" Size="50 200 20" Material="Blue"/>
        </Viewport3D>

        <cameras:TargetPositionCamera Heading="0" Attitude="-50" Distance="100"
                                      TargetPosition="75 0 20"/>

        <ab3dControls:MouseCameraController/>

        <ab3dControls:CameraControlPanel VerticalAlignment="Bottom" HorizontalAlignment="Left"/>
    </Grid>
</Page>
See Also