Category Archives: XNA

MSDN XNA4 Sounds

Creating and Playing Sounds
http://msdn.microsoft.com/en-us/library/bb195038(v=xnagamestudio.40).aspx

Playing a Sound (using SoundEffect)
http://msdn.microsoft.com/en-us/library/bb195053(v=xnagamestudio.40).aspx

Looping a Sound
http://msdn.microsoft.com/en-us/library/dd940203(v=xnagamestudio.40).aspx

Adjusting Pitch and Volume of a Sound
http://msdn.microsoft.com/en-us/library/dd940201(v=xnagamestudio.40).aspx

Playing a Song (using MediaPlayer)
http://msdn.microsoft.com/en-us/library/dd231914(v=xnagamestudio.40).aspx

Using XACT
http://msdn.microsoft.com/en-us/library/ff827590(v=xnagamestudio.40).aspx

XNA4Model (updated)

XNA4Model (updated)
– ModelNode (with ToonShading & BoundingSphere)
– GameComponent & GameService (InputHandler & FpsCounter)
– Event & EventHandler
8636798633.zip
XNA4ModelListPicking (updated)
– Mouse Left Button Pressed to Pick Object3684863626.zip
XNA4SkinnedModel (updated)
-animation clip name
6840418209.zip




  // draw text
        InputHandler input;
        bool drawFPS = false;
        SpriteFont font;

       public FpsCounter(Game game)
            : base(game)
        {
            Enabled = true;
            this.game = game;
            input = (InputHandler)game.Services.GetService(typeof(InputHandler));
        }


        public override void Update(GameTime gameTime)
        {
            base.Update(gameTime);
            if (input.IsKeyPressed(Keys.F))
                drawFPS = !drawFPS;


// 중간생략..
        }

        public sealed override void Draw(GameTime gameTime)
        {
            Game.Window.Title = “FPS: ” + fps.ToString();
            if (drawFPS)
            {
                // draw the text for fpsCounter
                spriteBatch.Begin();
                spriteBatch.DrawString(font, fps.ToString(), Vector2.One, Color.White);
                spriteBatch.End();
            }
        }



 


// GAME1.cs
        protected override void Initialize()
        {
            inputs = new InputHandler(this);
            Components.Add(inputs);
            Services.AddService(typeof(InputHandler), inputs);
// 중간생략..
        }

XNA4 DrawIndexedPrimitives vs DrawUserIndexedPrimitives

GraphicsDevice.DrawIndexedPrimitives
– 그래픽카드에 vertex와 index 정보를 초기화하고, 그것을 호출하여 Draw하는 방식

http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.graphics.graphicsdevice.drawindexedprimitives.aspx



void InitializePrimitive()
{
// 중간생략…
            // Initialize our Vertex Declaration
            vertexDeclaration = new VertexDeclaration(new VertexElement[]
                {
                    new VertexElement(0, VertexElementFormat.Vector3, VertexElementUsage.Position, 0),
                    new VertexElement(12, VertexElementFormat.Vector3, VertexElementUsage.Normal, 0),
                    new VertexElement(24, VertexElementFormat.Vector2, VertexElementUsage.TextureCoordinate, 0)
                }
            );


            // Initialize the vertex buffer, allocating memory for each vertex.
            vertexBuffer = new VertexBuffer(graphics.GraphicsDevice,
                vertexDeclaration, vertices.Count, BufferUsage.None);


            // Set the vertex buffer data to the array of vertices.
            vertexBuffer.SetData(vertices.ToArray());


            // Create an index buffer, and copy our index data into it.
            indexBuffer = new IndexBuffer(graphics.GraphicsDevice, typeof(ushort),
                                          indices.Count, BufferUsage.None);
            indexBuffer.SetData(indices.ToArray());
}

void DrawPrimitive()
{
// 중간생략…
            // Set our vertex declaration, vertex buffer, and index buffer.
            graphics.GraphicsDevice.SetVertexBuffer(vertexBuffer);
            graphics.GraphicsDevice.Indices = indexBuffer;        


            foreach (EffectPass pass in basicEffect.CurrentTechnique.Passes)
            {
                pass.Apply();
                int primitiveCount = indices.Count / 3;
                graphics.GraphicsDevice.DrawIndexedPrimitives(
                    PrimitiveType.TriangleList, 0, 0, vertices.Count, 0, primitiveCount);

            }
}




GraphicsDevice.DrawUserIndexedPrimitives
– 매 프레임마다 GPU로 vertex와 index 정보를 보내어 Draw 하는 방식
– vertex와 index 정보가 계속해서 바뀌는 경우에 사용 (그러나, DynamicVertexBuffer가 이것보다 좀 더 빠르다고 함)

http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.graphics.graphicsdevice.drawuserindexedprimitives.aspx


void DrawPrimitive()
{
// 중간생략…
            foreach (EffectPass pass in basicEffect.CurrentTechnique.Passes)
            {
                pass.Apply();
                int primitiveCount = indices.Count / 3;
                graphics.GraphicsDevice.DrawUserIndexedPrimitives(
                    PrimitiveType.TriangleList, vertices.ToArray(), 0, vertices.Count,
                    indices.ToArray(), 0, primitiveCount);

            }
}