Esempio n. 1
0
            public void Initialize()
            {
                vertexDeclaration = new VertexDeclaration(new VertexElement[]
                    {
                        new VertexElement(0, VertexElementFormat.Vector3, VertexElementUsage.Position, 0),
                        new VertexElement(12, VertexElementFormat.Color, VertexElementUsage.Color, 0)
                    }
                );
                basicEffect = new BasicEffect(Game.Game.Graphics.GraphicsDevice);
                basicEffect.VertexColorEnabled = true;
                world = Matrix.CreateTranslation(0, 0, 0);

                basicEffect.World = world;
                view = Matrix.CreateLookAt(
                    new Vector3(0.0f, 0.0f, 1.0f),
                    Vector3.Zero,
                    Vector3.Up
                    );
                basicEffect.View = view;

                projection = Matrix.CreateOrthographicOffCenter(
                    0,
                    (float)(Game.Game.Graphics.GraphicsDevice.Viewport.Width - 1),
                    0,
                    (float)(Game.Game.Graphics.GraphicsDevice.Viewport.Height - 1),
                    1.0f, 1000.0f);
                basicEffect.Projection = projection;
            }
Esempio n. 2
0
		public PrimitiveBatch(GraphicsDevice graphicsDevice, int bufferSize = DefaultBufferSize)
		{
			if (graphicsDevice == null)
				throw new ArgumentNullException("graphicsDevice");
			
			_device = graphicsDevice;
			
			_triangleVertices = new VertexPositionColor[bufferSize - bufferSize % 3];
			_lineVertices = new VertexPositionColor[bufferSize - bufferSize % 2];
			
			// set up a new basic effect, and enable vertex colors.
			_basicEffect = new BasicEffect(graphicsDevice);
			_basicEffect.VertexColorEnabled = true;
		}
Esempio n. 3
0
        /// <summary>
        /// Draw this instance of the BasicModel mesh
        /// </summary>
        /// <param name="context">Rendering context to use for the draw calls</param>
        /// <param name="effect">BasicEffect to use for the draw call</param>
        /// <param name="viewProj">ViewProj combined matrix</param>
        public void Draw(DeviceContext context, BasicEffect effect, Matrix viewProj)
        {
            var world = World;
            var worldInverseTranspose = MathF.InverseTranspose(world);
            var worldViewProj = world * viewProj;

            effect.SetWorld(World);
            effect.SetWorldInvTranspose(worldInverseTranspose);
            effect.SetWorldViewProj(worldViewProj);
            effect.SetTextureTransform(Matrix.Identity);

            for (int i = 0; i < Model.SubsetCount; ++i)
            {
                effect.SetMaterial(Model.Materials[i]);
                // TODO KAM: Remove this shim
                if (Model.DiffuseMapSRV.Count > 0)
                {
                    effect.SetDiffuseMap(Model.DiffuseMapSRV[i]);
                }

                effect.ColorTech.GetPassByIndex(0).Apply(context);
                Model.ModelMesh.Draw(context, i);
            }
        }
Esempio n. 4
0
        public SceneControl(ScreenComponent manager, string style = "")
            : base(manager, style)
        {
            player = manager.Player;
            camera = manager.Camera;
            assets = manager.Game.Assets;

            Manager = manager;

            simpleShader = manager.Game.Content.Load<Effect>("simple");
            sunTexture = assets.LoadTexture(typeof(ScreenComponent), "sun");

            //List<Bitmap> bitmaps = new List<Bitmap>();
            var definitions = DefinitionManager.Instance.GetBlockDefinitions();
            int textureCount = 0;
            foreach (var definition in definitions)
            {
                textureCount += definition.Textures.Length;
            }
            int bitmapSize = 128;
            blockTextures = new Texture2DArray(manager.GraphicsDevice, 1, bitmapSize, bitmapSize, textureCount);
            int layer = 0;
            foreach (var definition in definitions)
            {
                foreach (var bitmap in definition.Textures)
                {
                    System.Drawing.Bitmap texture = manager.Game.Assets.LoadBitmap(definition.GetType(), bitmap);

                    var scaled = texture;//new Bitmap(bitmap, new System.Drawing.Size(bitmapSize, bitmapSize));
                    int[] data = new int[scaled.Width * scaled.Height];
                    var bitmapData = scaled.LockBits(new System.Drawing.Rectangle(0, 0, scaled.Width, scaled.Height), ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
                    System.Runtime.InteropServices.Marshal.Copy(bitmapData.Scan0, data, 0, data.Length);
                    blockTextures.SetData(data, layer);
                    scaled.UnlockBits(bitmapData);
                    layer++;
                }
            }

            /*int size = (int)Math.Ceiling(Math.Sqrt(bitmaps.Count));
            Bitmap blocks = new Bitmap(size * TEXTURESIZE, size * TEXTURESIZE);
            using (Graphics g = Graphics.FromImage(blocks))
            {
                int counter = 0;
                foreach (var bitmap in bitmaps)
                {
                    int x = counter % size;
                    int y = (int)(counter / size);
                    g.DrawImage(bitmap, new System.Drawing.Rectangle(TEXTURESIZE * x, TEXTURESIZE * y, TEXTURESIZE, TEXTURESIZE));
                    counter++;
                }
            }

            using (MemoryStream stream = new MemoryStream())
            {
                blocks.Save(stream, ImageFormat.Png);
                stream.Seek(0, SeekOrigin.Begin);
                blockTextures = Texture2D.FromStream(manager.GraphicsDevice, stream);
            }*/

            planet = ResourceManager.Instance.GetPlanet(0);

            // TODO: evtl. Cache-Size (Dimensions) VIEWRANGE + 1

            int range = ((int)Math.Pow(2, VIEWRANGE) - 2) / 2;
            localChunkCache = new LocalChunkCache(ResourceManager.Instance.GlobalChunkCache, VIEWRANGE, range);

            chunkRenderer = new ChunkRenderer[
                (int)Math.Pow(2, VIEWRANGE) * (int)Math.Pow(2, VIEWRANGE),
                planet.Size.Z];
            orderedChunkRenderer = new List<ChunkRenderer>(
                (int)Math.Pow(2, VIEWRANGE) * (int)Math.Pow(2, VIEWRANGE) * planet.Size.Z);

            for (int i = 0; i < chunkRenderer.GetLength(0); i++)
            {
                for (int j = 0; j < chunkRenderer.GetLength(1); j++)
                {
                    ChunkRenderer renderer = new ChunkRenderer(simpleShader, manager.GraphicsDevice, camera.Projection, blockTextures);
                    chunkRenderer[i, j] = renderer;
                    orderedChunkRenderer.Add(renderer);
                }
            }

            backgroundThread = new Thread(BackgroundLoop);
            backgroundThread.Priority = ThreadPriority.Lowest;
            backgroundThread.IsBackground = true;
            backgroundThread.Start();

            var selectionVertices = new[]
            {
                new VertexPositionColor(new Vector3(-0.001f, +1.001f, +1.001f), Color.Black * 0.5f),
                new VertexPositionColor(new Vector3(+1.001f, +1.001f, +1.001f), Color.Black * 0.5f),
                new VertexPositionColor(new Vector3(-0.001f, -0.001f, +1.001f), Color.Black * 0.5f),
                new VertexPositionColor(new Vector3(+1.001f, -0.001f, +1.001f), Color.Black * 0.5f),
                new VertexPositionColor(new Vector3(-0.001f, +1.001f, -0.001f), Color.Black * 0.5f),
                new VertexPositionColor(new Vector3(+1.001f, +1.001f, -0.001f), Color.Black * 0.5f),
                new VertexPositionColor(new Vector3(-0.001f, -0.001f, -0.001f), Color.Black * 0.5f),
                new VertexPositionColor(new Vector3(+1.001f, -0.001f, -0.001f), Color.Black * 0.5f),
            };

            var billboardVertices = new[]
            {
                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, 0)),
                new VertexPositionTexture(new Vector3(0.5f, -0.5f, 0), new Vector2(1, 1)),
                new VertexPositionTexture(new Vector3(-0.5f, -0.5f, 0), new Vector2(0, 1)),
            };

            var selectionIndices = new short[]
            {
                0, 1, 0, 2, 1, 3, 2, 3,
                4, 5, 4, 6, 5, 7, 6, 7,
                0, 4, 1, 5, 2, 6, 3, 7
            };

            selectionLines = new VertexBuffer(manager.GraphicsDevice, VertexPositionColor.VertexDeclaration, selectionVertices.Length);
            selectionLines.SetData(selectionVertices);

            selectionIndexBuffer = new IndexBuffer(manager.GraphicsDevice, DrawElementsType.UnsignedShort, selectionIndices.Length);
            selectionIndexBuffer.SetData(selectionIndices);

            billboardVertexbuffer = new VertexBuffer(manager.GraphicsDevice, VertexPositionTexture.VertexDeclaration, billboardVertices.Length);
            billboardVertexbuffer.SetData(billboardVertices);

            sunEffect = new BasicEffect(manager.GraphicsDevice);
            sunEffect.TextureEnabled = true;

            selectionEffect = new BasicEffect(manager.GraphicsDevice);
            selectionEffect.VertexColorEnabled = true;

            MiniMapTexture = new RenderTarget2D(manager.GraphicsDevice, 128, 128, PixelInternalFormat.Rgb8); // , false, SurfaceFormat.Color, DepthFormat.Depth24Stencil8, 0, RenderTargetUsage.PreserveContents);
            miniMapProjectionMatrix = Matrix.CreateOrthographic(128, 128, 1, 10000);
        }
