本文整理汇总了C++中Hit::setImpactPoint方法的典型用法代码示例。如果您正苦于以下问题:C++ Hit::setImpactPoint方法的具体用法?C++ Hit::setImpactPoint怎么用?C++ Hit::setImpactPoint使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Hit
的用法示例。
在下文中一共展示了Hit::setImpactPoint方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: intersect
bool Sphere::intersect(const Rayon &rayon, Hit &hit, float& dist) const
{
const float m_Pi = 3.14159265358979323846;
Vector OC(sphereOrigin-rayon.getOrigin());
float k(dotProduct(OC,rayon.getDirect()));
float h(dotProduct(OC,OC) - k*k);
float radiusSquare = radius*radius ;
if (h <= radiusSquare)
{
float delta = sqrt(radiusSquare-h);
hit.setImpactPoint(rayon.getDistantPoint(k-delta));
dist = k-delta ;
if (dist <0)
{
return false ;
}
Vector normal(hit.getImpactPoint()-sphereOrigin);
normal.normalize();
hit.setNormal(normal);
hit.setV( (hit.getImpactPoint().z - (sphereOrigin.z - radius)) / (2*radius) );
Vector A (radius,0.0,0.0);
Vector B (hit.getImpactPoint().x-sphereOrigin.x,hit.getImpactPoint().y-sphereOrigin.y,0.0);
A.normalize();
B.normalize();
float cosAlpha = dotProduct(A,B) ;
float alphaAlpha = acos(cosAlpha) ;
float alpha ;
if (B.getY() >0)
{
alpha = alphaAlpha;
}
else
{
alpha = 2*m_Pi - alphaAlpha ;
}
hit.setU(alpha/(2*m_Pi));
return true;
}
else
{
return false;
}
}