我正在尝试对无限大的锥体进行线性测试,但我无法理解我做错了什么。我确实得到某种像对象一样的圆锥体,但看起来......错了。
EDIT: This is the solution for line-testing a infinite cone.
double Cone::lineTest(double lineOrigin[3],double dir[3],double maxDistance)
{
//Returns the distance from line origin to the collision point
//The object is located at 0,0,0 so the difference is the lineOrigin
double a = pow(D[0], 2) + pow(D[1], 2) - pow(D[2], 2);
double b = 2*(O[0]*D[0] + O[1]*D[1] - O[2]*D[2]);
double c = pow(O[0], 2) + pow(O[1], 2) - pow(O[2], 2);
double d = b * b - 4*a*c;
if(d < 0)
{ return MAX_DISTANCE; }
d = sqrt(d);
double sol1 = (-b - d)/(2.0*a);
if(sol1 > 0)
return sol1;
return MAX_DISTANCE;
}