• FEATURED

View more

View more

View more

### Image of the Day Submit

IOTD | Top Screenshots

### The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.

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

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

12 replies to this topic

### #1Helixirr  Members

Posted 13 February 2013 - 09:38 AM

Hi, there!

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?

Edited by Helixirr, 13 February 2013 - 09:40 AM.

### #2Álvaro  Members

Posted 13 February 2013 - 09:56 AM

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.

### #3Olof Hedman  Members

Posted 13 February 2013 - 09:58 AM

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

Edited by Olof Hedman, 13 February 2013 - 10:00 AM.

### #4Helixirr  Members

Posted 13 February 2013 - 11:23 AM

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

What are the benefits of whichever approach?

### #5C0lumbo  Members

Posted 13 February 2013 - 11:32 AM

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

### #6Helixirr  Members

Posted 13 February 2013 - 11:36 AM

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

Of course.  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.

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

Edited by Helixirr, 13 February 2013 - 11:37 AM.

### #7Polarist  Members

Posted 13 February 2013 - 12:07 PM

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.)

Edited by Polarist, 13 February 2013 - 12:28 PM.

### #8Helixirr  Members

Posted 13 February 2013 - 12:21 PM

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!   Thank you, Polaris! I finally understand this, maybe not everything, but this post surely made my day! Useful reference.

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.

### #9Polarist  Members

Posted 13 February 2013 - 12:33 PM

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.  )

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

### #10Helixirr  Members

Posted 13 February 2013 - 01:59 PM

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.  )

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.

### #11Olof Hedman  Members

Posted 13 February 2013 - 05:40 PM

In fact, forward, right and up vector is so basic for defining an orientation, that you can put them directly into the columns of a matrix, and you have a rotation matrix that transforms your points into the orientation.

Edited by Olof Hedman, 13 February 2013 - 05:41 PM.

### #12Helixirr  Members

Posted 14 February 2013 - 08:49 AM

In fact, forward, right and up vector is so basic for defining an orientation, that you can put them directly into the columns of a matrix, and you have a rotation matrix that transforms your points into the orientation.

Oh, interesting. Thank you for pointing that out.

No wonder they used these vectors in Ratchet and Clank 3, then.

### #13BCullis  Members

Posted 14 February 2013 - 02:27 PM

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.

QFE!

My camera needs a contextual Up, Left, and Forward, as do my character controls.  Physics calculations want to know positions, surface normals, incoming direction and magnitude, etc.  They're all represented by three values corresponding to a game-space X-, Y-, and Z-axis, but in some contexts the numbers are purely positional, and in others (usually interactions as opposed to identities) they represent distances or velocities.

Hazard Pay :: FPS/RTS in SharpDX (gathering dust, retained for... historical purposes)
DeviantArt :: Because right-brain needs love too (also pretty neglected these days)

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.