// Definition of overloaded functions for trigonometric functions sin, cos, atan.
// These are needed for cartesian<->polar coordinate conversions.
// The functions in this file approximate by texture lookup for use with GLSL.

const float RAD_90  = 1.57079632680;
const float RAD_180 = 3.14159265359;
const float RAD_270 = 4.71238898039;
const float RAD_360 = 6.28318530718;

float sin (in float ang) {
    if (ang < 0.0) {
        ang += RAD_360;
    }
    return 2.0 * texture1D(sincosSampler, ang/RAD_360).r - 1.0;
}

float cos (in float ang) {
    if (ang < 0.0) {
        ang += RAD_360;
    }
    return 2.0 * texture1D(sincosSampler, (RAD_90-ang)/RAD_360).r - 1.0;
}

float atan (in float y, in float x) {
    float xt = 0.5 * x + 0.5;
    float yt = 0.5 * y + 0.5;
    vec2  lookup = vec2 (yt, xt);
    return RAD_360 * texture2D(atanSampler, lookup).r - RAD_180;
}
