Packed Record TGenericVector3

Unit

Declaration

type TGenericVector3 = packed record

Description

Vector of 3 floating-point values.

This is generic type (although not using "proper" Pascal generics for implementation reasons). In has two actual uses:

  1. TVector3, a vector of 3 Single values (floats with single precision),

  2. TVector3Double, a vector of 3 Double values (floats with double precision).

The actual type of TGenericScalar is Single or Double for (respectively) TVector3 or TVector3Double.

Source: src/base/castlevectors_generic_float_record.inc (line 190).

Overview

Nested Types

Public TIndex = 0..Count - 1;

Fields

Public nested const Count = 3;
Public X: TGenericScalar
Public Y: TGenericScalar
Public Z: TGenericScalar
Public Data: array [TIndex] of TGenericScalar
Public XY: TGenericVector2

Methods

Public class operator + (const A, B: TGenericVector3): TGenericVector3; inline;
Public class operator - (const A, B: TGenericVector3): TGenericVector3; inline;
Public class operator - (const V: TGenericVector3): TGenericVector3; inline;
Public class operator * (const V: TGenericVector3; const Scalar: TGenericScalar): TGenericVector3; inline;
Public class operator * (const Scalar: TGenericScalar; const V: TGenericVector3): TGenericVector3; inline;
Public class operator * (const V1, V2: TGenericVector3): TGenericVector3; inline;
Public class operator / (const V: TGenericVector3; const Scalar: TGenericScalar): TGenericVector3; inline;
Public procedure Init(const AX, AY, AZ: TGenericScalar); inline; deprecated 'initialize instead like "V := Vector3(X, Y, Z)"; modifying a temporary record value is a trap, e.g. this is not reliable: "Scene.Translation.Init(X, Y, Z)"';
Public function ToString: string;
Public function ToRawString(const FloatFormat: String = '%g'): string;
Public function Normalize: TGenericVector3; inline;
Public procedure NormalizeMe; inline; deprecated 'normalize instead like "V := V.Normalize"; modifying a temporary record value is a trap, e.g. this is not reliable: "Scene.Translation.NormalizeMe"';
Public function Length: TGenericScalar; inline;
Public function LengthSqr: TGenericScalar; inline;
Public function AdjustToLength(const NewLength: TGenericScalar): TGenericVector3; inline;
Public class function CrossProduct(const V1, V2: TGenericVector3): TGenericVector3; static; inline;
Public class function DotProduct(const V1, V2: TGenericVector3): TGenericScalar; static; inline;
Public function Abs: TGenericVector3; inline;
Public function Min: TGenericScalar;
Public function Max: TGenericScalar;
Public function Average: TGenericScalar; inline;
Public function IsZero: boolean; overload; inline;
Public function IsZero(const Epsilon: TGenericScalar): boolean; overload; inline;
Public function IsPerfectlyZero: boolean; inline;
Public class function Equals(const V1, V2: TGenericVector3): boolean; overload; inline; static;
Public class function Equals(const V1, V2: TGenericVector3; const Epsilon: TGenericScalar): boolean; overload; inline; static;
Public class function PerfectlyEquals(const V1, V2: TGenericVector3): boolean; static; inline;
Public class function Lerp(const A: TGenericScalar; const V1, V2: TGenericVector3): TGenericVector3; static; inline;
Public class function Zero: TGenericVector3; static; inline;

Properties

Public property AsArray [const Index: TIndex]: TGenericScalar read GetItems;
Public class property One [const Index: TIndex]: TGenericVector3 read GetOne;

Description

Nested Types

Public TIndex = 0..Count - 1;

This item has no description.

Source: src/base/castlevectors_generic_float_record.inc (line 193).

Fields

Public nested const Count = 3;

This item has no description.

Source: src/base/castlevectors_generic_float_record.inc (line 193).

Public X: TGenericScalar

This item has no description.

Source: src/base/castlevectors_generic_float_record.inc (line 333).

Public Y: TGenericScalar

This item has no description.

Source: src/base/castlevectors_generic_float_record.inc (line 333).

Public Z: TGenericScalar

This item has no description.

Source: src/base/castlevectors_generic_float_record.inc (line 333).

