Advertisement

vertex vs. vector & following camera

Started by September 04, 2005 06:39 AM
1 comment, last by python_regious 19 years, 2 months ago
I have been confused by a couple of terminology issues. I am trying to implement a following camera, and the example that is given is a pretty rough cut for functionality. Firstly, what I understand a vertex is a 3d point in space, with an x, y, and z. A vector, however is what I am a little more fuzzy on, usually I think of a line with a direction, so it could be a pair of vertices, or an origin (vertex), three angles, magnitude, and for either case, a direction. Anyway, I think it is mistakenly used interchangably, and leads to some confusion on my part. Here is a good tutorial http://chortle.ccsu.edu/VectorLessons/vectorIndex.html. So, I have been trying to implement the NeHe Camera article #8, and there are several typos, as well as a few incompletions that make me wonder what exactly is going on. If anyone has any experience implementing this article, it would be very helpful. I have a small application I am writing and need a chase camera. Thanks, -Kevin
Think of a vector as so:

Origin: 0,0,0 (doesn't actually store this, just assumed)

Then it stores the direction as a point around the origin. This point is of a
single unit in length. For example:
1,0,0 - Points in the X direction
0,0,1 - Points in the Z direction
.5,.5,0 - Points in the X/Y direction

The thing that is probably throwing you off is the fact that the vector is not
storing the origin, but just a unit direction, and the magnitude is assumed
to be 1, but can also be calculated if necessary (distance formula from origin
to location).
Advertisement
An article on vectors. [smile]

A vector is just a magnetude and direction. That is all. There are many ways of expressing this, for instance you could have a vector in rectangular/cartesian form, polar form, intrinsic form, etc...

A vertex to me is just a concept. It defines a point in space with a variety of properties (colour, normal, etc). If a vertex has only position - then it can be attributed to being a point.

Points are for all intents and purposes identical to position vectors (A vector that has a defined and specific starting position - usually the origin of a defined frame).

As for implementing a camera, totally ignoring what Nehe lesson 8 does (I haven't read it for years), this is what I do, and is a pretty nice system.

Firstly - you have your camera frame, which is a set of basis vectors that define that frame (or coordinate system if you prefer). These vectors are the front, up, and side vectors. This frame also needs a position reletive to another defined frame (in this case - the world frame, assumed to be postioned at (0,0,0) and have the unit basis vectors of i, j and k respectively).

What you want to do is to transform vertices that are in the world frame, into that of the camera frame. To transform a vertex by a frame, we use the matrix:

[Sx Ux Fx Px][Sy Uy Fy Py][Sz Uz Fz Pz][0  0  0  1]


To transform vertices into that frame (what we need to do) we take the inverse of that matrix which is:

[Sx Sy Sz -P.S][Ux Uy Uz -P.U][Fx Fy Fz -P.F][ 0  0  0  1 ]


So, as an example. Say you want the camera to follow a point, that you move around. Well, we can assume the up vector is [0, 1, 0], the front vector will be the vector to the point that you're moving, and the side vector can be calculated using the cross product. You will also need to recalcuate the true up vector from the side and front vectors, and normalise them all.

You will want to look up how to rotate vectors and so on to implement a full blown camera. Tutorials that use gluLookAt would be a good start (gluLookAt essentially performs the matrix stuff I just described).

Hmmm... Went a bit off topic there, but it should be useful.
If at first you don't succeed, redefine success.

This topic is closed to new replies.

Advertisement