Esempio n. 5
0
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            // TODO: Add your initialization logic here
            this.Window.AllowUserResizing  = true;
            this.Window.ClientSizeChanged += new EventHandler <EventArgs>(Window_ClientSizeChanged);

            void Window_ClientSizeChanged(object sender, EventArgs e)
            {
                graphics.PreferredBackBufferWidth  = Window.ClientBounds.Width;
                graphics.PreferredBackBufferHeight = Window.ClientBounds.Height;
                graphics.ApplyChanges();
            }

            originalcubepos = new Vector3(0, 0, -5);
            floor           = new Model3D(new Vector3(0, -1, 0), 0, 256, 0, 192);
            cube            = new Player(originalcubepos, 1, 2, 2, 2);
            cube.initialize(GraphicsDevice);
            cube.health  = 4;
            level        = 0;
            levelseconds = 0;
            leveltimer   = 0;
            levelenemies = new List <List <Enemy> >();
            List <Enemy> e0 = new List <Enemy>();

            e0.Add(new Enemy(new Vector3(15, 0, 30), 2, 2, 2, 2));
            e0.Add(new Enemy(new Vector3(-15, 0, 30), 2, 2, 2, 2));
            levelenemies.Add(e0);
            List <Enemy> e1 = new List <Enemy>();

            e1.Add(new Enemy(new Vector3(40, 0, 40), 2, 2, 2, 2));
            e1.Add(new Enemy(new Vector3(-40, 0, 40), 2, 2, 2, 2));
            e1.Add(new Enemy(new Vector3(-40, 0, -40), 2, 2, 2, 2));
            e1.Add(new Enemy(new Vector3(40, 0, -40), 2, 2, 2, 2));
            levelenemies.Add(e1);
            List <Enemy> e2 = new List <Enemy>();;
            float        x1 = (float)((enemyrange + 5) * Math.Sin(2 * Math.PI / 5));
            float        x2 = (float)((enemyrange + 5) * Math.Sin(4 * Math.PI / 5));
            float        z1 = (float)((enemyrange + 5) * Math.Cos(2 * Math.PI / 5));
            float        z2 = (float)((enemyrange + 5) * Math.Cos(Math.PI / 5));

            e2.Add(new Enemy(new Vector3(0, 0, enemyrange + 5), 2, 2, 2, 2));
            e2.Add(new Enemy(new Vector3(x1, 0, z1), 2, 2, 2, 2));
            e2.Add(new Enemy(new Vector3(-x1, 0, z1), 2, 2, 2, 2));
            e2.Add(new Enemy(new Vector3(x2, 0, -z2), 2, 2, 2, 2));
            e2.Add(new Enemy(new Vector3(-x2, 0, -z2), 2, 2, 2, 2));
            levelenemies.Add(e2);

            //m.initialize(GraphicsDevice);
            for (int i = 0; i < levelenemies.Count; i++)
            {
                List <Enemy> e = levelenemies.ElementAt <List <Enemy> >(i);
                for (int j = 0; j < e.Count; j++)
                {
                    Enemy enemy = e.ElementAt <Enemy>(j);
                    enemy.initialize(GraphicsDevice);
                }
            }
            floor.initialize(GraphicsDevice);
            state       = 0;
            basic       = new BasicEffect(GraphicsDevice);
            basic.Alpha = 1.0f;
            //basic.TextureEnabled = true;
            basic.VertexColorEnabled = true;
            basic.LightingEnabled    = false;
            bill = new BasicEffect(GraphicsDevice)
            {
                TextureEnabled     = true,
                VertexColorEnabled = true,
            };
            walls = new List <Model3D>();
            for (int i = 0; i < 50; i++)
            {
                walls.Add(new Model3D(new Vector3((2 * i) - 50, 0, 50), 0, 2, 2, 2));
                walls.Add(new Model3D(new Vector3((2 * i) - 50, 0, -50), 0, 2, 2, 2));
                walls.Add(new Model3D(new Vector3(-50, 0, (2 * i) - 50), 0, 2, 2, 2));
                walls.Add(new Model3D(new Vector3(50, 0, (2 * i) - 50), 0, 2, 2, 2));
            }
            h    = new Rectangle[4];
            h[0] = new Rectangle(0, 0, GraphicsDevice.Viewport.Width / 8, GraphicsDevice.Viewport.Height / 8);
            h[1] = new Rectangle(GraphicsDevice.Viewport.Width / 8, 0, GraphicsDevice.Viewport.Width / 8, GraphicsDevice.Viewport.Height / 8);
            h[2] = new Rectangle(GraphicsDevice.Viewport.Width / 4, 0, GraphicsDevice.Viewport.Width / 8, GraphicsDevice.Viewport.Height / 8);
            h[3] = new Rectangle(3 * GraphicsDevice.Viewport.Width / 8, 0, GraphicsDevice.Viewport.Width / 8, GraphicsDevice.Viewport.Height / 8);

            /*for (int i = 0; i < walls.Count; i++)
             * {
             *  Model3D w = walls.ElementAt<Model3D>(i);
             *  walls.Add(new Model3D(w.position+new Vector3(0,2,0),0, 2,2,2));
             *  walls.Add(new Model3D(w.position + new Vector3(0, 4, 0), 0, 2, 2, 2));
             * }*/
            for (int i = 0; i < walls.Count; i++)
            {
                Model3D w = walls.ElementAt <Model3D>(i);
                w.initialize(GraphicsDevice);
            }
            soundeffects = new List <SoundEffect>();
            base.Initialize();

            //Create the triangle

            /*triangleVertices = new VertexPositionColor[3];
             * triangleVertices[0] = new VertexPositionColor(new Vector3(-1, 0, 0), Color.Red);
             * triangleVertices[1] = new VertexPositionColor(new Vector3(-1, 10, 10), Color.Blue);
             * triangleVertices[2] = new VertexPositionColor(new Vector3(-1, 0, 20), Color.Green);
             * // triangleVertices[3] = new VertexPositionColor(new Vector3(100, 0, 0), Color.Goldenrod);
             *
             * vertexBuffer = new VertexBuffer(GraphicsDevice, typeof(VertexPositionColor), 4, BufferUsage.WriteOnly);
             *
             * vertexBuffer.SetData<VertexPositionColor>(triangleVertices);
             */
        }
