• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
garrus

local vs world coordinate system for object manipulation

12 posts in this topic

I used to do everything using vectors defined in the world coordinate system, but i'm reading up more and more about manipulating objects in their local coordinates.

For example, define every object looking towards the + Z axis, and the up direction the +Y axis, so as to simplify actions like "move forward" or "jump".

 

Do you have any tips/material/advice on how that's implemented?

 

I'm guessing i'll have to center the object to the world as mentioned above to begin with?

0

Share this post


Link to post
Share on other sites

Usually objects rotations are represented using matrices.

 

Matrices basically contain the direction of each local axis of an object in world space.

 

So if your object is not rotated, its local Y axis direction is 0,1,0, X 1,0,0 and X 0,0,1.

 

If you rotated it upside down the local y axis would be 0,-1,0 (as from the objects perspective, up is down) and possibly X and Z changing (so it wont mirror on some axis somehow...)

 

You can use them for things like "where in world coordinates is this point, that is at these coordinates from the objects point of view?"

 

So yeah, read up on matrices for object positioning/rotation.

0

Share this post


Link to post
Share on other sites

Usually objects rotations are represented using matrices.

 

Matrices basically contain the direction of each local axis of an object in world space.

 

So if your object is not rotated, its local Y axis direction is 0,1,0, X 1,0,0 and X 0,0,1.

 

If you rotated it upside down the local y axis would be 0,-1,0 (as from the objects perspective, up is down) and possibly X and Z changing (so it wont mirror on some axis somehow...)

 

You can use them for things like "where in world coordinates is this point, that is at these coordinates from the objects point of view?"

 

So yeah, read up on matrices for object positioning/rotation.

 

Thanks for the reply!

Yeah, i know about matrices  :) , but as i'm having problems due to doing everything in world space, using a left,forward..etc vector to perform rotations and displacements for each objects,

as i unsuccessfully inquired about here.

 

So i thought that it'd be easier doing the above around the (local object axes, and then simply transforming them to world space representation.

 

 


You can use them for things like "where in world coordinates is this point, that is at these coordinates from the objects point of view?"

 

 

Isn't that a single translation,using the object's position?

0

Share this post


Link to post
Share on other sites

I am also a bit newbie in this, but let me describe the way I do it.
I can convert angle (Euler) rotation to quaternion like this:
 

Quaternion qHeading(Vector3(0.0f, 0.0f, 1.0f), headingRadians); // my "up" is Z
Quaternion qPitch(Vector3(1.0f, 0.0f, 0.0f), pitchRadians); // my "up down" rotates around X
Quaternion qRoll(Vector3(0.0f, 1.0f, 0.0f), rollRadians); // my "roll" around Y
auto rot = qHeading * qPitch * qRoll;

 
I can convert quaternion rotation to analogical matrix transformation with my math lib:
 

Matrix4 rotMatrix;
rot.to4x4Matrix(&rotMatrix);

 
I can convert my position to another matrix transformation:
 

Vector3 pos(15, 0, 0); // example position

Matrix4 posMatrix;
pos.to4x4Matrix(&posMatrix);
 

 
Now, I can get a single matrix which represents BOTH transformations by multiplying them:
 

Matrix4 finalMatrix = rotMatrix * posMatrix;

 
And I can use this matrix in OpenGL to do both transformations in one call:
 

glMultMatrixf(finalMatrix.element); // "element" here is matrix in OpenGL compatible 4x4 array

 
Now, back to rotations: Note how Quaternion rotation is just composition of different rotations about arbitrary vectors.
You can easily rotate Quaternion around any axis just like so:
 

Quaternion newRot(Vector3(1.0f, 0.0f, 0.0f), PI / 2); // 90 degrees around X
rot *= newRot;

 
If you read more about matrices you can do a lot of optimizations to these operations.
You can get back the Euler angles from Quaternion if needed. I find Euler angles still required for objects such as camera.

Now, if my object is actually a collection of other objects rotated and positioned (transformed) with this matrix, this is the way to render it:
 

glPushMatrix(); // save current OpenGL matrix to stack

glMultMatrixf(objectPosAndRot); // move into object's position and rotation
// do the same for each object in collection! (push, transform, pop)

glPopMatrix(); // restore previous matrix

 
And for camera's positioning and rotation, you do the same with inverted matrix at the beginning of the scene.
Hopefully I covered it right.
 

So i thought that it'd be easier doing the above around the (local object axes, and then simply transforming them to world space representation.


That is exactly what happens. But think of it like this:

 

glPushMatrix(); // saved current world transformation matrix
glTranslate(); // moved into object's position
glRotate(); // rotated in local space
glPopMatrix(); // cancel all transformations, move back to world space

 

And, ugh, to avoid any confusion, I am doing exactly the same with math lib (Matrix4 finalMatrix = rotMatrix * posMatrix). Well, order of operations happens to be reverse there.

Edited by Nercury
0

Share this post


Link to post
Share on other sites

