Marquee tool and projection

Have jReality programming problems or questions? Post them here.
Post Reply
sechel
Posts: 69
Joined: Tue 2. Oct 2007, 09:20

Marquee tool and projection

Post by sechel » Wed 11. Aug 2010, 17:27

Hi,
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);
And then something like

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);
	}
I get convincing results as long as I do not tilt the object to much. I expect the projection matrix to be incorrect.
Image
Anybody?

User avatar
steffen
Posts: 186
Joined: Fri 16. Jun 2006, 13:30
Location: TU Berlin
Contact:

Re: Marquee tool and projection

Post by steffen » Thu 12. Aug 2010, 07:02

My guess is that you need to invert the matrix C with the camera path - this maps camera coordinates to world coordinates, but you want to map world coordinates into the Camera coordinate system. Maybe it is the other way round, but definitely one of the matrices needs to be inverted.

Steffen.

sechel
Posts: 69
Joined: Tue 2. Oct 2007, 09:20

Re: Marquee tool and projection

Post by sechel » Thu 12. Aug 2010, 08:25

Works!
Image

Post Reply