Beispiel #1
0
 public MyModel(Project1Game game, VertexPositionTexture[] shapeArray, String textureName)
 {
     this.vertices = Buffer.Vertex.New(game.GraphicsDevice, shapeArray);
     this.inputLayout = VertexInputLayout.New<VertexPositionTexture>(0);
     vertexStride = Utilities.SizeOf<VertexPositionTexture>();
     modelType = ModelType.Textured;
     Texture = game.Content.Load<Texture2D>(textureName);
 }
Beispiel #2
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="game">Juego</param>
        /// <param name="side">Lado del suelo</param>
        /// <param name="textureAssetName">Nombre de la textura</param>
        public FloorGameComponent(Game game, float side, string textureAssetName)
            : base(game)
        {
            float edge = side / 2f;

            NorthEast = new VertexPositionTexture(new Vector3(-edge, 0, -edge), new Vector2(0, 0));
            NorthWest = new VertexPositionTexture(new Vector3(edge, 0, -edge), new Vector2(1, 0));
            SouthEast = new VertexPositionTexture(new Vector3(-edge, 0, edge), new Vector2(0, 1));
            SouthWest = new VertexPositionTexture(new Vector3(edge, 0, edge), new Vector2(1, 1));

            textureName = textureAssetName;

            this.m_Box = new BoundingBox(NorthEast.Position, SouthWest.Position);
        }
Beispiel #3
0
        void CréerTableauSommets()
        {
            PtsTexture = new Vector2[NbColonnes + 1, NbRangées + 1];
            Sommets    = new VertexPositionTexture[NbSommets];
            Vector2 graduation = new Vector2(1f / NbColonnes, 1f / NbRangées);

            for (int j = NbRangées; j >= 0; --j)
            {
                for (int i = 0; i <= NbColonnes; ++i)
                {
                    PtsTexture[i, NbRangées - j] = new Vector2(i * graduation.X, j * graduation.Y);
                }
            }
        }
Beispiel #4
0
        public VertexPositionTexture[] GetVertexArray(RectangleF bounds)
        {
            VertexPositionTexture[] vdecl = new VertexPositionTexture[6];

            vdecl[0] = new VertexPositionTexture(new Vector3(bounds.X, bounds.Y, 0), Vector2.One);
            vdecl[1] = new VertexPositionTexture(new Vector3(bounds.X, bounds.Y + bounds.Height, 0), Vector2.UnitX);
            vdecl[2] = new VertexPositionTexture(new Vector3(bounds.X + bounds.Width, bounds.Y, 0), Vector2.UnitY);

            vdecl[3] = new VertexPositionTexture(new Vector3(bounds.X + bounds.Width, bounds.Y, 0), Vector2.UnitY);
            vdecl[4] = new VertexPositionTexture(new Vector3(bounds.X, bounds.Y + bounds.Height, 0), Vector2.UnitX);
            vdecl[5] = new VertexPositionTexture(new Vector3(bounds.X + bounds.Width, bounds.Y + bounds.Height, 0), Vector2.Zero);

            return(vdecl);
        }
Beispiel #5
0
        public static (VertexPositionTexture[] Vertices, int[] Indices) GenerateCone(float height, float radius, int tesselations, int uvSplits = 4, int uvSplitsBottom = 0)
        {
            if (tesselations < 3)
            {
                tesselations = 3;
            }

            if (uvSplits != 0 && tesselations % uvSplits != 0) // FIXME: this can read a lot nicer i think?
            {
                throw new ArgumentException("expected the desired number of uv splits to be a divisor of the number of tesselations");
            }

            if (uvSplitsBottom != 0 && tesselations % uvSplitsBottom != 0) // FIXME: this can read a lot nicer i think?
            {
                throw new ArgumentException("expected the desired number of uv splits for the bottom to be a divisor of the number of tesselations");
            }

            var(bottomVertices, bottomIndices) = GenerateCircle(radius, tesselations, uvSplits, yOffset: -(height / 2.0f));
            var(topVertices, topIndices)       = GenerateCircle(radius, tesselations, uvSplitsBottom, isFlipped: true, yOffset: -(height / 2.0f));
            VertexPositionTexture[] vertices = new VertexPositionTexture[bottomVertices.Length + topVertices.Length];
            int[] indices = new int[topIndices.Length + bottomIndices.Length];

            // copy vertices from circle
            for (int i = 0; i < bottomVertices.Length; ++i)
            {
                vertices[i] = bottomVertices[i];
            }

            for (int i = 0; i < topVertices.Length; ++i)
            {
                vertices[i + bottomVertices.Length] = topVertices[i];
            }

            // copy indices from circle
            for (int i = 0; i < bottomIndices.Length; ++i)
            {
                indices[i] = bottomIndices[i];
            }

            for (int i = 0; i < topIndices.Length; ++i)
            {
                indices[i + bottomIndices.Length] = topIndices[i] + bottomVertices.Length;
            }

            // extrude middle vertex of center of first circle triangle fan
            vertices[0].Position.Y = height / 2.0f;
            vertices[1].Position.Y = height / 2.0f;

            return(vertices, indices);
        }
Beispiel #6
0
        protected override void Initialize()
        {
            mainForm            = (Form)Form.FromHandle(Window.Handle);
            mainForm.AllowDrop  = true;
            mainForm.DragEnter += new DragEventHandler(mainForm_DragEnter);
            mainForm.DragDrop  += new DragEventHandler(mainForm_DragDrop);
            base.Initialize();
            IsMouseVisible = true;

            graphics.PreferredBackBufferWidth  = defaultSize.X;
            graphics.PreferredBackBufferHeight = defaultSize.Y;
            graphics.ApplyChanges();

            VertexPositionTexture[] vpt;
            int[] indices;

            vpt     = new VertexPositionTexture[4];
            vpt[0]  = new VertexPositionTexture(new Vector3(-1.0f, -1.0f, 0.0f), new Vector2(0.0f, 1.0f));
            vpt[1]  = new VertexPositionTexture(new Vector3(+1.0f, -1.0f, 0.0f), new Vector2(1.0f, 1.0f));
            vpt[2]  = new VertexPositionTexture(new Vector3(+1.0f, +1.0f, 0.0f), new Vector2(1.0f, 0.0f));
            vpt[3]  = new VertexPositionTexture(new Vector3(-1.0f, +1.0f, 0.0f), new Vector2(0.0f, 0.0f));
            indices = new int[] {
                2, 1, 0,
                0, 3, 2,
            };

            vbo = new VertexBuffer(GraphicsDevice, typeof(VertexPositionTexture), vpt.Length, BufferUsage.WriteOnly);
            ibo = new IndexBuffer(GraphicsDevice, IndexElementSize.ThirtyTwoBits, indices.Length, BufferUsage.WriteOnly);
            vbo.SetData <VertexPositionTexture>(vpt);
            ibo.SetData <int>(indices);

            SamplerState sam = new SamplerState();

            sam.AddressU = TextureAddressMode.Wrap;
            sam.AddressV = TextureAddressMode.Wrap;
            sam.AddressW = TextureAddressMode.Wrap;
            sam.Filter   = TextureFilter.Point;

            GraphicsDevice.SamplerStates[0]   = sam;
            graphics.PreparingDeviceSettings += new EventHandler <PreparingDeviceSettingsEventArgs>(graphics_PreparingDeviceSettings);
            screenbuffer = new Color[GraphicsDevice.Viewport.Width * GraphicsDevice.Viewport.Height];

            target = new RenderTarget2D(GraphicsDevice, GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height);


            previousframe = new Texture2D(GraphicsDevice, GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height);
            previousframe.SetData <Color>(screenbuffer);
            effect.Parameters["resolution"].SetValue(new Vector2(graphics.PreferredBackBufferWidth, graphics.PreferredBackBufferHeight));
            DrawSplatter();
        }
