namespace blank {
void Shape::Vertices(
- Model::Positions &vertex,
- Model::Normals &normal,
- Model::Indices &index
+ EntityModel::Buffer &out,
+ float tex_offset
) const {
for (const auto &pos : vtx_pos) {
- vertex.emplace_back(pos);
+ out.vertices.emplace_back(pos);
+ }
+ for (const auto &coord : vtx_tex_coords) {
+ out.tex_coords.emplace_back(coord.x, coord.y, coord.z + tex_offset);
}
for (const auto &nrm : vtx_nrm) {
- normal.emplace_back(nrm);
+ out.normals.emplace_back(nrm);
}
for (auto idx : vtx_idx) {
- index.emplace_back(idx);
+ out.indices.emplace_back(idx);
}
}
void Shape::Vertices(
- Model::Positions &vertex,
- Model::Normals &normal,
- Model::Indices &index,
+ EntityModel::Buffer &out,
const glm::mat4 &transform,
- Model::Index idx_offset
+ float tex_offset,
+ EntityModel::Index idx_offset
) const {
for (const auto &pos : vtx_pos) {
- vertex.emplace_back(transform * glm::vec4(pos, 1.0f));
+ out.vertices.emplace_back(transform * glm::vec4(pos, 1.0f));
+ }
+ for (const auto &coord : vtx_tex_coords) {
+ out.tex_coords.emplace_back(coord.x, coord.y, coord.z + tex_offset);
}
for (const auto &nrm : vtx_nrm) {
- normal.emplace_back(transform * glm::vec4(nrm, 0.0f));
+ out.normals.emplace_back(transform * glm::vec4(nrm, 0.0f));
}
for (auto idx : vtx_idx) {
- index.emplace_back(idx_offset + idx);
+ out.indices.emplace_back(idx_offset + idx);
}
}
void Shape::Vertices(
- BlockModel::Positions &vertex,
- BlockModel::Indices &index,
+ BlockModel::Buffer &out,
const glm::mat4 &transform,
+ float tex_offset,
BlockModel::Index idx_offset
) const {
for (const auto &pos : vtx_pos) {
- vertex.emplace_back(transform * glm::vec4(pos, 1.0f));
+ out.vertices.emplace_back(transform * glm::vec4(pos, 1.0f));
+ }
+ for (const auto &coord : vtx_tex_coords) {
+ out.tex_coords.emplace_back(coord.x, coord.y, coord.z + tex_offset);
}
for (auto idx : vtx_idx) {
- index.emplace_back(idx_offset + idx);
+ out.indices.emplace_back(idx_offset + idx);
}
}
void Shape::Outline(
- OutlineModel::Positions &vertex,
- OutlineModel::Indices &index,
+ OutlineModel::Buffer &out,
const OutlineModel::Position &elem_offset,
OutlineModel::Index idx_offset
) const {
for (const auto &pos : out_pos) {
- vertex.emplace_back(elem_offset + pos);
+ out.vertices.emplace_back(elem_offset + pos);
}
for (auto idx : out_idx) {
- index.emplace_back(idx_offset + idx);
+ out.indices.emplace_back(idx_offset + idx);
}
}
+void Shape::SetShape(
+ const EntityModel::Positions &pos,
+ const EntityModel::Normals &nrm,
+ const EntityModel::Indices &idx
+) {
+ vtx_pos = pos;
+ vtx_nrm = nrm;
+ vtx_idx = idx;
+}
+
+void Shape::SetTexture(
+ const BlockModel::TexCoords &tex_coords
+) {
+ vtx_tex_coords = tex_coords;
+}
+
+void Shape::SetOutline(
+ const OutlineModel::Positions &pos,
+ const OutlineModel::Indices &idx
+) {
+ out_pos = pos;
+ out_idx = idx;
+}
+
NullShape::NullShape()
: Shape() {
16, 17, 18, 18, 17, 19, // left
20, 21, 22, 22, 21, 23, // right
});
+ SetTexture({
+ { 0.0f, 1.0f, 0.0f }, // front
+ { 1.0f, 1.0f, 0.0f },
+ { 0.0f, 0.0f, 0.0f },
+ { 1.0f, 0.0f, 0.0f },
+ { 1.0f, 1.0f, 0.0f }, // back
+ { 1.0f, 0.0f, 0.0f },
+ { 0.0f, 1.0f, 0.0f },
+ { 0.0f, 0.0f, 0.0f },
+ { 0.0f, 0.0f, 0.0f }, // top
+ { 0.0f, 1.0f, 0.0f },
+ { 1.0f, 0.0f, 0.0f },
+ { 1.0f, 1.0f, 0.0f },
+ { 1.0f, 0.0f, 0.0f }, // bottom
+ { 0.0f, 0.0f, 0.0f },
+ { 1.0f, 1.0f, 0.0f },
+ { 0.0f, 1.0f, 0.0f },
+ { 0.0f, 1.0f, 0.0f }, // left
+ { 1.0f, 1.0f, 0.0f },
+ { 0.0f, 0.0f, 0.0f },
+ { 1.0f, 0.0f, 0.0f },
+ { 1.0f, 1.0f, 0.0f }, // right
+ { 1.0f, 0.0f, 0.0f },
+ { 0.0f, 1.0f, 0.0f },
+ { 0.0f, 0.0f, 0.0f },
+ });
SetOutline({
{ bb.min.x, bb.min.y, bb.min.z }, // back
{ bb.max.x, bb.min.y, bb.min.z },
32, 33, 34, 34, 33, 35, // right, upper
36, 37, 38, 38, 37, 39, // right, lower
});
+ SetTexture({
+ { 0.0f, 0.5f, 0.0f }, // front, upper
+ { 1.0f, 0.5f, 0.0f },
+ { 0.0f, 0.0f, 0.0f },
+ { 1.0f, 0.0f, 0.0f },
+ { 0.0f, 1.0f, 0.0f }, // front, lower
+ { 1.0f, 1.0f, 0.0f },
+ { 0.0f, 0.5f, 0.0f },
+ { 1.0f, 0.5f, 0.0f },
+ { 1.0f, 1.0f, 0.0f }, // back
+ { 1.0f, 0.0f, 0.0f },
+ { 0.0f, 1.0f, 0.0f },
+ { 0.0f, 0.0f, 0.0f },
+ { 0.0f, 0.0f, 0.0f }, // top, upper
+ { 0.0f, 0.5f, 0.0f },
+ { 1.0f, 0.0f, 0.0f },
+ { 1.0f, 0.5f, 0.0f },
+ { 0.0f, 0.5f, 0.0f }, // top, lower
+ { 0.0f, 1.0f, 0.0f },
+ { 1.0f, 0.5f, 0.0f },
+ { 1.0f, 1.0f, 0.0f },
+ { 1.0f, 0.0f, 0.0f }, // bottom
+ { 0.0f, 0.0f, 0.0f },
+ { 1.0f, 1.0f, 0.0f },
+ { 0.0f, 1.0f, 0.0f },
+ { 0.0f, 0.5f, 0.0f }, // left, upper
+ { 0.5f, 0.5f, 0.0f },
+ { 0.0f, 0.0f, 0.0f },
+ { 0.5f, 0.0f, 0.0f },
+ { 0.0f, 1.0f, 0.0f }, // left, lower
+ { 1.0f, 1.0f, 0.0f },
+ { 0.0f, 0.5f, 0.0f },
+ { 1.0f, 0.5f, 0.0f },
+ { 1.0f, 0.5f, 0.0f }, // right, upper
+ { 1.0f, 0.0f, 0.0f },
+ { 0.5f, 0.5f, 0.0f },
+ { 0.5f, 0.0f, 0.0f },
+ { 1.0f, 1.0f, 0.0f }, // right, lower
+ { 1.0f, 0.5f, 0.0f },
+ { 0.0f, 1.0f, 0.0f },
+ { 0.0f, 0.5f, 0.0f },
+ });
SetOutline({
{ bot.min.x, bot.min.y, bot.min.z }, // bottom
{ bot.max.x, bot.min.y, bot.min.z },
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;
+ }
}
}