1 module rbody;
2 
3 import dlib.math.vector;
4 import dlib.math.matrix;
5 import dmech.rigidbody;
6 
7 extern(C):
8 
9 export void dmBodyGetPosition(void* pBody, float* px, float* py, float* pz)
10 {
11     RigidBody rb = cast(RigidBody)pBody;        
12     if (rb)
13     {
14         *px = rb.position.x;
15         *py = rb.position.y;
16         *pz = rb.position.z;
17     }
18 }
19 
20 export void dmBodyGetOrientation(void* pBody, float* x, float* y, float* z, float* w)
21 {
22     RigidBody rb = cast(RigidBody)pBody;        
23     if (rb)
24     {
25         *x = rb.orientation.x;
26         *y = rb.orientation.y;
27         *z = rb.orientation.z;
28         *w = rb.orientation.w;
29     }
30 }
31 
32 export void dmBodyGetMatrix(void* pBody, float* m4x4)
33 {
34     RigidBody rb = cast(RigidBody)pBody;        
35     if (rb)
36     {
37         Matrix4x4f m = rb.transformation;
38         for(uint i = 0; i < 16; i++)
39             m4x4[i] = m.arrayof[i];
40     }
41 }
42 
43 export void dmBodyGetVelocity(void* pBody, float* vx, float* vy, float* vz)
44 {
45     RigidBody rb = cast(RigidBody)pBody;        
46     if (rb)
47     {
48         *vx = rb.linearVelocity.x;
49         *vy = rb.linearVelocity.y;
50         *vz = rb.linearVelocity.z;
51     }
52 }
53 
54 export void dmBodyGetAngularVelocity(void* pBody, float* ax, float* ay, float* az)
55 {
56     RigidBody rb = cast(RigidBody)pBody;        
57     if (rb)
58     {
59         *ax = rb.angularVelocity.x;
60         *ay = rb.angularVelocity.y;
61         *az = rb.angularVelocity.z;
62     }
63 }
64 
65 export float dmBodyGetMass(void* pBody)
66 {
67     RigidBody rb = cast(RigidBody)pBody;        
68     if (rb)
69     {
70         return rb.mass;
71     }
72     else
73         return -1.0f;
74 }
75 
76 export void dmBodyGetInertiaTensor(void* pBody, float* inertia)
77 {
78     RigidBody rb = cast(RigidBody)pBody;        
79     if (rb)
80     {
81         for(uint i = 0; i < 9; i++)
82             inertia[i] = rb.inertiaTensor.arrayof[i];
83     }
84 }
85 
86 export void dmBodyGetInvInertiaTensor(void* pBody, float* inertia)
87 {
88     RigidBody rb = cast(RigidBody)pBody;        
89     if (rb)
90     {
91         for(uint i = 0; i < 9; i++)
92             inertia[i] = rb.invInertiaTensor.arrayof[i];
93     }
94 }
95 
96 export void dmBodySetActive(void* pBody, int active)
97 {
98     RigidBody rb = cast(RigidBody)pBody;        
99     if (rb)
100     {
101         rb.active = cast(bool)active;
102     }
103 }
104 
105 export int dmBodyGetActive(void* pBody)
106 {
107     RigidBody rb = cast(RigidBody)pBody;        
108     if (rb)
109         return rb.active;
110     else
111         return 0;
112 }
113 
114 export int dmBodyGetNumCollisionShapes(void* pBody)
115 {
116     RigidBody rb = cast(RigidBody)pBody;        
117     if (rb)
118         return rb.shapes.length;
119     else
120         return 0;
121 }
122 
123 export void* dmBodyGetCollisionShape(void* pBody, uint index)
124 {
125     RigidBody rb = cast(RigidBody)pBody;        
126     if (rb)
127     {
128         return cast(void*)rb.shapes[index];
129     }
130     else
131         return null;
132 }
133 
134 export void dmBodySetBounce(void* pBody, float bounce)
135 {
136     RigidBody rb = cast(RigidBody)pBody;        
137     if (rb)
138         rb.bounce = bounce;
139 }
140 
141 export float dmBodyGetBounce(void* pBody)
142 {
143     RigidBody rb = cast(RigidBody)pBody;        
144     if (rb)
145         return rb.bounce;
146     else
147         return 0.0f;
148 }
149 
150 export void dmBodySetFriction(void* pBody, float friction)
151 {
152     RigidBody rb = cast(RigidBody)pBody;        
153     if (rb)
154         rb.friction = friction;
155 }
156 
157 export float dmBodyGetFriction(void* pBody)
158 {
159     RigidBody rb = cast(RigidBody)pBody;        
160     if (rb)
161         return rb.friction;
162     else
163         return 0.0f;
164 }
165 
166 // TODO:
167 /*
168     - dmBodySetUseGravity
169     - dmBodySetEnableRotation
170     - dmBodySetDamping
171     - dmBodySetStopThreshold
172     - dmBodySetUseOwnGravity
173     - dmBodySetGravity
174     - dmBodyAddCollisionCallback
175     - dmBodySetRaycastable
176     - dmBodySetUseFriction
177     - dmBodySetMaxSpeed
178 
179     - dmBodyGetCenterOfMass
180     - dmBodyRecalcMass
181 
182     - dmBodyApplyForce
183     - dmBodyApplyTorque
184     - dmBodyApplyForceAtPoint
185     - dmBodyApplyForceAtRelPoint
186     - dmBodyGetTotalForce
187     - dmBodyGetTotalTorque
188     - dmBodyApplyImpulse
189     - dmBodyApplyImpulseAtPoint
190     - dmBodyApplyImpulseAtRelPoint
191     - dmBodySetVelocity
192     - dmBodySetAngularVelocity
193     - dmBodySetPosition
194     - dmBodySetRotation
195     - dmBodySetRotationMatrix
196 */
197