2
// This unit is part of the GLScene Engine https://github.com/glscene
5
Defines vector types for geometry only aiming to imply
6
compatibility of GLScene for Delphi with C+Builder.
7
Do not include any other units in uses clause
10
01/11/13 - PW - Fixed XE5 error: E2376 static can only be used on non-virtual class methods
11
12/12/12 - PW - Added TGLVector's and TGLMatrix's types
12
11/11/11 - PW - Creation. Defined TGLPoint, TGLPolygon and TGLPolyhedron types
21
ALeft, ATop, ANear, ARight, ABottom, AFar: Single;
24
//-----------------------
26
//-----------------------
29
PGLPoint2D = ^TGLPoint2D;
34
function Create(X, Y : Single): TGLPoint2D;{$IF (FPC_VERSION < 3)} static; {$ENDIF}
35
procedure SetPosition(const X, Y : Single);
36
function Add(const APoint2D: TGLPoint2D): TGLPoint2D;
37
function Length: Single; //distance to origin
38
function Distance(const APoint2D : TGLPoint2D) : Single;
39
procedure Offset(const ADeltaX, ADeltaY : Single);
42
PGLPoint3D = ^TGLPoint3D;
48
function Create(X, Y, Z: Single): TGLPoint3D; {$IF (FPC_VERSION < 3)} static; {$ENDIF}
49
procedure SetPosition(const X, Y, Z : Single);
50
function Add(const AGLPoint3D: TGLPoint3D): TGLPoint3D;
51
function Length: Single; //distance to origin
52
function Distance(const APoint3D : TGLPoint3D) : Single;
53
procedure Offset(const ADeltaX, ADeltaY, ADeltaZ : Single);
56
TGLPoint2DArray = array of TGLPoint2D;
57
TGLPoint3DArray = array of TGLPoint3D;
60
//-----------------------
62
//-----------------------
63
TGLPolygon2D = TGLPoint2DArray;
64
TGLPolygon3D = TGLPoint3DArray;
67
ClosedPolygon2D: TGLPoint2D = (X: $FFFF; Y: $FFFF);
68
ClosedPolygon3D: TGLPoint3D = (X: $FFFF; Y: $FFFF; Z: $FFFF);
71
//-----------------------
73
//-----------------------
75
TGLPolyhedron = array of TGLPolygon3D;
77
//-----------------------
79
//-----------------------
80
TGLVector2DType = array [0..1] of Single;
81
TGLVector3DType = array [0..2] of Single;
85
function Add(const AVector2D: TGLVector2D): TGLVector2D;
86
function Norm: Single;
88
function Create(const AX, AY, AW : Single): TGLVector2D; {$IF (FPC_VERSION < 3)} static; {$ENDIF}
89
function Length: Single;
91
0: (V: TGLVector2DType;);
99
function Add(const AVector3D: TGLVector3D): TGLVector3D;
100
function Norm: Single;
102
function Create(const AX, AY, AZ, AW : Single): TGLVector3D; {$IF (FPC_VERSION < 3)} static; {$ENDIF}
103
function Length: Single;
105
0: (V: TGLVector3DType;);
112
//-----------------------
114
//-----------------------
115
TGLMatrix2DType = array[0..3] of TGLVector2D;
116
{$NODEFINE TGLMatrix2DType}
117
(*$HPPEMIT END OPENNAMESPACE*)
118
(*$HPPEMIT END 'typedef TGLVector2D TGLMatrix2DArray[4];'*)
119
(*$HPPEMIT END CLOSENAMESPACE*)
120
TGLMatrix3DType = array[0..3] of TGLVector3D;
121
{$NODEFINE TGLMatrix3DType}
122
(*$HPPEMIT END OPENNAMESPACE*)
123
(*$HPPEMIT END 'typedef TGLVector3D TGLMatrix3DType[4];'*)
124
(*$HPPEMIT END CLOSENAMESPACE*)
130
0: (M: TGLMatrix2DType;);
131
1: (e11, e12, e13: Single;
132
e21, e22, e23: Single;
133
e31, e32, e33: Single);
140
0: (M: TGLMatrix3DType;);
141
1: (e11, e12, e13, e14: Single;
142
e21, e22, e23, e24: Single;
143
e31, e32, e33, e34: Single;
144
e41, e42, e43, e44: Single);
147
TGLMatrix2DArray = array of TGLMatrix2D;
148
TGLMatrix3DArray = array of TGLMatrix3D;
151
TGLMesh2DVertex = packed record
157
TGLMesh3DVertex = packed record
163
TGLMesh2D = array of TGLMesh2DVertex;
164
TGLMesh3D = array of TGLMesh3DVertex;
167
TGLQuaternion3D = record
172
//---------------------------------------------------------------
173
//---------------------------------------------------------------
174
//---------------------------------------------------------------
181
function TGLPoint2D.Create(X, Y : Single): TGLPoint2D;
187
procedure TGLPoint2D.SetPosition(const X, Y: Single);
193
function TGLPoint2D.Length: Single;
195
Result := Sqrt(Self.X * Self.X + Self.Y * Self.Y);
198
function TGLPoint2D.Add(const APoint2D: TGLPoint2D): TGLPoint2D;
200
Result.SetPosition(Self.X + APoint2D.X, Self.Y + APoint2D.Y);
203
function TGLPoint2D.Distance(const APoint2D: TGLPoint2D): Single;
205
Result := Sqrt(Sqr(Self.X - APoint2D.X) + Sqr(Self.Y - APoint2D.Y));
208
procedure TGLPoint2D.Offset(const ADeltaX, ADeltaY: Single);
210
Self.X := Self.X + ADeltaX;
211
Self.Y := Self.Y + ADeltaY;
216
function TGLPoint3D.Create(X, Y, Z: Single): TGLPoint3D;
223
function TGLPoint3D.Add(const AGLPoint3D: TGLPoint3D): TGLPoint3D;
225
Result.X := Self.X + AGLPoint3D.X;
226
Result.Y := Self.Y + AGLPoint3D.Y;
227
Result.Z := Self.Z + AGLPoint3D.Z;
230
function TGLPoint3D.Distance(const APoint3D: TGLPoint3D): Single;
232
Result := Self.Length - APoint3D.Length;
235
function TGLPoint3D.Length: Single;
237
Result := Sqrt(Self.X * Self.X + Self.Y * Self.Y + Self.Z * Self.Z);
240
procedure TGLPoint3D.Offset(const ADeltaX, ADeltaY, ADeltaZ: Single);
242
Self.X := Self.X + ADeltaX;
243
Self.Y := Self.Y + ADeltaY;
244
Self.Z := Self.Z + ADeltaZ;
247
procedure TGLPoint3D.SetPosition(const X, Y, Z: Single);
256
function TGLVector2D.Create(const AX, AY, AW: Single): TGLVector2D;
263
function TGLVector2D.Add(const AVector2D: TGLVector2D): TGLVector2D;
265
Result.X := Self.X + AVector2D.X;
266
Result.Y := Self.Y + AVector2D.Y;
270
function TGLVector2D.Length: Single;
272
Result := Sqrt(Self.Norm);
275
function TGLVector2D.Norm: Single;
277
Result := (Self.X * Self.X) + (Self.Y * Self.Y);
282
function TGLVector3D.Create(const AX, AY, AZ, AW: Single): TGLVector3D;
290
function TGLVector3D.Add(const AVector3D: TGLVector3D): TGLVector3D;
292
Result.X := Self.X + AVector3D.X;
293
Result.Y := Self.Y + AVector3D.Y;
294
Result.Z := Self.Z + AVector3D.Z;
298
function TGLVector3D.Norm: Single;
300
Result := (Self.X * Self.X) + (Self.Y * Self.Y) + (Self.Z * Self.Z);
303
function TGLVector3D.Length: Single;
305
Result := Sqrt(Self.Norm);