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

Quaternion rotation

4 posts in this topic

Hi, I'm working on a 3D space game built with C++ and DirectX. I've got a question about using quaternions for object rotation and I'm hoping someone might have an idea.

Currently, the player ship's rotation is represented by a quaternion. The ship starts off level and facing directly straight forward (towards the positive Z axis). I create a quaternion based on the 3 axes (positive X to the right, Y is up, and Z is forward).

If I want to apply a rotation to the ship, for example 90 degrees to the right, I can call D3DXQuaternionRotationAxis() to get a rotation quaternion. I then multiply that against the original rotation using D3DXQuaternionMultiply() and I get a new updated rotation where the ship is facing forward along the X axis (perfect!).

The problem I have is in the next step:

If I then want to make a second rotation of pitching the nose of the ship up (based on the current direction it's facing along the X axis), when I try to use the method described above I don't get the intended result. What happens instead is the ship indeed rotates, but as if it were still facing in it's original direction towards the Z axis. So instead of seeing the nose of the ship rotate up, I see the ship roll. Or to be more clear, I see a rotation around the X axis, rather than seeing a rotation around the Z axis.

This is probably a very simple mistake, but for some reason I always have trouble wrapping my head around quaternion math.

Any help is appreciated!
0

Share this post


Link to post
Share on other sites
If I understand your description correctly, it just sounds like you're applying the rotations in the wrong order; try reversing the order of the multiplication.
1

Share this post


Link to post
Share on other sites
Ah, the catch is I want the rotations to be independent. For example, the ship first rotates 90 degrees around the Y axis (yaw to the right), then moves in that direction for some amount of time, and finally as a later action it rotates 90 degrees around the Z axis (pitching the nose upwards).

I'm basically trying to give the player the freedom to move/rotate the ship as if it were a real spaceship. ;)
0

Share this post


Link to post
Share on other sites
Co-ordinates are to be interpreted w.r.t. to a space to give a sense. E.g. if you ever pick (0,1,0) as rotation axis for heading, then you probably mean to rotate in the ship's local space. However, it doesn't work this way. A concatenated transformation is applied in the most global space.

So you need to take explicit steps to first fit the space as you want it, i.e. you to transform it so that the local axes are coincident to the global ones. You do this by first applying the inverse of the current orientation before applying the new rotation. Because you don't want to loose the former orientation, you then have to re-apply a rotation to reconstruct it.

Now, when you think on this further (try it with e.g. 3 rotations on paper), you'll see that the order of all the rotations applied over time is simply reversed. That is probably the reasoning behind SiCrane's post, and it makes sense w.r.t. your problem.
1

Share this post


Link to post
Share on other sites
Ah, I understand! Thanks haegarr (and SiCrane). :)

I changed the code so I apply the newest rotation first then reapply the older rotations and it works beautifully!

Thanks so much. :)
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