Archived

This topic is now archived and is closed to further replies.

Vectors.......how do u use them??

This topic is 5701 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Ok i''m looking at starting 3d programing so i''v been checking out peoples source looking around and have discovered inorder to get anywhere in 3d i have to learn about vectors and matrixs(i know i spelled it wrong) and on searching the web i''v learning how to add multiply and do all the cool stuff with vectors but can''t figure out how to use them in a game so i''m hoping someone here knows of a good web site that teachs u how to use vectors & matrix in games??

Share this post


Link to post
Share on other sites
Vectors are used to a point in 3D basically (x, y, z). Common uses include vertices of 3D models, and lighting normals in OGL (you can get a normal for a vertex using cross product IIRC). They are also used a lot to represent stuff in physics like force and acceleration. You might simulate wind with a vector, or gravity. For particle systems, it is common for each particle to have vectors for position, velocity, and acceleration. The velocity vector is added to the position vector each tick and the acceleration vector is added to the velocity vector each tick.

Matrices are commonly used for transformation. I won''t go into this really, but you should be able to find something if you google ''3D transformation matrix'' or something similar to that. The book OpenGL Game Programming has a rather good explanation of vectors and matrices so if you find OpenGL is your thing, it''s definitely worth your money.

Share this post


Link to post
Share on other sites
a vector in general represents a length and a direction..

every point is some length away from the origin in a specific direction => use a vector to represent it
a force acts on a model with some strength (==length) in a certain direction => use a vector to represent it
light hits a surface in some direction (with length == 1 normally) => use a vector to represent it

you get the idea..

wind comes from some direction
bullets fly in some directions
gravity goes down in some direction
car drives in some direction
enemy looks in some direction

etc...

there and at million other places vectors are used..

matrices are for all sort of linear transformations like:
translation
rotation
scaling
mirroring
projecting
sharing

etc..

as you want to project your stuff in front of your cam to the screen, you use a matrix for that

as you want to rotate your cam (or instead, you will rotate your world in the oposite direction, just as sidenote) you''ll use matrices for this as well..

don''t stress around too much, you will have to learn it all early enough..i''ll suggest you dive into some opengl tutorials from nehe and play around with them.. sooner or later you want to represent your objects with some structure called point and triangle.. some times later you realise that your point could be bether a vector..
then you realise you need something called "vertex normals"
and where ever you see something new you need infos, you can find them.. if you need specific infos you''ll have much more luck in a search than for general info, as you find then generally everything

and: TAKE YOU TIME!
it''ll take some time to understand that stuff more and more

"take a look around" - limp bizkit
www.google.com

Share this post


Link to post
Share on other sites
A vector represents a direction and a magnitude. Probably the easiest way to get used to dealing with them is using them to represent velocity.

First, think in 2d. A car is traveling Northeast at 60 mph at a heading of 25o from North. The 60 mph is the magnitude of the vector. The 25o is the direction . One would call this type of representation of a vector polar since it represents the vector directly in terms of an angle and a magnitude. A more common (and often more useful) form, however, is cartesian or component (or rectangular ) form. Now, think of it this way: That same car is going a certain distance East each second, and a certain distance north. You can convert from polar to rectangular using simple trigonometry. For our example, the x component will equal 60sin(25) and the y component will equal 60cos(25). Now, if you need to simulate the car, just add the x component of its velocity vector to the x component of its position each frame, and do the same thing with the y components.

If you are given a vector and need to determine its magnitude [the magnitude of velocity, for example, is speed (No, the two words aren't synonymous)], then you just use the Pythagorean theorem with the x and y components: sqrt(x2+y2). Note that the magnitude of a vector is also less commonly called its absolute value . It is denoted using the same notation you're used to; the absolute value of vector V is |V |.

These same concepts apply in 3d. The difference is merely that there is also a z component.

This should start you on your way. Check the Articles and Resources section here on gamedev for more info. Look for introductory articles on vectors.

Matrices are more difficult. They are used to solve many simultaneous linear equations. You can also find info on gamedev about them.

[edited by - TerranFury on May 9, 2002 7:03:16 PM]

Share this post


Link to post
Share on other sites
Here's a simple example of the use of matrices. Let's say you have these equations:

5x + 6y = 8
8x - 9y = 4

You want to solve for x and y. You can set this up using matrices like so:


| 5 6 | | x | | 8 |
| | * | | = | |
| 8 -9 | | y | | 4 |

I'll replace these matrices with symbols...
A * B = C

You know A and C and must solve for B . You can do this as follows:

B = A -1 * C

You find,

| 1.03226... |
C = | |
| 0.47312... |


If you solve with your familiar algebraic techniques you'll get the same results.

It is from these very simple concepts that such things as 3d projection matrices are built.


[edited by - TerranFury on May 9, 2002 7:17:51 PM]

Share this post


Link to post
Share on other sites