Hi,
I have an issue when calculating the perspective view in my game. Most of the time it’s fine, but sometimes I end up with a very large x or y value (-ve or +ve) and due to the limitations of java it flips the coordinates and I end up with a line drawing in the wrong direction.
What I would like to calculate (as part of my screen projection method) is if the point is outside the screen (lets say 600,800) I’d like to calculate the point on edge of the screen, so that the points are always between zero and the max dimension of the screen.
I thought about trying to calculate the line intersection depending which quadrant it is, but this seems messy. Is there a better way to do this?
Here’s my code for reference:
public Point getScreenProjection(Coordinates a)
{
double f = (viewPoint.z - screenPlane.z) / (viewPoint.z - a.z);
Point p = new Point();
p.x = (int)(a.x * f + dimensions.x * .5);
p.y = (int)(dimensions.y * .5 - a.y * f) + (int)(m_yoffset);
return p;
}
The point ‘dimensions’ is the dimension of the screen view (ie 600,800).