Beispiel #1
0
        public override void Init()
        {
            Camera.FoV         = 75f;
            Camera.AspectRatio = width / (float)height;
            Camera.Position    = new Vector3(0f, 0f, -2f);
            Camera.zNear       = 0.1f;
            Camera.zFar        = 150f;

            vertexBuffer  = VertexBuffer.Create(BufferUsage.Dynamic);
            indexBuffer   = IndexBuffer.Create(BufferUsage.Dynamic);
            geometryInput = GeometryInput.Create(indexBuffer, new VertexStream(vertexBuffer, vertexFormat));
        }
Beispiel #2
0
        public override void Init()
        {
            //Window.SetIcon("textures/icon.png");

            Platform.RelativeMouseMode = true;
            //Platform.ShowCursor = false; // Default true

            Camera.FoV         = 75f;
            Camera.AspectRatio = width / (float)height;
            Camera.Position    = new Vector3(0f, 2f, -5f);
            //Camera.Projection = Projection.Orthographic;
            //Camera.Width = Window.Width / 10;
            //Camera.Height = Window.Height / 10;
            Camera.zNear = 0.1f;
            Camera.zFar  = 150f;

            surface = Framebuffer.Create(width, height, 1, TextureFormat.RGB8, TextureFormat.Depth24);

            vertexFormat = new VertexFormat(
                4,                                                                    // Pack
                new VertexAttribute(DataType.Float, 3, false),                        // Position
                new VertexAttribute(DataType.Float, 3, false),                        // Normal
                new VertexAttribute(DataType.UnsignedByte, 4, true),                  // Colour
                new VertexAttribute(DataType.UnsignedShort, 2, true),                 // UV
                new VertexAttribute(DataType.UnsignedByte, 1, true)                   // Textured
                );

            Geometry cubeGeometry = Geometry.Cube();

            cubeVertices = new Vertex[cubeGeometry.Vertices.Length];
            for (int i = 0; i < cubeGeometry.Vertices.Length; i++)
            {
                cubeVertices[i] = new Vertex(cubeGeometry.Vertices[i].Position, cubeGeometry.Vertices[i].Normal, cubeGeometry.Vertices[i].Colour, cubeGeometry.Vertices[i].UV, false);
            }
            cubeIndices = cubeGeometry.Indices16;

            Geometry icosphereGeometry = Geometry.Icosphere(0.5f, 4);

            icosphereVertices = new Vertex[icosphereGeometry.Vertices.Length];
            for (int i = 0; i < icosphereGeometry.Vertices.Length; i++)
            {
                icosphereVertices[i] = new Vertex(icosphereGeometry.Vertices[i].Position, icosphereGeometry.Vertices[i].Normal, icosphereGeometry.Vertices[i].Colour, icosphereGeometry.Vertices[i].UV, false);
            }
            icosphereIndices = icosphereGeometry.Indices16;

            Geometry planeGeometry = Geometry.Plane(1f, Geometry.Orientation.XZ, 10, 10, false);

            planeVertices = new Vertex[planeGeometry.Vertices.Length];
            for (int i = 0; i < planeGeometry.Vertices.Length; i++)
            {
                planeVertices[i] = new Vertex(planeGeometry.Vertices[i].Position, planeGeometry.Vertices[i].Normal, planeGeometry.Vertices[i].Colour, planeGeometry.Vertices[i].UV, false);
            }
            planeIndices = planeGeometry.Indices16;

            cubeVertexBuffer       = VertexBuffer.Create(BufferUsage.Static);
            cubeIndexBuffer        = IndexBuffer.Create(BufferUsage.Static);
            icosphereVertexBuffer  = VertexBuffer.Create(BufferUsage.Static);
            icosphereIndexBuffer   = IndexBuffer.Create(BufferUsage.Static);
            planeVertexBuffer      = VertexBuffer.Create(BufferUsage.Static);
            planeIndexBuffer       = IndexBuffer.Create(BufferUsage.Static);
            cubeGeometryInput      = GeometryInput.Create(cubeIndexBuffer, new VertexStream(cubeVertexBuffer, vertexFormat));
            icosphereGeometryInput = GeometryInput.Create(icosphereIndexBuffer, new VertexStream(icosphereVertexBuffer, vertexFormat));
            planeGeometryInput     = GeometryInput.Create(planeIndexBuffer, new VertexStream(planeVertexBuffer, vertexFormat));
            cubeVertexBuffer.LoadData(cubeVertices);
            cubeIndexBuffer.LoadData(cubeIndices);
            icosphereVertexBuffer.LoadData(icosphereVertices);
            icosphereIndexBuffer.LoadData(icosphereIndices);
            planeVertexBuffer.LoadData(planeVertices);
            planeIndexBuffer.LoadData(planeIndices);

            light1Transform.Parent = light1ParentTransform;
            light2Transform.Parent = light2ParentTransform;
            light3Transform.Parent = light3ParentTransform;
        }
