summaryrefslogtreecommitdiff
path: root/fpcsrc/packages/libndsfpc/src/nds/arm9/trig_lut.inc
blob: aa14c1b74c665538c45217a66577b68b23ab20d8 (plain)
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
60
61
62
{$ifdef NDS_INTERFACE}
const
  DEGREES_IN_CIRCLE = (1 shl 15);

function fixedToInt(n, bits: cint): cint; inline;
function intToFixed(n, bits: cint): cint; inline;

function floatToFixed(n, bits: cint): cint; inline;
function fixedToFloat(n, bits: cint): cfloat; inline;

function floorFixed(n, bits: cint): cint; inline;

function degreesToAngle(degrees: cint): cint; inline;
function angleToDegrees(angle: cint): cint; inline;

function cosLerp(angle: cint16): cint16; cdecl; external;
function sinLerp(angle: cint16): cint16; cdecl; external;
function tanLerp(angle: cint16): cint32; cdecl; external;
function acosLerp(par: cint16): cint16; cdecl; external;
function asinLerp(par: cint16): cint16; cdecl; external;

{$endif NDS_INTERFACE}

{$ifdef NDS_IMPLEMENTATION}


function fixedToInt(n, bits: cint): cint; inline;
begin
  result := cint(n shr bits);
end;

function intToFixed(n, bits: cint): cint; inline;
begin
  result := cint(n shl bits);
end;

function floatToFixed(n, bits: cint): cint; inline;
begin
  result := cint(n * cfloat(1 shl bits));
end;

function fixedToFloat(n, bits: cint): cfloat; inline;
begin
  result := cfloat(n) / cfloat(1 shl bits);
end;

function floorFixed(n, bits: cint): cint; inline;
begin
  result := cint(n and (not ((1 shl bits) - 1)));
end;

function degreesToAngle(degrees: cint): cint; inline;
begin
  result := degrees * DEGREES_IN_CIRCLE div 360;
end;

function angleToDegrees(angle: cint): cint; inline;
begin
  result := angle * 360 div DEGREES_IN_CIRCLE;
end;

{$endif NDS_IMPLEMENTATION}