PDA

View Full Version : Tutorials Math/Vectors



kung foo man
18th November 2012, 13:21
Hey,

does anybody know a good tutorials about the math behind vectors?

Some people are interested to work on K~Surf, but they lack the math-skills atm.

Regards


Collection of Tutorials:

Bullettrace and you
http://killtube.org/showthread.php?893-Bullettrace-and-you&highlight=vector

[advanced] movegravity() and movement vectors
http://killtube.org/showthread.php?894-advanced-movegravity%28%29-and-movement-vectors&highlight=vector

Mitch
18th November 2012, 13:32
You mean something like this:

A vector in cod is (x,y,z) = (forward, left/right, up). The most used function with vectors in cod are distance, VectorNormalize and VectorToAngles.

With distance you can calcatulate the distance between two points.

Example:


one = (0,0,0);
two = (100, 0, 100);
dist = Distance( one, two );


With VectorNormalize you get a vector between 0 and 1. So (0-1, 0-1, 0-1).

Example:


difference = VectorNormalize( end - start );


With VectorToAngles you can calculate the angles you need to get from your current position (vector) to a other position.

Example:


angles = VectorToAngles( end - start );

kung foo man
18th November 2012, 13:59
Yeah, thats already a good beginning :)

IzNoGoD
18th November 2012, 14:12
Nope, vectornormalize does actually the following:



vec = (123, 234, 345);
vec = vectornormalize(vec);
}

vectornormalize(vector)
{
l = length(vector);
vector = maps\mp\_utility::vectorScale(vector, 1/l);
}


As you can see, vectornormalize will a vector with exactly the same direction, but with length of one. Always. (although behaviour with vec = (0,0,0) is not defined)