I'm currently working on convertering some Lua script to C, and I've struggled upon some code:
markerCoords.x = playerCoords.x - ( sin(math.rad(camRot.z)) * 20 );
markerCoords.y = playerCoords.y + ( cos(math.rad(camRot.z)) * 20 );
I've looked online but I can't seem to find an equivalent of Lua's math.rad
in C.
The description of this math function is as follows:
math.rad (x)
Returns the angle x (given in degrees) in radians.
What is the equivalent of Lua's math.rad
in C?
There isn't a standard function to do that in C, but as shown in this Q&A
Is there a function in C language to calculate degrees/radians?
It can be done with an user defined function
// Make sure to have the (non standard) M_PI defined
#define _USE_MATH_DEFINES
#include <math.h>
#ifndef M_PI
#define M_PI 3.14159265358979323846264338327950288
#endif
// Apply basic trigonometry
inline double rad_from_deg(double degrees)
{
return degrees * M_PI / 180.0;
}
inline double deg_from_rad(double radians)
{
return radians * 180.0 / M_PI;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.