Esempio n. 6
0
        float frameSize = 1 / 5f; // 1 wäre die Gesamtlänge vom Texture-Atlas



        /// <summary>
        /// Erstellt eine Representation eines stationären Schildes.
        /// </summary>
        public ShieldRepresentation(Shield shield, GraphicsDeviceManager graphics)
        {
            this.texture  = ViewContent.RepresentationContent.ShieldTexture;
            GameItem      = shield;
            this.position = PlaneProjector.Convert2DTo3D(GameItem.Position);
            this.graphics = graphics;
            this.World    = Matrix.CreateWorld(this.position, Vector3.Forward, Vector3.Up);
            this.effect   = new BasicEffect(graphics.GraphicsDevice);
            this.update   = 0;

            // UNDONE: alter Code - TB
            ////Eckpunkte des Rechtecks
            //this.vertices = new VertexPositionColorTexture[4];
            ////6 Punkte für zwei polygone, um ein Rechteck zu zeichnen
            //this.indices = new int[6];

            ////Skalierung
            //float scaleWidth = 0.03f;
            //float scaleHeight = 0.03f;

            ////Eckpunkte in 3D ebene "Aufstellen"
            //Vector3 erect = new Vector3(0, 50, 0);

            ////Viereck aufbauen
            //Vector3 leftBot = PlaneProjector.Convert2DTo3D(new Vector2(-texture.Width / 2.0f, -texture.Height / 2.0f));
            //Vector3 leftTop = PlaneProjector.Convert2DTo3D(new Vector2(-texture.Width / 2.0f, texture.Height / 2.0f));
            //Vector3 rightBot = PlaneProjector.Convert2DTo3D(new Vector2(texture.Width / 2.0f, -texture.Height/2.0f));
            //Vector3 rightTop = PlaneProjector.Convert2DTo3D(new Vector2(texture.Width / 2.0f, texture.Height / 2.0f));

            //Vector2 textureLeftBot = new Vector2(0, 0);
            //Vector2 textureLeftTop = new Vector2(0, 1 / 5f);
            //Vector2 textureRightBot = new Vector2(1 / 5f, 0);
            //Vector2 textureRightTop = new Vector2(1 / 5f, 1 / 5f);

            //Color color2 = new Color(0, 150, 255);
            //Color color1 = new Color(0, 210, 255);
            //vertices[0] = new VertexPositionColorTexture(leftBot, color1, textureLeftBot);
            //vertices[1] = new VertexPositionColorTexture(leftTop, color1, textureLeftTop);
            //vertices[2] = new VertexPositionColorTexture(rightBot, color2, textureRightBot);
            //vertices[3] = new VertexPositionColorTexture(rightTop, color2, textureRightTop);


            ////Positionieren
            //this.World = Matrix.CreateScale(scaleWidth, 0.0f, scaleHeight) * (Matrix.CreateRotationX(MathHelper.ToRadians(45)) * Matrix.CreateTranslation(this.position));

            ////1. Polygon: Punkte 0,1,2 im Urzeigersinn
            //indices[0] = 0;
            //indices[1] = 1;
            //indices[2] = 2;
            ////2. Polygon: Punkte 1,3,2 im Urzeigersinn
            //indices[3] = 1;
            //indices[4] = 3;
            //indices[5] = 2;


            // neuer Code - TB

            //Eckpunkte der Rechtecke
            this.vertices = new VertexPositionColorTexture[12];
            //18 Punkte für 6 polygone, um 3 Rechtecke zu zeichnen
            this.indices = new int[18];

            //Skalierung
            float scaleWidth  = 0.03f;
            float scaleHeight = 0.03f;

            //Größe des Schilds
            shieldSize = 750;
            //Größe des Schildrandes
            borderSize = 75;
            //Relative Größe des Randes zum ganzen Schild
            relBorderSize = (float)borderSize / (float)shieldSize;

            //Vierecke aufbauen
            Vector3[] leftRect   = new Vector3[4];
            Vector3[] middleRect = new Vector3[4];
            Vector3[] rightRect  = new Vector3[4];

            leftRect[0] = PlaneProjector.Convert2DTo3D(new Vector2(-texture.Width / 2.0f, -texture.Height / 2.0f));                //links unten
            leftRect[1] = PlaneProjector.Convert2DTo3D(new Vector2(-texture.Width / 2.0f, texture.Height / 2.0f));                 //links oben
            leftRect[2] = PlaneProjector.Convert2DTo3D(new Vector2(-texture.Width / 2.0f + borderSize, -texture.Height / 2.0f));   //rechts unten
            leftRect[3] = PlaneProjector.Convert2DTo3D(new Vector2(-texture.Width / 2.0f + borderSize, texture.Height / 2.0f));    //rechts oben

            middleRect[0] = PlaneProjector.Convert2DTo3D(new Vector2(-texture.Width / 2.0f + borderSize, -texture.Height / 2.0f)); //links unten
            middleRect[1] = PlaneProjector.Convert2DTo3D(new Vector2(-texture.Width / 2.0f + borderSize, texture.Height / 2.0f));  //links oben
            middleRect[2] = PlaneProjector.Convert2DTo3D(new Vector2(texture.Width / 2.0f - borderSize, -texture.Height / 2.0f));  //rechts unten
            middleRect[3] = PlaneProjector.Convert2DTo3D(new Vector2(texture.Width / 2.0f - borderSize, texture.Height / 2.0f));   //rechts oben

            rightRect[0] = PlaneProjector.Convert2DTo3D(new Vector2(texture.Width / 2.0f - borderSize, -texture.Height / 2.0f));   //links unten
            rightRect[1] = PlaneProjector.Convert2DTo3D(new Vector2(texture.Width / 2.0f - borderSize, texture.Height / 2.0f));    //links oben
            rightRect[2] = PlaneProjector.Convert2DTo3D(new Vector2(texture.Width / 2.0f, -texture.Height / 2.0f));                //rechts unten
            rightRect[3] = PlaneProjector.Convert2DTo3D(new Vector2(texture.Width / 2.0f, texture.Height / 2.0f));                 //rechts oben

            //Texturkoordinaten berechnen
            leftRectTexCoords   = new Vector2[4];
            middleRectTexCoords = new Vector2[4];
            rightRectTexCoords  = new Vector2[4];

            leftRectTexCoords[0] = new Vector2(0, 0);                                  //links unten
            leftRectTexCoords[1] = new Vector2(0, 1 / 5f);                             //links oben
            leftRectTexCoords[2] = new Vector2(relBorderSize / 5f, 0);                 //rechts unten
            leftRectTexCoords[3] = new Vector2(relBorderSize / 5f, 1 / 5f);            //rechts oben

            middleRectTexCoords[0] = new Vector2(relBorderSize / 5f, 0);               //links unten
            middleRectTexCoords[1] = new Vector2(relBorderSize / 5f, 1 / 5f);          //links oben
            middleRectTexCoords[2] = new Vector2((1.0f - relBorderSize) / 5f, 0);      //rechts unten
            middleRectTexCoords[3] = new Vector2((1.0f - relBorderSize) / 5f, 1 / 5f); //rechts oben

            rightRectTexCoords[0] = new Vector2((1.0f - relBorderSize) / 5f, 0);       //links unten
            rightRectTexCoords[1] = new Vector2((1.0f - relBorderSize) / 5f, 1 / 5f);  //links oben
            rightRectTexCoords[2] = new Vector2(1.0f / 5f, 0);                         //rechts unten
            rightRectTexCoords[3] = new Vector2(1.0f / 5f, 1 / 5f);                    //rechts oben


            //Vertices erstellen
            for (int i = 0; i < 4; i++)
            {
                //linkes Viereck
                vertices[i] = new VertexPositionColorTexture(leftRect[i], Color.White, leftRectTexCoords[i]);
                //mittleres Viereck
                vertices[i + 4] = new VertexPositionColorTexture(middleRect[i], new Color(0, 1.0f, 0), middleRectTexCoords[i]);
                //rechtes Viereck
                vertices[i + 8] = new VertexPositionColorTexture(rightRect[i], Color.White, rightRectTexCoords[i]);
            }

            //Indizes zuweisen
            for (int i = 0; i < 3; i++)
            {
                indices[6 * i + 0] = 0 + i * 4;
                indices[6 * i + 1] = 1 + i * 4;
                indices[6 * i + 2] = 2 + i * 4;
                indices[6 * i + 3] = 1 + i * 4;
                indices[6 * i + 4] = 3 + i * 4;
                indices[6 * i + 5] = 2 + i * 4;
            }

            //Positionieren
            this.World = Matrix.CreateScale(scaleWidth, 0.0f, scaleHeight) * (Matrix.CreateRotationX(MathHelper.ToRadians(45)) * Matrix.CreateTranslation(this.position));
        }
Esempio n. 7
0
 public override void Initialize()
 {
     base.Initialize();
     basicEffect = new BasicEffect(this.GraphicsDevice);
     basicEffect.VertexColorEnabled = true;
 }
Esempio n. 8
0
 /// <summary>
 /// Method to draw a line in 3D
 /// </summary>
 /// <param name="color">Color of line</param>
 /// <param name="point1">first point</param>
 /// <param name="point2">second point</param>
 /// <param name="effect">Basic effects object</param>
 /// <param name="gfxDevice">Graphics device</param>
 /// <param name="projection">Projection matrix</param>
 /// <param name="view">view matrix</param>
 /// <param name="world">world matrix</param>
 public static void Draw3DLine(Microsoft.Xna.Framework.Graphics.Color color, Vector3 point1, Vector3 point2, BasicEffect effect, GraphicsDevice gfxDevice, Matrix projection, Matrix view, Matrix world)
 {
     VertexPositionColor[] vertexList = new VertexPositionColor[2];
     vertexList[0] = new VertexPositionColor(point1, color);
     vertexList[1] = new VertexPositionColor(point2, color);
     gfxDevice.VertexDeclaration = new VertexDeclaration(gfxDevice, VertexPositionColor.VertexElements);
     effect.Projection           = projection;
     effect.View  = view;
     effect.World = world;
     effect.Begin();
     foreach (EffectPass pass in effect.CurrentTechnique.Passes)
     {
         pass.Begin();
         gfxDevice.DrawUserPrimitives <VertexPositionColor>(PrimitiveType.LineList, vertexList, 0, 1);
         pass.End();
     }
     effect.End();
 }
        public void UltravioletGraphics_CanRenderAColoredTriangle(ColorEncoding encoding)
        {
            var effect         = default(BasicEffect);
            var vertexBuffer   = default(VertexBuffer);
            var geometryStream = default(GeometryStream);

            var result = GivenAnUltravioletApplication()
                         .WithConfiguration(config =>
            {
                if (encoding == ColorEncoding.Srgb)
                {
                    config.SrgbBuffersEnabled           = true;
                    config.SrgbDefaultForTexture2D      = true;
                    config.SrgbDefaultForRenderBuffer2D = true;
                }
            })
                         .WithContent(content =>
            {
                effect = BasicEffect.Create();

                vertexBuffer = VertexBuffer.Create(VertexPositionColor.VertexDeclaration, 3);
                vertexBuffer.SetData(new[]
                {
                    new VertexPositionColor(new Vector3(0, 1, 0), Color.Red),
                    new VertexPositionColor(new Vector3(1, -1, 0), Color.Lime),
                    new VertexPositionColor(new Vector3(-1, -1, 0), Color.Blue),
                });

                geometryStream = GeometryStream.Create();
                geometryStream.Attach(vertexBuffer);
            })
                         .Render(uv =>
            {
                var gfx         = uv.GetGraphics();
                var window      = uv.GetPlatform().Windows.GetPrimary();
                var viewport    = new Viewport(0, 0, window.Compositor.Width, window.Compositor.Height);
                var aspectRatio = viewport.Width / (float)viewport.Height;

                gfx.SetViewport(viewport);

                effect.World              = Matrix.Identity;
                effect.View               = Matrix.CreateLookAt(new Vector3(0, 0, 5), Vector3.Zero, Vector3.Up);
                effect.Projection         = Matrix.CreatePerspectiveFieldOfView((float)Math.PI / 4f, aspectRatio, 1f, 1000f);
                effect.VertexColorEnabled = true;

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

                    gfx.SetRasterizerState(RasterizerState.CullNone);
                    gfx.SetGeometryStream(geometryStream);
                    gfx.DrawPrimitives(PrimitiveType.TriangleList, 0, 1);
                }
            });

            if (encoding == ColorEncoding.Linear)
            {
                TheResultingImage(result)
                .ShouldMatch(@"Resources/Expected/Graphics/UltravioletGraphics_CanRenderAColoredTriangle.png");
            }
            else
            {
                TheResultingImage(result)
                .ShouldMatch(@"Resources/Expected/Graphics/UltravioletGraphics_CanRenderAColoredTriangle(Srgb).png");
            }
        }
