Beispiel #1
0
 // tick: renders one frame
 public void Tick()
 {
     screen.Clear(0);
     // Drawing the Red Seperation line in the middle   
     screen.Line(screen.width / 2, 0, screen.width / 2, screen.height, 0xff0000);
     screen.Print("X", screen.width - 25, screen.height /2 + 10, 0xffffff);
     screen.Print("Z", screen.width / 4 * 3+ 5, screen.height - 20, 0xffffff);
     // start rendering
     Raytracing();  
 }
Beispiel #2
0
        // tick: renders one frame
        public void Tick()
        {
            screen.Clear(0x000000);

            KeyboardInput();

            DrawGridLines(0x008800, 0x004400, 1f, 1f);
            PlotFunction(0.1f, 0xff0000);
            PlotPolarFunction(0.01f, 0x0000ff,0,(float)Math.PI*10f);
            screen.Print(labelFunction(),5,5, 0xff0000);
            screen.Print(labelPolarFunction(), 5, 25, 0x0000ff);
        }
Beispiel #3
0
        public void Tick()
        {
            // start timer
            timer.Restart();
            // run the simulation, 1 step
            inBuffer.CopyToDevice();
            kernel.Execute(workSize);
            outBuffer.CopyFromDevice();


            for (int i = 0; i < pw * ph; i++)
            {
                _in[i] = 0;
            }

            // visualize current state, DRAW FUNCTION -> GPU BONUS.
            screen.Clear(0);
            for (uint y = 0; y < screen.height / scale; y++)
            {
                for (uint x = 0; x < screen.width / scale; x++)
                {
                    if (GetBit(x + xoffset, y + yoffset) == 1)
                    {
                        if (scale > 1)
                        {
                            for (uint j = 0; ((j + 1) % scale) != 0; j++)
                            {
                                for (uint i = 0; ((i + 1) % scale) != 0; i++)
                                {
                                    screen.Plot((x * scale + i), (y * scale + j), 0xffffff);
                                }
                            }
                        }
                        else
                        {
                            screen.Plot(x, y, 0xffffff);
                        }
                    }
                }
            }

            for (uint y = 0; y < ph; y++)
            {
                for (uint x = 0; x < pw * 32; x++)
                {
                    if (GetBit(x, y) == 1)
                    {
                        BitSet(x, y);
                    }
                }
            }


            string text = "Scale: " + scale + "x";

            screen.Print(text, 5, 5, 0xffffff);

            // report performance
            Console.WriteLine("generation " + generation++ + ": " + timer.ElapsedMilliseconds + "ms");
        }
Beispiel #4
0
	// tick: renders one frame
	public void Tick()
	{
		screen.Clear( 0 );
		screen.Print( "hello world", 2, 2, 0xffffff );
        screen.Line(2, 20, 160, 20, 0xff0000);
            a += 1f / 30;
            Ex3(a);
	}
Beispiel #5
0
        public void Tick()
        {
            DrawDebug();

            // Camera coördinaten worden afgerond op 3 decimalen en wordt geprint.
            screen.Print("Cameraposition:" + new Vector3((float)Math.Round(camera.CameraPosition.X, 3),
                                                         (float)Math.Round(camera.CameraPosition.Y, 3),
                                                         (float)Math.Round(camera.CameraPosition.Z, 3)),
                         512, 490, 0xffffff);
        }
