]> git.localhorst.tv Git - blank.git/blobdiff - src/world/world.cpp
use yaw as entity's orientation
[blank.git] / src / world / world.cpp
index 3f5740e21f75d8755d84003ef8882874c642828c..08ee294fca5e5a8b72351be8bb3ff3e3e40abdd2 100644 (file)
@@ -128,15 +128,9 @@ Ray Entity::Aim(const Chunk::Pos &chunk_offset) const noexcept {
 
 void Entity::UpdateModel() noexcept {
        state.AdjustHeading();
+       state.orient = glm::quat(glm::vec3(0.0f, state.yaw, 0.0f));
        if (model) {
-               Part::State &body_state = model.BodyState();
-               Part::State &eyes_state = model.EyesState();
-               if (&body_state != &eyes_state) {
-                       body_state.orientation = glm::quat(glm::vec3(0.0f, state.yaw, 0.0f));
-                       eyes_state.orientation = glm::quat(glm::vec3(state.pitch, 0.0f, 0.0f));
-               } else {
-                       eyes_state.orientation = glm::quat(glm::vec3(state.pitch, state.yaw, 0.0f));
-               }
+               model.EyesState().orientation = glm::quat(glm::vec3(state.pitch, 0.0f, 0.0f));
        }
 }
 
@@ -666,7 +660,27 @@ void World::Render(Viewport &viewport) {
        entity_prog.SetFogDensity(fog_density);
 
        for (Entity &entity : entities) {
-               entity.Render(entity.Transform(players.front().GetEntity().ChunkCoords()), entity_prog);
+               glm::mat4 M(entity.Transform(players.front().GetEntity().ChunkCoords()));
+               if (!CullTest(entity.Bounds(), entity_prog.GetVP() * M)) {
+                       entity.Render(M, entity_prog);
+               }
+       }
+}
+
+namespace {
+
+PrimitiveMesh::Buffer debug_buf;
+
+}
+
+void World::RenderDebug(Viewport &viewport) {
+       PrimitiveMesh debug_mesh;
+       PlainColor &prog = viewport.WorldColorProgram();
+       for (const Entity &entity : entities) {
+               debug_buf.OutlineBox(entity.Bounds(), glm::vec4(1.0f, 0.0f, 0.0f, 1.0f));
+               debug_mesh.Update(debug_buf);
+               prog.SetM(entity.Transform(players.front().GetEntity().ChunkCoords()));
+               debug_mesh.DrawLines();
        }
 }