First |
public class FirstPersonCamera : SphericalCamera, IMovableCamera
The FirstPersonCamera type exposes the following members.
Name | Description | |
---|---|---|
FirstPersonCamera | Constructor |
Name | Description | |
---|---|---|
BaseCreateFrom |
This method is called from CreateFrom method and actually sets the properties on this camera.
(Overrides SphericalCameraBaseCreateFrom(Camera)) | |
IsValid |
Gets a Boolean that specifies if the camera is valid (has TargetViewport3D that has a valid size; has valid values for all properties).
When camera is valid the Point3DTo2D(Point3D) returns correct value; when the camera is not valid, the Point3DTo2D method cannot calculate the 2D screen position.
(Overrides SphericalCameraIsValid(Boolean)) | |
MoveBackward | Moves the camera backward (in the opposite as look direction) | |
MoveCamera | Moves the camera for the moveVector (regardless of the current camera's LookDirection and UpDirection) | |
MoveDown | Moves the camera down (in the opposite up direction) | |
MoveForward | Moves the camera forward (in the look direction) | |
MoveLeft | Moves the camera left (strafe) | |
MoveRight | Moves the camera right (strafe) | |
MoveUp | Moves the camera up (in the up direction) | |
StrafeCamera | StrafeCamera moves the camera based on the current camera's LookDirection and UpDirection. | |
TurnTo(Point3D) | Turns the camera to the direction of the specified position | |
TurnTo(Vector3D) | Turns the camera to the specified direction | |
TurnTo(Point3D, Double, FuncDouble, Double) | Turns the camera to the direction of the specified position | |
TurnTo(Vector3D, Double, FuncDouble, Double) | Turns the camera to the specified direction | |
UpdateCamera |
Updates the PerspectiveCamera
(Overrides SphericalCameraUpdateCamera(ProjectionCamera)) |
Name | Description | |
---|---|---|
PositionProperty | PositionProperty |
FirstPersonCamera is a camera that simulates the person's view on the world. It is defined by the Position of the person and the direction of the camera - defined by Heading, Attitude and Bank properties.
FirstPersonCamera also has some other properties that are common to all cameras that derive from SphericalCamera class.
The ShowCameraLight defines when the camera light is shown. The possible values are:
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 FirstPersonCamera 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.
The First person camera also defines methods to simplify the "persons" movement:
MoveForward(Double), MoveBackward(Double), MoveRight(Double), MoveLeft(Double), MoveDown(Double), MoveUp(Double), StrafeCamera(Double, Double, Double) and MoveCamera(Vector3D).
The following xaml creates a Viewport3D with a 3D Box and a FirstPersonCamera that is looking at the Box from (50, 50, 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.
<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 Size="20 20 20" Material="Blue"/> </Viewport3D> <cameras:FirstPersonCamera Position="50 50 100" Heading="45" Attitude="-20"/> <ab3dControls:MouseCameraController/> <ab3dControls:CameraControlPanel VerticalAlignment="Bottom" HorizontalAlignment="Left"/> </Grid> </Page>