namespace blank {
void Shape::Vertices(
- EntityModel::Buffer &out,
+ EntityMesh::Buffer &out,
float tex_offset
) const {
for (const auto &pos : vtx_pos) {
}
void Shape::Vertices(
- EntityModel::Buffer &out,
+ EntityMesh::Buffer &out,
const glm::mat4 &transform,
float tex_offset,
- EntityModel::Index idx_offset
+ EntityMesh::Index idx_offset
) const {
for (const auto &pos : vtx_pos) {
out.vertices.emplace_back(transform * glm::vec4(pos, 1.0f));
}
void Shape::Vertices(
- BlockModel::Buffer &out,
+ BlockMesh::Buffer &out,
const glm::mat4 &transform,
float tex_offset,
- BlockModel::Index idx_offset
+ BlockMesh::Index idx_offset
) const {
for (const auto &pos : vtx_pos) {
out.vertices.emplace_back(transform * glm::vec4(pos, 1.0f));
}
}
-void Shape::Outline(
- OutlineModel::Buffer &out,
- const OutlineModel::Position &elem_offset,
- OutlineModel::Index idx_offset
-) const {
- for (const auto &pos : out_pos) {
- out.vertices.emplace_back(elem_offset + pos);
- }
- for (auto idx : out_idx) {
- out.indices.emplace_back(idx_offset + idx);
- }
+void Shape::Outline(OutlineMesh::Buffer &out) const {
+ out.vertices.insert(out.vertices.end(), out_pos.begin(), out_pos.end());
+ out.indices.insert(out.indices.end(), out_idx.begin(), out_idx.end());
}
void Shape::SetShape(
- const EntityModel::Positions &pos,
- const EntityModel::Normals &nrm,
- const EntityModel::Indices &idx
+ const EntityMesh::Positions &pos,
+ const EntityMesh::Normals &nrm,
+ const EntityMesh::Indices &idx
) {
vtx_pos = pos;
vtx_nrm = nrm;
}
void Shape::SetTexture(
- const BlockModel::TexCoords &tex_coords
+ const BlockMesh::TexCoords &tex_coords
) {
vtx_tex_coords = tex_coords;
}
void Shape::SetOutline(
- const OutlineModel::Positions &pos,
- const OutlineModel::Indices &idx
+ const OutlineMesh::Positions &pos,
+ const OutlineMesh::Indices &idx
) {
out_pos = pos;
out_idx = idx;
8, 9, 9, 11, 11, 10, 10 , 8, // top
0, 8, 4, 10, 2, 6, // verticals, btf
1, 9, 5, 11, 3, 7,
- // 5, 8, 7, 10,
- // 1, 9, 3, 11,
});
}
const glm::mat4 &M,
const AABB &box,
const glm::mat4 &box_M,
- float &depth,
+ float &dist,
glm::vec3 &normal
) const noexcept {
- // TODO: this is wrong, but simple. so for now will have to do
- return Intersection(bot, M, box, box_M, depth, normal) || Intersection(top, M, box, box_M, depth, normal);
+ bool top_hit, bot_hit;
+ float top_dist, bot_dist;
+ glm::vec3 top_normal, bot_normal;
+
+ top_hit = Intersection(bot, M, box, box_M, top_dist, top_normal);
+ bot_hit = Intersection(top, M, box, box_M, bot_dist, bot_normal);
+
+ if (top_hit) {
+ if (bot_hit && bot_dist < top_dist) {
+ dist = bot_dist;
+ normal = bot_normal;
+ return true;
+ } else {
+ dist = top_dist;
+ normal = top_normal;
+ return true;
+ }
+ return true;
+ } else if (bot_hit) {
+ dist = bot_dist;
+ normal = bot_normal;
+ return true;
+ } else {
+ return false;
+ }
}
}