Vector Class

Started by
12 comments, last by PlutoWarrior 19 years, 4 months ago
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.
--------------------C++ Home - Check it out!Lol... - Amazing video
Advertisement
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.
-------------Become part of developing the specifications of a new language. Visit CodeBASIC.org
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

"Man has got to know... his limitations..."
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.
Quote:Original post by ratt1233
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

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.
--------------------C++ Home - Check it out!Lol... - Amazing video
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]
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?
---------------------------------------------Warning: This post may contain traces of Q-Basic
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.
--------------------C++ Home - Check it out!Lol... - Amazing video
This I can help you with.
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
---------------------------------------------Warning: This post may contain traces of Q-Basic
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.
--------------------C++ Home - Check it out!Lol... - Amazing video

This topic is closed to new replies.

Advertisement