Class Projection
- java.lang.Object
-
- renderer.pipeline.Projection
-
public final class Projection extends Object
Project eachVertexof aModelfrom camera coordinates to theCamera's image planez = -1.Let us derive the formulas for the perspective projection transformation (the formulas for the parallel projection transformation are pretty obvious). We will derive the x-coordinate formula; the y-coordinate formula is similar.
Let
(x_c, y_c, z_c)denote a point in the 3-dimensional camera coordinate system. Let(x_p, y_p, -1)denote the point's perspective projection into the image plane,z = -1. Here is a "picture" of just the xz-plane from camera space. This picture shows the point(x_c, z_c)and its projection to the point(x_p, -1)in the image plane.x | / | / x_c + + (x_c, z_c) | / | | / | | / | | / | | / | | / | x_p + + | | / | | | / | | | / | | | / | | | / | | +-----------+-------------+------------> -z (0,0) -1 z_cWe are looking for a formula that computes
x_pin terms ofx_candz_c. There are two similar triangles in this picture that share a vertex at the origin. Using the properties of similar triangles we have the following ratios. (Remember that these are ratios of positive lengths, so we write-z_c, sincez_cis on the negative z-axis).x_p x_c ----- = ----- 1 -z_cIf we solve this ratio for the unknown,
x_p, we get the projection formula,x_p = -x_c / z_c.The equivalent formula for the y-coordinate is
y_p = -y_c / z_c.