Exemplo n.º 1
0
        public override void Render()
        {
            Matrix4 lookAt = Matrix4.LookAt(new Vector3(-7.0f, 5.0f, -7.0f), new Vector3(0.0f, 0.0f, 0.0f), new Vector3(0.0f, 1.0f, 0.0f));

            GL.LoadMatrix(Matrix4.Transpose(lookAt).Matrix);

            GL.Disable(EnableCap.DepthTest);
            grid.Render();
            GL.Enable(EnableCap.DepthTest);

            GL.EnableClientState(ArrayCap.VertexArray);
            GL.EnableClientState(ArrayCap.ColorArray);

            GL.BindBuffer(BufferTarget.ArrayBuffer, vertexBuffer);
            GL.BindBuffer(BufferTarget.ElementArrayBuffer, indexBuffer);

            // 0 bytes from the begenning of the buffer
            GL.VertexPointer(3, VertexPointerType.Float, 0, new System.IntPtr(0));
            // The buffer first contains positions, which are 8 vertices, made up of 3 floats each.
            // after that comes the color information, therefore the colors are:
            // 8 * 3 * sizeof(float) bytes away from the begenning of the buffer
            GL.ColorPointer(3, ColorPointerType.Float, 0, new System.IntPtr(sizeof(float) * 8 * 3));

            // The index buffer only contains indices we want to draw, so they are 0 bytes
            // from the begenning of the array. You can use the constant i use here instead
            // of making a new IntPtr, if the offset you are looking for is 0
            GL.DrawElements(PrimitiveType.Triangles, numIndices, DrawElementsType.UnsignedInt, System.IntPtr.Zero);

            GL.BindBuffer(BufferTarget.ArrayBuffer, 0);
            GL.BindBuffer(BufferTarget.ElementArrayBuffer, 0);

            GL.DisableClientState(ArrayCap.VertexArray);
            GL.DisableClientState(ArrayCap.ColorArray);
        }
Exemplo n.º 2
0
        public override void Render()
        {
            GL.Viewport(0, 0, MainGameWindow.Window.Width, MainGameWindow.Window.Height);

            GL.MatrixMode(MatrixMode.Projection);
            GL.LoadIdentity();
            Perspective(60.0f, (float)MainGameWindow.Window.Width / (float)MainGameWindow.Window.Height, 0.01f, 1000.0f);

            GL.MatrixMode(MatrixMode.Modelview);
            GL.LoadIdentity();
            LookAt(10.0f, 4.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f);

            grid.Render();

            GL.PushMatrix();
            {
                GL.Color3(1.0f, 0.0f, 0.0f);
                Matrix4 scale       = Matrix4.Scale(new Vector3(0.5f, 0.5f, 0.5f));
                Matrix4 rotation    = Matrix4.AngleAxis(45.0f, 1.0f, 0.0f, 0.0f);
                Matrix4 translation = Matrix4.Translate(new Vector3(-2.0f, 1.0f, 3.0f));
                Matrix4 model       = translation * rotation * scale;
                GL.MultMatrix(Matrix4.Transpose(model).Matrix);
                DrawCube();
            }
            GL.PopMatrix();
        }
Exemplo n.º 3
0
        public override void Render()
        {
            GL.LoadMatrix(Matrix4.Transpose(viewMatrix).Matrix);

            GL.Disable(EnableCap.Lighting);
            GL.Disable(EnableCap.DepthTest);
            grid.Render();
            GL.Enable(EnableCap.DepthTest);
            GL.Enable(EnableCap.Lighting);



            /*if (Plane.HalfSpace(cameraPlane,new Vector3(0f,0f,0f)) >= 0) {
             *  GL.Color3(1f, 1f, 1f);
             *  model.Render(true, false);
             * }*/
            if (PointInFrustum(frustum, new Vector3(0f, 0f, 0f)))
            {
                GL.Color3(1f, 1f, 1f);
                model.Render(true, false);
            }
            else
            {
                Console.WriteLine("Green susane culled");
            }
        }
Exemplo n.º 4
0
 public override void Render()
 {
     GL.MatrixMode(MatrixMode.Modelview);
     GL.LoadIdentity();
     GL.Rotate(90f, 1.0f, 0.0f, 0.0f);
     GL.Rotate(180.0f, 0.0f, 0.0f, 1.0f);
     grid.Render();
 }
Exemplo n.º 5
0
        public override void Render()
        {
            GL.MatrixMode(MatrixMode.Modelview);
            GL.LoadIdentity(); // Reset modelview matrix
            LookAt(0.5f, 0.5f, 0.5f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f);

            grid.Render();
        }
