MCPcopy Create free account
hub / github.com/davideberly/GeometricTools / Initialize

Method Initialize

GTE/Samples/Physics/BeadSlide/PhysicsModule.cpp:20–47  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

18}
19
20void PhysicsModule::Initialize(float time, float deltaTime, float q, float qDot)
21{
22 mTime = time;
23
24 // State variables.
25 mState[0] = q;
26 mState[1] = qDot;
27
28 // Auxiliary variable.
29 mAux = gravity;
30
31 // RK4 differential equation solver.
32 std::function<Vector2<float>(float, Vector2<float> const&)> odeFunction
33 =
34 [this](float, Vector2<float> const& input) -> Vector2<float>
35 {
36 float qSqr = input[0] * input[0];
37 float qDotSqr = input[1] * input[1];
38 float numer = -3.0f * mAux * qSqr - 2.0f * input[0] * (2.0f + 9.0f * qSqr) * qDotSqr;
39 float denom = 1.0f + qSqr * (4.0f + 9.0f * qSqr);
40 float qDotFunction = numer / denom;
41
42 // (q, dot(q))
43 return Vector2<float>{ input[1], qDotFunction };
44 };
45
46 mSolver = std::make_unique<Solver>(deltaTime, odeFunction);
47}
48
49void PhysicsModule::Update()
50{

Callers 1

ExecuteMethod · 0.45

Calls

no outgoing calls

Tested by

no test coverage detected