Class T3DCustomTransform

Unit

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

Overview

Fields

Public internal const DefaultMiddleHeight = 0.5;

Methods

Protected function GetTranslation: TVector3Single; virtual;
Protected function GetCenter: TVector3Single; virtual;
Protected function GetRotation: TVector4Single; virtual;
Protected function GetScale: TVector3Single; virtual;
Protected function GetScaleOrientation: TVector4Single; virtual;
Protected function GetTranslation2D: TVector2Single;
Protected function OnlyTranslation: boolean; virtual;
Protected function Transform: TMatrix4Single;
Protected function TransformInverse: TMatrix4Single;
Protected procedure TransformMatricesMult(var M, MInverse: TMatrix4Single); virtual;
Protected procedure TransformMatrices(out M, MInverse: TMatrix4Single);
Protected function AverageScale: Single;
Protected function HeightCollision(const Position, GravityUp: TVector3Single; const TrianglesToIgnoreFunc: T3DTriangleIgnoreFunc; out AboveHeight: Single; out AboveGround: P3DTriangle): boolean; override;
Protected function MoveCollision( const OldPos, ProposedNewPos: TVector3Single; out NewPos: TVector3Single; const IsRadius: boolean; const Radius: Single; const OldBox, NewBox: TBox3D; const TrianglesToIgnoreFunc: T3DTriangleIgnoreFunc): boolean; override;
Protected function MoveCollision( const OldPos, NewPos: TVector3Single; const IsRadius: boolean; const Radius: Single; const OldBox, NewBox: TBox3D; const TrianglesToIgnoreFunc: T3DTriangleIgnoreFunc): boolean; override;
Protected function SegmentCollision(const Pos1, Pos2: TVector3Single; const TrianglesToIgnoreFunc: T3DTriangleIgnoreFunc; const ALineOfSight: boolean): boolean; override;
Protected function SphereCollision(const Pos: TVector3Single; const Radius: Single; const TrianglesToIgnoreFunc: T3DTriangleIgnoreFunc): boolean; override;
Protected function SphereCollision2D(const Pos: TVector2Single; const Radius: Single; const TrianglesToIgnoreFunc: T3DTriangleIgnoreFunc; const Details: TCollisionDetails): boolean; override;
Protected function PointCollision2D(const Point: TVector2Single; const TrianglesToIgnoreFunc: T3DTriangleIgnoreFunc): boolean; override;
Protected function BoxCollision(const Box: TBox3D; const TrianglesToIgnoreFunc: T3DTriangleIgnoreFunc): boolean; override;
Protected function RayCollision(const RayOrigin, RayDirection: TVector3Single; const TrianglesToIgnoreFunc: T3DTriangleIgnoreFunc): TRayCollision; override;
Protected procedure Fall(const FallHeight: Single); virtual;
Protected function LocalBoundingBox: TBox3D;
Public constructor Create(AOwner: TComponent); override;
Public function BoundingBox: TBox3D; override;
Public procedure Render(const Frustum: TFrustum; const Params: TRenderParams); override;
Public procedure RenderShadowVolume( ShadowVolumeRenderer: TBaseShadowVolumeRenderer; const ParentTransformIsIdentity: boolean; const ParentTransform: TMatrix4Single); override;
Public function Middle: TVector3Single; override;
Public procedure Update(const SecondsPassed: Single; var RemoveMe: TRemoveType); override;
Public function OutsideToLocal(const Pos: TVector3Single): TVector3Single;
Public function LocalToOutside(const Pos: TVector3Single): TVector3Single;
Public function PreferredHeight: Single; virtual;
Public procedure Translate(const T: TVector3Single); virtual; abstract;
Public function Move(const ATranslation: TVector3Single; const BecauseOfGravity: boolean; const EnableWallSliding: boolean = true): boolean;

Properties

Public property Gravity: boolean read FGravity write FGravity default false;
Public property FallSpeed: Single read FFallSpeed write FFallSpeed default 0;
Public property GrowSpeed: Single read FGrowSpeed write FGrowSpeed default 0;
Public property MiddleHeight: Single read FMiddleHeight write FMiddleHeight default DefaultMiddleHeight;
Public property Translation: TVector3Single read GetTranslation;
Public property Rotation: TVector4Single read GetRotation;

Description

Fields

Public internal const DefaultMiddleHeight = 0.5;
 

Methods

Protected 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, thus directly affecting the transformation. They should still also override other methods to make sure that they return correct results (OnlyTranslation, GetTranslation, GetRotation, GetScale and friends...). They are seldom used (outside of the default TransformMatricesMult implementation), but are used.

Protected function GetCenter: TVector3Single; virtual;
 
