示例#1
1
文件: Wall.cs 项目: Woodje/3DGame
        public void LoadContent(ContentManager content, GraphicsDeviceManager graphicsDeviceManager)
        {
            texture = content.Load<Texture2D>("brick_texture_map");

            wall = new VertexPositionTexture[22];
            wall[0] = new VertexPositionTexture(new Vector3(200, 0, 200), new Vector2(0, 0));
            wall[1] = new VertexPositionTexture(new Vector3(200, 200, 200), new Vector2(2, 0));
            wall[2] = new VertexPositionTexture(new Vector3(0, 0, 200), new Vector2(0, 2));
            wall[3] = new VertexPositionTexture(new Vector3(0, 200, 200), new Vector2(2, 2));
            wall[4] = new VertexPositionTexture(new Vector3(0, 0, 220), new Vector2(0, 0));
            wall[5] = new VertexPositionTexture(new Vector3(0, 200, 220), new Vector2(2, 0));
            wall[6] = new VertexPositionTexture(new Vector3(200, 0, 220), new Vector2(0, 2));
            wall[7] = new VertexPositionTexture(new Vector3(200, 200, 220), new Vector2(2, 2));
            wall[8] = new VertexPositionTexture(new Vector3(200, 0, 200), new Vector2(0, 0));
            wall[9] = new VertexPositionTexture(new Vector3(200, 200, 220), new Vector2(2, 0));
            wall[10] = new VertexPositionTexture(new Vector3(200, 200, 200), new Vector2(2, 2));
            wall[11] = new VertexPositionTexture(new Vector3(0, 200, 220), new Vector2(0, 2));
            wall[12] = new VertexPositionTexture(new Vector3(0, 200, 200), new Vector2(0, 0));

            // Set vertex data in VertexBuffer
            vertexBuffer = new VertexBuffer(graphicsDeviceManager.GraphicsDevice, typeof(VertexPositionTexture), wall.Length, BufferUsage.None);
            vertexBuffer.SetData(wall);

            // Initialize the BasicEffect
            effect = new BasicEffect(graphicsDeviceManager.GraphicsDevice);
        }
        // To get the texture you want to draw
        public BoardTexture()
        {
            // Initialization of each value
            this.pos = Vector3.Zero;
            this.scale = Vector3.One;
            this.rotation = Vector3.Zero;
            this.alpha = 1.0f;

            // Effects creation
            this.basicEffect = Game1.basicEffect;
            // I authorize the use of texture
            this.basicEffect.TextureEnabled = true;

            // Create a vertex buffer
            this.vertexBuffer = new VertexBuffer(
                                        Game1.graphics.GraphicsDevice,
                                        typeof(VertexPositionTexture),
                                        4,
                                        BufferUsage.None);

            // I want to create the vertex data
            VertexPositionTexture[] vertices = new VertexPositionTexture[4];
            // I want to set the value of each vertex
            vertices[0] = new VertexPositionTexture(new Vector3(-1.0f, 1.0f, 1.0f),
                                                new Vector2(0.0f, 0.0f));
            vertices[1] = new VertexPositionTexture(new Vector3(1.0f, 1.0f, 1.0f),
                                                new Vector2(1.0f, 0.0f));
            vertices[2] = new VertexPositionTexture(new Vector3(-1.0f, -1.0f, 1.0f),
                                                new Vector2(0.0f, 1.0f));
            vertices[3] = new VertexPositionTexture(new Vector3(1.0f, -1.0f, 1.0f),
                                                new Vector2(1.0f, 1.0f));

            // I write in the vertex buffer vertex data
            this.vertexBuffer.SetData(vertices);
        }
示例#3
0
        public static void Render(GraphicsDevice device, Color color)
        {
            BasicEffect _effect = new BasicEffect(device);
            _effect.Texture = new Texture2D(device, 1, 1);
            _effect.Texture.SetData<Color>(new Microsoft.Xna.Framework.Color[] { color });
            _effect.TextureEnabled = true;
            //_effect.VertexColorEnabled = true;

            VertexPositionTexture[] _vertices = new VertexPositionTexture[3];

            _vertices[0].Position = new Vector3(.5f,.5f,0);
            _vertices[1].Position = new Vector3(-.5f, -.5f, 0);
            _vertices[2].Position = new Vector3(.5f, 0f, 0);

            foreach (var pass in _effect.CurrentTechnique.Passes)
            {
                pass.Apply();

                device.DrawUserIndexedPrimitives<VertexPositionTexture>
                (
                    PrimitiveType.TriangleStrip, // same result with TriangleList
                    _vertices,
                    0,
                    _vertices.Length,
                    new int[] { 0, 1, 2 },
                    0,
                    1
                );
            }

        }
示例#4
0
        private void InitializeParticleVertices()
        {
            verts = new VertexPositionTexture[maxParticles * 4];
            vertexColorArray = new Color[maxParticles];

            Color[] colors = new Color[particleColorsTexture.Width * particleColorsTexture.Height];
            particleColorsTexture.GetData(colors);

            for (int i = 0; i < maxParticles; ++i)
            {
                float size = (float)rand.NextDouble() * particleSettings.maxSize;

                Vector3 position = new Vector3(rand.Next(-(int)maxPosition.X,(int)maxPosition.X),rand.Next(-(int)maxPosition.Y,(int)maxPosition.Y),maxPosition.Z);

                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));

                vertexColorArray[i] = colors[(rand.Next(0,particleColorsTexture.Height) *  particleColorsTexture.Width) + rand.Next(0,particleColorsTexture.Width)];
            }

            particleVertexBuffer = new VertexBuffer(graphicDevice, typeof(VertexPositionTexture), verts.Length, BufferUsage.None);
        }
