Looking at a vector.
vector vA = Vector ( 1,2);

In the diagram above you can see that vA graphically drawn as an arrow with the head 1 unit over and 2 units up from where it begins. The arrow points in a direction that can be converted into an angle using the VectorToAngle function. The length of the arrow could be found using the VectorMagnitude function.
Here is a second vector.
vector vB = vector (2,1);

Adding vectors.
When adding vectors the x's are added together and the y's are added together to get the sum of the vectors. It can be visualized graphically by placing the tail of one vector to the head of the other with the sum being the vector that would connect the tail of the first to the head of the second. It look like this.

Negative Vectors.
A negative vector runs in the opposite direction from the original
( 180 degrees out).

Here is the subtraction of the same two vectors we added earlier.
Note that -vB runs in the opposite direction that vB ran.

Now even though the above diagram is a 100% valid way of representing the subtraction, I do not find it very useful to visualize it that way. I will get into the reason why shortly but lets look at the subtraction a different way first. We all know that in basic math, or I hope we all do, that the order of subtracting and adding does not effect the results. 5 -2 is the same thing as -2 + 5. It works the same way with vectors. In the next diagram I am going to change the order I draw the vectors in, It will not change the value of the results, it will just display them with a different visual.

The reason this visual is better when working in NWN is because 90% of the time, when you are subtracting vectors, you are looking for the vector between two positions. A position of course is nothing but a vector that has its tail set a (0,0).
For example. We have a guard standing watch in a town that has rules on unsheathed weapons. Anytime a person is detected, we want to the guard to turn to face them and we will also determine how far away they are, just encase the guard has to react to a weapons violation.

VectorToAngle returns the angle the vector is pointing in, setting the facing of the guard to that angle will make him turn towards the target.
VectorMagnitude will return the length of the vector, In the case above will be the distance between oTarget and oGuard.
Scaling
When a vector is multiplied by a number both the x and y elements get multiplied by that number. Since the ratio of x:y remains the same, the angle of the vector does not change only the length is effected.
Modifié par Lightfoot8, 02 octobre 2013 - 03:23 .





Retour en haut







