tailieunhanh - Microsoft XNA Game Studio Creator’s Guide- P5

Microsoft XNA Game Studio Creator’s Guide- P5:The release of the XNA platform and specifically the ability for anyone to write Xbox 360 console games was truly a major progression in the game-programming world. Before XNA, it was simply too complicated and costly for a student, software hobbyist, or independent game developer to gain access to a decent development kit for a major console platform. | 98 MICROSOFT X N A GAME STUDIO CREATOR S GUIDE FIGURE 7-2 Earth and moon example The vertices for the earth and moon are set when the program begins so InitializeTriangle is called from the Initialize method InitializeTriangle When animating the triangle a time-scaled increment is made to the triangle s rotation during each Update . This rotation value is modded by 2n to clamp the value between 0 and 2n. earthRotation earthRotation earthRotation moonRotation float moonRotation moonRotation Here are the five recommended steps for drawing the revolving Earth object 1. Declare the matrices. 2. Initialize the matrices. The identity matrix is initialized as a default matrix in the event of no transformations. Try leaving it out of the transformation CHAPTER 7 and notice you still get the same result. A matrix that generates the earth s revolution on the Y axis is computed based on a constantly changing angle in radians . Every frame the angle is incremented with a value based on the time lapse between frames. This time-scaled increment to the rotation angle ensures that the animation appears smoothly while maintaining a constant rate of change. Scaling the increment based on time is necessary because durations between frames can vary depending on other tasks being performed by the operating system. Finally a translation is created to move the earth units upward on the Y axis and units inward on the Z axis. 3. The World matrix is built by multiplying each of the matrices in the transformation using the . sequence. 4. The World matrix used to transform the earth is passed to the shader as part of the World View Projection matrix. 5. The triangle is rendered by drawing vertices with a triangle strip. Adding DrawEarth to the game class provides the code needed for transforming and drawing the Earth private void DrawEarth 1 declare .