[PR]
×
[PR]上記の広告は3ヶ月以上新規記事投稿のないブログに表示されています。新しい記事を書く事で広告が消えます。
プログラミング、3DCGとその他いろいろについて
[PR]上記の広告は3ヶ月以上新規記事投稿のないブログに表示されています。新しい記事を書く事で広告が消えます。
using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; class Triangle { VertexPositionColor[] vertices = new VertexPositionColor[3]; public Triangle(Vector3 p1, Vector3 p2, Vector3 p3) { vertices[0].Position = p1; vertices[1].Position = p2; vertices[2].Position = p3; } public Color Color { set { for (int i = 0; i < vertices.Length; i++) { vertices[i].Color = value; } } } public void Draw(GraphicsDevice graphicsDevice, BasicEffect effect) { graphicsDevice.VertexDeclaration = new VertexDeclaration( graphicsDevice, VertexPositionColor.VertexElements); effect.VertexColorEnabled = true; effect.Begin(); foreach (EffectPass pass in effect.CurrentTechnique.Passes) { pass.Begin(); graphicsDevice.DrawUserPrimitives<VertexPositionColor>( PrimitiveType.TriangleList, vertices, 0, 1 ); pass.End(); } effect.End(); } } class MyGame : Game { GraphicsDeviceManager graphics; BasicEffect basicEffect; Triangle redTriangle = new Triangle( new Vector3(1, 0.5f, 0), new Vector3(0, -1, 0), new Vector3(-1, 0.5f, 0) ); Triangle blueTriangle = new Triangle( new Vector3(0, 1, -1), new Vector3(1, -0.5f, -1), new Vector3(-1, -0.5f, -1) ); byte alpha; public MyGame() { graphics = new GraphicsDeviceManager(this); } protected override void LoadGraphicsContent(bool loadAllContent) { if (loadAllContent) { basicEffect = new BasicEffect(graphics.GraphicsDevice, null); basicEffect.View = Matrix.CreateLookAt( new Vector3(0, 0, 3), new Vector3(0, 0, 0), new Vector3(0, 1, 0) ); basicEffect.Projection = Matrix.CreatePerspectiveFieldOfView( MathHelper.ToRadians(45), Window.ClientBounds.Width / (float)Window.ClientBounds.Height, 1, 100 ); } } protected override void Update(GameTime gameTime) { alpha++; Window.Title = "Alpha: " + alpha; } protected override void Draw(GameTime gameTime) { graphics.GraphicsDevice.Clear(Color.CornflowerBlue); graphics.GraphicsDevice.RenderState.AlphaBlendEnable = true; graphics.GraphicsDevice.RenderState.DestinationBlend = Blend.InverseSourceAlpha; graphics.GraphicsDevice.RenderState.SourceBlend = Blend.SourceAlpha; graphics.GraphicsDevice.RenderState.AlphaTestEnable = true; graphics.GraphicsDevice.RenderState.AlphaFunction = CompareFunction.Greater; graphics.GraphicsDevice.RenderState.ReferenceAlpha = 30; redTriangle.Color = new Color(255, 0, 0, alpha); redTriangle.Draw(graphics.GraphicsDevice, basicEffect); graphics.GraphicsDevice.RenderState.AlphaBlendEnable = false; blueTriangle.Color = Color.Blue; blueTriangle.Draw(graphics.GraphicsDevice, basicEffect); } }アルファ:19