Bug fixing in the PickFace function

Bug fixing in the projection of the vertices near to the plane of the
projection point
This commit is contained in:
Gianpaolo Palma 2017-03-27 11:13:14 +02:00
parent 8efebae360
commit a34532abac
1 changed files with 22 additions and 20 deletions

View File

@ -28,6 +28,7 @@
#include <algorithm> #include <algorithm>
#include "gl_type_name.h" #include "gl_type_name.h"
namespace vcg{ namespace vcg{
template <class MESH_TYPE> template <class MESH_TYPE>
@ -169,23 +170,24 @@ public:
return result.size(); return result.size();
} }
static int PickFace(int x, int y, MESH_TYPE &m, std::vector<FacePointer> &result, int width=4, int height=4) static int PickFace(int x, int y, MESH_TYPE &m, std::vector<FacePointer> &result, int width = 4, int height = 4)
{ {
static Eigen::Matrix<ScalarType,4,4> lastM; static Eigen::Matrix<ScalarType, 4, 4> lastM;
static MESH_TYPE *lastm=0; static MESH_TYPE *lastm = 0;
static std::vector<CoordType> pVec; static std::vector<CoordType> pVec;
ScalarType viewportF[4]; ScalarType viewportF[4];
Eigen::Matrix<ScalarType,4,4> M; Eigen::Matrix<ScalarType, 4, 4> M;
glGetMatrixAndViewport(M,viewportF); glGetMatrixAndViewport(M, viewportF);
result.clear(); result.clear();
Box3<ScalarType> reg; Box3<ScalarType> reg;
reg.Add(CoordType(x-width/ScalarType(2.0),y-height/ScalarType(2.0),ScalarType(-1.0))); reg.Add(CoordType(x - width / ScalarType(2.0), y - height / ScalarType(2.0), ScalarType(-1.0)));
reg.Add(CoordType(x+width/ScalarType(2.0),y+height/ScalarType(2.0),ScalarType(1.0))); reg.Add(CoordType(x + width / ScalarType(2.0), y + height / ScalarType(2.0), ScalarType(1.0)));
if((M!=lastM) || (&m != lastm) || (pVec.size() != m.VN()))
if ((M != lastM) || (&m != lastm) || (pVec.size() != m.VN()))
{ {
FillProjectedVector(m,pVec,M,viewportF); FillProjectedVector(m, pVec, M, viewportF);
lastM = M; lastM = M;
lastm = &m; lastm = &m;
} }
@ -197,7 +199,7 @@ public:
const CoordType &p0 = pVec[tri::Index(m, m.face[i].V(0))]; const CoordType &p0 = pVec[tri::Index(m, m.face[i].V(0))];
const CoordType &p1 = pVec[tri::Index(m, m.face[i].V(1))]; const CoordType &p1 = pVec[tri::Index(m, m.face[i].V(1))];
const CoordType &p2 = pVec[tri::Index(m, m.face[i].V(2))]; const CoordType &p2 = pVec[tri::Index(m, m.face[i].V(2))];
if ((p0[2] > -1.0f) && (p1[2] > -1.0f) && (p2[2] > -1.0f) && IntersectionTriangleBox(reg, p0, p1, p2))
result.push_back(&m.face[i]); result.push_back(&m.face[i]);
} }
} }