MCPcopy Create free account
hub / github.com/FlaxEngine/FlaxEngine / Tick

Method Tick

Source/Engine/Physics/Actors/SplineRopeBody.cpp:16–172  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

14}
15
16void SplineRopeBody::Tick()
17{
18 if (!_spline || _spline->GetSplinePointsCount() < 2)
19 return;
20 PROFILE_CPU();
21 PROFILE_MEM(Physics);
22
23 // Cache data
24 const Vector3 gravity = GetPhysicsScene()->GetGravity() * GravityScale;
25 auto& keyframes = _spline->Curve.GetKeyframes();
26 const Transform splineTransform = _spline->GetTransform();
27 const int32 keyframesCount = keyframes.Count();
28 const float substepTime = SubstepTime;
29 // TODO: scale substep time based on distance to the camera to have better performance when rope is far away
30 bool splineDirty = false;
31
32 // Synchronize spline keyframes with simulated masses
33 if (_masses.Count() > keyframesCount)
34 _masses.Resize(keyframesCount);
35 else
36 {
37 _masses.EnsureCapacity(keyframesCount);
38 while (_masses.Count() < keyframesCount)
39 {
40 const int32 i = _masses.Count();
41 auto& mass = _masses.AddOne();
42 mass.Position = mass.PrevPosition = splineTransform.LocalToWorld(keyframes[i].Value.Translation);
43 if (i != 0)
44 mass.SegmentLength = Vector3::Distance(mass.PrevPosition, _masses[i - 1].PrevPosition);
45 else
46 mass.SegmentLength = 0.0f;
47 }
48 }
49 {
50 // Rope start
51 auto& mass = _masses.First();
52 mass.Position = GetPosition();
53 mass.Unconstrained = false;
54 if (splineTransform.LocalToWorld(keyframes.First().Value.Translation) != mass.Position)
55 splineDirty = true;
56 }
57 bool syncPositions = true;
58 if (splineTransform != _splineTransform)
59 {
60 _splineTransform = splineTransform;
61 syncPositions = false;
62 splineDirty = true;
63 }
64 if (syncPositions)
65 {
66 for (int32 i = 1; i < keyframesCount; i++)
67 {
68 auto& mass = _masses[i];
69 mass.Unconstrained = true;
70 mass.Position = splineTransform.LocalToWorld(keyframes[i].Value.Translation);
71 }
72 }
73 if (AttachEnd)

Callers

nothing calls this directly

Calls 15

GetPhysicsSceneFunction · 0.85
DistanceFunction · 0.85
GetSplinePointsCountMethod · 0.80
GetGravityMethod · 0.80
GetTransformMethod · 0.80
AddOneMethod · 0.80
UpdateSplineMethod · 0.80
GetPositionFunction · 0.50
GetKeyframesMethod · 0.45
CountMethod · 0.45
ResizeMethod · 0.45
EnsureCapacityMethod · 0.45

Tested by

no test coverage detected