Added PickVertSW to offer an alternative for selection for hw that does not support opengl selection
This commit is contained in:
parent
b87832a022
commit
adfa6dde12
|
@ -60,6 +60,54 @@ public:
|
||||||
fi=NULL;
|
fi=NULL;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static Point3f Proj(const Eigen::Matrix4f &M, const float * viewport, Point3f &p)
|
||||||
|
{
|
||||||
|
const float vx=viewport[0];
|
||||||
|
const float vy=viewport[1];
|
||||||
|
const float vw2=viewport[2]/2.0f;
|
||||||
|
const float vh2=viewport[3]/2.0f;
|
||||||
|
Eigen::Vector4f vp(p[0],p[1],p[2],1.0f);
|
||||||
|
Eigen::Vector4f vpp = M*vp;
|
||||||
|
Eigen::Vector4f ndc = vpp/vpp[3];
|
||||||
|
|
||||||
|
Point3f sc(
|
||||||
|
vw2*ndc[0] + vx+vw2,
|
||||||
|
vh2*ndc[1] + vy+vh2,
|
||||||
|
ndc[2]
|
||||||
|
);
|
||||||
|
|
||||||
|
return sc;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int PickVertSW(int x, int y, MESH_TYPE &m, std::vector<VertexPointer> &result, int width=4, int height=4,bool sorted=true)
|
||||||
|
{
|
||||||
|
result.clear();
|
||||||
|
Eigen::Matrix4d mp,mm;
|
||||||
|
Eigen::Matrix4f M;
|
||||||
|
GLint viewport[4];
|
||||||
|
Box2f reg;
|
||||||
|
reg.Add(Point2f(x-width/2.0f,y-height/2.0f));
|
||||||
|
reg.Add(Point2f(x+width/2.0f,y+height/2.0f));
|
||||||
|
glGetIntegerv(GL_VIEWPORT,viewport);
|
||||||
|
float viewportF[4];
|
||||||
|
for(int i=0;i<4;++i) viewportF[i]=viewport[i];
|
||||||
|
|
||||||
|
glGetDoublev(GL_PROJECTION_MATRIX ,mp.data());
|
||||||
|
glGetDoublev(GL_MODELVIEW_MATRIX,mm.data());
|
||||||
|
M = (mp*mm).cast<float>();
|
||||||
|
for(VertexIterator vi=m.vert.begin();vi!=m.vert.end();++vi)if(!vi->IsD())
|
||||||
|
{
|
||||||
|
Point3f pp = Proj(M,viewportF,vi->P());
|
||||||
|
if(pp[0]<reg.min[0]) continue;
|
||||||
|
if(pp[0]>reg.max[0]) continue;
|
||||||
|
if(pp[1]<reg.min[1]) continue;
|
||||||
|
if(pp[1]>reg.max[1]) continue;
|
||||||
|
result.push_back(&*vi);
|
||||||
|
}
|
||||||
|
return result.size();
|
||||||
|
}
|
||||||
|
|
||||||
static int PickVert(int x, int y, MESH_TYPE &m, std::vector<VertexPointer> &result, int width=4, int height=4,bool sorted=true)
|
static int PickVert(int x, int y, MESH_TYPE &m, std::vector<VertexPointer> &result, int width=4, int height=4,bool sorted=true)
|
||||||
{
|
{
|
||||||
result.clear();
|
result.clear();
|
||||||
|
|
Loading…
Reference in New Issue