diff options
Diffstat (limited to 'src/o3d')
-rw-r--r-- | src/o3d/mesh.cpp | 44 | ||||
-rw-r--r-- | src/o3d/mesh.h | 3 | ||||
-rw-r--r-- | src/o3d/vertex_data.cpp | 24 | ||||
-rw-r--r-- | src/o3d/vertex_data.h | 8 |
4 files changed, 47 insertions, 32 deletions
diff --git a/src/o3d/mesh.cpp b/src/o3d/mesh.cpp index 47a1ea2..bf60cc8 100644 --- a/src/o3d/mesh.cpp +++ b/src/o3d/mesh.cpp @@ -6,25 +6,39 @@ using namespace engine::o3d; -Mesh Mesh::cube() { +// Mesh Mesh::cube() { +// return { +// { +// { engine::math::Vector3(-1.f, -1.f, -1.f), {} }, +// { engine::math::Vector3(+1.f, -1.f, -1.f), {} }, +// { engine::math::Vector3(-1.f, +1.f, -1.f), {} }, +// { engine::math::Vector3(+1.f, +1.f, -1.f), {} }, +// { engine::math::Vector3(-1.f, -1.f, +1.f), {} }, +// { engine::math::Vector3(+1.f, -1.f, +1.f), {} }, +// { engine::math::Vector3(-1.f, +1.f, +1.f), {} }, +// { engine::math::Vector3(+1.f, +1.f, +1.f), {} }, +// }, +// { +// { 0, 2, 3 }, { 0, 3, 1 }, // face 1 +// { 0, 4, 6 }, { 0, 6, 2 }, // face 2 +// { 0, 1, 5 }, { 0, 5, 4 }, // face 3 +// { 7, 6, 4 }, { 7, 4, 5 }, // face 4 +// { 7, 3, 2 }, { 7, 2, 6 }, // face 5 +// { 7, 5, 1 }, { 7, 1, 3 }, // face 6 +// } +// }; +// } + +Mesh Mesh::plane() { return { { - { engine::math::Vector3(-1.f, -1.f, -1.f), {} }, - { engine::math::Vector3(+1.f, -1.f, -1.f), {} }, - { engine::math::Vector3(-1.f, +1.f, -1.f), {} }, - { engine::math::Vector3(+1.f, +1.f, -1.f), {} }, - { engine::math::Vector3(-1.f, -1.f, +1.f), {} }, - { engine::math::Vector3(+1.f, -1.f, +1.f), {} }, - { engine::math::Vector3(-1.f, +1.f, +1.f), {} }, - { engine::math::Vector3(+1.f, +1.f, +1.f), {} }, + { engine::math::Vector3(-1.f, 0.f, -1.f), {0.f, 0.f} }, + { engine::math::Vector3(+1.f, 0.f, -1.f), {1.f, 0.f} }, + { engine::math::Vector3(+1.f, 0.f, +1.f), {1.f, 1.f} }, + { engine::math::Vector3(-1.f, 0.f, +1.f), {0.f, 1.f} }, }, { - { 0, 2, 3 }, { 0, 3, 1 }, // face 1 - { 0, 4, 6 }, { 0, 6, 2 }, // face 2 - { 0, 1, 5 }, { 0, 5, 4 }, // face 3 - { 7, 6, 4 }, { 7, 4, 5 }, // face 4 - { 7, 3, 2 }, { 7, 2, 6 }, // face 5 - { 7, 5, 1 }, { 7, 1, 3 }, // face 6 + { 0, 1, 2 }, { 2, 3, 0 }, } }; } diff --git a/src/o3d/mesh.h b/src/o3d/mesh.h index 579c8b2..34d1e09 100644 --- a/src/o3d/mesh.h +++ b/src/o3d/mesh.h @@ -10,7 +10,8 @@ namespace engine::o3d { class Mesh { public: - static Mesh cube(); // this function should not be in this file +// static Mesh cube(); // this function should not be in this file + static Mesh plane(); // this function should not be in this file std::vector<Vertex3> pts; std::vector<std::array<int, 3>> faces; diff --git a/src/o3d/vertex_data.cpp b/src/o3d/vertex_data.cpp index ea8c5fd..b05e382 100644 --- a/src/o3d/vertex_data.cpp +++ b/src/o3d/vertex_data.cpp @@ -2,21 +2,19 @@ using namespace engine::o3d; -VertexData VertexData::lerp(const VertexData& vd1, const VertexData& vd2, float s) { - (void) vd1; - (void) vd2; - (void) s; - return {}; +VertexData VertexData::lerp(const VertexData& vd1, const VertexData& vd2, float b0) { + return { + b0 * vd1.tx + (1.f - b0) * vd2.tx, + b0 * vd1.ty + (1.f - b0) * vd2.ty + }; } -VertexData VertexData::bilerp(const VertexData& vd1, const VertexData& vd2, const VertexData& vd3, float s, float t) { - (void) vd1; - (void) vd2; - (void) vd3; - (void) s; - (void) t; - return {}; +VertexData VertexData::bilerp(const VertexData& vd1, const VertexData& vd2, const VertexData& vd3, float b0, float b1) { + return { + b0 * vd1.tx + b1 * vd2.tx + (1.f - b0 - b1) * vd3.tx, + b0 * vd1.ty + b1 * vd2.ty + (1.f - b0 - b1) * vd3.ty + }; } -VertexData::VertexData() { +VertexData::VertexData(float tx, float ty) : tx{tx}, ty{ty} { } diff --git a/src/o3d/vertex_data.h b/src/o3d/vertex_data.h index ec5fa25..b8ed14c 100644 --- a/src/o3d/vertex_data.h +++ b/src/o3d/vertex_data.h @@ -5,10 +5,12 @@ namespace engine::o3d { class VertexData { public: - static VertexData lerp(const VertexData& vd1, const VertexData& vd2, float s); - static VertexData bilerp(const VertexData& vd1, const VertexData& vd2, const VertexData& vd3, float s, float t); + static VertexData lerp(const VertexData& vd1, const VertexData& vd2, float b0); + static VertexData bilerp(const VertexData& vd1, const VertexData& vd2, const VertexData& vd3, float b0, float b1); - VertexData(); + float tx, ty; + + VertexData(float tx, float ty); }; } |