Sunday, August 17, 2014

Homemade 3D rendering engine (II)

The key to 3D rendering is about being able to describe what we wanted to render in 3D coordinates and draw them on screen. That involves a mapping from the 3D coordinates (on the world) to the 2D coordinate (on the screen). In this entry we give an overview on how that can be done.

First, it is easy to describe a 3D coordinate system, to be consistent with the literature, I will use a right-handed coordinate system, meaning the z-axis is x-axis cross y-axis. With a 3D coordinate system, we can describe the model in that coordinate system.

Second, we need to specify how the projection is done. This is key to the construction of the mapping. Imagine a camera is placed in the world. The camera is simply a rectangle that represent the screen. Imagine a ray is shoot orthogonal to the camera rectangle to the model. That is what we will be drawing on the screen. For simplicity, we assume the camera is outside of the model to be rendered, and it is assumed to be able to see the whole model through the camera.

Third, we imagine another coordinate system is defined at the center of the camera. The camera rectangle provides us with that coordinate system.

Last but not least, we transform the world coordinates to the camera coordinate, and then drop the z-axis information, that will be our projection.


In the next entries, we will describe in details how that can be done.

No comments :

Post a Comment