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

 Home / 3D Theory & Graphics / Camera Tutorials 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

August 08, 1999, 12:51 PM

A while ago I posted a message regarding implementing 3D cameras into my 3D engine. Initially I though I had it working but after further investigation I found out otherwise.

All I want to do if move the camera around a 3D scene.

I'm a beginner to 3D graphics but I understand the basics and was wondering if there are any GOOD camera tutorials for beginners?

I've set up a camera matrix and a camera position and the rotation seems to work okay BUT I cannot move the camera. It's driving me mad cos I think I'm close to getting the basic working.

Any help would be great. Thanks.

 
Kurt Miller

August 08, 1999, 03:36 PM



Scott Baillie wrote:
>>I'm a beginner to 3D graphics but I understand the basics and was wondering if there
>>are any GOOD camera tutorials for beginners?

There are plenty of 3D camera tutorials out there. Here are two that come to mind:

3D Cameras by Jorrit Tyberghein
Cameras by Tweak

-kurt


 
ChaiBot

August 09, 1999, 11:00 PM

The simplest thing to do is to build the matrix yourself. The advantage of this is even if you are working in something like D3D (which renders left-handed) you can build the matrix out of a right handed system.

Let me show you how to set up a D3D camera in a right handed scene. All the math/visualization in right handed systems is very close to what is taught in most high school/college math courses. But that doesn't preclude you from setting up a Left-Handed view matrix. I'll try to explain all the essential steps very clearly (i.e. this may be a bit basic for many people but I'll try to be complete). Also it will apply to OpenGL or other custom renderers. You may just have to flip some of the vectors.

First of all, you have to build the basis vectors for the camera. This is easy, all you have to do is think about how to describe the camera's location in your space. Your view matrix is built out of these basis vectors. So you know you'll need to find the camera's x, y, and z vectors. For a Left Handed System these are "Right"(x), "Up"(y), and "View"(z). If you think about this, and remember your "left-hand rule" you'll see that right, up and view form a left handed system. According to the left hand rule, crossing x to y should give the z vector if you use your left hand. And if you place the fingertips of your open left hand toward the your right (x vector), palm up, then curl your fingers upward (y vector), you'll find that your thumb does point toward your "view." (z vector)

You remember the cross product (hopefully). Take the fingers of your right hand and place them along the first vector. Then curl them toward the second vector. Your right thumb points to the result of the cross product. This is defined in code like so (for example):

Vector3f temp;
temp.x = v1.y * v2.z - v1.z * v2.y;
temp.y = v1.z * v2.x - v1.x * v2.z;
temp.z = v1.x * v2.y - v1.y * v2.x;
return temp;

This cross product is used to build the basis vectors for your camera. What should you have so far from the rest of your program? Coordinates for the camera and the target. Also you will want to assume (or provide) an "up" vector for your camera.

Vector3f vWorldUp;
vWorldUp.x = 0.0f;
vWorldUp.y = 0.0f;
vWorldUp.z = 1.0f;

Vector3f vTarget;
Vector3f vPosition;

Now the rest is a piece of cake. As Dr. GUI says, "It couldn't be easier." First we need to find the "view" (z axis) vector for the camera. This is simply the direction you are looking at.

Vector3f vView = vTarget - vPosition;

Also, now is a good time to check to see if you are too close to your target, if so you will get some division errors, etc. So have some code like:

if(vView.magnitude() >
>>I've set up a camera matrix and a camera position and the rotation seems to work okay BUT I cannot move the camera. It's driving me mad cos I think I'm close to getting the basic working.
>>
>>Any help would be great. Thanks.

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