示例#5
0
文件: Taku.cs 项目: wistery-k/Mjai3D
        public void Draw(GraphicsDevice device, BasicEffect effect)
        {
            if (buf == null)
            {
                buf = new VertexBuffer(device, typeof(VertexPositionTexture), 4, BufferUsage.None);
                var vpt = new VertexPositionTexture[4]{
                    new VertexPositionTexture(new Vector3(0, 0, 0), new Vector2(0,0)),
                    new VertexPositionTexture(new Vector3(SIZE, 0, 0), new Vector2(1,0)),
                    new VertexPositionTexture(new Vector3(0, 0, SIZE), new Vector2(0,1)),
                    new VertexPositionTexture(new Vector3(SIZE, 0, SIZE), new Vector2(1,1))
                };

                buf.SetData(vpt);
            }

            device.SetVertexBuffer(buf);

            effect.TextureEnabled = true;
            effect.Texture = texture;

            foreach (EffectPass pass in effect.CurrentTechnique.Passes)
            {
                pass.Apply();
                device.DrawPrimitives(PrimitiveType.TriangleStrip, 0, 2);
            }
        }
        public static void initialize()
        {
            vertex = new VertexPositionTexture[4];
            vertex[0].Position = new Vector3(-0.5f,-0.5f, 0.0f);
            vertex[0].TextureCoordinate = new Vector2(0.0f, 1.0f);
            //vertex[0].Color = new Color(1, 1, 1, 1);
            vertex[1].Position = new Vector3(-0.5f, 0.5f, 0.0f);
            vertex[1].TextureCoordinate = new Vector2(0.0f, 0.0f);
            //vertex[1].Color = new Color(1, 1, 1, 1);
            vertex[2].Position = new Vector3(0.5f, -0.5f, 0.0f);
            vertex[2].TextureCoordinate = new Vector2(1.0f, 1.0f);
            //vertex[2].Color = new Color(1, 1, 1, 1);
            vertex[3].Position = new Vector3(0.5f, 0.5f, 0.0f);
            vertex[3].TextureCoordinate = new Vector2(1.0f, 0.0f);
            //vertex[3].Color = new Color(1, 1, 1, 1);

            vertexUVs = new VertexPositionTexture[4];
            vertexUVs[0].Position = new Vector3(-0.5f, -0.5f, 0.0f);
            //vertexUVs[0].Color = new Color(1, 1, 1, 1);
            vertexUVs[1].Position = new Vector3(-0.5f, 0.5f, 0.0f);
            //vertexUVs[1].Color = new Color(1, 1, 1, 1);
            vertexUVs[2].Position = new Vector3(0.5f, -0.5f, 0.0f);
            //vertexUVs[2].Color = new Color(1, 1, 1, 1);
            vertexUVs[3].Position = new Vector3(0.5f, 0.5f, 0.0f);
            //vertexUVs[3].Color = new Color(1, 1, 1, 1);
        }
示例#7
0
 void CréerTableauSommets()
 {
    PtsTexture = new Vector2[NbColonnes + 1, NbRangées + 1];
    PtsSommets = new Vector3[NbColonnes + 1, NbRangées - 1]; //-1, texture occupe le haut et le bas, donc 2 rangées de moins dans les ptsSommets
    Sommets = new VertexPositionTexture[NbSommets];
    CréerTableauPointsTexture();
 }
示例#8
0
        public SkyplaneEngine(InfiniminerGame gameInstance)
        {
            this.gameInstance = gameInstance;

            // Generate a noise texture.
            randGen = new Random();
            texNoise = new Texture2D(gameInstance.GraphicsDevice, 64, 64);
            uint[] noiseData = new uint[64*64];
            for (int i = 0; i < 64 * 64; i++)
                if (randGen.Next(32) == 0)
                    noiseData[i] = Color.White.PackedValue;
                else
                    noiseData[i] = Color.Black.PackedValue;
            texNoise.SetData(noiseData);

            // Load the effect file.
            effect = gameInstance.Content.Load<Effect>("effect_skyplane");

            // Create our vertices.
            vertexDeclaration = new VertexDeclaration(gameInstance.GraphicsDevice, VertexPositionTexture.VertexElements);
            vertices = new VertexPositionTexture[6];
            vertices[0] = new VertexPositionTexture(new Vector3(-210, 100, -210), new Vector2(0, 0));
            vertices[1] = new VertexPositionTexture(new Vector3(274, 100, -210), new Vector2(1, 0));
            vertices[2] = new VertexPositionTexture(new Vector3(274, 100, 274), new Vector2(1, 1));
            vertices[3] = new VertexPositionTexture(new Vector3(-210, 100, -210), new Vector2(0, 0));
            vertices[4] = new VertexPositionTexture(new Vector3(274, 100, 274), new Vector2(1, 1));
            vertices[5] = new VertexPositionTexture(new Vector3(-210, 100, 274), new Vector2(0, 1));
        }