Beispiel #7
0
        public VertexPositionTexture[] CalculateVertices(float radius, float height, int segments, int rings)
        {
            int i = 0;
            // Load data into a vertex buffer or a display list afterwards.
            var data = new VertexPositionTexture[rings * segments];

            for (double y = 0; y < rings; y++)
            {
                double phi = (y / (rings - 1)) * Math.PI;
                for (double x = 0; x < segments; x++)
                {
                    double theta = (x / (segments - 1)) * 2 * Math.PI;

                    Vector3 v = new Vector3()
                    {
                        X = (float)(radius * Math.Sin(phi) * Math.Cos(theta)),
                        Y = (float)(height * Math.Cos(phi)),
                        Z = (float)(radius * Math.Sin(phi) * Math.Sin(theta)),
                    };
                    //Vector3 n = Vector3.Normalize(v);
                    // Horizontal texture projection
                    Vector2 uv = new Vector2()
                    {
                        X = (float)(x / (segments - 1)),
                        Y = (float)(y / (rings - 1))
                    };
                    // Using data[i++] causes i to be incremented multiple times in Mono 2.2 (bug #479506).
                    data[i] = new VertexPositionTexture()
                    {
                        Position = v,
                        //Normal = n,
                        u = uv.X,
                        v = uv.Y,
                        a = byte.MaxValue,
                        r = byte.MaxValue,
                        g = byte.MaxValue,
                        b = byte.MaxValue,
                    };
                    i++;

                    // Top - down texture projection.
                    //Vector2 uv = new Vector2()
                    //{
                    //    X = (float)(Math.Atan2(n.X, n.Z) / Math.PI / 2 + 0.5),
                    //    Y = (float)(Math.Asin(n.Y) / Math.PI / 2 + 0.5)
                    //};
                }
            }
            return(data);
        }
Beispiel #8
0
        private void InitializeParticleVertices()
        {
            // Instantiate all particle arrays
            verts = new VertexPositionTexture[maxParticles * 4];
            vertexDirectionArray = new Vector3[maxParticles];
            vertexColorArray     = new Color[maxParticles];

            // Get color data from colors texture
            Color[] colors = new Color[particleColorsTexture.Width *
                                       particleColorsTexture.Height];
            particleColorsTexture.GetData(colors);

            // Loop until max particles
            for (int i = 0; i < maxParticles; ++i)
            {
                float size = (float)rnd.NextDouble() * particleSettings.maxSize;

                // set position, direction and size of particle
                verts[i * 4]       = new VertexPositionTexture(position, new Vector2(0, 0));
                verts[(i * 4) + 1] = new VertexPositionTexture(new Vector3(position.X,
                                                                           position.Y + size, position.Z), new Vector2(0, 1));
                verts[(i * 4) + 2] = new VertexPositionTexture(new Vector3(position.X + size,
                                                                           position.Y, position.Z), new Vector2(1, 0));
                verts[(i * 4) + 3] = new VertexPositionTexture(new Vector3(position.X + size,
                                                                           position.Y + size, position.Z), new Vector2(1, 1));

                // Create a random velocity/direction
                Vector3 direction = new Vector3(
                    (float)rnd.NextDouble() * 2 - 1,
                    (float)rnd.NextDouble() * 2 - 1,
                    (float)rnd.NextDouble() * 2 - 1);
                direction.Normalize();

                // Multiply by NextDouble to make sure that
                // all particles move at random speeds
                direction *= (float)rnd.NextDouble();

                // Set direction of particle
                vertexDirectionArray[i] = direction;

                // Set color of particle bygetting a random color from the texture
                vertexColorArray[i] = colors[(
                                                 rnd.Next(0, particleColorsTexture.Height) * particleColorsTexture.Width) +
                                             rnd.Next(0, particleColorsTexture.Width)];
            }

            // Instantiate vertex buffer
            particleVertexBuffer = new VertexBuffer(graphicsDevice,
                                                    typeof(VertexPositionTexture), verts.Length, BufferUsage.None);
        }
Beispiel #9
0
        public void LoadContent(GraphicsDevice graphicsDevice, ContentManager contentManager)
        {
            MyTexture = contentManager.Load <Texture2D>(Asset);

            Vertices = new VertexPositionTexture[]
            {
                new VertexPositionTexture(new Vector3(-0.5f, 0.5f, 0), new Vector2(0, 0)),
                new VertexPositionTexture(new Vector3(0.5f, 0.5f, 0), new Vector2(1, 0)),
                new VertexPositionTexture(new Vector3(-0.5f, -0.5f, 0), new Vector2(0, 1)),
                new VertexPositionTexture(new Vector3(0.5f, -0.5f, 0), new Vector2(1, 1))
            };

            Inds = new int[] { 0, 1, 2, 1, 3, 2 };
        }
Beispiel #10
0
        public QuadRenderer(GraphicsDevice device)
        {
            this.device = device;

            vertices = new VertexPositionTexture[]
            {
                new VertexPositionTexture(new Vector3(0, 0, 0), new Vector2(1, 1)),
                new VertexPositionTexture(new Vector3(0, 0, 0), new Vector2(0, 1)),
                new VertexPositionTexture(new Vector3(0, 0, 0), new Vector2(0, 0)),
                new VertexPositionTexture(new Vector3(0, 0, 0), new Vector2(1, 0))
            };

            indexBuffer = new short[] { 0, 1, 2, 2, 3, 0 };
        }
Beispiel #11
0
 public static VertexBuffer GetTextureVerts(GraphicsDevice gd)
 {
     if (_TextureVerts == null)
     {
         var verts = new VertexPositionTexture[4];
         verts[0]      = new VertexPositionTexture(new Vector3(-1, -1, 0), new Vector2(0, 0));
         verts[1]      = new VertexPositionTexture(new Vector3(-1, 1, 0), new Vector2(0, 1));
         verts[2]      = new VertexPositionTexture(new Vector3(1, -1, 0), new Vector2(1, 0));
         verts[3]      = new VertexPositionTexture(new Vector3(1, 1, 0), new Vector2(1, 1));
         _TextureVerts = new VertexBuffer(gd, typeof(VertexPositionTexture), 4, BufferUsage.None);
         _TextureVerts.SetData(verts);
     }
     return(_TextureVerts);
 }
Beispiel #12
0
        private static VertexPositionTexture[] CreateQuadVertices(int width, int height)
        {
            int halfWidth  = width / 2;
            int halfHeight = height / 2;

            VertexPositionTexture[] vertices = new VertexPositionTexture[4];

            vertices[0] = new VertexPositionTexture(new Vector3(-halfWidth, halfHeight, 0), mUpperLeft);
            vertices[1] = new VertexPositionTexture(new Vector3(halfWidth, halfHeight, 0), mUpperRight);
            vertices[2] = new VertexPositionTexture(new Vector3(-halfWidth, -halfHeight, 0), mBottomLeft);
            vertices[3] = new VertexPositionTexture(new Vector3(halfWidth, -halfHeight, 0), mBottomRight);

            return(vertices);
        }
