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


C++ Ray::apply方法代码示例

本文整理汇总了C++中Ray::apply方法的典型用法代码示例。如果您正苦于以下问题:C++ Ray::apply方法的具体用法?C++ Ray::apply怎么用?C++ Ray::apply使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Ray的用法示例。


在下文中一共展示了Ray::apply方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: trace

Colour Scene::trace(const Ray& ray)
{
	Shape *shape;
	float t = -255;

	shape = intersect(t, ray); //t is change

	if (shape == NULL)
		return Colour::black();


	vec3f incidentRay = ray.getDirection();
	vec3f point = ray.apply(t);

	return getShapeColor(shape, incidentRay, point);
}
开发者ID:Ilyazykov,项目名称:Ray-Tracing,代码行数:16,代码来源:Scene.cpp

示例2: getNormal

Vec3D Cylinder::getNormal(const Ray& ray, float distance, const CIsect& isect /*= CIsect()*/) const
{
	const Vec3D atSurface = ray.apply(distance);
  // Check, whether pnt is lying on caps
	// Bottom
	const Vec3D& toBottom = atSurface - mBottom;
	if (fabs(dot(mAxis, toBottom)) < FLOAT_ZERO && dot(toBottom, toBottom) < mRadius2)
	{
		return -mAxis;
	}
	const Vec3D& toTop = atSurface - mTop;
	if (fabs(dot(mAxis, toTop)) < FLOAT_ZERO && dot(toTop, toTop) < mRadius2)
	{
		return mAxis;
	}
    
	return (atSurface - mAxis * dot(toBottom, mAxis) - mBottom).toUnit();
}
开发者ID:DimkoChurinov,项目名称:raytracing,代码行数:18,代码来源:cylinder.cpp

示例3: intersect

CIsect Cylinder::intersect(const Ray& ray)
{
  const Vec3D& origin    = ray.getOrg();
  const Vec3D& direction = ray.getDir();

	const Vec3D& CO = origin - mBottom;
	
	const Vec3D& u = direction - mAxis * (dot(direction, mAxis));
	const Vec3D& v = CO - mAxis * (dot(CO, mAxis));

	CIsect res = CIsect(true);
	// Let a, b and c be coefficients of some square equation
	const float a = dot(u, u);
	float root		= 0.f;
	float closest = -1.f;
	float rayExit = -1.f;
	if (fabs(a) > FLOAT_ZERO)
	{
		const float b = 2 * dot(u, v);
		const float c = dot(v, v) - mRadius2;

		float D = b * b - 4 * a * c;

		// Complete miss
		if (D < 0.f) 
		{
			return CIsect(false);
		}

		D = sqrtf(D);

		// Calculate roots and take closest
		float denom = 1 / (2 * a);

		root = (-b - D) * denom;
		if (root >= 0.f)
		{
			Vec3D toBottom = ray.apply(root) - mBottom;
			Vec3D toTop		= ray.apply(root) - mTop;
			if (dot(mAxis, toBottom) > 0.f && dot(mAxis, toTop) < 0.f)
			{
				res.Dst.push_back(root);
				closest = root;
			}
		}
		root = (-b + D) * denom;
		if (root > 0.f)
		{
			// Awful copy paste :(
			Vec3D toBottom = ray.apply(root) - mBottom;
			Vec3D toTop		= ray.apply(root) - mTop;
			if (dot(mAxis, toBottom) > 0.f && dot(mAxis, toTop) < 0.f)
			{
				res.Dst.push_back(root);
				if (closest < 0.f)
				{
					root = closest;
				}
				else if (root < closest)
				{
					rayExit = closest;
					closest = root;
				}
				else
				{
					rayExit = root;
				}
			}
		}
	}
	
	// dot(va, (q - p1)) = 0   t = (dot(va, p1) - dot(va, p)) / dot(va, v)

	// Find intersection with caps
	// Bottom one
	float axisToDir = dot(mAxis, direction);

	if (fabs(axisToDir) < FLOAT_ZERO)
	{
		if (closest > 0.f)
		{
			res.Distance = closest;
			res.Object   = this;
			res.Normal	 = getNormal(ray, closest);
			if (rayExit < 0.f) 
			{
				res.InsideIntervals.push_back(Span(0.f, closest));
				res.Dst.insert(res.Dst.begin(), 0.f);
			}
			else
			{
				res.InsideIntervals.push_back(Span(closest, rayExit));
			}
			return res;
		}

		return CIsect(false);
	}

	float axisToOrg		= dot(mAxis, origin);
//.........这里部分代码省略.........
开发者ID:DimkoChurinov,项目名称:raytracing,代码行数:101,代码来源:cylinder.cpp


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