示例#9
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            // Initialize vertices
            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(1, 0));
            verts[2] = new VertexPositionTexture(
                new Vector3(-1, -1, 0), new Vector2(0, 1));
            verts[3] = new VertexPositionTexture(
                new Vector3(1, -1, 0), new Vector2(1, 1));

            // Set vertex data in VertexBuffer
            vertexBuffer = new VertexBuffer(GraphicsDevice, typeof(VertexPositionTexture), verts.Length, BufferUsage.None);
            vertexBuffer.SetData(verts);

            // Initialize the BasicEffect
            effect = new BasicEffect(GraphicsDevice);

            // Load texture
            texture = Content.Load<Texture2D>(@"Textures\trees");
           
        }
示例#10
0
        private void SetUpVertices()
        {
            // Fill in texture coordinates to display full texture
            // on quad
            Vector2 textureUpperLeft = new Vector2(0.0f, 0.0f);
            Vector2 textureUpperRight = new Vector2(1.0f, 0.0f);
            Vector2 textureLowerLeft = new Vector2(0.0f, 1.0f);
            Vector2 textureLowerRight = new Vector2(1.0f, 1.0f);

            // Create 4 vertices
            vertices[0] = new VertexPositionTexture(LowerLeft, textureLowerLeft);
            vertices[1] = new VertexPositionTexture(UpperLeft, textureUpperLeft);
            vertices[2] = new VertexPositionTexture(LowerRight, textureLowerRight);
            vertices[3] = new VertexPositionTexture(UpperRight, textureUpperRight);

            // Set the index buffer for each vertex, using
            // clockwise winding
            indices[0] = 0;
            indices[1] = 1;
            indices[2] = 2;
            indices[3] = 2;
            indices[4] = 1;
            indices[5] = 3;

            // Initialize the VertexBuffer, and insert the data
            this.vertexBuffer = new VertexBuffer(Device, typeof(VertexPositionTexture), vertices.Length, BufferUsage.WriteOnly);
            this.vertexBuffer.SetData(vertices);

            // Initialize the IndexBuffer, and insert the data
            indexBuffer = new IndexBuffer(Device, typeof(short), indices.Length, BufferUsage.WriteOnly);
            indexBuffer.SetData(indices);
        }
示例#11
0
        public void draw()
        {
            if (show)
            {
                //Lägg spriten på en triangel
                VertexPositionTexture[] vertices = new VertexPositionTexture[6];
                //vertices[0] = new VertexPositionTexture(position, new Vector2(1, 1));
                vertices[0] = new VertexPositionTexture(position, new Vector2(1, 1));
                vertices[1] = new VertexPositionTexture(position, new Vector2(0, 0));
                vertices[2] = new VertexPositionTexture(position, new Vector2(1, 0));

                vertices[3] = new VertexPositionTexture(position, new Vector2(1, 1));
                vertices[4] = new VertexPositionTexture(position, new Vector2(0, 1));
                vertices[5] = new VertexPositionTexture(position, new Vector2(0, 0));

                Globals.effect.CurrentTechnique = Globals.effect.Techniques["PointSprites"];
                Globals.effect.Parameters["xWorld"].SetValue(Matrix.Identity);
                Globals.effect.Parameters["xProjection"].SetValue(Globals.player.camera.projection);
                Globals.effect.Parameters["xView"].SetValue(Globals.player.camera.view);
                Globals.effect.Parameters["xCamPos"].SetValue(Globals.player.camera.position);
                Globals.effect.Parameters["xTexture"].SetValue(sprite[frame]);
                Globals.effect.Parameters["xCamUp"].SetValue(Globals.player.camera.up);
                Globals.effect.Parameters["xPointSpriteSize"].SetValue(100f);

                if (frame >= sprite.Length - 40) Globals.device.BlendState = BlendState.Additive;

                foreach (EffectPass pass in Globals.effect.CurrentTechnique.Passes)
                {
                    pass.Apply();
                    Globals.device.DrawUserPrimitives(PrimitiveType.TriangleList, vertices, 0, 2);
                }

                if (frame >= sprite.Length - 40) Globals.device.BlendState = BlendState.Opaque;
            }
        }
        public void DrawPolygons(Vector2 position, float angle, float scale,
            Texture2D texture, VertexPositionTexture[] vertices, BlendState blendMode)
        {
            effect.World = Matrix.CreateRotationZ(angle) *
                Matrix.CreateScale(scale) *
                Matrix.CreateTranslation(new Vector3(position, 0));
            effect.Texture = texture;

            GraphicsDevice device = GameEngine.Instance.GraphicsDevice;

            if (blendMode == BlendState.AlphaBlend)
            {
                device.BlendState = BlendState.AlphaBlend;
            }
            else if (blendMode == BlendState.Additive)
            {
                device.BlendState = BlendState.Additive;
            }
            SamplerState s = new SamplerState();
            s.AddressU = TextureAddressMode.Wrap;
            s.AddressV = TextureAddressMode.Wrap;
            device.SamplerStates[0] = s;

            foreach (EffectPass pass in effect.CurrentTechnique.Passes)
            {
                pass.Apply();
                device.DrawUserPrimitives<VertexPositionTexture>(PrimitiveType.TriangleList, vertices, 0, vertices.Length / 3);
                //pass.Apply();
            }
        }
