本文整理汇总了C++中Point2f::squareMagnitude方法的典型用法代码示例。如果您正苦于以下问题:C++ Point2f::squareMagnitude方法的具体用法?C++ Point2f::squareMagnitude怎么用?C++ Point2f::squareMagnitude使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Point2f
的用法示例。
在下文中一共展示了Point2f::squareMagnitude方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: colliderParticeCirclePeg
bool colliderParticeCirclePeg(Ball &ball, Peg &peg, GLfloat time)
{
GLfloat sum_radii, sum_radii_sq, n_mag_sq;
Point2f normal;
normal = ball.position - peg.position;
//GLfloat distance = normal.magitude();
sum_radii = ball.radius + peg.radius;
sum_radii_sq = sum_radii * sum_radii;
//std::cout << "x " << normal._x << std::endl;
n_mag_sq = normal.squareMagnitude();
// std::cout << " n_maq_sq:" << sum_radii_sq << std::endl;
// std::cout << "sum_radii_sq:" << sum_radii_sq << std::endl;
if (n_mag_sq <= sum_radii_sq)
{
std::cout << "x " << normal._x << std::endl;
normal.normalize();
std::cout << "normal x " << normal._x << std::endl;
GLfloat velocityDotN = dotProduct(normal, ball.velocity);
if(velocityDotN < 0)
{
ball.velocity._x -= 2.0f * velocityDotN * normal._x;
ball.velocity._y -= 2.0f * velocityDotN * normal._y;
ball.position._x += 2.0f * (sum_radii - peg.radius + ball.radius) * normal._x * time;
ball.position._y += 2.0f * (sum_radii - peg.radius + ball.radius) * normal._y * time;
}
return true;
}
else
{
return false;
}
}