Example #1
0
        public void Tick()
        { 
            KeyboardHandler.Update();
            screen.Clear(0);
            rayTracer.Draw(viewScreen, debugScreen);

            AddSurface(0, 0, viewScreen);
            AddSurface(screen.width - debugScreen.width, 0, debugScreen);
        }
Example #2
0
 // initialize
 public void Init()
 {
     //Screen size is defined in the template.cs
     viewScreen = new Surface(OpenTKApp.VIEW_WIDTH, OpenTKApp.VIEW_HEIGHT);
     debugScreen = new Surface(OpenTKApp.DEBUG_WIDTH, OpenTKApp.DEBUG_HEIGHT);
     rayTracer = new RayTracer(screen, debugScreen);
     KeyboardHandler.Init();
     Debugger.DrawDebug();
 }
Example #3
0
        public void Update()
        {
            if (KeyboardHandler.IsAnyKeyDown())
            {
                IsMoving = true;
            }
            else
            {
                IsMoving = false;
            }

            //Rotation control
            #region Rotation
            //rotate left
            if (KeyDown(Key.Left))
            {
                Vector3 v = Center;
                v        -= 0.01f * Vector3.Normalize(TopRight - TopLeft);
                direction = Vector3.Normalize(v - position);
            }

            //rotate right
            if (KeyDown(Key.Right))
            {
                Vector3 v = Center;
                v        += 0.01f * Vector3.Normalize(TopRight - TopLeft);
                direction = Vector3.Normalize(v - position);
            }

            //rotate up
            if (KeyDown(Key.Up) && direction.Y < 0.9f)
            {
                Vector3 v = Center;
                v        -= 0.01f * Vector3.Normalize(BottomLeft - TopLeft);
                direction = Vector3.Normalize(v - position);
            }

            //rotate down
            if (KeyDown(Key.Down) && direction.Y > -0.9f)
            {
                Vector3 v = Center;
                v        += 0.01f * Vector3.Normalize(BottomLeft - TopLeft);
                direction = Vector3.Normalize(v - position);
            }
            #endregion

            //Movement control
            #region Movement
            //move forwards
            if (KeyDown(Key.W))
            {
                position.X += 0.05f * direction.X;
                position.Z += 0.05f * direction.Z;
            }

            //move backwards
            if (KeyDown(Key.S))
            {
                position.X -= 0.05f * direction.X;
                position.Z -= 0.05f * direction.Z;
            }

            //move rightwards
            if (KeyDown(Key.D))
            {
                position.X += 0.05f * direction.Z;
                position.Z -= 0.05f * direction.X;
            }

            //move leftwards
            if (KeyDown(Key.A))
            {
                position.X -= 0.05f * direction.Z;
                position.Z += 0.05f * direction.X;
            }

            //move up
            if (KeyDown(Key.LShift))
            {
                position.Y += 0.05f;
            }

            //move down
            if (KeyDown(Key.LControl))
            {
                position.Y -= 0.05f;
            }
            #endregion

            //Other controls
            #region Others
            if (KeyDown(Key.I))
            {
                //decrease FOV
                FOVd    -= 5;
                FOVr     = FOVd * FOVcalc;
                distance = (float)((width / 2.0) / Math.Tan(FOVr / 2.0));
            }

            if (KeyDown(Key.K))
            {
                //increase FOV
                FOVd    += 5;
                FOVr     = FOVd * FOVcalc;
                distance = (float)((width / 2.0) / Math.Tan(FOVr / 2.0));
            }

            if (KeyDown(Key.L))
            {
                Console.WriteLine("Type desired FOV in degrees:");
                string s = Console.ReadLine();
                try
                {
                    FOVd     = double.Parse(s);
                    FOVr     = FOVd * FOVcalc;
                    distance = (float)((width / 2.0) / Math.Tan(FOVr / 2.0));
                    Console.WriteLine("FOV successfully set to: " + FOVd + " degrees");
                }
                catch (Exception e)
                {
                    Console.WriteLine("Error: " + e.Message);
                }
            }

            if (KeyDown(Key.T))
            {
                Console.WriteLine("Index : Primitives");
                for (int j = 0; j < RayTracer.Scene.Primitives.Count; j++)
                {
                    Console.Write(j);
                    Console.Write(" : ");
                    Console.WriteLine(RayTracer.Scene.Primitives[j].PrimitiveName);
                }
                Console.WriteLine("Type desired target's index number:");
                string s = Console.ReadLine();
                try
                {
                    int i = int.Parse(s);
                    if (i < 0 || i > RayTracer.Scene.Primitives.Count - 1)
                    {
                        Console.WriteLine("Error, input value not in range of list. Reset to default '0'");
                        direction = Vector3.Normalize(RayTracer.Scene.Primitives[0].Position - position);
                    }
                    else
                    {
                        Console.Write("Succes, target set to: ");
                        Console.WriteLine(RayTracer.Scene.Primitives[i].PrimitiveName);
                        direction = Vector3.Normalize(RayTracer.Scene.Primitives[i].Position - position);
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine("Error: " + e.Message);
                }
            }
            #endregion
        }