示例#13
0
文件: Tile.cs 项目: Woodje/3DGame
        public Tile(Texture2D texture2D, GraphicsDeviceManager graphicsDeviceManager, Vector3 position, Vector3 dimension)
        {
            texture = texture2D;

            tile = new VertexPositionTexture[14];
            tile[0] = new VertexPositionTexture(new Vector3(position.X, position.Y, position.Z), new Vector2(0, 0));
            tile[1] = new VertexPositionTexture(new Vector3(position.X + dimension.X, position.Y, position.Z), new Vector2(1, 0));
            tile[2] = new VertexPositionTexture(new Vector3(position.X, position.Y + dimension.Y, position.Z), new Vector2(0, 1));
            tile[3] = new VertexPositionTexture(new Vector3(position.X + dimension.X, position.Y + dimension.Y, position.Z), new Vector2(1, 1));
            tile[4] = new VertexPositionTexture(new Vector3(position.X + dimension.X, position.Y + dimension.Y, position.Z + dimension.Z), new Vector2(1, 0));
            tile[5] = new VertexPositionTexture(new Vector3(position.X + dimension.X, position.Y, position.Z), new Vector2(0, 1));
            tile[6] = new VertexPositionTexture(new Vector3(position.X + dimension.X, position.Y, position.Z + dimension.Z), new Vector2(0, 0));
            tile[7] = new VertexPositionTexture(new Vector3(position.X, position.Y, position.Z), new Vector2(1, 1));
            tile[8] = new VertexPositionTexture(new Vector3(position.X, position.Y, position.Z + dimension.Z), new Vector2(1, 0));
            tile[9] = new VertexPositionTexture(new Vector3(position.X, position.Y + dimension.Y, position.Z), new Vector2(0, 1));
            tile[10] = new VertexPositionTexture(new Vector3(position.X, position.Y + dimension.Y, position.Z + dimension.Z), new Vector2(0, 0));
            tile[11] = new VertexPositionTexture(new Vector3(position.X + dimension.X, position.Y + dimension.Y, position.Z + dimension.Z), new Vector2(1, 0));
            tile[12] = new VertexPositionTexture(new Vector3(position.X, position.Y, position.Z + dimension.Z), new Vector2(0, 1));
            tile[13] = new VertexPositionTexture(new Vector3(position.X + dimension.X, position.Y, position.Z + dimension.Z), new Vector2(1, 1));

            // Set vertex data in VertexBuffer
            vertexBuffer = new VertexBuffer(graphicsDeviceManager.GraphicsDevice, typeof(VertexPositionTexture), tile.Length, BufferUsage.None);
            vertexBuffer.SetData(tile);

            // Initialize the BasicEffect
            effect = new BasicEffect(graphicsDeviceManager.GraphicsDevice);
        }
示例#14
0
文件: Billboard.cs 项目: myko/Eternia
        public Billboard(GraphicsDevice graphicsDevice, Effect effect)
        {
            this.graphicsDevice = graphicsDevice;
            this.effect = effect;

            LifeTime = 1f;
            Scale = 1f;
            Alpha = 1f;
            Angle = 0f;
            Diffuse = Color.White;
            Age = 0f;

            PositionFunc = x => Position;
            AlphaFunc = x => Alpha;
            ScaleFunc = x => Scale;
            AngleFunc = x => Angle;
            DiffuseFunc = x => Diffuse;

            vertices[0] = new VertexPositionTexture(new Vector3(-1, 0, 1), new Vector2(0, 0));
            vertices[1] = new VertexPositionTexture(new Vector3(1, 0, 1), new Vector2(1, 0));
            vertices[2] = new VertexPositionTexture(new Vector3(-1, 0, -1), new Vector2(0, 1));
            vertices[3] = new VertexPositionTexture(new Vector3(1, 0, 1), new Vector2(1, 0));
            vertices[4] = new VertexPositionTexture(new Vector3(1, 0, -1), new Vector2(1, 1));
            vertices[5] = new VertexPositionTexture(new Vector3(-1, 0, -1), new Vector2(0, 1));
        }
        public override void Draw(GameTime gameTime)
        {
            VertexPositionTexture[] bulletVertices = new VertexPositionTexture[6];
            int i = 0;
            Vector3 center = Position + (Vector3.Up * 0.75f);

            bulletVertices[i++] = new VertexPositionTexture(center, new Vector2(1, 1));
            bulletVertices[i++] = new VertexPositionTexture(center, new Vector2(0, 0));
            bulletVertices[i++] = new VertexPositionTexture(center, new Vector2(1, 0));

            bulletVertices[i++] = new VertexPositionTexture(center, new Vector2(1, 1));
            bulletVertices[i++] = new VertexPositionTexture(center, new Vector2(0, 1));
            bulletVertices[i++] = new VertexPositionTexture(center, new Vector2(0, 0));

            effects.CurrentTechnique = effects.Techniques["PointSprites"];
            effects.Parameters["xWorld"].SetValue(Matrix.Identity);
            effects.Parameters["xProjection"].SetValue(camera.projectionMatrix);
            effects.Parameters["xView"].SetValue(camera.viewMatrix);
            effects.Parameters["xTexture"].SetValue(Texture);
            effects.Parameters["xCamPos"].SetValue(camera.cameraPos);
            effects.Parameters["xCamUp"].SetValue(Vector3.Up);
            effects.Parameters["xPointSpriteSize"].SetValue(0.5f);

            graphics.GraphicsDevice.BlendState = BlendState.AlphaBlend;

            foreach (EffectPass pass in effects.CurrentTechnique.Passes)
            {
                pass.Apply();
                graphics.GraphicsDevice.DrawUserPrimitives(PrimitiveType.TriangleList, bulletVertices, 0, 2);
            }
            graphics.GraphicsDevice.BlendState = BlendState.Opaque;

            base.Draw(gameTime);
        }
