| 1 |
{%MainUnit castlevectors.pas} |
| 2 |
{ |
| 3 |
Copyright 2017-2022 Michalis Kamburelis. |
| 4 |
|
| 5 |
This file is part of "Castle Game Engine". |
| 6 |
|
| 7 |
"Castle Game Engine" is free software; see the file COPYING.txt, |
| 8 |
included in this distribution, for details about the copyright. |
| 9 |
|
| 10 |
"Castle Game Engine" is distributed in the hope that it will be useful, |
| 11 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| 13 |
|
| 14 |
---------------------------------------------------------------------------- |
| 15 |
} |
| 16 |
|
| 17 |
{ Deprecated definitions (types and functions), existing only to keep |
| 18 |
backward-compatibility with older versions of Castle Game Engine. } |
| 19 |
|
| 20 |
{$ifdef read_interface} |
| 21 |
|
| 22 |
const |
| 23 |
{ Vector with all components zero. } |
| 24 |
ZeroVector2Single: TVector2 = (X: 0; Y: 0) deprecated 'use TVector2.Zero'; |
| 25 |
ZeroVector3Single: TVector3 = (X: 0; Y: 0; Z: 0) deprecated 'use TVector3.Zero'; |
| 26 |
ZeroVector4Single: TVector4 = (X: 0; Y: 0; Z: 0; W: 0) deprecated 'use TVector4.Zero'; |
| 27 |
|
| 28 |
ZeroVector2Double: TVector2Double = (X: 0; Y: 0) deprecated 'use TVector2Double.Zero'; |
| 29 |
ZeroVector3Double: TVector3Double = (X: 0; Y: 0; Z: 0) deprecated 'use TVector3Double.Zero'; |
| 30 |
ZeroVector4Double: TVector4Double = (X: 0; Y: 0; Z: 0; W: 0) deprecated 'use TVector4Double.Zero'; |
| 31 |
|
| 32 |
ZeroVector2Byte: TVector2Byte = (X: 0; Y: 0) deprecated 'use TVector2Byte.Zero'; |
| 33 |
ZeroVector3Byte: TVector3Byte = (X: 0; Y: 0; Z: 0) deprecated 'use TVector3Byte.Zero'; |
| 34 |
ZeroVector4Byte: TVector4Byte = (X: 0; Y: 0; Z: 0; W: 0) deprecated 'use TVector4Byte.Zero'; |
| 35 |
|
| 36 |
ZeroVector2Integer: TVector2Integer = (X: 0; Y: 0) deprecated 'use TVector2Integer.Zero'; |
| 37 |
ZeroVector3Integer: TVector3Integer = (X: 0; Y: 0; Z: 0) deprecated 'use TVector3Integer.Zero'; |
| 38 |
ZeroVector4Integer: TVector4Integer = (X: 0; Y: 0; Z: 0; W: 0) deprecated 'use TVector4Integer.Zero'; |
| 39 |
|
| 40 |
ZeroVector2Cardinal: TVector2Cardinal = (X: 0; Y: 0) deprecated 'use TVector2Cardinal.Zero'; |
| 41 |
ZeroVector3Cardinal: TVector3Cardinal = (X: 0; Y: 0; Z: 0) deprecated 'use TVector3Cardinal.Zero'; |
| 42 |
ZeroVector4Cardinal: TVector4Cardinal = (X: 0; Y: 0; Z: 0; W: 0) deprecated 'use TVector4Cardinal.Zero'; |
| 43 |
|
| 44 |
ZeroMatrix2Single: TMatrix2 = (Data: ((0, 0), (0, 0))) deprecated 'use TMatrix2.Zero'; |
| 45 |
ZeroMatrix3Single: TMatrix3 = (Data: ((0, 0, 0), (0, 0, 0), (0, 0, 0))) deprecated 'use TMatrix3.Zero'; |
| 46 |
ZeroMatrix4Single: TMatrix4 = (Data: ((0, 0, 0, 0), (0, 0, 0, 0), (0, 0, 0, 0), (0, 0, 0, 0))) deprecated 'use TMatrix4.Zero'; |
| 47 |
|
| 48 |
ZeroMatrix2Double: TMatrix2Double = (Data: ((0, 0), (0, 0))) deprecated 'use TMatrix2Double.Zero'; |
| 49 |
ZeroMatrix3Double: TMatrix3Double = (Data: ((0, 0, 0), (0, 0, 0), (0, 0, 0))) deprecated 'use TMatrix3Double.Zero'; |
| 50 |
ZeroMatrix4Double: TMatrix4Double = (Data: ((0, 0, 0, 0), (0, 0, 0, 0), (0, 0, 0, 0), (0, 0, 0, 0))) deprecated 'use TMatrix4Double.Zero'; |
| 51 |
|
| 52 |
IdentityMatrix2Single: TMatrix2 = (Data: ((1, 0), (0, 1))) deprecated 'use TMatrix2.Identity'; |
| 53 |
IdentityMatrix3Single: TMatrix3 = (Data: ((1, 0, 0), (0, 1, 0), (0, 0, 1))) deprecated 'use TMatrix3.Identity'; |
| 54 |
IdentityMatrix4Single: TMatrix4 = (Data: ((1, 0, 0, 0), (0, 1, 0, 0), (0, 0, 1, 0), (0, 0, 0, 1))) deprecated 'use TMatrix4.Identity'; |
| 55 |
|
| 56 |
IdentityMatrix2Double: TMatrix2Double = (Data: ((1, 0), (0, 1))) deprecated 'use TMatrix2Double.Identity'; |
| 57 |
IdentityMatrix3Double: TMatrix3Double = (Data: ((1, 0, 0), (0, 1, 0), (0, 0, 1))) deprecated 'use TMatrix3Double.Identity'; |
| 58 |
IdentityMatrix4Double: TMatrix4Double = (Data: ((1, 0, 0, 0), (0, 1, 0, 0), (0, 0, 1, 0), (0, 0, 0, 1))) deprecated 'use TMatrix4Double.Identity'; |
| 59 |
|
| 60 |
UnitVector2Single: array [TVector2.TIndex] of TVector2 = ( |
| 61 |
(X: 1; Y: 0), |
| 62 |
(X: 0; Y: 1) |
| 63 |
) deprecated 'use TVector2.One'; |
| 64 |
UnitVector3Single: array [TVector3.TIndex] of TVector3 = ( |
| 65 |
(X: 1; Y: 0; Z: 0), |
| 66 |
(X: 0; Y: 1; Z: 0), |
| 67 |
(X: 0; Y: 0; Z: 1) |
| 68 |
) deprecated 'use TVector3.One'; |
| 69 |
UnitVector4Single: array [TVector4.TIndex] of TVector4 = ( |
| 70 |
(X: 1; Y: 0; Z: 0; W: 0), |
| 71 |
(X: 0; Y: 1; Z: 0; W: 0), |
| 72 |
(X: 0; Y: 0; Z: 1; W: 0), |
| 73 |
(X: 0; Y: 0; Z: 0; W: 1) |
| 74 |
) deprecated 'use TVector4.One'; |
| 75 |
|
| 76 |
type |
| 77 |
TVector2Single = TVector2 deprecated; |
| 78 |
TVector3Single = TVector3 deprecated; |
| 79 |
TVector4Single = TVector4 deprecated; |
| 80 |
|
| 81 |
TMatrix2Single = TMatrix2 deprecated; |
| 82 |
TMatrix3Single = TMatrix3 deprecated; |
| 83 |
TMatrix4Single = TMatrix4 deprecated; |
| 84 |
|
| 85 |
TVector2SingleList = TVector2List deprecated; |
| 86 |
TVector3SingleList = TVector3List deprecated; |
| 87 |
TVector4SingleList = TVector4List deprecated; |
| 88 |
|
| 89 |
TMatrix3SingleList = TMatrix3List deprecated; |
| 90 |
TMatrix4SingleList = TMatrix4List deprecated; |
| 91 |
|
| 92 |
PVector2Single = PVector2 deprecated; |
| 93 |
PVector3Single = PVector3 deprecated; |
| 94 |
PVector4Single = PVector4 deprecated; |
| 95 |
|
| 96 |
PMatrix2Single = PMatrix2 deprecated; |
| 97 |
PMatrix3Single = PMatrix3 deprecated; |
| 98 |
PMatrix4Single = PMatrix4 deprecated; |
| 99 |
|
| 100 |
{ Construct an initialized TVector2 value. } |
| 101 |
function Vector2Single(const X, Y: Single): TVector2; overload; deprecated 'use Vector2'; |
| 102 |
function Vector2Single(const V: TVector2Double): TVector2; overload; deprecated 'use Vector2'; |
| 103 |
|
| 104 |
{ Construct an initialized TVector3 value. } |
| 105 |
function Vector3Single(const X, Y, Z: Single): TVector3; overload; deprecated 'use Vector3'; |
| 106 |
function Vector3Single(const V: TVector2; const Z: Single): TVector3; overload; deprecated 'use Vector3'; |
| 107 |
function Vector3Single(const V: TVector3Double): TVector3; overload; deprecated 'use Vector3'; |
| 108 |
|
| 109 |
{ Construct an initialized TVector4 value. } |
| 110 |
function Vector4Single(const X, Y, Z, W: Single): TVector4; overload; deprecated 'use Vector4'; |
| 111 |
function Vector4Single(const V: TVector3; const W: Single): TVector4; overload; deprecated 'use Vector4'; |
| 112 |
function Vector4Single(const V: TVector4Double): TVector4; overload; deprecated 'use Vector4'; |
| 113 |
|
| 114 |
{ Various compatibility functions (on Single) } |
| 115 |
|
| 116 |
function FloatsEqual(const A, B: Single): boolean; overload; deprecated 'use Math.SameValue'; |
| 117 |
function FloatsEqual(const A, B: Single; const Epsilon: Single): boolean; overload; deprecated 'use Math.SameValue'; |
| 118 |
function FloatToNiceStr(const A: Single): string; overload; deprecated 'use Format(''%f'', [Value])'; |
| 119 |
function FloatToRawStr(const A: Single): string; overload; deprecated 'use Format(''%g'', [Value])'; |
| 120 |
function Zero(const A: Single): boolean; overload; deprecated 'use Math.IsZero'; |
| 121 |
|
| 122 |
{ Various compatibility functions (on vectors and matrices) } |
| 123 |
|
| 124 |
function VectorAdd(const V1, V2: TVector2): TVector2; overload; deprecated 'use V1 + V2'; |
| 125 |
function VectorAdd(const V1, V2: TVector3): TVector3; overload; deprecated 'use V1 + V2'; |
| 126 |
function VectorAdd(const V1, V2: TVector4): TVector4; overload; deprecated 'use V1 + V2'; |
| 127 |
function VectorSubtract(const V1, V2: TVector2): TVector2; overload; deprecated 'use V1 - V2'; |
| 128 |
function VectorSubtract(const V1, V2: TVector3): TVector3; overload; deprecated 'use V1 - V2'; |
| 129 |
function VectorSubtract(const V1, V2: TVector4): TVector4; overload; deprecated 'use V1 - V2'; |
| 130 |
function VectorMultiplyComponents(const V1, V2: TVector2): TVector2; overload; deprecated 'use V1 * V2'; |
| 131 |
function VectorMultiplyComponents(const V1, V2: TVector3): TVector3; overload; deprecated 'use V1 * V2'; |
| 132 |
function VectorMultiplyComponents(const V1, V2: TVector4): TVector4; overload; deprecated 'use V1 * V2'; |
| 133 |
function VectorProduct(const V1, V2: TVector3): TVector3; overload; deprecated 'use TVector3.CrossProduct'; |
| 134 |
function Normalized(const V: TVector2): TVector2; overload; deprecated 'use V.Normalize method'; |
| 135 |
function Normalized(const V: TVector3): TVector3; overload; deprecated 'use V.Normalize method'; |
| 136 |
procedure NormalizeVar(var V: TVector2); overload; deprecated 'use V := V.Normalize'; |
| 137 |
procedure NormalizeVar(var V: TVector3); overload; deprecated 'use V := V.Normalize'; |
| 138 |
function MatrixMult(const M1, M2: TMatrix4): TMatrix4; overload; deprecated 'use * operator to multiply matrices'; |
| 139 |
function MatrixMultPoint(const M: TMatrix4; const P: TVector2): TVector2; overload; deprecated 'use M.MultPoint method'; |
| 140 |
function MatrixMultPoint(const M: TMatrix4; const P: TVector3): TVector3; overload; deprecated 'use M.MultPoint method'; |
| 141 |
function MatrixMultDirection(const M: TMatrix4; const P: TVector2): TVector2; overload; deprecated 'use M.MultDirection method'; |
| 142 |
function MatrixMultDirection(const M: TMatrix4; const P: TVector3): TVector3; overload; deprecated 'use M.MultDirection method'; |
| 143 |
function VectorLenSqr(const V: TVector2): Single; overload; deprecated 'use V.LengthSqr'; |
| 144 |
function VectorLenSqr(const V: TVector3): Single; overload; deprecated 'use V.LengthSqr'; |
| 145 |
function VectorLenSqr(const V: TVector4): Single; overload; deprecated 'use V.LengthSqr'; |
| 146 |
function VectorLen(const V: TVector2): Single; overload; deprecated 'use V.Length'; |
| 147 |
function VectorLen(const V: TVector3): Single; overload; deprecated 'use V.Length'; |
| 148 |
function VectorLen(const V: TVector4): Single; overload; deprecated 'use V.Length'; |
| 149 |
function VectorAverage(const V: TVector3): Single; overload; deprecated 'use V.Average'; |
| 150 |
function VectorToRawStr(const V: TVector2): string; overload; deprecated 'use V.ToRawString'; |
| 151 |
function VectorToRawStr(const V: TVector3): string; overload; deprecated 'use V.ToRawString'; |
| 152 |
function VectorToRawStr(const V: TVector4): string; overload; deprecated 'use V.ToRawString'; |
| 153 |
function VectorToNiceStr(const V: TVector2): string; overload; deprecated 'use V.ToString'; |
| 154 |
function VectorToNiceStr(const V: TVector3): string; overload; deprecated 'use V.ToString'; |
| 155 |
function VectorToNiceStr(const V: TVector4): string; overload; deprecated 'use V.ToString'; |
| 156 |
function VectorToNiceStr(const V: TVector2Integer): string; overload; deprecated 'use V.ToString'; |
| 157 |
function VectorToNiceStr(const V: TVector3Integer): string; overload; deprecated 'use V.ToString'; |
| 158 |
function VectorToNiceStr(const V: TVector4Integer): string; overload; deprecated 'use V.ToString'; |
| 159 |
function VectorToNiceStr(const V: TVector2Cardinal): string; overload; deprecated 'use V.ToString'; |
| 160 |
function VectorToNiceStr(const V: TVector3Cardinal): string; overload; deprecated 'use V.ToString'; |
| 161 |
function VectorToNiceStr(const V: TVector4Cardinal): string; overload; deprecated 'use V.ToString'; |
| 162 |
function VectorToNiceStr(const V: TVector2Byte): string; overload; deprecated 'use V.ToString'; |
| 163 |
function VectorToNiceStr(const V: TVector3Byte): string; overload; deprecated 'use V.ToString'; |
| 164 |
function VectorToNiceStr(const V: TVector4Byte): string; overload; deprecated 'use V.ToString'; |
| 165 |
function ZeroVector(const V: TVector2): boolean; overload; deprecated 'use V.IsZero'; |
| 166 |
function ZeroVector(const V: TVector3): boolean; overload; deprecated 'use V.IsZero'; |
| 167 |
function ZeroVector(const V: TVector4): boolean; overload; deprecated 'use V.IsZero'; |
| 168 |
function ZeroVector(const V: TVector2Byte): boolean; overload; deprecated 'use V.IsZero'; |
| 169 |
function ZeroVector(const V: TVector3Byte): boolean; overload; deprecated 'use V.IsZero'; |
| 170 |
function ZeroVector(const V: TVector4Byte): boolean; overload; deprecated 'use V.IsZero'; |
| 171 |
function ZeroVector(const V: TVector2Integer): boolean; overload; deprecated 'use V.IsZero'; |
| 172 |
function ZeroVector(const V: TVector3Integer): boolean; overload; deprecated 'use V.IsZero'; |
| 173 |
function ZeroVector(const V: TVector4Integer): boolean; overload; deprecated 'use V.IsZero'; |
| 174 |
function ZeroVector(const V: TVector2Cardinal): boolean; overload; deprecated 'use V.IsZero'; |
| 175 |
function ZeroVector(const V: TVector3Cardinal): boolean; overload; deprecated 'use V.IsZero'; |
| 176 |
function ZeroVector(const V: TVector4Cardinal): boolean; overload; deprecated 'use V.IsZero'; |
| 177 |
function PerfectlyZeroVector(const V: TVector2): boolean; overload; deprecated 'use V.IsPerfectlyZero'; |
| 178 |
function PerfectlyZeroVector(const V: TVector3): boolean; overload; deprecated 'use V.IsPerfectlyZero'; |
| 179 |
function PerfectlyZeroVector(const V: TVector4): boolean; overload; deprecated 'use V.IsPerfectlyZero'; |
| 180 |
function VectorAdjustToLength(const V: TVector2; const NewLength: Single): TVector2; overload; deprecated 'use V.AdjustToLength'; |
| 181 |
function VectorAdjustToLength(const V: TVector3; const NewLength: Single): TVector3; overload; deprecated 'use V.AdjustToLength'; |
| 182 |
function VectorAdjustToLength(const V: TVector4; const NewLength: Single): TVector4; overload; deprecated 'use V.AdjustToLength'; |
| 183 |
function Vector2SingleFromStr(const S: string): TVector2; overload; deprecated 'use Vector2FromStr'; |
| 184 |
function Vector3SingleFromStr(const s: string): TVector3; overload; deprecated 'use Vector3FromStr'; |
| 185 |
function Vector4SingleFromStr(const S: string): TVector4; overload; deprecated 'use Vector4FromStr'; |
| 186 |
function VectorDotProduct(const V1, V2: TVector2): Single; overload; deprecated 'use TVector2.DotProduct(V1, V2)'; |
| 187 |
function VectorDotProduct(const V1, V2: TVector3): Single; overload; deprecated 'use TVector3.DotProduct(V1, V2)'; |
| 188 |
function VectorDotProduct(const V1, V2: TVector4): Single; overload; deprecated 'use TVector4.DotProduct(V1, V2)'; |
| 189 |
function VectorsEqual(const V1, V2: TVector2): boolean; overload; deprecated 'use TVector2.Equals(V1, V2)'; |
| 190 |
function VectorsEqual(const V1, V2: TVector3): boolean; overload; deprecated 'use TVector3.Equals(V1, V2)'; |
| 191 |
function VectorsEqual(const V1, V2: TVector4): boolean; overload; deprecated 'use TVector4.Equals(V1, V2)'; |
| 192 |
function VectorsEqual(const V1, V2: TVector2; const Epsilon: Single): boolean; overload; deprecated 'use TVector2.Equals(V1, V2, Epsilon)'; |
| 193 |
function VectorsEqual(const V1, V2: TVector3; const Epsilon: Single): boolean; overload; deprecated 'use TVector3.Equals(V1, V2, Epsilon)'; |
| 194 |
function VectorsEqual(const V1, V2: TVector4; const Epsilon: Single): boolean; overload; deprecated 'use TVector4.Equals(V1, V2, Epsilon)'; |
| 195 |
function VectorsPerfectlyEqual(const V1, V2: TVector2): boolean; overload; deprecated 'use TVector2.PerfectlyEquals(V1, V2)'; |
| 196 |
function VectorsPerfectlyEqual(const V1, V2: TVector3): boolean; overload; deprecated 'use TVector3.PerfectlyEquals(V1, V2)'; |
| 197 |
function VectorsPerfectlyEqual(const V1, V2: TVector4): boolean; overload; deprecated 'use TVector4.PerfectlyEquals(V1, V2)'; |
| 198 |
function VectorsPerfectlyEqual(const V1, V2: TVector2Byte): boolean; overload; deprecated 'use TVector2Byte.Equals(V1, V2)'; |
| 199 |
function VectorsPerfectlyEqual(const V1, V2: TVector3Byte): boolean; overload; deprecated 'use TVector3Byte.Equals(V1, V2)'; |
| 200 |
function VectorsPerfectlyEqual(const V1, V2: TVector4Byte): boolean; overload; deprecated 'use TVector4Byte.Equals(V1, V2)'; |
| 201 |
function VectorsPerfectlyEqual(const V1, V2: TVector2Integer): boolean; overload; deprecated 'use TVector2Integer.Equals(V1, V2)'; |
| 202 |
function VectorsPerfectlyEqual(const V1, V2: TVector3Integer): boolean; overload; deprecated 'use TVector3Integer.Equals(V1, V2)'; |
| 203 |
function VectorsPerfectlyEqual(const V1, V2: TVector4Integer): boolean; overload; deprecated 'use TVector4Integer.Equals(V1, V2)'; |
| 204 |
function VectorsPerfectlyEqual(const V1, V2: TVector2Cardinal): boolean; overload; deprecated 'use TVector2Cardinal.Equals(V1, V2)'; |
| 205 |
function VectorsPerfectlyEqual(const V1, V2: TVector3Cardinal): boolean; overload; deprecated 'use TVector3Cardinal.Equals(V1, V2)'; |
| 206 |
function VectorsPerfectlyEqual(const V1, V2: TVector4Cardinal): boolean; overload; deprecated 'use TVector4Cardinal.Equals(V1, V2)'; |
| 207 |
function TryMatrixInverse(const M: TMatrix2; out MInverse: TMatrix2): boolean; overload; overload; deprecated 'use TMatrix2.TryInverse'; |
| 208 |
function TryMatrixInverse(const M: TMatrix3; out MInverse: TMatrix3): boolean; overload; overload; deprecated 'use TMatrix3.TryInverse'; |
| 209 |
function TryMatrixInverse(const M: TMatrix4; out MInverse: TMatrix4): boolean; overload; overload; deprecated 'use TMatrix4.TryInverse'; |
| 210 |
function MatrixToRawStr(const M: TMatrix2; const LineIndent: string): string; overload; overload; deprecated 'use TMatrix2.ToRawString'; |
| 211 |
function MatrixToRawStr(const M: TMatrix3; const LineIndent: string): string; overload; overload; deprecated 'use TMatrix3.ToRawString'; |
| 212 |
function MatrixToRawStr(const M: TMatrix4; const LineIndent: string): string; overload; overload; deprecated 'use TMatrix4.ToRawString'; |
| 213 |
function MatrixToNiceStr(const M: TMatrix2; const LineIndent: string): string; overload; overload; deprecated 'use TMatrix2.ToString'; |
| 214 |
function MatrixToNiceStr(const M: TMatrix3; const LineIndent: string): string; overload; overload; deprecated 'use TMatrix3.ToString'; |
| 215 |
function MatrixToNiceStr(const M: TMatrix4; const LineIndent: string): string; overload; overload; deprecated 'use TMatrix4.ToString'; |
| 216 |
function MatricesPerfectlyEqual(const V1, V2: TMatrix2): boolean; overload; deprecated 'use TMatrix2.PerfectlyEquals(V1, V2)'; |
| 217 |
function MatricesPerfectlyEqual(const V1, V2: TMatrix3): boolean; overload; deprecated 'use TMatrix3.PerfectlyEquals(V1, V2)'; |
| 218 |
function MatricesPerfectlyEqual(const V1, V2: TMatrix4): boolean; overload; deprecated 'use TMatrix4.PerfectlyEquals(V1, V2)'; |
| 219 |
function MatrixRow(const M: TMatrix2; const Row: Integer): TVector2; overload; overload; deprecated 'use TMatrix2.Rows[Row]'; |
| 220 |
function MatrixRow(const M: TMatrix3; const Row: Integer): TVector3; overload; overload; deprecated 'use TMatrix3.Rows[Row]'; |
| 221 |
function MatrixRow(const M: TMatrix4; const Row: Integer): TVector4; overload; overload; deprecated 'use TMatrix4.Rows[Row]'; |
| 222 |
function Vector2SingleCut(const V: TVector3): TVector2; overload; deprecated 'use V.XY'; |
| 223 |
function Vector3SingleCut(const V: TVector4): TVector3; overload; deprecated 'use V.XYZ'; |
| 224 |
function Matrix3Single(const V: TMatrix3Double): TMatrix3; overload; deprecated 'use Matrix3'; |
| 225 |
function Matrix4Single(const V: TMatrix4Double): TMatrix4; overload; deprecated 'use Matrix4'; |
| 226 |
|
| 227 |
{$endif read_interface} |
| 228 |
|
| 229 |
{$ifdef read_implementation} |
| 230 |
|
| 231 |
{ Construct 2D float vectors ------------------------------------------------------------ } |
| 232 |
|
| 233 |
function Vector2Single(const X, Y: Single): TVector2; |
| 234 |
begin |
| 235 |
Result.X := X; |
| 236 |
Result.Y := Y; |
| 237 |
end; |
| 238 |
|
| 239 |
function Vector2Single(const V: TVector2Double): TVector2; |
| 240 |
begin |
| 241 |
Result.X := V.X; |
| 242 |
Result.Y := V.Y; |
| 243 |
end; |
| 244 |
|
| 245 |
{ Construct 3D float vectors ------------------------------------------------------------ } |
| 246 |
|
| 247 |
function Vector3Single(const X, Y, Z: Single): TVector3; |
| 248 |
begin |
| 249 |
Result.X := X; |
| 250 |
Result.Y := Y; |
| 251 |
Result.Z := Z; |
| 252 |
end; |
| 253 |
|
| 254 |
function Vector3Single(const V: TVector2; const Z: Single): TVector3; |
| 255 |
begin |
| 256 |
Result.X := V.X; |
| 257 |
Result.Y := V.Y; |
| 258 |
Result.Z := Z; |
| 259 |
end; |
| 260 |
|
| 261 |
function Vector3Single(const V: TVector3Double): TVector3; |
| 262 |
begin |
| 263 |
Result.X := V.X; |
| 264 |
Result.Y := V.Y; |
| 265 |
Result.Z := V.Z; |
| 266 |
end; |
| 267 |
|
| 268 |
{ Construct 4D float vectors ------------------------------------------------------------ } |
| 269 |
|
| 270 |
function Vector4Single(const X, Y, Z, W: Single): TVector4; |
| 271 |
begin |
| 272 |
Result.X := X; |
| 273 |
Result.Y := Y; |
| 274 |
Result.Z := Z; |
| 275 |
Result.W := W; |
| 276 |
end; |
| 277 |
|
| 278 |
function Vector4Single(const V: TVector3; const W: Single): TVector4; |
| 279 |
begin |
| 280 |
Result.X := V.X; |
| 281 |
Result.Y := V.Y; |
| 282 |
Result.Z := V.Z; |
| 283 |
Result.W := W; |
| 284 |
end; |
| 285 |
|
| 286 |
function Vector4Single(const V: TVector4Double): TVector4; |
| 287 |
begin |
| 288 |
Result.X := V.X; |
| 289 |
Result.Y := V.Y; |
| 290 |
Result.Z := V.Z; |
| 291 |
Result.W := V.W; |
| 292 |
end; |
| 293 |
|
| 294 |
{ float compatibility functions ---------------------------------------------- } |
| 295 |
|
| 296 |
function FloatsEqual(const A, B: Single): boolean; |
| 297 |
begin |
| 298 |
Result := SameValue(A, B); |
| 299 |
end; |
| 300 |
|
| 301 |
function FloatsEqual(const A, B, Epsilon: Single): boolean; |
| 302 |
begin |
| 303 |
Result := SameValue(A, B, Epsilon); |
| 304 |
end; |
| 305 |
|
| 306 |
function FloatToNiceStr(const A: Single): string; |
| 307 |
begin |
| 308 |
Result := Format('%f', [A]); |
| 309 |
end; |
| 310 |
|
| 311 |
function FloatToRawStr(const A: Single): string; |
| 312 |
begin |
| 313 |
Result := Format('%g', [A]); |
| 314 |
end; |
| 315 |
|
| 316 |
function Zero(const A: Single): boolean; |
| 317 |
begin |
| 318 |
Result := IsZero(A); |
| 319 |
end; |
| 320 |
|
| 321 |
{ various compatibility functions -------------------------------------------- } |
| 322 |
|
| 323 |
function VectorAdd(const V1, V2: TVector2): TVector2; |
| 324 |
begin |
| 325 |
Result := V1 + V2; |
| 326 |
end; |
| 327 |
|
| 328 |
function VectorAdd(const V1, V2: TVector3): TVector3; |
| 329 |
begin |
| 330 |
Result := V1 + V2; |
| 331 |
end; |
| 332 |
|
| 333 |
function VectorAdd(const V1, V2: TVector4): TVector4; |
| 334 |
begin |
| 335 |
Result := V1 + V2; |
| 336 |
end; |
| 337 |
|
| 338 |
function VectorSubtract(const V1, V2: TVector2): TVector2; |
| 339 |
begin |
| 340 |
Result := V1 - V2; |
| 341 |
end; |
| 342 |
|
| 343 |
function VectorSubtract(const V1, V2: TVector3): TVector3; |
| 344 |
begin |
| 345 |
Result := V1 - V2; |
| 346 |
end; |
| 347 |
|
| 348 |
function VectorSubtract(const V1, V2: TVector4): TVector4; |
| 349 |
begin |
| 350 |
Result := V1 - V2; |
| 351 |
end; |
| 352 |
|
| 353 |
function VectorMultiplyComponents(const V1, V2: TVector2): TVector2; |
| 354 |
begin |
| 355 |
Result := V1 * V2; |
| 356 |
end; |
| 357 |
|
| 358 |
function VectorMultiplyComponents(const V1, V2: TVector3): TVector3; |
| 359 |
begin |
| 360 |
Result := V1 * V2; |
| 361 |
end; |
| 362 |
|
| 363 |
function VectorMultiplyComponents(const V1, V2: TVector4): TVector4; |
| 364 |
begin |
| 365 |
Result := V1 * V2; |
| 366 |
end; |
| 367 |
|
| 368 |
function VectorProduct(const V1, V2: TVector3): TVector3; |
| 369 |
begin |
| 370 |
Result := TVector3.CrossProduct(V1, V2); |
| 371 |
end; |
| 372 |
|
| 373 |
function Normalized(const V: TVector2): TVector2; |
| 374 |
begin |
| 375 |
Result := V.Normalize; |
| 376 |
end; |
| 377 |
|
| 378 |
function Normalized(const V: TVector3): TVector3; |
| 379 |
begin |
| 380 |
Result := V.Normalize; |
| 381 |
end; |
| 382 |
|
| 383 |
procedure NormalizeVar(var V: TVector2); |
| 384 |
begin |
| 385 |
V := V.Normalize; |
| 386 |
end; |
| 387 |
|
| 388 |
procedure NormalizeVar(var V: TVector3); |
| 389 |
begin |
| 390 |
V := V.Normalize; |
| 391 |
end; |
| 392 |
|
| 393 |
function MatrixMult(const M1, M2: TMatrix4): TMatrix4; |
| 394 |
begin |
| 395 |
Result := M1 * M2; |
| 396 |
end; |
| 397 |
|
| 398 |
function MatrixMultPoint(const M: TMatrix4; const P: TVector2): TVector2; |
| 399 |
begin |
| 400 |
Result := M.MultPoint(P); |
| 401 |
end; |
| 402 |
|
| 403 |
function MatrixMultPoint(const M: TMatrix4; const P: TVector3): TVector3; |
| 404 |
begin |
| 405 |
Result := M.MultPoint(P); |
| 406 |
end; |
| 407 |
|
| 408 |
function MatrixMultDirection(const M: TMatrix4; const P: TVector2): TVector2; |
| 409 |
begin |
| 410 |
Result := M.MultDirection(P); |
| 411 |
end; |
| 412 |
|
| 413 |
function MatrixMultDirection(const M: TMatrix4; const P: TVector3): TVector3; |
| 414 |
begin |
| 415 |
Result := M.MultDirection(P); |
| 416 |
end; |
| 417 |
|
| 418 |
function VectorLenSqr(const V: TVector2): Single; |
| 419 |
begin |
| 420 |
Result := V.LengthSqr; |
| 421 |
end; |
| 422 |
|
| 423 |
function VectorLenSqr(const V: TVector3): Single; |
| 424 |
begin |
| 425 |
Result := V.LengthSqr; |
| 426 |
end; |
| 427 |
|
| 428 |
function VectorLenSqr(const V: TVector4): Single; |
| 429 |
begin |
| 430 |
Result := V.LengthSqr; |
| 431 |
end; |
| 432 |
|
| 433 |
function VectorLen(const V: TVector2): Single; |
| 434 |
begin |
| 435 |
Result := V.Length; |
| 436 |
end; |
| 437 |
|
| 438 |
function VectorLen(const V: TVector3): Single; |
| 439 |
begin |
| 440 |
Result := V.Length; |
| 441 |
end; |
| 442 |
|
| 443 |
function VectorLen(const V: TVector4): Single; |
| 444 |
begin |
| 445 |
Result := V.Length; |
| 446 |
end; |
| 447 |
|
| 448 |
function VectorAverage(const V: TVector3): Single; |
| 449 |
begin |
| 450 |
Result := V.Average; |
| 451 |
end; |
| 452 |
|
| 453 |
function VectorToRawStr(const V: TVector2): string; |
| 454 |
begin |
| 455 |
Result := V.ToRawString; |
| 456 |
end; |
| 457 |
|
| 458 |
function VectorToRawStr(const V: TVector3): string; |
| 459 |
begin |
| 460 |
Result := V.ToRawString; |
| 461 |
end; |
| 462 |
|
| 463 |
function VectorToRawStr(const V: TVector4): string; |
| 464 |
begin |
| 465 |
Result := V.ToRawString; |
| 466 |
end; |
| 467 |
|
| 468 |
function VectorToNiceStr(const V: TVector2): string; |
| 469 |
begin |
| 470 |
Result := V.ToString; |
| 471 |
end; |
| 472 |
|
| 473 |
function VectorToNiceStr(const V: TVector3): string; |
| 474 |
begin |
| 475 |
Result := V.ToString; |
| 476 |
end; |
| 477 |
|
| 478 |
function VectorToNiceStr(const V: TVector4): string; |
| 479 |
begin |
| 480 |
Result := V.ToString; |
| 481 |
end; |
| 482 |
|
| 483 |
function VectorToNiceStr(const V: TVector2Integer): string; |
| 484 |
begin |
| 485 |
Result := V.ToString; |
| 486 |
end; |
| 487 |
|
| 488 |
function VectorToNiceStr(const V: TVector3Integer): string; |
| 489 |
begin |
| 490 |
Result := V.ToString; |
| 491 |
end; |
| 492 |
|
| 493 |
function VectorToNiceStr(const V: TVector4Integer): string; |
| 494 |
begin |
| 495 |
Result := V.ToString; |
| 496 |
end; |
| 497 |
|
| 498 |
function VectorToNiceStr(const V: TVector2Cardinal): string; |
| 499 |
begin |
| 500 |
Result := V.ToString; |
| 501 |
end; |
| 502 |
|
| 503 |
function VectorToNiceStr(const V: TVector3Cardinal): string; |
| 504 |
begin |
| 505 |
Result := V.ToString; |
| 506 |
end; |
| 507 |
|
| 508 |
function VectorToNiceStr(const V: TVector4Cardinal): string; |
| 509 |
begin |
| 510 |
Result := V.ToString; |
| 511 |
end; |
| 512 |
|
| 513 |
function VectorToNiceStr(const V: TVector2Byte): string; |
| 514 |
begin |
| 515 |
Result := V.ToString; |
| 516 |
end; |
| 517 |
|
| 518 |
function VectorToNiceStr(const V: TVector3Byte): string; |
| 519 |
begin |
| 520 |
Result := V.ToString; |
| 521 |
end; |
| 522 |
|
| 523 |
function VectorToNiceStr(const V: TVector4Byte): string; |
| 524 |
begin |
| 525 |
Result := V.ToString; |
| 526 |
end; |
| 527 |
|
| 528 |
function ZeroVector(const V: TVector2): boolean; |
| 529 |
begin |
| 530 |
Result := V.IsZero; |
| 531 |
end; |
| 532 |
|
| 533 |
function ZeroVector(const V: TVector3): boolean; |
| 534 |
begin |
| 535 |
Result := V.IsZero; |
| 536 |
end; |
| 537 |
|
| 538 |
function ZeroVector(const V: TVector4): boolean; |
| 539 |
begin |
| 540 |
Result := V.IsZero; |
| 541 |
end; |
| 542 |
|
| 543 |
function ZeroVector(const V: TVector2Byte): boolean; |
| 544 |
begin |
| 545 |
Result := V.IsZero; |
| 546 |
end; |
| 547 |
|
| 548 |
function ZeroVector(const V: TVector3Byte): boolean; |
| 549 |
begin |
| 550 |
Result := V.IsZero; |
| 551 |
end; |
| 552 |
|
| 553 |
function ZeroVector(const V: TVector4Byte): boolean; |
| 554 |
begin |
| 555 |
Result := V.IsZero; |
| 556 |
end; |
| 557 |
|
| 558 |
function ZeroVector(const V: TVector2Integer): boolean; |
| 559 |
begin |
| 560 |
Result := V.IsZero; |
| 561 |
end; |
| 562 |
|
| 563 |
function ZeroVector(const V: TVector3Integer): boolean; |
| 564 |
begin |
| 565 |
Result := V.IsZero; |
| 566 |
end; |
| 567 |
|
| 568 |
function ZeroVector(const V: TVector4Integer): boolean; |
| 569 |
begin |
| 570 |
Result := V.IsZero; |
| 571 |
end; |
| 572 |
|
| 573 |
function ZeroVector(const V: TVector2Cardinal): boolean; |
| 574 |
begin |
| 575 |
Result := V.IsZero; |
| 576 |
end; |
| 577 |
|
| 578 |
function ZeroVector(const V: TVector3Cardinal): boolean; |
| 579 |
begin |
| 580 |
Result := V.IsZero; |
| 581 |
end; |
| 582 |
|
| 583 |
function ZeroVector(const V: TVector4Cardinal): boolean; |
| 584 |
begin |
| 585 |
Result := V.IsZero; |
| 586 |
end; |
| 587 |
|
| 588 |
function PerfectlyZeroVector(const V: TVector2): boolean; |
| 589 |
begin |
| 590 |
Result := V.IsPerfectlyZero; |
| 591 |
end; |
| 592 |
|
| 593 |
function PerfectlyZeroVector(const V: TVector3): boolean; |
| 594 |
begin |
| 595 |
Result := V.IsPerfectlyZero; |
| 596 |
end; |
| 597 |
|
| 598 |
function PerfectlyZeroVector(const V: TVector4): boolean; |
| 599 |
begin |
| 600 |
Result := V.IsPerfectlyZero; |
| 601 |
end; |
| 602 |
|
| 603 |
function VectorAdjustToLength(const V: TVector2; const NewLength: Single): TVector2; |
| 604 |
begin |
| 605 |
Result := V.AdjustToLength(NewLength); |
| 606 |
end; |
| 607 |
|
| 608 |
function VectorAdjustToLength(const V: TVector3; const NewLength: Single): TVector3; |
| 609 |
begin |
| 610 |
Result := V.AdjustToLength(NewLength); |
| 611 |
end; |
| 612 |
|
| 613 |
function VectorAdjustToLength(const V: TVector4; const NewLength: Single): TVector4; |
| 614 |
begin |
| 615 |
Result := V.AdjustToLength(NewLength); |
| 616 |
end; |
| 617 |
|
| 618 |
function Vector2SingleFromStr(const S: string): TVector2; |
| 619 |
begin |
| 620 |
Result := Vector2FromStr(S); |
| 621 |
end; |
| 622 |
|
| 623 |
function Vector3SingleFromStr(const s: string): TVector3; |
| 624 |
begin |
| 625 |
Result := Vector3FromStr(S); |
| 626 |
end; |
| 627 |
|
| 628 |
function Vector4SingleFromStr(const S: string): TVector4; |
| 629 |
begin |
| 630 |
Result := Vector4FromStr(S); |
| 631 |
end; |
| 632 |
|
| 633 |
function VectorDotProduct(const V1, V2: TVector2): Single; |
| 634 |
begin |
| 635 |
Result := TVector2.DotProduct(V1, V2); |
| 636 |
end; |
| 637 |
|
| 638 |
function VectorDotProduct(const V1, V2: TVector3): Single; |
| 639 |
begin |
| 640 |
Result := TVector3.DotProduct(V1, V2); |
| 641 |
end; |
| 642 |
|
| 643 |
function VectorDotProduct(const V1, V2: TVector4): Single; |
| 644 |
begin |
| 645 |
Result := TVector4.DotProduct(V1, V2); |
| 646 |
end; |
| 647 |
|
| 648 |
function VectorsEqual(const V1, V2: TVector2): boolean; |
| 649 |
begin |
| 650 |
Result := TVector2.Equals(V1, V2); |
| 651 |
end; |
| 652 |
|
| 653 |
function VectorsEqual(const V1, V2: TVector3): boolean; |
| 654 |
begin |
| 655 |
Result := TVector3.Equals(V1, V2); |
| 656 |
end; |
| 657 |
|
| 658 |
function VectorsEqual(const V1, V2: TVector4): boolean; |
| 659 |
begin |
| 660 |
Result := TVector4.Equals(V1, V2); |
| 661 |
end; |
| 662 |
|
| 663 |
function VectorsEqual(const V1, V2: TVector2; const Epsilon: Single): boolean; |
| 664 |
begin |
| 665 |
Result := TVector2.Equals(V1, V2, Epsilon); |
| 666 |
end; |
| 667 |
|
| 668 |
function VectorsEqual(const V1, V2: TVector3; const Epsilon: Single): boolean; |
| 669 |
begin |
| 670 |
Result := TVector3.Equals(V1, V2, Epsilon); |
| 671 |
end; |
| 672 |
|
| 673 |
function VectorsEqual(const V1, V2: TVector4; const Epsilon: Single): boolean; |
| 674 |
begin |
| 675 |
Result := TVector4.Equals(V1, V2, Epsilon); |
| 676 |
end; |
| 677 |
|
| 678 |
function VectorsPerfectlyEqual(const V1, V2: TVector2): boolean; |
| 679 |
begin |
| 680 |
Result := TVector2.PerfectlyEquals(V1, V2); |
| 681 |
end; |
| 682 |
|
| 683 |
function VectorsPerfectlyEqual(const V1, V2: TVector3): boolean; |
| 684 |
begin |
| 685 |
Result := TVector3.PerfectlyEquals(V1, V2); |
| 686 |
end; |
| 687 |
|
| 688 |
function VectorsPerfectlyEqual(const V1, V2: TVector4): boolean; |
| 689 |
begin |
| 690 |
Result := TVector4.PerfectlyEquals(V1, V2); |
| 691 |
end; |
| 692 |
|
| 693 |
function VectorsPerfectlyEqual(const V1, V2: TVector2Byte): boolean; |
| 694 |
begin |
| 695 |
Result := TVector2Byte.Equals(V1, V2); |
| 696 |
end; |
| 697 |
|
| 698 |
function VectorsPerfectlyEqual(const V1, V2: TVector3Byte): boolean; |
| 699 |
begin |
| 700 |
Result := TVector3Byte.Equals(V1, V2); |
| 701 |
end; |
| 702 |
|
| 703 |
function VectorsPerfectlyEqual(const V1, V2: TVector4Byte): boolean; |
| 704 |
begin |
| 705 |
Result := TVector4Byte.Equals(V1, V2); |
| 706 |
end; |
| 707 |
|
| 708 |
function VectorsPerfectlyEqual(const V1, V2: TVector2Integer): boolean; |
| 709 |
begin |
| 710 |
Result := TVector2Integer.Equals(V1, V2); |
| 711 |
end; |
| 712 |
|
| 713 |
function VectorsPerfectlyEqual(const V1, V2: TVector3Integer): boolean; |
| 714 |
begin |
| 715 |
Result := TVector3Integer.Equals(V1, V2); |
| 716 |
end; |
| 717 |
|
| 718 |
function VectorsPerfectlyEqual(const V1, V2: TVector4Integer): boolean; |
| 719 |
begin |
| 720 |
Result := TVector4Integer.Equals(V1, V2); |
| 721 |
end; |
| 722 |
|
| 723 |
function VectorsPerfectlyEqual(const V1, V2: TVector2Cardinal): boolean; |
| 724 |
begin |
| 725 |
Result := TVector2Cardinal.Equals(V1, V2); |
| 726 |
end; |
| 727 |
|
| 728 |
function VectorsPerfectlyEqual(const V1, V2: TVector3Cardinal): boolean; |
| 729 |
begin |
| 730 |
Result := TVector3Cardinal.Equals(V1, V2); |
| 731 |
end; |
| 732 |
|
| 733 |
function VectorsPerfectlyEqual(const V1, V2: TVector4Cardinal): boolean; |
| 734 |
begin |
| 735 |
Result := TVector4Cardinal.Equals(V1, V2); |
| 736 |
end; |
| 737 |
|
| 738 |
function TryMatrixInverse(const M: TMatrix2; out MInverse: TMatrix2): boolean; |
| 739 |
begin |
| 740 |
Result := M.TryInverse(MInverse); |
| 741 |
end; |
| 742 |
|
| 743 |
function TryMatrixInverse(const M: TMatrix3; out MInverse: TMatrix3): boolean; |
| 744 |
begin |
| 745 |
Result := M.TryInverse(MInverse); |
| 746 |
end; |
| 747 |
|
| 748 |
function TryMatrixInverse(const M: TMatrix4; out MInverse: TMatrix4): boolean; |
| 749 |
begin |
| 750 |
Result := M.TryInverse(MInverse); |
| 751 |
end; |
| 752 |
|
| 753 |
function MatrixToRawStr(const M: TMatrix2; const LineIndent: string): string; |
| 754 |
begin |
| 755 |
Result := M.ToRawString(LineIndent); |
| 756 |
end; |
| 757 |
|
| 758 |
function MatrixToRawStr(const M: TMatrix3; const LineIndent: string): string; |
| 759 |
begin |
| 760 |
Result := M.ToRawString(LineIndent); |
| 761 |
end; |
| 762 |
|
| 763 |
function MatrixToRawStr(const M: TMatrix4; const LineIndent: string): string; |
| 764 |
begin |
| 765 |
Result := M.ToRawString(LineIndent); |
| 766 |
end; |
| 767 |
|
| 768 |
function MatrixToNiceStr(const M: TMatrix2; const LineIndent: string): string; |
| 769 |
begin |
| 770 |
Result := M.ToString(LineIndent); |
| 771 |
end; |
| 772 |
|
| 773 |
function MatrixToNiceStr(const M: TMatrix3; const LineIndent: string): string; |
| 774 |
begin |
| 775 |
Result := M.ToString(LineIndent); |
| 776 |
end; |
| 777 |
|
| 778 |
function MatrixToNiceStr(const M: TMatrix4; const LineIndent: string): string; |
| 779 |
begin |
| 780 |
Result := M.ToString(LineIndent); |
| 781 |
end; |
| 782 |
|
| 783 |
function MatricesPerfectlyEqual(const V1, V2: TMatrix2): boolean; |
| 784 |
begin |
| 785 |
Result := TMatrix2.PerfectlyEquals(V1, V2); |
| 786 |
end; |
| 787 |
|
| 788 |
function MatricesPerfectlyEqual(const V1, V2: TMatrix3): boolean; |
| 789 |
begin |
| 790 |
Result := TMatrix3.PerfectlyEquals(V1, V2); |
| 791 |
end; |
| 792 |
|
| 793 |
function MatricesPerfectlyEqual(const V1, V2: TMatrix4): boolean; |
| 794 |
begin |
| 795 |
Result := TMatrix4.PerfectlyEquals(V1, V2); |
| 796 |
end; |
| 797 |
|
| 798 |
function MatrixRow(const M: TMatrix2; const Row: Integer): TVector2; |
| 799 |
begin |
| 800 |
Result := M.Rows[Row]; |
| 801 |
end; |
| 802 |
|
| 803 |
function MatrixRow(const M: TMatrix3; const Row: Integer): TVector3; |
| 804 |
begin |
| 805 |
Result := M.Rows[Row]; |
| 806 |
end; |
| 807 |
|
| 808 |
function MatrixRow(const M: TMatrix4; const Row: Integer): TVector4; |
| 809 |
begin |
| 810 |
Result := M.Rows[Row]; |
| 811 |
end; |
| 812 |
|
| 813 |
function Vector2SingleCut(const V: TVector3): TVector2; |
| 814 |
begin |
| 815 |
Result := V.XY; |
| 816 |
end; |
| 817 |
|
| 818 |
function Vector3SingleCut(const V: TVector4): TVector3; |
| 819 |
begin |
| 820 |
Result := V.XYZ; |
| 821 |
end; |
| 822 |
|
| 823 |
function Matrix3Single(const V: TMatrix3Double): TMatrix3; |
| 824 |
begin |
| 825 |
Result := Matrix3(V); |
| 826 |
end; |
| 827 |
|
| 828 |
function Matrix4Single(const V: TMatrix4Double): TMatrix4; |
| 829 |
begin |
| 830 |
Result := Matrix4(V); |
| 831 |
end; |
| 832 |
|
| 833 |
{$endif read_implementation} |