#include "EntityCollision.hpp"
#include "WorldCollision.hpp"
#include "../app/Assets.hpp"
+#include "../geometry/const.hpp"
+#include "../geometry/distance.hpp"
#include "../graphics/Format.hpp"
#include "../graphics/Viewport.hpp"
}
void Entity::Position(const glm::ivec3 &c, const glm::vec3 &b) noexcept {
- state.chunk_pos = c;
- state.block_pos = b;
+ state.pos.chunk = c;
+ state.pos.block = b;
}
void Entity::Position(const glm::vec3 &pos) noexcept {
- state.block_pos = pos;
+ state.pos.block = pos;
state.AdjustPosition();
}
}
glm::mat4 Entity::Transform(const glm::ivec3 &reference) const noexcept {
- return glm::translate(glm::vec3((state.chunk_pos - reference) * Chunk::Extent())) * model_transform;
+ return glm::translate(glm::vec3((state.pos.chunk - reference) * ExactLocation::Extent())) * model_transform;
}
glm::mat4 Entity::ViewTransform(const glm::ivec3 &reference) const noexcept {
return Transform(reference) * view_transform;
}
-Ray Entity::Aim(const Chunk::Pos &chunk_offset) const noexcept {
+Ray Entity::Aim(const ExactLocation::Coarse &chunk_offset) const noexcept {
glm::mat4 transform = ViewTransform(chunk_offset);
return Ray{ glm::vec3(transform[3]), -glm::vec3(transform[2]) };
}
void Entity::UpdateTransforms() noexcept {
// model transform is the one given by current state
- model_transform = state.Transform(state.chunk_pos);
+ model_transform = state.Transform(state.pos.chunk);
// view transform is either the model's eyes transform or,
// should the entity have no model, the pitch (yaw already is
// in model transform)
std::cout << "forward: " << forward << std::endl;
std::cout << "facing: " << facing << std::endl;
std::cout << "direction: " << direction << std::endl;
- std::cout << "difference: " << rad2deg(relative_difference) << "°" << std::endl;
- std::cout << "correction: " << rad2deg(correction) << "°" << std::endl;
+ std::cout << "difference: " << glm::degrees(relative_difference) << "°" << std::endl;
+ std::cout << "correction: " << glm::degrees(correction) << "°" << std::endl;
std::cout << std::endl;
}
// now rotate body by correction and head by -correction
EntityState::EntityState()
-: chunk_pos(0)
-, block_pos(0.0f)
+: pos()
, velocity(0.0f)
, orient(1.0f, 0.0f, 0.0f, 0.0f)
, pitch(0.0f)
}
void EntityState::AdjustPosition() noexcept {
- while (block_pos.x >= Chunk::width) {
- block_pos.x -= Chunk::width;
- ++chunk_pos.x;
- }
- while (block_pos.x < 0) {
- block_pos.x += Chunk::width;
- --chunk_pos.x;
- }
- while (block_pos.y >= Chunk::height) {
- block_pos.y -= Chunk::height;
- ++chunk_pos.y;
- }
- while (block_pos.y < 0) {
- block_pos.y += Chunk::height;
- --chunk_pos.y;
- }
- while (block_pos.z >= Chunk::depth) {
- block_pos.z -= Chunk::depth;
- ++chunk_pos.z;
- }
- while (block_pos.z < 0) {
- block_pos.z += Chunk::depth;
- --chunk_pos.z;
- }
+ pos.Correct();
}
void EntityState::AdjustHeading() noexcept {
bool World::Intersection(
const Ray &ray,
const glm::mat4 &M,
- const Chunk::Pos &reference,
+ const ExactLocation::Coarse &reference,
WorldCollision &coll
) {
candidates.clear();
bool World::Intersection(const Entity &e, const EntityState &s, std::vector<WorldCollision> &col) {
AABB box = e.Bounds();
- Chunk::Pos reference = s.chunk_pos;
+ glm::ivec3 reference = s.pos.chunk;
glm::mat4 M = s.Transform(reference);
return Intersection(box, M, reference, col);
}
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);
- state.block_pos += f.position * dt;
+ state.pos.block += f.position * dt;
state.velocity += f.velocity * dt;
state.AdjustPosition();
const EntityDerivative &delta
) {
EntityState next(cur);
- next.block_pos += delta.position * dt;
+ next.pos.block += delta.position * dt;
next.velocity += delta.velocity * dt;
next.AdjustPosition();