Original Post
I am implementing a virtual sphere for controlling a globe w/ a perspective camera. I am using the following function to project a 2d mouse point onto the surface of the sphere. This function assumes an orthogonal projection. Does anybody know how to modify this function to work with a perspective projection? private void pointOnUnitSphere(Point3d p, Vector3d v) { double vx = (p.getX() - this.center.getX()) / this.radius; double vy = (p.getY() - this.center.getY()) / this.radius; double lengthSquared = vx * vx + vy * vy; // Project the point onto the sphere, assuming orthognal projection. // Points beyond the virtual sphere are normalized onto edge of the sphere (where z = 0) double vz = 0.0; if (lengthSquared < 1.0) vz = Math.sqrt(1.0 - lengthSquared); else { // past the edge of the sphere. Normalize onto edge of // the sphere double length = Math.sqrt(lengthSquared); vx /= length; vy /= length; } v.setVector(vx, vy, vz); }