Beispiel #13
0
        public static VertexPositionTexture[] RampWall(float x, float y, float z, float width, float height, Direction4 dir)
        {
            VertexPositionTexture[] tileVerts = new VertexPositionTexture[3];
            float Left  = -width * x;
            float Right = -width + (-width * x);

            float Up   = y;
            float Down = y + height;

            float Top = height + (z * height);
            float Bot = z * height;

            Vector3 origin           = new Vector3();
            Vector3 verticalVector   = new Vector3();
            Vector3 horizontalVector = new Vector3();

            switch (dir)
            {
            case Direction4.North:
                origin           = new Vector3(Left, Up, Bot);
                verticalVector   = new Vector3(Left, Up, Top);
                horizontalVector = new Vector3(Left, Down, Bot);
                break;

            case Direction4.East:
                origin           = new Vector3(Right, Up, Bot);
                verticalVector   = new Vector3(Right, Up, Top);
                horizontalVector = new Vector3(Left, Up, Bot);
                break;

            case Direction4.South:
                origin           = new Vector3(Right, Down, Bot);
                verticalVector   = new Vector3(Right, Down, Top);
                horizontalVector = new Vector3(Right, Up, Bot);
                break;

            case Direction4.West:
                origin           = new Vector3(Left, Down, Bot);
                verticalVector   = new Vector3(Left, Down, Top);
                horizontalVector = new Vector3(Right, Down, Bot);
                break;
            }

            tileVerts[0] = new VertexPositionTexture(origin, new Vector2(0, 0));
            tileVerts[1] = new VertexPositionTexture(verticalVector, new Vector2(0, 1));
            tileVerts[2] = new VertexPositionTexture(horizontalVector, new Vector2(1, 0));


            return(tileVerts);
        }
Beispiel #14
0
        public VertexPositionTexture[] CalculateVertices(float radius, float height, int segments, int rings)
        {
            int i = 0;
            // Load data into a vertex buffer or a display list afterwards.
            var data = new VertexPositionTexture[rings * segments];

            for (double y = 0; y < rings; y++)
            {
                double phi = (y / (rings - 1)) * Math.PI;
                for (double x = 0; x < segments; x++)
                {
                    double theta = (x / (segments - 1)) * 2 * Math.PI;

                    Vector3 v = new Vector3()
                    {
                        X = (float)(radius * Math.Sin(phi) * Math.Cos(theta)),
                        Y = (float)(height * Math.Cos(phi)),
                        Z = (float)(radius * Math.Sin(phi) * Math.Sin(theta)),
                    };
                    //Vector3 n = Vector3.Normalize(v);
                    // Horizontal texture projection
                    Vector2 uv = new Vector2()
                    {
                        X = (float)(x / (segments - 1)),
                        Y = (float)(y / (rings - 1))
                    };
                    // Using data[i++] causes i to be incremented multiple times in Mono 2.2 (bug #479506).
                    data[i] = new VertexPositionTexture()
                    {
                        Position = v,
                        //Normal = n,
                        u = uv.X,
                        v = uv.Y,
                        a = byte.MaxValue,
                        r = byte.MaxValue,
                        g = byte.MaxValue,
                        b = byte.MaxValue,
                    };
                    i++;

                    // Top - down texture projection.
                    //Vector2 uv = new Vector2()
                    //{
                    //    X = (float)(Math.Atan2(n.X, n.Z) / Math.PI / 2 + 0.5),
                    //    Y = (float)(Math.Asin(n.Y) / Math.PI / 2 + 0.5)
                    //};
                }
            }
            return data;
        }
        public static void DrawWithLighting(Rectangle pos, Texture2D tex, Rectangle source, Color color = default)
        {
            if (Main.dedServ || !Helper.OnScreen(new Rectangle(pos.X, pos.Y, tex.Width, tex.Height)))
            {
                return;
            }
            if (color == default)
            {
                color = Color.White;
            }

            Matrix zoom = //Main.GameViewMatrix.ZoomMatrix;
                          new Matrix
                          (
                Main.GameViewMatrix.Zoom.X, 0, 0, 0,
                0, Main.GameViewMatrix.Zoom.X, 0, 0,
                0, 0, 1, 0,
                0, 0, 0, 1
                          );

            ApplyEffect.Parameters["screenSize"].SetValue(new Vector2(Main.screenWidth, Main.screenHeight));
            ApplyEffect.Parameters["texSize"].SetValue(tex.Size());
            ApplyEffect.Parameters["offset"].SetValue((pos.TopLeft()) / new Vector2(Main.screenWidth, Main.screenHeight));
            ApplyEffect.Parameters["zoom"].SetValue(zoom);
            ApplyEffect.Parameters["drawColor"].SetValue(color.ToVector4());

            ApplyEffect.Parameters["targetTexture"].SetValue(tex);
            ApplyEffect.Parameters["sampleTexture"].SetValue(StarlightRiver.LightingBufferInstance.ScreenLightingTexture);

            verticies[0] = new VertexPositionTexture(new Vector3(DrawHelper.ConvertX(pos.X + source.X), DrawHelper.ConvertY(pos.Y + source.Y), 0), source.TopLeft() / tex.Size());
            verticies[1] = new VertexPositionTexture(new Vector3(DrawHelper.ConvertX(pos.X + source.X + source.Width), DrawHelper.ConvertY(pos.Y + source.Y), 0), source.TopLeft() / tex.Size() + Vector2.UnitX * source.Width / tex.Width);
            verticies[2] = new VertexPositionTexture(new Vector3(DrawHelper.ConvertX(pos.X + source.X), DrawHelper.ConvertY(pos.Y + source.Y + source.Height), 0), source.TopLeft() / tex.Size() + Vector2.UnitY * source.Height / tex.Height);

            verticies[3] = new VertexPositionTexture(new Vector3(DrawHelper.ConvertX(pos.X + source.X + source.Width), DrawHelper.ConvertY(pos.Y + source.Y), 0), source.TopLeft() / tex.Size() + Vector2.UnitX * source.Width / tex.Width);
            verticies[4] = new VertexPositionTexture(new Vector3(DrawHelper.ConvertX(pos.X + source.X + source.Width), DrawHelper.ConvertY(pos.Y + source.Y + source.Height), 0), source.BottomRight() / tex.Size());
            verticies[5] = new VertexPositionTexture(new Vector3(DrawHelper.ConvertX(pos.X + source.X), DrawHelper.ConvertY(pos.Y + source.Y + source.Height), 0), source.TopLeft() / tex.Size() + Vector2.UnitY * source.Height / tex.Height);

            buffer.SetData(verticies);

            Main.instance.GraphicsDevice.SetVertexBuffer(buffer);

            foreach (EffectPass pass in ApplyEffect.CurrentTechnique.Passes)
            {
                pass.Apply();
                Main.instance.GraphicsDevice.DrawPrimitives(PrimitiveType.TriangleList, 0, 2);
            }

            Main.instance.GraphicsDevice.SetVertexBuffer(null);
        }
