common: change mesh_t to use qvec3f

This commit is contained in:
Eric Wasylishen 2017-04-22 20:39:50 -06:00
parent 4996796944
commit b8f5a4f8e1
3 changed files with 18 additions and 18 deletions

View File

@ -25,7 +25,7 @@
using namespace std; using namespace std;
mesh_t buildMesh(const vector<vector<glm::vec3>> &faces) mesh_t buildMesh(const vector<vector<qvec3f>> &faces)
{ {
// FIXME: this is ugly // FIXME: this is ugly
using pos_t = tuple<float, float, float>; using pos_t = tuple<float, float, float>;
@ -55,11 +55,11 @@ mesh_t buildMesh(const vector<vector<glm::vec3>> &faces)
} }
// convert posToVertIndex to a vector // convert posToVertIndex to a vector
vector<glm::vec3> vertsVec; vector<qvec3f> vertsVec;
vertsVec.resize(posToVertIndex.size()); vertsVec.resize(posToVertIndex.size());
for (const auto &posIndex : posToVertIndex) { for (const auto &posIndex : posToVertIndex) {
const pos_t &pos = posIndex.first; const pos_t &pos = posIndex.first;
vertsVec.at(posIndex.second) = glm::vec3(std::get<0>(pos), std::get<1>(pos), std::get<2>(pos)); vertsVec.at(posIndex.second) = qvec3f(std::get<0>(pos), std::get<1>(pos), std::get<2>(pos));
} }
mesh_t res; mesh_t res;
@ -68,13 +68,13 @@ mesh_t buildMesh(const vector<vector<glm::vec3>> &faces)
return res; return res;
} }
std::vector<std::vector<glm::vec3>> meshToFaces(const mesh_t &mesh) std::vector<std::vector<qvec3f>> meshToFaces(const mesh_t &mesh)
{ {
std::vector<std::vector<glm::vec3>> res; std::vector<std::vector<qvec3f>> res;
for (const auto &meshFace : mesh.faces) { for (const auto &meshFace : mesh.faces) {
std::vector<glm::vec3> points; std::vector<qvec3f> points;
for (int vertIndex : meshFace) { for (int vertIndex : meshFace) {
const glm::vec3 point = mesh.verts.at(vertIndex); const qvec3f point = mesh.verts.at(vertIndex);
points.push_back(point); points.push_back(point);
} }
res.push_back(points); res.push_back(points);

View File

@ -21,17 +21,17 @@
#define __COMMON_MESH_HH__ #define __COMMON_MESH_HH__
#include <vector> #include <vector>
#include <glm/glm.hpp> // FIXME: switch to qvec #include <common/qvec.hh>
class mesh_t { class mesh_t {
public: public:
std::vector<glm::vec3> verts; std::vector<qvec3f> verts;
std::vector<std::vector<int>> faces; std::vector<std::vector<int>> faces;
}; };
// Welds vertices at exactly the same position // Welds vertices at exactly the same position
mesh_t buildMesh(const std::vector<std::vector<glm::vec3>> &faces); mesh_t buildMesh(const std::vector<std::vector<qvec3f>> &faces);
std::vector<std::vector<glm::vec3>> meshToFaces(const mesh_t &mesh); std::vector<std::vector<qvec3f>> meshToFaces(const mesh_t &mesh);
// Preserves the number and order of faces. // Preserves the number and order of faces.
// doesn't merge verts. // doesn't merge verts.

View File

@ -530,19 +530,19 @@ TEST(mathlib, FractionOfLine) {
// mesh_t // mesh_t
TEST(mathlib, meshCreate) { TEST(mathlib, meshCreate) {
const vector<vec3> poly1 { const vector<qvec3f> poly1 {
{ 0,0,0 }, { 0,0,0 },
{ 0,64,0 }, { 0,64,0 },
{ 64,64,0 }, { 64,64,0 },
{ 64,0,0 } { 64,0,0 }
}; };
const vector<vec3> poly2 { const vector<qvec3f> poly2 {
{ 64,0,0 }, { 64,0,0 },
{ 64,64,0 }, { 64,64,0 },
{ 128,64,0 }, { 128,64,0 },
{ 128,0,0 } { 128,0,0 }
}; };
const vector<vector<vec3>> polys { poly1, poly2 }; const vector<vector<qvec3f>> polys { poly1, poly2 };
const mesh_t m = buildMesh(polys); const mesh_t m = buildMesh(polys);
ASSERT_EQ(6, m.verts.size()); ASSERT_EQ(6, m.verts.size());
@ -564,26 +564,26 @@ TEST(mathlib, meshFixTJuncs) {
poly1 should get a vertex inserted at the + poly1 should get a vertex inserted at the +
*/ */
const vector<vec3> poly1 { const vector<qvec3f> poly1 {
{ 0,0,0 }, { 0,0,0 },
{ 0,64,0 }, { 0,64,0 },
{ 64,64,0 }, { 64,64,0 },
{ 64,0,0 } { 64,0,0 }
}; };
const vector<vec3> poly2 { const vector<qvec3f> poly2 {
{ 64,32,0 }, { 64,32,0 },
{ 64,64,0 }, { 64,64,0 },
{ 128,64,0 }, { 128,64,0 },
{ 128,32,0 } { 128,32,0 }
}; };
const vector<vec3> poly3 { const vector<qvec3f> poly3 {
{ 64,0,0 }, { 64,0,0 },
{ 64,32,0 }, { 64,32,0 },
{ 128,32,0 }, { 128,32,0 },
{ 128,0,0 } { 128,0,0 }
}; };
const vector<vector<vec3>> polys { poly1, poly2, poly3 }; const vector<vector<qvec3f>> polys { poly1, poly2, poly3 };
mesh_t m = buildMesh(polys); mesh_t m = buildMesh(polys);
ASSERT_EQ(8, m.verts.size()); ASSERT_EQ(8, m.verts.size());