Esempio n. 10
0
 protected override void LoadContent()
 {
     base.LoadContent();
     EffetDeBase = new BasicEffect(GraphicsDevice);
 }
        public static void Initialize(GraphicsDevice graphicsDevice, int sphereResolution)
        {
            // create our effect
            EffectPool mm = new EffectPool();

            effect = new BasicEffect(graphicsDevice, mm);


            effect.LightingEnabled    = false;
            effect.VertexColorEnabled = true;

            // calculate the number of lines to draw for all circles
            lineCount = (sphereResolution + 1) * 3;

            // we need two vertices per line, so we can allocate our vertices
            VertexPositionColor[] verts = new VertexPositionColor[lineCount * 2];

            // compute our step around each circle
            float step = MathHelper.TwoPi / sphereResolution;

            // used to track the index into our vertex array
            int index = 0;

            //create the loop on the XY plane first
            for (float a = 0f; a < MathHelper.TwoPi; a += step)
            {
                verts[index++] = new VertexPositionColor(
                    new Vector3((float)Math.Cos(a), (float)Math.Sin(a), 0f),
                    Color.Blue);
                verts[index++] = new VertexPositionColor(
                    new Vector3((float)Math.Cos(a + step), (float)Math.Sin(a + step), 0f),
                    Color.Blue);
            }

            //next on the XZ plane
            for (float a = 0f; a < MathHelper.TwoPi; a += step)
            {
                verts[index++] = new VertexPositionColor(
                    new Vector3((float)Math.Cos(a), 0f, (float)Math.Sin(a)),
                    Color.Red);
                verts[index++] = new VertexPositionColor(
                    new Vector3((float)Math.Cos(a + step), 0f, (float)Math.Sin(a + step)),
                    Color.Red);
            }

            //finally on the YZ plane
            for (float a = 0f; a < MathHelper.TwoPi; a += step)
            {
                verts[index++] = new VertexPositionColor(
                    new Vector3(0f, (float)Math.Cos(a), (float)Math.Sin(a)),
                    Color.Green);
                verts[index++] = new VertexPositionColor(
                    new Vector3(0f, (float)Math.Cos(a + step), (float)Math.Sin(a + step)),
                    Color.Green);
            }

            // now we create the vertex buffer and put the vertices in it
            vertBuffer = new VertexBuffer(
                graphicsDevice, typeof(VertexPositionColor), verts.Length, BufferUsage.WriteOnly);
            vertBuffer.SetData(verts);
        }
 public AssetCreator(GraphicsDevice device)
 {
     _device = device;
     _effect = new BasicEffect(_device);
 }
Esempio n. 13
0
 /// <summary>
 /// Create the lit material.
 /// </summary>
 /// <param name="fromEffect">Effect to create material from.</param>
 /// <param name="copyEffectProperties">If true, will copy initial properties from effect.</param>
 public LitMaterialAlphaTest(BasicEffect fromEffect, bool copyEffectProperties = true) : base(fromEffect, copyEffectProperties)
 {
 }
        public void OnCreateDevice()
        {
            basicEffect = new BasicEffect(FrameworkCore.Graphics.GraphicsDevice);

            CreateShape();
        }
Esempio n. 15
0
 /// <summary>
 /// Draw fired from the <see cref="GameEngine.Worker.GraphicsWorker"/> logic.
 /// </summary>
 /// <param name="graphicsDevice">The graphic device that will render the model</param>
 /// <param name="effect">The effect that will be used to render the model</param>
 public virtual void Draw(GraphicsDevice graphicsDevice, BasicEffect effect)
 {
 }
Esempio n. 16
0
 public Axis(GraphicsDevice device)
 {
     myEffect = new BasicEffect(device);
 }
Esempio n. 17
0
        public virtual void DrawWireframe(GraphicsDevice Graphics, Matrix View, Matrix Projection)
        {
            try
            {
                VertexPositionColor[] wireFrame = Skin.GetLocalSkinWireframe();
                Body.TransformWireframe(wireFrame);
                if (Effect == null)
                {
                    Effect = new BasicEffect(Graphics);
                    Effect.VertexColorEnabled = true;
                }
                Effect.TextureEnabled  = false;
                Effect.LightingEnabled = false;
                Effect.View            = View;
                Effect.Projection      = Projection;

                foreach (EffectPass pass in Effect.CurrentTechnique.Passes)
                {
                    pass.Apply();
                    Graphics.DrawUserPrimitives <VertexPositionColor>(
                        Microsoft.Xna.Framework.Graphics.PrimitiveType.LineStrip,
                        wireFrame, 0, wireFrame.Length - 1);
                }

                VertexPositionColor[] Velocity = new VertexPositionColor[2];
                Velocity[0] = new VertexPositionColor(Body.Position, Color.Blue);
                Velocity[1] = new VertexPositionColor(Body.Position + Body.Velocity, Color.Red);

                foreach (EffectPass pass in Effect.CurrentTechnique.Passes)
                {
                    pass.Apply();
                    Graphics.DrawUserPrimitives <VertexPositionColor>(
                        Microsoft.Xna.Framework.Graphics.PrimitiveType.LineStrip,
                        Velocity, 0, Velocity.Length - 1);
                }

                foreach (Controller c in controllers)
                {
                    if (c is BoostController)
                    {
                        VertexPositionColor[] Force = new VertexPositionColor[2];
                        BoostController       bc    = c as BoostController;
                        Force[0] = new VertexPositionColor(bc.ForcePosition, Color.Green);
                        Force[1] = new VertexPositionColor(bc.ForcePosition + (bc.Force * bc.forceMag), Color.Yellow);
                        if (!bc.worldForce)
                        {
                            Body.TransformWireframe(Force);
                        }

                        VertexBuffer verts = new VertexBuffer(Graphics, VertexPositionColor.VertexDeclaration, Force.Length, BufferUsage.WriteOnly);
                        verts.SetData(Force);

                        foreach (EffectPass pass in Effect.CurrentTechnique.Passes)
                        {
                            pass.Apply();
                            Graphics.SetVertexBuffer(verts);
                            Graphics.DrawPrimitives(Microsoft.Xna.Framework.Graphics.PrimitiveType.LineStrip, 0, Force.Length - 1);

                            /*Graphics.DrawUserPrimitives<VertexPositionColor>(
                             *  Microsoft.Xna.Framework.Graphics.PrimitiveType.LineStrip,
                             *  Force, 0, Force.Length - 1, LightingVertexFormat.VertexDeclaration);*/
                        }
                    }
                }
            }
            catch (Exception e)
            {
                System.Console.WriteLine(e.StackTrace);
            }
        }
Esempio n. 18
0
 public _3DWorldBatch(WorldState state)
 {
     this.State  = state;
     this.Effect = new BasicEffect(state.Device, null);
 }
Esempio n. 19
0
 public Mirror(List <BoundingBox> boundingBoxes, GraphicsDevice device)
 {
     this.device  = device;
     mirrorEffect = new BasicEffect(this.device);
     SetUpMirror(boundingBoxes);
 }
