Advertisement

Direct 3DIM Camera Transform also Lightmaps

Started by February 07, 2000 10:49 PM
4 comments, last by nes8bit 25 years, 1 month ago
Does anyone know a better way of transforming the View matrix other than dx.ViewMatrix? I am trying to make my code act like a 3d shooter. I did get the x and z coordinantes properly rotate arround the camera using sin() and cos(), but I cannot get the z to work when I add the y coord. I tried Rotate?Matrix, but it rotated the view matrix arround the axis instead of the current point. Also, does anyone know how to make dynamic light maps and keep the rendering fast. I also have the problem with memmory usage. I am using Single-Pass multitexturing. I have been to flipcode and saw the light map doc, but it was too basic
The Viewmatrix is the best way to place your camera transforms. You need to follow these steps to produce a
view matrix.

1. Translate world to camera, i.e. -camera.pos
2. Roll world, rotate Z with -camera.roll
3. Pitch world, rotote X with -camera.pitch
4. Turn world, rotate Y with -camera.yaw

These four matrices are concatenated and put in the Viewmatrix.

Also you take a look at the function that is implemented in D3DUtil of D3DIM Framework:

HRESULT D3DUtil_SetViewMatrix( D3DMATRIX &mat, D3DVECTOR &vFrom, D3DVECTOR &vAt, D3DVECTOR &vWorldUp )

This function creates a viewmatrix from three vectors. From is where your camera is, At is what your camera is looking at, WorldUp is the direction of your camera up vector in world coordinates.
Advertisement
For some nice lightmap docs, check out...
http://www.gamedeveloper.org/delphi3d

Make sure to check the radiosity tutorial, it''s also on
lightmaps.

Greets Tobias
1. Translate world to camera, i.e. -camera.pos
2. Roll world, rotate Z with -camera.roll
3. Pitch world, rotote X with -camera.pitch
4. Turn world, rotate Y with -camera.yaw

Is this code with the D3DX util? I cannot use the D3DX util because I am writing in Visual Basic. I did that, but when I rotate the camera, it rotates arround the axis and not the current point.

HRESULT D3DUtil_SetViewMatrix( D3DMATRIX &mat, D3DVECTOR &vFrom, D3DVECTOR &vAt, D3DVECTOR &vWorldUp )

This function does exist in the Visual Basic version, but it is a pain in the a$$. I was trying to avoid this function because when you have to create a sphere arround the camera, but I was only able to create a circle arround the camera. It would look something like this

Call DX.ViewMatrix(ViewMatrix, Position, MakeVector(CircleX(Angle), 0, CircleY(Angle)), MakeVector(0, 1, 0))

Do you see the circle? Do you see my problem?
You need to make the call like this:

Call DX.ViewMatrix(ViewMatrix, Position, Position + MakeVector(cos(pitch)*cos(yaw), sin(pitch), cos(pitch)*sin(yaw)), MakeVector(0, 1, 0))

The third argument is point in world coordinates that the camera is facing, which is why it gets wrong if you only specify MakeVector(CircleX(Angle), 0, CircleY(Angle)), where the focus of the camera circles around the world origo.

If you don't want to use this function you need to create the viewmatrix yourself, and then send that to DX.

Some pseudo code:

Mtx = TranslateMatrix(-CameraPos);
Mtx = Mtx * RotateZMatrix(-CameraRoll);
Mtx = Mtx * RotateXMatrix(-CameraPitch);
Mtx = Mtx * RotateYMatrix(-CameraYaw);
SetViewMatrix(Mtx);

Hope that clears things up for you =)


Edited by - Spellbound on 2/10/00 9:48:33 AM
Well, I finally got the stupid thing working and here is the code. Thanks.

dx.IdentityMatrix TempTranMatrix
dx.IdentityMatrix TempRotYMatrix
dx.IdentityMatrix TempRotXMatrix

TempTranMatrix.rc41 = Position.X
TempTranMatrix.rc42 = Position.Y
TempTranMatrix.rc43 = Position.Z

dx.RotateXMatrix TempRotXMatrix, AngleY / 90
dx.RotateYMatrix TempRotYMatrix, AngleX / 90
dx.MatrixMultiply TempDestMatrix, TempRotYMatrix, TempRotXMatrix
dx.MatrixMultiply TempDestMatrix, TempTranMatrix, TempDestMatrix

Direct3DDevice.SetTransform D3DTRANSFORMSTATE_VIEW, TempDestMatrix

This topic is closed to new replies.

Advertisement