Click or drag to resize
AB4D logo

BaseCamera Class

BaseCamera class is the base class for all Ab3d.Cameras. It defines common properties and methods.
Inheritance Hierarchy

Namespace:  Ab3d.Cameras
Assembly:  Ab3d.PowerToys (in Ab3d.PowerToys.dll) Version: 10.1.8147.1045
Syntax
C#
public abstract class BaseCamera : FrameworkElement, 
	ICompositionRenderingSubscriber

The BaseCamera type exposes the following members.

Properties
  NameDescription
Public propertyAnimationController
Gets an AnimationController that is used to animate this camera. When this AnimationController is used to animate the camera, it is possible to control if MouseCameraController can stop the animation when user starts camera rotation or movement by mouse or touch. This is controller with the IsCameraAnimationStoppedOnUserAction property (by default set to true to stop the animation on user action).
Public propertyCameraLight
Gets or sets a Light that is used as a Camera Light. The default value is White DirectionalLight.
Public propertyCameraType
Gets or sets a type of camera. The default camera type value is PerspectiveCamera. The camera type can be also OrthographicCamera.
Public propertyCameraWidth
Gets or sets the width of the camera's viewing box. The property is used when the camera type is set to OrthographicCamera.
Public propertyCurrentCamera
Gets the WPF's ProjectionCamera that is controlled by this Camera.
Public propertyFarPlaneDistance
Gets or sets a value that specifies the distance from the camera of the camera's far clip plane. This is a dependency property.
Public propertyFieldOfView
Gets or sets a value that represents the camera's horizontal field of view in degrees. The property is used when the camera type is set to PerspectiveCamera. Default value is 45 degrees.
Public propertyIsAutoViewport3DFindingEnabled
Gets or sets a Boolean which specifies that if the TargetViewport3D property is not manually set the first Viewport3D is automatically find from the current UserControl, Page or Window. Default value is true.
Protected propertyIsDesignTime
Gets a Boolean that specifies if design time is used.
Public propertyIsDesignTimeInfoIconShown
Gets or sets a Boolean that specifies if Camera info icon is visible in design time. Default value is true.
Public propertyIsRotating
Gets or sets a boolean that specifies if the camera is currently being animated.
Public propertyLookDirection
Gets a Vector3D which defines the look direction of the camera.
Public propertyNearPlaneDistance
Gets or sets a value that specifies the distance from the camera of the camera's near clip plane. This is a dependency property.
Public propertyOffset
Gets or sets a Vector3D that specifies an offset of the camera's position.
Public propertyShowCameraLight
Gets or sets a ShowCameraLightType that specifies when the Cameras light is shown. The default value is ShowCameraLightType.Auto.
Public propertyTargetViewport3D
Gets or sets a Viewport3D whose Camera is controlled by this Ab3d.Camera.
Public propertyTargetViewport3DName
Gets or sets a name of the Viewport3D whose Camera is controlled by this Ab3d.Camera.
Public propertyUpDirection
Gets a Vector3D that represents the upward direction in the scene projection.
Top
Methods
  NameDescription
