Esempio n. 1
0
        /// <summary>
        /// Creates a Texture assigning then C++ object. This is used when creating a backbuffer based <see cref="RenderTarget"/>
        /// </summary>
        /// <param name="engine"></param>
        /// <param name="name"></param>
        internal Texture2D(VisualEngine engine, StringBuilder name, _Texture2D internalTexture)
            : base(engine, name)
        {
            Engine.Log.AddInformation(TAG, new StringBuilder("Create " + Name + " (C++ _Texture2D based)"));

            Internal = internalTexture;
        }
Esempio n. 2
0
        /// <summary>
        /// Creates a new RenderTarget based in a previously created RenderTarget from C++
        /// </summary>
        /// <param name="engine"></param>
        /// <param name="name"></param>
        /// <param name="internalRenderTarget"></param>
        internal RenderTarget(VisualEngine engine, StringBuilder name, _RenderTarget internalRenderTarget)
            : this(engine, name)
        {
            Engine.Log.AddInformation(TAG, new StringBuilder("Create " + Name + " (C++ _RenderTarget based)"));

            Internal = internalRenderTarget;

            Texture = new Texture2D(engine, name, Internal.GetTexture());
        }
Esempio n. 3
0
        /// <summary>
        /// Constructs the instance without vertices/indices
        /// </summary>
        public MeshBasic(VisualEngine engine)
        {
            this.engine = engine;

            Internal = new GraphicsEngineSpace._MeshBasic(engine.Device);

            BoundingBox = new BoundingBox();

            BoundingSphere = new BoundingSphere();
        }
Esempio n. 4
0
        public Textures(VisualEngine engine)
        {
            Engine = engine;

            Items = new List <Texture>();

            Paths = new List <string>();

            // Add the internal path for textures used by the engine
            Paths.Add(VisualEngine.InternalPath + "Graphics\\");
        }
Esempio n. 5
0
        /// <summary>
        /// Default constructor.
        /// </summary>
        /// <param name="engine"></param>
        /// <param name="material"></param>
        public RenderableMesh(VisualEngine engine, MeshBasic mesh)
            : base()
        {
            this.Mesh = mesh;

            // Informs that the mesh has changed to update the internal buffers
            // We do not have to do it each frame if it's not necessary
            Mesh.Changed = true;

            Visible = true;
        }
Esempio n. 6
0
        /// <summary>
        /// Creates a Texture and loads it
        /// </summary>
        /// <param name="engine"></param>
        /// <param name="name"></param>
        public Texture2D(VisualEngine engine, StringBuilder name, StringBuilder fullPath)
            : base(engine, name)
        {
            Engine.Log.AddInformation(TAG, new StringBuilder("Creating " + name));

            FullPath = fullPath;

            Internal = new GraphicsEngineSpace._Texture2D(engine.Device, name.ToString());

            LoadFromFile();
        }
Esempio n. 7
0
        /// <summary>
        /// Creates a new RenderTarget object
        /// </summary>
        /// <param name="engine"></param>
        /// <param name="name"></param>
        /// <param name="width"></param>
        /// <param name="height"></param>
        internal RenderTarget(VisualEngine engine, StringBuilder name, int width, int height)
            : this(engine, name)
        {
            Engine.Log.AddInformation(TAG, new StringBuilder("Create " + Name + " " + width + "x" + height + " RGBA"));

            Texture = new Texture2D(engine, name);

            Texture.CreateForRenderTargetUse(name, width, height, TextureFormat.RGBA);

            Internal = new _RenderTarget(Engine.Device, Texture.InternalTexture2D);
        }
Esempio n. 8
0
        /// <summary>
        /// Default constructor.
        /// </summary>
        /// <param name="engine"></param>
        /// <param name="material"></param>
        internal Sprite(VisualEngine engine, int width = 100, int height = 100)
            : base()
        {
            Width = (Numeric)width;

            Height = (Numeric)height;

            this.Mesh = GeometryFactory.CreateRectangleXY(engine, Width, Height);

            Visible = true;
        }
