return pickBuffer;
}
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);