World space is for positioning your objects around the world. You should deal with specific aspects of your meshes in their own model space (ie, their scale, their orientation). Once you set up that, then you can position that object on your world.

 

Otherwise you'd be rotating an object with the world as reference coordinate system, which it isn't what you'd do if you wanted to, say, turn the mesh upside down.

1

Share this post


Link to post
Share on other sites

World cordinate never changes, but local coordinate is relative to the object you are modifying. For example if your up vector is represented by 0,1,0 in world it will always be 0,1,0 even though your orientation may have changed.

Edited by BornToCode
0

Share this post


Link to post
Share on other sites

So i mantain,say,a 4x4 matrix to store the object's orientation and displacement , edit that matrix to rotate/move the object, and glRotate,glTranslate accordingly before drawing the object?

0

Share this post


Link to post
Share on other sites

So i mantain,say,a 4x4 matrix to store the object's orientation and displacement , edit that matrix to rotate/move the object, and glRotate,glTranslate accordingly before drawing the object?

 

Look into my previous post's history, it may give you some ideas.

0

Share this post


Link to post
Share on other sites


So i mantain,say,a 4x4 matrix to store the object's orientation and displacement , edit that matrix to rotate/move the object, and glRotate,glTranslate accordingly before drawing the object?

 

Look into my previous post's history, it may give you some ideas.

 

Thanks, that helped smile.png

 

So is the following correct?

So If i want to move an object to the direction it's facing, since i don't have a "forward" vector explicitly,

i assume that all objects begin facing a certain direciton.

 

For example -Z direction, and the current direction they're facing is [0 0 -1]^T times their rotation matrix?

 

Is this how it's done generally?

If so, isn't it processor-intensive to compute all orientations from this?

Edited by garrus
0

Share this post


Link to post
Share on other sites



So i mantain,say,a 4x4 matrix to store the object's orientation and displacement , edit that matrix to rotate/move the object, and glRotate,glTranslate accordingly before drawing the object?

 
Look into my previous post's history, it may give you some ideas.


 
Thanks, that helped smile.png
 
So is the following correct?
So If i want to move an object to the direction it's facing, since i don't have a "forward" vector explicitly,
i assume that all objects begin facing a certain direciton.
 
For example -Z direction, and the current direction they're facing is [0 0 -1]^T times their rotation matrix?
 
Is this how it's done generally?
If so, isn't it processor-intensive to compute all orientations from this?


 
If ^ meant transformation by matrix, then yes. Let me iterate to avoid any error:
If you want to move, lets say, a camera -Z units back (in it's rotated state), you simply transform this movement vector (0, 0, -1) by camera's current rotation matrix, and just do pos += that_vector.
 
pos += vec3(0, 0, -1) ^ rotation; // ^ == transform
I have no idea "how it is done", I find this easy for me and just try to minimize the amount of things I do smile.png. Ok, I started by modding Unreal so I guess I got some concepts in my head from that.
As for performance, I think this kind of operation goes like butter in C++. It is bunch of additions and multiplications. Edited by Nercury
0

Share this post


Link to post
Share on other sites

So i mantain,say,a 4x4 matrix to store the object's orientation and displacement , edit that matrix to rotate/move the object, and glRotate,glTranslate accordingly before drawing the object?

Edit: I guess I should have answered YES. I am actually not sure if maintaining transformation matrix with both rotation and translation for EVERY object has any benefits versus simply calling glTranslate, glRotate.
0

Share this post


Link to post
Share on other sites

Thanks Nercury smile.png

^ meant simply the transpose (to get a column vector from [0 0 -1] )

 

To store each rotation, i'd imagine you mantain 3 angles for the object, which you modify according to user input, and from these you transform the unit vectors of the axes 

( [1 0 0] , [0 1 0] , [0 0 1])  to get the transformed orientation.

 


So i mantain,say,a 4x4 matrix to store the object's orientation and displacement , edit that matrix to rotate/move the object, and glRotate,glTranslate accordingly before drawing the object?

Edit: I guess I should have answered YES. I am actually not sure if maintaining transformation matrix with both rotation and translation for EVERY object has any benefits versus simply calling glTranslate, glRotate.

 

I meant, keeping such a matrix for every object, and calling glMatrixMult before drawing the object.

If you didn't do this, wouldn't you need to call a glTranslate and 3 glRotates for every object either way?

Edited by garrus
1

Share this post


Link to post
Share on other sites

I meant, keeping such a matrix for every object, and calling glMatrixMult before drawing the object.
If you didn't do this, wouldn't you need to call a glTranslate and 3 glRotates for every object either way?

You are right, I would smile.png

To store each rotation, i'd imagine you mantain 3 angles for the object, which you modify according to user input, and from these you transform the unit vectors of the axes
( [1 0 0] , [0 1 0] , [0 0 1]) to get the transformed orientation.

Yeah, I am keeping euler for such objects like my camera, because they better map to mouse input (heading - X, pitch - Y).
I think most of my other objects will not need euler angles at all, so I am planning on storing only the quaternion which represents current rotation. Edited by Nercury
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0