Castle Game Engine: Castle3D: Class T3DCustomTransform

# Class T3DCustomTransform
Description | Hierarchy | Fields | Methods | Properties
## Unit Castle3D ## Declaration `type T3DCustomTransform = class(T3DList)` ## Description Transform (move, rotate, scale) other T3D objects. Descends from T3DList, transforming all it's children. Also adds gravity and related features. `T3DCustomTransform` is an abstract class, that doesn't define how the transformation is stored and accessed. Descendants define it by overriding protected virtual methods like GetTranslation and GetRotation (in this class they return zeros). Use T3DTransform to have simple T3DTransform.Translation and such properties. Use T3DOrient to have camera-like transformation vectors. ## Hierarchy TComponent T3D T3DList T3DCustomTransform ## Overview ### Fields
| `internal const DefaultMiddleHeight = 0.5;`
### Methods
| `function GetTranslation: TVector3Single; virtual;`
| `function GetCenter: TVector3Single; virtual;`
| `function GetRotation: TVector4Single; virtual;`
| `function GetScale: TVector3Single; virtual;`
| `function GetScaleOrientation: TVector4Single; virtual;`
| `function OnlyTranslation: boolean; virtual;`
| `function Transform: TMatrix4Single;`
| `function TransformInverse: TMatrix4Single;`
| `procedure TransformMatricesMult(var M, MInverse: TMatrix4Single); virtual;`
| `procedure TransformMatrices(out M, MInverse: TMatrix4Single);`
| `function AverageScale: Single;`
| `function HeightCollision(const Position, GravityUp: TVector3Single; const TrianglesToIgnoreFunc: T3DTriangleIgnoreFunc; out AboveHeight: Single; out AboveGround: P3DTriangle): boolean; override;`
| `function MoveCollision( const OldPos, ProposedNewPos: TVector3Single; out NewPos: TVector3Single; const IsRadius: boolean; const Radius: Single; const OldBox, NewBox: TBox3D; const TrianglesToIgnoreFunc: T3DTriangleIgnoreFunc): boolean; override;`
| `function MoveCollision( const OldPos, NewPos: TVector3Single; const IsRadius: boolean; const Radius: Single; const OldBox, NewBox: TBox3D; const TrianglesToIgnoreFunc: T3DTriangleIgnoreFunc): boolean; override;`
| `function SegmentCollision(const Pos1, Pos2: TVector3Single; const TrianglesToIgnoreFunc: T3DTriangleIgnoreFunc; const ALineOfSight: boolean): boolean; override;`
| `function SphereCollision(const Pos: TVector3Single; const Radius: Single; const TrianglesToIgnoreFunc: T3DTriangleIgnoreFunc): boolean; override;`
| `function BoxCollision(const Box: TBox3D; const TrianglesToIgnoreFunc: T3DTriangleIgnoreFunc): boolean; override;`
| `function RayCollision(const RayOrigin, RayDirection: TVector3Single; const TrianglesToIgnoreFunc: T3DTriangleIgnoreFunc): TRayCollision; override;`
| `procedure Fall(const FallHeight: Single); virtual;`
| `function LocalBoundingBox: TBox3D;`
| `constructor Create(AOwner: TComponent); override;`
| `function BoundingBox: TBox3D; override;`
| `procedure Render(const Frustum: TFrustum; const Params: TRenderParams); override;`
| `procedure RenderShadowVolume( ShadowVolumeRenderer: TBaseShadowVolumeRenderer; const ParentTransformIsIdentity: boolean; const ParentTransform: TMatrix4Single); override;`
| `function Middle: TVector3Single; override;`
| `procedure Update(const SecondsPassed: Single; var RemoveMe: TRemoveType); override;`
| `function OutsideToLocal(const Pos: TVector3Single): TVector3Single;`
| `function LocalToOutside(const Pos: TVector3Single): TVector3Single;`
| `function PreferredHeight: Single; virtual;`
### Properties
| `property Gravity: boolean read FGravity write FGravity default false;`
| `property FallSpeed: Single read FFallSpeed write FFallSpeed default 0;`
| `property GrowSpeed: Single read FGrowSpeed write FGrowSpeed default 0;`
| `property MiddleHeight: Single read FMiddleHeight write FMiddleHeight default DefaultMiddleHeight;`
## Description ### Fields
| `internal const DefaultMiddleHeight = 0.5;`
### Methods
| `function GetTranslation: TVector3Single; virtual;`
The GetXxx methods below determine the transformation returned by default TransformMatricesMult implementation in this class. Simple descendants need only to override these, and OnlyTranslation, and the TransformMatricesMult will automatically work correctly already. More complicated descendants may override TransformMatricesMult, and then GetCenter, GetRotation etc. methods can be ignored (if your TransformMatricesMult will not use it, then GetCenter, GetRotation will not be used at all and there's no point in overriding them). You still need to override OnlyTranslation `GetTranslation` (it's used by default Middle implementation, and it's also used in case OnlyTranslation returns `True`), And make sure AverageScale is correct (if you want it to be <> 1, that is: if your transformation may make some scale, then you need to override GetScale).
| `function GetCenter: TVector3Single; virtual;`
| `function GetRotation: TVector4Single; virtual;`
| `function GetScale: TVector3Single; virtual;`
| `function GetScaleOrientation: TVector4Single; virtual;`
| `function OnlyTranslation: boolean; virtual;`
Can we use simple GetTranslation instead of full TransformMatricesMult. Returning `True` allows optimization in some cases.
| `function Transform: TMatrix4Single;`
| `function TransformInverse: TMatrix4Single;`
| `procedure TransformMatricesMult(var M, MInverse: TMatrix4Single); virtual;`
Transformation matrix. You can override this to derive transformation using anything, not necessarily GetTranslation / GetCenter etc. methods. This method must produce matrices that preserve points as points and directions as directions in homegeneous space. In other words, using MatrixMultPoint or MatrixMultDirection with these matrices must never raise ETransformedResultInvalid. For example, a combination of translations, rotations, scaling is Ok.
| `procedure TransformMatrices(out M, MInverse: TMatrix4Single);`
| `function AverageScale: Single;`
| `function HeightCollision(const Position, GravityUp: TVector3Single; const TrianglesToIgnoreFunc: T3DTriangleIgnoreFunc; out AboveHeight: Single; out AboveGround: P3DTriangle): boolean; override;`
| `function MoveCollision( const OldPos, ProposedNewPos: TVector3Single; out NewPos: TVector3Single; const IsRadius: boolean; const Radius: Single; const OldBox, NewBox: TBox3D; const TrianglesToIgnoreFunc: T3DTriangleIgnoreFunc): boolean; override;`
| `function MoveCollision( const OldPos, NewPos: TVector3Single; const IsRadius: boolean; const Radius: Single; const OldBox, NewBox: TBox3D; const TrianglesToIgnoreFunc: T3DTriangleIgnoreFunc): boolean; override;`
| `function SegmentCollision(const Pos1, Pos2: TVector3Single; const TrianglesToIgnoreFunc: T3DTriangleIgnoreFunc; const ALineOfSight: boolean): boolean; override;`
| `function SphereCollision(const Pos: TVector3Single; const Radius: Single; const TrianglesToIgnoreFunc: T3DTriangleIgnoreFunc): boolean; override;`
| `function BoxCollision(const Box: TBox3D; const TrianglesToIgnoreFunc: T3DTriangleIgnoreFunc): boolean; override;`
| `function RayCollision(const RayOrigin, RayDirection: TVector3Single; const TrianglesToIgnoreFunc: T3DTriangleIgnoreFunc): TRayCollision; override;`
| `procedure Fall(const FallHeight: Single); virtual;`
Called when `fall` ended. You can use FallHeight to decrease creature life or such.
| `function LocalBoundingBox: TBox3D;`
Untransformed bounding box value.
| `constructor Create(AOwner: TComponent); override;`
| `function BoundingBox: TBox3D; override;`
| `procedure Render(const Frustum: TFrustum; const Params: TRenderParams); override;`
| `procedure RenderShadowVolume( ShadowVolumeRenderer: TBaseShadowVolumeRenderer; const ParentTransformIsIdentity: boolean; const ParentTransform: TMatrix4Single); override;`
| `function Middle: TVector3Single; override;`
| `procedure Update(const SecondsPassed: Single; var RemoveMe: TRemoveType); override;`
| `function OutsideToLocal(const Pos: TVector3Single): TVector3Single;`
Convert position between local and outside coordinate system. This is called `OutsideToLocal`, not WorldToLocal, because it only handles transformation defined in this item — it does not recursively apply all transform on the way to root .
| `function LocalToOutside(const Pos: TVector3Single): TVector3Single;`
| `function PreferredHeight: Single; virtual;`
The preferred height of the object Middle above the ground, when the object is standing on the ground firmly. This is used by objects affected by gravity (like non-flying creatures and items) to know how far they should fall down or grow up. The default implementation in this class looks at MiddleHeight property, see the algorithm described there. This may be dynamic (may change during creature lifetime, so you can make the creature duck or grow if you want).
### Properties
| `property Gravity: boolean read FGravity write FGravity default false;`
Gravity may make this object fall down (see FallSpeed) or grow up (see GrowSpeed). See also PreferredHeight. Special notes for TPlayer: player doesn't use this (TPlayer.Gravity should remain `False`), instead player relies on TPlayer.Camera.Gravity = `True`, that does a similar thing (with some extras, to make camera effects). This will change in the future, to merge these two gravity implementations. Although the TPlayer.Fall method still works as expected (it's linked to TWalkCamera.OnFall in this case).
| `property FallSpeed: Single read FFallSpeed write FFallSpeed default 0;`
Falling speed, in units per second, for Gravity. TODO: this will be replaced with more physically-based approach. This is relevant only if Gravity and PreferredHeight <> 0. 0 means no falling.
| `property GrowSpeed: Single read FGrowSpeed write FGrowSpeed default 0;`
Growing (raising from crouching to normal standing position) speed, in units per second. This is used by non-flying creatures when climbing up stairs, in which case GetTranslation ("legs positon") may be sometimes under the ground while Middle ("eyes position") will be always above the ground and will try to grow to be at PreferredHeight above the ground. This is relevant only if Gravity and PreferredHeight <> 0. 0 means no growing.
| `property MiddleHeight: Single read FMiddleHeight write FMiddleHeight default DefaultMiddleHeight;`
How high are creature eyes in the model. Value 0 means that eyes are at the bottom of the model, 0.5 means the middle, 1 means top. The top is always considered to be at the top of the bounding box. Definition of bottom depends on Gravity: When Gravity is `True`, then the bottom is considered to be the plane where World.GravityCoordinate (like Z or Y axis) is zero. The actual bottom (lowest point) of the bounding box doesn't matter. This means that things placed below zero plane (like a creature tentacle or leg) will sink into the ground, instead of causing whole creature to move up. It also means that the creature can easily float above the ground, just model it a little above the zero plane. In other words, this allows you to model the creature with respect to the ground (zero plane), which is comfortable. Note that setting `MiddleHeight` to exact 0 means that gravity will not work, as it means that the PreferredHeight above the ground is to be stuck right at the ground level. For gravity to work right, the `MiddleHeight` should be large enough to cause PreferredHeight to be > Sphere radius, for all possible animation states (for all possible bounding box values). When Gravity is `False`, then the bottom is considered at the bottom of the bounding box. This way it works regardless of where (0,0,0) is in your model (regardless if (0,0,0) represents legs, or middle of your creature), since we adjust to the BoundingBox position. This property determines how the T3DCustomTransform handles the Middle implementation (this is the point used for various collision detection routines) and PreferredHeight (this is the preferred height of Middle above the ground). You can override these two methods to use a different approach, and then ignore `MiddleHeight` completely.
Generated by PasDoc 0.13.0 on 2015-06-15 04:43:08