MCPcopy Create free account
hub / github.com/NVIDIAGameWorks/FleX / MovingFrame

Class MovingFrame

extensions/flexExtMovingFrame.cpp:13–82  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

11// our math types on the API
12
13struct MovingFrame
14{
15 Vec3 position;
16 Quat rotation;
17
18 Vec3 velocity;
19 Vec3 omega;
20
21 Vec3 acceleration;
22 Vec3 tau;
23
24 Matrix44 delta;
25
26 MovingFrame(Vec3 worldTranslation, Quat worldRotation)
27 {
28 position = worldTranslation;
29 rotation = worldRotation;
30 delta = Matrix44::kIdentity;
31 }
32
33 // update the frame, returns a matrix representing the delta transform that
34 // can be applied to particles to teleport them to the frame's new location
35 void Move(Vec3 newPosition, Quat newRotation, float dt)
36 {
37 const float invDt = 1.0f/dt;
38
39 // calculate new velocity
40 Vec3 newVelocity = (newPosition-position)*invDt;
41 Vec3 newOmega = 2.0f*Vec3(Quat(newRotation-rotation)*Inverse(rotation)*invDt);
42
43 // calculate new acceleration
44 Vec3 newAcceleration = (newVelocity-velocity)*invDt;
45 Vec3 newTau = (newOmega-omega)*invDt;
46
47 // calculate delta transform
48 Matrix44 LocalFromOld = AffineInverse(TranslationMatrix(Point3(position))*RotationMatrix(rotation));
49 Matrix44 NewFromLocal = TranslationMatrix(Point3(newPosition))*RotationMatrix(newRotation);
50
51 // update delta transform
52 delta = NewFromLocal*LocalFromOld;
53
54 // position
55 position = newPosition;
56 rotation = newRotation;
57
58 // update velocity
59 velocity = newVelocity;
60 omega = newOmega;
61
62 acceleration = newAcceleration;
63 tau = newTau;
64 }
65
66 inline Vec3 GetLinearForce() const
67 {
68 return -acceleration;
69 }
70

Callers 1

NvFlexExtMovingFrameInitFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected