
|
Notes:
A Vector
A vector is a quantity that has both direction and magnitude. Acceleration, force, and velocity are vectors. Not all vectors need the magnitude. These vectors are used for direction only and are called lookvectors in cog. You can visualize vectors with arrows as in this example:
Three vectors are shown in this diagram. The length of each vector's arrow is its magnitude. You can have a vector with any number of dimensions. In this 2d picture, only two dimensions are used - x and y. In JK's virtual world, a third dimesion - the z axis - is added to simulate the real world.
A 3d vector is expressed as three numbers - (x, y, z). Each number holds the vector's value on that axis. Because you can have vectors with different numbers of dimensions, you can't write all vectors as three numbers. The examples in this reference use three numbers for all vectors, and the z axis will be left at zero if it is not used.
The blue vector in the above diagram can be expressed as '1 -1 0'. That's plus one unit on the x axis and minus one unit on the y axis. This gives the vector a direction of -45 degrees on the graph. The length of that vector is nearly 1.4.1
The length can be increased with no change in direction. This graph shows the blue vector from the above diagram. The length has been increased to about 2.83, but the direction has not changed. The new vector is expressed as '-2 -2 0'.
Because vectors can represent different quantities (positions, velocity, acceleration), their unit is not consistent. The length of a velocity will be the speed of the velocity while the length of a position vector will be the JKU distance from the center of the virtual world.
Vectors vs. Positions
This reference makes a distinction between vectors and positions. A vector is a direction and magnitude, and a position is a point on a 3d map. Both are used for different things. But positions are just vectors. Positions can also be called displacement vectors. Look at these two pictures:
These dots represent positions in the virtual world. They are expressed the same as the vectors in the first diagram. The '0 0 0' on the graph is the center of the world. If you imagine a line from '0 0 0' to any of the positions on this map, you'll have drawn one of the vectors from the first graph. A position is a vector, but not all vectors are used for positions.
Written Vectors
Jedi Knight allows vectors to be given in two ways. You can have a variable of type vector. For example:
lvec=GetThingLook(player);
The variable, lvec, now holds the vector direction that the player is looking. You can use this variable in any vector parameter. For example:
SetThingLook(some_thing, lvec);
some_thing will be set to look in the direction held by lvec. The other way to write a vector is in this form: 'x y z'. You can use this anywhere in place of a vector variable. For example:
lvec='1 0 0';
Or,
SetThingLook(player, '1 0 0');
In this last example, the player was set to look straight down the x axis.
Sine, Cosine, and Quadrants
These are only covered briefly in this reference (for now).
Two vectors form an angle and a plane. This picture from VectorDot's description shows two vectors and the angle between them. The angle starts at the +x black line and extends into the second quadrant (see below). Angles always start at the positive x line. Angles can extend positively or negatively. In this case, the angle is +120, but the same angle could be written as -240.
These two vectors form a 2d plane. Unless the vectors are pointing in the same direction, they will always form a plane.
There are four quadrants on a graph. The results of the cosine and sine functions are negative in some quadrants and positive in others. In the above example, the dot product was negative because the angle ended in the second quadrant - in which cosine is negative.
Fully explaining sine and cosine is beyond the scope of this reference (for now). Only the results of sine and cosine operations will be explained.
Sine returns a number from 0 to 1. The closer the end of the angle is to the y axis, the closer the returned number will be to 1. As the VectorDot() picture shows, vector1 is placed on the positive side of the x axis. Wherever vector2 points will be the end of the angle formed between the vectors. As the quadrant diagram shows, sine is negative in quadrants 3 and 4.
The closer the end of the angle is to the x axis, the higher the cosine will be. As shown in the quadrant graph, cosine is negative in the second and third quadrants.
Vectors and Scalars
Scalars are quantities that have only magnitude whereas vectors have magnitude and direction. Scalars include time, mass, and speed. You can use physics formulas like f=ma with vectors. Scale an acceleration vector by a mass and you will get a force vector. Here are some other formulas to use:
| Vector Multiplication Examples | |
|---|---|
| Vector * Scalar = | Resulting Vector |
| velocity * mass = | momentum |
| acceleration * mass = | force |
| velocity * time = | displacement |
| acceleration * time = | velocity |
| lookvector * speed = | velocity |
1Read the description of VectorLen() to see the length formula.