123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112 |
- #pragma once
- #include <Mathematics/ParticleSystem.h>
- namespace WwiseGTE
- {
- template <int N, typename Real>
- class MassSpringCurve : public ParticleSystem<N, Real>
- {
- public:
-
-
- virtual ~MassSpringCurve() = default;
- MassSpringCurve(int numParticles, Real step)
- :
- ParticleSystem<N, Real>(numParticles, step),
- mConstant(numParticles - 1),
- mLength(numParticles - 1)
- {
- std::fill(mConstant.begin(), mConstant.end(), (Real)0);
- std::fill(mLength.begin(), mLength.end(), (Real)0);
- }
-
-
- inline int GetNumSprings() const
- {
- return this->mNumParticles - 1;
- }
- inline void SetConstant(int i, Real constant)
- {
- mConstant[i] = constant;
- }
- inline void SetLength(int i, Real length)
- {
- mLength[i] = length;
- }
- inline Real const& GetConstant(int i) const
- {
- return mConstant[i];
- }
- inline Real const& GetLength(int i) const
- {
- return mLength[i];
- }
-
-
-
-
- virtual Vector<N, Real> ExternalAcceleration(int, Real,
- std::vector<Vector<N, Real>> const&,
- std::vector<Vector<N, Real>> const&)
- {
- return Vector<N, Real>::Zero();
- }
- protected:
-
-
-
-
- virtual Vector<N, Real> Acceleration(int i, Real time,
- std::vector<Vector<N, Real>> const& position,
- std::vector<Vector<N, Real>> const& velocity)
- {
-
-
-
-
-
- Vector<N, Real> acceleration = ExternalAcceleration(i, time, position, velocity);
- Vector<N, Real> diff, force;
- Real ratio;
- if (i > 0)
- {
- int iM1 = i - 1;
- diff = position[iM1] - position[i];
- ratio = mLength[iM1] / Length(diff);
- force = mConstant[iM1] * ((Real)1 - ratio) * diff;
- acceleration += this->mInvMass[i] * force;
- }
- int iP1 = i + 1;
- if (iP1 < this->mNumParticles)
- {
- diff = position[iP1] - position[i];
- ratio = mLength[i] / Length(diff);
- force = mConstant[i] * ((Real)1 - ratio) * diff;
- acceleration += this->mInvMass[i] * force;
- }
- return acceleration;
- }
- std::vector<Real> mConstant, mLength;
- };
- }
|