当前位置: 首页>>代码示例>>C++>>正文


C++ Intersection::GetNormal方法代码示例

本文整理汇总了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() );
}
开发者ID:gnuvince,项目名称:ift3355-tp2,代码行数:11,代码来源:NodeIntersector.cpp

示例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;
}
开发者ID:gnuvince,项目名称:ift3355-tp2,代码行数:44,代码来源:SphereIntersector.cpp


注:本文中的Intersection::GetNormal方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。