Esempio n. 9
0
        /// <summary>
        /// Creates a new DepthStencil Resource. To add a new DepthStencil, you must call to DepthStenciles.Create()
        /// </summary>
        /// <param name="engine"></param>
        /// <param name="name"></param>
        /// <param name="width"></param>
        /// <param name="height"></param>
        internal DepthStencil(VisualEngine engine, StringBuilder name, int width, int height)
        {
            Engine = engine;

            Name = name;

            Width = width;

            Height = height;

            Engine.Log.AddInformation(TAG, new StringBuilder("Create " + name + " " + Width + "x" + Height));

            // Creates the DepthStencil & the Texture2D

            Internal = new _DepthStencil(Engine.Device, name.ToString(), width, height);
        }
Esempio n. 10
0
        /// <summary>
        /// Creates a centered rectangle using X,Y planes
        /// </summary>
        /// <param name="device"></param>
        /// <param name="material"></param>
        /// <param name="width"></param>
        /// <param name="height"></param>
        /// <param name="zvalue"></param>
        /// <returns></returns>
        public static MeshBasic CreateRectangleXY(VisualEngine engine, Numeric width, Numeric height, Numeric zvalue = 0)
        {
            MeshBasic mesh = new MeshBasic(engine, 4, 6);

            Vector3[] vb = mesh.Position;

            Vector3[] normal = mesh.Normal = new Vector3[mesh.NumVertices];

            Vector2[,] texCoord = mesh.TexCoord = new Vector2[1, mesh.NumVertices];

            uint[] ib = mesh.Indices;

            float wdiv2 = width / 2;
            float hdiv2 = height / 2;

            int i = 0;

            // Front 0
            vb[i] = new Vector3(0, 1, zvalue); normal[i] = new Vector3(0, 0, -1); texCoord[0, i] = new Vector2(0, 0); i++;
            vb[i] = new Vector3(1, 1, zvalue); normal[i] = new Vector3(0, 0, -1); texCoord[0, i] = new Vector2(1, 0); i++;
            vb[i] = new Vector3(1, 0, zvalue); normal[i] = new Vector3(0, 0, -1); texCoord[0, i] = new Vector2(1, 1); i++;
            vb[i] = new Vector3(0, 0, zvalue); normal[i] = new Vector3(0, 0, -1); texCoord[0, i] = new Vector2(0, 1); i++;

            for (i = 0; i < 4; i++)
            {
                vb[i].X *= width;
                vb[i].Y *= height;
                vb[i].X -= wdiv2;
                vb[i].Y -= hdiv2;
            }

            // OGL COUNTER-ClockWISE order

            ib[0] = 2;
            ib[1] = 1;
            ib[2] = 0;
            ib[3] = 3;
            ib[4] = 2;
            ib[5] = 0;

            return(mesh);
        }
Esempio n. 11
0
        /// <summary>
        /// Creates a new RenderTarget
        /// </summary>
        /// <param name="engine"></param>
        /// <param name="name"></param>
        protected RenderTarget(VisualEngine engine, StringBuilder name)
        {
            Engine = engine;

            this.Name = name;
        }
