Consistent angle system?
by Jacob Wagner · in Torque Game Builder · 07/31/2008 (1:29 am) · 3 replies
Hi, I'm coming back to TGB after a bit of playing around in smalltalk and 3d engines. (Boy I wish I could program 2d games in smalltalk. Although someone worked on a dll TGB earlier that could be imported into smalltalk, I'd still need some way to import the rakNet networking library for my game so it's a no go :( )
Anyways, one thing that got me confused a few times in the past was the angle systems used for various functions. They were not uniform for each function, so one function would report in degrees like: -160 <> 160, another function would report back (or perhaps expect numbers from) 0-360. It turned out to be ok after a bit of coding, but debugging it took up some time.
I was wondering if this is still an issue if anyone can give me a heads up on what I should expect? Thanks.
Anyways, one thing that got me confused a few times in the past was the angle systems used for various functions. They were not uniform for each function, so one function would report in degrees like: -160 <> 160, another function would report back (or perhaps expect numbers from) 0-360. It turned out to be ok after a bit of coding, but debugging it took up some time.
I was wondering if this is still an issue if anyone can give me a heads up on what I should expect? Thanks.
#2
This will convert the result to be between 0 and 360.
08/10/2008 (8:59 pm)
I think Kevin means that you can just add 360 to an angle less than 0 and get the same angle. Sometimes if the result will range wildly I'll do the following:%angle = someFunction(); while( %angle < 0 ) %angle += 360; while( %angle >= 360 ) %angle -= 360;
This will convert the result to be between 0 and 360.
#3
08/20/2008 (1:11 pm)
Another thing to keep in mind is that setRotation()/getRotation() use values that are the opposite of the normal "math" rotations. So in math, 0 degrees points to the right, 90 degrees is up, 180 is left, and 270 is down. Torque rotations are the opposite, so if you're doing things in math angles, you need to convert before you all setRotation(). This is very easy however:%this.setRotation(270 - %theMathAngle);
Torque Owner Kevin James