Exemple #1
0
 Bitmap create_map(Bitmap map, int z = 600)
 {
     for (int i = 0; i < map.Width; i++)
     {
         for (int j = 0; j < map.Height; j++)
         {
             ray r = new ray(Scene.camera, new Vector(i, j, z));
             r.init_color(3000);
             map.SetPixel(i, j, r.get_col());
         }
     }
     return(map);
 }
Exemple #2
0
        public void init_color(double max_dist)
        {
            double min_dist = max_dist;
            obj o = null;
            intersection? intersec = null;

            int x;
            if (dir.X == 250 && dir.Y == 250)
                x = 1;

            foreach (obj figure in Scene.list_obj)
            {
                intersection? intersec0 = figure.is_cross(this);
                if (intersec0 != null && intersec0.Value.dist < min_dist)
                {
                    min_dist = intersec0.Value.dist;
                    intersec = intersec0;
                    //this_col = figure.color_obj;
                    o = figure;
                }
            }


            if (min_dist < max_dist)
            {
                ray second_ray = new ray(intersec.Value.point, Scene.light);
                //MessageBox.Show(intersec.Value.point.Z + "");
                bool is_light = true;
                intersec = new intersection();
                foreach (obj figure in Scene.list_obj)
                {
                    if (!(figure is wall))
                    {
                        intersec = figure.is_cross(second_ray);
                        if (intersec != null)
                        {
                            is_light = false;
                            break;
                        }
                    }
                }
                if (is_light) this_col = o.color_obj;
            }

        }
Exemple #3
0
        public override intersection?is_cross(ray r)
        {
            var v1 = point - r.begin;
            var v2 = (r.dir - r.begin).Normalized();

            var temp = v2 * norm;

            if (temp >= 0)
            {
                return(null);
            }

            var t = (point - r.begin) * norm / temp;

            return(new intersection(r.begin + (v2.Normalized() * t), t));

            /*if (v2 * norm - Epsilon >= 0)
             *  return null;
             *
             * var angle = Vector.AngleBet(v1, v2);
             * var angle2 = Vector.AngleBet(v2, norm);
             *
             * float dist1 = (float)Vector.Dist(r.begin, point);
             * float dist2 = (float)Math.Sin(angle) * dist1;
             *
             * float dist3 = (float)(dist2 / (Math.Sin(angle2)));
             *
             * float dist4 = (float)(dist3 * (Math.Tan(angle2)));
             *
             * float dist5 = (float)Math.Sqrt(dist4 * dist4 - dist2 * dist2);
             *
             * float dist01 = (float)(dist1 * dist1);
             * float dist02 = (float)(dist2 * dist2);
             * float dist03 = (float)(dist01 - dist02);
             *
             * float dist6 = (float)Math.Sqrt(dist1 * dist1 - dist2 * dist2);
             *
             * float dist = dist5 + dist6;
             * if (dist < 1) return null;
             * return new intersection(r.begin + (v2.Normalized() * dist), dist);*/
        }
Exemple #4
0
        public override intersection?is_cross(ray r)
        {
            var v1    = r.begin - center;
            var v2    = r.begin - r.dir;
            var angle = Vector.AngleBet(v1, v2);
            var dist2 = Vector.Dist(r.begin, center);
            var dist1 = Math.Abs(Math.Sin(angle) * dist2);

            bool b = angle > Math.PI / 2;

            if (angle > Math.PI / 2 || dist1 > radius)
            {
                return(null);
            }

            var dist3 = Math.Abs(Math.Cos(angle) * dist2);
            var dist4 = dist3 - Math.Sqrt(radius * radius - dist1 * dist1);

            var v_cross = r.begin - v2.Normalized() * dist4;

            return(new intersection(v_cross, dist4));
        }
Exemple #5
0
 abstract public intersection?is_cross(ray r);