Protected methodArrangeOverride
override ArrangeOverride - used to display design time info
(Overrides FrameworkElementArrangeOverride(Size).)
Protected methodBaseCreateFrom
This method is called from CreateFrom method and actually sets the properties on this camera.
Protected methodBeginCameraUpdate
BeginCameraUpdate method must be called in each UpdateCamera method, to ensure that the CameraChanged event is fired after all the UpdateCamera methods in all child cameras are called.
Public methodBeginInit
BeginInit
(Overrides FrameworkElementBeginInit.)
Protected methodStatic memberCameraPropertyChanged
Called when a property that updates the camera is changed
Protected methodStatic memberCameraTypePropertyPropertyChanged
Called when CameraType is changed
Protected methodStatic memberCameraWidthPropertyChanged
Called when CameraWidth is changed
Public methodConvertToWpfCamera
ConvertToWpfCamera method converts Ab3d.PowerToys camera to a standard WPF camera.
Public methodCreateFrom
Creates an Ab3d.Camera from a WPF's Camera.
Public methodCreateMouseRay3D(Point, Point3D, Vector3D)
CreateMouseRay3D calculates the 3D ray that goes from the mouse position into the 3D scene. The ray goes from rayOrigin in the rayDirection. If the ray cannot be calculated this method returns false.
Public methodStatic memberCreateMouseRay3D(Point, Size, Matrix3D, Matrix3D, Point3D, Vector3D) Obsolete.
CreateMouseRay3D calculates a normalized 3D ray that goes from the mouse position into the 3D scene. The ray goes from rayOrigin in the rayDirection. If the ray cannot be calculated this method returns false.
Protected methodCreateNewCamera(Viewport3D)
Creates a new Camera for the viewport3D
Protected methodCreateNewCamera(BaseCameraCameraTypes)
Creates a new Camera for the cameraType.
Protected methodCreateNewCamera(Viewport3D, BaseCameraCameraTypes)
Creates a new Camera for the viewport3D and cameraType.
Public methodStatic memberCreateOrthographicMouseRay3D
CreateOrthographicMouseRay3D is used for orthographic camera and calculates a normalized 3D ray that goes from the mouse position into the 3D scene for an Orthographic camera. The ray goes from rayOrigin in the rayDirection. If the ray cannot be calculated this method returns false. For perspective camera use CreatePerspectiveMouseRay3D(Point, Size, Matrix3D, Matrix3D, Point3D, Vector3D) or use non-static CreateMouseRay3D(Point, Point3D, Vector3D) method.
Public methodStatic memberCreatePerspectiveMouseRay3D
CreatePerspectiveMouseRay3D is used for perspective camera and calculates a normalized 3D ray that goes from the mouse position into the 3D scene. The ray goes from rayOrigin in the rayDirection. If the ray cannot be calculated this method returns false. For orthographic camera use CreateOrthographicMouseRay3D(Point, Size, Point3D, Vector3D, Vector3D, Double, Double, Point3D, Vector3D) or use non-static CreateMouseRay3D(Point, Point3D, Vector3D) method.
Protected methodEndCameraUpdate
EndCameraUpdate method must be called in each UpdateCamera method, to ensure that the CameraChanged event is fired after all the UpdateCamera methods in all child cameras are called.
Public methodEndInit
EndInit
(Overrides FrameworkElementEndInit.)
Protected methodStatic memberFarPlaneDistancePropertyChanged
Called when FarPlaneDistance is changed
Protected methodStatic memberFieldOfViewPropertyChanged
Called when FieldOfView is changed
Protected methodForceRefresh
Forces a refresh of the camera.
Public methodGetCameraMatrices(Matrix3D, Matrix3D)
GetCameraMatrices gets view and projection matrix of the current camera.
Public methodStatic memberGetCameraMatrices(Viewport3D, Matrix3D, Matrix3D)
GetCameraMatrices gets view and projection matrix of the camera used by the specified viewport3D.
Public methodStatic memberGetCameraMatrices(Camera, Double, Matrix3D, Matrix3D)
GetCameraMatrices gets view and projection matrix of specified camera and specified viewport's aspect ratio.
Public methodStatic memberGetCameraMatrices(BaseCamera, Double, Matrix3D, Matrix3D)
GetCameraMatrices gets view and projection matrix of specified Ab3d.PowerToys camera and specified viewport's aspect ratio. The method sets matrices even if TargetViewport3D is not assigned to the camera.
Public methodGetCameraMatrixes(Matrix3D, Matrix3D)
GetCameraMatrixes gets view and projection matrix of the current camera.
Public methodStatic memberGetCameraMatrixes(Viewport3D, Matrix3D, Matrix3D)
GetCameraMatrixes gets view and projection matrix of the camera used by the specified viewport3D.
Public methodStatic memberGetCameraMatrixes(Camera, Double, Matrix3D, Matrix3D)
GetCameraMatrixes gets view and projection matrix of specified camera and specified viewport's aspect ratio.
Public methodStatic memberGetCameraMatrixes(BaseCamera, Double, Matrix3D, Matrix3D)
GetCameraMatrixes gets view and projection matrix of specified Ab3d.PowerToys camera and specified viewport's aspect ratio. The method sets matrixes even if TargetViewport3D is not assigned to the camera.
Public methodGetCameraPlaneOrientation(Vector3D, Vector3D, Vector3D)
GetCameraPlaneOrientation gets plane's width and height vectors that can be used to orient the plane 3D model so that it is aligned with the camera view.
Public methodStatic memberGetCameraPlaneOrientation(ProjectionCamera, Vector3D, Vector3D, Vector3D)
GetCameraPlaneOrientation sets plane width and height vectors that can be used to orient the plane 3D model so that it is aligned with the camera view.
Public methodGetCameraPosition
Gets the position of the camera.
Public methodGetMousePositionOnPlane
GetMousePositionOnPlane calculates a position where a ray from mouse position intersects a plane. Returns false if there is no intersection.
Public methodGetScreenSize
GetScreenSize calculates a size on screen (in same units as size of Viewport3D.Width - without DPI scale) of a Size in 3D space (worldSize) that is at distanceFromCamera and shown with this camera and in TargetViewport3D.
Public methodGetTargetViewport3DSceneBounds
Returns a Rect3D that represents the bounding box of the 3D scene defined in the TargetViewport3D.
Public methodGetWorldSize
GetWorldSize calculates a size in 3D world coordinates from a size provided in 2D screen coordinates. The calculation is based on the this camera and the screen size of TargetViewport3D.
Public methodGetWorldToViewportMatrix
Gets Matrix3D that can be used to convert 3D coordinates to 2D viewport (screen) coordinates. If the method returns true, than the worldToViewportMatrix was set; if false is returned than the matrix cannot be calculated.
Protected methodGetWPFCameraDirections
The method gets lookDirection and upDirection from WPF's camera
Protected methodGetWPFCameraPosition
Returns a Position of the WPF camera.
Protected methodInitInfoElement
Initializes the info element that is used for design time support
Protected methodStatic memberIsDesignTimeInfoIconShownPropertyChanged
Called when IsDesignTimeInfoIconShown is changed
Public methodIsValid
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.
Public methodLine3DTo2D(Point3D, Point3D, Point, Point)
Converts a 3D line that is defined by startPositionWorld and endPositionWorld to a line on the screen that is defined by startPositionScreen and endPositionScreen. This method correctly handles the case when the 3D line crosses the camera near plane (goes behind the camera). In this case the line needs to be cropped at the camera near plane.
Public methodLine3DTo2D(Point3D, Point3D, Size, Point, Point)
Converts a 3D line that is defined by startPositionWorld and endPositionWorld to a line on the screen that is defined by startPositionScreen and endPositionScreen. The method takes a custom Viewport3D size and does not require that this Camera class is connected to real Viewport3D. This method correctly handles the case when the 3D line crosses the camera near plane (goes behind the camera). In this case the line needs to be cropped at the camera near plane.
Protected methodMeasureOverride
override MeasureOverride - used to display design time info
(Overrides FrameworkElementMeasureOverride(Size).)
Protected methodStatic memberNearPlaneDistancePropertyChanged
Called when NearPlaneDistance is changed
Protected methodOnCameraChanged
Called to raise CameraChangedRoutedEvent
Protected methodOnCameraLoaded
OnCameraLoaded methods ensures that the CurrentCamera is set
Protected methodOnIsRotatingChanged
OnIsRotatingChanged is caled to fire IsRotatingChanged event.
Protected methodOnIsValidChanged
OnIsValidChanged is called on IsValidChanged event. The event is subscribed by calling SubscribeToIsValidChanged and unsubscribed by calling UnsubscribeFromIsValidChanged.
Protected methodStatic memberOnPreviewCameraChanged
OnPreviewCameraChanged calls the PreviewCameraChangedEvent routed event.
Protected methodOnRender
OnRender
(Overrides UIElementOnRender(DrawingContext).)
Protected methodOnRendering
Called when Rendering event is subscribed
Protected methodOnTargetViewport3DChanged
OnTargetViewport3DChanged is called when the TargetViewport3D is changed
Public methodPoint3DTo2D(Point3D)
Converts a Point3D to the Point 2D on the screen.
Public methodPoint3DTo2D(Point3D, Size)
Converts a Point3D to the Point 2D on the screen with custom Viewport3D size (no need that this Camera class is connected to real Viewport3D)
Public methodPoints3DTo2D(IListPoint3D, Point, Transform3D, Boolean)
Points3DTo2D calculates 2D screen positions from the specified 3D positions. Calculated screen positions are stored into the specified points2D array (its size must be at least the size of the 3D positions).
Public methodPoints3DTo2D(Point3D, Point, Transform3D, Boolean)
Points3DTo2D calculates 2D screen positions from the specified 3D positions. Calculated screen positions are stored into the specified points2D array (its size must be at least the size of the 3D positions).
Public methodRect3DTo2D
Converts a Rect3D to the Rect 2D on the screen.
Public methodRefresh
Refresh method refreshes the camera.
Protected methodRefreshCurrentCamera
Refreshes the CurrentCamera - check if TargetViewport3D is null and tries to find it, also creates a new camera is necessary
Public methodRenderToBitmap(Brush, Int32)
Renders TargetViewport3D to bitmap with specifed backgroundBrush and dpi. The size of the created bitmap is the same as the size of the TargetViewport3D.
Public methodRenderToBitmap(Int32, Int32, Int32, Brush, Int32)
Renders TargetViewport3D to bitmap. It is possible to specify custom bitmap width and height (when customWidth and customHeight are bigger than 0). When antialiasingLevel is bigger than 1, the bitmap is rendered into bigger image and than scaled down to create an antialiasing effect.
Public methodRotateCamera
Rotates the camera for the specified heading and attitude
Public methodStartRotation(Double, Double)
StartRotation method immediately starts Heading and Attitude animation for this camera. To slowly start the camera rotation and than accelerating the rotation, use the StartRotation(Double, Double, Double, BaseCameraEasingFunctionDelegate) method.
Public methodStartRotation(Double, Double, Double, BaseCameraEasingFunctionDelegate)
StartRotation method immediately starts Heading and Attitude animation for this camera. To slowly start the camera rotation and than accelerating the rotation, use the StartRotation(Double, Double, Double, BaseCameraEasingFunctionDelegate) method.
Public methodStopRotation
StopRotation immediately stops the animation of the camera. To slowly stop the camera rotation with preserving the camera's inertia, use the StopRotation(Double, BaseCameraEasingFunctionDelegate) method.
Public methodStopRotation(Double, BaseCameraEasingFunctionDelegate)
StopRotation slowly stops the animation of the camera with preserving the rotation inertia.
Protected methodSubscribeRenderingEvent
Subscribe to Rendering event
Protected methodSubscribeToIsValidChanged
SubscribeToIsValidChanged
Protected methodStatic memberTargetViewport3DPropertyChanged
Called when a property that updates the camera is changed
Protected methodTryToUpdate
Update the Camera if it is already initialized and is not in a batch updated (using BeginInit)
Protected methodUnsubscribeFromIsValidChanged
UnsubscribeFromIsValidChanged
Protected methodUnsubscribeRenderingEvent
Unsubscribe to Rendering event
Protected methodUpdateCamera
Updates the CurrentCamera
Protected methodUpdateCameraLight
Updates the camera light if needed
Protected methodUpdateCameraLightData
Updates the CameraLight based on the current camera position
Protected methodUpdateWorldToViewportMatrix
Updates the worldToViewportMatrix if needed
Top
Events
  NameDescription
