Game programming - Using vectors called forward, left/right and up

Started by
11 comments, last by BCullis 11 years, 2 months ago

Hi, there! smile.png

When programming games, it is mandatory to know something about vectors. They are neat, and well represent... Wait, what do they represent?

Yeah, my problem is that I have come across vectors called forward, left/right and up. As far as I know, these 3 vectors were put to use in at least one commercially successful video game franchise, Ratchet And Clank:

">

In the video, two game developers, who worked on Ratchet And Clank: Up Your Arsenal, talk about problems they were having with vectors on spherical worlds. Very interesting, but difficult for me to internalize.

What do these 3 vectors represents and how could one put them to use? unsure.png

Advertisement

Vectors are objects that can be added, subtracted and multiplied by numbers (scaled). They can represent a large variety of things, but a couple of relevant ones in this context are velocities and translations.

In a 3-dimensional vector space, you can pick three vectors (like "forward", "right" and "up") and express any vector as a linear combination of those three. "Linear combination" means an expression like C1*forward + C2*right + C3*up, where C1, C2 and C3 are real numbers. The three vectors are said to be a basis of the vector space.

The problems that arise when you handle curved space using vectors in a naive way are probably the result of trying to use affine geometry where differential geometry should be used.

Normal numbers (scalars) has just a magnitude (the value).

A vector has both magnitude and a direction.

There is several possible ways to represent a vector, but in computer graphics, we often use euclidian space, and there we represent the vector as three scalar "coordinates", x,y and z. (in some cases polar coordinates might be more convenient, maybe using them would have solved the problems the developers had)

Vectors, representing a magnitude and a direction is very convenient when working with positions and directions in space.

A "position" is a vector from origo to the point in space where we want to be.

A "direction" is usually represented as a normalized vector. A normalized vector is a vector where magnitude is always 1.

"up", "forward", "left/right" is normalized direction vectors used to rotate an object in the space.

you need to know these three to know how to place the object in the world.

To get more information on how to do math with vectors, look up Linear Algebra

Vectors are objects that can be added, subtracted and multiplied by numbers (scaled). They can represent a large variety of things, but a couple of relevant ones in this context are velocities and translations.

In a 3-dimensional vector space, you can pick three vectors (like "forward", "right" and "up") and express any vector as a linear combination of those three. "Linear combination" means an expression like C1*forward + C2*right + C3*up, where C1, C2 and C3 are real numbers. The three vectors are said to be a basis of the vector space.

The problems that arise when you handle curved space using vectors in a naive way are probably the result of trying to use affine geometry where differential geometry should be used.

Normal numbers (scalars) has just a magnitude (the value).

A vector has both magnitude and a direction.

There is several possible ways to represent a vector, but in computer graphics, we often use euclidian space, and there we represent the vector as three scalar "coordinates", x,y and z. (in some cases polar coordinates might be more convenient, maybe using them would have solved the problems the developers had)

Vectors, representing a magnitude and a direction is very convenient when working with positions and directions in space.

A "position" is a vector from origo to the point in space where we want to be.

A "direction" is usually represented as a normalized vector. A normalized vector is a vector where magnitude is always 1.

"up", "forward", "left/right" is normalized direction vectors used to rotate an object in the space.

you need to know these three to know how to place the object in the world.

To get more information on how to do math with vectors, look up Linear Algebra

Both of these replies tell us what vectors consist of, a direction and a magnitude. I know this already, but of course it is helpful for newcomers. I'm also aware cross and dot products etc.

The problem I'm having is that I can't distinguish the difference between two different approaches, the use vectors direction, position and velocity or the use of vectors forward, left/right and up. Here are two examples of two diffent approaches:

http://blog.wolfire.com/2009/07/linear-algebra-for-game-developers-part-1/

and

the video I already posted.

What are the benefits of whichever approach?

That's a 20 minute video. Could you point to the bit where the developers talk about their non-standard approach?

That's a 20 minute video. Could you point to the bit where the developers talk about their non-standard approach?

Of course. smile.png The interesting part and the part relevant to the topic starts after 06:25. I wouldn't call the approach "non-standard", though. It's just, you know, different. happy.png

I'm trying to explain my problem the best I can, but it's difficult. wacko.png I hope you get the gist of what am I looking after. wink.png

