Beispiel #1
0
//non-accelerate castShadowRay
bool RayTracer::castShadowRay(Vec3f point, Vec3f lightDir, float distanceToLight) const
{
	Group *group = s->getGroup();
	int numOfPrim = group->getNumber();
	Object3D* instance;
	Ray r(lightDir,point);

	Material* material =NULL;
	Hit hit(distanceToLight,material,Vec3f(1,1,1));
	for(int i=0; i<numOfPrim; i++)
	{
		instance = group->getObject(i);
		if(instance->intersect(r,hit,0) == 1) //设置tmin为EPSILON
		{
			return 1;
		}
	}
	//没有相交
	return 0;
}
Beispiel #2
0
bool Grid::intersectWithOverlapObject(const Ray & r, Hit & h, float tmin) const
{
	MarchInfo mi;

	bool re = initializeRayMarch ( mi, r, tmin );
	if ( re == false ) {
		return false;
	}

	int index_i, index_j, index_k;

	while ( IsCellValid(mi) ) 
	{
		RayTracing_Stats::IncrementNumGridCellsTraversed();

		index_i = mi.get_i();
		index_j = mi.get_j();
		index_k = mi.get_k();

		Object3DVector & obj_array = cells[num_y * num_z * index_i + num_z * index_j + index_k].objs;
		
		int num_objs = obj_array.getNumOfObjects();
		if ( num_objs > 0 ) 
		{
			bool flag = false;
			
			for (int i = 0; i < num_objs; ++i) {
				Object3D * obj = obj_array.getObject(i);
				
				if (obj->intersect(r, h, tmin) == true)
					flag = true;
			}

			if ( flag ) return true;
		}
		
		mi.nextCell();
	}

	return false;
}