Esempio n. 20
0
 public override void ApplyEffects(BasicEffect effect)
 {
     effect.DiffuseColor = Color;
 }
Esempio n. 21
0
        protected override void Initialize()
        {
            _disposed = false;
            _graphicsDeviceService = new WpfGraphicsDeviceService(this);
            Components.Add(new FpsComponent(this));
            Components.Add(new TimingComponent(this));
            Components.Add(new DpiScalingTextComponent(this, false, new Vector2(5, 50)));
            Components.Add(new DpiScalingTextComponent(this, true, new Vector2(5, 75)));
            Components.Add(new TextComponent(this, "Leftclick anywhere in the game to change dpi scaling", new Vector2(1, 0), HorizontalAlignment.Right));

            float tilt = MathHelper.ToRadians(0);  // 0 degree angle

            // Use the world matrix to tilt the cube along x and y axes.
            _worldMatrix = Matrix.CreateRotationX(tilt) * Matrix.CreateRotationY(tilt);
            _viewMatrix  = Matrix.CreateLookAt(new Vector3(5, 5, 5), Vector3.Zero, Vector3.Up);


            _basicEffect = new BasicEffect(GraphicsDevice);

            _basicEffect.World = _worldMatrix;
            _basicEffect.View  = _viewMatrix;
            RefreshProjection();

            // primitive color
            _basicEffect.AmbientLightColor = new Vector3(0.1f, 0.1f, 0.1f);
            _basicEffect.DiffuseColor      = new Vector3(1.0f, 1.0f, 1.0f);
            _basicEffect.SpecularColor     = new Vector3(0.25f, 0.25f, 0.25f);
            _basicEffect.SpecularPower     = 5.0f;
            _basicEffect.Alpha             = 1.0f;

            _basicEffect.LightingEnabled = true;
            if (_basicEffect.LightingEnabled)
            {
                _basicEffect.DirectionalLight0.Enabled = true; // enable each light individually
                if (_basicEffect.DirectionalLight0.Enabled)
                {
                    // x direction
                    _basicEffect.DirectionalLight0.DiffuseColor = new Vector3(1, 0, 0); // range is 0 to 1
                    _basicEffect.DirectionalLight0.Direction    = Vector3.Normalize(new Vector3(-1, 0, 0));
                    // points from the light to the origin of the scene
                    _basicEffect.DirectionalLight0.SpecularColor = Vector3.One;
                }

                _basicEffect.DirectionalLight1.Enabled = true;
                if (_basicEffect.DirectionalLight1.Enabled)
                {
                    // y direction
                    _basicEffect.DirectionalLight1.DiffuseColor  = new Vector3(0, 0.75f, 0);
                    _basicEffect.DirectionalLight1.Direction     = Vector3.Normalize(new Vector3(0, -1, 0));
                    _basicEffect.DirectionalLight1.SpecularColor = Vector3.One;
                }

                _basicEffect.DirectionalLight2.Enabled = true;
                if (_basicEffect.DirectionalLight2.Enabled)
                {
                    // z direction
                    _basicEffect.DirectionalLight2.DiffuseColor  = new Vector3(0, 0, 0.5f);
                    _basicEffect.DirectionalLight2.Direction     = Vector3.Normalize(new Vector3(0, 0, -1));
                    _basicEffect.DirectionalLight2.SpecularColor = Vector3.One;
                }
            }

            _vertexDeclaration = new VertexDeclaration(
                new VertexElement(0, VertexElementFormat.Vector3, VertexElementUsage.Position, 0),
                new VertexElement(12, VertexElementFormat.Vector3, VertexElementUsage.Normal, 0),
                new VertexElement(24, VertexElementFormat.Vector2, VertexElementUsage.TextureCoordinate, 0)
                );

            Vector3 topLeftFront     = new Vector3(-1.0f, 1.0f, 1.0f);
            Vector3 bottomLeftFront  = new Vector3(-1.0f, -1.0f, 1.0f);
            Vector3 topRightFront    = new Vector3(1.0f, 1.0f, 1.0f);
            Vector3 bottomRightFront = new Vector3(1.0f, -1.0f, 1.0f);
            Vector3 topLeftBack      = new Vector3(-1.0f, 1.0f, -1.0f);
            Vector3 topRightBack     = new Vector3(1.0f, 1.0f, -1.0f);
            Vector3 bottomLeftBack   = new Vector3(-1.0f, -1.0f, -1.0f);
            Vector3 bottomRightBack  = new Vector3(1.0f, -1.0f, -1.0f);

            Vector2 textureTopLeft     = new Vector2(0.0f, 0.0f);
            Vector2 textureTopRight    = new Vector2(1.0f, 0.0f);
            Vector2 textureBottomLeft  = new Vector2(0.0f, 1.0f);
            Vector2 textureBottomRight = new Vector2(1.0f, 1.0f);

            Vector3 frontNormal  = new Vector3(0.0f, 0.0f, 1.0f);
            Vector3 backNormal   = new Vector3(0.0f, 0.0f, -1.0f);
            Vector3 topNormal    = new Vector3(0.0f, 1.0f, 0.0f);
            Vector3 bottomNormal = new Vector3(0.0f, -1.0f, 0.0f);
            Vector3 leftNormal   = new Vector3(-1.0f, 0.0f, 0.0f);
            Vector3 rightNormal  = new Vector3(1.0f, 0.0f, 0.0f);

            var cubeVertices = new VertexPositionNormalTexture[36];

            // Front face.
            cubeVertices[0] = new VertexPositionNormalTexture(topLeftFront, frontNormal, textureTopLeft);
            cubeVertices[1] = new VertexPositionNormalTexture(bottomLeftFront, frontNormal, textureBottomLeft);
            cubeVertices[2] = new VertexPositionNormalTexture(topRightFront, frontNormal, textureTopRight);
            cubeVertices[3] = new VertexPositionNormalTexture(bottomLeftFront, frontNormal, textureBottomLeft);
            cubeVertices[4] = new VertexPositionNormalTexture(bottomRightFront, frontNormal, textureBottomRight);
            cubeVertices[5] = new VertexPositionNormalTexture(topRightFront, frontNormal, textureTopRight);

            // Back face.
            cubeVertices[6]  = new VertexPositionNormalTexture(topLeftBack, backNormal, textureTopRight);
            cubeVertices[7]  = new VertexPositionNormalTexture(topRightBack, backNormal, textureTopLeft);
            cubeVertices[8]  = new VertexPositionNormalTexture(bottomLeftBack, backNormal, textureBottomRight);
            cubeVertices[9]  = new VertexPositionNormalTexture(bottomLeftBack, backNormal, textureBottomRight);
            cubeVertices[10] = new VertexPositionNormalTexture(topRightBack, backNormal, textureTopLeft);
            cubeVertices[11] = new VertexPositionNormalTexture(bottomRightBack, backNormal, textureBottomLeft);

            // Top face.
            cubeVertices[12] = new VertexPositionNormalTexture(topLeftFront, topNormal, textureBottomLeft);
            cubeVertices[13] = new VertexPositionNormalTexture(topRightBack, topNormal, textureTopRight);
            cubeVertices[14] = new VertexPositionNormalTexture(topLeftBack, topNormal, textureTopLeft);
            cubeVertices[15] = new VertexPositionNormalTexture(topLeftFront, topNormal, textureBottomLeft);
            cubeVertices[16] = new VertexPositionNormalTexture(topRightFront, topNormal, textureBottomRight);
            cubeVertices[17] = new VertexPositionNormalTexture(topRightBack, topNormal, textureTopRight);

            // Bottom face.
            cubeVertices[18] = new VertexPositionNormalTexture(bottomLeftFront, bottomNormal, textureTopLeft);
            cubeVertices[19] = new VertexPositionNormalTexture(bottomLeftBack, bottomNormal, textureBottomLeft);
            cubeVertices[20] = new VertexPositionNormalTexture(bottomRightBack, bottomNormal, textureBottomRight);
            cubeVertices[21] = new VertexPositionNormalTexture(bottomLeftFront, bottomNormal, textureTopLeft);
            cubeVertices[22] = new VertexPositionNormalTexture(bottomRightBack, bottomNormal, textureBottomRight);
            cubeVertices[23] = new VertexPositionNormalTexture(bottomRightFront, bottomNormal, textureTopRight);

            // Left face.
            cubeVertices[24] = new VertexPositionNormalTexture(topLeftFront, leftNormal, textureTopRight);
            cubeVertices[25] = new VertexPositionNormalTexture(bottomLeftBack, leftNormal, textureBottomLeft);
            cubeVertices[26] = new VertexPositionNormalTexture(bottomLeftFront, leftNormal, textureBottomRight);
            cubeVertices[27] = new VertexPositionNormalTexture(topLeftBack, leftNormal, textureTopLeft);
            cubeVertices[28] = new VertexPositionNormalTexture(bottomLeftBack, leftNormal, textureBottomLeft);
            cubeVertices[29] = new VertexPositionNormalTexture(topLeftFront, leftNormal, textureTopRight);

            // Right face.
            cubeVertices[30] = new VertexPositionNormalTexture(topRightFront, rightNormal, textureTopLeft);
            cubeVertices[31] = new VertexPositionNormalTexture(bottomRightFront, rightNormal, textureBottomLeft);
            cubeVertices[32] = new VertexPositionNormalTexture(bottomRightBack, rightNormal, textureBottomRight);
            cubeVertices[33] = new VertexPositionNormalTexture(topRightBack, rightNormal, textureTopRight);
            cubeVertices[34] = new VertexPositionNormalTexture(topRightFront, rightNormal, textureTopLeft);
            cubeVertices[35] = new VertexPositionNormalTexture(bottomRightBack, rightNormal, textureBottomRight);

            _vertexBuffer = new VertexBuffer(GraphicsDevice, _vertexDeclaration, cubeVertices.Length, BufferUsage.None);
            _vertexBuffer.SetData(cubeVertices);

            _keyboard = new WpfKeyboard(this);
            _mouse    = new WpfMouse(this);

            base.Initialize();
        }
