2017-11-20 5 views
0

그래서 구가 AABB와 올바르게 충돌하도록하려고합니다. 그러나 어떤 이유로 AABB의 한쪽에서만 발생합니다. 다른 모든면은 충돌이없는 것처럼 행동합니다.AABB intersect BoundingSphere는 한쪽에서만 작동합니다

float dmin; 
    float r2 = pow(m_Radius, 2); 
    dmin = 0; 

    if (m_Center.GetX() < other.GetMinExtents().GetX()) 
     dmin += pow(m_Center.GetX() - other.GetMinExtents().GetX(), 2); 
    else if (m_Center.GetX() > other.GetMaxExtents().GetX()) 
     dmin += pow(m_Center.GetX() - other.GetMaxExtents().GetX(), 2); 

    if (m_Center.GetY() < other.GetMinExtents().GetY()) 
     dmin += pow(m_Center.GetY() - other.GetMinExtents().GetY(), 2); 
    else if (m_Center.GetY() > other.GetMaxExtents().GetY()) 
     dmin += pow(m_Center.GetY() - other.GetMaxExtents().GetY(), 2); 

    if (m_Center.GetZ() < other.GetMinExtents().GetZ()) 
     dmin += pow(m_Center.GetZ() - other.GetMinExtents().GetZ(), 2); 
    else if (m_Center.GetZ() > other.GetMaxExtents().GetZ()) 
     dmin += pow(m_Center.GetZ() - other.GetMaxExtents().GetZ(), 2); 

    if (dmin < r2) 
    { 
     return true; 
    } 

답변

0

이 그냥 직감입니다 ... 당신은 지정하지 않았다 정확히 플랫폼과 컴파일러 당신이이 테스트를하고 있지만 펑() 함수가 순진하게 구현되는 경우는 음의 값을 실패 할 수 있습니다 첫 번째 인수. According to the specs이면 지수가 정수인 경우 음수 값 인 base에 대해 올바르게 작동해야합니다. 그러나 순진하게 구현 된 범용 pow (base, exponent)는 exp (e, ln (base) * exponent)와 같은 일을 할 수 있으며, base의 음의 값에 대해서는 NaN을 반환합니다.

당신이 묘사 한 것과 똑같은 효과가 있습니다. 예제 코드에서 세 축 모두 양의 델타를 생성하는면에서만 작동합니다.

어쨌든 수동으로 제곱을 수행하거나 깨끗한 코드로 float square(float a) { return a*a; } 과 같은 인라인을 구현하는 것이 더 안전합니다.