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


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

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


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

示例1: getCoords

    Point PlaneCoordMapper::getCoords(const Intersection& hit) const
	{
		/*
		//assumes local hit = hit - center;
		Vector dir = normal;
		Point center = Point::rep(0);
		Point local = hit.hitPoint();
		if(dot(dir, local - center) > 0)
		{
			dir = -dir;
		}
		//intersect ray (local, n) to plane (center, n)
		float temp = dot(dir , -dir);
		float distance = dot((center - local), -dir) / temp;
		Point hp = local + ((dir * distance) / dir.length());
		//calculate uv

		float u = (hp - center).length() * dot((hp - center).normalize(), e1.normalize()) / e1.length();
		float v = (hp - center).length() * dot((hp - center).normalize(), e2.normalize()) / e2.length();
		*/
		
		//Vector localV = hit.local() - Point::rep(0);
		Vector localV = hit.hitPoint() - Point::rep(0);
		float dist = localV.length();
		float u = dist * (dot(e1, localV) / dist / e1.length()) / e1.length();
		float v = dist * (dot(e2, localV) / dist / e2.length()) / e2.length();
		
		return Point(u, v, 0);
	}
开发者ID:atanas1054,项目名称:ray_tracer,代码行数:29,代码来源:plane.cpp

示例2: getRadianceRec

	RGBColor RecursiveRayTracingIntegrator::getRadianceRec(const Ray& ray, int counter) const
	{
		if(counter > 6)
		{
			return RGBColor::rep(0);
		}
		Intersection intersect  = world->scene->intersect(ray);
		if(intersect)
		{
			RGBColor color = RGBColor::rep(0.1f) + intersect.solid->material->getEmission(
				intersect.solid->texMapper->getCoords(intersect),
				intersect.normal(), -ray.d);
			Point p = intersect.hitPoint();
			if(intersect.solid->material->useSampling() == Material::Sampling::SAMPLING_NOT_NEEDED)
			{			
				for(int i = 0; i < world->light.size();i++)
				{
					LightHit lh = world->light[i]->getLightHit(p);

					float n1 = dot(ray.o-p, intersect.normal());
					float n2 = dot(lh.direction, intersect.normal());
					if((n1 > 0 && n2 > 0) || (n1 < 0 && n2 < 0))
					{
						Ray shadowRay = Ray(p, lh.direction);
						Intersection shadowIntrsct = world->scene->intersect(shadowRay, lh.distance);
						if(!shadowIntrsct)
						{
							RGBColor sourceColor = world->light[i]->getIntensity(lh);
							RGBColor reflectInt = intersect.solid->material->getReflectance(intersect.solid->texMapper->getCoords(intersect), intersect.normal(), -ray.d, lh.direction);
							RGBColor reflectColor = sourceColor * reflectInt;
							color = color + reflectColor;
							//color = color + reflectInt;
						}
					}
				}
			}
			else if(intersect.solid->material->useSampling() == Material::Sampling::SAMPLING_ALL)
			{
				Material::SampleReflectance sample = intersect.solid->material->getSampleReflectance(intersect.solid->texMapper->getCoords(intersect), intersect.normal(), -ray.d);
				RGBColor refColor = getRadianceRec(Ray(p, sample.direction), counter + 1);
				color = color + (refColor * sample.reflectance);
			}
			else if(intersect.solid->material->useSampling() == Material::Sampling::SAMPLING_SECONDARY)
			{
				for(int i = 0; i < world->light.size();i++)
				{
					LightHit lh = world->light[i]->getLightHit(p);

					float n1 = dot(ray.o-p, intersect.normal());
					float n2 = dot(lh.direction, intersect.normal());
					if((n1 > 0 && n2 > 0) || (n1 < 0 && n2 < 0))
					{
						Ray shadowRay = Ray(p, lh.direction);
						Intersection shadowIntrsct = world->scene->intersect(shadowRay, lh.distance);
						if(!shadowIntrsct)
						{
							RGBColor sourceColor = world->light[i]->getIntensity(lh);
							RGBColor reflectInt = intersect.solid->material->getReflectance(intersect.solid->texMapper->getCoords(intersect), intersect.normal(), -ray.d, -lh.direction);
							RGBColor reflectColor = sourceColor * reflectInt;
							color = color + reflectColor;
						}
					}
				}
				Material::SampleReflectance sample = intersect.solid->material->getSampleReflectance(intersect.solid->texMapper->getCoords(intersect), intersect.normal(), -ray.d);
				RGBColor refColor = getRadianceRec(Ray(intersect.hitPoint(), sample.direction), counter + 1);
				color = color + (refColor * sample.reflectance);
			}
			return color;
		}
		return RGBColor::rep(0);
	}
开发者ID:atanas1054,项目名称:ray_tracer,代码行数:71,代码来源:recraytrace.cpp

示例3: getRadiance

