Jump to content
  • Advertisement
Sign in to follow this  
Darobat

Vector Class

This topic is 4965 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

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 this post


Link to post
Share on other sites
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.

Share this post


Link to post
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 this post


Link to post
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 this post


Link to post
Share on other sites
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.

Share this post


Link to post
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 this post


Link to post
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 this post


Link to post
Share on other sites
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

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!