Beispiel #16
0
        public void createDecals()
        {
            VertexPositionTexture [] vertices = new VertexPositionTexture[MAX_DECALS * 4];
            int t = 0;

            for (int i = 0; i < cant_decals; ++i)
            {
                // determino en que cara vive el decal
                int f = que_face(decals[i].origin);
                if (f != -1)
                {
                    Vector3 n = Vector3.Cross(faces[f].v[2] - faces[f].v[0], faces[f].v[1] - faces[f].v[0]);
                    n.Normalize();
                    Vector3 up;
                    if (MathF.Abs(n.X) <= MathF.Abs(n.Y) && MathF.Abs(n.X) <= MathF.Abs(n.Z))
                    {
                        up = new Vector3(1, 0, 0);
                    }
                    else
                    if (MathF.Abs(n.Y) <= MathF.Abs(n.X) && MathF.Abs(n.Y) <= MathF.Abs(n.Z))
                    {
                        up = new Vector3(0, 1, 0);
                    }
                    else
                    {
                        up = new Vector3(0, 0, 1);
                    }

                    Vector3 v = Vector3.Cross(n, up);
                    v.Normalize();
                    Vector3 u = Vector3.Cross(n, v);
                    u.Normalize();

                    float du = 50;
                    float dv = 50;

                    Vector3 p = decals[i].origin - u * du * 0.5f - v * dv * 0.5f - n * 5;
                    vertices[t++] = new VertexPositionTexture(p, new Vector2(0, 0));
                    vertices[t++] = new VertexPositionTexture(p + u * du, new Vector2(0, 1));
                    vertices[t++] = new VertexPositionTexture(p + v * dv, new Vector2(-1, 0));
                    vertices[t++] = new VertexPositionTexture(p + u * du + v * dv, new Vector2(-1, 1));
                }
            }
            decalsVertexBuffer = new VertexBuffer(device, VertexPositionTexture.VertexDeclaration, MAX_DECALS, BufferUsage.WriteOnly);
            if (t > 0)
            {
                decalsVertexBuffer.SetData(vertices, 0, t);
            }
        }
Beispiel #17
0
        protected void InitXNA(int ext_vc, short[] tri_fin_vid_list, short[] ext_tri_list)
        {
            _vertexcount = tri_fin_vid_list.Length;
            _extendcount = ext_vc;

            _trianglecount = _vertexcount * DmS + ext_tri_list.Length / 3;

            _buffervertexcount = _vertexcount * DmS + _extendcount;

            //init vertex buffer
            _vertexlist   = new VertexPositionTexture[_buffervertexcount];
            _vertexbuffer = new DynamicVertexBuffer(_graphicsdevice, typeof(VertexPositionTexture), _buffervertexcount, BufferUsage.WriteOnly);

            //init each one
            for (int i = 0; i < _buffervertexcount; ++i)
            {
                _vertexlist[i] = new VertexPositionTexture(Vector3.Zero, Vector2.Zero);
            }

            //init index buffer
            _indexbuffer = new IndexBuffer(_graphicsdevice, IndexElementSize.SixteenBits, _trianglecount * 3, BufferUsage.WriteOnly);

            short[] indexs = new short[_trianglecount * 3];

            int w_p = 0;//current write position
            int gvc;

            //base
            for (gvc = 0; gvc < _vertexcount; ++gvc)
            {
                for (int subgvc = 0; subgvc < DmS; ++subgvc)
                {
                    indexs[w_p++] = (short)(gvc * DmS + subgvc);
                    indexs[w_p++] = (short)(gvc * DmS + subgvc + 1);
                    indexs[w_p++] = tri_fin_vid_list[gvc];
                }
            }
            indexs[w_p - 2] = 0;//cycle
            //extend
            gvc = 0;
            while (gvc < ext_tri_list.Length)
            {
                /*indexs[w_p++] = ext_tri_list[gvc++];
                *  indexs[w_p++] = ext_tri_list[gvc++];*/
                indexs[w_p++] = ext_tri_list[gvc++];
            }

            _indexbuffer.SetData(indexs);
        }
Beispiel #18
0
        private void SetUpWaterVertices()
        {
            VertexPositionTexture[] waterVertices = new VertexPositionTexture[6];

            waterVertices[0] = new VertexPositionTexture(new Vector3(0, waterHeight, 0), new Vector2(0, 1));
            waterVertices[2] = new VertexPositionTexture(new Vector3(terrainWidth, waterHeight, -terrainLength), new Vector2(1, 0));
            waterVertices[1] = new VertexPositionTexture(new Vector3(0, waterHeight, -terrainLength), new Vector2(0, 0));

            waterVertices[3] = new VertexPositionTexture(new Vector3(0, waterHeight, 0), new Vector2(0, 1));
            waterVertices[5] = new VertexPositionTexture(new Vector3(terrainWidth, waterHeight, 0), new Vector2(1, 1));
            waterVertices[4] = new VertexPositionTexture(new Vector3(terrainWidth, waterHeight, -terrainLength), new Vector2(1, 0));

            waterVertexBuffer = new VertexBuffer(device, waterVertices.Length * VertexPositionTexture.SizeInBytes, BufferUsage.WriteOnly);
            waterVertexBuffer.SetData(waterVertices);
        }
Beispiel #19
0
        public void SetUpWaterVertices(Game1 game, Terrain terrain)
        {
            VertexPositionTexture[] waterVertices = new VertexPositionTexture[6];

            waterVertices[0] = new VertexPositionTexture(new Vector3(0, waterHeight, 0), new Vector2(0, 1));
            waterVertices[2] = new VertexPositionTexture(new Vector3(terrain.terrainWidth * 4, waterHeight, -terrain.terrainLength * 4), new Vector2(1, 0));
            waterVertices[1] = new VertexPositionTexture(new Vector3(0, waterHeight, -terrain.terrainLength * 4), new Vector2(0, 0));

            waterVertices[3] = new VertexPositionTexture(new Vector3(0, waterHeight, 0), new Vector2(0, 1));
            waterVertices[5] = new VertexPositionTexture(new Vector3(terrain.terrainWidth * 4, waterHeight, 0), new Vector2(1, 1));
            waterVertices[4] = new VertexPositionTexture(new Vector3(terrain.terrainWidth * 4, waterHeight, -terrain.terrainLength * 4), new Vector2(1, 0));

            waterVertexBuffer = new VertexBuffer(game.GraphicsDevice, VertexPositionTexture.VertexDeclaration, waterVertices.Count(), BufferUsage.WriteOnly);
            waterVertexBuffer.SetData(waterVertices);
        }
        void SetupPlane(float width, float height)
        {
            // Setup plane
            Width  = width;
            Height = height;

            Verts[0] = new VertexPositionTexture(new Vector3(-width / 3f, -height / 3f, 0), new Vector2(0, 0));
            Verts[1] = new VertexPositionTexture(new Vector3(-width / 3f, height / 3f, 0), new Vector2(0, 1));
            Verts[2] = new VertexPositionTexture(new Vector3(width / 3f, -height / 3f, 0), new Vector2(1, 0));
            Verts[3] = new VertexPositionTexture(new Vector3(-width / 3f, height / 3f, 0), new Vector2(0, 1));
            Verts[4] = new VertexPositionTexture(new Vector3(width / 3f, height / 3f, 0), new Vector2(1, 1));
            Verts[5] = new VertexPositionTexture(new Vector3(width / 3f, -height / 3f, 0), new Vector2(1, 0));

            PlaneVertexBuffer.SetData(Verts);
        }
Beispiel #21
0
        void CreateTextureVertices()
        {
            texture = Content.Load <Texture2D>("uv_texture");
            //create the array
            textureVertices = new VertexPositionTexture[3];

            //instantiate the 3 vertices -> position and color
            textureVertices[0] = new VertexPositionTexture(new Vector3(1, 0, 0), new Vector2(1, 1));       //BR
            textureVertices[1] = new VertexPositionTexture(new Vector3(-1, 0, 0), new Vector2(0, 1));      //BL
            textureVertices[2] = new VertexPositionTexture(new Vector3(0, 1, 0), new Vector2(0.5f, 0.5f)); //TOP

            textureEffect = new BasicEffect(GraphicsDevice);
            textureEffect.TextureEnabled = true;
            textureEffect.Texture        = texture;
        }
