Exemple #1
0
        public override void debug(Surface screen)
        {
            float  newradius = (float)Math.Sqrt(Radius2 - Location.Y);
            VPoint middle    = Location;

            middle.Y = 0;
            VPoint previousDrawPoint = new VPoint(0, 0, 1);

            previousDrawPoint  = previousDrawPoint.Normalize() * Radius;
            previousDrawPoint += middle;
            for (int i = 1; i < 121; i++)
            {
                VPoint DrawPoint = new VPoint(Game.SinTable[(i * 3) % 360], 0, Game.SinTable[(i * 3 + 90) % 360]);
                DrawPoint  = DrawPoint.Normalize() * Radius;
                DrawPoint += middle;
                int x1, x2;
                x1 = DrawPoint.transform("x");
                x2 = previousDrawPoint.transform("x");
                if (x1 <= 512 && x2 <= 512)
                {
                    screen.Line(x1, DrawPoint.transform("y"), x2, previousDrawPoint.transform("y"), Mat.GetColor(new VPoint(0, 0, 0)).getColor());
                }
                previousDrawPoint = DrawPoint;
            }
        }
Exemple #2
0
 // Create ray
 public Ray(VPoint Locationinit, VPoint Directioninit)
 {
     Location  = Locationinit;
     Direction = Directioninit.Normalize();
     Distance  = float.PositiveInfinity;
     recursion = 0;
 }
Exemple #3
0
 // Determine the colors on the scene
 public VPoint color(Scene scene)
 {
     if (ThingWeIntersectedWith != null)
     {
         ShadowRays = new Ray[scene.Lights.Length];
         VPoint diffusion = new VPoint();
         for (int i = 0; i < scene.Lights.Length; i++)
         {
             Light  light = scene.Lights[i];
             VPoint shadowRayDirection = (light.Location - Location);
             ShadowRays[i]          = new Ray(Location + 0.00001f * shadowRayDirection.Normalize(), shadowRayDirection.Normalize());
             ShadowRays[i].Distance = shadowRayDirection.Length;
             float distance = scene.intersect(ShadowRays[i]).Distance;
             if (distance >= shadowRayDirection.Length - 2 * 0.00001)
             {
                 ShadowRays[i].Distance = distance;
                 VPoint j = ThingWeIntersectedWith.normal(Location).Direction;
                 if (j * Ray.Direction > 0)
                 {
                     j *= -1;
                 }
                 diffusion += light.reflectedColor(ThingWeIntersectedWith.Mat.GetColor(Location), 60 * Math.Max(0, j * ShadowRays[i].Direction.Normalize()) * (1 / (shadowRayDirection.Length * shadowRayDirection.Length)));
             }
         }
         diffusion = new VPoint(Math.Min(diffusion.X, 255), Math.Min(diffusion.Y, 255), Math.Min(diffusion.Z, 255));
         if (ThingWeIntersectedWith.Mat.Reflects != 0 && Ray.recursion < Game.Recursion)
         {
             secondaryRay           = ThingWeIntersectedWith.Reflect(Ray, Location);
             secondaryRay.recursion = Ray.recursion + 1;
             Intersection inter = scene.intersect(secondaryRay);
             if (inter.ThingWeIntersectedWith == scene.Primitives[0])
             {
                 secondaryRay.Distance = 3;
             }
             else
             {
                 secondaryRay.Distance = inter.Distance;
             }
             return(VPoint.colorStuff(inter.color(scene), diffusion, ThingWeIntersectedWith.Mat.Reflects));
         }
         else
         {
             return(diffusion);
         }
     }
     return(new VPoint());
 }
Exemple #4
0
 // Create the plane
 public Plane(VPoint normal, float distance, Material mat)
 {
     Mat      = mat;
     Normal   = normal.Normalize();
     Distance = distance;
 }