Esempio n. 22
0
 public virtual void Draw(BasicEffect effect, Matrix world)
 {
 }
Esempio n. 23
0
        protected override void DebugDrawn(SceneControl.RenderHelper render, GameTime gt, Cameras.ICamera cam)
        {
            if (BasicEffect == null)
            {
                BasicEffect = new BasicEffect(render.device);
                BasicEffect.VertexColorEnabled = true;
                BasicEffect.TextureEnabled     = false;
            }

            //if (_fetchedResults == false)
            {
                DebugRenderable RenderBuffer = Scene.GetDebugRenderable();
                if (RenderBuffer == null || (RenderBuffer.TriangleCount == 0 && RenderBuffer.LineCount == 0))
                {
                    return;
                }

                Color c = Color.Red;
                if (RenderBuffer.TriangleCount > 0)
                {
                    VertexPositionColor1 = new VertexPositionColor[RenderBuffer.TriangleCount * 3];
                    for (int i = 0, j = 0; i < RenderBuffer.TriangleCount; i += 3, j++)
                    {
                        VertexPositionColor1[i].Color    = c;
                        VertexPositionColor1[i].Position = RenderBuffer.GetDebugTriangles()[j].Point0.AsXNA();

                        VertexPositionColor1[i + 1].Color    = c;
                        VertexPositionColor1[i + 1].Position = RenderBuffer.GetDebugTriangles()[j].Point1.AsXNA();

                        VertexPositionColor1[i + 2].Color    = c;
                        VertexPositionColor1[i + 2].Position = RenderBuffer.GetDebugTriangles()[j].Point2.AsXNA();
                    }
                }

                if (RenderBuffer.LineCount > 0)
                {
                    VertexPositionColor2 = new VertexPositionColor[RenderBuffer.LineCount * 2];
                    for (int i = 0, j = 0; i < RenderBuffer.LineCount; i += 2, j++)
                    {
                        VertexPositionColor2[i].Color    = c;
                        VertexPositionColor2[i].Position = RenderBuffer.GetDebugLines()[j].Point0.AsXNA();

                        VertexPositionColor2[i + 1].Color    = c;
                        VertexPositionColor2[i + 1].Position = RenderBuffer.GetDebugLines()[j].Point1.AsXNA();
                    }
                }
            }

            BasicEffect.View       = cam.View;
            BasicEffect.Projection = cam.Projection;
            BasicEffect.World      = Matrix.Identity;

            if (VertexPositionColor2 != null)
            {
                render.RenderUserPrimitive <VertexPositionColor>(BasicEffect, PrimitiveType.LineList, VertexPositionColor2, 0, VertexPositionColor2.Length / 2);
            }

            if (VertexPositionColor1 != null)
            {
                render.RenderUserPrimitive <VertexPositionColor>(BasicEffect, PrimitiveType.TriangleList, VertexPositionColor1, 0, VertexPositionColor1.Length / 3);
            }
        }
Esempio n. 24
0
 /// <summary>
 /// Initializes the effect (loading, parameter setting, and technique selection)
 /// used by the game.
 /// </summary>
 private void InitializeEffect()
 {
     fBasicEffect = new BasicEffect(GraphicsDevice);
     fBasicEffect.LightingEnabled    = false;
     fBasicEffect.VertexColorEnabled = true;
 }
Esempio n. 25
0
 protected override void LoadContent()
 {
     spriteBatch = new SpriteBatch(GraphicsDevice);
     effect      = new BasicEffect(GraphicsDevice);
     font        = Content.Load <SpriteFont>("Fonts/Augusta");
 }
Esempio n. 26
0
 public DebugDraw()
 {
     graphicsDevice = Costam.Game.GraphicsDevice;
     effect         = new BasicEffect(graphicsDevice);
 }
Esempio n. 27
0
    public LoadGraphicsContent( bool loadAllContent )
    {
        if (loadAllContent)
        {
            // TODO: Load any ResourceManagementMode.Automatic content
            texture = content.Load<Texture2D>( "Glass" );
            quadEffect = new BasicEffect( graphics.GraphicsDevice, null );
            quadEffect.EnableDefaultLighting();

            quadEffect.World = Matrix.Identity;
            quadEffect.View = View;
            quadEffect.Projection = Projection;
            quadEffect.TextureEnabled = true;
            quadEffect.Texture = texture;
        }
        // TODO: Load any ResourceManagementMode.Manual content
        quadVertexDecl = new VertexDeclaration(graphics.GraphicsDevice, 
            VertexPositionNormalTexture.VertexElements );
    }
        public static void Update()
        {
            if (!_bInitialized)
            {
                _fpsCamera = new FPS_Camera();
                //init renderer
                Effect = new BasicEffect(Memory.Graphics.GraphicsDevice);
                Effect.EnableDefaultLighting();
                Effect.TextureEnabled              = true;
                Effect.DirectionalLight0.Enabled   = true;
                Effect.DirectionalLight1.Enabled   = false;
                Effect.DirectionalLight2.Enabled   = false;
                Effect.DirectionalLight0.Direction = new Vector3(
                    -0.349999f,
                    0.499999f,
                    -0.650000f
                    );
                Effect.DirectionalLight0.SpecularColor = new Vector3(0.8500003f, 0.8500003f, 0.8500003f);
                Effect.DirectionalLight0.DiffuseColor  = new Vector3(1.54999f, 1.54999f, 1.54999f);
                _camTarget        = new Vector3(0, 0f, 0f);
                _camPosition      = new Vector3(0, 0f, 0f);
                _projectionMatrix = Matrix.CreatePerspectiveFieldOfView(
                    MathHelper.ToRadians(60),
                    Memory.Graphics.GraphicsDevice.Viewport.AspectRatio,
                    1f, 10000f);
                _viewMatrix = Matrix.CreateLookAt(_camPosition, _camTarget,
                                                  new Vector3(0f, 1f, 0f)); // Y up
                                                                            //worldMatrix = Matrix.CreateWorld(camTarget, Vector3.
                                                                            //              Forward, Vector3.Up);
                _worldMatrix = Matrix.CreateTranslation(0, 0, 0);
                //temporarily disabling this, because I'm getting more and more tired of this music playing over and over when debugging
                //Memory.musicIndex = 30;
                //AV.Music.Play();
                Ate = new AlphaTestEffect(Memory.Graphics.GraphicsDevice)
                {
                    Projection = _projectionMatrix,
                    View       = _viewMatrix,
                    World      = _worldMatrix,
                    FogEnabled = false,
                    FogColor   = Color.CornflowerBlue.ToVector3(),
                    FogStart   = 9.75f,
                    FogEnd     = RenderCamDistance
                };
                _bInitialized = true;
            }
            if (_lastFieldId != Memory.FieldHolder.FieldID)
            {
                ReInit();
            }
            _viewMatrix = _fpsCamera.Update(ref _camPosition, ref _camTarget, ref _degrees);
            if (Input2.Button(MouseButtons.LeftButton, ButtonTrigger.OnRelease))
            {
                _debugModelId++;
            }
            if (Input2.Button(Microsoft.Xna.Framework.Input.Keys.F1, ButtonTrigger.OnRelease))
            {
                ReInit();
            }
            if (Input2.Button(Microsoft.Xna.Framework.Input.Keys.F2))
            {
                Memory.FieldHolder.FieldID++;
            }
            if (Input2.Button(Microsoft.Xna.Framework.Input.Keys.F3))
            {
                Memory.FieldHolder.FieldID--;
            }
            if (Input2.Button(Microsoft.Xna.Framework.Input.Keys.F4))
            {
                _animId++;
                _animFrame = 0;
            }

            _timer += Memory.ElapsedGameTime.TotalMilliseconds / 1000.0d;
            if (_timer > 0.033d)
            {
                _animFrame++;
                _timer = 0f;
            }
        }
