| 96 | } |
| 97 | |
| 98 | void NvFlexExtMovingFrameApply(NvFlexExtMovingFrame* frame, float* positions, float* velocities, int numParticles, float linearScale, float angularScale, float dt) |
| 99 | { |
| 100 | const MovingFrame& f = (MovingFrame&)(*frame); |
| 101 | |
| 102 | // linear force constant for all particles |
| 103 | Vec3 linearForce = f.GetLinearForce()*linearScale; |
| 104 | |
| 105 | for (int i=0; i < numParticles; ++i) |
| 106 | { |
| 107 | Vec3 particlePos = Vec3(&positions[i*4]); |
| 108 | Vec3 particleVel = Vec3(&velocities[i*3]); |
| 109 | |
| 110 | // angular force depends on particles position |
| 111 | Vec3 angularForce = f.GetAngularForce(particlePos)*angularScale; |
| 112 | |
| 113 | // transform particle to frame's new location |
| 114 | particlePos = Vec3(f.delta*Vec4(particlePos, 1.0f)); |
| 115 | particleVel += (linearForce + angularForce)*dt; |
| 116 | |
| 117 | // update positions |
| 118 | positions[i*4+0] = particlePos.x; |
| 119 | positions[i*4+1] = particlePos.y; |
| 120 | positions[i*4+2] = particlePos.z; |
| 121 | |
| 122 | velocities[i*3+0] = particleVel.x; |
| 123 | velocities[i*3+1] = particleVel.y; |
| 124 | velocities[i*3+2] = particleVel.z; |
| 125 | |
| 126 | } |
| 127 | } |
no test coverage detected