|
|||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||
|
Announcements
Chapters
Services
Feature Zones
|
Note: This is an unedited contribution. If this article is inappropriate,
needs attention or copies someone else's work without reference then please
Report This Article
Rotating Terrain with Basic Matrices InputNow, we will learn to perform basic input commands on our sample so that we can traverse the island from a "god" camera. Short & SweetAs we learnt a lot about matrices in the earlier tutorials, we can now add input relatively painlessly. public const float rotateSpeed = 2;
public float Zoom = 0.0f;
public float Alpha = 0;
public float Beta = 0;
public float Charlie = 10;
The first one of these is a modifier which will define how fast we rotate / zoom our terrain. As this is a sample as opposed to a game, we do not need to time it as nothing needs to be balanced. However, it is nice to have a simple member to change to modify the speed. device.Transform.View = Matrix.LookAtLH ( new Vector3 ( 0, Zoom, 150 ), new Vector3 ( 0, -5, 0 ), new Vector3 ( 0, 1, 0 ) ); device.Transform.World = Matrix.Translation ( -256 / 2, -256/ 2, 0 )* Matrix.RotationX ( Alpha ) * Matrix.RotationY ( Beta ) * Matrix.RotationZ ( Charlie ); As you can see, we change the View (camera position)'s Y axis (for different results, try moving the Zoom member to affect different axis). private void Form1_KeyDown ( object sender, KeyEventArgs e )
{
switch (e.KeyData)
{
case Keys.A:
{
Charlie += 0.01f * rotateSpeed;
} break;
case Keys.D:
{
Charlie -= 0.01f * rotateSpeed;
} break;
case Keys.W:
{
Alpha += 0.01f * rotateSpeed;
} break;
case Keys.S:
{
Alpha -= 0.01f * rotateSpeed;
} break;
case Keys.Left:
{
Beta += 0.01f * rotateSpeed;
} break;
case Keys.Right:
{
Beta -= 0.01f * rotateSpeed;
} break;
case Keys.Up:
{
Zoom += 1f * rotateSpeed;
} break;
case Keys.Down:
{
Zoom -= 1f * rotateSpeed;
} break;
}
} DONT FORGET TO WIRE THE EVENT HANDLER IN THE FORMS CONSTRUCTOR:
FeedbackI am always open for answering questions, whether through MSN (jamespraveen@aol.com), email (james@magclan.cwhnetworks.com) or through the message board attatched to this article. History26/05/06: Posted on CodeProject
Previous ArticlesPart 1: Setting Up DirectX
|
||||||||||||||||||||||||||||||||||||||||