Esempio n. 12
0
        public static MeshBasic CreateTorus(VisualEngine engine, float diameter, float thickness, int tessellation)
        {
            if (tessellation < 3)
            {
                throw new Exception("tesselation parameter out of range");
            }

            int verticalSegments   = tessellation;
            int horizontalSegments = tessellation;

            uint numVertices = (uint)((verticalSegments + 1) * (horizontalSegments + 1));

            float radius = diameter / 2;

            MeshBasic mesh = new MeshBasic(engine, numVertices, 6 * numVertices);

            Vector3[] vertices = mesh.Position;

            mesh.Normal = new Vector3[mesh.NumVertices];

            mesh.TexCoord = new Vector2[1, mesh.NumVertices];

            mesh.Tangent = new Vector3[mesh.NumVertices];

            mesh.VertexColor = new Vector4[mesh.NumVertices];

            uint[] indices     = mesh.Indices;
            uint   vertexCount = 0;
            uint   indexCount  = 0;

            int stride = tessellation + 1;

            // First we loop around the main ring of the torus.
            for (int i = 0; i <= tessellation; i++)
            {
                float u = (float)i / tessellation;

                float outerAngle = i * MathHelper.TwoPi / tessellation - MathHelper.PiOver2;

                // Create a transform matrix that will align geometry to
                // slice perpendicularly though the current ring position.
                Matrix transform = Matrix.CreateTranslation(diameter / 2, 0, 0) * Matrix.CreateRotationY(outerAngle);

                // Now we loop along the other axis, around the side of the tube.
                for (int j = 0; j <= tessellation; j++)
                {
                    float v = 1 - (float)j / tessellation;

                    float innerAngle = j * MathHelper.TwoPi / tessellation + MathHelper.PiOver2;
                    float dx = 0, dy = 0;

                    MathHelper.XMScalarSinCos(ref dy, ref dx, innerAngle);

                    // Create a vertex.
                    Vector3 normal   = new Vector3(dx, dy, 0);
                    Vector3 position = normal * thickness / 2;

                    mesh.Position[vertexCount]    = Vector3.Transform(position, transform);
                    mesh.Normal[vertexCount]      = Vector3.TransformNormal(normal, transform);
                    mesh.TexCoord[0, vertexCount] = new Vector2(u, v);

                    vertexCount++;

                    // And create indices for two triangles.
                    int nextI = (i + 1) % stride;
                    int nextJ = (j + 1) % stride;

                    mesh.Indices[indexCount + 2] = (uint)(i * stride + j);
                    mesh.Indices[indexCount + 1] = (uint)(i * stride + nextJ);
                    mesh.Indices[indexCount + 0] = (uint)(nextI * stride + j);

                    indexCount += 3;

                    mesh.Indices[indexCount + 2] = (uint)(i * stride + nextJ);
                    mesh.Indices[indexCount + 1] = (uint)(nextI * stride + nextJ);
                    mesh.Indices[indexCount + 0] = (uint)(nextI * stride + j);

                    indexCount += 3;
                }
            }

            for (int k = 0; k < mesh.NumVertices; k++)
            {
                // Tangent vectors are always the same for a cube

                mesh.Tangent[k] = new Vector3(1, 0, 0);

                mesh.VertexColor[k] = new Vector4(1, 1, 1, 1);
            }

            return(mesh);
        }
Esempio n. 13
0
 /// <summary>
 /// Creates a Texture without size. This is used by <see cref="DepthStencil"/> constructor
 /// </summary>
 /// <param name="engine"></param>
 /// <param name="name"></param>
 internal Texture2D(VisualEngine engine, StringBuilder name)
     : base(engine, name)
 {
 }
Esempio n. 14
0
        public Sprites(VisualEngine engine)
        {
            Engine = engine;

            Items = new List <Sprite>();
        }
Esempio n. 15
0
        /// <summary>
        /// Default constructor
        /// </summary>
        /// <param name="engine"></param>
        internal RenderTargets(VisualEngine engine)
        {
            Engine = engine;

            Items = new List <RenderTarget>();
        }
Esempio n. 16
0
        public Texture(VisualEngine engine, StringBuilder name)
        {
            Engine = engine;

            Name = name;
        }
