+ Improve mesh selection (precompute projection matrix and use polygon bounding box)
This commit is contained in:
@@ -51,6 +51,7 @@ Base::Vector3f ViewVolumeProjection::operator()(const Base::Vector3f &pt) const
|
||||
pt3d.setValue(ptt.x, ptt.y, ptt.z);
|
||||
}
|
||||
|
||||
// Calling this function is expensive as the complete projection matrix is recomputed on each step
|
||||
viewVolume.projectToScreen(pt3d,pt3d);
|
||||
return Base::Vector3f(pt3d[0],pt3d[1],pt3d[2]);
|
||||
}
|
||||
@@ -101,12 +102,26 @@ Base::Matrix4D ViewVolumeProjection::getProjectionMatrix () const
|
||||
// Inventor stores the transposed matrix
|
||||
Base::Matrix4D mat;
|
||||
SbMatrix affine, proj;
|
||||
|
||||
// The Inventor projection matrix is obtained by multiplying both matrices together (cf source)
|
||||
viewVolume.getMatrices(affine, proj);
|
||||
SbMatrix pmatrix = affine.multRight(proj);
|
||||
|
||||
for (int i=0; i<4; i++) {
|
||||
for (int j=0; j<4; j++)
|
||||
mat[i][j] = proj[j][i];
|
||||
mat[i][j] = pmatrix[j][i];
|
||||
}
|
||||
|
||||
// Compose the object transform, if defined
|
||||
if (hasTransform) {
|
||||
mat = mat * transform;
|
||||
}
|
||||
|
||||
// Scale from [-1,1] to [0,1]
|
||||
// As done in OpenInventor sources (see SbDPViewVolume::projectToScreen)
|
||||
mat.scale(0.5, 0.5, 0.5);
|
||||
mat.move(0.5, 0.5, 0.5);
|
||||
|
||||
return mat;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user