@dayme/bunraylib 0.1.0 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +60 -11
- package/package.json +11 -3
- package/src/Raylib.ts +58 -3678
- package/src/c/common.h +0 -2
- package/src/constants.ts +2 -2
- package/src/index.ts +6 -6
- package/src/main.c +0 -1
- package/src/main.d.ts +1 -1
- package/src/modules/audio/AudioModule.ts +197 -0
- package/src/modules/audio/symbols.ts +70 -0
- package/src/{c/audio.c → modules/audio/wrapper.c} +40 -80
- package/src/modules/camera/CameraModule.ts +239 -0
- package/src/modules/camera/symbols.ts +49 -0
- package/src/modules/camera/wrapper.c +141 -0
- package/src/modules/collision/CollisionModule.ts +363 -0
- package/src/modules/collision/symbols.ts +149 -0
- package/src/modules/collision/wrapper.c +176 -0
- package/src/modules/color/ColorModule.ts +65 -0
- package/src/modules/color/symbols.ts +26 -0
- package/src/modules/color/wrapper.c +16 -0
- package/src/modules/draw3d/Draw3DModule.ts +441 -0
- package/src/modules/draw3d/symbols.ts +199 -0
- package/src/modules/draw3d/wrapper.c +202 -0
- package/src/modules/font/FontModule.ts +250 -0
- package/src/modules/font/symbols.ts +46 -0
- package/src/{c/font.c → modules/font/wrapper.c} +50 -70
- package/src/modules/image/ImageModule.ts +451 -0
- package/src/{symbols/image.ts → modules/image/symbols.ts} +15 -12
- package/src/{c/image.c → modules/image/wrapper.c} +23 -45
- package/src/modules/input/InputModule.ts +160 -0
- package/src/modules/input/symbols.ts +54 -0
- package/src/modules/input/wrapper.c +31 -0
- package/src/modules/model/ModelModule.ts +228 -0
- package/src/{symbols/model.ts → modules/model/symbols.ts} +17 -14
- package/src/{c/model.c → modules/model/wrapper.c} +30 -30
- package/src/modules/shader/ShaderModule.ts +78 -0
- package/src/{symbols/shader.ts → modules/shader/symbols.ts} +3 -1
- package/src/{c/shader.c → modules/shader/wrapper.c} +11 -1
- package/src/modules/shapes/ShapesModule.ts +687 -0
- package/src/modules/shapes/symbols.ts +161 -0
- package/src/modules/shapes/wrapper.c +183 -0
- package/src/modules/texture/TextureModule.ts +190 -0
- package/src/{symbols/texture.ts → modules/texture/symbols.ts} +15 -9
- package/src/{c/texture.c → modules/texture/wrapper.c} +7 -22
- package/src/modules/window/WindowModule.ts +248 -0
- package/src/modules/window/symbols.ts +85 -0
- package/src/modules/window/wrapper.c +39 -0
- package/src/symbols.ts +87 -47
- package/src/utils.ts +63 -15
- package/src/c/camera.c +0 -161
- package/src/c/collision.c +0 -176
- package/src/c/color.c +0 -100
- package/src/c/draw3d.c +0 -222
- package/src/c/filesystem.c +0 -36
- package/src/c/input.c +0 -85
- package/src/c/shapes.c +0 -283
- package/src/c/window.c +0 -150
- package/src/symbols/audio.ts +0 -64
- package/src/symbols/camera.ts +0 -46
- package/src/symbols/collision.ts +0 -116
- package/src/symbols/color.ts +0 -22
- package/src/symbols/draw3d.ts +0 -137
- package/src/symbols/filesystem.ts +0 -30
- package/src/symbols/font.ts +0 -40
- package/src/symbols/input.ts +0 -51
- package/src/symbols/shapes.ts +0 -92
- package/src/symbols/window.ts +0 -83
|
@@ -0,0 +1,363 @@
|
|
|
1
|
+
import { getSymbols } from '../../symbols';
|
|
2
|
+
import { bufs as b, f, i, validatePoints } from '../../utils';
|
|
3
|
+
import type { Vec2, Vec3, Rectangle, Ray, BoundingBox, Mesh, RayCollision } from '../../types';
|
|
4
|
+
|
|
5
|
+
const r = () => getSymbols();
|
|
6
|
+
|
|
7
|
+
export class CollisionModule {
|
|
8
|
+
/** Check collision between two rectangles */
|
|
9
|
+
static checkCollisionRecs(rec1: Rectangle, rec2: Rectangle): boolean {
|
|
10
|
+
return r().symbols.CheckCollisionRecsW(
|
|
11
|
+
f(rec1.x),
|
|
12
|
+
f(rec1.y),
|
|
13
|
+
f(rec1.width),
|
|
14
|
+
f(rec1.height),
|
|
15
|
+
f(rec2.x),
|
|
16
|
+
f(rec2.y),
|
|
17
|
+
f(rec2.width),
|
|
18
|
+
f(rec2.height),
|
|
19
|
+
);
|
|
20
|
+
}
|
|
21
|
+
/** Check collision between two circles */
|
|
22
|
+
static checkCollisionCircles(
|
|
23
|
+
center1: Vec2,
|
|
24
|
+
radius1: number,
|
|
25
|
+
center2: Vec2,
|
|
26
|
+
radius2: number,
|
|
27
|
+
): boolean {
|
|
28
|
+
return r().symbols.CheckCollisionCirclesW(
|
|
29
|
+
f(center1.x),
|
|
30
|
+
f(center1.y),
|
|
31
|
+
f(radius1),
|
|
32
|
+
f(center2.x),
|
|
33
|
+
f(center2.y),
|
|
34
|
+
f(radius2),
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
/** Check collision between circle and rectangle */
|
|
38
|
+
static checkCollisionCircleRec(center: Vec2, radius: number, rec: Rectangle): boolean {
|
|
39
|
+
return r().symbols.CheckCollisionCircleRecW(
|
|
40
|
+
f(center.x),
|
|
41
|
+
f(center.y),
|
|
42
|
+
f(radius),
|
|
43
|
+
f(rec.x),
|
|
44
|
+
f(rec.y),
|
|
45
|
+
f(rec.width),
|
|
46
|
+
f(rec.height),
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
/** Check if circle collides with a line created between two points [p1] and [p2] */
|
|
50
|
+
static checkCollisionCircleLine(center: Vec2, radius: number, p1: Vec2, p2: Vec2): boolean {
|
|
51
|
+
return r().symbols.CheckCollisionCircleLineW(
|
|
52
|
+
f(center.x),
|
|
53
|
+
f(center.y),
|
|
54
|
+
f(radius),
|
|
55
|
+
f(p1.x),
|
|
56
|
+
f(p1.y),
|
|
57
|
+
f(p2.x),
|
|
58
|
+
f(p2.y),
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
/** Check if point is inside rectangle */
|
|
62
|
+
static checkCollisionPointRec(point: Vec2, rec: Rectangle): boolean {
|
|
63
|
+
return r().symbols.CheckCollisionPointRecW(
|
|
64
|
+
f(point.x),
|
|
65
|
+
f(point.y),
|
|
66
|
+
f(rec.x),
|
|
67
|
+
f(rec.y),
|
|
68
|
+
f(rec.width),
|
|
69
|
+
f(rec.height),
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
/** Check if point is inside circle */
|
|
73
|
+
static checkCollisionPointCircle(point: Vec2, center: Vec2, radius: number): boolean {
|
|
74
|
+
return r().symbols.CheckCollisionPointCircleW(
|
|
75
|
+
f(point.x),
|
|
76
|
+
f(point.y),
|
|
77
|
+
f(center.x),
|
|
78
|
+
f(center.y),
|
|
79
|
+
f(radius),
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
/** Check if point is inside a triangle */
|
|
83
|
+
static checkCollisionPointTriangle(point: Vec2, p1: Vec2, p2: Vec2, p3: Vec2): boolean {
|
|
84
|
+
return r().symbols.CheckCollisionPointTriangleW(
|
|
85
|
+
f(point.x),
|
|
86
|
+
f(point.y),
|
|
87
|
+
f(p1.x),
|
|
88
|
+
f(p1.y),
|
|
89
|
+
f(p2.x),
|
|
90
|
+
f(p2.y),
|
|
91
|
+
f(p3.x),
|
|
92
|
+
f(p3.y),
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
/** Check if point belongs to line created between two points [p1] and [p2] with defined margin [threshold] */
|
|
96
|
+
static checkCollisionPointLine(point: Vec2, p1: Vec2, p2: Vec2, threshold: number): boolean {
|
|
97
|
+
return r().symbols.CheckCollisionPointLineW(
|
|
98
|
+
f(point.x),
|
|
99
|
+
f(point.y),
|
|
100
|
+
f(p1.x),
|
|
101
|
+
f(p1.y),
|
|
102
|
+
f(p2.x),
|
|
103
|
+
f(p2.y),
|
|
104
|
+
i(threshold),
|
|
105
|
+
);
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Check if point is within a polygon described by array of vertices.
|
|
109
|
+
* Points are packed as [x0,y0, x1,y1, ...] in Float32Array.
|
|
110
|
+
*/
|
|
111
|
+
static checkCollisionPointPoly(point: Vec2, points: Float32Array): boolean {
|
|
112
|
+
validatePoints('checkCollisionPointPoly', points, 2, 3);
|
|
113
|
+
return r().symbols.CheckCollisionPointPolyW(
|
|
114
|
+
f(point.x),
|
|
115
|
+
f(point.y),
|
|
116
|
+
points,
|
|
117
|
+
i(points.length / 2),
|
|
118
|
+
);
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Check collision between two lines defined by two points each.
|
|
122
|
+
* @returns Object with `collides` boolean and `collisionPoint` Vec2 (valid only if collides is true)
|
|
123
|
+
*/
|
|
124
|
+
static checkCollisionLines(
|
|
125
|
+
startPos1: Vec2,
|
|
126
|
+
endPos1: Vec2,
|
|
127
|
+
startPos2: Vec2,
|
|
128
|
+
endPos2: Vec2,
|
|
129
|
+
): { collides: boolean; collisionPoint: Vec2 } {
|
|
130
|
+
const collides = r().symbols.CheckCollisionLinesW(
|
|
131
|
+
b._colPtBuf,
|
|
132
|
+
f(startPos1.x),
|
|
133
|
+
f(startPos1.y),
|
|
134
|
+
f(endPos1.x),
|
|
135
|
+
f(endPos1.y),
|
|
136
|
+
f(startPos2.x),
|
|
137
|
+
f(startPos2.y),
|
|
138
|
+
f(endPos2.x),
|
|
139
|
+
f(endPos2.y),
|
|
140
|
+
);
|
|
141
|
+
return { collides, collisionPoint: { x: b._colPtBuf[0]!, y: b._colPtBuf[1]! } };
|
|
142
|
+
}
|
|
143
|
+
/** Get collision rectangle for two rectangles collision. Returns null if no overlap */
|
|
144
|
+
static getCollisionRec(rec1: Rectangle, rec2: Rectangle): Rectangle {
|
|
145
|
+
r().symbols.GetCollisionRecW(
|
|
146
|
+
b._recBuf,
|
|
147
|
+
f(rec1.x),
|
|
148
|
+
f(rec1.y),
|
|
149
|
+
f(rec1.width),
|
|
150
|
+
f(rec1.height),
|
|
151
|
+
f(rec2.x),
|
|
152
|
+
f(rec2.y),
|
|
153
|
+
f(rec2.width),
|
|
154
|
+
f(rec2.height),
|
|
155
|
+
);
|
|
156
|
+
return {
|
|
157
|
+
x: b._recBuf[0]!,
|
|
158
|
+
y: b._recBuf[1]!,
|
|
159
|
+
width: b._recBuf[2]!,
|
|
160
|
+
height: b._recBuf[3]!,
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
static checkCollisionSpheres(
|
|
164
|
+
center1: Vec3,
|
|
165
|
+
radius1: number,
|
|
166
|
+
center2: Vec3,
|
|
167
|
+
radius2: number,
|
|
168
|
+
): boolean {
|
|
169
|
+
return r().symbols.CheckCollisionSpheresW(
|
|
170
|
+
f(center1.x),
|
|
171
|
+
f(center1.y),
|
|
172
|
+
f(center1.z),
|
|
173
|
+
f(radius1),
|
|
174
|
+
f(center2.x),
|
|
175
|
+
f(center2.y),
|
|
176
|
+
f(center2.z),
|
|
177
|
+
f(radius2),
|
|
178
|
+
);
|
|
179
|
+
}
|
|
180
|
+
static checkCollisionBoxes(box1: BoundingBox, box2: BoundingBox): boolean {
|
|
181
|
+
return r().symbols.CheckCollisionBoxesW(
|
|
182
|
+
f(box1.min.x),
|
|
183
|
+
f(box1.min.y),
|
|
184
|
+
f(box1.min.z),
|
|
185
|
+
f(box1.max.x),
|
|
186
|
+
f(box1.max.y),
|
|
187
|
+
f(box1.max.z),
|
|
188
|
+
f(box2.min.x),
|
|
189
|
+
f(box2.min.y),
|
|
190
|
+
f(box2.min.z),
|
|
191
|
+
f(box2.max.x),
|
|
192
|
+
f(box2.max.y),
|
|
193
|
+
f(box2.max.z),
|
|
194
|
+
);
|
|
195
|
+
}
|
|
196
|
+
static checkCollisionBoxSphere(box: BoundingBox, center: Vec3, radius: number): boolean {
|
|
197
|
+
return r().symbols.CheckCollisionBoxSphereW(
|
|
198
|
+
f(box.min.x),
|
|
199
|
+
f(box.min.y),
|
|
200
|
+
f(box.min.z),
|
|
201
|
+
f(box.max.x),
|
|
202
|
+
f(box.max.y),
|
|
203
|
+
f(box.max.z),
|
|
204
|
+
f(center.x),
|
|
205
|
+
f(center.y),
|
|
206
|
+
f(center.z),
|
|
207
|
+
f(radius),
|
|
208
|
+
);
|
|
209
|
+
}
|
|
210
|
+
static getRayCollisionSphere(ray: Ray, center: Vec3, radius: number): RayCollision {
|
|
211
|
+
r().symbols.GetRayCollisionSphereW(
|
|
212
|
+
b._rcHit,
|
|
213
|
+
b._rcDist,
|
|
214
|
+
b._rcPt,
|
|
215
|
+
b._rcNorm,
|
|
216
|
+
f(ray.position.x),
|
|
217
|
+
f(ray.position.y),
|
|
218
|
+
f(ray.position.z),
|
|
219
|
+
f(ray.direction.x),
|
|
220
|
+
f(ray.direction.y),
|
|
221
|
+
f(ray.direction.z),
|
|
222
|
+
f(center.x),
|
|
223
|
+
f(center.y),
|
|
224
|
+
f(center.z),
|
|
225
|
+
f(radius),
|
|
226
|
+
);
|
|
227
|
+
return {
|
|
228
|
+
hit: b._rcHit[0]! !== 0,
|
|
229
|
+
distance: b._rcDist[0]!,
|
|
230
|
+
point: { x: b._rcPt[0]!, y: b._rcPt[1]!, z: b._rcPt[2]! },
|
|
231
|
+
normal: { x: b._rcNorm[0]!, y: b._rcNorm[1]!, z: b._rcNorm[2]! },
|
|
232
|
+
};
|
|
233
|
+
}
|
|
234
|
+
static getRayCollisionBox(ray: Ray, box: BoundingBox): RayCollision {
|
|
235
|
+
r().symbols.GetRayCollisionBoxW(
|
|
236
|
+
b._rcHit,
|
|
237
|
+
b._rcDist,
|
|
238
|
+
b._rcPt,
|
|
239
|
+
b._rcNorm,
|
|
240
|
+
f(ray.position.x),
|
|
241
|
+
f(ray.position.y),
|
|
242
|
+
f(ray.position.z),
|
|
243
|
+
f(ray.direction.x),
|
|
244
|
+
f(ray.direction.y),
|
|
245
|
+
f(ray.direction.z),
|
|
246
|
+
f(box.min.x),
|
|
247
|
+
f(box.min.y),
|
|
248
|
+
f(box.min.z),
|
|
249
|
+
f(box.max.x),
|
|
250
|
+
f(box.max.y),
|
|
251
|
+
f(box.max.z),
|
|
252
|
+
);
|
|
253
|
+
return {
|
|
254
|
+
hit: b._rcHit[0]! !== 0,
|
|
255
|
+
distance: b._rcDist[0]!,
|
|
256
|
+
point: { x: b._rcPt[0]!, y: b._rcPt[1]!, z: b._rcPt[2]! },
|
|
257
|
+
normal: { x: b._rcNorm[0]!, y: b._rcNorm[1]!, z: b._rcNorm[2]! },
|
|
258
|
+
};
|
|
259
|
+
}
|
|
260
|
+
static getRayCollisionTriangle(ray: Ray, p1: Vec3, p2: Vec3, p3: Vec3): RayCollision {
|
|
261
|
+
r().symbols.GetRayCollisionTriangleW(
|
|
262
|
+
b._rcHit,
|
|
263
|
+
b._rcDist,
|
|
264
|
+
b._rcPt,
|
|
265
|
+
b._rcNorm,
|
|
266
|
+
f(ray.position.x),
|
|
267
|
+
f(ray.position.y),
|
|
268
|
+
f(ray.position.z),
|
|
269
|
+
f(ray.direction.x),
|
|
270
|
+
f(ray.direction.y),
|
|
271
|
+
f(ray.direction.z),
|
|
272
|
+
f(p1.x),
|
|
273
|
+
f(p1.y),
|
|
274
|
+
f(p1.z),
|
|
275
|
+
f(p2.x),
|
|
276
|
+
f(p2.y),
|
|
277
|
+
f(p2.z),
|
|
278
|
+
f(p3.x),
|
|
279
|
+
f(p3.y),
|
|
280
|
+
f(p3.z),
|
|
281
|
+
);
|
|
282
|
+
return {
|
|
283
|
+
hit: b._rcHit[0]! !== 0,
|
|
284
|
+
distance: b._rcDist[0]!,
|
|
285
|
+
point: { x: b._rcPt[0]!, y: b._rcPt[1]!, z: b._rcPt[2]! },
|
|
286
|
+
normal: { x: b._rcNorm[0]!, y: b._rcNorm[1]!, z: b._rcNorm[2]! },
|
|
287
|
+
};
|
|
288
|
+
}
|
|
289
|
+
static getRayCollisionQuad(ray: Ray, p1: Vec3, p2: Vec3, p3: Vec3, p4: Vec3): RayCollision {
|
|
290
|
+
r().symbols.GetRayCollisionQuadW(
|
|
291
|
+
b._rcHit,
|
|
292
|
+
b._rcDist,
|
|
293
|
+
b._rcPt,
|
|
294
|
+
b._rcNorm,
|
|
295
|
+
f(ray.position.x),
|
|
296
|
+
f(ray.position.y),
|
|
297
|
+
f(ray.position.z),
|
|
298
|
+
f(ray.direction.x),
|
|
299
|
+
f(ray.direction.y),
|
|
300
|
+
f(ray.direction.z),
|
|
301
|
+
f(p1.x),
|
|
302
|
+
f(p1.y),
|
|
303
|
+
f(p1.z),
|
|
304
|
+
f(p2.x),
|
|
305
|
+
f(p2.y),
|
|
306
|
+
f(p2.z),
|
|
307
|
+
f(p3.x),
|
|
308
|
+
f(p3.y),
|
|
309
|
+
f(p3.z),
|
|
310
|
+
f(p4.x),
|
|
311
|
+
f(p4.y),
|
|
312
|
+
f(p4.z),
|
|
313
|
+
);
|
|
314
|
+
return {
|
|
315
|
+
hit: b._rcHit[0]! !== 0,
|
|
316
|
+
distance: b._rcDist[0]!,
|
|
317
|
+
point: { x: b._rcPt[0]!, y: b._rcPt[1]!, z: b._rcPt[2]! },
|
|
318
|
+
normal: { x: b._rcNorm[0]!, y: b._rcNorm[1]!, z: b._rcNorm[2]! },
|
|
319
|
+
};
|
|
320
|
+
}
|
|
321
|
+
static getRayCollisionMesh(
|
|
322
|
+
ray: Ray,
|
|
323
|
+
mesh: Mesh,
|
|
324
|
+
transform: { m: Float32Array } | Float32Array,
|
|
325
|
+
): RayCollision {
|
|
326
|
+
const m = transform instanceof Float32Array ? transform : transform.m;
|
|
327
|
+
r().symbols.GetRayCollisionMeshW(
|
|
328
|
+
b._rcHit,
|
|
329
|
+
b._rcDist,
|
|
330
|
+
b._rcPt,
|
|
331
|
+
b._rcNorm,
|
|
332
|
+
f(ray.position.x),
|
|
333
|
+
f(ray.position.y),
|
|
334
|
+
f(ray.position.z),
|
|
335
|
+
f(ray.direction.x),
|
|
336
|
+
f(ray.direction.y),
|
|
337
|
+
f(ray.direction.z),
|
|
338
|
+
i(mesh),
|
|
339
|
+
f(m[0]!),
|
|
340
|
+
f(m[4]!),
|
|
341
|
+
f(m[8]!),
|
|
342
|
+
f(m[12]!),
|
|
343
|
+
f(m[1]!),
|
|
344
|
+
f(m[5]!),
|
|
345
|
+
f(m[9]!),
|
|
346
|
+
f(m[13]!),
|
|
347
|
+
f(m[2]!),
|
|
348
|
+
f(m[6]!),
|
|
349
|
+
f(m[10]!),
|
|
350
|
+
f(m[14]!),
|
|
351
|
+
f(m[3]!),
|
|
352
|
+
f(m[7]!),
|
|
353
|
+
f(m[11]!),
|
|
354
|
+
f(m[15]!),
|
|
355
|
+
);
|
|
356
|
+
return {
|
|
357
|
+
hit: b._rcHit[0]! !== 0,
|
|
358
|
+
distance: b._rcDist[0]!,
|
|
359
|
+
point: { x: b._rcPt[0]!, y: b._rcPt[1]!, z: b._rcPt[2]! },
|
|
360
|
+
normal: { x: b._rcNorm[0]!, y: b._rcNorm[1]!, z: b._rcNorm[2]! },
|
|
361
|
+
};
|
|
362
|
+
}
|
|
363
|
+
}
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import { FFIType } from 'bun:ffi';
|
|
2
|
+
const { i32, bool, ptr, f32 } = FFIType;
|
|
3
|
+
|
|
4
|
+
export const collisionSymbols = {
|
|
5
|
+
CheckCollisionRecsW: {
|
|
6
|
+
args: [f32, f32, f32, f32, f32, f32, f32, f32],
|
|
7
|
+
returns: bool,
|
|
8
|
+
},
|
|
9
|
+
CheckCollisionCirclesW: {
|
|
10
|
+
args: [f32, f32, f32, f32, f32, f32],
|
|
11
|
+
returns: bool,
|
|
12
|
+
},
|
|
13
|
+
CheckCollisionCircleRecW: {
|
|
14
|
+
args: [f32, f32, f32, f32, f32, f32, f32],
|
|
15
|
+
returns: bool,
|
|
16
|
+
},
|
|
17
|
+
CheckCollisionCircleLineW: {
|
|
18
|
+
args: [f32, f32, f32, f32, f32, f32, f32],
|
|
19
|
+
returns: bool,
|
|
20
|
+
},
|
|
21
|
+
CheckCollisionPointRecW: {
|
|
22
|
+
args: [f32, f32, f32, f32, f32, f32],
|
|
23
|
+
returns: bool,
|
|
24
|
+
},
|
|
25
|
+
CheckCollisionPointCircleW: {
|
|
26
|
+
args: [f32, f32, f32, f32, f32],
|
|
27
|
+
returns: bool,
|
|
28
|
+
},
|
|
29
|
+
CheckCollisionPointTriangleW: {
|
|
30
|
+
args: [f32, f32, f32, f32, f32, f32, f32, f32],
|
|
31
|
+
returns: bool,
|
|
32
|
+
},
|
|
33
|
+
CheckCollisionPointLineW: {
|
|
34
|
+
args: [f32, f32, f32, f32, f32, f32, i32],
|
|
35
|
+
returns: bool,
|
|
36
|
+
},
|
|
37
|
+
CheckCollisionPointPolyW: { args: [f32, f32, ptr, i32], returns: bool },
|
|
38
|
+
CheckCollisionLinesW: {
|
|
39
|
+
args: [ptr, f32, f32, f32, f32, f32, f32, f32, f32],
|
|
40
|
+
returns: bool,
|
|
41
|
+
},
|
|
42
|
+
GetCollisionRecW: {
|
|
43
|
+
args: [ptr, f32, f32, f32, f32, f32, f32, f32, f32],
|
|
44
|
+
returns: FFIType.void,
|
|
45
|
+
},
|
|
46
|
+
CheckCollisionSpheresW: {
|
|
47
|
+
args: [f32, f32, f32, f32, f32, f32, f32, f32],
|
|
48
|
+
returns: bool,
|
|
49
|
+
},
|
|
50
|
+
CheckCollisionBoxesW: {
|
|
51
|
+
args: [f32, f32, f32, f32, f32, f32, f32, f32, f32, f32, f32, f32],
|
|
52
|
+
returns: bool,
|
|
53
|
+
},
|
|
54
|
+
CheckCollisionBoxSphereW: {
|
|
55
|
+
args: [f32, f32, f32, f32, f32, f32, f32, f32, f32, f32],
|
|
56
|
+
returns: bool,
|
|
57
|
+
},
|
|
58
|
+
GetRayCollisionSphereW: {
|
|
59
|
+
args: [ptr, ptr, ptr, ptr, f32, f32, f32, f32, f32, f32, f32, f32, f32, f32],
|
|
60
|
+
returns: FFIType.void,
|
|
61
|
+
},
|
|
62
|
+
GetRayCollisionBoxW: {
|
|
63
|
+
args: [ptr, ptr, ptr, ptr, f32, f32, f32, f32, f32, f32, f32, f32, f32, f32, f32, f32],
|
|
64
|
+
returns: FFIType.void,
|
|
65
|
+
},
|
|
66
|
+
GetRayCollisionTriangleW: {
|
|
67
|
+
args: [
|
|
68
|
+
ptr,
|
|
69
|
+
ptr,
|
|
70
|
+
ptr,
|
|
71
|
+
ptr,
|
|
72
|
+
f32,
|
|
73
|
+
f32,
|
|
74
|
+
f32,
|
|
75
|
+
f32,
|
|
76
|
+
f32,
|
|
77
|
+
f32,
|
|
78
|
+
f32,
|
|
79
|
+
f32,
|
|
80
|
+
f32,
|
|
81
|
+
f32,
|
|
82
|
+
f32,
|
|
83
|
+
f32,
|
|
84
|
+
f32,
|
|
85
|
+
f32,
|
|
86
|
+
f32,
|
|
87
|
+
],
|
|
88
|
+
returns: FFIType.void,
|
|
89
|
+
},
|
|
90
|
+
GetRayCollisionQuadW: {
|
|
91
|
+
args: [
|
|
92
|
+
ptr,
|
|
93
|
+
ptr,
|
|
94
|
+
ptr,
|
|
95
|
+
ptr,
|
|
96
|
+
f32,
|
|
97
|
+
f32,
|
|
98
|
+
f32,
|
|
99
|
+
f32,
|
|
100
|
+
f32,
|
|
101
|
+
f32,
|
|
102
|
+
f32,
|
|
103
|
+
f32,
|
|
104
|
+
f32,
|
|
105
|
+
f32,
|
|
106
|
+
f32,
|
|
107
|
+
f32,
|
|
108
|
+
f32,
|
|
109
|
+
f32,
|
|
110
|
+
f32,
|
|
111
|
+
f32,
|
|
112
|
+
f32,
|
|
113
|
+
f32,
|
|
114
|
+
],
|
|
115
|
+
returns: FFIType.void,
|
|
116
|
+
},
|
|
117
|
+
GetRayCollisionMeshW: {
|
|
118
|
+
args: [
|
|
119
|
+
ptr,
|
|
120
|
+
ptr,
|
|
121
|
+
ptr,
|
|
122
|
+
ptr,
|
|
123
|
+
f32,
|
|
124
|
+
f32,
|
|
125
|
+
f32,
|
|
126
|
+
f32,
|
|
127
|
+
f32,
|
|
128
|
+
f32,
|
|
129
|
+
i32,
|
|
130
|
+
f32,
|
|
131
|
+
f32,
|
|
132
|
+
f32,
|
|
133
|
+
f32,
|
|
134
|
+
f32,
|
|
135
|
+
f32,
|
|
136
|
+
f32,
|
|
137
|
+
f32,
|
|
138
|
+
f32,
|
|
139
|
+
f32,
|
|
140
|
+
f32,
|
|
141
|
+
f32,
|
|
142
|
+
f32,
|
|
143
|
+
f32,
|
|
144
|
+
f32,
|
|
145
|
+
f32,
|
|
146
|
+
],
|
|
147
|
+
returns: FFIType.void,
|
|
148
|
+
},
|
|
149
|
+
} as const;
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
#include "../../c/common.h"
|
|
2
|
+
|
|
3
|
+
bool CheckCollisionRecsW(float x1, float y1, float w1, float h1, float x2, float y2, float w2, float h2) {
|
|
4
|
+
Rectangle r1 = {x1, y1, w1, h1};
|
|
5
|
+
Rectangle r2 = {x2, y2, w2, h2};
|
|
6
|
+
return CheckCollisionRecs(r1, r2);
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
bool CheckCollisionCirclesW(float cx1, float cy1, float r1, float cx2, float cy2, float r2) {
|
|
10
|
+
return CheckCollisionCircles((Vector2){cx1, cy1}, r1, (Vector2){cx2, cy2}, r2);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
bool CheckCollisionCircleRecW(float cx, float cy, float radius, float rx, float ry, float rw, float rh) {
|
|
14
|
+
return CheckCollisionCircleRec((Vector2){cx, cy}, radius, (Rectangle){rx, ry, rw, rh});
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
bool CheckCollisionCircleLineW(float cx, float cy, float radius, float p1x, float p1y, float p2x, float p2y) {
|
|
18
|
+
return CheckCollisionCircleLine((Vector2){cx, cy}, radius, (Vector2){p1x, p1y}, (Vector2){p2x, p2y});
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
bool CheckCollisionPointRecW(float px, float py, float rx, float ry, float rw, float rh) {
|
|
22
|
+
return CheckCollisionPointRec((Vector2){px, py}, (Rectangle){rx, ry, rw, rh});
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
bool CheckCollisionPointCircleW(float px, float py, float cx, float cy, float radius) {
|
|
26
|
+
return CheckCollisionPointCircle((Vector2){px, py}, (Vector2){cx, cy}, radius);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
bool CheckCollisionPointTriangleW(float px, float py, float p1x, float p1y, float p2x, float p2y, float p3x, float p3y) {
|
|
30
|
+
return CheckCollisionPointTriangle((Vector2){px, py}, (Vector2){p1x, p1y}, (Vector2){p2x, p2y}, (Vector2){p3x, p3y});
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
bool CheckCollisionPointLineW(float px, float py, float p1x, float p1y, float p2x, float p2y, int threshold) {
|
|
34
|
+
return CheckCollisionPointLine((Vector2){px, py}, (Vector2){p1x, p1y}, (Vector2){p2x, p2y}, threshold);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
bool CheckCollisionPointPolyW(float px, float py, const float* points, int pointCount) {
|
|
38
|
+
return CheckCollisionPointPoly((Vector2){px, py}, (const Vector2*)points, pointCount);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
bool CheckCollisionLinesW(float* out, float s1x, float s1y, float e1x, float e1y, float s2x, float s2y, float e2x, float e2y) {
|
|
42
|
+
Vector2 cp;
|
|
43
|
+
bool result = CheckCollisionLines((Vector2){s1x, s1y}, (Vector2){e1x, e1y}, (Vector2){s2x, s2y}, (Vector2){e2x, e2y}, &cp);
|
|
44
|
+
out[0] = cp.x;
|
|
45
|
+
out[1] = cp.y;
|
|
46
|
+
return result;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
void GetCollisionRecW(float* out, float x1, float y1, float w1, float h1, float x2, float y2, float w2, float h2) {
|
|
50
|
+
Rectangle r1 = {x1, y1, w1, h1};
|
|
51
|
+
Rectangle r2 = {x2, y2, w2, h2};
|
|
52
|
+
Rectangle result = GetCollisionRec(r1, r2);
|
|
53
|
+
out[0] = result.x;
|
|
54
|
+
out[1] = result.y;
|
|
55
|
+
out[2] = result.width;
|
|
56
|
+
out[3] = result.height;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
bool CheckCollisionSpheresW(float cx1, float cy1, float cz1, float r1, float cx2, float cy2, float cz2, float r2) {
|
|
60
|
+
return CheckCollisionSpheres(
|
|
61
|
+
(Vector3){cx1, cy1, cz1}, r1,
|
|
62
|
+
(Vector3){cx2, cy2, cz2}, r2);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
bool CheckCollisionBoxesW(
|
|
66
|
+
float minX1, float minY1, float minZ1, float maxX1, float maxY1, float maxZ1,
|
|
67
|
+
float minX2, float minY2, float minZ2, float maxX2, float maxY2, float maxZ2) {
|
|
68
|
+
BoundingBox bb1 = {
|
|
69
|
+
{minX1, minY1, minZ1},
|
|
70
|
+
{maxX1, maxY1, maxZ1}
|
|
71
|
+
};
|
|
72
|
+
BoundingBox bb2 = {
|
|
73
|
+
{minX2, minY2, minZ2},
|
|
74
|
+
{maxX2, maxY2, maxZ2}
|
|
75
|
+
};
|
|
76
|
+
return CheckCollisionBoxes(bb1, bb2);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
bool CheckCollisionBoxSphereW(
|
|
80
|
+
float minX, float minY, float minZ, float maxX, float maxY, float maxZ,
|
|
81
|
+
float cx, float cy, float cz, float radius) {
|
|
82
|
+
BoundingBox bb = {
|
|
83
|
+
{minX, minY, minZ},
|
|
84
|
+
{maxX, maxY, maxZ}
|
|
85
|
+
};
|
|
86
|
+
return CheckCollisionBoxSphere(bb,
|
|
87
|
+
(Vector3){cx, cy, cz}, radius);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
void GetRayCollisionSphereW(bool* outHit, float* outDist, float* outPt, float* outNorm,
|
|
91
|
+
float rPx, float rPy, float rPz, float rDx, float rDy, float rDz,
|
|
92
|
+
float cx, float cy, float cz, float radius) {
|
|
93
|
+
Ray ray = {
|
|
94
|
+
{rPx, rPy, rPz},
|
|
95
|
+
{rDx, rDy, rDz}
|
|
96
|
+
};
|
|
97
|
+
RayCollision rc = GetRayCollisionSphere(ray,
|
|
98
|
+
(Vector3){cx, cy, cz}, radius);
|
|
99
|
+
*outHit = rc.hit;
|
|
100
|
+
outDist[0] = rc.distance;
|
|
101
|
+
outPt[0] = rc.point.x; outPt[1] = rc.point.y; outPt[2] = rc.point.z;
|
|
102
|
+
outNorm[0] = rc.normal.x; outNorm[1] = rc.normal.y; outNorm[2] = rc.normal.z;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
void GetRayCollisionBoxW(bool* outHit, float* outDist, float* outPt, float* outNorm,
|
|
106
|
+
float rPx, float rPy, float rPz, float rDx, float rDy, float rDz,
|
|
107
|
+
float minX, float minY, float minZ, float maxX, float maxY, float maxZ) {
|
|
108
|
+
Ray ray = {
|
|
109
|
+
{rPx, rPy, rPz},
|
|
110
|
+
{rDx, rDy, rDz}
|
|
111
|
+
};
|
|
112
|
+
BoundingBox bb = {
|
|
113
|
+
{minX, minY, minZ},
|
|
114
|
+
{maxX, maxY, maxZ}
|
|
115
|
+
};
|
|
116
|
+
RayCollision rc = GetRayCollisionBox(ray, bb);
|
|
117
|
+
*outHit = rc.hit;
|
|
118
|
+
outDist[0] = rc.distance;
|
|
119
|
+
outPt[0] = rc.point.x; outPt[1] = rc.point.y; outPt[2] = rc.point.z;
|
|
120
|
+
outNorm[0] = rc.normal.x; outNorm[1] = rc.normal.y; outNorm[2] = rc.normal.z;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
void GetRayCollisionTriangleW(bool* outHit, float* outDist, float* outPt, float* outNorm,
|
|
124
|
+
float rPx, float rPy, float rPz, float rDx, float rDy, float rDz,
|
|
125
|
+
float p1x, float p1y, float p1z, float p2x, float p2y, float p2z, float p3x, float p3y, float p3z) {
|
|
126
|
+
Ray ray = {
|
|
127
|
+
{rPx, rPy, rPz},
|
|
128
|
+
{rDx, rDy, rDz}
|
|
129
|
+
};
|
|
130
|
+
RayCollision rc = GetRayCollisionTriangle(ray,
|
|
131
|
+
(Vector3){p1x, p1y, p1z},
|
|
132
|
+
(Vector3){p2x, p2y, p2z},
|
|
133
|
+
(Vector3){p3x, p3y, p3z});
|
|
134
|
+
*outHit = rc.hit;
|
|
135
|
+
outDist[0] = rc.distance;
|
|
136
|
+
outPt[0] = rc.point.x; outPt[1] = rc.point.y; outPt[2] = rc.point.z;
|
|
137
|
+
outNorm[0] = rc.normal.x; outNorm[1] = rc.normal.y; outNorm[2] = rc.normal.z;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
void GetRayCollisionQuadW(bool* outHit, float* outDist, float* outPt, float* outNorm,
|
|
141
|
+
float rPx, float rPy, float rPz, float rDx, float rDy, float rDz,
|
|
142
|
+
float p1x, float p1y, float p1z, float p2x, float p2y, float p2z,
|
|
143
|
+
float p3x, float p3y, float p3z, float p4x, float p4y, float p4z) {
|
|
144
|
+
Ray ray = {
|
|
145
|
+
{rPx, rPy, rPz},
|
|
146
|
+
{rDx, rDy, rDz}
|
|
147
|
+
};
|
|
148
|
+
RayCollision rc = GetRayCollisionQuad(ray,
|
|
149
|
+
(Vector3){p1x, p1y, p1z},
|
|
150
|
+
(Vector3){p2x, p2y, p2z},
|
|
151
|
+
(Vector3){p3x, p3y, p3z},
|
|
152
|
+
(Vector3){p4x, p4y, p4z});
|
|
153
|
+
*outHit = rc.hit;
|
|
154
|
+
outDist[0] = rc.distance;
|
|
155
|
+
outPt[0] = rc.point.x; outPt[1] = rc.point.y; outPt[2] = rc.point.z;
|
|
156
|
+
outNorm[0] = rc.normal.x; outNorm[1] = rc.normal.y; outNorm[2] = rc.normal.z;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
void GetRayCollisionMeshW(bool* outHit, float* outDist, float* outPt, float* outNorm,
|
|
160
|
+
float rPx, float rPy, float rPz, float rDx, float rDy, float rDz,
|
|
161
|
+
int meshId,
|
|
162
|
+
float im0, float im4, float im8, float im12,
|
|
163
|
+
float im1, float im5, float im9, float im13,
|
|
164
|
+
float im2, float im6, float im10, float im14,
|
|
165
|
+
float im3, float im7, float im11, float im15) {
|
|
166
|
+
Ray ray = { {rPx, rPy, rPz}, {rDx, rDy, rDz} };
|
|
167
|
+
Matrix transform = {im0, im1, im2, im3, im4, im5, im6, im7, im8, im9, im10, im11, im12, im13, im14, im15};
|
|
168
|
+
if (meshId < 0 || meshId >= MAX_MESHES || !meshUsed[meshId]) {
|
|
169
|
+
*outHit = false; *outDist = 0; return;
|
|
170
|
+
}
|
|
171
|
+
RayCollision rc = GetRayCollisionMesh(ray, meshRegistry[meshId], transform);
|
|
172
|
+
*outHit = rc.hit;
|
|
173
|
+
outDist[0] = rc.distance;
|
|
174
|
+
outPt[0] = rc.point.x; outPt[1] = rc.point.y; outPt[2] = rc.point.z;
|
|
175
|
+
outNorm[0] = rc.normal.x; outNorm[1] = rc.normal.y; outNorm[2] = rc.normal.z;
|
|
176
|
+
}
|