Esempio n. 17
0
        /// <summary>
        /// Creates a RenderableMeshMultiMaterial for a 1 unit Cube with 6 faces
        /// Each face has is own TextureCoords, so you could assign one texture to each face
        /// Face 0 is Rear Face
        /// Face 1 is Front
        /// Face 2 is Top
        /// Face 3 is Bottom
        /// Face 4 is Left
        /// Face 5 is Right
        /// </summary>
        /// <param name="device"></param>
        public static RenderableMeshMultiMaterial CreateCube(VisualEngine engine)
        {
            MeshBasic mesh = new MeshBasic(engine, 24, 36);

            Vector3[] vb = mesh.Position;

            Vector3[] normal = mesh.Normal = new Vector3[mesh.NumVertices];

            Vector2[,] texCoord = mesh.TexCoord = new Vector2[1, mesh.NumVertices];

            mesh.Tangent = new Vector3[mesh.NumVertices];

            mesh.VertexColor = new Vector4[mesh.NumVertices];

            uint[] ib = mesh.Indices;

            uint i = 0;

            // Rear 0
            vb[i] = new Vector3(0.5f, 0.5f, -0.5f); normal[i] = new Vector3(0, 0, -1); texCoord[0, i] = new Vector2(0, 0); i++;
            vb[i] = new Vector3(-0.5f, 0.5f, -0.5f); normal[i] = new Vector3(0, 0, -1); texCoord[0, i] = new Vector2(1, 0); i++;
            vb[i] = new Vector3(-0.5f, -0.5f, -0.5f); normal[i] = new Vector3(0, 0, -1); texCoord[0, i] = new Vector2(1, 1); i++;
            vb[i] = new Vector3(0.5f, -0.5f, -0.5f); normal[i] = new Vector3(0, 0, -1); texCoord[0, i] = new Vector2(0, 1); i++;

            // Front 4
            vb[i] = new Vector3(-0.5f, 0.5f, 0.5f); normal[i] = new Vector3(0, 0, 1); texCoord[0, i] = new Vector2(0, 0); i++;
            vb[i] = new Vector3(0.5f, 0.5f, 0.5f); normal[i] = new Vector3(0, 0, 1); texCoord[0, i] = new Vector2(1, 0); i++;
            vb[i] = new Vector3(0.5f, -0.5f, 0.5f); normal[i] = new Vector3(0, 0, 1); texCoord[0, i] = new Vector2(1, 1); i++;
            vb[i] = new Vector3(-0.5f, -0.5f, 0.5f); normal[i] = new Vector3(0, 0, 1); texCoord[0, i] = new Vector2(0, 1); i++;

            // Top 8
            vb[i] = new Vector3(-0.5f, 0.5f, -0.5f); normal[i] = new Vector3(0, 1, 0); texCoord[0, i] = new Vector2(0, 0); i++;
            vb[i] = new Vector3(0.5f, 0.5f, -0.5f); normal[i] = new Vector3(0, 1, 0); texCoord[0, i] = new Vector2(1, 0); i++;
            vb[i] = new Vector3(0.5f, 0.5f, 0.5f); normal[i] = new Vector3(0, 1, 0); texCoord[0, i] = new Vector2(1, 1); i++;
            vb[i] = new Vector3(-0.5f, 0.5f, 0.5f); normal[i] = new Vector3(0, 1, 0); texCoord[0, i] = new Vector2(0, 1); i++;

            // Bottom 12
            vb[i] = new Vector3(0.5f, -0.5f, -0.5f); normal[i] = new Vector3(0, -1, 0); texCoord[0, i] = new Vector2(0, 0); i++;
            vb[i] = new Vector3(-0.5f, -0.5f, -0.5f); normal[i] = new Vector3(0, -1, 0); texCoord[0, i] = new Vector2(1, 0); i++;
            vb[i] = new Vector3(-0.5f, -0.5f, 0.5f); normal[i] = new Vector3(0, -1, 0); texCoord[0, i] = new Vector2(1, 1); i++;
            vb[i] = new Vector3(0.5f, -0.5f, 0.5f); normal[i] = new Vector3(0, -1, 0); texCoord[0, i] = new Vector2(0, 1); i++;

            // Left 16
            vb[i] = new Vector3(-0.5f, 0.5f, -0.5f); normal[i] = new Vector3(-1, 0, 0); texCoord[0, i] = new Vector2(0, 0); i++;
            vb[i] = new Vector3(-0.5f, 0.5f, 0.5f); normal[i] = new Vector3(-1, 0, 0); texCoord[0, i] = new Vector2(1, 0); i++;
            vb[i] = new Vector3(-0.5f, -0.5f, 0.5f); normal[i] = new Vector3(-1, 0, 0); texCoord[0, i] = new Vector2(1, 1); i++;
            vb[i] = new Vector3(-0.5f, -0.5f, -0.5f); normal[i] = new Vector3(-1, 0, 0); texCoord[0, i] = new Vector2(0, 1); i++;

            // Right 20
            vb[i] = new Vector3(0.5f, 0.5f, 0.5f); normal[i] = new Vector3(1, 0, 0); texCoord[0, i] = new Vector2(0, 0); i++;
            vb[i] = new Vector3(0.5f, 0.5f, -0.5f); normal[i] = new Vector3(1, 0, 0); texCoord[0, i] = new Vector2(1, 0); i++;
            vb[i] = new Vector3(0.5f, -0.5f, -0.5f); normal[i] = new Vector3(1, 0, 0); texCoord[0, i] = new Vector2(1, 1); i++;
            vb[i] = new Vector3(0.5f, -0.5f, 0.5f); normal[i] = new Vector3(1, 0, 0); texCoord[0, i] = new Vector2(0, 1); i++;

            for (int k = 0; k < i; k++)
            {
                // Tangent vectors are always the same for a cube

                mesh.Tangent[k] = new Vector3(1, 0, 0);

                mesh.VertexColor[k] = new Vector4(1, 1, 1, 1);
            }

            // OGL COUNTER-ClockWISE order

            i = 0;

            for (uint face = 0; face < 6; face++)
            {
                uint vertex = face * 4;

                ib[i++] = vertex + 2;
                ib[i++] = vertex + 1;
                ib[i++] = vertex + 0;
                ib[i++] = vertex + 2;
                ib[i++] = vertex + 0;
                ib[i++] = vertex + 3;
            }

            // Create the RenderableMeshPart, six parts, one part for each face
            RenderableMeshMultiMaterial renderable = new RenderableMeshMultiMaterial(mesh);

            renderable.Mesh.MeshParts = new List <RenderableMeshPart>(6);

            for (i = 0; i < 6; i++)
            {
                RenderableMeshPart meshPart = new RenderableMeshPart(6, i * 6, 0);

                renderable.Mesh.MeshParts.Add(meshPart);
            }

            return(renderable);
        }
