Repository navigation
Expand file tree
/
Copy pathdebug_rollback3.c
More file actions
59 lines (51 loc) · 2 KB
/
Copy pathdebug_rollback3.c
File metadata and controls
59 lines (51 loc) · 2 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
/* Port of examples3d/debug_rollback3.rs. */
#include "testbed.h"
#include "rapier_helpers.h"
#include "rapier_math.h"
void tbDebugRollback3(Testbed *testbed) {
/* World. */
R3World *world = r3NewWorld();
R3RigidBodyHandle ballHandle = {0};
R3Vector savedLinvel = {0};
R3AngVector savedAngvel = {0};
R3Pose savedPosition = {0};
unsigned stepId = {0};
R3ColliderDesc collider = r3CuboidColliderDesc(r3Vector(20, 0.1, 0.4));
collider.friction = 0.15;
R3RigidBodyDesc groundBody = r3FixedRigidBodyDesc();
groundBody.position.translation = r3Vector(0, -0.1, 0);
groundBody.canSleep = !testbed->noSleep;
R3RigidBodyHandle groundBodyHandle = r3InsertRigidBody(world, &groundBody);
r3InsertCollider(groundBodyHandle, &collider);
R3RigidBodyDesc rigidBody = r3DynamicRigidBodyDesc();
rigidBody.position.translation = r3Vector(0, 0.2, 0);
rigidBody.linvel = r3Vector(10, 0, 0);
collider = r3BallColliderDesc(0.1);
collider.density = 100;
rigidBody.canSleep = !testbed->noSleep;
ballHandle = r3InsertRigidBody(world, &rigidBody);
r3InsertCollider(ballHandle, &collider);
/* Set up the viewer. */
tbCamera(testbed, 10, 10, 10, 0, 0, 0);
/* Set up rendering and run the simulation. */
tbSetWorld(testbed, world);
testbed->snapshotSupported = 0;
while (tbRenderFrame(testbed, &world)) {
if (tbSimulating(testbed)) {
r3Step(world, NULL, NULL);
stepId++;
if (stepId == 51) {
savedLinvel = r3RigidBody_Linvel(ballHandle);
savedAngvel = r3RigidBody_Angvel(ballHandle);
savedPosition = r3RigidBody_Position(ballHandle);
}
if (stepId == 100) {
r3RigidBody_SetLinvel(ballHandle, savedLinvel, 1);
r3RigidBody_SetAngvel(ballHandle, savedAngvel, 1);
r3RigidBody_SetPosition(ballHandle, savedPosition, 1);
stepId = 51;
}
}
}
r3FreeWorld(world);
}