#include "math.h"
cvex
main(
vector ray_org = 0;
vector ray_dir = 0;
float radius = 1;
vector
color = {1, 1, 1};
export vector Ng = 0;
export vector uvw = 0;
export int hit = 0;
)
{
hit = 0;
float b = 2*
dot(ray_org, ray_dir);
float c = length2(ray_org) - radius*radius;
if (d > 0)
{
float dist0 = 0.5f * (-b - d);
float dist1 = 0.5f * (-b + d);
if (dist0 > 0 && dist0 < dist1)
{
hit = 1;
distance = dist0;
}
else if (dist1 > 0)
{
hit = 1;
distance = dist1;
}
Ng = ray_org + distance * ray_dir;
uvw.x =
fit(
atan2(Ng.x, Ng.z), -PI, PI, 0, 1);
uvw.y =
fit(
asin(Ng.y), -PI_2, PI_2, 0, 1);
uvw.z = 0;
}
}