You're talking about different concepts.

Practically every 3d game will find a use for forward, up, and right vectors. But they also need direction, position, velocity vectors for each entity.

In the context of the video, forward, up and, right are are constantly changing (as opposed to most games which can hardcode "up" to an arrow pointing along the positive y axis, meaning that only forward and right are changing.) The three directions are a basic inputs used, among other things, to orient the player and to orient the camera (set up a "view matrix" and "projection matrix"). Their optimization was that in a spherical world, the up vector could be calculated simply by taking the position of the player and subtracting the center of the world. This makes it cheap to calculate the right vector. This is compared to a more general approach of finding the normal vector that corresponds to the polygon that you're standing on (the collision approach he describes as super expensive).

I watched the entire video (thanks, it was interesting), but they did not compare forward, up, right to direction, position, velocity, directly. They are not competing concepts. Defining forward, up, and right are useful constructs to describe orientation, in general. Where as direction, position, velocity are useful to describe movement and physics and such.

Sounds like just semantics. I think you might be over-thinking the concept if you understand vectors, cross products, and dot products (and other basic ideas in linear algebra). These are super, SUPER basic ideas, so if they are confusing you then you're probably thinking about them the wrong way.

Again just to make it clear. EVERY 3D game will use vectors that represent forward, up, right, direction, position, velocity, acceleration, etc. These are just terms to describe what a particular vector is trying to describe. Unless I missed something, there aren't "two approaches" here.

Don't even think about vectors as "a direction and a magnitude," that idea will be limiting and it conveys them as being special in a sense. Really, the best way to think about it is that a vector is just a number. (Sure it's actually 3 numbers, but just think of it as a bloated "number".) So a vector *could* be used to describe a point, or a direction, or a direction and a magnitude, but that's giving them special meaning. It just happens that in a 3d world, it's convenient to use 3 numbers at a time to describe things. That's really all there is to it.

(Tangential side note: In higher mathematics, they are useful because often you want to describe things in higher dimensional space or even n-dimensional space, meaning that you don't define whether the problem lies in 1-D, 2-D, 3-D, 12,345-D. To grasp these concepts, you'll have to "unlearn" that stuff about "directions" and "magnitude" if you've internalized it too much.)

You're talking about different concepts.

Practically every 3d game will find a use for forward, up, and right vectors. But they also need direction, position, velocity vectors for each entity.

In the context of the video, forward, up and, right are are constantly changing (as opposed to most games which can hardcode "up" to an arrow pointing along the positive y axis, meaning that only forward and right are changing.) The three directions are a basic inputs used, among other things, to orient the player and to orient the camera (set up a "view matrix" and "projection matrix"). Their optimization was that in a spherical world, the up vector could be calculated simply by taking the position of the player and subtracting the center of the world. This makes it cheap to calculate the right vector. This is compared to a more general approach of finding the normal vector that corresponds to the polygon that you're standing on (the collision approach he describes as super expensive).

I watched the entire video (thanks, it was interesting), but they did not compare forward, up, right to direction, position, velocity, directly. They are not competing concepts. Defining forward, up, and right are useful constructs to describe orientation, in general. Where as direction, position, velocity are useful to describe movement and physics and such.

Sounds like just semantics. I think you might be over-thinking the concept if you understand vectors, cross products, and dot products (and other basic ideas in linear algebra).

This is the kind of reply I was looking for! wub.png Thank you, Polaris! I finally understand this, maybe not everything, but this post surely made my day! Useful reference. biggrin.png

PS: No advertising or anything, but I also recommend you all to check out all the other episodes from the developer commentary as well. That way it is easier to get a better picture of game development process. happy.png

This is the kind of reply I was looking for! Thank you, Polaris!

You're welcome. I edited the original post to add more detail. (I may have veered a bit off track though. laugh.png )

Feel free to add more or PM me if you have any further questions.

This is the kind of reply I was looking for! Thank you, Polaris!

You're welcome. I edited the original post to add more detail. (I may have veered a bit off track though. laugh.png )

Feel free to add more or PM me if you have any further questions.

Thanks for the PM offer, but I prefer discussing subjects on the forums, so that everyone can see them. Helpful resources should belong to everyone. smile.png

This topic is closed to new replies.

Advertisement