Beispiel #6
0
        // initialize
        public void Init()
        {
            screen.Print("Move: UP, DOWN, LEFT, RIGHT", 10, 10, 10);
            // load teapot
            mesh  = new Mesh("../../assets/teapot.obj");
            floor = new Mesh("../../assets/floor.obj");
            eye   = new Mesh("../../assets/eyeball.obj");
            moon  = new Mesh("../../assets/moon.obj");
            earth = new Mesh("../../assets/earth.obj");
            jet   = new Mesh("../../assets/jet.obj");
            // initialize stopwatch
            timer = new Stopwatch();
            timer.Reset();
            timer.Start();
            // create shaders
            shader = new Shader("../../shaders/vs.glsl", "../../shaders/fs.glsl");
            // load a texture
            wood   = new Texture("../../assets/wood.jpg");
            eyeR   = new Texture("../../assets/ref1.jpg");
            crater = new Texture("../../assets/crater.jpg");
            land   = new Texture("../../assets/land.jpg");
            stars  = new Texture("../../assets/stars.jpg");
            jetp   = new Texture("../../assets/jetp.png");
            //add light
            int lightID = GL.GetUniformLocation(shader.programID, "lightPos");

            GL.UseProgram(shader.programID);
            GL.Uniform3(lightID, 0f, 10f, 0.0f);
            //add camera position
            Tc = Matrix4.CreateTranslation(new Vector3(0, -25.5f, 0)) * Matrix4.CreateFromAxisAngle(new Vector3(1, 0, 0), PI / 2);
            Vector4 c        = Tc * (new Vector4(0f, 0f, 0f, 1f));
            int     cameraID = GL.GetUniformLocation(shader.programID, "cPos");

            GL.UseProgram(shader.programID);
            GL.Uniform4(cameraID, c);

            //create scenegraph
            meshes = new scenegraph(floor, Matrix4.CreateScale(6.0f) * Matrix4.CreateFromAxisAngle(new Vector3(0, 1, 0), 0), stars, shader);
            meshes.addNode(mesh, Matrix4.CreateScale(0.5f) * Matrix4.CreateFromAxisAngle(new Vector3(0, 1, 0), 0), wood, shader);
            meshes.getChildren()[0].addNode(mesh, Matrix4.CreateScale(0.5f) * Matrix4.CreateTranslation(new Vector3(5, 0, 0)) * Matrix4.CreateFromAxisAngle(new Vector3(0, 1, 0), 0), wood, shader);
            meshes.getChildren()[0].getChildren()[0].addNode(mesh, Matrix4.CreateScale(0.25f) * Matrix4.CreateTranslation(new Vector3(8, 0, 0)) * Matrix4.CreateFromAxisAngle(new Vector3(0, 1, 0), 0), wood, shader);
        }
Beispiel #7
0
        // tick: renders one frame
        public void Tick()
        {
            // Handle keyboard input. Arrow keys move the camera, WASD is used for turning the camera, LShift and Enter move the camera up and down
            var keyboard = OpenTK.Input.Keyboard.GetState();

            if (keyboard[OpenTK.Input.Key.W])
            {
                Tracer.Camera.turnCamera(-0.1f * Tracer.Camera.YDirection);
            }
            if (keyboard[OpenTK.Input.Key.A])
            {
                Tracer.Camera.turnCamera(-0.1f * Tracer.Camera.XDirection);
            }
            if (keyboard[OpenTK.Input.Key.S])
            {
                Tracer.Camera.turnCamera(0.1f * Tracer.Camera.YDirection);
            }
            if (keyboard[OpenTK.Input.Key.D])
            {
                Tracer.Camera.turnCamera(0.1f * Tracer.Camera.XDirection);
            }
            if (keyboard[OpenTK.Input.Key.Enter])
            {
                Tracer.Camera.moveCamera(-0.1f * Tracer.Camera.YDirection);
            }
            if (keyboard[OpenTK.Input.Key.LShift])
            {
                Tracer.Camera.moveCamera(0.1f * Tracer.Camera.YDirection);
            }
            if (keyboard[OpenTK.Input.Key.Left])
            {
                Tracer.Camera.moveCamera(-0.1f * Tracer.Camera.XDirection);
            }
            if (keyboard[OpenTK.Input.Key.Right])
            {
                Tracer.Camera.moveCamera(0.1f * Tracer.Camera.XDirection);
            }
            if (keyboard[OpenTK.Input.Key.Up])
            {
                Tracer.Camera.moveCamera(0.1f * Tracer.Camera.Orientation);
            }
            if (keyboard[OpenTK.Input.Key.Down])
            {
                Tracer.Camera.moveCamera(-0.1f * Tracer.Camera.Orientation);
            }
            Screen.Clear(0);
            Screen.Print("Tracer", 2, 2, 0xffffff);
            Tracer.Render(Debugging);
        }