Beispiel #22
0
        public void SetVertices()
        {
            vertices = new VertexPositionTexture[width * height];
            Vector2 texturePosition;

            for (int x = 0; x < width; x++)
            {
                for (int y = 0; y < height; y++)
                {
                    texturePosition         = new Vector2((float)x / 25.5f, (float)y / 25.5f);
                    vertices[x + y * width] = new VertexPositionTexture(new Vector3(x, heightMapData[x, y], -y), texturePosition);
                }
                //graphicsDevice.VertexDeclaration = new VertexDeclaration(graphicsDevice, VertexPositionTexture.VertexElements);
            }
        }
Beispiel #23
0
        public HPRenderer(Vector3 positionOffset)
        {
            this.hpTexture      = Game.Content.Load <Texture2D>(@"Sprites\WhiteBar");
            this.positionOffset = positionOffset;

            customEffect.CurrentTechnique = customEffect.Techniques["Billboard"];

            vertices[0] = new VertexPositionTexture(Vector3.Zero, new Vector2(0, 0));
            vertices[1] = new VertexPositionTexture(Vector3.Zero, new Vector2(1, 0));
            vertices[2] = new VertexPositionTexture(Vector3.Zero, new Vector2(1, 1));

            vertices[3] = new VertexPositionTexture(Vector3.Zero, new Vector2(0, 0));
            vertices[4] = new VertexPositionTexture(Vector3.Zero, new Vector2(1, 1));
            vertices[5] = new VertexPositionTexture(Vector3.Zero, new Vector2(0, 1));
        }
Beispiel #24
0
        public void ShouldSetAndGetData(bool dynamic)
        {
            Game.DrawWith += (sender, e) =>
            {
                var vertexBuffer = (dynamic)
                    ?new DynamicVertexBuffer(Game.GraphicsDevice, typeof(VertexPositionTexture), savedData.Length, BufferUsage.None)
                    :new VertexBuffer(Game.GraphicsDevice, typeof(VertexPositionTexture), savedData.Length, BufferUsage.None);
                vertexBuffer.SetData(savedData);

                var readData = new VertexPositionTexture[4];
                vertexBuffer.GetData(readData, 0, 4);
                Assert.AreEqual(savedData, readData);
            };
            Game.Run();
        }
Beispiel #25
0
        /// <summary>
        /// Fills the texture type buffer (VertexPositionTexture)
        /// </summary>
        /// <param name="points">The points.</param>
        /// <param name="destinationSize">Size of the destination.</param>
        /// <param name="sourceRect">The source rect.</param>
        /// <param name="primitiveType">Type of the primitive.</param>
        public override void FillTexture(List <PointF> points, Size destinationSize, Rect sourceRect, GeometryPrimitiveType primitiveType)
        {
            SetPrimitiveCount(primitiveType, points.Count);

            VertexPositionTexture[] vertex = new VertexPositionTexture[points.Count];
            for (int i = 0; i < points.Count; i++)
            {
                Vector2 uv = new Vector2(sourceRect.X + (points[i].X / destinationSize.Width) * sourceRect.Width,
                                         sourceRect.Y + (points[i].Y / destinationSize.Height) * sourceRect.Height);
                vertex[i] = new VertexPositionTexture(new Vector3(points[i].X, points[i].Y, 0), uv);
            }

            VertexBuffer = new VertexBuffer(FNARenderer.GraphicsDevice, VertexPositionTexture.VertexDeclaration, vertex.Length, BufferUsage.WriteOnly);
            VertexBuffer.SetData <VertexPositionTexture>(vertex);
        }
Beispiel #26
0
        protected override void InitialiserSommets()
        {
            int iSommet = 0;

            for (int j = 0; j < Dimensions.Y; ++j)
            {
                for (int i = 0; i < Dimensions.X + 1; ++i)
                {
                    Sommets[iSommet] = new VertexPositionTexture(Points[i, j], PointsTexture[i, j]);
                    ++iSommet;
                    Sommets[iSommet] = new VertexPositionTexture(Points[i, j + 1], PointsTexture[i, j + 1]);
                    ++iSommet;
                }
            }
        }
Beispiel #27
0
        public void ShouldSetAndGetData(bool dynamic)
        {
            var vertexBuffer = (dynamic)
                ?new DynamicVertexBuffer(gd, typeof(VertexPositionTexture), savedData.Length, BufferUsage.None)
                :new VertexBuffer(gd, typeof(VertexPositionTexture), savedData.Length, BufferUsage.None);

            vertexBuffer.SetData(savedData);

            var readData = new VertexPositionTexture[4];

            vertexBuffer.GetData(readData, 0, 4);
            Assert.AreEqual(savedData, readData);

            vertexBuffer.Dispose();
        }
Beispiel #28
0
        public static void Start()
        {
            AsyncManage.AsyncDelegate(() => { FileManage.LoadAppLayout("001.png", (t) => { maps = t; }); });
            int pid = RegPicture("polygon");

            iid.land  = RegImage(pid, 0);
            buff_land = new LandDate[64];
            VertexPositionTexture[] vpt = new VertexPositionTexture[384];//64*6
            for (int i = 1; i < 384; i++)
            {
                vpt[i].TextureCoordinate.Y = 1;
                i++;
                vpt[i].TextureCoordinate.X = 0.25f;
                i++;
                vpt[i].TextureCoordinate.X = 0.25f;
                i++;
                vpt[i].TextureCoordinate.Y = 1;
                i++;
                vpt[i].TextureCoordinate.X = 0.25f;
                vpt[i].TextureCoordinate.Y = 1;
                i++;
            }
            buff_img[iid.land].vertex = vpt;
            iid.needle = RegImage(pid, 0);
            vpt        = new VertexPositionTexture[384];//128*3
            for (int i = 0; i < 384; i++)
            {
                vpt[i].TextureCoordinate.X = 0.25f;
                vpt[i].TextureCoordinate.Y = 1;
                i++;
                vpt[i].TextureCoordinate.X = 0.375f;
                i++;
                vpt[i].TextureCoordinate.X = 0.5f;
                vpt[i].TextureCoordinate.Y = 1;
            }
            buff_img[iid.needle].vertex = vpt;
            save        = FileManage.LoadArichive();
            role        = new Role();
            role.points = new Point2[4];
            role.pid    = RegPicture("wanna");
            role.imgid  = RegImage(role.pid, 0);
            vpt         = new VertexPositionTexture[6];
            buff_img[role.imgid].vertex = vpt;
            SetTex_PosA(ref buff_img[role.imgid].vertex, 0, Vector2.Zero);
            Initial();
            buff_t[0].col.A = 255;
            buff_t[0].col.R = 255;
        }
