# Vector Class

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

## Recommended Posts

Greetings I plan on making a Vector class for future use with future projects. I've been told that they are useful, but I can't figure out what they are or why they would be used. Also, where could I get some formula's that I would need or a list of things that should be part of the class. Thanks.

##### Share on other sites
You can think of a vector as a one dimensional array. A vector only goes in one direction (adding onto it) and can dynamically increase in size. It's basically an array that allocates memory and reallocates it when needed. This is great because you can dynamically add data to the vector and not have to worry about memory management. I've converted my VList (on my website) into a class CVectorList, and fixed some bugs I have. So far It works fantastic for what I need.

##### Share on other sites
Or you could be talking about a Mathematical vector - x, y, z (coords) which I use for vertices of 3d models, along with physics modeling (velocity, acceleration, Forces, torques). I suggest make something *when* you need them instead of making stuff in hopes that you will use them someday. Start projects and see how it would be easier to implement something. Then research and figure out the best way around the problem before writing code. Just my 2 cents

##### Share on other sites
Yeah there are two types of vectors, well they are technically the same thing, but if you want the array type use the STL implementation

#include <vector>
using std::vector;

The other vector is a 1x3 matrix and is used in physics, ie veloctiy is a vector, it is a magnitude and a direction.

##### Share on other sites
Quote:
 Original post by ratt1233Or you could be talking about a Mathematical vector - x, y, z (coords) which I use for vertices of 3d models, along with physics modeling (velocity, acceleration, Forces, torques). I suggest make something *when* you need them instead of making stuff in hopes that you will use them someday. Start projects and see how it would be easier to implement something. Then research and figure out the best way around the problem before writing code. Just my 2 cents

Yup, thats the one I was thinking of. I'm going to begin 3D programming with OGL rther than 2D, and I've been told that they come in handy for moving the player, bullets etc. I was just looking for a tut/article on making a vector class that woudl be suffitient for my purposes.

##### Share on other sites
if you know vector maths making a vector class is a cake walk, if you dont know vector maths, well, its time to learn [wink]

##### Share on other sites
I just made myself one because I needed to do my own terrain normals in opengl. I understood cross and dot product stuff from physics but I never knew how to use it in programming. So I gave it a shot. I just wish I knew why my terrain looks like a chess board now, lots of black and white quads. Maybe I need to average the normals?

##### Share on other sites
I dont know vector math. I was looking at one that some guy made and I get a bit of it. Some questions:
1) What is a dot product? What is it for?
2) Same thing for cross proudct
3) What is a normalizing function for?

Thanks.

##### Share on other sites
1)The dot product mutliplys the components of each vector that are parallel to each other. It finds the angle between two vectors and gives a scalar answer.
2)The dot product multiplys the components of the vectors that are perpendicular to each other. The answer that results is another vector and its direction is perpedicular to the plane the first two vectors lie on.
3)A normalizing function takes the answer from your dot product and divdes it by the length of that vector. This effecitivly makes it equal one. This vector can then be used to do lighting.

Example:
Dot Product-(x*x2,y*y2,z*z2)
Cross Product-(y*z2 - z*y2, z*x2 - x*z2, x*y2 - y*x2)
Normal- First you find the length
length=sqr(x^2+y^2+z^2)
then you divide each component of your new vector by the length
x/=length
y/=length
z/=length
this will normalize the vector so that is can be used for lighting applications

##### Share on other sites
Do you think perhaps you could give me an example of lets say moving a bullet in a straight line? Things work nicely in examples.

1. 1
Rutin
25
2. 2
3. 3
4. 4
5. 5

• 10
• 13
• 19
• 14
• 9
• ### Forum Statistics

• Total Topics
632943
• Total Posts
3009347
• ### Who's Online (See full list)

There are no registered users currently online

×