Public Data: array [TIndex] of TGenericScalar

Access (get, set) vector components by index.

Source: src/base/castlevectors_generic_float_record.inc (line 334).

Public XY: TGenericVector2

This item has no description.

Source: src/base/castlevectors_generic_float_record.inc (line 335).

Methods

Public class operator + (const A, B: TGenericVector3): TGenericVector3; inline;

This item has no description.

Source: src/base/castlevectors_generic_float_record.inc (line 220).

Public class operator - (const A, B: TGenericVector3): TGenericVector3; inline;

This item has no description.

Source: src/base/castlevectors_generic_float_record.inc (line 221).

Public class operator - (const V: TGenericVector3): TGenericVector3; inline;

This item has no description.

Source: src/base/castlevectors_generic_float_record.inc (line 222).

Public class operator * (const V: TGenericVector3; const Scalar: TGenericScalar): TGenericVector3; inline;

This item has no description.

Source: src/base/castlevectors_generic_float_record.inc (line 223).

Public class operator * (const Scalar: TGenericScalar; const V: TGenericVector3): TGenericVector3; inline;

This item has no description.

Source: src/base/castlevectors_generic_float_record.inc (line 224).

Public class operator * (const V1, V2: TGenericVector3): TGenericVector3; inline;

Vector * vector makes a component-wise multiplication. This is consistent with GLSL and other vector APIs.

Source: src/base/castlevectors_generic_float_record.inc (line 227).

Public class operator / (const V: TGenericVector3; const Scalar: TGenericScalar): TGenericVector3; inline;

This item has no description.

Source: src/base/castlevectors_generic_float_record.inc (line 228).

Public procedure Init(const AX, AY, AZ: TGenericScalar); inline; deprecated 'initialize instead like "V := Vector3(X, Y, Z)"; modifying a temporary record value is a trap, e.g. this is not reliable: "Scene.Translation.Init(X, Y, Z)"';

Warning: this symbol is deprecated: initialize instead like "V := Vector3(X, Y, Z)"; modifying a temporary record value is a trap, e.g. this is not reliable: "Scene.Translation.Init(X, Y, Z)"

This item has no description.

Source: src/base/castlevectors_generic_float_record.inc (line 230).

Public function ToString: string;

This item has no description.

Source: src/base/castlevectors_generic_float_record.inc (line 233).

Public function ToRawString(const FloatFormat: String = '%g'): string;

Convert to string using the most precise (not always easily readable by humans) float format. This may use the exponential (scientific) notation to represent the floating-point value, if needed.

You can pass, as parameter, the format to use. By default it is '%g', "general number format" with maximum precision documented on https://www.freepascal.org/docs-html/rtl/sysutils/format.html .

This is suitable for storing the value in a file, with a best precision possible.

Source: src/base/castlevectors_generic_float_record.inc (line 246).

Public function Normalize: TGenericVector3; inline;

This item has no description.

Source: src/base/castlevectors_generic_float_record.inc (line 248).

Public procedure NormalizeMe; inline; deprecated 'normalize instead like "V := V.Normalize"; modifying a temporary record value is a trap, e.g. this is not reliable: "Scene.Translation.NormalizeMe"';

Warning: this symbol is deprecated: normalize instead like "V := V.Normalize"; modifying a temporary record value is a trap, e.g. this is not reliable: "Scene.Translation.NormalizeMe"

This item has no description.

Source: src/base/castlevectors_generic_float_record.inc (line 249).

Public function Length: TGenericScalar; inline;

This item has no description.

Source: src/base/castlevectors_generic_float_record.inc (line 252).

Public function LengthSqr: TGenericScalar; inline;

