-
Notifications
You must be signed in to change notification settings - Fork 0
/
smallvectorlib.pas
59 lines (48 loc) · 1.88 KB
/
smallvectorlib.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
{ *********************************************************************** }
{ }
{ Very easy Very basic vector unit for VirtualOpenAL demo app. }
{ Prototype 1A 2009200X }
{ }
{ Notes: }
{ replace bidirectional bubble sort with something.. better? }
{ }
{ Copyright (c) 2001-2006 Jernej L. }
{ }
{ *********************************************************************** }
unit smallvectorlib;
interface
type
// a vector for general processing
Vector = packed record
case boolean of
True: (x, y, z: single);
False: (componens: array[0..2] of single);
end;
Pvector = ^Vector;
function vectordistance(const v1, v2: Vector): single;
function makevector(const x, y, z: single): Vector;
function VectorSize(const vector: Vector): single;
function SubVectors(const First, second: Vector): Vector;
implementation
function VectorSize(const vector: Vector): single;
begin
Result := sqrt(vector.x * vector.x + vector.y * vector.y + vector.z * vector.z);
end;
function makevector(const x, y, z: single): Vector;
begin
Result.x := x;
Result.y := y;
Result.z := z;
end;
function SubVectors(const First, second: Vector): Vector;
begin
result:= makevector(first.x - second.x, first.y - second.y, first.z - second.z);
end;
function vectordistance(const v1, v2: Vector): single;
var
tmp: Vector;
begin
tmp := SubVectors(v2, v1);
Result := VectorSize(tmp);
end;
end.