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


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

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


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

示例1: getIntersection

bool Mesh::getIntersection(const Ray & ray, float & t, Vec3<float> & normal) const{
	Plane plane;
	Vec3<float> normalOutput, vertices4;
	bool colision=false;
	float pointIntersection;
	t=inf;
	
	for(size_t i = 0; i < poligons.size(); i++) {	
		plane.setPlane(poligons[i].vertices1,poligons[i].vertices2,poligons[i].vertices3);
		if(plane.getIntersection(ray,pointIntersection,normal)) {
			vertices4 = ray.eval(pointIntersection);

            if(getIntersectionTriangle(poligons[i].vertices1, poligons[i].vertices2, poligons[i].vertices3, vertices4) && pointIntersection < t) {
                t=pointIntersection;
                normalOutput=normal;
                colision=true;
            }
        }
	}

	if(colision) {
		normal = normalOutput;
		return true;
	}

	return false;
}
开发者ID:ssyp,项目名称:pathtracer,代码行数:27,代码来源:Mesh.cpp

示例2: intersect

bool Box::intersect(const Ray & ray, Intersection & it)
{
	Vector3f normal0, normal1, normalVec;
	float t0 = 0, t1 = FLT_MAX;
	float _t0, _t1;
	for (int i = 0; i < 3; ++i) {
		if (slabs[i].normal.dot(ray.D)) {
			float NdotQ = slabs[i].normal.dot(ray.Q);
			float NdotD = slabs[i].normal.dot(ray.D);
			_t0 = -(slabs[i].d0 + NdotQ) / NdotD;
			_t1 = -(slabs[i].d1 + NdotQ) / NdotD;
			if (_t0 > _t1) {
				float temp = _t0;
				_t0 = _t1;
				_t1 = temp;
			}
			normalVec = slabs[i].normal;
		} else {
			float NdotQ = slabs[i].normal.dot(ray.Q);
			float s0 = NdotQ + slabs[i].d0;
			float s1 = NdotQ + slabs[i].d1;
			if (s0 * s1 < 0.0f) {
				_t0 = 0.0f;
				_t1 = FLT_MAX;
			} else return false;
		}

		if (t0 < _t0) {
			t0 = _t0;
			normal0 = normalVec;
		}
		if (t1 > _t1) {
			t1 = _t1;
			normal1 = normalVec;
		}
	}

	if (t0 > t1) return false;
	else if (t0 > epsilon) {
		it.t = t0; 
		it.normal = normal0;
	}
	else if (t1 > epsilon) {
		it.t = t1;
		it.normal = normal1;
	}
	else return false;

	it.pos = ray.eval(it.t);
	it.normal.normalize();
	Vector3f cornerToIt = it.pos - corner;
	if (cornerToIt[0] < epsilon || cornerToIt[1] < epsilon || cornerToIt[2] < epsilon) {
		if (it.normal.dot(diag) > 0.0f) it.normal *= -1;
	} else if (it.normal.dot(diag) < 0.0f) it.normal *= -1;
	it.pS = this;
	return true;
}
开发者ID:KoumaTeacup,项目名称:CS500,代码行数:57,代码来源:shape.cpp

示例3: intersection

/**
 * Calculates whether a ray intersects with a sphere. Returns true or false,
 * storing the collision point in result if true.
 */
bool Sphere::intersection(Ray prim_ray, Vec3 &result) {
  double t0, t1;
  Vec3 obj_center(pos);

  Vec3 L = (*prim_ray.p1) - obj_center;

  double a = prim_ray.p2->dot(*prim_ray.p2);
  double b = 2 * prim_ray.p2->dot(L);
  double c = L.dot(L) - (radius * radius);

  if(!solve_quadratic(a, b, c, t0, t1)) {
    return false;
  } else {
    prim_ray.eval(t0, result);
    return true;
  }
}
开发者ID:pacebl,项目名称:luaray,代码行数:21,代码来源:sphere.cpp

示例4: getIntersection