Esempio n. 29
0
        /// <summary>
        /// Looks up shortcut references to our effect parameters.
        /// </summary>
        void CacheEffectParameters(BasicEffect cloneSource)
        {
            textureParam                = Parameters["Texture"];
            diffuseColorParam           = Parameters["DiffuseColor"];
            emissiveColorParam          = Parameters["EmissiveColor"];
            specularColorParam          = Parameters["SpecularColor"];
            specularPowerParam          = Parameters["SpecularPower"];
            eyePositionParam            = Parameters["EyePosition"];
            fogColorParam               = Parameters["FogColor"];
            fogVectorParam              = Parameters["FogVector"];
            worldParam                  = Parameters["World"];
            worldInverseTransposeParam  = Parameters["WorldInverseTranspose"];
            worldViewProjParam          = Parameters["WorldViewProj"];
            shaderIndexParam            = Parameters["ShaderIndex"];

            light0 = new DirectionalLight(Parameters["DirLight0Direction"],
                                          Parameters["DirLight0DiffuseColor"],
                                          Parameters["DirLight0SpecularColor"],
                                          (cloneSource != null) ? cloneSource.light0 : null);

            light1 = new DirectionalLight(Parameters["DirLight1Direction"],
                                          Parameters["DirLight1DiffuseColor"],
                                          Parameters["DirLight1SpecularColor"],
                                          (cloneSource != null) ? cloneSource.light1 : null);

            light2 = new DirectionalLight(Parameters["DirLight2Direction"],
                                          Parameters["DirLight2DiffuseColor"],
                                          Parameters["DirLight2SpecularColor"],
                                          (cloneSource != null) ? cloneSource.light2 : null);
        }
 public override void LoadContent(ContentManager Content, GraphicsDeviceManager graphics, SpriteBatch spriteBatch)
 {
     effect = new BasicEffect(graphics.GraphicsDevice);
 }
        public void DrawUserIndexedPrimitivesParameterValidation()
        {
            var vertexDataNonEmpty = new[]
            {
                new VertexPositionColorTexture(Vector3.Zero, Color.White, Vector2.Zero),
                new VertexPositionColorTexture(Vector3.Zero, Color.White, Vector2.Zero),
                new VertexPositionColorTexture(Vector3.Zero, Color.White, Vector2.Zero)
            };
            var vertexDataEmpty = new VertexPositionColorTexture[0];

            var indexDataNonEmpty = new short[] { 0, 1, 2 };
            var indexDataEmpty    = new short[0];

            // No vertex shader or pixel shader.
            Assert.Throws <InvalidOperationException>(() => gd.DrawUserIndexedPrimitives(PrimitiveType.TriangleList, vertexDataNonEmpty, 0, 3, indexDataNonEmpty, 0, 1));

            var effect = new BasicEffect(gd);

            effect.CurrentTechnique.Passes[0].Apply();

            // Success - "normal" usage.
            Assert.DoesNotThrow(() => gd.DrawUserIndexedPrimitives(PrimitiveType.TriangleList, vertexDataNonEmpty, 0, 3, indexDataNonEmpty, 0, 1));

            // Failure cases.

            // Null vertexData.
            DoDrawUserIndexedPrimitivesAsserts(null, 0, 3, indexDataNonEmpty, 0, 1, d => Assert.Throws <ArgumentNullException>(d));

            // Empty vertexData.
            DoDrawUserIndexedPrimitivesAsserts(vertexDataEmpty, 0, 3, indexDataNonEmpty, 0, 1, d => Assert.Throws <ArgumentNullException>(d));

            // vertexOffset too small / large.
            DoDrawUserIndexedPrimitivesAsserts(vertexDataNonEmpty, -1, 3, indexDataNonEmpty, 0, 1, d => Assert.Throws <ArgumentOutOfRangeException>(d));
            DoDrawUserIndexedPrimitivesAsserts(vertexDataNonEmpty, 3, 3, indexDataNonEmpty, 0, 1, d => Assert.Throws <ArgumentOutOfRangeException>(d));

            // numVertices too small / large.
            DoDrawUserIndexedPrimitivesAsserts(vertexDataNonEmpty, 0, 0, indexDataNonEmpty, 0, 1, d => Assert.Throws <ArgumentOutOfRangeException>(d));
            DoDrawUserIndexedPrimitivesAsserts(vertexDataNonEmpty, 0, 4, indexDataNonEmpty, 0, 1, d => Assert.Throws <ArgumentOutOfRangeException>(d));

            // vertexOffset + numVertices too large.
            DoDrawUserIndexedPrimitivesAsserts(vertexDataNonEmpty, 1, 3, indexDataNonEmpty, 0, 1, d => Assert.Throws <ArgumentOutOfRangeException>(d));

            // Null indexData.
            DoDrawUserIndexedPrimitivesAsserts(vertexDataNonEmpty, 0, 3, null, 0, 1, d => Assert.Throws <ArgumentNullException>(d));

            // Empty indexData.
            DoDrawUserIndexedPrimitivesAsserts(vertexDataNonEmpty, 0, 3, indexDataEmpty, 0, 1, d => Assert.Throws <ArgumentNullException>(d));

            // indexOffset too small / large.
            DoDrawUserIndexedPrimitivesAsserts(vertexDataNonEmpty, 0, 3, indexDataNonEmpty, -1, 1, d => Assert.Throws <ArgumentOutOfRangeException>(d));
            DoDrawUserIndexedPrimitivesAsserts(vertexDataNonEmpty, 0, 3, indexDataNonEmpty, 1, 1, d => Assert.Throws <ArgumentOutOfRangeException>(d));

            // primitiveCount too small / large.
            DoDrawUserIndexedPrimitivesAsserts(vertexDataNonEmpty, 0, 3, indexDataNonEmpty, 0, -1, d => Assert.Throws <ArgumentOutOfRangeException>(d));
            DoDrawUserIndexedPrimitivesAsserts(vertexDataNonEmpty, 0, 3, indexDataNonEmpty, 0, 0, d => Assert.Throws <ArgumentOutOfRangeException>(d));
            DoDrawUserIndexedPrimitivesAsserts(vertexDataNonEmpty, 0, 3, indexDataNonEmpty, 0, 2, d => Assert.Throws <ArgumentOutOfRangeException>(d));

            // indexOffset + primitiveCount too large.
            DoDrawUserIndexedPrimitivesAsserts(vertexDataNonEmpty, 0, 3, indexDataNonEmpty, 1, 1, d => Assert.Throws <ArgumentOutOfRangeException>(d));

            // Null vertexDeclaration.
            Assert.Throws <ArgumentNullException>(() => gd.DrawUserIndexedPrimitives(PrimitiveType.TriangleList, vertexDataNonEmpty, 0, 3, indexDataNonEmpty, 0, 1, null));

            // Smaller vertex stride in VertexDeclaration than in actual vertices.

            // XNA is inconsistent; in DrawUserIndexedPrimitives, it allows vertexStride to be less than the actual size of the data,
            // but in VertexBuffer.SetData, XNA requires vertexStride to greater than or equal to the actual size of the data.
            // Since we use a DynamicVertexBuffer to implement DrawUserIndexedPrimitives, we use the same validation in both places.
            // The same applies to DrawUserPrimitives.
#if XNA
            Assert.DoesNotThrow(() => gd.DrawUserIndexedPrimitives(PrimitiveType.TriangleList, vertexDataNonEmpty, 0, 3, indexDataNonEmpty, 0, 1, VertexPositionColor.VertexDeclaration));
            Assert.DoesNotThrow(() => gd.DrawUserIndexedPrimitives(PrimitiveType.TriangleList, vertexDataNonEmpty, 0, 3, indexDataNonEmpty.Select(x => (int)x).ToArray(), 0, 1, VertexPositionColor.VertexDeclaration));
#else
            Assert.Throws <ArgumentOutOfRangeException>(() => gd.DrawUserIndexedPrimitives(PrimitiveType.TriangleList, vertexDataNonEmpty, 0, 3, indexDataNonEmpty, 0, 1, VertexPositionColor.VertexDeclaration));
            Assert.Throws <ArgumentOutOfRangeException>(() => gd.DrawUserIndexedPrimitives(PrimitiveType.TriangleList, vertexDataNonEmpty, 0, 3, indexDataNonEmpty.Select(x => (int)x).ToArray(), 0, 1, VertexPositionColor.VertexDeclaration));
#endif
            effect.Dispose();
        }
        public void SetupBasicEffect(BasicEffect e, float opacity, System.Drawing.Color color)
        {
            Vector4 correctedColor;
            if (sRGB)
            {
                // sRGB correction for alpha. Even though alpha should be linear, we apply a
                // gamma correction because it's multiplied with color values. The right thing
                // to do is probably to use pre-multiplied alpha throughout WWT and not gamma
                // correct alpha.
                opacity = (float)Math.Pow(opacity, 2.2);
                correctedColor = new Vector4((float)Math.Pow(color.R / 255.0f, 2.2),
                                             (float)Math.Pow(color.G / 255.0f, 2.2),
                                             (float)Math.Pow(color.B / 255.0f, 2.2), opacity);
            }
            else
            {
                correctedColor = new Vector4(color.R / 255.0f, color.G / 255.0f, color.B / 255.0f, opacity);
            }

            switch (e)
            {
                case BasicEffect.TextureOnly:
                    {
                        PlanetShaderKey key = new PlanetShaderKey(PlanetSurfaceStyle.Emissive, false, 0);
                        SetupPlanetSurfaceEffect(key, opacity);
                        Shader.DiffuseColor = new Vector4(1.0f, 1.0f, 1.0f, opacity);
                    }
                    break;

                case BasicEffect.ColorOnly:
                    {
                        PlanetShaderKey key = new PlanetShaderKey(PlanetSurfaceStyle.Emissive, false, 0);
                        key.textures = 0;
                        SetupPlanetSurfaceEffect(key, opacity);
                        Shader.DiffuseColor = correctedColor;
                    }
                    break;

                case BasicEffect.TextureColorOpacity:
                    {
                        PlanetShaderKey key = new PlanetShaderKey(PlanetSurfaceStyle.Emissive, false, 0);
                        SetupPlanetSurfaceEffect(key, opacity);
                        Shader.DiffuseColor = correctedColor;
                    }
                    break;

                case BasicEffect.ColoredText:
                    {
                        PlanetShaderKey key = new PlanetShaderKey(PlanetSurfaceStyle.Emissive, false, 0);
                        key.AlphaTexture = true;
                        SetupPlanetSurfaceEffect(key, opacity);
                        Shader.DiffuseColor = correctedColor;
                    }
                    break;

                default:
                    Shader = null;
                    break;
            }
        }