RGBColor RayMarchingIntegrator::getRadiance(const Ray& ray) const {
	Intersection intersection = world->scene->intersect(ray);
	if (intersection) {
		RGBColor color = RGBColor(0, 0, 0);
		Point local;
		if (intersection.solid->texMapper == nullptr) {
			local = WorldMapper(Float4::rep(1)).getCoords(intersection);
		} else {
			local = intersection.solid->texMapper->getCoords(intersection);
		}
		RGBColor emission;
		if (intersection.solid->material == nullptr) {
			float greyScale = fabs(dot(intersection.ray.d, intersection.normalVector));
			emission = RGBColor(greyScale, greyScale, greyScale);
		} else {
			emission = intersection.solid->material->getEmission(local, intersection.normalVector, -ray.d);
		}
		Material::SampleReflectance sample;
		Ray sampleRay;
		switch (intersection.solid->material->useSampling()) {
		case Material::SAMPLING_NOT_NEEDED:
			for (int i = 0; i < world->light.size(); i++) {
				LightHit shadowRay = world->light[i]->getLightHit(intersection.hitPoint());
				if (dot(intersection.normalVector, shadowRay.direction) > 0) {
					Ray shadow = Ray(intersection.hitPoint() + EPSILON * shadowRay.direction, shadowRay.direction);
					//TODO more epsilon?
					Intersection shadowRayIntersection = world->scene->intersect(shadow, shadowRay.distance);
					if (!shadowRayIntersection) {
						RGBColor reflectance;
						if (intersection.solid->material == nullptr) {
							reflectance = RGBColor(0.5, 0.5, 0.5);
						} else {
							if(intersection.solid->isFracLand){
								reflectance =
										intersection.solid->material->getReflectance(
												intersection.hitPoint(),
												intersection.normalVector,
												-ray.d, shadowRay.direction);
							}
							else{
								reflectance =
										intersection.solid->material->getReflectance(local,
												intersection.normalVector, -ray.d, shadowRay.direction);
							}
//														reflectance = intersection.solid->material->getReflectance(local,
//																							intersection.normalVector, -ray.d, shadowRay.direction);
						}
						RGBColor intensity = world->light[i]->getIntensity(shadowRay);
						RGBColor lightSourceColor = (reflectance * intensity);
						color = color + lightSourceColor;
					}
				}
			}
			break;

		case Material::SAMPLING_ALL:
			sample = intersection.solid->material->getSampleReflectance(intersection.hitPoint(),
					intersection.normalVector, -intersection.ray.d);
			//			sample = intersection.solid->material->getSampleReflectance(local, intersection.normalVector,
			//					-intersection.ray.d);
			sampleRay = Ray(intersection.hitPoint() + EPSILON * sample.direction, sample.direction);
			if (MarchRecursionDepth > MAX_RECURSION_DEPTH) {
				MarchRecursionDepth = 0.f;
			} else {
				MarchRecursionDepth++;
				color = color + getRadiance(sampleRay) * sample.reflectance;
			}
			break;

		case Material::SAMPLING_SECONDARY:
			for (int i = 0; i < world->light.size(); i++) {
				LightHit shadowRay = world->light[i]->getLightHit(intersection.hitPoint());
				if (dot(intersection.normalVector, shadowRay.direction) > 0) {
					Ray shadow = Ray(intersection.hitPoint() + EPSILON * intersection.normal(),
							shadowRay.direction);
					Intersection shadowRayIntersection = world->scene->intersect(shadow, shadowRay.distance);
					if (!shadowRayIntersection) {
						RGBColor reflectance = intersection.solid->material->getReflectance(local,
								intersection.normalVector, -ray.d, shadowRay.direction);
						RGBColor emission = intersection.solid->material->getEmission(local,
								intersection.normalVector, -ray.d);
						RGBColor intensity = world->light[i]->getIntensity(shadowRay);
						RGBColor lightSourceColor = (reflectance * intensity);
						color = color + lightSourceColor;
					}
				}
			}
			sample = intersection.solid->material->getSampleReflectance(local, intersection.normalVector,
					-intersection.ray.d);
			if (sample.direction != Vector(0, 0, 1) && sample.reflectance != RGBColor(0.f, 0.f, 0.f)) {
				sampleRay = Ray(intersection.hitPoint() + EPSILON * sample.direction, sample.direction);
				if (MarchRecursionDepth > MAX_RECURSION_DEPTH) {
					MarchRecursionDepth = 0;
				} else {
					MarchRecursionDepth++;
					color = color + getRadiance(sampleRay) * sample.reflectance;
				}
			}
			break;
		default:
//.........这里部分代码省略.........
开发者ID:Spide90,项目名称:Raytracer,代码行数:101,代码来源:rayMarching.cpp

示例4: getCoords

	Point WorldMapper::getCoords(const Intersection& hit) const 
	{
		Point p = hit.hitPoint();
		return Point(scale.x * p.x, scale.y * p.y, scale.z * p.z);
	}
开发者ID:atanas1054,项目名称:ray_tracer,代码行数:5,代码来源:worldmapper.cpp


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