示例#1
0
 public DirectionalLight(Vect3D d)
 {
     _direction = d.Hat();
     _intensity = 0.5f;
     _color = new RGBColor(1, 1, 1);
     _castsShadows = false;
 }
示例#2
0
 //Constructors
 public DirectionalLight()
 {
     _direction = (new Vect3D(-1, -1, -1)).Hat();
     _intensity = 0.5f;
     _color = new RGBColor(1, 1, 1);
     _castsShadows = false;
 }
示例#3
0
 public DirectionalLight(RGBColor c, float i, Vect3D d)
 {
     _color = new RGBColor(c);
     _intensity = i;
     _direction = d.Hat();
     _castsShadows = false;
 }
示例#4
0
 public ThinLensCamera()
     : base()
 {
     viewPlaneDistance = 250;
     focalPlaneDistance = 500;
     radius = 20;
     Up = new Vect3D(0, 1, 0);
     FOVERD = focalPlaneDistance / viewPlaneDistance;
 }
示例#5
0
        public override Point2D GetUV(Point3D hitPoint)
        {
            //Map hit point to a unit sphere by normalizing vector from origin to hit point.
            //Vector3 hitNormalized = Vector3.Normalize(hitPoint.Coordinates);
            Vect3D hitNormalized = new Vect3D(hitPoint).Hat();

            float phi = (float)Math.Atan2(hitNormalized.X, hitNormalized.Z) + FastMath.FPI;
            float omega = (float)Math.Acos(hitNormalized.Y);

            //Calculate spherical UV coordinates
            float u = phi * FastMath.FINVTWOPI;
            float v = 1 - (omega * FastMath.FINVPI);

            return new Point2D(u, v);
        }
示例#6
0
 public void compute_uvw()
 {
     _up = new Vect3D(0, 1, 0);
     w = _eye - _lookAt;
     w.Normalize();
     u = _up ^ w;
     u.Normalize();
     v = w ^ u;
 }
示例#7
0
        public override RGBColor F(ShadeRec sr, Vect3D incomingDirection, Vect3D reflectedDirection)
        {
            RGBColor L = new RGBColor(0.0f, 0.0f, 0.0f);
            float nDotWi = (sr.Normal * incomingDirection); //Dot product of normal and angle of incidence gives the angle of mirror reflection
            Vect3D r = new Vect3D(-incomingDirection + 2.0f * sr.Normal * nDotWi); //Vector describing direction of mirror reflection
            float rDotWo = (r * reflectedDirection);

            if (rDotWo > 0.0)
            {
                L = _specularReflectionCoefficient * (float)Math.Pow(rDotWo, _phongExponent) * _colorSpecular;
            }

            return L;
        }
示例#8
0
 protected override float EvaluateDistanceFunction(Point3D p, Vect3D d, ref float cur)
 {
     //Translate the point
     cur = EvaluateImplicitFunction(p);
     return (p.Coordinates - disp).Length() - r;
 }
 //Evaluates distance function at a given point in space. Can be overridden for special cases where exact distance function known (ie. sphere)
 protected virtual float EvaluateDistanceFunction(Point3D point, Vect3D distance, ref float cur)
 {
     //Distance (or at least the approximation of it) is a function d(x) = |f(x)/f'(x)|
     cur = EvaluateImplicitFunction(point);
     return Math.Abs(cur / EvaluateImplicitFunctionDerivative(point, distance));
 }
示例#10
0
        public void Rotate(float x, float y, float z)
        {
            Vect3D rot = new Vect3D(x, y, z);
            Matrix4x4 xmat = Matrix4x4.CreateRotationX(x * FastMath.THREESIXTYINVTWOPI);
            Matrix4x4 ymat = Matrix4x4.CreateRotationY(y * FastMath.THREESIXTYINVTWOPI);
            Matrix4x4 zmat = Matrix4x4.CreateRotationZ(z * FastMath.THREESIXTYINVTWOPI);
            Matrix4x4 xmatinv, ymatinv, zmatinv;
            Matrix4x4.Invert(xmat, out xmatinv);
            Matrix4x4.Invert(ymat, out ymatinv);
            Matrix4x4.Invert(zmat, out zmatinv);
            Matrix4x4 temp = xmat * ymat * zmat;
            Matrix4x4 inv_temp = zmatinv * ymatinv * xmatinv;

            inverseNetTransformationMatrix = inv_temp * inverseNetTransformationMatrix; //Post multiply for inverse transformation matrix
            netTransformationMatrix = netTransformationMatrix * temp; //Pre multiply for transformation matrix.
        }
示例#11
0
 public void Rotate(Vect3D rot)
 {
     Rotate(rot.X, rot.Y, rot.Z);
 }
示例#12
0
 //Copy constructor
 public Vect3D(Vect3D vector)
 {
     _coords = vector.Coordinates;
 }
示例#13
0
 public float AngleBetween(Vect3D b)
 {
     return (float)Math.Acos(this * b);
 }
示例#14
0
 public Normal(Vect3D v)
 {
     _coords = v.Coordinates;
 }
示例#15
0
        protected virtual float EvaluateImplicitFunctionDerivative(Point3D point, Vect3D direction)
        {
            //Find the points just in front of the provided point, and just behind it along the ray
            Point3D behind = point + (direction * EPSILON);
            Point3D infront = point - (direction * EPSILON);

            //Slope = rise over run
            return (EvaluateImplicitFunction(infront) - EvaluateImplicitFunction(behind)) * INVTWOEPSILON;
        }
示例#16
0
        /*
        public RenderableObject getHandle()
        {
            return payload;
        }
        public void setHandle(RenderableObject handle)
        {
            payload = handle;
        }
        */
        public void Translate(Vect3D trans)
        {
            Matrix4x4 temp = Matrix4x4.CreateTranslation(trans.Coordinates);
            Matrix4x4 inv_temp;
            Matrix4x4.Invert(temp, out inv_temp);

            inverseNetTransformationMatrix = inv_temp * inverseNetTransformationMatrix; //Post multiply for inverse transformation matrix
            netTransformationMatrix = netTransformationMatrix * temp; //Pre multiply for transformation matrix.
        }
示例#17
0
        //Approximates the gradient of F(p) at a given point p
        protected virtual Normal ApproximateNormal(Point3D p, Vect3D rd)
        {
            float f = EvaluateImplicitFunction(p);
            float f_x = EvaluateImplicitFunction(new Point3D(p.X + EPSILON, p.Y, p.Z));
            float f_y = EvaluateImplicitFunction(new Point3D(p.X, p.Y + EPSILON, p.Z));
            float f_z = EvaluateImplicitFunction(new Point3D(p.X, p.Y, p.Z + EPSILON));

            //Compute vector for normal
            Vect3D raw_normal = (new Vect3D((float)(f_x - f), (float)(f_y - f), (float)(f_z - f))).Hat();

            //Check if dot product is positive, if so, flip the vector so it's facing the ray origin
            if(raw_normal * rd.Hat() > 0.0f) { raw_normal = -raw_normal; }
            return (new Normal(raw_normal));
        }