本文整理汇总了C++中Intersection::GetNormal方法的典型用法代码示例。如果您正苦于以下问题:C++ Intersection::GetNormal方法的具体用法?C++ Intersection::GetNormal怎么用?C++ Intersection::GetNormal使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Intersection
的用法示例。
在下文中一共展示了Intersection::GetNormal方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
void NodeIntersector<real>::TransformIntersectionToGlobalCoordinates( const CoreLib::Node<real>* node, Intersection<real>& ioIntersection )
{
// newPosition = M * position
// newNormal = M^{-T} * normal
const Matrix4<real>& localToGlobal = node->GetLocalToGlobal();
Matrix4<real> localToGlobalForNormals = node->GetGlobalToLocal();
localToGlobalForNormals.Transpose();
ioIntersection.SetPosition( localToGlobal * ioIntersection.GetPosition() );
ioIntersection.SetNormal( localToGlobalForNormals ^ ioIntersection.GetNormal() );
}
示例2: if
bool SphereIntersector<real>::Intersect( const Sphere<real>* sphere, const Ray<real>& ray, Intersection<real>& oIntersection )
{
// Compute the equation corresponding to x²+y²+z²=0 with p+t*d to obtain a quadratic equation
real a = ray.GetDirection().SquaredLength();
real b = 2.0 * ray.GetDirection() * ray.GetOrigin();
real c = ray.GetOrigin().SquaredLength() - sphere->GetRadius() * sphere->GetRadius();
real discriminant = b*b - 4*a*c;
// Discriminant >= 0 => the must be at least one intersection
if ( discriminant >= 0 )
{
// Compute the two potential intersections and only keep the nearest
real sqrtDisc = sqrt( discriminant );
real t = 0;
real t1 = ( -b - sqrtDisc ) / ( 2.0 * a );
real t2 = ( -b + sqrtDisc ) / ( 2.0 * a );
if ( t1 >= 0 )
{
t = t1;
oIntersection.IsInside( false );
}
else if ( t2 >= 0 )
{
t = t2;
oIntersection.IsInside( true );
}
else
return false;
oIntersection.SetPosition( ray.GetOrigin() + t * ray.GetDirection() );
oIntersection.SetNormal( oIntersection.GetPosition().Normalized() );
oIntersection.SetTextureCoordinates( oIntersection.GetPosition().Normalized() );
// The normal must be flipped to coincide with the hit direction
if ( oIntersection.IsInside() )
oIntersection.SetNormal( -oIntersection.GetNormal() );
return true;
}
return false;
}