Esempio n. 1
0
 //virtual public BoundingBox getBoundingBox() { return _boundingBox; }
 protected void CalculateNormals(Mesh parent)
 {
     if(GlobalVars.verbose)
     {
         System.Console.WriteLine("Calculating vertex normals for mesh " + parent.id);
     }
     //Get the list of faces attached to a given vertex
     for (int i = 0; i < parent.countVertices; i++)
     {
         //Sum together all the normals of the faces attached to this vertex
         List<int> faceList = parent.vertexFaces[i];
         Normal normalSum = new Normal(0,0,0);
         for(int j = 0; j < faceList.Count; j++)
         {
             normalSum += parent.NormalForFace(faceList[j]);
         }
         normalSum.Normalize();
         parent.normals[i] = normalSum;
     }
 }
Esempio n. 2
0
        /// <summary>
        /// Step 1 in rendering pipeline.
        /// Generic intersection detection for objectList called by a Tracer, returns ShadeRec describing intersection.
        /// </summary>
        /// <param name="ray">Ray for intersection calculation</param>
        /// <returns>ShadeRec object with all relevant information about object that was intersected for generating
        /// pixel data</returns>
        public ShadeRec HitObjects(Ray ray)
        {
            ShadeRec sr = new ShadeRec(this); // create shaderec

            // set normal and local hit point to non-null values
            Normal normal = new Normal();
            Point3D local_hit_point = new Point3D();

            float t = GlobalVars.K_HUGE_VALUE - 1.0f; // t value for corrent object
            float tmin = GlobalVars.K_HUGE_VALUE; //  current lowest t value
            int num_objects = _renderList.Count; // store count of objects to minimize unecessary member access
            Material closestmat = null; // material reference for closest object

            //Find the closest intersection point along the given ray
            for(int i = 0; i < num_objects; i++)
            {
                // Intersect each object in render list
                // First term evaluated first, therefore (t < tmin) will be doing a comparison of t value
                // of present object vs minimum t value.
                if (_renderList[i].Hit(ray, ref t, ref sr) && (t < tmin))
                {
                    sr.HitAnObject = true; // at least one intersection has occurred

                    // store temporary references to information about current object with minimum t
                    tmin = t;
                    closestmat = sr.ObjectMaterial;
                    sr.HitPoint = ray.Origin + t * ray.Direction; // calculate hit point in world space by adding t*direction to origin
                    normal = sr.Normal;
                    local_hit_point = sr.HitPointLocal;
                }
            }

            //If we hit an object, store local vars for closest object with ray intersection in sr before returning
            if(sr.HitAnObject)
            {
                sr.TMinimum = tmin;
                sr.Normal = normal;
                sr.HitPointLocal = local_hit_point;
                sr.ObjectMaterial = closestmat;
            }

            return (sr);
        }
        public override bool Hit(Ray r, ref float tMin, ref ShadeRec sr)
        {
            float t = GlobalVars.K_HUGE_VALUE;
            Normal normal = new Normal();
            Point3D localHitPoint = new Point3D();
            bool hit = false;
            tMin = GlobalVars.K_HUGE_VALUE;
            int countObjects = containedObjects.Count;
            Material closestObjectMaterial = null;

            //Traverse the list of renderable objects, and test for collisions in the same manner as in the world
            //hit function
            for(int i = 0; i < countObjects; i++)
            {
                if(containedObjects[i].Hit(r, ref t, ref sr) && (t<tMin))
                {
                    hit = true;
                    tMin = t;
                    closestObjectMaterial = sr.ObjectMaterial;
                    normal = sr.Normal;
                    localHitPoint = sr.HitPointLocal;
                }
            }

            if(hit)
            {
                sr.TMinimum = tMin;
                sr.Normal = normal;
                sr.HitPointLocal = localHitPoint;
                sr.ObjectMaterial = closestObjectMaterial;
            }

            return hit;
        }
Esempio n. 4
0
 public Vect3D(Normal normal)
 {
     _coords = normal.Coordinates;
 }
Esempio n. 5
0
 //Copy constructor
 public Normal(Normal n)
 {
     _coords = n.Coordinates;
 }
Esempio n. 6
0
        private Normal CalculateNormal(Point3D point)
        {
            Normal result = new Normal();

            float param_squared = _a * _a + _b * _b;

            float x = point.X;
            float y = point.Y;
            float z = point.Z;
            float sum_squared = x * x + y * y + z * z;

            result.X = 4.0f * x * (sum_squared - param_squared);
            result.Y = 4.0f * y * (sum_squared - param_squared + 2.0f * _a * _a);
            result.Z = 4.0f * z * (sum_squared - param_squared);
            result.Normalize();

            return result;
        }
Esempio n. 7
0
 public Plane(Point3D point, Normal normal)
 {
     _p = point;
     _n = normal;
 }
Esempio n. 8
0
 public Plane()
 {
     _p = new Point3D(0, 0, 0);
     _n = new Normal(0, 1, 0);
 }
Esempio n. 9
0
 public Point3D(Normal normal)
 {
     _coords = normal.Coordinates;
 }