Protected function GetRotation: TVector4Single; virtual;
 
Protected function GetScale: TVector3Single; virtual;
 
Protected function GetScaleOrientation: TVector4Single; virtual;
 
Protected function GetTranslation2D: TVector2Single;

Get translation in 2D (uses GetTranslation, ignores Z coord).

Protected function OnlyTranslation: boolean; virtual;

Can we use simple GetTranslation instead of full TransformMatricesMult. Returning True allows optimization in some cases.

Protected function Transform: TMatrix4Single;
 
Protected function TransformInverse: TMatrix4Single;
 
Protected procedure TransformMatricesMult(var M, MInverse: TMatrix4Single); virtual;

Transformation matrix. You can override this to derive transformation using anything, not necessarily from 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.

Protected procedure TransformMatrices(out M, MInverse: TMatrix4Single);
 
Protected function AverageScale: Single;
 
Protected function HeightCollision(const Position, GravityUp: TVector3Single; const TrianglesToIgnoreFunc: T3DTriangleIgnoreFunc; out AboveHeight: Single; out AboveGround: P3DTriangle): boolean; override;
 
Protected function MoveCollision( const OldPos, ProposedNewPos: TVector3Single; out NewPos: TVector3Single; const IsRadius: boolean; const Radius: Single; const OldBox, NewBox: TBox3D; const TrianglesToIgnoreFunc: T3DTriangleIgnoreFunc): boolean; override;
 
Protected function MoveCollision( const OldPos, NewPos: TVector3Single; const IsRadius: boolean; const Radius: Single; const OldBox, NewBox: TBox3D; const TrianglesToIgnoreFunc: T3DTriangleIgnoreFunc): boolean; override;
 
Protected function SegmentCollision(const Pos1, Pos2: TVector3Single; const TrianglesToIgnoreFunc: T3DTriangleIgnoreFunc; const ALineOfSight: boolean): boolean; override;
 
Protected function SphereCollision(const Pos: TVector3Single; const Radius: Single; const TrianglesToIgnoreFunc: T3DTriangleIgnoreFunc): boolean; override;
 
Protected function SphereCollision2D(const Pos: TVector2Single; const Radius: Single; const TrianglesToIgnoreFunc: T3DTriangleIgnoreFunc; const Details: TCollisionDetails): boolean; override;
 
Protected function PointCollision2D(const Point: TVector2Single; const TrianglesToIgnoreFunc: T3DTriangleIgnoreFunc): boolean; override;
 
Protected function BoxCollision(const Box: TBox3D; const TrianglesToIgnoreFunc: T3DTriangleIgnoreFunc): boolean; override;
 
Protected function RayCollision(const RayOrigin, RayDirection: TVector3Single; const TrianglesToIgnoreFunc: T3DTriangleIgnoreFunc): TRayCollision; override;
 
Protected procedure Fall(const FallHeight: Single); virtual;

Called when fall ended. You can use FallHeight to decrease creature life or such.

Protected function LocalBoundingBox: TBox3D;

Untransformed bounding box value.

Public constructor Create(AOwner: TComponent); override;
 
Public function BoundingBox: TBox3D; override;
 
Public procedure Render(const Frustum: TFrustum; const Params: TRenderParams); override;
 
Public procedure RenderShadowVolume( ShadowVolumeRenderer: TBaseShadowVolumeRenderer; const ParentTransformIsIdentity: boolean; const ParentTransform: TMatrix4Single); override;
 
Public function Middle: TVector3Single; override;
 
Public procedure Update(const SecondsPassed: Single; var RemoveMe: TRemoveType); override;
 
Public 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 .

Public function LocalToOutside(const Pos: TVector3Single): TVector3Single;
 
Public 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).

Public procedure Translate(const T: TVector3Single); virtual; abstract;

Unconditionally move this 3D object by given vector. You usually don't want to use this directly, instead use Move method to move checking collisions (and with optional wall sliding).

Public function Move(const ATranslation: TVector3Single; const BecauseOfGravity: boolean; const EnableWallSliding: boolean = true): boolean;

Move, if possible (no collisions). This is the simplest way to move a 3D object, and a basic building block for artificial intelligence of creatures.

Checks move possibility by MoveAllowed, using Middle point. Actual move is done using Translate.

Properties

Public 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).

Public 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.

Public 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.

Public 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.

Public property Translation: TVector3Single read GetTranslation;

Translation (move) the children. Zero by default.

See also
T3DTransform.Translation
Translation (move) the children.
Public property Rotation: TVector4Single read GetRotation;

Rotation in 3D, around a specified axis.

See also
T3DTransform.Rotation
Rotation in 3D, around a specified axis.

Generated by PasDoc 0.14.0.