math - Projection- Transforming 3d to 2d -
i have problem or well, not know how transform 3d point x,y,z values 2d point, have draw projection, have x,y,z values points don't know how transform them 2d can move them onto axis.
i have been looking around wiki , google, howevever i'm not quite sure matrix transformations should use wanted result.
let's first assume camera looking @ scene centered @ origin, , looking @ -z
direction. then:
a perspective projection given by:
x' = x/z
y' = y/z
an orthographic projection given by:
x' = x
y' = y
(i.e., discard z component)
now have applied step above, might obtain point @ (x',y') = (-28.4, +134.5)
. need scale , center them based on screen resolution , camera "zoom factor" , aspect ratio : instance, might want multiply zoom
, add screen_center
both x
, y
components (beware: graphics rendering systems have y
direction pointing down, might need swap signs y
component). might still end pixels negative coordinates or coordinates greater canvas size. discard them : means outside of view frustum.
finally, might wonder if camera not pointing toward -z
or not centered @ origin. later, simple: subtract camera coordinates component of 3d points prior doing else. camera rotation, quite easy : need rotate points in inverse way camera rotated prior doing else well. means need multiply 3d coordinates transpose of camera rotation matrix. idea behind step moving camera around same moving points in reverse direction (and happen inverse of rotation matrix transpose of same matrix).
Comments
Post a Comment