Beispiel #29
0
        private void CalculatePenumbraVertices(int startingIndex, int endingIndex, Vector2 lightSourcePos, bool los)
        {
            Vector3 offset = Vector3.Zero;
            if (parentEntity != null && parentEntity.Submarine != null)
            {
                offset = new Vector3(parentEntity.Submarine.DrawPosition.X, parentEntity.Submarine.DrawPosition.Y, 0.0f);
            }

            for (int n = 0; n < 4; n += 3)
            {
                Vector3 penumbraStart = new Vector3((n == 0) ? vertices[startingIndex].Pos : vertices[endingIndex].Pos, 0.0f);

                penumbraVertices[n] = new VertexPositionTexture();
                penumbraVertices[n].Position = penumbraStart + offset;
                penumbraVertices[n].TextureCoordinate = new Vector2(0.0f, 1.0f);
                //penumbraVertices[0].te = fow ? Color.Black : Color.Transparent;

                for (int i = 0; i < 2; i++)
                {
                    penumbraVertices[n + i + 1] = new VertexPositionTexture();
                    Vector3 vertexDir = penumbraStart - new Vector3(lightSourcePos, 0);
                    vertexDir.Normalize();

                    Vector3 normal = (i == 0) ? new Vector3(-vertexDir.Y, vertexDir.X, 0.0f) : new Vector3(vertexDir.Y, -vertexDir.X, 0.0f) * 0.05f;
                    if (n > 0) normal = -normal;

                    vertexDir = penumbraStart - (new Vector3(lightSourcePos, 0) - normal * 20.0f);
                    vertexDir.Normalize();
                    penumbraVertices[n + i + 1].Position = new Vector3(lightSourcePos, 0) + vertexDir * 9000 + offset;

                    if (los)
                    {
                        penumbraVertices[n + i + 1].TextureCoordinate = (i == 0) ? new Vector2(0.05f, 0.0f) : new Vector2(1.0f, 0.0f);
                    }
                    else
                    {
                        penumbraVertices[n + i + 1].TextureCoordinate = (i == 0) ? new Vector2(1.0f, 0.0f) : Vector2.Zero;
                    }
                }

                if (n > 0)
                {
                    var temp = penumbraVertices[4];
                    penumbraVertices[4] = penumbraVertices[5];
                    penumbraVertices[5] = temp;
                }
            }
        }
        public Terrain(float Scale)
        {
            //Get the textures and color for the terrain
            TerrainMap = Manager.GeneratePerlinNoise(MyGame.random.Next(15, 30));
            Color[] textureData = new Color[TerrainMap.Width * TerrainMap.Height];
            TerrainMap.GetData <Color>(textureData);
            Color[] ColorScheme = Manager.GenerateStaticNoise(8, 8);
            for (int i = 0; i < ColorScheme.Length; i++)
            {
                ColorScheme[i] = Color.Lerp(ColorScheme[i], Color.Black, 0.8f + 0.2f * (float)MyGame.random.NextDouble());
            }
            ColorMap = new Texture2D(MyGame.graphics.GraphicsDevice, 8, 8);
            ColorMap.SetData <Color>(ColorScheme);

            //Calculate the necessary number of vertices to make the terrain mesh
            this.Scale = Scale;
            GridWidth  = TerrainMap.Width / 10;
            GridHeight = TerrainMap.Width / 10;
            //Initializes the terrain with modulation based on the noise texture
            Grid            = new VertexPositionTexture[GridWidth * GridHeight];
            GridDeclaration = new VertexDeclaration(MyGame.graphics.GraphicsDevice, VertexPositionTexture.VertexElements);
            for (int x = 0; x < GridWidth; x++)
            {
                for (int y = 0; y < GridHeight; y++)
                {
                    Grid[x + y * GridWidth] = new VertexPositionTexture(
                        new Vector3(x * Scale
                                    , Scale * (textureData[5 * x + 5 * y * TerrainMap.Width].B / 32.0f - 8.0f)
                                    , y * Scale)
                        , new Vector2((float)x / (GridWidth - 1.0f), (float)y / (GridHeight - 1.0f)));
                }
            }
            int counter = 0;

            IndexBuffer = new int[6 * (GridWidth - 1) * (GridHeight - 1)];
            for (int x = 0; x < GridWidth - 1; x++)
            {
                for (int y = 0; y < GridHeight - 1; y++)
                {
                    IndexBuffer[counter++] = x + y * GridWidth;
                    IndexBuffer[counter++] = x + 1 + y * GridWidth;
                    IndexBuffer[counter++] = x + 1 + (y + 1) * GridWidth;
                    IndexBuffer[counter++] = x + y * GridWidth;
                    IndexBuffer[counter++] = x + 1 + (y + 1) * GridWidth;
                    IndexBuffer[counter++] = x + (y + 1) * GridWidth;
                }
            }
        }
        void CreateCubeVertexBuffer()
        {
            VertexPositionTexture[] cubeVertices = new VertexPositionTexture[number_of_vertices];

            cubeVertices [0].Position = new Vector3(-1, -1, -1);
            cubeVertices [1].Position = new Vector3(-1, -1, 1);
            cubeVertices [2].Position = new Vector3(1, -1, 1);
            cubeVertices [3].Position = new Vector3(1, -1, -1);
            cubeVertices [4].Position = new Vector3(-1, 1, -1);
            cubeVertices [5].Position = new Vector3(-1, 1, 1);
            cubeVertices [6].Position = new Vector3(1, 1, 1);
            cubeVertices [7].Position = new Vector3(1, 1, -1);

            vertices = new VertexBuffer(GraphicsDevice, VertexPositionTexture.VertexDeclaration, number_of_vertices, BufferUsage.WriteOnly);
            vertices.SetData(cubeVertices);
        }
        //private VertexBuffer _vBuffer;
        //private IndexBuffer _iBuffer;

        public QuadRenderer(GraphicsDevice graphicsDevice)
        {
            _vertexBuffer    = new VertexPositionTexture[4];
            _vertexBuffer[0] = new VertexPositionTexture(new Vector3(-1, 1, 1), new Vector2(0, 0));
            _vertexBuffer[1] = new VertexPositionTexture(new Vector3(1, 1, 1), new Vector2(1, 0));
            _vertexBuffer[2] = new VertexPositionTexture(new Vector3(-1, -1, 1), new Vector2(0, 1));
            _vertexBuffer[3] = new VertexPositionTexture(new Vector3(1, -1, 1), new Vector2(1, 1));

            _indexBuffer = new short[] { 0, 3, 2, 0, 1, 3 };

            //_vBuffer = new VertexBuffer(graphicsDevice, VertexPositionTexture.VertexDeclaration, 4, BufferUsage.WriteOnly);
            //_iBuffer = new IndexBuffer(graphicsDevice, IndexElementSize.SixteenBits, 6, BufferUsage.WriteOnly);

            //_vBuffer.SetData(_vertexBuffer);
            //_iBuffer.SetData(_indexBuffer);
        }
        private void createBillboardVerticesFromList(List<Vector3> treeList)
        {
            if (!treeList.Any())
                return;

            var billboardVertices = new VertexPositionTexture[treeList.Count*6];
            var i = 0;
            foreach (var currentV3 in treeList)
            {
                billboardVertices[i++] = new VertexPositionTexture(currentV3, new Vector2(0, 0));
                billboardVertices[i++] = new VertexPositionTexture(currentV3, new Vector2(1, 0));
                billboardVertices[i++] = new VertexPositionTexture(currentV3, new Vector2(1, 1));

                billboardVertices[i++] = new VertexPositionTexture(currentV3, new Vector2(0, 0));
                billboardVertices[i++] = new VertexPositionTexture(currentV3, new Vector2(1, 1));
                billboardVertices[i++] = new VertexPositionTexture(currentV3, new Vector2(0, 1));
            }

            _vertexBuffer = Buffer.Vertex.New(Effect.GraphicsDevice, billboardVertices);
            _vertexInputLayout = VertexInputLayout.FromBuffer(0, _vertexBuffer);
        }
