Help with understanding uses of vectors

I’ve been recently exploring the world of vectors to see how they can make life easier when it comes to games programming. I was wondring how they would be put into pratical use, if i was to use a voxel render (like minecraft) would it be easier to use a vector for each cube or each face when it comes to lighting aswell.

I’m yet to truely explore vectors in pratical use, so my question is really, how would you use vectors in daily game programming of many game styles.

Thank you, in advance for any help :slight_smile:

You can use a vector to define which direction an object is moving, what velocity it has, and what acceleration it has, and it’s easy to add other vectors to the acceleration/velocity, to make the object move as if it were under the effects of gravity or wind blowing, etc.

Do you mean mathematical vector (eg. x,y,z) or vector collection (eg. java.util.Vector)?

OpenGL vectors which are mathematical vectors :slight_smile:

Java.util.Vector is a mathematical Vector too. It’s just meant to be extended, e.g. as in Vector2d. ^^

The uses is still like what I wrote earlier. :slight_smile:

This is how I use them:

this.acceleration.add(this.force);
this.velocity.add(this.acceleration);
this.location.add(this.velocity);

They are all instances of Vector2d.

Wouldn’t it be easier to use an array?

Personally I think it would even be easier to use:


public class Vector2D {
    public float x;
    public float y;
}

Or even just use org.lwjgl.util.vector.Vector2f, if you’re using LWJGL.

I use the lwjgl vectors, but I was more conserned on how one would use them in everyday programming for models, maps and lighting or finding the normal to faces.

A vector is just a Nx1 or 1xN matrix, typically interpreted as representing a direction in a N-dimensional space, but it can be anything you want it to be. Any linear algebra textbook will tell you how to use vectors, though you might want a book that specializes in 3d graphic. This book is pretty decent. There’s a second edition available now, but the first edition is still pretty good and quite a bit cheaper.

Pretty much everyone ignore me: but a 1xn or nx1 is ‘a’ notion of a vector, which is different from 2D, 3D and some other notions of vectors. Vector is a very overloaded term. Specifically they are typically homomorphic but not isomorphic to the LA representation.

homomorphism includes isomorphism. But let’s not derail the topic into category theory ok? :slight_smile: It suffices to say that vectors have different interpretation (even in GLSL – vertices get passed in as vectors after all) but that you’ll do well to study the linear algebra interpretation.

Yeah, keep ignoring me. It’s deeper than interpretations. Dot(a,b) = Trace(A*Transpose(B)) ?? That’s jumping through hoops…now consider the cross product without reverting to a formal matrix (i.e. only matrix ops over only reals).

I think most people would be better off with basic understanding of geometry and vectors before jumping into LA. Really I think understanding complex number before vectors & LA would be a very good thing.

Vector is a very vague term… we use vectors for

  1. to represent some point in space
  2. to represent some direction in space
  3. to represent some direction and speed in space


Vector position = new Vector2(0,0);

Vector velocity = new Vector2(10,10);

Vector newPosition = new Vector2(position.tmp().add(velocity));


Snarf

Thank you, vectors really are easy to understand and provide nice features that may be useful.

Snarf?

Yes, my addition to the discussion, being at least as useful. :wink:

narf! poit! egad!