예제 #1
0
 public float intersect(Ray ray)
 {
     P3 E = ray.origin;
     P3 O = this.center;
     P3 EO = O.sub(E);
     P3 V = ray.direction;
     float r = this.radius;
     float v = EO.dotProduct(V);
     float dot = EO.dotProduct(EO);
     float disc = (r * r) - (dot - (v * v));
     if (disc < 0)
     {
         return -1;
     }
     else
     {
         float d = (float)Math.Sqrt(disc);
         float time = (v - d);
         if (time < 0)
         {
             return -1;
         }
            return time;
     }
 }
예제 #2
0
        public RColor Coloring(P3 p, Ray r, SceneObject so)
        {
            P2 textureLoc = so.shape.toP2(p);
            RColor textureColor = so.texture.texture(textureLoc);
            RColor sumOfLights = new RColor(0, 0, 0);
            RColor lightColor;
            foreach (Light lightSource in Form1.lights)
            {
                lightColor = lightSource.illumination(p,so);
                sumOfLights = sumOfLights.add(lightColor);
            }

            return RColor.multiplyColor(textureColor, sumOfLights);
        }
예제 #3
0
 public float intersect(Ray r)
 {
     P3 o = r.origin;
     P3 v = r.direction;
     r = new Ray(o, v);
     if (n.dotProduct(v) < 0)
     {
         return -1;
     }
     float t = -(d + n.dotProduct(o)) / (n.dotProduct(v));
     if (t < 0)
     {
         return -1;
     }
     return t;
 }
예제 #4
0
 public float distance(Ray r)
 {
     return shape.intersect(r);
 }
예제 #5
0
 public RColor colorAt(P3 p, Ray r)
 {
     return skin.Coloring(p, r, this);
 }
예제 #6
0
        //public static SceneObject shootRay(Ray r, out double d)
        //{
        //    float dist;
        //    SceneObject obj = closest(r);
        //    if (obj == null)
        //    {
        //        return null;
        //    }
        //    dist = obj.distance(r);
        //    if (dist == infinity)
        //    {
        //        return null;
        //    }
        //    else
        //    {
        //        return obj;
        //    }
        //}
        //public static SceneObject closest(Ray ray)
        //{
        //    SceneObject sceneObj = null;
        //    float dist, smallestDist = infinity;
        //    foreach (SceneObject obj in objects)
        //    {
        //        if ((dist = obj.distance(ray)) <= smallestDist)
        //        {
        //            smallestDist = dist;
        //            sceneObj = obj;
        //        }
        //    }
        //    return sceneObj;
        //}
        public void noName()
        {
            for (int i = 0; i < size; i++)
            {
                for (int j = 0; j < size; j++)
                {
                    float size1 = size;
                    P3 p = new P3(i / size1 * 2.0f - 1, 0, j / size1 * 2.0f - 1);
                    Ray r = new Ray(camera, p.sub(camera).normalize());
                    float distance = sphere.intersect(r);
                    if (distance != -1)
                    {
                        P3 sp = r.travel(distance);
                        P3 n = sphere.normal(sp);
                        float intensity = n.dotProduct(direction);
                        if (intensity < 0)
                        {
                            intensity = 0;
                        }

                        pixels[i, j] = directional.scalarMultiply(intensity);

                    }
                    else
                    {
                        pixels[i, j] = new RColor(0, 0, 0);
                    }

                }
            }
            panel.Refresh();
        }