comparison trunk/chipmunkd/chipmunk_types_h.d @ 4:7ebbd4d05553

initial commit
author Extrawurst
date Thu, 02 Dec 2010 02:11:26 +0100
parents
children
comparison
equal deleted inserted replaced
3:81145a61c2fe 4:7ebbd4d05553
1
2 // written in the D programming language
3
4 module chipmunkd.chipmunk_types_h;
5
6 //#ifdef __APPLE__
7 // #import "TargetConditionals.h"
8 //#endif
9 //
10 //#ifndef CP_USE_DOUBLES
11 // // Use single precision floats on the iPhone.
12 // #if TARGET_OS_IPHONE
13 // #define CP_USE_DOUBLES 0
14 // #else
15 // // use doubles by default for higher precision
16 // #define CP_USE_DOUBLES 1
17 // #endif
18 //#endif
19 //
20 version(CP_USE_DOUBLES){
21 alias double cpFloat;
22 //TODO:
23 // #define cpfsqrt sqrt
24 // #define cpfsin sin
25 // #define cpfcos cos
26 // #define cpfacos acos
27 // #define cpfatan2 atan2
28 // #define cpfmod fmod
29 // #define cpfexp exp
30 // #define cpfpow pow
31 // #define cpffloor floor
32 // #define cpfceil ceil
33 }else{
34 extern (C) nothrow {
35 float sqrtf(float);
36 float sinf(float);
37 float cosf(float);
38 float acosf(float);
39 float atan2f(float,float);
40 float fmodf(float,float);
41 float expf(float);
42 float powf(float,float);
43 float floorf(float);
44 float ceilf(float);
45 }
46
47 alias float cpFloat;
48
49 alias sqrtf cpfsqrt;
50 alias sinf cpfsin;
51 alias cosf cpfcos;
52 alias acosf cpfacos;
53 alias atan2f cpfatan2;
54 alias fmodf cpfmod;
55 alias expf cpfexp;
56 alias powf cpfpow;
57 alias floorf cpffloor;
58 alias ceilf cpfceil;
59 }
60
61 static cpFloat
62 cpfmax(cpFloat a, cpFloat b)
63 {
64 return (a > b) ? a : b;
65 }
66
67 static cpFloat
68 cpfmin(cpFloat a, cpFloat b)
69 {
70 return (a < b) ? a : b;
71 }
72
73 static cpFloat
74 cpfabs(cpFloat n)
75 {
76 return (n < 0) ? -n : n;
77 }
78
79 static cpFloat
80 cpfclamp(cpFloat f, cpFloat min, cpFloat max)
81 {
82 return cpfmin(cpfmax(f, min), max);
83 }
84
85 static cpFloat
86 cpflerp(cpFloat f1, cpFloat f2, cpFloat t)
87 {
88 return f1*(1.0f - t) + f2*t;
89 }
90
91 static cpFloat
92 cpflerpconst(cpFloat f1, cpFloat f2, cpFloat d)
93 {
94 return f1 + cpfclamp(f2 - f1, -d, d);
95 }
96
97 //#if TARGET_OS_IPHONE
98 // // CGPoints are structurally the same, and allow
99 // // easy interoperability with other iPhone libraries
100 // #import <CoreGraphics/CGGeometry.h>
101 // typedef CGPoint cpVect;
102 //#else
103 struct cpVect{cpFloat x = 0; cpFloat y=0;}
104 //#endif
105
106 alias uint cpHashValue;
107
108 // Oh C, how we love to define our own boolean types to get compiler compatibility
109 //#ifdef CP_BOOL_TYPE
110 // typedef CP_BOOL_TYPE cpBool;
111 //#else
112 alias bool cpBool;
113 //#endif
114
115 //#ifndef cpTrue
116 enum cpTrue = true;
117 //#endif
118
119 //#ifndef cpFalse
120 enum cpFalse = false;
121 //#endif
122
123 //#ifdef CP_DATA_POINTER_TYPE
124 // typedef CP_DATA_POINTER_TYPE cpDataPointer;
125 //#else
126 alias void * cpDataPointer;
127 //#endif
128
129 //#ifdef CP_COLLISION_TYPE_TYPE
130 // typedef CP_COLLISION_TYPE_TYPE cpCollisionType;
131 //#else
132 alias uint cpCollisionType;
133 //#endif
134
135 //#ifdef CP_GROUP_TYPE
136 // typedef CP_GROUP_TYPE cpGroup;
137 //#else
138 alias uint cpGroup;
139 //#endif
140
141 //#ifdef CP_LAYERS_TYPE
142 // typedef CP_GROUP_TYPE cpLayers;
143 //#else
144 alias uint cpLayers;
145 //#endif
146
147 //#ifdef CP_TIMESTAMP_TYPE
148 // typedef CP_TIMESTAMP_TYPE cpTimestamp;
149 //#else
150 alias uint cpTimestamp;
151 //#endif
152
153 //#ifndef CP_NO_GROUP
154 enum CP_NO_GROUP = 0;
155 //#endif
156
157 //#ifndef CP_ALL_LAYERS
158 enum CP_ALL_LAYERS = ~0;
159 //#endif