示例#16
0
        /// <summary>
        /// A new 2D target which will spin in place.
        /// </summary>
        public FlatTarget(GraphicsDevice graphicsDevice, Texture2D texture, 
            Vector3 bottomLeft, Vector3 topLeft,
            Vector3 bottomRight, Vector3 topRight, float size, Boolean moving)
        {
            this.graphicsDevice = graphicsDevice;
            this.bottomLeft = bottomLeft;
            this.topLeft = topLeft;
            this.bottomRight = bottomRight;
            this.topRight = topRight;

            this.moving = moving;
            this.movingBack = true;
            this.movingForward = false;

            // Initialize verticies
            verts = new VertexPositionTexture[4];
            verts[0] = new VertexPositionTexture(bottomLeft, new Vector2(0, 1));
            verts[1] = new VertexPositionTexture(topLeft, new Vector2(0, 0));
            verts[2] = new VertexPositionTexture(bottomRight, new Vector2(1, 1));
            verts[3] = new VertexPositionTexture(topRight, new Vector2(1, 0));

            vertexBuffer = new VertexBuffer(this.graphicsDevice, typeof(VertexPositionTexture),
                                            verts.Length, BufferUsage.None);
            vertexBuffer.SetData(verts);

            // Initialize the BasicEffect to draw background left
            effect = new BasicEffect(this.graphicsDevice);
            this.texture = texture;
        }
        public TerrainComponent(HouseRenderState state)
        {
            var textureBase = GameFacade.GameFilePath("gamedata/terrain/newformat/");
            var grass = Texture2D.FromFile(GameFacade.GraphicsDevice, Path.Combine(textureBase, "gr.tga"));
            Texture = grass;

            Effect = new BasicEffect(GameFacade.GraphicsDevice, null);
            Effect.TextureEnabled = true;
            Effect.Texture = Texture;

            Geom = new VertexPositionTexture[4];

            var repeatX = state.Size / 2.5f;
            var repeatY = repeatX;

            var tl = state.GetWorldFromTile(new Vector2(1, 1));
            var tr = state.GetWorldFromTile(new Vector2(state.Size-1, 1));
            var bl = state.GetWorldFromTile(new Vector2(1, state.Size-1));
            var br = state.GetWorldFromTile(new Vector2(state.Size-1, state.Size-1));

            Geom[0] = new VertexPositionTexture(tl, new Vector2(0, 0));
            Geom[1] = new VertexPositionTexture(tr, new Vector2(repeatX, 0));
            Geom[2] = new VertexPositionTexture(br, new Vector2(repeatX, repeatY));
            Geom[3] = new VertexPositionTexture(bl, new Vector2(0, repeatY));
        }
