Created
September 26, 2011 08:09
-
-
Save jcayzac/1241829 to your computer and use it in GitHub Desktop.
Sqrt-less sphere-cone intersection test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// V=(sphere.center - cone.apex_location) | |
// dotProduct_V_V = dotProduct(V, V) | |
// a = dotProduct(V, cone.direction_normal) | |
int cbloom_test(float dotProduct_V_V, float a, float sphere_radius, float cone_sin, float cone_cos) { | |
const float x(cone_cos*sqrt(dotProduct_V_V - a*a) - a*cone_sin); | |
return (fabsf(x)>=sphere_radius)?(x<0):-1; | |
} | |
int jcayzac_test(float dotProduct_V_V, float a, float sphere_radius, float cone_sin, float cone_cos) { | |
const float p(a*cone_sin); | |
const float q(cone_cos*cone_cos*dotProduct_V_V-a*a); | |
const bool tmp(q<0); | |
float lhs[2]; | |
lhs[0]=(sphere_radius*sphere_radius - q); | |
lhs[1]=-lhs[0]; | |
return (lhs[(p<sphere_radius) || !tmp]<2.f*sphere_radius*p)?-1:tmp; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Full article here