Not logged in, Join Here! or Log In Below:  
 
News Articles Search    
 

 Home / 3D Theory & Graphics / Moveable cameras Account Manager
 
Archive Notice: This thread is old and no longer active. It is here for reference purposes. This thread was created on an older version of the flipcode forums, before the site closed in 2005. Please keep that in mind as you view this thread, as many of the topics and opinions may be outdated.
 
Scott Baillie

July 11, 1999, 02:02 PM

Can anyone explain, in simple terms, how I would go about introducing a moveable camera into my Gfx library?

thanks.

 
Raven

July 13, 1999, 04:19 PM

Scott Baillie wrote:
>>Can anyone explain, in simple terms, how I would go about introducing a moveable camera into my Gfx library?
>>
>>thanks.

well, at the basic level(without BSP's etc.), a moveable camera is simply another coordinate system in your transformation pipeline. Example:

step 1-Object is in local coordinate system. Translation to world coordinates and appropriate user-defined transforms are applied

step 2-Lighting fogging etc

step 3-Perspective projection

step 4-Rasterizing

we wanna insert a camera in here. a pipeline without a camera is as if the viewer is sitting at the origin and looking down(or up) z, or whatever your projection is. a camera usually goes between step 2 and step 3. it is defined as:

typedef struct {
Point position;
double Yaw, Pitch, Roll;
} Camera;

now, we want to transform our stuff so that arbitrary cameras will eventually sit at the origin looking down z. for this we do simply:

x'=x-Camera.Position.x;
y'=x-Camera.Position.y;
z'=x-Camera.Position.z;

RotateY(Vert, -Camera->Yaw);
RotateX(Vert, -Camera->Pitch);
RotateZ(Vert, -Camera->Roll);

ie. we move our entire coordinate system so that the camera is now the origin and rotate it so that it is looking down z. of course, you have to maintain the orientation of your system(left or right-handed) and maybe use a matrix and concatenate it with the rest of your transforms for optimization. also, yaw is looking left/right, pitch is up/down, roll is turning the camera along z(whatever it's called:)

hope this helps,
raven

 
Scott Baillie

July 14, 1999, 03:04 PM

Thanks. I think i've got the basic camera set up okay. I currently have a camera position and a camera matrix as follows.

Camera pos = (0,0,0) - At the origin for now

Camera Matrix = 1, 0, 0, 0
0, 1, 0, 0
0, 0, 1, 0
0, 0, 0, 1

Roration matrix - depends which direction I want to rotate.

I now do the following for each vertex coord

New Object Coord = Rotation Matrix * Camera Matrix * (world object position - camera position)

This seems to work when I want to rotate the camera but I can't move the camera forward(in to the screen) or side-to-side.

Any ideas?

Thankz.


 
Raven

July 15, 1999, 05:00 PM



Scott Baillie wrote:
>>Thanks. I think i've got the basic camera set up okay. I currently have a camera position and a camera matrix as follows.
>>
>>Camera pos = (0,0,0) - At the origin for now
>>
>>Camera Matrix = 1, 0, 0, 0
>> 0, 1, 0, 0
>> 0, 0, 1, 0
>> 0, 0, 0, 1
>>
>>Roration matrix - depends which direction I want to rotate.
>>
>>I now do the following for each vertex coord
>>
>>New Object Coord = Rotation Matrix * Camera Matrix * (world object position - camera position)
>>
>>This seems to work when I want to rotate the camera but I can't move the camera forward(in to the screen) or side-to-side.
>>
>>Any ideas?
>>
>>Thankz.
>>
>>

Hello again.

I don't really know what it is that is happening here, but maybe it's what i think it is. You have to remember that matrix multiplication is NOT commutative. what it means is that if we have a matrix ||Aij|| and ||Bkl|| then ||Aij||*||Bkl|| does NOT equal ||Bkl||*||Aij||. I found out the hard way:) that in a camera transformation the translation has to go before the rotation. This is due to the fact that unless you will move first you will be rotating about the origin of the world system, not the camera system. You'll get an orbiting effect instead of a moving effect. If you change your coordinates during rotation you'll hardly see any change at all. This is possibly what's happening. As far as i see you are doing everything correct except for the order of your matrix concatenation. Explanation:

Camera matrix=Identity matrix(?)

| 1 0 0 0 |
| 0 1 0 0 | => This is usually called an identity matrix. It's linear transformation that
| 0 0 1 0 | doesn't transform anything
| 0 0 0 1 |

camera pos=(object world coordinates-camera world coordinates)

Multiply this by your translation vector(camera pos). NOTE! the vector has to be in a homogenious 4D space ie (0,0,0,1), since all your matrices are 4-dimensional(Don't worry about this)

If camera pos=(x1,y1,z1,w) where x1, y1, z1 are (object worldcoord-camera worldcoord) then your translation matrix will be:

| x1 0 0 0 |
| 0 y1 0 0 |
| 0 0 z1 0 |
| 0 0 0 w |

Now multiply this by your rotation matrix and try moving the camera pos around. it should work now

 
Scott Baillie

July 16, 1999, 07:23 PM

I've got it working now. You were correct. The problem was that matrix multiplication is NOT commutative.

Your help is much appreciated. Thanks.

 
This thread contains 5 messages.
 
 
Hosting by Solid Eight Studios, maker of PhotoTangler Collage Maker.