Please support our sponsor:
DirectX4VB.Com - All You Need For Multimedia Visual Basic Programming

Main Site Links Resources Tutorials
News VB Gaming Code Downloads DirectX 7
Contact Webmaster VB Programming Product Reviews DirectX 8
  General Multimedia Articles DirectX 9
      Miscellaneous

 

Immediate Mode: Camera Setup
By: Jack Hoxley
Written: August 2000

Download: IM_Camera.Zip (14kb)


Moving the camera - essential and easy; but it still confuses some of you....

Moving the camera is very simple as long as you can get the hang of where it is, and where it's looking at. You'll use vectors to define a point in 3D space that represents the source of the camera, and a second point to define where it is looking at.

The code for this looks like:

'The Basic Variables
Dim vFrom As D3DVECTOR, vTo As D3DVECTOR, vUp As D3DVECTOR, matView As D3DMATRIX
dx.IdentityMatrix matView 'Initialise our Matrix

'This is where you are looking at..

vTo.X = 0
vTo.y = 0
vTo.z = 0

'This is where the player is sitting (or standing)
vFrom.X = vTo.X - 5: vFrom.y = 4: vFrom.z = vTo.z - 5
'This defines what direction up is - in this case [0,1,0] is up in the real world
vUp.X = 0: vUp.y = 1: vUp.z = 0

'Get DirectX to generate a matrix for us
Call dx.ViewMatrix(matView, vFrom, vTo, vUp, 0)

'Apply the camera changes to the world-view....
Device.SetTransform D3DTRANSFORMSTATE_VIEW, matView

Simple as that. If you were to use this code, the camera would look at [0,0,0] from a little up and diagonally across...

This is so simple there is no proper download - but there is a modified version of the character movement demo where the character follows the player... You can grab it from the top of the page, or from the downloads page...

DirectX 4 VB © 2000 Jack Hoxley. All rights reserved.
Reproduction of this site and it's contents, in whole or in part, is prohibited,
except where explicitly stated otherwise.
Design by Mateo
Contact Webmaster
This site is hosted by Exhedra Solutions, Inc., the parent company of RentACoder.com and PlanetSourceCode.com