Repository navigation
Expand file tree
/
Copy pathtestbed3.c
More file actions
64 lines (56 loc) · 2.32 KB
/
Copy pathtestbed3.c
File metadata and controls
64 lines (56 loc) · 2.32 KB
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
63
64
/* Compiled against the header of the C testbed, with a stub viewer rendering 100 frames, since the
* user-guide snippets are not linked to the testbed itself. */
#include "snippets.h"
#include "../../../../../c/testbed/testbed.h"
int tbRenderFrame(Testbed *testbed, R3World **world) {
testbed->world = *world;
return testbed->step++ < 100;
}
int tbSimulating(Testbed *testbed) {
(void)testbed;
return 1;
}
void tbSetWorld(Testbed *testbed, R3World *world) {
testbed->world = world;
}
void tbCamera(Testbed *testbed, float x, float y, float z, float tx, float ty, float tz) {
(void)testbed;
(void)x, (void)y, (void)z, (void)tx, (void)ty, (void)tz;
}
// DOCUSAURUS: Scene start
void tbBouncingBall3(Testbed *testbed) {
/* The scene itself, built like in any other application. */
R3World *world = r3NewWorld();
R3ColliderDesc ground = r3CuboidColliderDesc(r3Vector(100.0, 0.1, 100.0));
r3InsertColliderWithoutParent(world, &ground);
R3RigidBodyDesc ball_body = r3DynamicRigidBodyDesc();
ball_body.position.translation = r3Vector(0.0, 10.0, 0.0);
R3ColliderDesc ball = r3BallColliderDesc(0.5);
ball.restitution = 0.7;
r3InsertCollider(r3InsertRigidBody(world, &ball_body), &ball);
/* Hand the world to the viewer, and place the camera (eye, then target). */
tbSetWorld(testbed, world);
tbCamera(testbed, 10, 10, 10, 0, 0, 0);
/* The rendering loop: it ends when the user closes the window or selects another scene. The
* viewer may replace the world, e.g., when a snapshot is restored, hence its address. */
while (tbRenderFrame(testbed, &world)) {
if (tbSimulating(testbed)) {
r3Step(world, NULL, NULL);
}
}
r3FreeWorld(world);
}
// DOCUSAURUS: Scene stop
int main(void) {
snippets_init();
static Testbed testbed;
// DOCUSAURUS: Registry start
/* An entry of the `tbExamples` array: identifier, group, name, source, scene function, and the
* reason why it is unavailable (NULL if it is available). */
TbExample entry = {"bouncing_ball3", "Demos", "Bouncing ball", "examples3d/bouncing_ball3.c",
tbBouncingBall3, NULL};
// DOCUSAURUS: Registry stop
entry.run(&testbed);
printf("Ran %llu frames of \"%s\".\n", (unsigned long long)testbed.step, entry.name);
return EXIT_SUCCESS;
}