forked from bepu/bepuphysics2
-
Notifications
You must be signed in to change notification settings - Fork 2
/
PositionLastTimestepper.cs
55 lines (48 loc) · 2.25 KB
/
PositionLastTimestepper.cs
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
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
using BepuUtilities;
namespace BepuPhysics
{
/// <summary>
/// Updates the simulation in the order of: sleeper -> integrate velocities and update body bounding boxes -> collision detection -> solver -> integrate body poses -> data structure optimization.
/// </summary>
public class PositionLastTimestepper : ITimestepper
{
/// <summary>
/// Fires after the sleeper completes and before bodies are integrated.
/// </summary>
public event TimestepperStageHandler Slept;
/// <summary>
/// Fires after bodies have had their velocities and bounding boxes updated, but before collision detection begins.
/// </summary>
public event TimestepperStageHandler BeforeCollisionDetection;
/// <summary>
/// Fires after all collisions have been identified, but before constraints are solved.
/// </summary>
public event TimestepperStageHandler CollisionsDetected;
/// <summary>
/// Fires after the solver executes and before body poses are integrated.
/// </summary>
public event TimestepperStageHandler ConstraintsSolved;
/// <summary>
/// Fires after bodies have their poses integrated and before data structures are incrementally optimized.
/// </summary>
public event TimestepperStageHandler PosesIntegrated;
public void Timestep(Simulation simulation, float dt, IThreadDispatcher threadDispatcher = null)
{
simulation.Sleep(threadDispatcher);
Slept?.Invoke(dt, threadDispatcher);
simulation.IntegrateVelocitiesBoundsAndInertias(dt, threadDispatcher);
BeforeCollisionDetection?.Invoke(dt, threadDispatcher);
simulation.CollisionDetection(dt, threadDispatcher);
CollisionsDetected?.Invoke(dt, threadDispatcher);
simulation.Solve(dt, threadDispatcher);
ConstraintsSolved?.Invoke(dt, threadDispatcher);
simulation.IntegratePoses(dt, threadDispatcher);
PosesIntegrated?.Invoke(dt, threadDispatcher);
simulation.IncrementallyOptimizeDataStructures(threadDispatcher);
}
}
}