I'm trying to implement a marquee tool for the jtem halfedge tools. For this I have to transform the vertices according to the world and camera transforms and the camera projection. Here is the code I came up with:
Code: Select all
SceneGraphComponent root = view.getViewer().getSceneRoot();
SceneGraphPath hifPath = SceneGraphUtility.getPathsBetween(root, hif.getActiveComponent()).iterator().next();
SceneGraphPath camPath = view.getViewer().getCameraPath();
Matrix P = new Matrix(CameraUtility.getCameraToNDC(view.getViewer()));
Matrix C = new Matrix(camPath.getMatrix(null));
Matrix T = new Matrix(hifPath.getMatrix(null));
T.multiplyOnLeft(C);
Code: Select all
T.transformVector(homPos);
P.transformVector(homPos);
Pn.dehomogenize(homPos, homPos);
double xPos = -homPos[0] * size.width / 2;
double yPos = homPos[1] * size.height / 2;
if (xPos > xMin && xPos < xMax &&
yPos > yMin && yPos < yMax) {
sel.setSelected(v, true);
}
Anybody?