示例#18
0
 public static void CreateUVSphere(int Width, int Height, out VertexPositionTexture[] UVSphere, out int[] IndexBuffer)
 {
     UVSphere = new VertexPositionTexture[Width * Height];
     for (int x = 0; x < Width; x++)
     {
         for (int y = 0; y < Height; y++)
         {
             UVSphere[x + y * Width] = new VertexPositionTexture(
                 new Vector3((float)Math.Cos((double)x / (Width - 1.0) * 2.0 * Math.PI)
                         * (float)Math.Sin((double)y / (Height - 1.0) * Math.PI)
                     , -(float)Math.Cos((double)y / (Height - 1.0) * Math.PI)
                     , (float)(Math.Sin((double)x / (Width - 1.0) * 2.0 * Math.PI))
                         * (float)Math.Sin((double)y / (Height - 1.0) * Math.PI))
                 , new Vector2((float)x / (Width - 1.0f), (float)y / (Height - 1.0f)));
         }
     }
     int counter = 0;
     IndexBuffer = new int[6 * (Width - 1) * (Height - 1)];
     for (int x = 0; x < Width - 1; x++)
     {
         for (int y = 0; y < Height - 1; y++)
         {
             IndexBuffer[counter++] = x + y * Width;
             IndexBuffer[counter++] = x + 1 + y * Width;
             IndexBuffer[counter++] = x + 1 + (y + 1) * Width;
             IndexBuffer[counter++] = x + y * Width;
             IndexBuffer[counter++] = x + 1 + (y + 1) * Width;
             IndexBuffer[counter++] = x + (y + 1) * Width;
         }
     }
 }
        protected override void LoadModel(GraphicFactory factory, out BatchInformation[][] BatchInformations, out TextureInformation[][] TextureInformations)
        {
            VertexPositionTexture[] billboardVertices = new VertexPositionTexture[positions.Count * 6];
            int i = 0;

            foreach (var position in positions)
            {
                billboardVertices[i++] = new VertexPositionTexture(position, new Vector2(0, 0));
                billboardVertices[i++] = new VertexPositionTexture(position, new Vector2(1, 0));
                billboardVertices[i++] = new VertexPositionTexture(position, new Vector2(1, 1));

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


            VertexBuffer vertexBufferS = factory.CreateVertexBuffer(VertexPositionTexture.VertexDeclaration, billboardVertices.Count(), BufferUsage.WriteOnly);
            vertexBufferS.SetData(billboardVertices);
            int noVertices = billboardVertices.Count();
            int noTriangles = noVertices / 3;

            BatchInformations = new BatchInformation[1][];
            BatchInformation[] b = new BatchInformation[1];
            b[0] = new BatchInformation(0, 0, noTriangles, 0, 0, VertexPositionTexture.VertexDeclaration, VertexPositionTexture.VertexDeclaration.VertexStride, BatchType.NORMAL);
            b[0].VertexBuffer = vertexBufferS;
            b[0].IndexBuffer = null;
            BatchInformations[0] = b;

            TextureInformations = new TextureInformation[1][];
            TextureInformations[0] = new TextureInformation[1];
            TextureInformations[0][0] = new TextureInformation(isInternal, factory, diffuseTextureName, null, null, null);
            TextureInformations[0][0].LoadTexture();
        }
            /// <summary>
            /// Create VB screen
            /// </summary>
            public VBScreen()
            {
                VertexPositionTexture[] vertices = new VertexPositionTexture[]
                {
                    new VertexPositionTexture(
                        new Vector3(-1.0f, -1.0f, 0.5f),
                        new Vector2(0, 1)),
                    new VertexPositionTexture(
                        new Vector3(-1.0f, 1.0f, 0.5f),
                        new Vector2(0, 0)),
                    new VertexPositionTexture(
                        new Vector3(1.0f, -1.0f, 0.5f),
                        new Vector2(1, 1)),
                    new VertexPositionTexture(
                        new Vector3(1.0f, 1.0f, 0.5f),
                        new Vector2(1, 0)),
                };

                vbScreen = new VertexBuffer(
                    BaseGame.Device,
                    typeof(VertexPositionTexture),
                    vertices.Length,
                    BufferUsage.WriteOnly);

                vbScreen.SetData(vertices);
            }
示例#21
0
文件: world.cs 项目: er1/c376p1
        //Construct Cube
        public void setCubeVertices(int worldSize)
        {
            cubeSize = new Vector3(390, 390, 390);
            cubeVertices = new VertexPositionTexture[26];

            //Texture Mappting
            Vector2 topLeft = new Vector2(0.0f, 0.0f);  //0
            Vector2 bottomLeft = new Vector2(0.0f, 1.0f); //2
            Vector2 topRight = new Vector2(1.0f, 0.0f); //1
            Vector2 bottomRight = new Vector2(1.0f, 1.0f);//3

            //Cube World points (too lazy to write them, taken from a forum)
            Vector3 topLeftBack = cubePosition + new Vector3(-1.0f, 1.0f, -0.24f) * cubeSize;
            Vector3 bottomLeftBack = cubePosition + new Vector3(-1.0f, -0.1f, -0.24f) * cubeSize;
            Vector3 topRightBack = cubePosition + new Vector3(1.0f, 1.0f, -0.24f) * cubeSize;
            Vector3 bottomRightBack = cubePosition + new Vector3(1.0f, -0.1f, -0.24f) * cubeSize;
            Vector3 topLeftFront = cubePosition + new Vector3(-1.0f, 1.0f, 0.50f) * cubeSize;
            Vector3 topRightFront = cubePosition + new Vector3(1.0f, 1.0f, 0.50f) * cubeSize;
            Vector3 bottomLeftFront = cubePosition + new Vector3(-1.0f, -0.1f, 0.50f) * cubeSize;
            Vector3 bottomRightFront = cubePosition + new Vector3(1.0f, -0.1f, 0.50f) * cubeSize;

            //Back of Cube
            cubeVertices[0] = new VertexPositionTexture(topLeftBack, topLeft);
            cubeVertices[1] = new VertexPositionTexture(topRightBack, topRight);
            cubeVertices[2] = new VertexPositionTexture(bottomLeftBack, bottomLeft);
            cubeVertices[3] = new VertexPositionTexture(bottomRightBack, bottomRight);

            //Right Side of the Cube
            cubeVertices[4] = new VertexPositionTexture(bottomRightBack, bottomLeft);
            cubeVertices[5] = new VertexPositionTexture(topRightBack, topLeft);
            cubeVertices[6] = new VertexPositionTexture(bottomRightFront, bottomRight);
            cubeVertices[7] = new VertexPositionTexture(topRightFront, topRight);

            //Top of the Cube
            cubeVertices[8] = new VertexPositionTexture(topRightFront, topRight);
            cubeVertices[10] = new VertexPositionTexture(topLeftFront, topLeft);
            cubeVertices[9] = new VertexPositionTexture(topRightBack, bottomRight);
            cubeVertices[11] = new VertexPositionTexture(topLeftBack, bottomLeft);

            //Left Side of the Cube
            cubeVertices[12] = new VertexPositionTexture(topLeftBack, topLeft);
            cubeVertices[13] = new VertexPositionTexture(bottomLeftBack, bottomLeft);
            cubeVertices[14] = new VertexPositionTexture(topLeftFront, topRight);
            cubeVertices[15] = new VertexPositionTexture(bottomLeftFront, bottomRight);

            //Bottom of the Cube
            cubeVertices[16] = new VertexPositionTexture(bottomLeftFront, topRight);
            cubeVertices[17] = new VertexPositionTexture(bottomLeftBack, bottomRight);
            cubeVertices[18] = new VertexPositionTexture(bottomRightFront, topLeft);
            cubeVertices[19] = new VertexPositionTexture(bottomRightBack, bottomLeft);

            cubeVertices[20] = new VertexPositionTexture(bottomRightFront, topLeft);
            cubeVertices[21] = new VertexPositionTexture(bottomLeftFront, topLeft);
            //Front of Cube
            cubeVertices[22] = new VertexPositionTexture(bottomLeftFront, bottomLeft);
            cubeVertices[23] = new VertexPositionTexture(bottomRightFront, bottomRight);
            cubeVertices[24] = new VertexPositionTexture(topLeftFront, topLeft);
            cubeVertices[25] = new VertexPositionTexture(topRightFront, topRight);
        }
        protected override void InitialiserSommets()
        {
            Vector2 a = new Vector2(0, 0);
            Vector2 b = new Vector2(1, 0);
            Vector2 c = new Vector2(0, 1);
            Vector2 d = new Vector2(1, 1);

            VertexPositionTexture A = new VertexPositionTexture(Origine, c);
            VertexPositionTexture B = new VertexPositionTexture(new Vector3(Origine.X + Delta.X, Origine.Y, Origine.Z), d);
            VertexPositionTexture C = new VertexPositionTexture(new Vector3(Origine.X + Delta.X, Origine.Y, Origine.Z + Delta.Z), c);
            VertexPositionTexture D = new VertexPositionTexture(new Vector3(Origine.X, Origine.Y, Origine.Z + Delta.Z), d);

            VertexPositionTexture E = new VertexPositionTexture(new Vector3(Origine.X, Origine.Y + Delta.Y, Origine.Z), a);
            VertexPositionTexture F = new VertexPositionTexture(new Vector3(Origine.X + Delta.X, Origine.Y + Delta.Y, Origine.Z), b);
            VertexPositionTexture G = new VertexPositionTexture(new Vector3(Origine.X + Delta.X, Origine.Y + Delta.Y, Origine.Z + Delta.Z), a);
            VertexPositionTexture H = new VertexPositionTexture(new Vector3(Origine.X, Origine.Y + Delta.Y, Origine.Z + Delta.Z), b);
            
            #region TRIANGLELIST 1
            Sommets1[0] = F;
            Sommets1[1] = G;
            Sommets1[2] = B;

            Sommets1[3] = B;
            Sommets1[4] = G;
            Sommets1[5] = C;

            Sommets1[6] = C;
            Sommets1[7] = G;
            Sommets1[8] = D;

            Sommets1[9] = D;
            Sommets1[10] = G;
            Sommets1[11] = H;

            Sommets1[12] = H;
            Sommets1[13] = E;
            Sommets1[14] = D;

            Sommets1[15] = D;
            Sommets1[16] = E;
            Sommets1[17] = A;

            Sommets1[18] = A;
            Sommets1[19] = E;
            Sommets1[20] = B;

            Sommets1[21] = B;
            Sommets1[22] = E;
            Sommets1[23] = F;
            #endregion
            Sommets2[0] = E;
            Sommets2[1] = H;
            Sommets2[2] = G;
            Sommets2[3] = G;
            Sommets2[4] = F;
            Sommets2[5] = E;
        }
示例#23
0
文件: Element.cs 项目: Arasho/GR
 public Element(VertexPositionTexture[] x, Texture2D texture)
 {
     verts = x;
     Texture = texture;
     leftEdge = -10;
     rightEdge = -10;
     upEdge = -10;
     bottomEdge = -10;
 }
示例#24
0
        public QuadRenderer()
        {
            _vertexBuffer = new VertexPositionTexture[4];
            _vertexBuffer[0] = new VertexPositionTexture(new Vector3(-1, 1, 0), new Vector2(0.0f, 0.0f));
            _vertexBuffer[1] = new VertexPositionTexture(new Vector3(1, 1, 0), new Vector2(1.0f, 0.0f));
            _vertexBuffer[2] = new VertexPositionTexture(new Vector3(-1, -1, 0), new Vector2(0.0f, 1.0f));
            _vertexBuffer[3] = new VertexPositionTexture(new Vector3(1, -1, 0), new Vector2(1.0f, 1.0f));

            _indexBuffer = new short[] { 0, 3, 2, 0, 1, 3 };
        }
示例#25
0
文件: Track.cs 项目: Biskus/rush
        // Setter opp geometri og teksturkoordinater.
        private void initVertices()
        {
            vertices = new VertexPositionTexture[4];
            vertices[0] = new VertexPositionTexture(new Vector3(-100, 0, -100), new Vector2(0.0f, 50.0f));
            vertices[1] = new VertexPositionTexture(new Vector3(-100, 0, 100), new Vector2(0.0f, 0.0f));
            vertices[2] = new VertexPositionTexture(new Vector3(100, 0, 100), new Vector2(50.0f, 0.0f));
            vertices[3] = new VertexPositionTexture(new Vector3(100, 0, -100), new Vector2(50.0f, 50.0f));

            // Trianglestrip for to trekanter
            indices = new int[] { 0, 3, 1, 2 };
        }
示例#26
0
        public void Build(RTSRenderer renderer, string image, Vector3 radii, Vector3 heights)
        {
            fx = renderer.CreateEffect();

            fx.FogEnabled = false;
            fx.VertexColorEnabled = false;
            fx.LightingEnabled = false;
            fx.TextureEnabled = true;

            if(image == null || !File.Exists(image)) {
                Texture = renderer.CreateTexture2D(3, 3, SurfaceFormat.Color, false);
                Texture.SetData(new Color[] {
                    Color.White, Color.Transparent, Color.White,
                    Color.Transparent, Color.Transparent, Color.Transparent,
                    Color.White, Color.Transparent, Color.White
                });
            }
            else {
                Texture = renderer.LoadTexture2D(image);
            }
            fx.Texture = Texture;

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

                new VertexPositionTexture(new Vector3(-1, 1f, -1), new Vector2(0.5f, 0)),
                new VertexPositionTexture(new Vector3(1, 1f, -1), new Vector2(1f, 0)),
                new VertexPositionTexture(new Vector3(-1, 1f, 1), new Vector2(0.5f, 0.5f)),
                new VertexPositionTexture(new Vector3(1, 1f, 1), new Vector2(1f, 0.5f)),

                new VertexPositionTexture(new Vector3(-1, 1f, -1), new Vector2(0, 0.5f)),
                new VertexPositionTexture(new Vector3(1, 1f, -1), new Vector2(0.5f, 0.5f)),
                new VertexPositionTexture(new Vector3(-1, 1f, 1), new Vector2(0, 1f)),
                new VertexPositionTexture(new Vector3(1, 1f, 1), new Vector2(0.5f, 1f))
            };
            int[] inds = new int[] {
                0, 1, 2, 2, 1, 3,
                4, 5, 6, 6, 5, 7,
                8, 9, 10, 10, 9, 11
            };
            for(int i = 0; i < 4; i++) {
                verts[i].Position *= new Vector3(radii.X, heights.X, radii.X);
                verts[i + 4].Position *= new Vector3(radii.Y, heights.Y, radii.Y);
                verts[i + 8].Position *= new Vector3(radii.Z, heights.Z, radii.Z);
            }

            vb = renderer.CreateVertexBuffer(VertexPositionTexture.VertexDeclaration, verts.Length, BufferUsage.WriteOnly);
            vb.SetData(verts);
            ib = renderer.CreateIndexBuffer(IndexElementSize.ThirtyTwoBits, inds.Length, BufferUsage.WriteOnly);
            ib.SetData(inds);
        }