Esempio n. 18
0
        /// <summary>
        /// Construct the instance with Vertices & Indices, but not Normals, neither Texture Coods
        /// </summary>
        /// <param name="numVertices"></param>
        /// <param name="numIndices"></param>
        public MeshBasic(VisualEngine engine, uint numVertices, uint numIndices) : this(engine)
        {
            Position = new Vector3[numVertices];

            Indices = new uint[numIndices];
        }
Esempio n. 19
0
        public static MeshBasic CreateSphere(VisualEngine engine, float diameter, int tessellation)
        {
            if (tessellation < 3)
            {
                throw new Exception("tesselation parameter out of range");
            }

            int verticalSegments   = tessellation;
            int horizontalSegments = tessellation * 2;

            float radius = diameter / 2;

            MeshBasic mesh = new MeshBasic(engine, (uint)((verticalSegments + 1) * (horizontalSegments + 1)), 6 * (uint)(verticalSegments * (horizontalSegments + 1)));

            Vector3[] vertices = mesh.Position;

            Vector3[] normal = mesh.Normal = new Vector3[mesh.NumVertices];

            Vector2[,] texCoord = mesh.TexCoord = new Vector2[1, mesh.NumVertices];

            mesh.Tangent = new Vector3[mesh.NumVertices];

            mesh.VertexColor = new Vector4[mesh.NumVertices];

            uint[] indices     = mesh.Indices;
            uint   vertexCount = 0;

            // Create rings of vertices at progressively higher latitudes.
            for (int i = 0; i <= verticalSegments; i++)
            {
                float v = 1 - (float)i / verticalSegments;

                float latitude = (i * MathHelper.Pi / verticalSegments) - MathHelper.PiOver2;
                float dy = 0, dxz = 0;

                MathHelper.XMScalarSinCos(ref dy, ref dxz, latitude);

                // Create a single ring of vertices at this latitude.
                for (int j = 0; j <= horizontalSegments; j++)
                {
                    float u = (float)j / horizontalSegments;

                    float longitude = j * MathHelper.TwoPi / horizontalSegments;
                    float dx = 0, dz = 0;

                    MathHelper.XMScalarSinCos(ref dx, ref dz, longitude);

                    dx *= dxz;
                    dz *= dxz;

                    normal[vertexCount]        = new Vector3(dx, dy, dz);
                    vertices[vertexCount]      = normal[vertexCount] * radius;
                    texCoord[0, vertexCount++] = new Vector2(u, v);
                }
            }

            // Fill the index buffer with triangles joining each pair of latitude rings.
            int stride = horizontalSegments + 1;

            int indexCount = 0;

            for (int i = 0; i < verticalSegments; i++)
            {
                for (int j = 0; j <= horizontalSegments; j++)
                {
                    int nextI = i + 1;
                    int nextJ = (j + 1) % stride;
                    /* Left Handled */

                    /*
                     * indices[indexCount++] = (uint)(i * stride + j);
                     * indices[indexCount++] = (uint)(nextI * stride + j);
                     * indices[indexCount++] = (uint)(i * stride + nextJ);
                     *
                     * indices[indexCount++] = (uint)(i * stride + nextJ);
                     * indices[indexCount++] = (uint)(nextI * stride + j);
                     * indices[indexCount++] = (uint)(nextI * stride + nextJ);
                     */
                    /* Right Handled */
                    indices[indexCount + 2] = (uint)(i * stride + j);
                    indices[indexCount + 1] = (uint)(nextI * stride + j);
                    indices[indexCount]     = (uint)(i * stride + nextJ);
                    indexCount += 3;
                    indices[indexCount + 2] = (uint)(i * stride + nextJ);
                    indices[indexCount + 1] = (uint)(nextI * stride + j);
                    indices[indexCount]     = (uint)(nextI * stride + nextJ);
                    indexCount += 3;
                }
            }

            for (int k = 0; k < mesh.NumVertices; k++)
            {
                // Tangent vectors are always the same for a cube

                mesh.Tangent[k] = new Vector3(1, 0, 0);

                mesh.VertexColor[k] = new Vector4(1, 1, 1, 1);
            }

            return(mesh);
        }
