Castle Game Engine: CastleCameras: Class TCamera

# Class TCamera
Description | Hierarchy | Fields | Methods | Properties
## Unit CastleCameras ## Declaration `type TCamera = class(TInputListener)` ## Description Handle user navigation in 3D scene. You control camera parameters and provide user input to this class by various methods and properties. You can investigate the current camera configuration by many methods, the most final is the Matrix method that generates a simple 4x4 camera matrix. This class is not tied to any OpenGL specifics, any VRML specifics, and CastleWindow etc. — this class is fully flexible and may be used in any 3D program, whether using CastleWindow, OpenGL etc. or not. Various `TCamera` descendants implement various navigation methods, for example TExamineCamera allows the user to rotate and scale the model (imagine that you're holding a 3D model in your hands and you look at it from various sides) and TWalkCamera implements typical navigation in the style of first-person shooter games. The most comfortable way to use a camera is with a scene manager (TCastleSceneManager). You can create your camera instance, call it's `Init` method (this is initializes most important properties), and assign it to TCastleSceneManager.Camera property. This way SceneManager will pass all necessary window events to the camera, and when drawing SceneManager will load camera matrix like `glLoadMatrix(Camera.Matrix);`. In fact, if you do not assign anything to TCastleSceneManager.Camera property, then the default camera will be created for you. So when using TCastleSceneManager, you do not have to do anything to use a camera — default camera will be created and automatically used for you. ## Hierarchy TComponent TInputListener TCamera ## Overview ### Fields
| `MouseDraggingStarted: Integer;`
| `MouseDraggingStart: TVector2Single;`
| `internal const DefaultRadius = 0.25;`
| `internal const DefaultInput = [ciNormal, ciMouseDragging, ci3dMouse];`
### Methods
| `procedure BeginVisibleChangeSchedule;`
| `procedure ScheduleVisibleChange;`
| `procedure EndVisibleChangeSchedule;`
| `procedure SetInput(const Value: TCameraInputs); virtual;`
| `procedure SetEnableDragging(const Value: boolean); virtual;`
| `function GetIgnoreAllInputs: boolean;`
| `procedure SetIgnoreAllInputs(const Value: boolean);`
| `procedure SetProjectionMatrix(const Value: TMatrix4Single); virtual;`
| `procedure SetRadius(const Value: Single); virtual;`
| `constructor Create(AOwner: TComponent); override;`
| `procedure VisibleChange; override;`
| `function Matrix: TMatrix4Single; virtual; abstract;`
| `function RotationMatrix: TMatrix4Single; virtual; abstract;`
| `procedure GetView(out APos, ADir, AUp: TVector3Single); virtual; abstract;`
| `procedure GetView(out APos, ADir, AUp, AGravityUp: TVector3Single); virtual; abstract;`
| `function GetPosition: TVector3Single; virtual; abstract;`
| `function GetGravityUp: TVector3Single; virtual; abstract;`
| `procedure SetView(const APos, ADir, AUp: TVector3Single; const AdjustUp: boolean = true); virtual; abstract;`
| `procedure SetView(const APos, ADir, AUp, AGravityUp: TVector3Single; const AdjustUp: boolean = true); virtual; abstract;`
| `procedure Ray(const WindowPosition: TVector2Single; const Projection: TProjection; out RayOrigin, RayDirection: TVector3Single);`
| `procedure MouseRay( const Projection: TProjection; out RayOrigin, RayDirection: TVector3Single);`
| `procedure CustomRay( const Viewport: TRectangle; const WindowPosition: TVector2Single; const Projection: TProjection; out RayOrigin, RayDirection: TVector3Single);`
| `procedure Update(const SecondsPassed: Single; var HandleInput: boolean); override;`
| `function Press(const Event: TInputPressRelease): boolean; override;`
| `function Release(const Event: TInputPressRelease): boolean; override;`
| `procedure AnimateTo(OtherCamera: TCamera; const Time: TFloatTime);`
| `procedure AnimateTo(const Pos, Dir, Up: TVector3Single; const Time: TFloatTime);`
| `function Animation: boolean; virtual;`
| `procedure SetInitialView( const AInitialPosition: TVector3Single; AInitialDirection, AInitialUp: TVector3Single; const TransformCurrentCamera: boolean); virtual;`
| `procedure GoToInitial; virtual;`
| `function GetNavigationType: TNavigationType; virtual; abstract;`
### Properties
| `property IgnoreAllInputs: boolean read GetIgnoreAllInputs write SetIgnoreAllInputs default false; deprecated;`
| `property Frustum: TFrustum read FFrustum;`
| `property ProjectionMatrix: TMatrix4Single read FProjectionMatrix write SetProjectionMatrix;`
| `property Radius: Single read FRadius write SetRadius default DefaultRadius;`
| `property InitialPosition : TVector3Single read FInitialPosition;`
| `property InitialDirection: TVector3Single read FInitialDirection;`
| `property InitialUp : TVector3Single read FInitialUp;`
| `property EnableDragging: boolean read FEnableDragging write SetEnableDragging;`
| `property Input: TCameraInputs read FInput write SetInput default DefaultInput;`
## Description ### Fields
| `MouseDraggingStarted: Integer;`
Needed for ciMouseDragging navigation. Checking `MouseDraggingStarted` means that we handle only dragging that was initialized on viewport (since the viewport passed events to camera). `MouseDraggingStarted` -1 means none, otherwise it's the finder index (to support multitouch).
| `MouseDraggingStart: TVector2Single;`
| `internal const DefaultRadius = 0.25;`
Default value for TCamera.Radius. Matches the default VRML/X3D NavigationInfo.avatarSize[0].
| `internal const DefaultInput = [ciNormal, ciMouseDragging, ci3dMouse];`
### Methods
| `procedure BeginVisibleChangeSchedule;`
Mechanism to schedule VisibleChange calls. This mechanism allows to defer calling VisibleChange. Idea: `BeginVisibleChangeSchedule` increases internal VisibleChangeSchedule counter, EndVisibleChangeSchedule decreases it and calls actual VisibleChange if counter is zero and some ScheduleVisibleChange was called in between. When ScheduleVisibleChange is called when counter is zero, VisibleChange is called immediately, so it's safe to always use ScheduleVisibleChange instead of direct VisibleChange in this class.
| `procedure ScheduleVisibleChange;`
| `procedure EndVisibleChangeSchedule;`
| `procedure SetInput(const Value: TCameraInputs); virtual;`
| `procedure SetEnableDragging(const Value: boolean); virtual;`
| `function GetIgnoreAllInputs: boolean;`
| `procedure SetIgnoreAllInputs(const Value: boolean);`
| `procedure SetProjectionMatrix(const Value: TMatrix4Single); virtual;`
| `procedure SetRadius(const Value: Single); virtual;`
| `constructor Create(AOwner: TComponent); override;`
| `procedure VisibleChange; override;`
Called always when some visible part of this control changes. In the simplest case, this is used by the controls manager to know when we need to redraw the control. In case of the TCamera class, we assume that changes to the TCamera.Matrix, and other properties (for example even changes to TWalkCamera.MoveSpeed), are "visible", and they also result in this event.
| `function Matrix: TMatrix4Single; virtual; abstract;`
Current camera matrix. You should multiply every 3D point of your scene by this matrix, which usually simply means that you should do `glLoadMatrix` or `glMultMatrix` of this matrix.
| `function RotationMatrix: TMatrix4Single; virtual; abstract;`
Extract only rotation from your current camera Matrix. This is useful for rendering skybox in 3D programs (e.g. for VRML/X3D Background node) and generally to transform directions between world and camera space. It's guaranteed that this is actually only 3x3 matrix, the 4th row and 4th column are all zero except the lowest right item which is 1.0.
| `procedure GetView(out APos, ADir, AUp: TVector3Single); virtual; abstract;`
Express current view as camera vectors: position, direction, up. Returned Dir and Up must be orthogonal. Returned Dir and Up and GravityUp are already normalized.
| `procedure GetView(out APos, ADir, AUp, AGravityUp: TVector3Single); virtual; abstract;`
| `function GetPosition: TVector3Single; virtual; abstract;`
| `function GetGravityUp: TVector3Single; virtual; abstract;`
| `procedure SetView(const APos, ADir, AUp: TVector3Single; const AdjustUp: boolean = true); virtual; abstract;`
Set camera view from vectors: position, direction, up. Direction, Up and GravityUp do not have to be normalized, we will normalize them internally if necessary. But make sure they are non-zero. We will automatically fix Direction and Up to be orthogonal, if necessary: when AdjustUp = `True` (the default) we will adjust the up vector (preserving the given direction value), otherwise we will adjust the direction (preserving the given up value).
| `procedure SetView(const APos, ADir, AUp, AGravityUp: TVector3Single; const AdjustUp: boolean = true); virtual; abstract;`
| `procedure Ray(const WindowPosition: TVector2Single; const Projection: TProjection; out RayOrigin, RayDirection: TVector3Single);`
Calculate a 3D ray picked by the WindowX, WindowY position on the window. Uses current Container, which means that you have to add this camera to TCastleWindowCustom.Controls or TCastleControlCustom.Controls before using this method. Projection (read-only here) describe your projection, required for calculating the ray properly. Resulting RayDirection is always normalized. WindowPosition is given in the same style as TUIContainer.MousePosition: (0, 0) is bottom-left.
| `procedure MouseRay( const Projection: TProjection; out RayOrigin, RayDirection: TVector3Single);`
Calculate a ray picked by current mouse position on the window. Uses current Container (both to get it's size and to get current mouse position), which means that you have to add this camera to TCastleWindowCustom.Controls or TCastleControlCustom.Controls before using this method. ###### See also Ray Calculate a 3D ray picked by the WindowX, WindowY position on the window. CustomRay Calculate a ray picked by WindowPosition position on the viewport, assuming current viewport dimensions are as given.
| `procedure CustomRay( const Viewport: TRectangle; const WindowPosition: TVector2Single; const Projection: TProjection; out RayOrigin, RayDirection: TVector3Single);`
Calculate a ray picked by WindowPosition position on the viewport, assuming current viewport dimensions are as given. This doesn't look at our container sizes at all. Projection (read-only here) describe projection, required for calculating the ray properly. Resulting RayDirection is always normalized. WindowPosition is given in the same style as TUIContainer.MousePosition: (0, 0) is bottom-left.
| `procedure Update(const SecondsPassed: Single; var HandleInput: boolean); override;`
| `function Press(const Event: TInputPressRelease): boolean; override;`
| `function Release(const Event: TInputPressRelease): boolean; override;`
| `procedure AnimateTo(OtherCamera: TCamera; const Time: TFloatTime);`
Animate a camera smoothly into another camera settings. This will gradually change our settings (only the most important settings, that determine actual camera view, i.e. Matrix result) into another camera. Current OtherCamera settings will be internally copied during this call. So you can even free OtherCamera instance immediately after calling this. When we're during camera animation, Update doesn't do other stuff (e.g. gravity for TWalkCamera doesn't work, rotating for TExamineCamera doesn't work). This also means that the key/mouse controls of the camera do not work. Instead, we remember the source and target position (at the time AnimateTo was called) of the camera, and smoothly interpolate camera parameters to match the target. Once the animation stops, Update goes back to normal: gravity in TWalkCamera works again, rotating in TExamineCamera works again etc. Calling AnimateTo while the previous animation didn't finish yet is OK. This simply cancels the previous animation, and starts the new animation from the current position. Descendants implementors notes: In this class, almost everything is handled (through GetView / SetView). In descendants you have to only ignore key/mouse/Update events when IsAnimation is `True`. (Although each Update would override the view anyway, but for stability it's best to explicitly ignore them — you never know how often Update will be called.)
| `procedure AnimateTo(const Pos, Dir, Up: TVector3Single; const Time: TFloatTime);`
| `function Animation: boolean; virtual;`
| `procedure SetInitialView( const AInitialPosition: TVector3Single; AInitialDirection, AInitialUp: TVector3Single; const TransformCurrentCamera: boolean); virtual;`
Set three initial camera vectors. AInitialDirection and AInitialUp will be automatically normalized. Corresponding properties (InitialDirection and InitialUp) will always contain normalized values. AInitialUp will be also automatically corrected to be orthogonal to AInitialDirection. We will correct AInitialUp to make it orthogonal, but still preserving the plane they were indicating together with AInitialDirection. Do not ever give here AInitialUp that is parallel to AInitialDirection. If TransformCurrentCamera = `True`, then they will also try to change current camera relative to the initial vectors changes. This implements VRML/X3D desired behavior that "viewer position/orientation is conceptually a child of viewpoint position/orientation, and when viewpoint position/orientation changes, viewer should also change".
| `procedure GoToInitial; virtual;`
Jump to initial camera view (set by SetInitialView).
| `function GetNavigationType: TNavigationType; virtual; abstract;`
### Properties
| `property IgnoreAllInputs: boolean read GetIgnoreAllInputs write SetIgnoreAllInputs default false; deprecated;`
Warning: this symbol is deprecated. Deprecated, use more flexible Input instead. ``IgnoreAllInputs` := true` is equivalent to `Input := []`, ``IgnoreAllInputs` := false` is equivalent to `Input := DefaultInput`.
| `property Frustum: TFrustum read FFrustum;`
The current camera (viewing frustum, based on ProjectionMatrix (set by you) and Matrix (calculated here). This is recalculated whenever one of these two properties change. Be sure to set ProjectionMatrix before using this.
| `property ProjectionMatrix: TMatrix4Single read FProjectionMatrix write SetProjectionMatrix;`
Projection matrix that you should pass here to have Frustum calculated for you. This is initially IdentityMatrix4Single. This is not modified anywhere from this class. *You* should modify it, you should set it to projection matrix that you use, if you want to use Frustum value. This is used whenever Frustum is recalculated.
| `property Radius: Single read FRadius write SetRadius default DefaultRadius;`
The radius of a sphere around the camera that makes collisions with the world. Collision detection routines use this. It determines the projection near plane (that must be slightly smaller than this radius) for 3D rendering. Walk camera uses this for automatically correcting PreferredHeight, otherwise weird things could happen if your avatar height is too small compared to camera radius. See CorrectPreferredHeight. Especially useful if you let user change PreferredHeight at runtime by Input_IncreasePreferredHeight, Input_DecreasePreferredHeight. This is actually the whole use of Radius inside CastleCameras unit and classes. But the code all around the engine also looks for this Radius, and the camera is a natural place to keep this information.
| `property InitialPosition : TVector3Single read FInitialPosition;`
Initial camera values. InitialDirection and InitialUp must be always normalized, and orthogonal. Default value of `InitialPosition` is (0, 0, 0), InitialDirection is DefaultCameraDirection = (0, -1, 0), InitialUp is DefaultCameraUp = (0, 1, 0).
| `property InitialDirection: TVector3Single read FInitialDirection;`
| `property InitialUp : TVector3Single read FInitialUp;`
| `property EnableDragging: boolean read FEnableDragging write SetEnableDragging;`
Is mouse dragging allowed by scene manager. This is an additional condition to enable mouse dragging, above the existing ciMouseDragging in Input. It is set internally by scene manager, to prevent camera navigation by dragging when we already drag a 3D item (like X3D TouchSensor).
| `property Input: TCameraInputs read FInput write SetInput default DefaultInput;`
Input methods available to user. See documentation of TCameraInput type for possible values and their meaning. To disable any user interaction with camera (for example, to implement X3D "NONE" navigation type) you can simply set this to empty.
Generated by PasDoc 0.13.0 on 2015-06-15 04:43:09