示例#27
0
        public QuadRenderer()
        {
            _vertices = new VertexPositionTexture[4];

            _vertices[0] = new VertexPositionTexture(new Vector3(-1.0f, 1.0f, 1.0f), new Vector2(0.0f, 0.0f));
            _vertices[1] = new VertexPositionTexture(new Vector3(1.0f, 1.0f, 1.0f), new Vector2(1.0f, 0.0f));
            _vertices[2] = new VertexPositionTexture(new Vector3(-1.0f, -1.0f, 1.0f), new Vector2(0.0f, 1.0f));
            _vertices[3] = new VertexPositionTexture(new Vector3(1.0f, -1.0f, 1.0f), new Vector2(1.0f, 1.0f));

            _indices = new short[] { 0, 3, 2, 0, 1, 3 };
        }
 protected override void InitialiserSommets()
 {
    int NoSommet = -1;
    for (int j = 0; j < NbRangées; ++j)
    {
       for (int i = 0; i <= NbColonnes; ++i)
       {
          Sommets[++NoSommet] = new VertexPositionTexture(PtsSommets[i, j], PtsTexture[i, j]);
          Sommets[++NoSommet] = new VertexPositionTexture(PtsSommets[i, j + 1], PtsTexture[i, j + 1]);
       }
    }
 }
