Пример #1
0
        public int getMaterialIndex(Material material)
        {
            Debug.Assert(material.Reflectivity >= 0 && material.Reflectivity <= 1.0f);
            Debug.Assert(material.Transparency >= 0 && material.Transparency <= 1.0f);

            int materialIndex = _nextOpening;

            for (int i=0; i< _nextOpening; i++)
            {
                Material mat = _materialArray[i];

                if (mat == material)
                {
                    materialIndex = i;
                    break;
                }
            }

            System.Diagnostics.Debug.Assert(materialIndex < _materialArray.Length, "Maxium number of materials exceeded.");

            if (materialIndex == _nextOpening)
            {
                _materialArray[materialIndex] = material;
                _nextOpening++;
            }

            return materialIndex;
        }
Пример #2
0
 public virtual float getNearestIntersection(ref Ray r, ref Vector3 collisionPoint, ref Vector3 surfaceNormal, ref Material mat)
 {
     float nearestIntersection = float.PositiveInfinity;
     foreach (Sphere s in _spheres)
     {
         float intersection = r.intersects(s, ref collisionPoint, ref surfaceNormal);
         if (intersection < nearestIntersection)
         {
             nearestIntersection = intersection;
             mat = s.Material;
         }
     }
     return nearestIntersection;
 }
Пример #3
0
		public override float getNearestIntersection(ref Ray ray, ref Vector3 collisionPoint, ref Vector3 surfaceNormal, ref Material mat)
		{
			// Use KD-Tree to check for intersection
			Sphere primHit;
			float t = _tree.getNearestIntersection(ref ray, out primHit);

			if ( !float.IsPositiveInfinity(t) )
			{
				ray.Direction.Normalize();
				collisionPoint = ray.Origin + (Vector3)(t * ray.Direction);
				surfaceNormal = Vector3.Subtract(collisionPoint, primHit.Position);
				surfaceNormal.Normalize();

				collisionPoint = primHit.Position + primHit.Radius * surfaceNormal;

				mat = primHit.Material;
			}

			return t;
		}