Exemplo n.º 6
0
        public override void Render()
        {
            GL.Viewport(0, 0, MainGameWindow.Window.Width, MainGameWindow.Window.Height);

            float aspect = (float)MainGameWindow.Window.Width / (float)MainGameWindow.Window.Height;

            //set up projections
            GL.MatrixMode(MatrixMode.Projection);
            GL.LoadIdentity();
            Perspective(60.0f, aspect, 0.1f, 100.0f);
            //GL.Ortho(-1*aspect, 1*aspect, -1, 1, -10, 10);

            //get into model space
            GL.MatrixMode(MatrixMode.Modelview);
            GL.LoadIdentity();
            //position camera
            LookAt(
                10.0f, 10.0f, 10.0f,
                0.0f, 0.0f, 0.0f,
                0.0f, 1.0f, 0.0f
                );
            //draw grid
            grid.Render();
            GL.PushMatrix();
            //move render position
            GL.Translate(0.0f, 0.0f, -0.25f);
            GL.Translate(0.25f, 0.0f, 0.0f);
            GL.Rotate(45.0f, 1.0f, 0.0f, 0.0f);
            GL.Rotate(73.0f, 0.0f, 1.0f, 0.0f);
            GL.Scale(0.05f, 0.05f, 0.05f);
            //draw red cube
            GL.Color3(1.0f, 0.0f, 0.0f);
            DrawCube();
            //reset position to origin
            GL.PopMatrix();
            GL.PushMatrix();
            //move into new position
            GL.Translate(-0.25f, 0.0f, 0.25f);
            GL.Rotate(33.0f, 0.0f, 0.0f, 1.0f);
            GL.Rotate(97.0, 0.0f, 1.0f, 0.0f);
            GL.Scale(0.05f, 0.05f, 0.05f);
            //draw green cube
            GL.Color3(0.0f, 1.0f, 0.0f);
            DrawCube();
            GL.PopMatrix();

            GL.PushMatrix();
            //move into new position
            GL.Translate(0.0f, 0.25f, 0.25f);
            GL.Rotate(33.0f, 0.0f, 0.0f, 1.0f);
            GL.Rotate(53.0, 0.0f, 1.0f, 0.0f);
            GL.Scale(0.05f, 0.05f, 0.05f);
            //draw green cube
            GL.Color3(0.0f, -.0f, 1.0f);
            DrawCube();
            GL.PopMatrix();
        }
Exemplo n.º 7
0
 public override void Render()
 {
     GL.MatrixMode(MatrixMode.Modelview);
     GL.LoadIdentity();
     GL.Rotate(90.0f, 1.0f, 0.0f, 0.0f);
     GL.Rotate(180.0f, 0.0f, 0.0f, 1.0f); //to see the scaling
     //GL.Scale(2.0, 2.0, 2.0);
     GL.Scale(0.25, 0.25, 0.25);
     grid.Render();
 }
Exemplo n.º 8
0
        public override void Render()
        {
            //set view matrix
            Matrix4 lookAt = Matrix4.LookAt(new Vector3(10.0f, 5.0f, 15.0f), new Vector3(0.0f, 0.0f, 0.0f), new Vector3(0.0f, 1.0f, 0.0f));

            GL.LoadMatrix(lookAt.OpenGL);
            //render scene
            grid.Render();
            DrawPlanets(-1.0f, 1.0f, 0.0f);
        }
Exemplo n.º 9
0
        public override void Render()
        {
            Matrix4 lookAt = Matrix4.LookAt(new Vector3(0.0f, 0.0f, 30.0f), new Vector3(0.0f, 0.0f, 0.0f), new Vector3(0.0f, 1.0f, 0.0f));

            GL.LoadMatrix(lookAt.OpenGL);
            grid.Render();

            GL.ShadeModel(ShadingModel.Smooth);

            GL.Begin(PrimitiveType.Triangles);
            GL.Color3(1.0f, 0.0f, 0.0f);
            GL.Vertex3(-10.0f, -10.0f, -5.0f); //red
            GL.Color3(0.0f, 1.0f, 0.0f);
            GL.Vertex3(20.0f, -10.0f, -5.0f);  //green
            GL.Color3(0.0f, 0.0f, 1.0f);
            GL.Vertex3(-10.0f, 20.0f, -5.0f);  //blue
            GL.End();
        }
Exemplo n.º 10
0
        public override void Render()
        {
            Matrix4 lookAt = Matrix4.LookAt(new Vector3(-7.0f, 5.0f, -7.0f), new Vector3(0.0f, 0.0f, 0.0f), new Vector3(0.0f, 1.0f, 0.0f));

            GL.LoadMatrix(Matrix4.Transpose(lookAt).Matrix);

            GL.Disable(EnableCap.DepthTest);
            grid.Render();
            GL.Enable(EnableCap.DepthTest);

            GL.EnableClientState(ArrayCap.VertexArray);
            GL.EnableClientState(ArrayCap.ColorArray);
            GL.VertexPointer(3, VertexPointerType.Float, 0, cubeVertices);
            GL.ColorPointer(3, ColorPointerType.Float, 0, cubeColors);

            GL.DrawElements(PrimitiveType.Triangles, cubeIndicies.Length, DrawElementsType.UnsignedInt, cubeIndicies);

            GL.DisableClientState(ArrayCap.VertexArray);
            GL.DisableClientState(ArrayCap.ColorArray);
        }