示例#29
0
        public QuadMesh(GraphicsDevice graphicsDevice, float size)
        {
            var half = size * 0.5f;

            VertexBuffer = new VertexBuffer(graphicsDevice, typeof(VertexPositionTexture), 4, BufferUsage.WriteOnly);
            var vertices = new VertexPositionTexture[4];
            vertices[0] = new VertexPositionTexture(new Vector3(0, size, 0.0f), new Vector2(0, 0));
            vertices[1] = new VertexPositionTexture(new Vector3(size, size, 0.0f), new Vector2(1, 0));
            vertices[2] = new VertexPositionTexture(new Vector3(0, 0, 0.0f), new Vector2(0, 1));
            vertices[3] = new VertexPositionTexture(new Vector3(size, 0, 0.0f), new Vector2(1, 1));
            VertexBuffer.SetData(vertices);
        }
 protected override void InitialiserSommets() // Est appelée par base.Initialize()
 {
     int NoSommet = -1;
     for (int j = 0; j < 1; ++j)
     {
         for (int i = 0; i < 2; ++i)
         {
             Sommets[++NoSommet] = new VertexPositionTexture(PtsSommets[i, j], PtsTexture[i, j]);
             Sommets[++NoSommet] = new VertexPositionTexture(PtsSommets[i, j + 1], PtsTexture[i, j + 1]);
         }
     }
 }