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

How to handle rotation when its magnitude is 0 ?

6 posts in this topic

Lets say we have two vectors, Vector a (1, 0, 0) and b (0, 1, 0). If we want to rotate from a to b we need to find dot product for angle like angle = cos-1 (a.b) and we need to take a cross product for rotation vector that is (0, 0, 1).

 

But what if the two vectors are collinear, like for eg. both are (0, 1, 0). Then the cross product is (0, 0, 0) that is its magnitude is 0. So its no rotation, but how do we need to handle this in code ?

Should we test for this case or we can just leave it with its magnitude 0 ?

0

Share this post


Link to post
Share on other sites

Its not really that there's no rotation necessarily. The vectors are co-linear only if they point in exactly the same direction or exactly opposite directions. In the first case, no rotation is needed to get from a to be since they're the same, in the second case you need to rotate 180 degrees -- what the cross product is really telling you here is that all axes of rotation are equally good -- there is no shortest rotation from a to b, so the choice is arbitrary. You can handle that particular rotation as a special case and choose a fixed axis (probably the one linearly independent of the two primary axes of play, if applicable), choose any suitable axis of rotation at random, or one which best reflects any constraints of the physical object in question, if applicable.

 

[edit] Strikethrough: Realized a fixed axis isn't going to cut it for arbitrary rotations.

Edited by Ravyne
1

Share this post


Link to post
Share on other sites

Ok, lets say we have the first case, that two vectors are (0, 1, 0). How do we handle this ?

Do we just let the code pass and try to rotate around a cross that is (0, 0, 0) and an angle of 0 ?

 

For the second case if vector a is (0, 1, 0) and b is (0, -1, 0), how can we find a perpendicular vector to lets say vector a ? I thought maybe to take a cross product with some other vector like up vector and then normalize the result. But in this case we have vector a same as up so again our cross is 0. We could take then another vector and cross it again but that way we could arrive at the same thing if our vector a was something else.

0

Share this post


Link to post
Share on other sites

In the first case there is no rotation: if(a == b), just do nothing and return -- unless you mean that a == b might correspond to any integer multiple of 360 degree rotation that you actually want to happen, then you need to handle that too in some way, but you can get an axis of rotation the same as in the second case.

 

In the second case you can get a perpendicular vector just by dropping one component of the three, swapping the other two, and negating one of them. The particular vector depends on the input vector, of course, but its an easy, arbitrary vector when all choices are otherwise equally good.

 

If you want the whole set of perpendicular vectors, see the answer here, which explains better than I'll be able to: http://math.stackexchange.com/questions/137362/how-to-find-perpendicular-vector-to-another-vector

2

Share this post


Link to post
Share on other sites

Thank you very much, its a lot more clear to me now.

 

For the first case you sad just do nothing and return. The thing I'm asking this is because I use quaternion for rotation and if my rotation vector (result form cross a and b) is (0, 0, 0) and angle is 0, will I then get any unexpected rotation or an error since quaternion will then look like (1, 0, 0, 0) (for w = 1 and x, y, z = 0) ?

0

Share this post


Link to post
Share on other sites

You probably shouldn't attempt to do the rotation at all when you know the current and intended direction are the same (that is, there is no rotation) -- you might need to detect this occurrence at a higher level where you can skip the quaternion rotation, though.

 

An alternative, like I said before, is to use the same arbitrary perpendicular vector from the second case as I described before -- its already perpendicular so you don't need to do the cross product at all in either of these special cases. But you'll at least have a non-zero vector for the axis of rotation, and rotating by 0 degrees will leave the object unchanged, which I think is what you want. This way may be easier than detecting a 0-degree rotation and skipping it where the quaternion is applied.

 

If you don't need to support rotations of greater than 360 degrees (e.g. where 540 degrees is 1.5 turns) then in the case that the current and intended direction are identical (but not opposite) you can actually choose any vector at all to "rotate" around, because you rotate by 0 degrees anyhow, and the result is the same for any vector (modulo potential floating point error, I suppose, but should be too small to notice).

1

Share this post


Link to post
Share on other sites

I haven't realized before but quaternion (1, 0, 0, 0) is a unit quaternion so rotating around that I assume it would be ok, actually the rotation would remain the same.

 

Anyway thank you again.

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