Game Development Reference
In-Depth Information
Note
You may have noticed that we didn't create our DataStream object in a using
block this time. The reason is that we continue to use it throughout the life of the
program, so we can't dispose of it here, or else the demo would crash!
The next set of code does the same thing, but for the view matrix, sending it into
the m_CbChangesPerFrame constant buffer. And lastly, the final three lines in this
method tell the vertex shader to use our three new constant buffers. As you can see,
we put each constant buffer in its own slot; hence, the second parameter increments
by one in each line. This parameter specifies which slot to set the constant buffer to.
We are now ready to initialize our scene and create our cube!
Initializing the scene
A lot of the code for this method is the same as before, so we won't show it all here.
At the top of this method, we add some new code to initialize the projection and view
matrices:
// Create our projection matrix.
m_ProjectionMatrix =
Matrix.PerspectiveFovLH(1.570796f, // 90
degrees in radians(float) m_Form.Width /
(float) m_Form.Height,0.5f,1000.0f);
// Create our view matrix.
m_ViewMatrix =
Matrix.LookAtLH(m_CameraPosition,new Vector3(0,
0, 0),new Vector3(0, 1, 0));
The first line creates the projection matrix. The projection matrix is analogous to
choosing a type of lens for the camera. The four parameters we pass into the Mat-
rix.PerspectiveFovLH() method set the vertical field of view, the aspect ra-
tio, and the near clipping plane and far clipping plane distances. The Fov part
Search WWH ::




Custom Search