• Create Account

Interested in a FREE copy of HTML5 game maker Construct 2?

We'll be giving away three Personal Edition licences in next Tuesday's GDNet Direct email newsletter!

We're also offering banner ads on our site from just \$5! 1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.

Calculating angles of rotation

Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

21 replies to this topic

#21radioteeth  Prime Members   -  Reputation: 1104

Like
0Likes
Like

Posted 03 November 2012 - 09:52 AM

There seems to be a general lack of trig know-how on this thread..
I wrote this function for an aimbot known as 'ViperG' in a file that's dated june 24th, 2001
I've commented it and adjusted it a bit. You might need to swap some things, but this should help you understand the jist of what you're trying to accomplish..

[source lang="cpp"]#define RAD2DEG (180 / 3.141592654)void VectorAngles( float *vector, float *angles ){ float tmp, yaw, pitch; if (!vector[0] && !vector[1]) // no horizontal length { if (vector[2] > 0) // straight up pitch = 90; else pitch = -90; // straight down yaw = 0; // can't discern a heading with xy of zero } else { yaw = (atan2(vector[1], vector[0]) * RAD2DEG); if (yaw < 0) // set yaw between 0-360 yaw += 360; // get horizontal length of vector tmp = sqrt (vector[0]*vector[0] + vector[1]*vector[1]); // use horizontal length and vector[z] to get pitch pitch = (atan2(vector[2], tmp) * RAD2DEG); } angles[0] = pitch; angles[1] = yaw; angles[2] = 0;}[/source]

To use this function you'd do

[source lang="cpp"]...float vector[3], angles[3];// set your vector hereVectorAngles(vector, angles);// angles now contains yaw/pitch euler interpretation of vector.....[/source]
Let me know if you have any further questions..

#22Alessandro  Members   -  Reputation: 296

Like
0Likes
Like

Posted 03 November 2012 - 10:09 AM

Thanks a lot, I'm going to try this as well!

Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

PARTNERS