- /// direction is rotation axis, magnitude is speed in rad/ms
- const glm::vec3 &AngularVelocity() const noexcept { return angular_velocity; }
- void AngularVelocity(const glm::vec3 &) noexcept;
-
- const glm::quat &Rotation() const noexcept { return rotation; }
- void Rotation(const glm::quat &) noexcept;
- void Rotate(const glm::quat &delta) noexcept;
-
- glm::mat4 Transform(const Chunk::Pos &chunk_offset) const noexcept;
- Ray Aim(const Chunk::Pos &chunk_offset) const noexcept;
+ /// orientation of local coordinate system
+ void Orientation(const glm::quat &o) noexcept { state.orient = o; }
+ const glm::quat &Orientation() const noexcept { return state.orient; }
+
+ /// orientation of head within local coordinate system, in radians
+ float Pitch() const noexcept { return state.pitch; }
+ float Yaw() const noexcept { return state.yaw; }
+ void TurnHead(float delta_pitch, float delta_yaw) noexcept;
+ void SetHead(float pitch, float yaw) noexcept;
+
+ /// get a transform for this entity's coordinate space
+ const glm::mat4 Transform() const noexcept { return model_transform; }
+ /// get a transform for this entity's coordinate space relative to reference chunk
+ glm::mat4 Transform(const glm::ivec3 &reference) const noexcept;
+ /// get a transform for this entity's view space relative to reference chunk
+ glm::mat4 ViewTransform(const glm::ivec3 &reference) const noexcept;
+ /// get a ray in entity's face direction originating from center of vision
+ Ray Aim(const ExactLocation::Coarse &chunk_offset) const noexcept;
+
+ /// true if this entity's position will change (significantly) the next update
+ bool Moving() const noexcept { return speed > 0.0f; }
+ /// magnitude of velocity
+ float Speed() const noexcept { return speed; }
+ /// normalized velocity or heading if standing still
+ const glm::vec3 &Heading() const noexcept { return heading; }
+
+ void SetState(const EntityState &s) noexcept { state = s; }
+ const EntityState &GetState() const noexcept { return state; }
+
+ void Ref() noexcept { ++ref_count; }
+ void UnRef() noexcept { --ref_count; }
+ void Kill() noexcept { dead = true; }
+ bool Referenced() const noexcept { return ref_count > 0; }
+ bool Dead() const noexcept { return dead; }
+ bool CanRemove() const noexcept { return dead && ref_count <= 0; }
+
+ void Update(World &, float dt);
+
+ void Render(const glm::mat4 &M, DirectionalLighting &prog) noexcept {
+ if (model) model.Render(M, prog);
+ }