]> git.localhorst.tv Git - blank.git/commitdiff
use seconds as world time unit
authorDaniel Karbach <daniel.karbach@localhorst.tv>
Mon, 19 Oct 2015 10:43:19 +0000 (12:43 +0200)
committerDaniel Karbach <daniel.karbach@localhorst.tv>
Mon, 19 Oct 2015 10:43:19 +0000 (12:43 +0200)
src/ai/ai.cpp
src/client/NetworkedInput.hpp
src/client/net.cpp
src/ui/ui.cpp
src/world/Entity.hpp
src/world/World.hpp
src/world/world.cpp

index 7ada5a34b3bc6d80912f0dfd876e8a721217fff6..7dfe0424c44a210cdf1f1619063a2d756da45f64 100644 (file)
@@ -16,8 +16,8 @@ Chaser::Chaser(World &world, Entity &ctrl, Entity &tgt) noexcept
 : Controller(ctrl)
 , world(world)
 , tgt(tgt)
-, chase_speed(0.002f)
-, flee_speed(-0.005f)
+, chase_speed(2.0f)
+, flee_speed(-5.0f)
 , stop_dist(10)
 , flee_dist(5) {
        tgt.Ref();
@@ -109,7 +109,7 @@ void RandomWalk::Change() noexcept {
        start_vel = target_vel;
        start_rot = target_rot;
 
-       constexpr float base = 0.000001f;
+       constexpr float base = 0.001f;
 
        target_vel.x = base * (random.Next<short>() % 1024);
        target_vel.y = base * (random.Next<short>() % 1024);
index 36382b93225632d1b4056af8d3e9639f6b162d74..a6702228a149e6c1b80f78812a0dcd510e8e9ec3 100644 (file)
@@ -37,9 +37,9 @@ private:
        struct PlayerHistory {
                EntityState state;
                glm::vec3 tgt_vel;
-               int delta_t;
+               float delta_t;
                std::uint16_t packet;
-               PlayerHistory(EntityState s, const glm::vec3 &tv, int dt, std::uint16_t p)
+               PlayerHistory(EntityState s, const glm::vec3 &tv, float dt, std::uint16_t p)
                : state(s), tgt_vel(tv), delta_t(dt), packet(p) { }
        };
        std::list<PlayerHistory> player_hist;
index 8a4930410605b7a8eacf0ae0dd8886ef2630ad51..c3bbb67b40be4d8c7b81ab3d67a62f3ed0cff81b 100644 (file)
@@ -332,12 +332,12 @@ void NetworkedInput::PushPlayerUpdate(int dt) {
                InventorySlot()
        );
        if (player_hist.size() < 16) {
-               player_hist.emplace_back(state, GetPlayer().GetEntity().TargetVelocity(), dt, packet);
+               player_hist.emplace_back(state, GetPlayer().GetEntity().TargetVelocity(), dt * 0.001f, packet);
        } else {
                auto entry = player_hist.begin();
                entry->state = state;
                entry->tgt_vel = GetPlayer().GetEntity().TargetVelocity();
-               entry->delta_t = dt;
+               entry->delta_t = dt * 0.001f;
                entry->packet = packet;
                player_hist.splice(player_hist.end(), player_hist, entry);
        }
index 96386195e57803c4aa8fcd498072caa229df768f..5b0eec8b1dac47bb7b1798e51dbfb4d814892893 100644 (file)
@@ -83,7 +83,7 @@ void PlayerController::Invalidate() noexcept {
 }
 
 void PlayerController::UpdatePlayer() noexcept {
-       constexpr float max_vel = 0.005f;
+       constexpr float max_vel = 5.0f; // in m/s
        if (dirty) {
                player.GetEntity().Orientation(glm::quat(glm::vec3(pitch, yaw, 0.0f)));
                player.GetEntity().TargetVelocity(glm::rotateY(move_dir * max_vel, yaw));
index 1ac92235a9401f3c63675500a27b7ffcde977534..7e85591c89150f1c22e6a20604cca20a7c6eccca 100644 (file)
@@ -56,7 +56,7 @@ public:
                return state.Diff(other.state);
        }
 
-       /// direction is rotation axis, magnitude is speed in rad/ms
+       /// direction is rotation axis, magnitude is speed in rad/s
        const glm::vec3 &AngularVelocity() const noexcept { return state.ang_vel; }
        void AngularVelocity(const glm::vec3 &v) noexcept { state.ang_vel = v; }
 
index c24ccf327f4a21a848a5f6db1dc4616be3aea192..4755b18bcdea3cad24dc797c748691239d7f617f 100644 (file)
@@ -89,7 +89,9 @@ public:
        std::list<Entity> &Entities() noexcept { return entities; }
        const std::list<Entity> &Entities() const noexcept { return entities; }
 
+       // dt in ms
        void Update(int dt);
+       // dt in s
        void Update(Entity &, float dt);
 
        void Render(Viewport &);
index 750cd2d6ff31707e0613d30390bde043b2e78c95..15f1cabae2a124ff6eaa8e61baf1f0087b8fce89 100644 (file)
@@ -342,7 +342,7 @@ bool World::Intersection(const Entity &e, const EntityState &s, std::vector<Worl
 
 
 void World::Update(int dt) {
-       float fdt(dt);
+       float fdt(dt * 0.001f);
        for (Entity &entity : entities) {
                Update(entity, fdt);
        }
@@ -409,7 +409,7 @@ EntityDerivative World::CalculateStep(
 
        EntityDerivative out;
        out.position = next.velocity;
-       out.velocity = CalculateForce(entity, next); // by mass = 1
+       out.velocity = CalculateForce(entity, next); // by mass = 1kg
        return out;
 }
 
@@ -424,12 +424,11 @@ glm::vec3 World::ControlForce(
        const Entity &entity,
        const EntityState &state
 ) {
-       constexpr float k = 1.0f; // spring constant
-       constexpr float b = 1.0f; // damper constant
-       constexpr float t = 0.01f; // 1/time constant
-       const glm::vec3 x(-entity.TargetVelocity()); // endpoint displacement from equilibrium
-       const glm::vec3 v(state.velocity); // relative velocity between endpoints
-       return (((-k) * x) - (b * v)) * t; // times mass = 1
+       constexpr float k = 10.0f; // spring constant
+       constexpr float b = 10.0f; // damper constant
+       const glm::vec3 x(-entity.TargetVelocity()); // endpoint displacement from equilibrium, by 1s, in m
+       const glm::vec3 v(state.velocity); // relative velocity between endpoints in m/s
+       return ((-k) * x) - (b * v); // times 1kg/s, in kg*m/s²
 }
 
 namespace {
@@ -462,12 +461,11 @@ glm::vec3 World::CollisionForce(
                glm::vec3 normal_velocity(normal * dot(state.velocity, normal));
                // apply force proportional to penetration
                // use velocity projected onto normal as damper
-               constexpr float k = 1.0f; // spring constant
-               constexpr float b = 1.0f; // damper constant
-               constexpr float t = 0.001f; // 1/time constant
-               const glm::vec3 x(penetration); // endpoint displacement from equilibrium
-               const glm::vec3 v(normal_velocity); // relative velocity between endpoints
-               return (((-k) * x) - (b * v)) * t; // times mass = 1
+               constexpr float k = 1000.0f; // spring constant
+               constexpr float b = 100.0f; // damper constant
+               const glm::vec3 x(penetration); // endpoint displacement from equilibrium in m
+               const glm::vec3 v(normal_velocity); // relative velocity between endpoints in m/s
+               return (((-k) * x) - (b * v)); // times 1kg/s, in kg*m/s²
        } else {
                return glm::vec3(0.0f);
        }