Esempio n. 33
0
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            base.Initialize();
            float width;
            float height;
            float depth;
            float adjust;

            width  = 40f;
            adjust = 0.125f;
            height = width * (1 - adjust) + (adjust) * (width * ((float)System.Math.Sqrt(3.0f)) / 2f);
            depth  = 80f;
            //Setup Camera

            //bloom = new BloomComponent(this);
            //Components.Add(bloom);
            //bloom.Settings = new BloomSettings("None", 0.0f, 0, 0f, 1, 0, 0);
            //bloom.Initialize();
            //System.Console.WriteLine(bloom.Settings.BloomThreshold.ToString());

            worldMatrix = Matrix.Identity;
            viewMatrix  = Matrix.CreateLookAt(new Vector3(width / 2, width / 2, width / 2), new Vector3(0, 0, 0), new Vector3(0, 0, 1));



            projectionMatrix = Matrix.CreateOrthographic(width, height, 0, depth);

            //BasicEffect
            basicEffect       = new BasicEffect(GraphicsDevice);
            basicEffect.Alpha = 1f;

            // Want to see the colors of the vertices, this needs to be on
            basicEffect.VertexColorEnabled = true;

            //Lighting requires normal information which VertexPositionColor does not have
            //If you want to use lighting and VPC you need to create a custom def
            basicEffect.LightingEnabled = true;

            //vertexBuffer = new VertexBuffer(GraphicsDevice, typeof(
            //   Helpers.VertexPositionColorNormal), 36, BufferUsage.
            //   WriteOnly);
            Generate.Shapes.Vertex [] [] cubes =
                Generate.Vertices.shapesToTriangles(Generate.Clusters.simpleStack(new Generate.Shapes.Position(0, 0, 0), 8, System.Drawing.Color.Gray));
            int vertexCount = 0;

            for (int i = 0; i < cubes.Length; i++)
            {
                vertexCount = vertexCount + cubes[i].Length;
            }

            triangleVertices = new Helpers.VertexPositionColorNormal[vertexCount];
            int idx = 0;

            for (int h = 0; h < cubes.Length; h++)
            {
                for (int i = 0; i < cubes[h].Length; i++)
                {
                    triangleVertices[idx] = new Helpers.VertexPositionColorNormal(
                        new Vector3((float)cubes[h][i].PositionX, (float)cubes[h][i].PositionY, (float)cubes[h][i].PositionZ),
                        new Microsoft.Xna.Framework.Color((float)cubes[h][i].ColorR, (float)cubes[h][i].ColorG, (float)cubes[h][i].ColorB),
                        new Vector3((float)cubes[h][i].NormalX, (float)cubes[h][i].NormalY, (float)cubes[h][i].NormalZ));
                    idx += 1;
                }
            }
            vertexBuffer = new VertexBuffer(GraphicsDevice, typeof(Helpers.VertexPositionColorNormal), triangleVertices.Length, BufferUsage.WriteOnly);
            vertexBuffer.SetData <Helpers.VertexPositionColorNormal>(triangleVertices);
        }
Esempio n. 34
0
        /// <summary>
        /// Creates a new BasicEffect by cloning parameter settings from an existing instance.
        /// </summary>
        protected BasicEffect(BasicEffect cloneSource)
            : base(cloneSource)
        {
            CacheEffectParameters(cloneSource);

            lightingEnabled = cloneSource.lightingEnabled;
            preferPerPixelLighting = cloneSource.preferPerPixelLighting;
            fogEnabled = cloneSource.fogEnabled;
            textureEnabled = cloneSource.textureEnabled;
            vertexColorEnabled = cloneSource.vertexColorEnabled;

            world = cloneSource.world;
            view = cloneSource.view;
            projection = cloneSource.projection;

            diffuseColor = cloneSource.diffuseColor;
            emissiveColor = cloneSource.emissiveColor;
            ambientLightColor = cloneSource.ambientLightColor;

            alpha = cloneSource.alpha;

            fogStart = cloneSource.fogStart;
            fogEnd = cloneSource.fogEnd;
        }
Esempio n. 35
0
 protected override void LoadContent()
 {
     base.LoadContent();
     EffetDeBase = new BasicEffect(GraphicsDevice);
     InitialiserParamètresEffetDeBase();
 }
    /// <summary>
    /// Renders a Ray for debugging purposes.
    /// </summary>
    /// <param name="ray">The ray to render.</param>
    /// <param name="length">The distance along the ray to render.</param>
    /// <param name="graphicsDevice">The graphics device to use when rendering.</param>
    /// <param name="view">The current view matrix.</param>
    /// <param name="projection">The current projection matrix.</param>
    /// <param name="color">The color to use drawing the ray.</param>
    public static void Render(Ray ray, float length, GraphicsDevice graphicsDevice, Matrix view, Matrix projection, Color color)
    {
        if (effect == null)
            {
                effect = new BasicEffect(graphicsDevice);
                effect.VertexColorEnabled = false;
                effect.LightingEnabled = false;
            }

            verts[0] = new VertexPositionColor(ray.Position, Color.White);
            verts[1] = new VertexPositionColor(ray.Position + (ray.Direction * length), Color.White);

            effect.DiffuseColor = color.ToVector3();
            effect.Alpha = (float)color.A / 255f;

            effect.World = Matrix.Identity;
            effect.View = view;
            effect.Projection = projection;

            //note you may wish to comment these next 2 lines out and set the RasterizerState elswehere in code
            //rather than here for every ray draw call.
            RasterizerState rs = graphicsDevice.RasterizerState;
            graphicsDevice.RasterizerState = RasterizerState.CullNone;

            foreach (EffectPass pass in effect.CurrentTechnique.Passes)
            {
                pass.Apply();

                graphicsDevice.DrawUserPrimitives(PrimitiveType.LineList, verts, 0, 1);

                effect.World = Matrix.Invert(Matrix.CreateLookAt(
                    verts[1].Position,
                    verts[0].Position,
                    (ray.Direction != Vector3.Up) ? Vector3.Up : Vector3.Left));

                graphicsDevice.DrawUserIndexedPrimitives(PrimitiveType.LineList, arrowVerts, 0, 5, arrowIndexs, 0, 4);
            }

            //note you may wish to comment the next line out and set the RasterizerState elswehere in code
            //rather than here for every ray draw call.
            graphicsDevice.RasterizerState = rs;
    }
Esempio n. 37
0
 /// <summary>
 /// Create the BasicEffect to be used by Lines.
 /// </summary>
 private void CreateLineEffect()
 {
     mBasicLineVertexDecl = new VertexDeclaration(Engine.Device, VertexPositionColor.VertexElements);
     mBasicLineEffect     = new BasicEffect(Engine.Device, null);
     mBasicLineEffect.VertexColorEnabled = true;
 }
Esempio n. 38
0
 public Camera(GraphicsDeviceManager graphics, BasicEffect basicEffect)
 {
     this.graphics    = graphics;
     this.basicEffect = basicEffect;
 }
Esempio n. 39
0
 public void ApplyCamera(BasicEffect effect, WorldComponent component)
 {
     effect.World      = component.World;
     effect.View       = State.Camera.View;
     effect.Projection = State.Camera.Projection;
 }