示例#1
0
bool IsShadowed(int currPrimitiveNum, Ray &rayToLight, float distanceToLight, Primitive *primitives, int numPrimitives)
{  
  TraceResult traceResult;
  traceResult.hit=false;
  // check all spheres 
  for(int i=0; i<numPrimitives; i++)
    {
      if( i == currPrimitiveNum ) continue;//no auto
      
      switch(primitives[i].type)
        {
	case SPHERE_TYPE: 
	  traceResult = IntersectSphere(*primitives[i].sphereProperties, rayToLight);
	  break;
	case PLANE_TYPE:
	  traceResult = IntersectPlane(*primitives[i].planeProperties, rayToLight);
	  break;
	case CYLINDER_TYPE:
	  traceResult = IntersectCylinder(*primitives[i].cylinderProperties, rayToLight);
	  break;
	case TRIANGLE_TYPE:
	  traceResult = IntersectTriangle(*primitives[i].triangleProperties, rayToLight);
	  break;
	default:
	  continue; 
	  break;
        }
        
      if( traceResult.hit && (traceResult.distance < distanceToLight) )
	return true;
        
    }
    
  return false;
}
示例#2
0
void KDTree::TraversalRope(KDTreeNode *N, Ray &ray,Point3 ray_Pos)
{
	if(N==NULL)
		return ;
	N = findLeaf(N,ray_Pos);
	Intersect(N->m_List->GetHead(),ray);
	Point3 Pos[8];
	Point3 hitPoint;
	int i;
	GetBoxVertex(N->box,Pos);

	for(i=0;i<6;i++)
		if(IntersectPlane(ray,ray_Pos,Pos[index[i][0]],Pos[index[i][1]],Pos[index[i][2]],Pos[index[i][3]],hitPoint))
			break;
	
	if(i>5)
		i++;
	ray_Pos = hitPoint;
	N = N->ropes[i];
	TraversalRope(N,ray,ray_Pos);
}