Exemplo n.º 11
0
        public override void Render()
        {
            GL.Viewport(0, 0, MainGameWindow.Window.Width, MainGameWindow.Window.Height);

            GL.MatrixMode(MatrixMode.Projection);
            float   aspect      = (float)MainGameWindow.Window.Width / (float)MainGameWindow.Window.Height;
            Matrix4 perspective = Matrix4.Perspective(60, aspect, 0.01f, 1000.0f);

            GL.LoadMatrix(Matrix4.Transpose(perspective).Matrix);

            GL.MatrixMode(MatrixMode.Modelview);
            GL.LoadIdentity();
            Matrix4     lookAt = Matrix4.LookAt(new Vector3(10.0f, 5.0f, 15.0f), new Vector3(0.0f, 0.0f, 0.0f), new Vector3(0.0f, 1.0f, 0.0f));
            MatrixStack stack  = new MatrixStack();

            stack.Load(lookAt);
            GL.LoadMatrix(stack.OpenGL);

            grid.Render();
            DrawPlanets(-1.0f, 1.0f, 0.0f, stack);
        }
Exemplo n.º 12
0
        public override void Render()
        {
            Vector3 eyePos = new Vector3();

            eyePos.X = cameraAngle.Z * -(float)Math.Sin(cameraAngle.X * rads) * (float)Math.Cos(cameraAngle.Y * rads);
            eyePos.Y = cameraAngle.Z * -(float)Math.Sin(cameraAngle.Y * rads);
            eyePos.Z = -cameraAngle.Z * (float)Math.Cos(cameraAngle.X * rads) * (float)Math.Cos(cameraAngle.Y * rads);

            Matrix4 lookAt = Matrix4.LookAt(eyePos, new Vector3(0.0f, 0.0f, 0.0f), new Vector3(0.0f, 1.0f, 0.0f));

            GL.LoadMatrix(Matrix4.Transpose(lookAt).Matrix);

            GL.Disable(EnableCap.Lighting);
            GL.Disable(EnableCap.DepthTest);
            grid.Render();
            GL.Enable(EnableCap.DepthTest);
            GL.Enable(EnableCap.Lighting);

            GL.Color3(1f, 1f, 1f);
            models.Render(true, false);
        }
Exemplo n.º 13
0
        public override void Render()
        {
            Vector3 eyePos = new Vector3();

            eyePos.X = cameraAngle.Z * -(float)Math.Sin(cameraAngle.X * rads * (float)Math.Cos(cameraAngle.Y * rads));
            eyePos.Y = cameraAngle.Z * -(float)Math.Sin(cameraAngle.Y * rads);
            eyePos.Z = -cameraAngle.Z * (float)Math.Cos(cameraAngle.X * rads * (float)Math.Cos(cameraAngle.Y * rads));

            Matrix4 lookAt = Matrix4.LookAt(eyePos, new Vector3(0.0f, 0.0f, 0.0f), new Vector3(0.0f, 1.0f, 0.0f));

            GL.LoadMatrix(Matrix4.Transpose(lookAt).Matrix);

            grid.Render();

            GL.Color3(0.0f, 1.0f, 0.0f);
            GL.PushMatrix();
            {
                GL.Translate(0.0f, 2.5f, -2.0f);
                Primitives.Torus();
            }
            GL.PopMatrix();

            GL.Color3(1.0f, 0.0f, 0.0f);
            GL.PushMatrix();
            {
                GL.Translate(2.5f, 1.0f, -0.5f);
                Primitives.DrawSphere();
            }
            GL.PopMatrix();

            GL.Color3(0.0f, 0.0f, 1.0f);
            GL.PushMatrix();
            {
                GL.Translate(-1.0f, 0.5f, 0.5f);
                Primitives.Cube();
            }
            GL.PopMatrix();
        }
