Creating an Interactive 3D world with C# and DirectX
3. Set Camera
In the Form1 class, you declare and initialize some variables to set up the camera position and then move it through the scene as follows:
//Declaring variables for camera movement float sngPositionX; float sngPositionY; float sngPositionZ; float snglookatX; float snglookatY; float snglookatZ; float sngAngleX; float sngAngleY;
Now, coming back to the Form1_Load event, you set the position of the camera:
//Set the view to perspective TVScene.SetViewFrustum(45.0f,1000.0f);
The arguments for the above function are:
| sAngleFOV | Angle in degrees representing the FOV (Field of vision) of the view. |
| sFarPlane | Maximum distance of vision. Everything after this imaginary far plane will be not rendered. |
//set our camera location and lookat point, etc. sngPositionX = 0.0f; sngPositionY = 0.3f; sngPositionZ = 0.0f; snglookatX = 0.0f; snglookatY = 0.0f; snglookatZ = 0.0f; sngAngleY = -1.57f;
With SetCamera, you can't define a camera with a totally vertical orientation. To do this, you have to use the RotateX method or use special matrices. SetCamera also can be used with a trigonometry equation to get a fully working camera system.
TVScene.SetCamera(xpos As Single, ypos As Single,
zpos As Single, xlookat As Single,
ylookat As Single, zlookat As Single)
| xpos | X coordinate of the camera position |
| ypos | Y coordinate of the camera position (altitude) |
| zpos | Z coordinate of the camera position |
| xlookat | X coordinate of the camera look at point |
| ylookat | Y coordinate of the camera look at point (altitude) |
| zlookat | Z coordinate of the camera look at point |
The behaviour is undefined if you use Position = LookAtPoint values.
//The camera is initially set to the origin (0, 0, 0) values
TVScene.SetCamera(sngPositionX, sngPositionY, ngPositionZ, snglookatX,
snglookatY, snglookatZ);

Figure 9: Setting camera position and look at position
0 Comments (click to add your comment)
Networking Solutions



Solid state disks (SSDs) made a splash in consumer technology, and now the technology has its eyes on the enterprise storage market. Download this eBook to see what SSDs can do for your infrastructure and review the pros and cons of this potentially game-changing storage technology.