Public eventCameraChanged
Notify that the current camera has changed
Public eventIsRotatingChanged
IsRotatingChanged event is fired when the IsRotating is changed.
Public eventIsValidChanged
Notify that camera has become valid (for example after the size of the TargetViewport3D is set) or invalid. To get the new state of the camera, call the IsValid(Boolean) method.
Public eventPreviewCameraChanged
Notify that the current camera is about to change - user can set Handled property to true to prevent the change.
Top
Fields
  NameDescription
Public fieldStatic memberCameraChangedEvent
CameraChangedChangedEvent
Public fieldStatic memberCameraLightProperty
CameraLightProperty
Public fieldStatic memberCameraTypeProperty
CameraTypeProperty
Public fieldStatic memberCameraWidthProperty
FieldOfViewProperty
Public fieldStatic memberFarPlaneDistanceProperty
FarPlaneDistanceProperty
Public fieldStatic memberFieldOfViewProperty
FieldOfViewProperty
Protected fieldinfoElement
info element that is displayed in design time
Public fieldStatic memberIsAutoViewport3DFindingEnabledProperty
IsAutoViewport3DFindingEnabledProperty
Public fieldStatic memberIsDesignTimeInfoIconShownProperty
IsDesignTimeInfoIconShownProperty
Protected fieldisDirty
if true the camera needs to be recalculated
Protected fieldisInitializing
if true the camera is being initialized
Protected fieldisWorldToViewportMatrixDirty
if true the worldToViewportMatrix needs to be recalculated. Used for Point3DTo2D and Rect3DTo2D.
Protected fieldisworldToViewportMatrixValid
if false the WorldToViewportMatrix cannot be calculated (is not invertible, etc.) Used for Point3DTo2D and Rect3DTo2D.
Public fieldStatic memberNearPlaneDistanceProperty
NearPlaneDistanceProperty
Public fieldStatic memberOffsetProperty
OffsetProperty
Public fieldStatic memberPreviewCameraChangedEvent
PreviewCameraChangedEvent
Public fieldStatic memberShowCameraLightProperty
ShowCameraLightProperty
Public fieldStatic memberTargetViewport3DNameProperty
TargetViewport3DNameProperty
Public fieldStatic memberTargetViewport3DProperty
TargetViewport3DProperty
Protected fieldworldToViewportMatrix
WordlsToViewport matrix. Used for Point3DTo2D and Rect3DTo2D.
Top
See Also