Beispiel #1
0
        public InsertsectResult insertsect(Ray3 ray)
        {
            float            minDistance = 100000000;
            InsertsectResult minCom      = new InsertsectResult();
            int len = list.Count;

            for (int i = 0; i < len; i++)
            {
                InsertsectResult result = list[i].insertsect(ray);
                if (result.sphere != null && result.distance < minDistance)
                {
                    minDistance = result.distance;
                    minCom      = result;
                }
            }
            return(minCom);
        }
Beispiel #2
0
        public override InsertsectResult insertsect(Ray3 ray)
        {
            Vector3 v  = ray.getOrigin.sub(this.center);
            float   c  = (v.unSqrtLength() - this.sqrtRadius);
            float   dv = ray.getDirection.dot(v);

            if (dv <= 0)
            {
                float dis = dv * dv - c;
                if (c >= 0)
                {
                    float            distance   = -dv - (float)Math.Sqrt(dis);
                    Vector3          position   = ray.getPoint(distance);
                    Vector3          normal     = position.sub(this.center).nor();
                    InsertsectResult insertsect = new InsertsectResult(this, distance, position, normal);
                    return(insertsect);
                }
            }
            return(new InsertsectResult());
        }
Beispiel #3
0
 public void renderMulCom(Union union, PrespectCamera camera, int depth, Bitmap bitmap, int width, int height)
 {
     camera.init();
     for (int i = 0; i < height; i++)
     {
         float sy = 1 - i / (float)height;
         for (int k = 0; k < width; k++)
         {
             float            sx     = k / (float)width;
             Ray3             ray    = camera.GenerRay(sx, sy);
             InsertsectResult insert = union.insertsect(ray);
             if (insert.sphere != null && insert.distance > 0)
             {
                 int dep = 255 - Math.Min((int)((insert.distance / depth) * 255), 255);
                 //Color color = Color.FromArgb(dep, dep, dep);
                 Color color = Color.FromArgb((int)((insert.normal.x + 1) * 128), (int)((insert.normal.y + 1) * 128), (int)((insert.normal.z + 1) * 128));
                 bitmap.SetPixel(k, i, color);
             }
         }
     }
     this.g.DrawImage(bitmap, new Point(0, 0));
 }
Beispiel #4
0
        public static ColorChannel calcReflectChannel(Union b, Ray3 ray, int reflectTime)
        {
            InsertsectResult result = b.insertsect(ray);

            if (result.sphere != null)
            {
                float        reflectiveness = result.sphere.material.reflectiveness;
                ColorChannel color          = result.sphere.material.calcColor(ray, result.position, result.normal);
                color = color.mul(1 - reflectiveness);
                if (reflectiveness > 0 && reflectTime > 0)
                {
                    Vector3      tmpDir = result.normal.mul(-2 * result.normal.dot(ray.getDirection)).add(ray.getDirection);
                    Ray3         newRay = new Ray3(result.position, tmpDir);
                    ColorChannel tmp    = calcReflectChannel(b, newRay, reflectTime - 1);
                    color = color.add(tmp.mul(reflectiveness));
                }
                return(color);
            }
            else
            {
                return(Constant.black);
            }
        }