Beispiel #34
0
        public MyModel CreateTexturedCube(String texturePath, Vector3 size)
        {
            VertexPositionTexture[] shapeArray = new VertexPositionTexture[]{
            new VertexPositionTexture(new Vector3(-1.0f, -1.0f, -1.0f), new Vector2(1f, 2/3f)), // Front
            new VertexPositionTexture(new Vector3(1.0f, 1.0f, -1.0f), new Vector2(3/4f, 1/3f)),
            new VertexPositionTexture(new Vector3(-1.0f, 1.0f, -1.0f), new Vector2(1f, 1/3f)),

            new VertexPositionTexture(new Vector3(-1.0f, -1.0f, -1.0f), new Vector2(1f, 2/3f)),
            new VertexPositionTexture(new Vector3(1.0f, -1.0f, -1.0f), new Vector2(3/4f, 2/3f)),
            new VertexPositionTexture(new Vector3(1.0f, 1.0f, -1.0f), new Vector2(3/4f, 1/3f)),

            new VertexPositionTexture(new Vector3(-1.0f, -1.0f, 1.0f), new Vector2(1/4f, 2/3f)), // BACK
            new VertexPositionTexture(new Vector3(-1.0f, 1.0f, 1.0f), new Vector2(1/4f, 1/3f)),
            new VertexPositionTexture(new Vector3(1.0f, 1.0f, 1.0f), new Vector2(2/4f, 1/3f)),

            new VertexPositionTexture(new Vector3(-1.0f, -1.0f, 1.0f), new Vector2(1/4f, 2/3f)),
            new VertexPositionTexture(new Vector3(1.0f, 1.0f, 1.0f), new Vector2(2/4f, 1/3f)),
            new VertexPositionTexture(new Vector3(1.0f, -1.0f, 1.0f), new Vector2(2/4f, 2/3f)),

            new VertexPositionTexture(new Vector3(-1.0f, 1.0f, -1.0f), new Vector2(1/4f, 0.0f)), // Top
            new VertexPositionTexture(new Vector3(1.0f, 1.0f, 1.0f), new Vector2(2/4f, 1/3f)),
            new VertexPositionTexture(new Vector3(-1.0f, 1.0f, 1.0f), new Vector2(1/4f, 1/3f)),

            new VertexPositionTexture(new Vector3(-1.0f, 1.0f, -1.0f), new Vector2(1/4f, 1/3f)),
            new VertexPositionTexture(new Vector3(1.0f, 1.0f, -1.0f), new Vector2(2/4f, 1/3f)),
            new VertexPositionTexture(new Vector3(1.0f, 1.0f, 1.0f), new Vector2(2/4f, 0.0f)),

            new VertexPositionTexture(new Vector3(-1.0f, -1.0f, -1.0f), new Vector2(1/4f, 1.0f)), // Bottom
            new VertexPositionTexture(new Vector3(-1.0f, -1.0f, 1.0f), new Vector2(1/4f, 2/3f)),
            new VertexPositionTexture(new Vector3(1.0f, -1.0f, 1.0f), new Vector2(2/4f, 2/3f)),

            new VertexPositionTexture(new Vector3(-1.0f, -1.0f, -1.0f), new Vector2(1/4f, 1.0f)),
            new VertexPositionTexture(new Vector3(1.0f, -1.0f, 1.0f), new Vector2(2/4f, 2/3f)),
            new VertexPositionTexture(new Vector3(1.0f, -1.0f, -1.0f), new Vector2(2/4f, 1.0f)),

            new VertexPositionTexture(new Vector3(-1.0f, -1.0f, -1.0f), new Vector2(0.0f, 2/3f)), // Left
            new VertexPositionTexture(new Vector3(-1.0f, 1.0f, 1.0f), new Vector2(1/4f, 1/3f)),
            new VertexPositionTexture(new Vector3(-1.0f, -1.0f, 1.0f), new Vector2(1/4f, 2/3f)),

            new VertexPositionTexture(new Vector3(-1.0f, -1.0f, -1.0f), new Vector2(0.0f, 2/3f)),
            new VertexPositionTexture(new Vector3(-1.0f, 1.0f, -1.0f), new Vector2(0.0f, 1/3f)),
            new VertexPositionTexture(new Vector3(-1.0f, 1.0f, 1.0f), new Vector2(1/4f, 1/3f)),

            new VertexPositionTexture(new Vector3(1.0f, -1.0f, -1.0f), new Vector2(3/4f, 2/3f)), // Right
            new VertexPositionTexture(new Vector3(1.0f, -1.0f, 1.0f), new Vector2(2/4f, 2/3f)),
            new VertexPositionTexture(new Vector3(1.0f, 1.0f, 1.0f), new Vector2(2/4f, 1/3f)),

            new VertexPositionTexture(new Vector3(1.0f, -1.0f, -1.0f), new Vector2(3/4f, 2/3f)),
            new VertexPositionTexture(new Vector3(1.0f, 1.0f, 1.0f), new Vector2(2/4f, 1/3f)),
            new VertexPositionTexture(new Vector3(1.0f, 1.0f, -1.0f), new Vector2(3/4f, 1/3f)),

            };

            for (int i = 0; i < shapeArray.Length; i++)
            {
                shapeArray[i].Position.X *= size.X / 2;
                shapeArray[i].Position.Y *= size.Y / 2;
                shapeArray[i].Position.Z *= size.Z / 2;
            }

            return new MyModel(game, shapeArray, texturePath);
        }
Beispiel #35
0
        public MyModel CreateTexturedCube(String texturePath, Vector3 size)
        {
            VertexPositionTexture[] shapeArray = new VertexPositionTexture[]{
            new VertexPositionTexture(new Vector3(-1.0f, -1.0f, -1.0f), new Vector2(0.0f, 1.0f)), // Front
            new VertexPositionTexture(new Vector3(-1.0f, 1.0f, -1.0f), new Vector2(0.0f, 0.0f)),
            new VertexPositionTexture(new Vector3(1.0f, 1.0f, -1.0f), new Vector2(1.0f, 0.0f)),
            new VertexPositionTexture(new Vector3(-1.0f, -1.0f, -1.0f), new Vector2(0.0f, 1.0f)),
            new VertexPositionTexture(new Vector3(1.0f, 1.0f, -1.0f), new Vector2(1.0f, 0.0f)),
            new VertexPositionTexture(new Vector3(1.0f, -1.0f, -1.0f), new Vector2(1.0f, 1.0f)),

            new VertexPositionTexture(new Vector3(-1.0f, -1.0f, 1.0f), new Vector2(1.0f, 1.0f)), // BACK
            new VertexPositionTexture(new Vector3(1.0f, 1.0f, 1.0f), new Vector2(0.0f, 0.0f)),
            new VertexPositionTexture(new Vector3(-1.0f, 1.0f, 1.0f), new Vector2(1.0f, 0.0f)),
            new VertexPositionTexture(new Vector3(-1.0f, -1.0f, 1.0f), new Vector2(1.0f, 1.0f)),
            new VertexPositionTexture(new Vector3(1.0f, -1.0f, 1.0f), new Vector2(0.0f, 1.0f)),
            new VertexPositionTexture(new Vector3(1.0f, 1.0f, 1.0f), new Vector2(0.0f, 0.0f)),

            new VertexPositionTexture(new Vector3(-1.0f, 1.0f, -1.0f), new Vector2(0.0f, 1.0f)), // Top
            new VertexPositionTexture(new Vector3(-1.0f, 1.0f, 1.0f), new Vector2(0.0f, 0.0f)),
            new VertexPositionTexture(new Vector3(1.0f, 1.0f, 1.0f), new Vector2(1.0f, 0.0f)),
            new VertexPositionTexture(new Vector3(-1.0f, 1.0f, -1.0f), new Vector2(0.0f, 1.0f)),
            new VertexPositionTexture(new Vector3(1.0f, 1.0f, 1.0f), new Vector2(1.0f, 0.0f)),
            new VertexPositionTexture(new Vector3(1.0f, 1.0f, -1.0f), new Vector2(1.0f, 1.0f)),

            new VertexPositionTexture(new Vector3(-1.0f, -1.0f, -1.0f), new Vector2(0.0f, 0.0f)), // Bottom
            new VertexPositionTexture(new Vector3(1.0f, -1.0f, 1.0f), new Vector2(1.0f, 1.0f)),
            new VertexPositionTexture(new Vector3(-1.0f, -1.0f, 1.0f), new Vector2(0.0f, 1.0f)),
            new VertexPositionTexture(new Vector3(-1.0f, -1.0f, -1.0f), new Vector2(0.0f, 0.0f)),
            new VertexPositionTexture(new Vector3(1.0f, -1.0f, -1.0f), new Vector2(1.0f, 0.0f)),
            new VertexPositionTexture(new Vector3(1.0f, -1.0f, 1.0f), new Vector2(1.0f, 1.0f)),

            new VertexPositionTexture(new Vector3(-1.0f, -1.0f, -1.0f), new Vector2(1.0f, 1.0f)), // Left
            new VertexPositionTexture(new Vector3(-1.0f, -1.0f, 1.0f), new Vector2(0.0f, 1.0f)),
            new VertexPositionTexture(new Vector3(-1.0f, 1.0f, 1.0f), new Vector2(0.0f, 0.0f)),
            new VertexPositionTexture(new Vector3(-1.0f, -1.0f, -1.0f), new Vector2(1.0f, 1.0f)),
            new VertexPositionTexture(new Vector3(-1.0f, 1.0f, 1.0f), new Vector2(0.0f, 0.0f)),
            new VertexPositionTexture(new Vector3(-1.0f, 1.0f, -1.0f), new Vector2(1.0f, 0.0f)),

            new VertexPositionTexture(new Vector3(1.0f, -1.0f, -1.0f), new Vector2(0.0f, 1.0f)), // Right
            new VertexPositionTexture(new Vector3(1.0f, 1.0f, 1.0f), new Vector2(1.0f, 0.0f)),
            new VertexPositionTexture(new Vector3(1.0f, -1.0f, 1.0f), new Vector2(1.0f, 1.0f)),
            new VertexPositionTexture(new Vector3(1.0f, -1.0f, -1.0f), new Vector2(0.0f, 1.0f)),
            new VertexPositionTexture(new Vector3(1.0f, 1.0f, -1.0f), new Vector2(0.0f, 0.0f)),
            new VertexPositionTexture(new Vector3(1.0f, 1.0f, 1.0f), new Vector2(1.0f, 0.0f)),
            };

            for (int i = 0; i < shapeArray.Length; i++)
            {
                shapeArray[i].Position.X *= size.X / 2;
                shapeArray[i].Position.Y *= size.Y / 2;
                shapeArray[i].Position.Z *= size.Z / 2;
            }

            float collisionRadius = (size.X + size.Y + size.Z) / 6 ;
            return new MyModel(game, shapeArray, texturePath, collisionRadius);
        }