Beispiel #8
0
            GL.CompileShader(ID);
            GL.AttachShader(program, ID);
            Console.WriteLine(GL.GetShaderInfoLog(ID));
        }

        // tick: renders one frame
        public void Tick()
        {
            screen.Clear(0);
            screen.Print("hello world", 2, 2, 0xffffff);
            screen.Line(2, 20, 160, 20, 0xff0000);
            Vierkant();
            DraaiendVierkant();

            Matrix4 M = Matrix4.CreateFromAxisAngle(new Vector3(0, 0, 1), Timer);
            M *= Matrix4.CreateFromAxisAngle(new Vector3(1, 0, 0), 1.9f);
 // tick for background surface
 public void Tick()
 {
     screen.Clear(0);
     screen.Print("hello world", 2, 2, 0xffff00);
     readKey();
 }
Beispiel #10
0
        public void Render(Camera cam, Scene scene, Surface displaySurf)
        {
            if (aa == 2)
            {
                for (int x = -sQuarterWidth; x < sQuarterWidth; x++)
                {
                    for (int y = -sHalfHeight; y < sHalfHeight; y++)
                    {
                        Vector3 color      = AugustRay(x, y, (x * divX * cam.right) + (y * divY * cam.up) + cam.position + cam.direction, 4);
                        int     finalColor = (((int)color.X * 65536) + ((int)color.Y * 256) + (int)color.Z);
                        pixelBuffer[(y + sHalfHeight) * sWidth + (x + sQuarterWidth)] = finalColor;//screenpoint inserted here
                    }//for loop y
                }//(for loop x)
            }
            else if (aa == 1)
            {
                for (int x = -sQuarterWidth; x < sQuarterWidth; x += 2)
                {
                    for (int y = -sHalfHeight; y < sHalfHeight; y += 2)
                    {
                        Vector3 color      = AugustRay(x, y, (x * divX * cam.right) + (y * divY * cam.up) + cam.position + cam.direction, 4);
                        int     finalColor = (((int)color.X * 65536) + ((int)color.Y * 256) + (int)color.Z);

                        int bufferBuffer = finalColor;
                        pixelBuffer[(y + sHalfHeight) * sWidth + (x + sQuarterWidth)]         = bufferBuffer; //
                        pixelBuffer[(y + sHalfHeight) * sWidth + (x + 1 + sQuarterWidth)]     = bufferBuffer; //
                        pixelBuffer[(y + 1 + sHalfHeight) * sWidth + (x + sQuarterWidth)]     = bufferBuffer; //
                        pixelBuffer[(y + 1 + sHalfHeight) * sWidth + (x + 1 + sQuarterWidth)] = bufferBuffer; //
                    }//for loop y
                }//(for loop x)
            }
            else if (aa == 3)
            {
                for (int x = -sQuarterWidth * 2; x < sQuarterWidth * 2; x += 2)
                {
                    for (int y = -sHalfHeight * 2; y < sHalfHeight * 2; y += 2)
                    {
                        float red   = (AugustRay(x, y, (x * 0.5f * divX * cam.right) + (y * 0.5f * divY * cam.up) + cam.position + cam.direction, 4).X + AugustRay(x + 1, y, ((x + 1) * 0.5f * divX * cam.right) + (y * 0.5f * divY * cam.up) + cam.position + cam.direction, 4).X + AugustRay(x, y + 1, (x * 0.5f * divX * cam.right) + ((y + 1) * 0.5f * divY * cam.up) + cam.position + cam.direction, 4).X + AugustRay(x + 1, y + 1, ((x + 1) * 0.5f * divX * cam.right) + ((y + 1) * 0.5f * divY * cam.up) + cam.position + cam.direction, 4).X) * 0.25f;
                        float green = (AugustRay(x, y, (x * 0.5f * divX * cam.right) + (y * 0.5f * divY * cam.up) + cam.position + cam.direction, 4).Y + AugustRay(x + 1, y, ((x + 1) * 0.5f * divX * cam.right) + (y * 0.5f * divY * cam.up) + cam.position + cam.direction, 4).Y + AugustRay(x, y + 1, (x * 0.5f * divX * cam.right) + ((y + 1) * 0.5f * divY * cam.up) + cam.position + cam.direction, 4).Y + AugustRay(x + 1, y + 1, ((x + 1) * 0.5f * divX * cam.right) + ((y + 1) * 0.5f * divY * cam.up) + cam.position + cam.direction, 4).Y) * 0.25f;
                        float blue  = (AugustRay(x, y, (x * 0.5f * divX * cam.right) + (y * 0.5f * divY * cam.up) + cam.position + cam.direction, 4).Z + AugustRay(x + 1, y, ((x + 1) * 0.5f * divX * cam.right) + (y * 0.5f * divY * cam.up) + cam.position + cam.direction, 4).Z + AugustRay(x, y + 1, (x * 0.5f * divX * cam.right) + ((y + 1) * 0.5f * divY * cam.up) + cam.position + cam.direction, 4).Z + AugustRay(x + 1, y + 1, ((x + 1) * 0.5f * divX * cam.right) + ((y + 1) * 0.5f * divY * cam.up) + cam.position + cam.direction, 4).Z) * 0.25f;

                        int finalColor = (((int)red * 65536) + ((int)green * 256) + (int)blue);

                        pixelBuffer[(y / 2 + sHalfHeight) * sWidth + (x / 2 + sQuarterWidth)] = finalColor;

                        //if (x % 2 == 0 && y % 2 == 0)
                        //{
                        //    pixelBuffer[(y / 2 + sHalfHeight) * sWidth + (x / 2 + sQuarterWidth)] = 0;
                        //}

                        //int bufferBuffer = (AugustRay(x, y, (x * 0.5f * divX * cam.right) + (y * 0.5f * divY * cam.up) + cam.position + cam.direction, 4) >> 2);
                        //bufferBuffer &= 4144959;

                        //pixelBuffer[(y / 2 + sHalfHeight) * sWidth + (x / 2 + sQuarterWidth)] += bufferBuffer;
                    } //for loop y
                }     //(for loop x)
            }

            //Debugging view:

            foreach (Primitive s in scene.primitives)
            {
                if (s is Sphere)
                {
                    Vector2 sphereScreenPosition = returnScreenCoordinates(s.position);

                    double red     = 255 * s.color.X
                    , green        = 255 * s.color.Y
                    , blue         = 255 * s.color.Z;
                    int pixelColor = ((int)red * 65536) + ((int)green * 256) + ((int)blue);

                    drawCircle(sphereScreenPosition, (s as Sphere).radius * zMultiplier, pixelColor);
                }
            }

            for (int u = 0; u < sWidth * sHeight; u++)
            {
                if (u % sWidth < sHeight)
                {
                    screen.pixels[u] = pixelBuffer[u];
                }
            }

            screen.Print("WASD and Arrow keys to move, R to reset, F and G to change FOV", 5, 5, 0xffffff);
            screen.Print("Current FOV: " + cam.fov, sQuarterWidth * 2 + 5, 25, 0xffffff);
            screen.Print("1-2-3 to pick antialiasing.", sQuarterWidth * 2 + 5, 45, 0xffffff);
            screen.Print("x0.25, x1 and x4 respectively.", sQuarterWidth * 2 + 5, 65, 0xffffff);
            for (int i = 0; i < sHeight; i++)
            {
                screen.pixels[sWidth / 2 + i * sWidth] = 0xffffff;
            }

            Vector2 screenFirst  = returnScreenCoordinates(cam.position + cam.left + cam.direction);
            Vector2 screenSecond = returnScreenCoordinates(cam.position + cam.right + cam.direction);

            screen.Line((int)screenFirst.X, (int)screenFirst.Y, (int)screenSecond.X, (int)screenSecond.Y, 0xffffff);//deze moet iets anders tekenen op het moment dat je omhoog kijkt ....
        }