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

New question on radians

11 posts in this topic

Hi,

 

I can't help but feel like a noob once again, so I need to ask this before my head goes through the wall.

 

I'm working on a rotation algorithm. Basically, I have an angle (in rad) and a target angle (in rad) and I need to figure out whether the shortest rotation between the two is clockwise or counter-clockwise.

I've devised a bunch of algorithms, but all of them with complex exceptions to handle the wrap of the angle.

 

My circle is -Pi to Pi (where Pi and -Pi occupy the exact same position, which is the opposite to 0).

 

Anybody got a clue how to solve this 'elegantly'?

 

Thanks

 

1

Share this post


Link to post
Share on other sites

i don't understand why would need to "wrap the angle" more than once in your entire life?

if you have a function that does it, that should be the end of it

 

otherwise, there's quaternions and vectors

using vectors you can rotate around an axis without problems.. if its 2D its going to be really easy to implement

 

if you don't want to reinvent the wheel there's glm library that does all of this

not sure if it has quaternions, but either way someone on this forum has really good tutorials on basic quaternions

 

i also have basic implementations that i use myself here:

https://github.com/fwsGonzo/cppcraft/tree/master/source/library/math

just don't take everything i write at face value, since i'm the only one that has been using any of that

2

Share this post


Link to post
Share on other sites

That uses trig though but you can do it by applying the fmod (or fmodf for floats instead of doubles) function which may be faster.

 

Discussion here (starts off with degrees then various implementations for the radians case).

 

http://stackoverflow.com/questions/1878907/the-smallest-difference-between-2-angles

The point is, if possible, to not use angles in the first place. The need for trigonometry may just be the result of using the wrong tool, and the correct solution may not involve any trigonometry at all if done correctly to begin with. That's why Alvaro gave the advice to stop using angles.

2

Share this post


Link to post
Share on other sites

Yes, if you start with a vector representation. But OP dude sounds like he has angles to start with (let's hope he didn't extract them from the vectors via atan2).

1

Share this post


Link to post
Share on other sites

I'm currently using Dart (Web Language) implementing StageXL.

StageXL works in such a way that my sprite has an innate field that contains its 'rotation' which it applies to the sprite.

I can GET and modify that rotation field which is represented by a number between -Pi to +Pi.

This rotation hence gives me my point of origin to perform the rotation.

 

The 'target' of my rotation is the result of an atan2(y, x) function sadly (possibly because I'm unfamiliar with the suggested approach above).

 


http://stackoverflow.com/questions/1878907/the-smallest-difference-between-2-angles

That's the exact article that got me confused in the first place :)

 

Seems like I've got much to learn from vectors and/or quaternions.

I'll start with the above info and will 'ping' if I'm still at a loss.

 

Thanks all!

0

Share this post


Link to post
Share on other sites

You can do it with some if statements (and probably some abs()) if you can't fmod or fmodf in your language.

 

Write down some cases (try with angles from all 4 quadrants), work out the expected answer for each combination, and work out the pattern. You need to work out how to handle the "shortest angle crosses the discontinuity" case.

0

Share this post


Link to post
Share on other sites

Ended up using the below statement:

 

_a+= (_a>math.PI) ?-2*math.PI : (_a<-math.PI) ? 2*math.PI : 0;

 

and it works wonderfully.

I'll still look into vectors though. If there's a better way, I want to be able to do it too (aka get better at problem solving).

 

Thanks 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