Beispiel #3
0
        public override void Init()
        {
            Camera.FoV         = 75f;
            Camera.AspectRatio = width / (float)height;
            Camera.Position    = new Vector3(0f, 2f, -10f);
            Camera.zNear       = 0.1f;
            Camera.zFar        = 150f;

            vertexFormat = new VertexFormat(
                4,                                                                    // Pack
                new VertexAttribute(DataType.Float, 3, false),                        // Position
                new VertexAttribute(DataType.Float, 3, false),                        // Normal
                new VertexAttribute(DataType.UnsignedByte, 4, true),                  // Colour
                new VertexAttribute(DataType.UnsignedShort, 2, true),                 // UV
                new VertexAttribute(DataType.UnsignedByte, 1, true)                   // Textured
                );

            Geometry cubeGeometry = Geometry.Cube();

            cubeVertices = new Vertex[cubeGeometry.Vertices.Length];
            for (int i = 0; i < cubeGeometry.Vertices.Length; i++)
            {
                cubeVertices[i] = new Vertex(cubeGeometry.Vertices[i].Position, cubeGeometry.Vertices[i].Normal, cubeGeometry.Vertices[i].Colour, cubeGeometry.Vertices[i].UV, true);
            }
            cubeIndices = cubeGeometry.Indices16;

            Geometry icosphereGeometry = Geometry.Icosphere(0.5f, 2, true);

            icosphereVertices = new Vertex[icosphereGeometry.Vertices.Length];
            for (int i = 0; i < icosphereGeometry.Vertices.Length; i++)
            {
                icosphereVertices[i] = new Vertex(icosphereGeometry.Vertices[i].Position, icosphereGeometry.Vertices[i].Normal, icosphereGeometry.Vertices[i].Colour, icosphereGeometry.Vertices[i].UV, false);
            }
            icosphereIndices = icosphereGeometry.Indices16;

            Geometry planeGeometry = Geometry.Plane(1f, Geometry.Orientation.XZ, 10, 10, false);

            planeVertices = new Vertex[planeGeometry.Vertices.Length];
            for (int i = 0; i < planeGeometry.Vertices.Length; i++)
            {
                planeVertices[i] = new Vertex(planeGeometry.Vertices[i].Position, planeGeometry.Vertices[i].Normal, planeGeometry.Vertices[i].Colour, planeGeometry.Vertices[i].UV, false);
            }
            planeIndices = planeGeometry.Indices16;

            cubeVertexBuffer       = VertexBuffer.Create(BufferUsage.Static);
            cubeIndexBuffer        = IndexBuffer.Create(BufferUsage.Static);
            icosphereVertexBuffer  = VertexBuffer.Create(BufferUsage.Static);
            icosphereIndexBuffer   = IndexBuffer.Create(BufferUsage.Static);
            planeVertexBuffer      = VertexBuffer.Create(BufferUsage.Static);
            planeIndexBuffer       = IndexBuffer.Create(BufferUsage.Static);
            cubeGeometryInput      = GeometryInput.Create(cubeIndexBuffer, new VertexStream(cubeVertexBuffer, vertexFormat));
            icosphereGeometryInput = GeometryInput.Create(icosphereIndexBuffer, new VertexStream(icosphereVertexBuffer, vertexFormat));
            planeGeometryInput     = GeometryInput.Create(planeIndexBuffer, new VertexStream(planeVertexBuffer, vertexFormat));
#if WEBGL
            cubeVertexBuffer.LoadData(cubeVertices, vertexFormat);
            icosphereVertexBuffer.LoadData(icosphereVertices, vertexFormat);
            planeVertexBuffer.LoadData(planeVertices, vertexFormat);
#else
            cubeVertexBuffer.LoadData(cubeVertices);
            icosphereVertexBuffer.LoadData(icosphereVertices);
            planeVertexBuffer.LoadData(planeVertices);
#endif
            cubeIndexBuffer.LoadData(cubeIndices);
            icosphereIndexBuffer.LoadData(icosphereIndices);
            planeIndexBuffer.LoadData(planeIndices);

            light1Transform.Parent = light1ParentTransform;
            light2Transform.Parent = light2ParentTransform;
            light3Transform.Parent = light3ParentTransform;
        }