Sunday, August 17, 2014

Homemade 3D rendering engine (III)

We starts by describing the camera. A typical way of defining the camera is to define where the center of the camera is, as well as which direction is pointing upwards. With that information, we can easy compute the surface normal of the camera as $ \vec{E_z} = (-c_x, -c_y, -c_z)^T $, that will be the z-axis of the camera coordinate system. Next, we compute $ \vec{E_x} = (\vec{E_z} \times \vec{Up}) $, that gives the x-axis of the camera coordinate system, finally, we compute $ \vec{E_y} = (\vec{E_z} \times \vec{E_x}) $ to be our y axis, and we are done with specifying the camera coordinate system. Of course, these vectors need to be normalized to be an orthonormal basis.

Remember the point of defining the camera is about defining the camera coordinate system. We could have use any other ways to describe the camera, this is merely a conventional way of doing this.


Suppose we wanted to look at the model from (500, 500, 500), and the upwards direction as (0, 0, 1), we can compute EZ = (-500, -500, -500), EX = (-500, 500, 0) and EY = (-250000.0, -250000.0, 500000). 

No comments :

Post a Comment