Game Development Reference
InDepth Information
Figure 1.8 Perspective transform.
(
Px

Cx
)/(
Pz

Cz
)=(
P
x

Cx
)/
d
(
Py

Cy
)/(
Pz

Cz
)=(
P
y

Cy
)/
d
which can be rearranged to become
P
x
=((
Px

Cx
)
*
d
)/(
Pz

Cz
) +
Cx
P
y
=((
Py

Cy
)
*
d
)/(
Pz

Cz
) +
Cy
The value for
d
, the distance from the camera to the screen, should be of
the order of twice the pixel width of the 3D display window to avoid serious
distortion.
The above equations assume that the centre of the display window is
(0, 0) and that
y
values increase going up the screen. If (0, 0) for the
display window is actually in the top left corner, then the
y
values should
be subtracted from the height of the display window and half the width and
height if the display is added to the result.
sx
=((
Px

Cx
)
*
d
)/(
Pz

Cz
) +
Cx
+ screen width/2
sy
= screen height/2  (((
Py

Cy
)
*
d
)/(
Pz

Cz
) +
Cy
)
Using 4
×
4 matrix representations
Although rotation and scaling of an object can be achieved using 3
3
matrices, translation cannot be included. To get around this problem it is
usual to add a row and column to the matrix. We move from
×
Search Nedrilad ::
Custom Search