bool Cube::getIntersection(const Ray & ray, float & t, Vec3<float> & normal) const {
	Plane add1(Vec3<float>(min.x, min.y, min.z), Vec3<float>(max.x, min.y, min.z), Vec3<float>(max.x, min.y, max.z));
    Plane dd1c1(Vec3<float>(max.x, min.y, min.z), Vec3<float>(max.x, min.y, max.z), Vec3<float>(max.x, max.y, max.z));
	Plane adc(Vec3<float>(min.x, min.y, min.z), Vec3<float>(max.x, min.y, min.z), Vec3<float>(max.x, max.y, min.z));
	Plane abb1(Vec3<float>(min.x, min.y, min.z), Vec3<float>(min.x, max.y, min.z), Vec3<float>(min.x, max.y, max.z));
	Plane bcc1(Vec3<float>(min.x, max.y, min.z), Vec3<float>(max.x, max.y, min.z), Vec3<float>(max.x, max.y, max.z));
	Plane a1b1c1(Vec3<float>(min.x, min.y, max.z), Vec3<float>(min.x, max.y, max.z), Vec3<float>(max.x, max.y, max.z));
	
	Vec3<float> pointIntersection, minValue, maxValue, normal1, normalP;
	float t1, tP;
	t1 = inf;
	
	if(add1.getIntersection(ray, tP, normalP)) {
		pointIntersection = ray.eval(tP);
		minValue.x = min.x;
		minValue.y = min.y;
		minValue.z = min.z;
		maxValue.x = max.x;
		maxValue.y = min.y;
		maxValue.z = max.z;		
		if ((pointIntersection >= minValue) && (pointIntersection <= maxValue)) {		
			if(tP < t1) {
				t1 = tP;
				normal1 = normalP;
			}
		}
	}

   if(dd1c1.getIntersection(ray, tP, normalP)) {
		pointIntersection = ray.eval(tP);
		minValue.x = max.x;
		minValue.y = min.y;
		minValue.z = min.z;
		maxValue.x = max.x;
		maxValue.y = max.y;
		maxValue.z = max.z;
		if (pointIntersection >= minValue && pointIntersection <= maxValue) {
			if(tP < t1) {
				t1 = tP;
				normal1 = normalP;
			}
		}
	}
	if(adc.getIntersection(ray, tP, normalP)) {
		pointIntersection = ray.eval(tP);
		minValue.x = min.x;
		minValue.y = min.y;
		minValue.z = min.z;
		maxValue.x = max.x;
		maxValue.y = max.y;
		maxValue.z = min.z;	
		if (pointIntersection >= minValue && pointIntersection <= maxValue) {
			if(tP < t1) {
				t1 = tP;
				normal1 = normalP;
			}
		}
	}
	if(abb1.getIntersection(ray, tP, normalP)) {
		pointIntersection = ray.eval(tP);
		minValue.x = min.x;
		minValue.y = min.y;
		minValue.z = min.z;
		maxValue.x = min.x;
		maxValue.y = max.y;
		maxValue.z = max.z;
		if (pointIntersection >= minValue && pointIntersection <= maxValue) {
			if(tP < t1) {
				t1 = t;
				normal1 = normalP;
			}
		}
	}
	if(bcc1.getIntersection(ray, tP, normalP)) {
		pointIntersection = ray.eval(tP);
		minValue.x = min.x;
		minValue.y = max.y;
		minValue.z = min.z;
		maxValue.x = max.x;
		maxValue.y = max.y;
		maxValue.z = max.z;
		if (pointIntersection >= minValue && pointIntersection <= maxValue) {
			if(tP < t1) {
				t1 = tP;
				normal1 = normalP;
			}
		}
	}
	if(a1b1c1.getIntersection(ray, tP, normalP)) {
		pointIntersection = ray.eval(tP);
		minValue.x = min.x;
		minValue.y = min.y;
		minValue.z = max.z;
		maxValue.x = max.x;
		maxValue.y = max.y;
		maxValue.z = max.z;
		if (pointIntersection >= minValue && pointIntersection <= maxValue) {
			if(tP < t1) {
				t1 = tP;
				normal1 = normalP;
//.........这里部分代码省略.........
开发者ID:ssyp,项目名称:pathtracer,代码行数:101,代码来源:Cube.cpp


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