commit 1ff1455cfd740725b9a22883bea29dd22cde8513
parent f38664cfbe50a90f2f022bc8b091b207bdc30104
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Mon, 22 Jan 2018 09:07:35 +0100
Upd the computation of the uv parameter on sphere intersection
Diffstat:
2 files changed, 5 insertions(+), 7 deletions(-)
diff --git a/src/s3d.h b/src/s3d.h
@@ -447,7 +447,9 @@ s3d_triangle_get_vertex_attrib
struct s3d_attrib* attrib);
/*******************************************************************************
- * Sphere API - Manage a spherical shape
+ * Sphere API - Manage a spherical shape. By default, the sphere normals point
+ * outward the sphere. One can use the s3d_shape_flip_surface function to
+ * revert them.
******************************************************************************/
S3D_API res_T
s3d_shape_create_sphere
diff --git a/src/s3d_geometry.c b/src/s3d_geometry.c
@@ -183,12 +183,8 @@ geometry_rtc_sphere_intersect(void* data, RTCRay& ray, size_t item)
} else if(eq_epsf(ray.Ng[0], 0.f, 1.e-6f)) {
ray.u = ray.Ng[1] > 0 ? 0.25f : 0.75f;
} else {
- double phi = atan(ray.Ng[1] / ray.Ng[0]);
- if(ray.Ng[0] < 0) {
- phi = phi + PI;
- } else if(ray.Ng[1] < 0) {
- phi = 2*PI + phi;
- }
+ double phi = atan2f(ray.Ng[1], ray.Ng[0]); /* phi in [-PI, PI] */
+ if(phi < 0) phi = 2*PI + phi; /* phi in [0, 2PI] */
ray.u = (float)(phi / (2*PI));
}
}