From: Charles McGarvey Date: Sun, 20 Sep 2009 16:36:42 +0000 (-0600) Subject: spring experiments X-Git-Url: https://git.dogcows.com/gitweb?p=chaz%2Fyoink;a=commitdiff_plain;h=df541170776dc4ac4f241ca480812bd70bcb6eca spring experiments --- diff --git a/src/Character.cc b/src/Character.cc index c7de260..4ce1105 100644 --- a/src/Character.cc +++ b/src/Character.cc @@ -40,7 +40,7 @@ Character::Character(const std::string& name) : current.inverseMass = 1.0 / current.mass; // gravity - current.force = Mf::Vector2(0.0, -120.0); + //current.force = Mf::Vector2(0.0, -120.0); // starting position current.position = Mf::Vector2(64.0, 64.0); @@ -56,6 +56,23 @@ Character::Character(const std::string& name) : void Character::update(Mf::Scalar t, Mf::Scalar dt) { previous = current; + + Mf::Scalar epsilon = 100.0; + + //current.momentum = Mf::Vector2(0.0, -120.0); + current.momentum = -5 * (current.position - Mf::Vector2(500.0, 200.0)) + - 2.0 * current.velocity; + current.recalculate(); + std::cout << "force: " << current.momentum << std::endl; + + //if (std::abs(current.force[0]) < epsilon && std::abs(current.force[1]) < epsilon && + //std::abs(current.velocity[0]) < epsilon && std::abs(current.velocity[1]) < epsilon) + //{ + //current.force = Mf::Vector2(0.0, 0.0); + //current.velocity = Mf::Vector2(0.0, 0.0); + //current.momentum = Mf::Vector2(0.0, 0.0); + //} + Mf::integrate(current, t, dt); animation_.update(t, dt); diff --git a/src/Character.hh b/src/Character.hh index 96ac499..00e5a4b 100644 --- a/src/Character.hh +++ b/src/Character.hh @@ -123,7 +123,7 @@ struct Character : public Mf::Entity return state; } - State operator+(State state) const + State operator+(const State& state) const { State newState = *this; newState.position += state.position; diff --git a/src/Moof/RK4.hh b/src/Moof/RK4.hh index a2e0f1c..00c0b64 100644 --- a/src/Moof/RK4.hh +++ b/src/Moof/RK4.hh @@ -75,6 +75,15 @@ inline void integrate(S& state, Scalar t, Scalar dt) } +//template +//inline T spring(Scalar k, Scalar b) +//{ + //current.force = -15 * (current.position - Mf::Vector2(200.0, 200.0)) + //- 15.0 * current.velocity; + //return +//} + + } // namespace Mf #endif // _MOOF_RK4_HH_