示例#1
0
        public P2 toP2(P3 p)
        {
            P3 Vp = this.normal(p);
                float b = -Vn.dotProduct(Vp);
                float h = Vp.dotProduct(Ve);

                float u;

                float dotProduct = (float)Math.Min(1, Math.Max(-1, b));
                float phi = (float)Math.Acos(dotProduct);
                float v = (float)(phi / Math.PI);
                float dotCross = Vp.dotProduct(P3.crossProduct(Vn,Ve));
                float dotProduct2 = (float)Math.Min(1, Math.Max(-1, h / Math.Sin(phi)));
                float theta = (float)((Math.Acos(dotProduct2)) / (2 * Math.PI));
                if(dotCross > 0)
                {
                    u = theta;
                }
                else
                {
                    u = 1 - theta;
                }

                return new P2(u, v);
        }
示例#2
0
        public RColor illumination(P3 p, SceneObject so)
        {
            P3 surfaceNormal = so.shape.normal(p);
            float shade = surfaceNormal.dotProduct(this.direction);

            if (shade < 0)
            {
                return new RColor(0, 0, 0);
            }
            else
            {
                return this.color.scalarMultiply(shade);
            }
        }
示例#3
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);
        }
示例#4
0
 public P3 sub(P3 v)
 {
     return new P3(v.x - this.x, v.y - this.y, v.z - this.z);
 }
示例#5
0
 public float normLength(P3 v)
 {
     return (float)Math.Sqrt(x * x + y * y + z * z);
 }
示例#6
0
 public float dotProduct(P3 v)
 {
     return x * v.x + y * v.y + z * v.z;
 }
示例#7
0
 public P3 add(P3 v)
 {
     return new P3(v.x + this.x, v.y + this.y, v.z + this.z);
 }
示例#8
0
 public static P3 mul(P3 p, P3 p2)
 {
     return new P3(p.x * p2.x, p.y * p2.y, p.z * p2.z);
 }
示例#9
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();
        }
示例#10
0
 public P3 normal(P3 p)
 {
     P3 v2 = p.sub(this.center);
     return v2.scale(1 / radius);
 }
示例#11
0
 public Directional(RColor color, P3 direction)
 {
     this.color = color;
     this.direction = direction.normalize();
 }
示例#12
0
 public RColor colorAt(P3 p, Ray r)
 {
     return skin.Coloring(p, r, this);
 }
示例#13
0
 public RColor illumination(P3 p, SceneObject so)
 {
     return this.color;
 }
示例#14
0
 public P2 toP2(P3 p)
 {
     return new P2(0, 0);
 }
示例#15
0
 public P3 normal(P3 p)
 {
     return n;
 }
示例#16
0
 public Plane(P3 p, P3 n)
 {
     this.p = p;
     this.n = n;
     this.d = -(n.dotProduct(p));
 }
示例#17
0
 public Ray(P3 origin, P3 direction)
 {
     this.direction = (direction).normalize();
     this.origin = origin;
 }
示例#18
0
 private void pitchBar_Scroll(object sender, ScrollEventArgs e)
 {
     direction = P3.fromSpherical(3.5f, pitchBar.Value);
     noName();
 }
示例#19
0
 public Sphere(P3 center, float radius)
 {
     this.center = center;
     this.radius = radius;
 }
示例#20
0
 public static P3 crossProduct(P3 a, P3 b)
 {
     return new P3(a.y * b.z - a.z * b.y, a.z * b.x - a.x * b.z, a.x * b.y - a.y * b.x);
 }
示例#21
0
 private void headingBar_Scroll(object sender, ScrollEventArgs e)
 {
     direction = P3.fromSpherical(headingBar.Value, 3.1f);
     noName();
 }
示例#22
0
 private void zoomBar_Scroll(object sender, ScrollEventArgs e)
 {
     camera = new P3(0, zoomBar.Value, 0);
     noName();
 }