• 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
Schlabbermampf

Combined Rotation around Global Axis

10 posts in this topic

Hi there!

i am currently programming a rubiks cube for the playstation portable for my studies. so far it all works well except the rotation-control of the whole cube, so i'll explain it shortly:

the analog stick gives his X coordinate to the rotation function which adds this value with a small multiplicator to the total rotation angle around the global Y axis. the same with the analog stick's Y coordinate that lets the cube rotate around the global X axis.

to create the rotation matrix, the psp-api has a function sceGumRotateXYZ(float x, float y, float z) wich obviously uses euler angles.

 

so now my problem: the first rotation around the X-axis works well because the camera is fixed, but the second around the Y-axis rotates the cube around his local Y-axis, but i want it to rotate around the global Y-axis! for the first rotation it is similar if its around the global-world axis or the cube's local axis because they are the same, but for the second one the needed rotation-axis is transformed by the first one.

 

i don't know how to handle this situation. i just converted the Y-axis and the angle to euler angles with help of this article, but with the same fail-result. so i ask for your help.

 

greetings and best wishes

fabian

0

Share this post


Link to post
Share on other sites

If you do the two rotations (around the X axis and around the Y axis) yourself, reversing the order of the rotations will probably fix your problem.

0

Share this post


Link to post
Share on other sites

no, the reversed order lets the cube rotate around the Y-axis correctly, but the X-rotation is in the cube's local not in the global coordinate system. in other words: the problem is also reversed xD

0

Share this post


Link to post
Share on other sites

You may have to explain the problem in more detail, perhaps with an example. It is possible you are just confused by the nature of 3D rotations themselves...

0

Share this post


Link to post
Share on other sites
okay, i painted an image and will try to explain:

there is a coorinate system of the world in which the cube and the camera never change their position, i called it the global coordinate system.
then there is the coordinate system of the cube, which natually rotates by the rotation of the cube.
i want to rotate the cube along the global X and Y axis like a model viewer. so in the code, i used a rotationmatrix to rotate the cube around the first axis (image (1)). so now when i use a second rotation matrix, this one lets the cube move in his already transformed local coordinate system (image(2)). the desired rotation is orientated on the unchanged global coordinate system (image (3)).

14566849sq.jpg

i think the second rotation in global like in (3), is a combination of two or three euler-angles in local space. i try the work with an algorithm that convertes an axis-angle rotation to euler-angles. first i rotate the cube in xAngle by eulerrotation. then i take the y-axis (0, 1, 0) and turn it the x-rotation backwards (0.0f, cos(-xAngle), -sin(-xAngle)) to get from this axis and the yAngle the euler-angles for the second rotation. but then the problem returns? for now i do not have any correct solution...i cant believe that this is so difficult...maybe there is an easy way? Edited by Schlabbermampf
1

Share this post


Link to post
Share on other sites

Nice diagrams! I go back to my original post. Whether you get (2) or (3) depends on the order in which you perform your rotations. Perhaps you can post the relevant code? Explain how you tried to reverse the order of the rotations.

Edited by Álvaro
0

Share this post


Link to post
Share on other sites

hehe, thanks :D

okay, so here is the simple way i get (2) as code:

 

rotationAngle.y += analogStickX;
rotationAngle.x += analogStickY;

sceGumPushMatrix();
sceGumRotateX(rotationAngle.x);

sceGumPushMatrix();
sceGumRotateY(rotationAngle.y); 

 

 

 

this code has the same result so i think this funktion also do the same:

 

rotationAngle.y += analogStickX;
rotationAngle.x += analogStickY;

sceGumPushMatrix();
sceGumRotateXYZ(rotationAngle.x, rotationAngle.y, 0.0f); 

 

 

 

by reversing the order i simply understand this (the effect is still equal, just that the Y rotation is global and the X rotation is in local space):

 

rotationAngle.y += analogStickX;
rotationAngle.x += analogStickY;

sceGumPushMatrix();
sceGumRotateY(rotationAngle.y);

sceGumPushMatrix();
sceGumRotateX(rotationAngle.x);
0

Share this post


Link to post
Share on other sites

I see what you are trying to do. Ditch Euler angles. Now. Did you ditch them yet? Good.

 

Now, use either a 3x3 orthogonal matrix or a unit-length quaternion to represent the attitude of your object. Don't keep track of an accumulator of how much you have rotated in the x and y directions, because those are Euler angles in disguise, and you'll get your current behavior, no matter what representation you are using. Then change this attitude by composing small rotations around the x and y axes in response to user input.

 

If you can't figure out some of these steps by yourself with the help of the web and a bit of work, feel free to ask and I'll try to help you.

Edited by Álvaro
0

Share this post


Link to post
Share on other sites

thank you so far! i ditched eulers and this is what i tried:

 

sceGumLoadMatrix(&rotationMatrix); //load rotation matrix into "current"-register
sceGumRotateX(analogMoveY); //changing cube's attitude by small rotations depending on user input
sceGumRotateY(analogMoveX);
sceGumStoreMatrix(&rotationMatrix); //store rotation for next use
sceGumPushMatrix(); //push "current" matrix on matrix stack
 

i am not shure if this is what you meant, because the result has the reverse effect: the cube is always rotated in his local space and the controlling feels very confusing. thinking about it logically, the effect is also very predictable.

Edited by Schlabbermampf
0

Share this post


Link to post
Share on other sites

Back to my first suggestion: Reverse the order of the rotations.

 

 

sceGumLoadIdentity();
sceGumRotateX(analogMoveY);
sceGumRotateY(analogMoveX);
sceGumMultMatrix(&rotationMatrix);
sceGumStoreMatrix(&rotationMatrix);
sceGumPushMatrix();

 

I have no idea what this sceGum stuff is, so I am a wizard if that code works. :)

Edited by Álvaro
0

Share this post


Link to post
Share on other sites

HA! yes, nice, not this reversing of the rotation also makes sence! thank you so much!

 

and also you're really a wizard Álvaro, your code works perfectly in every letter :D

(Gum stands for grafic unit matrix or so and provides functions for matrix handling on the psp)

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