Esempio n. 1
0
        private static void Window_RenderFrame(object sender, FrameEventArgs e)
        {
            GL.ClearColor(Color.Black);
            GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);

            SolidColorMeshShader shader = SolidColorMeshShader.SharedInstance;

            shader.Use();
            camera.ApplyToShader(shader);

            sphere.Draw();

            window.SwapBuffers();
        }
Esempio n. 2
0
        // This gets called when the drawing surface is ready
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            SolidColorMeshShader.Load();
            SolidColorMeshShader.SharedInstance.Use();

            GL.Viewport(0, 0, Width, Height);
            Matrix4 mat = Matrix4.CreatePerspectiveFieldOfView(MathHelper.DegreesToRadians(40.0f), (float)Width / (float)Height, 1.0f, 10000.0f);

            camera.SetProjection(
                mat.M11, mat.M12, mat.M13, mat.M14,
                mat.M21, mat.M22, mat.M23, mat.M24,
                mat.M31, mat.M32, mat.M33, mat.M34,
                mat.M41, mat.M42, mat.M43, mat.M44
                );

            cameraUp    = new Vector4(0.0f, 1.0f, 0.0f, 1.0f);
            cameraRight = new Vector4(1.0f, 0.0f, 0.0f, 1.0f);
            cameraPos   = new Vector4(0.0f, 10.0f, 40.0f, 1.0f);
            mat         = Matrix4.LookAt(cameraPos.Xyz, Vector3.Zero, cameraUp.Xyz);
            camera.SetView(
                mat.M11, mat.M12, mat.M13, mat.M14,
                mat.M21, mat.M22, mat.M23, mat.M24,
                mat.M31, mat.M32, mat.M33, mat.M34,
                mat.M41, mat.M42, mat.M43, mat.M44
                );

            //sphere = ShapeGenerator.MakeCube<VertexPositioned>(SolidColorMeshShader.SharedInstance, VertexFormat.Position);
            sphere = ShapeGenerator.MakeSphere2 <VertexPositioned>(
                10, 20, Axii.Y, (int)All.Lines, SolidColorMeshShader.SharedInstance, VertexFormat.Position
                );
            mat = Matrix4.Scale(1.0f);
            World3DShaderTransform worldTrans = new World3DShaderTransform();

            worldTrans.SetWorld(
                mat.M11, mat.M12, mat.M13, mat.M14,
                mat.M21, mat.M22, mat.M23, mat.M24,
                mat.M31, mat.M32, mat.M33, mat.M34,
                mat.M41, mat.M42, mat.M43, mat.M44
                );
            sphere.Transform = worldTrans;
            SolidColorShaderMaterial material = new SolidColorShaderMaterial();

            material.SetColor(0.0f, 1.0f, 1.0f, 1.0f);
            sphere.DefaultMaterial = sphere.Parts[0].Material = material;

            // Run the render loop
            Run();
        }
Esempio n. 3
0
        // This gets called on each frame render
        protected override void OnRenderFrame(FrameEventArgs e)
        {
            base.OnRenderFrame(e);

            GL.ClearColor(0.0f, 0.0f, 0.0f, 1.0f);
            GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);

            SolidColorMeshShader shader = SolidColorMeshShader.SharedInstance;

            shader.Use();
            camera.ApplyToShader(shader);

            sphere.Draw();

            SwapBuffers();
        }
Esempio n. 4
0
 private static void Window_Closed(object sender, EventArgs e)
 {
     SolidColorMeshShader.Release();
     sphere.Dispose();
     sphere = null;
 }
