// check if our orientation and velocity are aligned
const glm::vec3 forward(-model_transform[2]);
// facing is local -Z rotated about local Y by yaw and transformed into world space
// check if our orientation and velocity are aligned
const glm::vec3 forward(-model_transform[2]);
// facing is local -Z rotated about local Y by yaw and transformed into world space
- const glm::vec3 facing(normalize(glm::vec3(glm::vec4(rotateY(glm::vec3(0.0f, 0.0f, -1.0f), state.yaw), 0.0f) * transpose(model_transform))));
+ const glm::vec3 facing(glm::normalize(glm::vec3(glm::vec4(glm::rotateY(glm::vec3(0.0f, 0.0f, -1.0f), state.yaw), 0.0f) * glm::transpose(model_transform))));
if (std::abs(1.0f - std::abs(vel_dot_up)) > std::numeric_limits<float>::epsilon()) {
// get direction of velocity projected onto model plane
if (std::abs(1.0f - std::abs(vel_dot_up)) > std::numeric_limits<float>::epsilon()) {
// get direction of velocity projected onto model plane
// if velocity points away from our facing (with a little bias), flip it around
// (the entity is "walking backwards")
// if velocity points away from our facing (with a little bias), flip it around
// (the entity is "walking backwards")
if (std::abs(state.yaw) > max_head_yaw) {
float deviation = state.yaw < 0.0f ? state.yaw + max_head_yaw : state.yaw - max_head_yaw;
// rotate the entity by deviation about local Y
if (std::abs(state.yaw) > max_head_yaw) {
float deviation = state.yaw < 0.0f ? state.yaw + max_head_yaw : state.yaw - max_head_yaw;
// rotate the entity by deviation about local Y
// and remove from head yaw
state.yaw -= deviation;
// shouldn't be necessary if max_head_yaw is < PI, but just to be sure :p
// and remove from head yaw
state.yaw -= deviation;
// shouldn't be necessary if max_head_yaw is < PI, but just to be sure :p
glm::mat4 EntityState::Transform(const glm::ivec3 &reference) const noexcept {
const glm::vec3 translation = RelativePosition(reference);
glm::mat4 EntityState::Transform(const glm::ivec3 &reference) const noexcept {
const glm::vec3 translation = RelativePosition(reference);
for (const WorldCollision &c : col) {
// diff points from block to state
glm::vec3 diff = entity.GetState().RelativePosition(c.ChunkPos()) - c.BlockCoords();
for (const WorldCollision &c : col) {
// diff points from block to state
glm::vec3 diff = entity.GetState().RelativePosition(c.ChunkPos()) - c.BlockCoords();
}
}
glm::vec3 Steering::Arrive(const EntityState &state, const ExactLocation &loc) const noexcept {
const glm::vec3 diff(loc.Difference(state.pos).Absolute());
}
}
glm::vec3 Steering::Arrive(const EntityState &state, const ExactLocation &loc) const noexcept {
const glm::vec3 diff(loc.Difference(state.pos).Absolute());
ExactLocation prediction(other.ChunkCoords(), other.Position() + (other.Velocity() * time_estimate));
return Seek(state, prediction);
}
ExactLocation prediction(other.ChunkCoords(), other.Position() + (other.Velocity() * time_estimate));
return Seek(state, prediction);
}
ExactLocation prediction(other.ChunkCoords(), other.Position() + (other.Velocity() * time_estimate));
return Flee(state, prediction);
}
}
glm::vec3 Steering::Wander(const EntityState &state) const noexcept {
ExactLocation prediction(other.ChunkCoords(), other.Position() + (other.Velocity() * time_estimate));
return Flee(state, prediction);
}
}
glm::vec3 Steering::Wander(const EntityState &state) const noexcept {
}
// if entity is already going in the direction of correction,
// let the problem resolve itself
}
// if entity is already going in the direction of correction,
// let the problem resolve itself
return;
}
// apply correction, maybe could use some damping, gotta test
state.pos.block += correction;
// kill velocity?
return;
}
// apply correction, maybe could use some damping, gotta test
state.pos.block += correction;
// kill velocity?
if (!c.Blocks()) continue;
glm::vec3 normal(c.normal);
// swap if neccessary (normal may point away from the entity)
if (!c.Blocks()) continue;
glm::vec3 normal(c.normal);
// swap if neccessary (normal may point away from the entity)
- min_pen = min(min_pen, local_pen);
- max_pen = max(max_pen, local_pen);
+ min_pen = glm::min(min_pen, local_pen);
+ max_pen = glm::max(max_pen, local_pen);
if (!center) {
// chunk unavailable, so make it really dark and from
// some arbitrary direction
if (!center) {
// chunk unavailable, so make it really dark and from
// some arbitrary direction
PrimitiveMesh debug_mesh;
PlainColor &prog = viewport.WorldColorProgram();
for (const Entity &entity : entities) {
PrimitiveMesh debug_mesh;
PlainColor &prog = viewport.WorldColorProgram();
for (const Entity &entity : entities) {
- debug_buf.OutlineBox(entity.Bounds(), glm::tvec4<unsigned char>(255, 0, 0, 255));
+ debug_buf.OutlineBox(entity.Bounds(), TVEC4<unsigned char, glm::precision(0)>(255, 0, 0, 255));
debug_mesh.Update(debug_buf);
prog.SetM(entity.Transform(players.front().GetEntity().ChunkCoords()));
debug_mesh.DrawLines();
debug_mesh.Update(debug_buf);
prog.SetM(entity.Transform(players.front().GetEntity().ChunkCoords()));
debug_mesh.DrawLines();