Esempio n. 20
0
        /// <summary>
        /// Creates a vertex buffer and an IndexBuffer for a 1 unit Cube without Normals and TexCoord
        /// </summary>
        /// <param name="device"></param>
        /// <param name="vb"></param>
        /// <param name="ib"></param>
        public static MeshBasic CreateCubeBasic(VisualEngine engine)
        {
            MeshBasic mesh = new MeshBasic(engine, 8, 36);

            Vector3[] vb = mesh.Position;

            vb[0] = new Vector3(-0.5f, 0.5f, -0.5f);
            vb[1] = new Vector3(0.5f, 0.5f, -0.5f);
            vb[2] = new Vector3(0.5f, -0.5f, -0.5f);
            vb[3] = new Vector3(-0.5f, -0.5f, -0.5f);

            vb[4] = new Vector3(-0.5f, 0.5f, 0.5f);
            vb[5] = new Vector3(0.5f, 0.5f, 0.5f);
            vb[6] = new Vector3(0.5f, -0.5f, 0.5f);
            vb[7] = new Vector3(-0.5f, -0.5f, 0.5f);

            uint[] ib = mesh.Indices;

            ib = new uint[36];

            // Front
            ib[0] = 0;
            ib[1] = 1;
            ib[2] = 2;
            ib[3] = 0;
            ib[4] = 2;
            ib[5] = 3;

            // rear
            ib[6]  = 4;
            ib[7]  = 6;
            ib[8]  = 5;
            ib[9]  = 4;
            ib[10] = 7;
            ib[11] = 6;

            // left
            ib[12] = 4;
            ib[13] = 0;
            ib[14] = 3;
            ib[15] = 4;
            ib[16] = 3;
            ib[17] = 7;

            // right
            ib[18] = 1;
            ib[19] = 5;
            ib[20] = 2;
            ib[21] = 2;
            ib[22] = 5;
            ib[23] = 6;

            // top
            ib[24] = 0;
            ib[25] = 4;
            ib[26] = 1;
            ib[27] = 1;
            ib[28] = 4;
            ib[29] = 5;

            // bottom
            ib[30] = 3;
            ib[31] = 2;
            ib[32] = 7;
            ib[33] = 7;
            ib[34] = 2;
            ib[35] = 6;

            return(mesh);
        }
Esempio n. 21
0
        /// <summary>
        /// Default constructor
        /// </summary>
        /// <param name="engine"></param>
        internal RenderViews(VisualEngine engine)
        {
            Engine = engine;

            Items = new List <RenderView>();
        }