Esempio n. 5
0
        private static void Window_Load(object sender, EventArgs e)
        {
            SolidColorMeshShader.Load();
            SolidColorMeshShader.SharedInstance.Use();

            camera.Projection = Matrix4.CreatePerspectiveFieldOfView(MathHelper.DegreesToRadians(40.0f), (float)window.Width / (float)window.Height, 1.0f, 10000.0f);
            //camera.Projection = Matrix4.CreateOrthographic(10.0f * (float)window.Width / (float)window.Height, 10.0f, 1.0f, 10000.0f);

            cameraUp    = new Vector4(0.0f, 1.0f, 0.0f, 1.0f);
            cameraRight = new Vector4(1.0f, 0.0f, 0.0f, 1.0f);
            cameraPos   = new Vector4(0.0f, 10.0f, 40.0f, 1.0f);
            camera.View = Matrix4.LookAt(cameraPos.Xyz, Vector3.Zero, cameraUp.Xyz);
            //camera.View = Matrix4.Identity;

            /*
             * sphere = new ModelMesh() {
             *  Transform = new World3DShaderTransform(Matrix4.CreateScale(8.0f)),
             *  DefaultShader = SolidColorMeshShader.SharedInstance,
             *  DefaultVertexBuffer = new VertexBuffer() { DisposalLevel = ItemDisposalLevel.ModelMesh },
             *  DefaultMaterial = new SolidColorShaderMaterial(new Vector4(0.0f, 1.0f, 1.0f, 1.0f)),
             *  IndexBuffer = new IndexBuffer() { DisposalLevel = ItemDisposalLevel.ModelMesh }
             * };
             */
            sphere = ShapeGenerator.MakeSphere <FirimenticEngine.CustomComponents.Graphics.Vertices.VertexPositioned>(
                10, 20, FirimenticEngine.Graphics.Axii.Y, PrimitiveType.Lines, SolidColorMeshShader.SharedInstance,
                FirimenticEngine.Graphics.VertexFormat.Position
                );
            sphere.Transform       = new World3DShaderTransform(Matrix4.CreateScale(8.0f));
            sphere.DefaultMaterial = sphere.Parts[0].Material = new SolidColorShaderMaterial(new Vector4(0.0f, 1.0f, 1.0f, 1.0f));

            /*
             * VertexPositioned[] verts = new VertexPositioned[] {
             *  new VertexPositioned( 0.0f, 0.0f, 0.0f),
             *  new VertexPositioned( 1.0f, 0.0f, 0.0f),
             *  new VertexPositioned(-1.0f, 0.0f, 0.0f),
             *  new VertexPositioned( 0.0f, 1.0f, 0.0f),
             *  new VertexPositioned( 0.0f,-1.0f, 0.0f),
             *  new VertexPositioned( 0.0f, 0.0f, 1.0f),
             *  new VertexPositioned( 0.0f, 0.0f,-1.0f)
             * };
             *
             * ushort[] indcs = new ushort[] {
             *  2, 0, 4
             * };
             */


            /*
             * VertexPositioned[] verts = new VertexPositioned[] {
             *  new VertexPositioned(-1.0f, 1.0f, 1.0f),
             *  new VertexPositioned( 1.0f, 1.0f, 1.0f),
             *  new VertexPositioned( 1.0f,-1.0f, 1.0f),
             *  new VertexPositioned(-1.0f,-1.0f, 1.0f),
             *  new VertexPositioned(-1.0f, 1.0f,-1.0f),
             *  new VertexPositioned( 1.0f, 1.0f,-1.0f),
             *  new VertexPositioned( 1.0f,-1.0f,-1.0f),
             *  new VertexPositioned(-1.0f,-1.0f,-1.0f)
             * };
             *
             * ushort[] indcs = new ushort[] {
             *  0, 1, 2, 3, 0,
             *  4, 7, 3, 2,
             *  6, 7, 6,
             *  5, 4, 5,
             *  1,
             *  3, 2, 0,
             *  7, 4, 3,
             *  6, 2, 7,
             *  5, 6, 4,
             *  1, 0, 5,
             *  2, 1, 6
             * };
             */


            /*
             * VertexPositioned[] verts = new VertexPositioned[19 * 40 + 2];
             *
             * float inc = 9.0f * MathHelper.Pi / 180.0f;
             * float fullCirc = 2 * MathHelper.Pi - float.Epsilon;
             * float halfCirc = MathHelper.Pi - float.Epsilon;
             * float scale = 1.0f;
             * int ind = 0;
             *
             * verts[ind++] = new VertexPositioned(Vector3.UnitY * scale);
             * verts[ind++] = new VertexPositioned(Vector3.UnitY * -scale);
             * for (float lng = 0; lng < fullCirc; lng += inc) {
             *  for (float lat = inc; lat < halfCirc; lat += inc) {
             *      Matrix4 rot = Matrix4.CreateRotationZ(lng) * Matrix4.CreateRotationX(lat);
             *      Vector3 pos = (Vector3.UnitY * scale).Transform(ref rot);
             *      verts[ind++] = new VertexPositioned(pos);
             *  }
             * }
             *
             *
             * ushort[] indcs = new ushort[20 * (2 + 19 + 19) + 1 + 19 * (40 + 1)];
             *
             * ind = 0;
             * for (ushort lngInd = 0; lngInd < 20; lngInd++) {
             *  indcs[ind++] = 0;
             *  for (ushort latInd = 2; latInd < 21; latInd++) {
             *      indcs[ind++] = (ushort)(lngInd * 19 + latInd);
             *  }
             *  indcs[ind++] = 1;
             *  for (ushort latInd = 20; latInd > 1; latInd--) {
             *      indcs[ind++] = (ushort)((lngInd + 20) * 19 + latInd);
             *  }
             * }
             * indcs[ind++] = 0;
             * for (ushort latInd = 2; latInd < 21; latInd++) {
             *  for (ushort lngInd = 0; lngInd < 40; lngInd++) {
             *      indcs[ind++] = (ushort)(lngInd * 19 + latInd);
             *  }
             *  indcs[ind++] = latInd;
             * }
             */


            //sphere.DefaultVertexBuffer.SetData(VertexFormat.Position, verts);
            //sphere.IndexBuffer.SetData(indcs);

            //new ModelMeshPart(sphere, null, null, null, PrimitiveType.LineStrip, indcs.Length, 0);
        }