Undoubtedly, the square to be rotated involves only the basic content in xNa. Now, the project is simply modified to make the displayed images more vivid and attractive.
PressCodeTo modify the code of the draw function, you will see a major change in the drawing on the screen.
Protected override void draw (gametime)
{
Graphicsdevice. Clear (color. cornflowerblue );
// Reset the world Matrix
_ Effect. World = matrix. identity;
// Loop for each square
For (INT I = 0; I <20; I ++)
{
Foreach (effectpass pass in _ effect. currenttechnique. Passes)
{
// Apply a further Rotation
_ Effect. World = matrix. createrotationz (_ angle) * _ effect. World;
// Scale the object so that it is shown slightly smaller
_ Effect. World = matrix. createscale (0.85f) * _ effect. World;
// Apply the pass
Pass. Apply ();
// Draw the square
Graphicsdevice. drawuserprimitives (primitivetype. trianglestrip, _ vertices, 0, 2 );
}
}
Base. Draw (gametime );
}
Unfortunately, the screen cannot reflect the real running effect of the project. Although the dynamic content must be much better than the static image, this method of using short code blocks to generate results is very good.
In the loop, 20 shapes are drawn, each of which is slightly smaller than the previous one and rotated to a different angle. The scaling and rotation operations are accumulative, which means that the first (largest) Square is rotated at the specified angle _ angle, then the second square is rotated twice the angle, and the third is rotated three times the angle, and so on.