Beispiel #36
0
        /// <summary>
        /// Performs further custom initialization for this instance.
        /// </summary>
        /// <exception cref="System.ObjectDisposedException">Skybox disposed.</exception>
        protected override void Initialize()
        {
            if (this.disposed)
            {
                throw new ObjectDisposedException("Skybox");
            }

            base.Initialize();

            this.material = new SkyboxMaterial(this.cubemapTexture);
            this.material.Initialize(this.Assets);

            Vector3[] normals =
            {
                new Vector3(0, 0, 1), 
                new Vector3(0, 0, -1), 
                new Vector3(1, 0, 0),
                new Vector3(-1, 0, 0), 
                new Vector3(0, 1, 0), 
                new Vector3(0, -1, 0)
            };

            Vector2[] texCoord = 
            {
                new Vector2(1, 1), new Vector2(0, 1), new Vector2(0, 0), new Vector2(1, 0),
                new Vector2(0, 0), new Vector2(1, 0), new Vector2(1, 1), new Vector2(0, 1),
                new Vector2(1, 0), new Vector2(1, 1), new Vector2(0, 1), new Vector2(0, 0),
                new Vector2(1, 0), new Vector2(1, 1), new Vector2(0, 1), new Vector2(0, 0),
                new Vector2(0, 1), new Vector2(0, 0), new Vector2(1, 0), new Vector2(1, 1),
                new Vector2(1, 0), new Vector2(1, 1), new Vector2(0, 1), new Vector2(0, 0),
            };

            float sizeOverTwo = 0.5f;

            ushort[] indices = new ushort[36];
            VertexPositionTexture[] vertices = new VertexPositionTexture[24];

            ushort currentIndice = 0;
            ushort currentVertex = 0;

            // Create each face in turn.
            for (int i = 0, j = 0; i < normals.Length; i++, j += 4)
            {
                Vector3 normal = normals[i];

                // Get two vectors perpendicular to the face normal and to each other.
                Vector3 side1 = new Vector3(normal.Y, normal.Z, normal.X);
                Vector3 side2 = Vector3.Cross(normal, side1);

                // Six indices (two triangles) per face.
                indices[currentIndice++] = (ushort)(currentVertex + 0);
                indices[currentIndice++] = (ushort)(currentVertex + 1);
                indices[currentIndice++] = (ushort)(currentVertex + 3);

                indices[currentIndice++] = (ushort)(currentVertex + 1);
                indices[currentIndice++] = (ushort)(currentVertex + 2);
                indices[currentIndice++] = (ushort)(currentVertex + 3);

                // 1   2
                // 0   3

                // Four vertices per face.
                vertices[currentVertex].Position = (normal - side1 - side2) * sizeOverTwo;
                vertices[currentVertex++].TexCoord = texCoord[j + 0];
                vertices[currentVertex].Position = (normal - side1 + side2) * sizeOverTwo;
                vertices[currentVertex++].TexCoord = texCoord[j + 1];
                vertices[currentVertex].Position = (normal + side1 + side2) * sizeOverTwo;
                vertices[currentVertex++].TexCoord = texCoord[j + 2];
                vertices[currentVertex].Position = (normal + side1 - side2) * sizeOverTwo;
                vertices[currentVertex++].TexCoord = texCoord[j + 3];
            }

            VertexBuffer vertexBuffer = new VertexBuffer(VertexPositionTexture.VertexFormat);
            vertexBuffer.SetData(vertices, 24);

            IndexBuffer indexBuffer = new IndexBuffer(indices);

            // create the quad
            this.cubeMesh = new Mesh(0, 24, 0, 12, vertexBuffer, indexBuffer, PrimitiveType.TriangleList);
        }
Beispiel #37
0
            public static Mesh Create(Graphics gfx)
            {
                var spriteVerts = new VertexPositionTexture[]
                {
                    new VertexPositionTexture ((-Vector3.Right - Vector3.Forward) / 2, new Vector2(0f, 1f)),
                    new VertexPositionTexture ((-Vector3.Right + Vector3.Forward) / 2, new Vector2(0f, 0f)),
                    new VertexPositionTexture ((Vector3.Right + Vector3.Forward) / 2, new Vector2(1f, 0f)),
                    new VertexPositionTexture ((Vector3.Right - Vector3.Forward) / 2, new Vector2(1f, 1f))
                };

                var spriteIndices = new Int32[]
                {
                    0,1,2,
                    0,2,3
                };

                var vertexBuffer = gfx.CreateVertexBuffer(
                  VertexPositionTexture.Default.VertexDeclaration,
                  spriteVerts.Length);
                var indexBuffer = gfx.CreateIndexBuffer(
                    spriteIndices.Length);

                  vertexBuffer.SetData(spriteVerts);
                  indexBuffer.SetData(spriteIndices);

                return new Mesh (vertexBuffer, indexBuffer);
            }