本文整理汇总了C++中CVector2::SquareLength方法的典型用法代码示例。如果您正苦于以下问题:C++ CVector2::SquareLength方法的具体用法?C++ CVector2::SquareLength怎么用?C++ CVector2::SquareLength使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CVector2
的用法示例。
在下文中一共展示了CVector2::SquareLength方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Distance
bool CKinematics2DCollisionCircle::CheckIntersectionWithRay(Real& f_distance, const CRay& c_ray) const {
CSegment c_segment = c_ray.ProjectOntoXY();
CVector2 c_closest_point, c_closest_segment_point;
c_segment.GetMinimumDistancePoints( m_cPosition, c_closest_point, c_closest_segment_point );
Real f_min_segment_distance = Distance(m_cPosition,c_closest_segment_point);
if( f_min_segment_distance > m_fRadius ) {
return false;
}
// see http://local.wasp.uwa.edu.au/~pbourke/geometry/sphereline/
CVector2 dp = c_segment.GetEnd() - c_segment.GetStart();
Real a = dp.SquareLength();
Real b = 2 * dp.DotProduct(c_segment.GetStart() - m_cPosition);
Real c = (m_cPosition.SquareLength() +
c_segment.GetStart().SquareLength() -
2 * m_cPosition.DotProduct(c_segment.GetStart()) -
m_fRadius*m_fRadius);
Real bb4ac = b*b - 4*a*c;
Real mu1 = (-b + sqrt(bb4ac)) / (2 * a);
Real mu2 = (-b - sqrt(bb4ac)) / (2 * a);
Real mu = Min(mu1,mu2);
if( mu < 0 || mu > 1 ) mu = Max(mu1,mu2);
f_distance = mu * c_ray.GetLength();
return true;
}