From 808d9dbd3ab101c0ff10697e36ef2c45a23b6ef5 Mon Sep 17 00:00:00 2001 From: Daniel Karbach Date: Wed, 21 Oct 2015 15:33:37 +0200 Subject: [PATCH] get rid of angular velocity orientation will be managed solely by controllers (ai/animation/input/etc) --- doc/protocol | 2 +- src/ai/RandomWalk.hpp | 3 --- src/ai/Spawner.cpp | 6 ------ src/ai/ai.cpp | 9 --------- src/net/net.cpp | 4 ---- src/world/Entity.hpp | 4 ---- src/world/EntityDerivative.hpp | 1 - src/world/EntityState.hpp | 1 - src/world/world.cpp | 21 +-------------------- tst/net/PacketTest.cpp | 9 --------- 10 files changed, 2 insertions(+), 58 deletions(-) diff --git a/doc/protocol b/doc/protocol index 1cea780..ce3f5fd 100644 --- a/doc/protocol +++ b/doc/protocol @@ -35,7 +35,7 @@ entity state 50 [ 0] vec3i chunk pos (there's a variation where this is a ve [12] vec3u block pos by 16, [18] vec3 velocity, [30] quat orientation, - [38] vec3 angular velocity + [38] 12 reserved bytes (used to be angular velocity) Packets diff --git a/src/ai/RandomWalk.hpp b/src/ai/RandomWalk.hpp index 8a0a19d..339e77d 100644 --- a/src/ai/RandomWalk.hpp +++ b/src/ai/RandomWalk.hpp @@ -29,9 +29,6 @@ private: glm::vec3 start_vel; glm::vec3 target_vel; - glm::vec3 start_rot; - glm::vec3 target_rot; - int switch_time; float lerp_max; float lerp_time; diff --git a/src/ai/Spawner.cpp b/src/ai/Spawner.cpp index a4b4030..7b6e4b2 100644 --- a/src/ai/Spawner.cpp +++ b/src/ai/Spawner.cpp @@ -125,17 +125,11 @@ void Spawner::TrySpawn() { } void Spawner::Spawn(Entity &reference, const glm::ivec3 &chunk, const glm::vec3 &pos) { - glm::vec3 rot(0.000001f); - rot.x *= (random.Next() % 1024); - rot.y *= (random.Next() % 1024); - rot.z *= (random.Next() % 1024); - Entity &e = world.AddEntity(); e.Position(chunk, pos); e.Bounds({ { -0.5f, -0.5f, -0.5f }, { 0.5f, 0.5f, 0.5f } }); e.WorldCollidable(true); RandomModel().Instantiate(e.GetModel()); - e.AngularVelocity(rot); Controller *ctrl; if (random()) { ctrl = new RandomWalk(e, random.Next()); diff --git a/src/ai/ai.cpp b/src/ai/ai.cpp index 7dfe042..9ec9fec 100644 --- a/src/ai/ai.cpp +++ b/src/ai/ai.cpp @@ -75,8 +75,6 @@ RandomWalk::RandomWalk(Entity &e, std::uint64_t seed) noexcept , random(seed) , start_vel(e.Velocity()) , target_vel(start_vel) -, start_rot(e.AngularVelocity()) -, target_rot(start_rot) , switch_time(0) , lerp_max(1.0f) , lerp_time(0.0f) { @@ -98,26 +96,19 @@ void RandomWalk::Update(int dt) { } else if (lerp_time > 0) { float a = std::min(lerp_time / lerp_max, 1.0f); Controlled().TargetVelocity(mix(target_vel, start_vel, a)); - Controlled().AngularVelocity(mix(target_rot, start_rot, a)); } else { Controlled().TargetVelocity(target_vel); - Controlled().AngularVelocity(target_rot); } } void RandomWalk::Change() noexcept { start_vel = target_vel; - start_rot = target_rot; constexpr float base = 0.001f; target_vel.x = base * (random.Next() % 1024); target_vel.y = base * (random.Next() % 1024); target_vel.z = base * (random.Next() % 1024); - - target_rot.x = base * (random.Next() % 1024); - target_rot.y = base * (random.Next() % 1024); - target_rot.z = base * (random.Next() % 1024); } } diff --git a/src/net/net.cpp b/src/net/net.cpp index 86098f4..25e5b43 100644 --- a/src/net/net.cpp +++ b/src/net/net.cpp @@ -281,7 +281,6 @@ void Packet::Payload::Write(const EntityState &state, size_t off) noexcept { WritePackU(state.block_pos * (1.0f / 16.0f), off + 12); Write(state.velocity, off + 18); Write(state.orient, off + 30); - Write(state.ang_vel, off + 38); } void Packet::Payload::Read(EntityState &state, size_t off) const noexcept { @@ -289,7 +288,6 @@ void Packet::Payload::Read(EntityState &state, size_t off) const noexcept { ReadPackU(state.block_pos, off + 12); Read(state.velocity, off + 18); Read(state.orient, off + 30); - Read(state.ang_vel, off + 38); state.block_pos *= 16.0f; } @@ -298,7 +296,6 @@ void Packet::Payload::Write(const EntityState &state, const glm::ivec3 &base, si WritePackU(state.block_pos * (1.0f / 16.0f), off + 3); Write(state.velocity, off + 9); Write(state.orient, off + 21); - Write(state.ang_vel, off + 29); } void Packet::Payload::Read(EntityState &state, const glm::ivec3 &base, size_t off) const noexcept { @@ -306,7 +303,6 @@ void Packet::Payload::Read(EntityState &state, const glm::ivec3 &base, size_t of ReadPackU(state.block_pos, off + 3); Read(state.velocity, off + 9); Read(state.orient, off + 21); - Read(state.ang_vel, off + 29); state.chunk_pos += base; state.block_pos *= 16.0f; } diff --git a/src/world/Entity.hpp b/src/world/Entity.hpp index 0a44303..65e1441 100644 --- a/src/world/Entity.hpp +++ b/src/world/Entity.hpp @@ -56,10 +56,6 @@ public: return state.Diff(other.state); } - /// 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; } - const glm::quat &Orientation() const noexcept { return state.orient; } void Orientation(const glm::quat &o) noexcept { state.orient = o; } diff --git a/src/world/EntityDerivative.hpp b/src/world/EntityDerivative.hpp index 9666b1f..d3a6f30 100644 --- a/src/world/EntityDerivative.hpp +++ b/src/world/EntityDerivative.hpp @@ -10,7 +10,6 @@ struct EntityDerivative { glm::vec3 position; glm::vec3 velocity; - glm::vec3 orient; }; diff --git a/src/world/EntityState.hpp b/src/world/EntityState.hpp index e93fffa..d3e34e5 100644 --- a/src/world/EntityState.hpp +++ b/src/world/EntityState.hpp @@ -16,7 +16,6 @@ struct EntityState { glm::vec3 velocity; glm::quat orient; - glm::vec3 ang_vel; EntityState(); diff --git a/src/world/world.cpp b/src/world/world.cpp index 8f22f0c..1885391 100644 --- a/src/world/world.cpp +++ b/src/world/world.cpp @@ -71,8 +71,7 @@ EntityState::EntityState() : chunk_pos(0) , block_pos(0.0f) , velocity(0.0f) -, orient(1.0f, 0.0f, 0.0f, 0.0f) -, ang_vel(0.0f) { +, orient(1.0f, 0.0f, 0.0f, 0.0f) { } @@ -370,21 +369,6 @@ void World::Update(int dt) { } } -namespace { - -glm::quat delta_rot(const glm::vec3 &av, float dt) { - glm::vec3 half(av * dt * 0.5f); - float mag = length(half); - if (mag > 0.0f) { - float smag = std::sin(mag) / mag; - return glm::quat(std::cos(mag), half * smag); - } else { - return glm::quat(1.0f, 0.0f, 0.0f, 0.0f); - } -} - -} - void World::Update(Entity &entity, float dt) { EntityState state(entity.GetState()); @@ -397,11 +381,9 @@ void World::Update(Entity &entity, float dt) { constexpr float sixth = 1.0f / 6.0f; f.position = sixth * ((a.position + 2.0f * (b.position + c.position)) + d.position); f.velocity = sixth * ((a.velocity + 2.0f * (b.velocity + c.velocity)) + d.velocity); - f.orient = sixth * ((a.orient + 2.0f * (b.orient + c.orient)) + d.orient); state.block_pos += f.position * dt; state.velocity += f.velocity * dt; - state.orient = delta_rot(f.orient, dt) * state.orient; state.AdjustPosition(); entity.SetState(state); @@ -416,7 +398,6 @@ EntityDerivative World::CalculateStep( EntityState next(cur); next.block_pos += delta.position * dt; next.velocity += delta.velocity * dt; - next.orient = delta_rot(cur.ang_vel, dt) * cur.orient; next.AdjustPosition(); EntityDerivative out; diff --git a/tst/net/PacketTest.cpp b/tst/net/PacketTest.cpp index 6803110..d616fd3 100644 --- a/tst/net/PacketTest.cpp +++ b/tst/net/PacketTest.cpp @@ -116,7 +116,6 @@ void PacketTest::testJoin() { write_entity.GetState().block_pos = { 1.5f, 0.9f, 12.0f }; write_entity.GetState().velocity = { 0.025f, 0.001f, 0.0f }; write_entity.GetState().orient = { 1.0f, 0.0f, 0.0f, 0.0f }; - write_entity.GetState().ang_vel = { 0.01f, 0.00302f, 0.0985f }; uint32_t read_id = 0; EntityState read_state; pack.WritePlayer(write_entity); @@ -164,7 +163,6 @@ void PacketTest::testPlayerUpdate() { write_state.block_pos = { 1.5f, 0.9f, 12.0f }; write_state.velocity = { 0.025f, 0.001f, 0.0f }; write_state.orient = { 1.0f, 0.0f, 0.0f, 0.0f }; - write_state.ang_vel = { 0.01f, 0.00302f, 0.0985f }; glm::vec3 write_movement(0.5f, -1.0f, 1.0f); float write_pitch = 1.25f; float write_yaw = -2.5f; @@ -228,7 +226,6 @@ void PacketTest::testSpawnEntity() { write_entity.GetState().block_pos = { 1.5f, 0.9f, 12.0f }; write_entity.GetState().velocity = { 0.025f, 0.001f, 0.0f }; write_entity.GetState().orient = { 1.0f, 0.0f, 0.0f, 0.0f }; - write_entity.GetState().ang_vel = { 0.01f, 0.00302f, 0.0985f }; write_entity.Bounds({{ -1, -1, -1 }, { 1, 1, 1 }}); write_entity.WorldCollidable(true); write_entity.Name("blah"); @@ -317,7 +314,6 @@ void PacketTest::testEntityUpdate() { write_entity.GetState().block_pos = { 1.5f, 0.9f, 12.0f }; write_entity.GetState().velocity = { 0.025f, 0.001f, 0.0f }; write_entity.GetState().orient = { 1.0f, 0.0f, 0.0f, 0.0f }; - write_entity.GetState().ang_vel = { 0.01f, 0.00302f, 0.0985f }; pack.WriteEntity(write_entity, write_base, 1); pack.WriteEntity(write_entity, write_base, 0); pack.WriteEntity(write_entity, write_base, 2); @@ -354,7 +350,6 @@ void PacketTest::testPlayerCorrection() { write_entity.GetState().block_pos = { 1.5f, 0.9f, 12.0f }; write_entity.GetState().velocity = { 0.025f, 0.001f, 0.0f }; write_entity.GetState().orient = { 1.0f, 0.0f, 0.0f, 0.0f }; - write_entity.GetState().ang_vel = { 0.01f, 0.00302f, 0.0985f }; pack.WritePlayer(write_entity); EntityState read_state; @@ -615,10 +610,6 @@ void PacketTest::AssertEqual( message + ": bad orientation", expected.orient, actual.orient ); - AssertEqual( - message + ": bad angular velocity", - expected.ang_vel, actual.ang_vel - ); } void PacketTest::AssertEqual( -- 2.39.2