Login x
User Name:
Password:
Social Links Facebook Twitter YouTube Steam RSS News Feeds
Watch MODSonair

Members Online

»
0 Active | 37 Guests
Online:

LATEST FORUM THREADS

»
SOF2 Prefabs map
SoFII Mapping
coduo mapping tools
CoDUO Mapping
Gaming
Q4 General

Forums

»

Welcome to the MODSonline.com forums. Looking for Frequently Asked Questions? Check out our FAQs section or search it out using the SEARCH link below. If you are new here, you may want to check out our rules and this great user's guide to the forums and the website.
For more mapping and modding information, see our Wiki: MODSonWiki.com

Jump To:
Forum: All Forums : General Gaming Topics
Category: General Modeling
General chat about modeling and animation.
Moderators: foyleman, Foxhound, Mystic, StrYdeR, batistablr, Welshy, DrBiggzz, supersword
Latest Posts
Subscribed Posts
Search
Restricted Access Topic is Locked subscribe
Author Topic: Vectors
tomalla
General Member
Since: Jan 16, 2007
Posts: 393
Last: Jun 10, 2012
[view latest posts]
Level 5
Im a fan of MODSonair
Category: General Modeling
Posted: Tuesday, Aug. 11, 2009 09:12 am
I'm trying to learn how vectors actually work.

In Call of Duty 2 there is few functions associated to vectors, here they are ( they all are in CoD2 documentation http://codhelp.info/mapping/scripting/index.htm ):

Vector/anglestoforward
Vector/anglestoright
Vector/anglestoup
Vector/vectordot
Vector/vectornormalize
Vector/vectortoangles

Those functions are really important to me, but I completely do not know, what do they actually do [sad]. What is "forward vector", "right vector", "up vector", "normalized vector" etc. ? Please, if anybody could explain it to me, I would really appreciate that. Also, some articles with examples would be good as well.

PS. I placed this topic in "General Gaming", because it's associated to vectors' knowledge itself, not a particular game.

Regards, Tomalla

PS.2 If anybody have questions, about what do I want, go ahead and ask.
Share |
Sevenz
General Member
Since: Apr 24, 2006
Posts: 2390
Last: May 10, 2013
[view latest posts]
Level 8
Category: General Modeling
Posted: Tuesday, Aug. 11, 2009 02:28 pm
didn't you learn that in school? hm

http://en.wikipedia.org/wiki/Euclidean_vector

well, the anglesto* functions return a vector calculated out of an set of angles (3 angles in degrees to rotate around each axis in the Cartesian coordinate system [3d space] i guess ;) ).

http://en.wikipedia.org/wiki/Euclidean_space
http://en.wikipedia.org/wiki/Rotation_matrix

each object (e.g. player entity) has its own coordinate space. you can imagine the forward, right and up vector as another 3d coordinate system. the forward vector is the direction the object faces to relative to the world coordinate system etc.

vectortoangles turns a vector into a set of angles, so the reverse action of anglesto[vector].

why not using angles only? 'cause vectors have a direction and a length, so they can represent "more information" (a distance) than angle sets.

vectordot: the dot product of two vectors is the resulting value of a two-vector-multiplication.

Code:
 / 1 \     / 4 \
| -3  | * |  2  | = 1 * 4 + (-3) * 2 + 2 * 0 = 4 + (-6) + 0 = -2
 \ 2 /     \ 0 /

-2 is the dot product

(vector1 component x1 multiplicated by vector2 component x1 plus vector1 component x2 multiplicated by vector2 component x2 plus vector1 component x3 multiplicated by vector2 component x3)

http://en.wikipedia.org/wiki/Dot_product


to calculate the actual length (magnitude) of a vector you use good old Pythagoras:

square root of ( distance x1 squared + distance x2 squared + distance x3 squared )

distance = a (non-local / direction) vector, most likely the resulting vector of a two-local-vector-subtraction (which is basically a two-point-subtration)

note: the length is always positive due to the squaring ( number multiplicated by itself, can only be positive * positive = positive and negative * negative = positive)


a normalized vector is a vector which has the length of 1. A normalized vector can have the same direction like a non-nomalized vector, the difference is really just the length in this case.

to normalize a vector, divide each vector component (x1 to x3) by the vector's dot product:


Code:
                                   / x1 \
normalized vector = dot product : |  x2  |
                                   \ x3 /

or

                                       / x1 \
normalized vector = (1/dot product) * |  x2  |
                                       \ x3 /

http://en.wikipedia.org/wiki/Unit_vector

!!! not to be confused with "normal" vectors:
http://en.wikipedia.org/wiki/Surface_normal !!!


a cross product (vector product) function is missing, but not really needed anyway - can be done via scripted function.

btw. there is another script parser function (cod4/5 only?):
Math/vectorfromlinetopoint
Share |
tomalla
General Member
Since: Jan 16, 2007
Posts: 393
Last: Jun 10, 2012
[view latest posts]
Level 5
Im a fan of MODSonair
Category: General Modeling
Posted: Wednesday, Aug. 12, 2009 07:32 am
Quote:
didn't you learn that in school?


Well ... not yet [lol] I think I will in few years [duh] However, I perfectly now the Pythagoras formula.

This is what I want to achieve:

http://i340.photobucket.com/albums/o324/tomalla5120x/plan.jpg

There is an object ( red ), which I want to move to certain place. This place is constant value far from a player. Also, this place is on the line which connects an object and the player. I hope You understand that to this point.

First of all, I made this object turn around, so he faces the player and that place:

object.angles = vectortoangles(level.player.origin - object.origin);

Now I have to calculate coordinates of "final point" ( light green ). My object already faces that point ( because it's on a straight line, right to the player ). I guess I have to use "anglestoforward" function ... but I'm not sure ... how?[banghead] Any hints?

Cheers
Share |
Sevenz
General Member
Since: Apr 24, 2006
Posts: 2390
Last: May 10, 2013
[view latest posts]
Level 8
Category: General Modeling
Posted: Thursday, Aug. 13, 2009 04:05 pm
vec_to_player = level.player.origin - object.origin; // vector from object to player

dist = length(vec_to_player); // distance between object and player
iprintlnbold("Object is " + dist + " units away from player");

vec_normalized = vectornormalize(vec_to_player); // direction vector, length 1

min_dist_to_player = 120; // min. distance object to player

target_origin = object.origin + (vec_to_player - vec_normalized*min_dist_to_player); // coord 120 units in front of player

// NOTE: if the object is already closer than 120 units, it will move away from player (backwards) until is has the minimum distance.


object moveto(target_origin, 3); // move object to target position within 3 seconds

// NOTE: keep in mind that the player can walk away while moving the object
Share |
Restricted Access Topic is Locked subscribe
MODSonline.com Forums : General Gaming Topics : General Modeling

Latest Syndicated News

»
Codutility.com up and runn...
Nice, and there still using the logo and template for the screenshots, which...
Codutility.com up and runn...
dundy writes...Quote:Call of Duty modding and mapping is barly alive only a ...
Codutility.com up and runn...
Mystic writes...Quote:It seems to me the like the site is completely dead? ...
Codutility.com up and runn...
It seems to me the like the site is completely dead?

Partners & Friends

»