public Vec2D getPointOnPlane(Vec2D mousePoint, Plane planeIn) {
Plane plane = new Plane(planeIn.copy(), planeIn.normal.copy());
Vec3D mouseRayPos = new Vec3D(mousePoint.x, mousePoint.y, planeIn.z); // this only works for planes perpendicular to the screen
Vec3D mouseRayDir = new Vec3D(0, 0, -1);
Vec3D focusCentre = new Vec3D(
((GLOBAL.windowWidth / 2) - (float)GLOBAL.CAM_OFFSET_X),
((GLOBAL.windowHeight / 2) - (float)GLOBAL.CAM_OFFSET_Y), 0);
//now mouse pos is refereced from the centre of the screen
mouseRayPos.x -= (GLOBAL.windowWidth / 2);
mouseRayPos.y -= (GLOBAL.windowHeight / 2);
mouseRayPos.scaleSelf((float) (1 / GLOBAL.getZOOM()));
mouseRayPos.addSelf(focusCentre);
Ray3D ray;
Vec3D mousePos = null;
Vec3D intersect;
mouseRayDir = new Vec3D(0, 0, -1);
plane.z = 0;
//we need to rotate the plane so that it matches the one on the draw view
plane.normal.rotateY(GLOBAL.rotateModelsY);
plane.normal.rotateX(GLOBAL.rotateModelsX);
plane.addSelf(plane.normal.scale(planeIn.z));
//mouseRayDir.rotateY(GLOBAL.rotateModelsY);
//mouseRayDir.rotateX(GLOBAL.rotateModelsX);
mouseRayPos.subSelf(focusCentre);
ray = new Ray3D(mouseRayPos, mouseRayDir); // this should be the world position of the mouse poiner on the 0,0,-1 plane
intersect = plane.getIntersectionWithRay(ray);
if (intersect == null) {
ray = new Ray3D(mouseRayPos, mouseRayDir.invert());
intersect = plane.getIntersectionWithRay(ray);
}
ray = new Ray3D(mouseRayPos, mouseRayDir);
ray.addSelf(focusCentre);
//if(this.mouseDown)
// GLOBAL.debugRay = ray;
if (intersect != null) {
// System.out.println(plane.getProjectedPoint(intersect));
// intersect.z -= plane.z*2;
//intersect.x += 70;
// System.out.println("before rotate " +intersect);
// intersect.subSelf(focusCentre.scale(GLOBAL.getZOOM()));
// intersect.
intersect.rotateX(-GLOBAL.rotateModelsX);
intersect.rotateY(-GLOBAL.rotateModelsY);
intersect.addSelf(focusCentre);
//intersect.x += (GLOBAL.CAM_OFFSET_X*GLOBAL.getZOOM());
//intersect.y += GLOBAL.CAM_OFFSET_Y;
//intersect.rotateAroundAxis(axis, theta)
mousePos = intersect;
//mousePos.x += intersect.z;
//System.out.println("after rotate " +intersect);
}
//get the chair matrix
Matrix4f chairMatrix = new Matrix4f();
Vec3D chairCentreOfMass = new Vec3D();
if (GLOBAL.sketchChairs.getCurChair() != null
&& GLOBAL.sketchChairs.getCurChair().rigidBody != null) {
Transform transform = new Transform();
GLOBAL.sketchChairs.getCurChair().rigidBody
.getWorldTransform(transform);