Beispiel #1
0
        public void line_rotate_rad(float rang, Point3D p1, Point3D p2)
        {
            p2 = new Point3D(p2.x - p1.x, p2.y - p1.y, p2.z - p1.z);
            p2 = Point3D.norm(p2);

            float[,] mt = get_matrix();
            apply_matrix(rotate_around_line(mt, p1, p2, rang));
        }
Beispiel #2
0
        // вычисление локальной модели освещения
        public Point3D shade(Point3D hit_point, Point3D normal, Point3D color_obj, float diffuse_coef)
        {
            Point3D dir = point_light - hit_point;

            dir = Point3D.norm(dir);                // направление луча из источника света в точку удара

            Point3D diff = diffuse_coef * color_light * Math.Max(Point3D.scalar(normal, dir), 0);

            return(new Point3D(diff.x * color_obj.x, diff.y * color_obj.y, diff.z * color_obj.z));
        }
Beispiel #3
0
        public static Point3D norm(Side S)
        {
            if (S.points.Count() < 3)
            {
                return(new Point3D(0, 0, 0));
            }
            Point3D U      = S.get_point(1) - S.get_point(0);
            Point3D V      = S.get_point(S.points.Count - 1) - S.get_point(0);
            Point3D normal = U * V;

            return(Point3D.norm(normal));
        }
Beispiel #4
0
        public override bool figure_intersection(Ray r, out float t, out Point3D normal)
        {
            t      = 0;
            normal = null;

            if (ray_sphere_intersection(r, points[0], radius, out t) && (t > EPS))
            {
                normal = (r.start + r.direction * t) - points[0];
                normal = Point3D.norm(normal);
                return(true);
            }
            return(false);
        }
Beispiel #5
0
        public override bool figure_intersection(Ray r, out float t, out Point3D normal)
        {
            t      = 0;
            normal = null;

            if (ray_sphere_intersection(r, points[0], radius, out t) && (t > EPS))
            {
                normal = (r.start + r.direction * t) - points[0];
                normal = Point3D.norm(normal);
                figure_material.clr = new Point3D(drawing_pen.Color.R / 255f, drawing_pen.Color.G / 255f, drawing_pen.Color.B / 255f);
                return(true);
            }
            return(false);
        }
Beispiel #6
0
 public void run_rayTrace()
 {
     get_pixels();
     for (int i = 0; i < w; ++i)
     {
         for (int j = 0; j < h; ++j)
         {
             Ray r = new Ray(focus, pixels[i, j]);
             r.start = new Point3D(pixels[i, j]);
             Point3D clr = RayTrace(r, 10, 1);
             if (clr.x > 1.0f || clr.y > 1.0f || clr.z > 1.0f)
             {
                 clr = Point3D.norm(clr);
             }
             color_pixels[i, j] = Color.FromArgb((int)(255 * clr.x), (int)(255 * clr.y), (int)(255 * clr.z));
         }
     }
 }
Beispiel #7
0
        // преломление
        public Ray refract(Point3D hit_point, Point3D normal, float eta)
        {
            Ray   res_ray = new Ray();
            float sclr    = Point3D.scalar(normal, direction);

            float k = 1 - eta * eta * (1 - sclr * sclr);

            if (k >= 0)
            {
                float cos_theta = (float)Math.Sqrt(k);
                res_ray.start     = new Point3D(hit_point);
                res_ray.direction = Point3D.norm(eta * direction - (cos_theta + eta * sclr) * normal);
                return(res_ray);
            }
            else
            {
                return(null);
            }
        }
Beispiel #8
0
 public Ray(Point3D st, Point3D end)
 {
     start     = new Point3D(st);
     direction = Point3D.norm(end - st);
 }