void EulerStep (ParticleSystem p, double delta_t) { int dim = ParticleStateDim (p); int spacedim; // double crossFraction; spacedim = 3; // we handle 3D always GetParticleState (p, p->state_old.Ref()); ParticleDerivative (p, p->state_dot.Ref()); p->state_new = p->state_old + delta_t * p->state_dot; // CombinedVector (1.0, p->state_old, delta_t, p->state_dot, p->state_new, dim); // anchor particles do not move for (unsigned int i = 0; i < p->particles.size(); i++) { if (p->particles[i]->anchor) { for (int ii = 0; ii < spacedim; ii++) { p->state_new[2*spacedim*i+ii] = p->state_old[2*spacedim*i+ii]; p->state_new[2*spacedim*i+ii+spacedim] = 0.0; } } } }
void SpringSys::UpdateParticleState(TimeValue t, Tab<Matrix3> tmArray, int index, TimeValue Delta) { Point3 t_pos, t_vel, orig_pos, orig_vel; Matrix3 tm; for (int b=0;b<parts[index].GetSprings()->length();b++) { if (parts[index].GetSpring(b)->GetPointConstraint()->GetIndex() < tmArray.Count()) { tm = tmArray[parts[index].GetSpring(b)->GetPointConstraint()->index]; ComputeControlledParticleForce(tm, index, b); /* compute bone deriv used by ApplySpring */ } } Clear_Forces(index); /* zero the force accumulators */ Compute_Forces(t, index); /* magic force function */ ComputeDerivative(index, t_pos, t_vel); /* get deriv */ //ComputeDerivative(pIndex, t_pos, t_vel, Delta); /* get deriv */ ScaleVectors(t_pos, t_vel, Delta); /* scale it */ GetParticleState(index, orig_pos, orig_vel); /* get state */ AddVectors(orig_pos, orig_vel, t_pos, t_vel); /* add -> temp2 */ SetParticleState(index, t_pos, t_vel); /* update state */ }