Exemplo n.º 14
0
        public override void Render()
        {
            GL.Viewport(0, 0, MainGameWindow.Window.Width, MainGameWindow.Window.Height);

            GL.MatrixMode(MatrixMode.Projection);
            GL.LoadIdentity();
            //Perspective(60.0f, (float)MainGameWindow.Window.Width / (float)MainGameWindow.Window.Height, 0.01f, 1000.0f);
            float aspect = (float)MainGameWindow.Window.Width / (float)MainGameWindow.Window.Height;
            //GL.Ortho(-25.0f * aspect, 25.0f * aspect, -25.0f, 25.0f, -25.0f, 25.0f);
            Matrix4 ortho = Matrix4.Ortho(-25.0f * aspect, 25.0f * aspect, -25.0f, 25.0f, -25.0f, 25.0f);

            GL.LoadMatrix(Matrix4.Transpose(ortho).OpenGL);

            GL.MatrixMode(MatrixMode.Modelview);
            GL.LoadIdentity();
            //LookAt(10.0f, 5.0f, 15.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f);
            Matrix4 lookAt = Matrix4.LookAt(new Vector3(10.0f, 5.0f, 15.0f), new Vector3(0.0f, 0.0f, 0.0f), new Vector3(0.0f, 1.0f, 0.0f));

            GL.LoadMatrix(Matrix4.Transpose(lookAt).Matrix);

            grid.Render();
            DrawRobot(-1.0f, 1.0f, 0.0f);
        }
Exemplo n.º 15
0
        public void RenderWorld()
        {
            GL.Disable(EnableCap.Texture2D);
            GL.Disable(EnableCap.DepthTest);
            grid.Render();
            GL.Enable(EnableCap.DepthTest);
            GL.Enable(EnableCap.Texture2D);

            GL.Color3(1f, 1f, 1f);//white
            GL.BindTexture(TextureTarget.Texture2D, crazyTexture);
            GL.Begin(PrimitiveType.Triangles);
            {
                GL.TexCoord2(2, -2);
                GL.Vertex3(1, 4, 2);  //top right
                GL.TexCoord2(-2, -2);
                GL.Vertex3(1, 4, -2); //top left
                GL.TexCoord2(-2, 2);
                GL.Vertex3(1, 0, -2); //bottom left

                GL.TexCoord2(2, -2);
                GL.Vertex3(1, 4, 2);  //top right
                GL.TexCoord2(-2, 2);
                GL.Vertex3(1, 0, -2); //bottom left
                GL.TexCoord2(2, 2);
                GL.Vertex3(1, 0, 2);  //bottom Right
            }
            GL.End();
            GL.BindTexture(TextureTarget.Texture2D, 0);

            GL.BindTexture(TextureTarget.Texture2D, houseTexture);
            //house 1
            GL.Color3(1f, 1f, 1f);
            GL.PushMatrix();
            GL.Translate(-1f, 0.5f, -1f);
            GL.Rotate(-130f, 0f, 1f, 0f);
            GL.Scale(0.57f, 1f, 1f);
            GL.Scale(3f, 3f, 3f);
            GL.Begin(PrimitiveType.Triangles);

            GL.TexCoord2(house1_uv_right, house1_uv_top);
            GL.Vertex3(0.5f, 0.5f, 0f);   //top right
            GL.TexCoord2(house1_uv_left, house1_uv_top);
            GL.Vertex3(-0.5f, 0.5f, 0f);  //top left
            GL.TexCoord2(house1_uv_left, house1_uv_bottom);
            GL.Vertex3(-0.5f, -0.5f, 0f); //bottom left
            GL.TexCoord2(house1_uv_right, house1_uv_top);
            GL.Vertex3(0.5, 0.5, 0);      //top right
            GL.TexCoord2(house1_uv_left, house1_uv_bottom);
            GL.Vertex3(-0.5, -0.5, 0);    //bottom left
            GL.TexCoord2(house1_uv_right, house1_uv_bottom);
            GL.Vertex3(0.5, -0.5, 0);     //bottom right
            GL.End();
            GL.PopMatrix();
            // house 2
            GL.Color3(1f, 1f, 1f);
            GL.PushMatrix();
            GL.Translate(-2f, 0.5f, -3f);
            GL.Rotate(-130f, 0f, 1f, 0f);
            GL.Scale(0.53f, 1f, 1f);
            GL.Scale(3f, 3f, 3f);
            GL.Begin(PrimitiveType.Triangles);
            GL.TexCoord2(house2_uv_right, house2_uv_top);
            GL.Vertex3(0.5, 0.5, 0);   //top right
            GL.TexCoord2(house2_uv_left, house2_uv_top);
            GL.Vertex3(-0.5, 0.5, 0);  //top left
            GL.TexCoord2(house2_uv_left, house2_uv_bottom);
            GL.Vertex3(-0.5, -0.5, 0); //bottom left
            GL.TexCoord2(house2_uv_right, house2_uv_top);
            GL.Vertex3(0.5, 0.5, 0);   //top right
            GL.TexCoord2(house2_uv_left, house2_uv_bottom);
            GL.Vertex3(-0.5, -0.5, 0); //bottom left
            GL.TexCoord2(house2_uv_right, house2_uv_bottom);
            GL.Vertex3(0.5, -0.5, 0);  //bottom Right
            GL.End();
            GL.PopMatrix();

            GL.BindTexture(TextureTarget.Texture2D, 0);
        }