Example #1
0
 public Triangle(Vector pointA, Vector pointB, Vector pointC, Matrices transform, Color color)
     : base(transform,color)
 {
     this.pointA = pointA;
     this.pointB = pointB;
     this.pointC = pointC;
 }
Example #2
0
 public static Vector CrossProduct(Vector u, Vector v)
 {
     Vector crossProduct = new Vector(u.y * v.z - u.z * v.y,
                                      u.z * v.x - u.x * v.z,
                                      u.x * v.y - u.y * v.x);
     return crossProduct;
 }
Example #3
0
 public Ray(Vector position, Vector direction)
 {
     this.position = position;
     this.direction = direction;
     this.intersectDistance = double.MaxValue;
     this.IntersectWith = null;
     this.color = Color.FromArgb(0, 0, 0);
 }
Example #4
0
 public void CalculateUpperLeft()
 {
     Vector center = camera.GetLookFrom();
     center -= camera.GetVectorW();
     position = center;
     upperLeft = center - camera.GetVectorU() * (worldWidth / 2)
                 + camera.GetVectorV() * (worldHeight / 2);
 }
Example #5
0
 public Camera(double[] param)
 {
     this.lookFrom = new Vector(param[0], param[1], param[2]);
     this.lookAt = new Vector(param[3], param[4], param[5]);
     this.up = new Vector(param[6], param[7], param[8]);
     this.fovy = param[9];
     CalculateUVW();
     this.fovx = Func.RadianToDegree(Math.Atan(CalculateFOVX())) * 2;
 }
Example #6
0
 public Camera(double LookFromX, double LookFromY, double LookFromZ,
        double LookAtX, double LookAtY, double LookAtZ,
        double UpX, double UpY, double UpZ, 
        double fovy)
 {
     this.lookFrom = new Vector(LookFromX, LookFromY, LookFromZ);
     this.lookAt = new Vector(LookAtX, LookAtY, LookAtZ);
     this.up = new Vector(UpX, UpY, UpZ);
     this.fovy = fovy;
     CalculateUVW();
     this.fovx = Func.RadianToDegree(Math.Atan(CalculateFOVX()))*2;
 }
Example #7
0
        private bool PointInTriangle(Vector pointT)
        {
            Vector v0 = this.pointC - this.pointA;
            Vector v1 = this.pointB - this.pointA;
            Vector v2 = pointT - this.pointA;

            double dot00 = Vector.DotProduct(v0, v0);
            double dot01 = Vector.DotProduct(v0, v1);
            double dot02 = Vector.DotProduct(v0, v2);
            double dot11 = Vector.DotProduct(v1, v1);
            double dot12 = Vector.DotProduct(v1, v2);

            double invDenom = 1 / (dot00 * dot11 - dot01 * dot01);
            double u = (dot11 * dot02 - dot01 * dot12) * invDenom;
            double v = (dot00 * dot12 - dot01 * dot02) * invDenom;

            return (u >= 0) && (v >= 0) && (u + v < 1);
        }
Example #8
0
 public Sphere(Vector center, double radius,Matrices transform, Color color)
     : base(transform,color)
 {
     this.center = center;
     this.radius = radius;
 }
Example #9
0
 public void SetDirection(Vector direction)
 {
     this.direction = direction;
 }
Example #10
0
 public void SetPosition(Vector position)
 {
     this.position = position;
 }
Example #11
0
 private void CalculateUVW()
 {
     Vector a = lookFrom - lookAt;
     Vector b = up;
     this.w = a / a.Distance();
     this.u = Vector.CrossProduct(b, this.w) / Vector.CrossProduct(b, this.w).Distance();
     this.v = Vector.CrossProduct(this.w, this.u);
 }
Example #12
0
 public static double DotProduct(Vector u, Vector v)
 {
     return u.x * v.x + u.y * v.y + u.z * v.z;
 }