Click or drag to resize
Ab4d.SharpEngine logo

FreeCamera Class

FreeCamera is a camera that is not defined by heading, attitude and bank angle. The camera is not limited to rotation around the up axis. Instead, the camera is defined by CameraPosition, TargetPosition and UpDirection.
Inheritance Hierarchy
SystemObject
  Ab4d.SharpEngine.CamerasCamera
    Ab4d.SharpEngine.CamerasFreeCamera

Namespace: Ab4d.SharpEngine.Cameras
Assembly: Ab4d.SharpEngine (in Ab4d.SharpEngine.dll) Version: 2.0.8956+4c7684e186ca1be74e7a284fbe739d9a1b843d3c
Syntax
C#
public class FreeCamera : Camera, IFreeCamera, 
	ITargetPositionCamera, ICameraPositionCamera, IRotationCenterPositionCamera, IFitIntoViewCamera

The FreeCamera type exposes the following members.

Constructors
 NameDescription
Public methodFreeCamera Constructor
Top
Properties
 NameDescription
Public propertyCameraPosition Gets the position of the camera as Vector3.
Public propertyRotationCenterPosition Gets or sets a nullable Vector3 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 propertyRotationUpAxis Gets or sets a nullable Vector3 that can specify a custom rotation up axis that is used to when camera is rotated "horizontally" (e.g when user drags the mouse horizontally). When RotationUpAxis is not set (is null) then camera rotates around the current camera's UpDirection. This provides the standard free camera experience and is the default setting.
Public propertyTargetPosition Gets the camera look position as Vector3.
Public propertyUpDirection Gets or sets the camera the up direction as Vector3.
Top
Methods
 NameDescription
Public methodCalculateCurrentUpDirection CalculateCurrentUpDirection calculates the UpDirection from the current values of CameraPosition and TargetPosition.
Public methodStatic memberCalculateUpDirection CalculateUpDirection calculates the up direction from the specified properties.
Public methodFitIntoView(BoundingBox, Boolean, Single, Boolean) FitIntoView adjusts the camera's Distance (for PerspectiveCamera) or ViewWidth (for OrthographicCamera) and TargetPosition (if adjustTargetPosition is true) so that the specified BoundingBox will be visible from one edge of the SceneView to another edge.
Public methodFitIntoView(FitIntoViewType, Boolean, Single, Boolean) FitIntoView adjusts the camera's Distance (for PerspectiveCamera) or ViewWidth (for OrthographicCamera) and TargetPosition (if adjustTargetPosition is true) so that all the objects on the scene will be visible from one edge of the SceneView to another edge. This is the same as calling FitIntoView and passing Scene.RootNode as parameter.
Public methodFitIntoView(Vector3, Boolean, Single, Boolean) FitIntoView adjusts the camera's Distance (for PerspectiveCamera) or ViewWidth (for OrthographicCamera) and TargetPosition (if adjustTargetPosition is true) so that all the specified positions will be visible from one edge of the viewport to another edge.
Public methodFitIntoView(SceneNode, FitIntoViewType, Boolean, Single, Boolean) FitIntoView adjusts the camera's Distance (for PerspectiveCamera) or ViewWidth (for OrthographicCamera) and TargetPosition (if adjustTargetPosition is true) so that the specified sceneNode (or all child SceneNodes if sceneNode is GroupNode) will be visible from one edge of the SceneView to another edge.
Public methodGetCameraPosition Returns the current position of the camera.
(Overrides CameraGetCameraPosition)
Public methodGetFitIntoViewDistanceOrViewWidth(SceneNode, FitIntoViewType, Boolean, Vector3) GetFitIntoViewDistanceOrViewWidth returns a Distance (for PerspectiveCamera) or a ViewWidth (for OrthographicCamera) and sets the newTargetPosition that will adjust the camera so that all the specified sceneNodes will be visible from one edge of the viewport to another edge.
Public methodGetFitIntoViewDistanceOrViewWidth(Vector3, FitIntoViewType, Boolean, Vector3) GetFitIntoViewDistanceOrViewWidth returns a Distance (for PerspectiveCamera) or a ViewWidth (for OrthographicCamera) and sets the newTargetPosition that will adjust the camera so that all the specified positions will be visible from one edge of the viewport to another edge.
Public methodGetLookDirection Returns the normalized look direction of the camera.
(Overrides CameraGetLookDirection)
Public methodGetRotatedCamera GetRotatedCamera method calculates rotatedCameraPosition, rotatedTargetPosition and rotatedUpDirection based on the rotating the camera from the initial camera position and direction.
Public methodGetUpDirection Returns the normalized up direction of the camera.
(Overrides CameraGetUpDirection)
Protected methodOnSceneViewChanged OnSceneViewChanged
(Overrides CameraOnSceneViewChanged)
Public methodRotateCamera(Single, Single) Rotates the free camera for the specified heading and attitude. When RotationCenterPosition is set, the camera rotates around RotationCenterPosition which changes the TargetPosition and CameraPosition.
(Overrides CameraRotateCamera(Single, Single))
Public methodRotateCamera(Single, Single, Single) Rotates the free camera for the specified heading, attitude and bank. When RotationCenterPosition is set, the camera rotates around RotationCenterPosition which changes the TargetPosition and CameraPosition.
Public methodUpdate Update method updates the camera matrices when needed (when there were any change in the camera properties) or when forceMatrixUpdate is set to true.
(Overrides CameraUpdate(Boolean))
Top
Remarks

FreeCamera is a camera that is not defined by heading, attitude and bank angle. The camera is not limited to rotation around the up axis. Instead, the camera is defined by CameraPosition, TargetPosition and UpDirection.

When only CameraPosition and TargetPosition are set, then it is possible to calculate the UpDirection by calling the CalculateCurrentUpDirection method.

When FreeCamera is used with a PointerCameraController, then by default user can freely rotate the camera around any axis. Tip: clockwise and anti-clockwise mouse movement can rotate the axis of the camera.

To fix the camera rotation axis, it is possible to set the RotationUpAxis property. For example when the default coordinate system is used and the RotationUpAxis is set to (0, 1, 0), then when FreeCamera is controller PointerCameraController it by behaves the same as TargetPositionCamera.

Example

The following code creates a FirstPersonCamera and assign it to the SceneView:

C#
var freeCamera = new FreeCamera()
{
    CameraPosition = new Vector3(0, 20, 300),
    TargetPosition = new Vector3(0, 30, 0),
    UpDirection = new Vector3(0, 1, 0)
};

sceneView.Camera = freeCamera;
See Also