Vector length squared. This is slightly faster than Length as it avoids calculating a square root along the way. (But, please remember to not optimize your code without a need. Optimize only parts that are proven bottlenecks, otherwise don't make the code less readable for the sake of speed.)

Source: src/base/castlevectors_generic_float_record.inc (line 259).

Public function AdjustToLength(const NewLength: TGenericScalar): TGenericVector3; inline;

Calculate a new vector scaled so that it has length equal to NewLength. NewLength may be negative, in which case we'll negate the vector and then adjust it's length to Abs(NewLength).

Source: src/base/castlevectors_generic_float_record.inc (line 264).

Public class function CrossProduct(const V1, V2: TGenericVector3): TGenericVector3; static; inline;

Vector cross product. See http://en.wikipedia.org/wiki/Cross_product .

Result is a vector orthogonal to both given vectors. Generally there are two such vectors, this method returns the one following right-hand rule. More precisely, V1, V2 and Product(V1, V2) are in the same relation as basic X, Y, Z axes. Reverse the order of arguments to get negated result.

If you use this to calculate a normal vector of a triangle (P0, P1, P2): note that TVector3.CrossProduct(P1 - P0, P1 - P2) points out from CCW triangle side in right-handed coordinate system.

When V1 and V2 are parallel (that is, when V1 = V2 multiplied by some scalar), and this includes the case when one of them is zero, then result is a zero vector.

Source: src/base/castlevectors_generic_float_record.inc (line 282).

Public class function DotProduct(const V1, V2: TGenericVector3): TGenericScalar; static; inline;

Dot product of two vectors. See https://en.wikipedia.org/wiki/Dot_product .

Source: src/base/castlevectors_generic_float_record.inc (line 286).

Public function Abs: TGenericVector3; inline;

Absolute value on all components.

Source: src/base/castlevectors_generic_float_record.inc (line 289).

Public function Min: TGenericScalar;

Smallest component.

Source: src/base/castlevectors_generic_float_record.inc (line 292).

Public function Max: TGenericScalar;

Largest component.

Source: src/base/castlevectors_generic_float_record.inc (line 295).

Public function Average: TGenericScalar; inline;

Average from all components.

Source: src/base/castlevectors_generic_float_record.inc (line 298).

Public function IsZero: boolean; overload; inline;

Are all components equal to zero (within some epsilon margin).

Source: src/base/castlevectors_generic_float_record.inc (line 301).

Public function IsZero(const Epsilon: TGenericScalar): boolean; overload; inline;

Are all components equal to zero (within Epsilon margin).

Source: src/base/castlevectors_generic_float_record.inc (line 304).

Public function IsPerfectlyZero: boolean; inline;

This item has no description.

Source: src/base/castlevectors_generic_float_record.inc (line 306).

Public class function Equals(const V1, V2: TGenericVector3): boolean; overload; inline; static;

Compare two vectors, with epsilon to tolerate slightly different floats.

Source: src/base/castlevectors_generic_float_record.inc (line 309).

Public class function Equals(const V1, V2: TGenericVector3; const Epsilon: TGenericScalar): boolean; overload; inline; static;

This item has no description.

Source: src/base/castlevectors_generic_float_record.inc (line 310).

Public class function PerfectlyEquals(const V1, V2: TGenericVector3): boolean; static; inline;

Compare two vectors using exact comparison (like the "=" operator to compare floats).

Source: src/base/castlevectors_generic_float_record.inc (line 313).

Public class function Lerp(const A: TGenericScalar; const V1, V2: TGenericVector3): TGenericVector3; static; inline;

Linear interpolation between two vector values. Returns (1-A) * V1 + A * V2.

So:

  • A = 0 gives V1,

  • A = 1 gives V2,

  • values between are interpolated,

  • values outside are extrapolated.

Source: src/base/castlevectors_generic_float_record.inc (line 327).

Public class function Zero: TGenericVector3; static; inline;

This item has no description.

Source: src/base/castlevectors_generic_float_record.inc (line 329).

Properties

Public property AsArray [const Index: TIndex]: TGenericScalar read GetItems;

Get vector components by index. This is a default property, so you can write MyVector[0] instead of MyVector.Data[0] or MyVector.AsArray[0].

But note that this is not writeable (because exposing writeable properties on vectors would cause some subtle traps, see https://castle-engine.io/coding_traps ). Use MyVector.Data[0] := 123.456 if you want to set by index, or MyVector.X := 123.456.

Source: src/base/castlevectors_generic_float_record.inc (line 209).

Public class property One [const Index: TIndex]: TGenericVector3 read GetOne;

This item has no description.

Source: src/base/castlevectors_generic_float_record.inc (line 330).


Generated by PasDoc 0.17.0.snapshot.