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;
mesh_t buildMesh(const vector<vector<glm::vec3>> &faces)
mesh_t buildMesh(const vector<vector<qvec3f>> &faces)
{
// FIXME: this is ugly
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
vector<glm::vec3> vertsVec;
vector<qvec3f> vertsVec;
vertsVec.resize(posToVertIndex.size());
for (const auto &posIndex : posToVertIndex) {
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;
@ -68,13 +68,13 @@ mesh_t buildMesh(const vector<vector<glm::vec3>> &faces)
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) {
std::vector<glm::vec3> points;
std::vector<qvec3f> points;
for (int vertIndex : meshFace) {
const glm::vec3 point = mesh.verts.at(vertIndex);
const qvec3f point = mesh.verts.at(vertIndex);
points.push_back(point);
}
res.push_back(points);

View File

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

View File

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