]> git.localhorst.tv Git - blank.git/blobdiff - src/shape.cpp
minor optimizations in chunk
[blank.git] / src / shape.cpp
index 8111258be6f83d5b2f7d24baeca0a96c99757e3d..59e4f1feee1dfd8a3a67851d729512fa66888cc3 100644 (file)
@@ -6,16 +6,16 @@ namespace blank {
 void Shape::Vertices(
        Model::Positions &vertex,
        Model::Normals &normal,
-       Model::Indices &index,
-       const Model::Position &elem_offset,
-       Model::Index idx_offset
+       Model::Indices &index
 ) const {
        for (const auto &pos : vtx_pos) {
-               vertex.emplace_back(elem_offset + pos);
+               vertex.emplace_back(pos);
+       }
+       for (const auto &nrm : vtx_nrm) {
+               normal.emplace_back(nrm);
        }
-       normal.insert(normal.end(), vtx_nrm.begin(), vtx_nrm.end());
        for (auto idx : vtx_idx) {
-               index.emplace_back(idx_offset + idx);
+               index.emplace_back(idx);
        }
 }
 
@@ -37,6 +37,20 @@ void Shape::Vertices(
        }
 }
 
+void Shape::Vertices(
+       BlockModel::Positions &vertex,
+       BlockModel::Indices &index,
+       const glm::mat4 &transform,
+       BlockModel::Index idx_offset
+) const {
+       for (const auto &pos : vtx_pos) {
+               vertex.emplace_back(transform * glm::vec4(pos, 1.0f));
+       }
+       for (auto idx : vtx_idx) {
+               index.emplace_back(idx_offset + idx);
+       }
+}
+
 void Shape::Outline(
        OutlineModel::Positions &vertex,
        OutlineModel::Indices &index,
@@ -61,7 +75,7 @@ bool NullShape::Intersects(
        const Ray &,
        const glm::mat4 &,
        float &, glm::vec3 &
-) const {
+) const noexcept {
        return false;
 }
 
@@ -148,7 +162,7 @@ bool CuboidShape::Intersects(
        const Ray &ray,
        const glm::mat4 &M,
        float &dist, glm::vec3 &normal
-) const {
+) const noexcept {
        return Intersection(ray, bb, M, &dist, &normal);
 }
 
@@ -280,7 +294,7 @@ bool StairShape::Intersects(
        const glm::mat4 &M,
        float &dist,
        glm::vec3 &norm
-) const {
+) const noexcept {
        float top_dist, bot_dist;
        glm::vec3 top_norm, bot_norm;
        bool top_hit = Intersection(ray, top, M, &top_dist, &top_norm);