Built-in effect that supports optional texturing, vertex coloring, fog, and lighting.
Наследование: Effect, IEffectMatrices, IEffectLights, IEffectFog
Пример #1
1
        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);
        }
Пример #2
0
        public override void Initialize()
        {
            Effect = new BasicEffect(Device, null);

            /** Bottom Face **/
            var btmTL = new Vector3(0.0f, 0.0f, 0.0f);
            var btmTR = new Vector3(Size.X, 0.0f, 0.0f);
            var btmBR = new Vector3(Size.X, 0.0f, Size.Z);
            var btmBL = new Vector3(0.0f, 0.0f, Size.Z);

            /** Top face **/
            var topTL = new Vector3(0.0f, Size.Y, 0.0f);
            var topTR = new Vector3(Size.X, Size.Y, 0.0f);
            var topBR = new Vector3(Size.X, Size.Y, Size.Z);
            var topBL = new Vector3(0.0f, Size.Y, Size.Z);

            GeomList = new List<VertexPositionColor>();
            AddQuad(Color, topTL, topTR, topBR, topBL);
            AddQuad(Color.Yellow, btmTL, btmTR, btmBR, btmBL);
            AddQuad(Color.Green, topTL, topTR, btmTR, btmTL);
            AddQuad(Color.Blue, topBL, topTL, btmTL, btmBL);
            AddQuad(Color.Orange, topBR, topTR, btmTR, btmBR);
            AddQuad(Color.White, topBL, topBR, btmBR, btmBL);

            Geom = GeomList.ToArray();
        }
Пример #3
0
        public void DrawDebugWorld(DynamicsWorld world)
        {
            world.DebugDrawWorld();

            if (lines.Count == 0)
                return;

            if (effect == null)
            {
                effect = new BasicEffect(graphics.Device);
                effect.World = Microsoft.Xna.Framework.Matrix.Identity;
                effect.VertexColorEnabled = true;
                pass = effect.CurrentTechnique.Passes[0];
            }

            effect.Projection = graphics.GetEffect().Projection;
            effect.View = graphics.GetEffect().View;
            pass.Apply();

            int pointCount = lines.Count;
            int linesCount = pointCount / 2;
            VertexPositionColor[] linesArray = new VertexPositionColor[pointCount];
            for (int i = 0; i < pointCount; i++)
            {
                int color = lines[i].Color;
                linesArray[i].Color = new Color(color & 0xff, (color & 0xff00) >> 8, (color & 0xff0000) >> 16, 1);
                linesArray[i].Position = MathHelper.Convert(lines[i].Position);
            }
            graphics.Device.DrawUserPrimitives(PrimitiveType.LineList, linesArray, 0, linesCount);
            lines.Clear();
        }
Пример #4
0
        public TextureCreator(SpriteManager sprManager, GraphicsDevice device)
        {
            this.sprManager = sprManager;
            this.device = device;

            effect = new BasicEffect(device);
        }
        public static void InitializeGraphics(GraphicsDevice graphicsDevice,
                                              Triangle[] triangles,
                                              Guid id)
        {
            var basicEffect = new BasicEffect(graphicsDevice)
                                  {
                                      LightingEnabled = false,
                                      VertexColorEnabled = false
                                  };

            var index = 0;
            var vertices = new VertexPositionColor[triangles.SelectMany(i => i.Points).Count()];

            foreach (var point in triangles.SelectMany(triangle => triangle.Points))
                vertices[index++] = new VertexPositionColor(new Vector3(point.X,
                                                                        point.Y,
                                                                        point.Z),
                                                            Color.White);

            var vertexBuffer = new VertexBuffer(graphicsDevice,
                                                typeof (VertexPositionColor),
                                                vertices.Length,
                                                BufferUsage.None);
            vertexBuffer.SetData(vertices);

            Subscriptions.Add(id, new RendererHelperData
                                       {
                                           BasicEffect = basicEffect,
                                           VertexBuffer = vertexBuffer
                                       });
        }
Пример #6
0
        public Earth()
        {
            Sun = Game.Sun;
            Rotation = 0;
            RotationInFastSpeed = 0;
            RotationAxisPointList = new VertexPositionColor[2];

            // vernal equinox
            RevolutionBasis = new Vector3(0, 0, -RevolutionRadius);

            Scale = Matrix.CreateScale(new Vector3(Radius, Radius, Radius));

            BasicEffect = new BasicEffect(Game.GraphicsDevice);

            InitLineStrip();
            InitRevPointList();

            BasicEffect.VertexColorEnabled = true;
            BasicEffect.World = Matrix.Identity;

            // up
            Up = Vector3.Transform(Vector3.Up, Matrix.CreateRotationZ(EclipticObliquity));
            Up.Normalize();

            // rotation axis
            RotationAxis = Up * Radius * 7f;
        }
Пример #7
0
        /// <summary>
        /// Constructor de la clase camara, se inicializan las matrices y se añaden al effect.
        /// </summary>
        /// <param name="effect">Effecto que se usa para dibujar.</param>
        /// <param name="device">El device actual.</param>
        public Camera(BasicEffect effect, GraphicsDevice device)
        {
            this.effect = effect;
            this.device = device;

            //Angulos inciales de la camara
            angleXZ = MathHelper.Pi / 4;
            angleYZ = MathHelper.Pi / 6;

            yaw = 0;
            pitch = 0;
            roll = 0;

            rotation = Quaternion.Identity;

            //Posicicón y destino inicial de la camara
            posicion.Y = 20 * (float)Math.Sin(angleYZ);
            posicion.X = 20 * (float)Math.Cos(angleYZ) * (float)Math.Sin(angleXZ);
            posicion.Z = 20 * (float)Math.Cos(angleYZ) * (float)Math.Cos(angleXZ);
            destino = new Vector3(0, 0, 0);

            //Se definen las matrices
            setCamera();
            worldMatrix = Matrix.Identity;
            projection = Matrix.CreateOrthographic(device.Viewport.Width / 8, device.Viewport.Height / 8, -200.0f, 200.0f);
            //projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.PiOver4, device.Viewport.AspectRatio, 1.0f, 200.0f);

            //Se añaden al effect
            effect.World = worldMatrix;
            effect.View = viewMatrix;
            effect.Projection = projection;
        }
Пример #8
0
        public DrawWrapper(SpriteBatch batch, GraphicsDevice device, AssetManager assetsManager)
        {
            GlobalScale = 1f;

            spriteBatch = batch;
            graphicsDevice = device;
            deviceWidth = graphicsDevice.Viewport.Width;

            Assets = assetsManager;

            basicEffect = new BasicEffect(device)
            {
                VertexColorEnabled = true,
                World = Matrix.Identity,
                View = Matrix.Identity,
            };

            guiEffect = (BasicEffect) basicEffect.Clone();

            SetProjectionMatrix(standardWidth, standardHeight);
            ScreenSize = new Vector2(graphicsDevice.Viewport.Width, graphicsDevice.Viewport.Height);

            displayWidth = standardWidth;
            displayHeight = standardHeight;
        }
Пример #9
0
 public Renderer(GraphicsDevice device, RenderState renderState)
 {
     RenderState  = renderState;
     Device = device;
     _effect = new BasicEffect(Device);
     _bufferedInstructions = new List<IEnumerable<RenderInstruction>>();
 }
Пример #10
0
        public static void Draw(this BoundingFrustum frustum, GraphicsDevice graphicsDevice, Matrix view, Matrix projection, Color color)
        {
            if (effect == null)
            {
                effect = new BasicEffect(graphicsDevice);
                effect.VertexColorEnabled = true;
                effect.LightingEnabled = false;
            }

            Vector3[] corners = frustum.GetCorners();
            for (int i = 0; i < 8; i++)
            {
                verts[i].Position = corners[i];
                verts[i].Color = color;
            }

            effect.View = view;
            effect.Projection = projection;
            foreach (var t in effect.Techniques)
                foreach (var p in t.Passes)
                {
                    p.Apply();

                    graphicsDevice.DrawUserIndexedPrimitives(
                        PrimitiveType.LineList, verts, 0, 8,
                        indices, 0, indices.Length / 2);

                }
        }
Пример #11
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()
        {
            lineEffect = new BasicEffect(graphics.GraphicsDevice);
            lineEffect.DiffuseColor = new Vector3(1.0f, 1.0f, 1.0f);

            base.Initialize();
        }
Пример #12
0
        public void Draw(Matrix parentMatrix, BasicEffect effect, float value, float headTurn)
        {
            Matrix headTranslation = Matrix.CreateTranslation(new Vector3(-4, 0, -4));
            headTranslation *= Matrix.CreateFromYawPitchRoll(headTurn, (float)Math.Sin(value * 8) / 10, 0);
            //headTranslation *= Matrix.CreateRotationX((float)Math.Sin(value * 8) / 10);
            //headTranslation *= Matrix.CreateRotationY(headTurn);
            headTranslation *= Matrix.CreateTranslation(new Vector3(4, 0, 4));

            //Matrix headTranslation = MatrixExtensions.CreateRotationX(new Vector3(4, 0, 4), (float)Math.Sin(value * 8) / 10);
            //headTranslation *= Matrix.;
            headModel.Draw(headTranslation * Matrix.CreateTranslation(0, 12, -2) * parentMatrix, effect);

            bodyModel.Draw(parentMatrix, effect);

            Matrix armLeftTranslation = MatrixExtensions.CreateRotationX(new Vector3(2, 10, 2), (float)Math.Sin(value * 5) / 2);
            armLeftTranslation *= MatrixExtensions.CreateRotationZ(new Vector3(2, 10, 2), (float)Math.Sin(value * 9) / 8 - 1.0f / 8.0f);
            armModelLeft.Draw(armLeftTranslation * Matrix.CreateTranslation(-4, 0, 0) * parentMatrix, effect);

            Matrix armRightTranslation = MatrixExtensions.CreateRotationX(new Vector3(2, 10, 2), (float)Math.Sin(value * 5 - Math.PI) / 2);
            armRightTranslation *= MatrixExtensions.CreateRotationZ(new Vector3(2, 10, 2), (float)Math.Sin(value * 9 - Math.PI) / 8 + 1.0f / 8.0f);
            armModelRight.Draw(armRightTranslation * Matrix.CreateTranslation(8, 0, 0) * parentMatrix, effect);

            Matrix legLeftTranslation = MatrixExtensions.CreateRotationX(new Vector3(2, 12, 2), (float)Math.Sin(value * 7) / 1);
            legModelLeft.Draw(legLeftTranslation * Matrix.CreateTranslation(0, -12, 0) * parentMatrix, effect);

            Matrix legRightTranslation = MatrixExtensions.CreateRotationX(new Vector3(2, 12, 2), (float)Math.Sin(value * 7 - Math.PI) / 1);
            legModelRight.Draw(legRightTranslation * Matrix.CreateTranslation(4, -12, 0) * parentMatrix, effect);
        }
Пример #13
0
        public LineBatch(GraphicsDevice graphicsDevice)
        {
            // assign the graphics device parameter after safety-checking
            if (graphicsDevice == null)
            {
                throw new ArgumentNullException("graphicsDevice");
            }
            this.graphicsDevice = graphicsDevice;

            // create and configure the effect
            this.effect = new BasicEffect(graphicsDevice);
            this.effect.VertexColorEnabled = true;
            this.effect.TextureEnabled = false;
            this.effect.LightingEnabled = false;
            // configure the effect
            this.effect.World = Matrix.Identity;
            this.effect.View = Matrix.CreateLookAt(Vector3.Zero, Vector3.Forward,
                Vector3.Up);
            
            // create the vertex declaration
            //this.vertexDeclaration = new VertexDeclaration(graphicsDevice,
            //    VertexPositionColor.VertexElements);
            this.vertexDeclaration = new VertexDeclaration(new VertexElement());

            // create the vertex array
            this.vertices = new VertexPositionColor[maxVertexCount];
        }
 public SimpleTree(GraphicsDevice device, TreeSkeleton skeleton)
 {
     this.device = device;
     this.skeleton = skeleton;
     BoneEffect = new BasicEffect(device, new EffectPool());
     UpdateSkeleton();
 }
Пример #15
0
 public ImmediateModeDebug(GraphicsDevice GraphicsDevice)
 {
     this.GraphicsDevice = GraphicsDevice;
     this.Effect = new BasicEffect(GraphicsDevice);
     Effect.TextureEnabled = false;
     Effect.VertexColorEnabled = true;
 }
Пример #16
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();

            //Add camera
            camera = new CameraController(this);

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

            basicEffect.VertexColorEnabled = true;

            //Lighting required information which VertexPositionColor does not have
            basicEffect.LightingEnabled = false;

            //Geometry of a simple triangle
            triangleVertices = new VertexPositionColor[3];
            triangleVertices[0] = new VertexPositionColor(new Vector3(0, 20, 0), Color.Red);
            triangleVertices[1] = new VertexPositionColor(new Vector3(-20, -20, 0), Color.Green);
            triangleVertices[2] = new VertexPositionColor(new Vector3(20, -20, 0), Color.Blue);

            //Vertex buffer
            vertexBuffer = new VertexBuffer(GraphicsDevice, typeof(VertexPositionColor),
                3, BufferUsage.WriteOnly);
            vertexBuffer.SetData<VertexPositionColor>(triangleVertices);
        }
Пример #17
0
        public CoordCross(GraphicsDevice device)
        {
            this.device = device;
            basicEffect = new BasicEffect(device);

            InitVertices();
        }
Пример #18
0
        public void drawSquarre(VertexPositionNormalTexture[] vertexData, int[] indexData, Camera came, BasicEffect effect, GraphicsDevice graphicsDevice)
        {
            Texture2D texture = Tools.Quick.groundTexture[BiomeType.SubtropicalDesert];
            effect.Projection = projectionMatrix;
            effect.Texture = texture;
            effect.TextureEnabled = true; ;

            graphicsDevice.RasterizerState = WIREFRAME_RASTERIZER_STATE;    // draw in wireframe
            graphicsDevice.BlendState = BlendState.Opaque;                  // no alpha this time

            //   effect.DiffuseColor = Color.Red.ToVector3();
            effect.CurrentTechnique.Passes[0].Apply();

            effect.View = came.getview();
            effect.CurrentTechnique.Passes[0].Apply();
            graphicsDevice.DrawUserIndexedPrimitives(PrimitiveType.TriangleList, vertexData, 0, 4, indexData, 0, 2);

            /*  // Draw wireframe box
              graphicsDevice.RasterizerState = WIREFRAME_RASTERIZER_STATE;    // draw in wireframe
              graphicsDevice.BlendState = BlendState.Opaque;                  // no alpha this time

              effect.TextureEnabled = false;
             // effect.DiffuseColor = Color.Black.ToVector3();
              effect.CurrentTechnique.Passes[0].Apply();

              graphicsDevice.DrawUserIndexedPrimitives(PrimitiveType.TriangleList, vertexData, 0, 4, indexData, 0, 2);
                 */
        }
        /// <summary>
        /// Draw a bounding frustrum representation
        /// </summary>
        /// <param name="frustum">Frustrum</param>
        /// <param name="camera">Camera</param>
        /// <param name="color">Color</param>
        public static void Draw(BoundingFrustum frustum, BaseCamera camera, Color color)
        {
            if (effect == null)
            {
                effect = new BasicEffect(YnG.GraphicsDevice);
                effect.VertexColorEnabled = true;
                effect.LightingEnabled = false;
            }

            Vector3[] corners = frustum.GetCorners();
            for (int i = 0; i < 8; i++)
            {
                vertices[i].Position = corners[i];
                vertices[i].Color = color;
            }

            effect.View = camera.View;
            effect.Projection = camera.Projection;

            foreach (EffectPass pass in effect.CurrentTechnique.Passes)
            {
                pass.Apply();
                YnG.GraphicsDevice.DrawUserIndexedPrimitives(PrimitiveType.LineList, vertices, 0, 8, indices, 0, indices.Length / 2);
            }
        }
Пример #20
0
        public Snowflake(Vector3 position, float snowflakeTemperature)
        {
            float diameter = Snowflake.CalculateDiameter(snowflakeTemperature);
            this.mass      = Snowflake.CalculateMass    (snowflakeTemperature, diameter);

            this.basicEffect = new BasicEffect(this.graphicsDevice);

            this.basicEffect.World = this.camera.World;
            this.basicEffect.View = this.camera.View;
            this.basicEffect.Projection = this.camera.Projection;
            this.basicEffect.TextureEnabled = true;

            if (this.showLeaf)
            {
                this.quad = new Quad(diameter * 2);
                Texture2D texture = this.contentManager.Load<Texture2D>("leaf_" + (int)(Snowflake.random.NextDouble() * numTextures));
                this.basicEffect.Texture = texture;
            }
            else
            {
                this.quad = new Quad(diameter);
                Texture2D texture = this.contentManager.Load<Texture2D>("flake_" + (int)(Snowflake.random.NextDouble() * numTextures));
                this.basicEffect.Texture = texture;
            }

            this.Position = position;
            this.velocity = new Vector3(0f, -0.1f, 0f);
        }
Пример #21
0
 /// <summary>
 /// Draw
 /// </summary>
 /// <param name="graphicsDevice"></param>
 /// <param name="basicEffect"></param>
 /// <param name="spriteBatch"></param>
 public virtual void Draw(GraphicsDevice graphicsDevice, BasicEffect basicEffect, SpriteBatch spriteBatch)
 {
     if (this._model != null)
     {
         this._model.Draw(graphicsDevice, basicEffect);
     }
 }
Пример #22
0
        public void Draw(GraphicsDevice graphicsDevice, BasicEffect basicEffect)
        {
            if (this.lines.Count > 0)
            {
                foreach (EffectPass pass in basicEffect.CurrentTechnique.Passes)
                {
                    pass.Apply();
                    graphicsDevice.DrawUserIndexedPrimitives<VertexPositionColor>(
                        PrimitiveType.LineList,
                        this.GetPointsAsArray(),
                        0,  // vertex buffer offset to add to each element of the index buffer
                        this.points.Count,  // number of vertices in pointList
                        this.GetLinesAsIndexArray(),  // the index buffer
                        0,  // first index element to read
                        this.lines.Count   // number of primitives to draw
                    );
                }
            }

            basicEffect.TextureEnabled = true;
            using (var batch = new SpriteBatch(graphicsDevice))
            {
                batch.Begin(0, null, null, null, null, basicEffect);
                foreach (var vertex in this.GetPointsAsArray())
                {
                    batch.Draw(GlobalTextures.pixelTexture, new Vector2(vertex.Position.X - 3, vertex.Position.Y - 3), vertex.Color);
                }
                batch.End();
            }

            basicEffect.TextureEnabled = false;
        }
Пример #23
0
 protected override void setBasicEffect(BasicEffect be)
 {
     be.DiffuseColor = _isLonger
         ? new Vector3(0.8f, 0.2f, 0.2f)
         : new Vector3(0.2f, 0.8f, 0.2f);
     be.Alpha = SerpentStatus == SerpentStatus.Alive ? 1 : 0.5f;
 }
Пример #24
0
        public PhysicsRenderer(GraphicsDevice device)
        {
            this.device = device;

            material = new BasicEffect(device);
            material.VertexColorEnabled = true;
        }
Пример #25
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
            zNear = 0.001f;
            zFar = 1000.0f;
            fov = MathHelper.Pi * 70.0f / 180.0f;
            eye = new Vector3(0.0f, 0.7f, 1.5f);
            at = new Vector3(0.0f, 0.0f, 0.0f);
            up = new Vector3(0.0f, 1.0f, 0.0f);

            cube = new VertexPositionColor[8];
            cube[0] = new VertexPositionColor(new Vector3(-0.5f, -0.5f, -0.5f), new Color(0.0f, 0.0f, 0.0f));
            cube[1] = new VertexPositionColor(new Vector3(-0.5f, -0.5f,  0.5f), new Color(0.0f, 0.0f, 1.0f));
            cube[2] = new VertexPositionColor(new Vector3(-0.5f,  0.5f, -0.5f), new Color(0.0f, 1.0f, 0.0f));
            cube[3] = new VertexPositionColor(new Vector3(-0.5f,  0.5f,  0.5f), new Color(0.0f, 1.0f, 1.0f));
            cube[4] = new VertexPositionColor(new Vector3( 0.5f, -0.5f, -0.5f), new Color(1.0f, 0.0f, 0.0f));
            cube[5] = new VertexPositionColor(new Vector3( 0.5f, -0.5f,  0.5f), new Color(1.0f, 0.0f, 1.0f));
            cube[6] = new VertexPositionColor(new Vector3( 0.5f,  0.5f, -0.5f), new Color(1.0f, 1.0f, 0.0f));
            cube[7] = new VertexPositionColor(new Vector3( 0.5f,  0.5f,  0.5f), new Color(1.0f, 1.0f, 1.0f));

            vertexBuffer = new DynamicVertexBuffer(graphics.GraphicsDevice, typeof(VertexPositionColor), 8, BufferUsage.WriteOnly);
            indexBuffer = new DynamicIndexBuffer(graphics.GraphicsDevice, typeof(ushort), 36, BufferUsage.WriteOnly);

            basicEffect = new BasicEffect(graphics.GraphicsDevice); //(device, null);
            basicEffect.LightingEnabled = false;
            basicEffect.VertexColorEnabled = true;
            basicEffect.TextureEnabled = false;

            graphics.SupportedOrientations = DisplayOrientation.LandscapeLeft | DisplayOrientation.LandscapeRight;
            base.Initialize();
        }
Пример #26
0
		protected override void Initialize ()
		{
			floorVerts = new VertexPositionTexture[6];

			floorVerts [0].Position = new Vector3 (-20, -20, 0);
			floorVerts [1].Position = new Vector3 (-20,  20, 0);
			floorVerts [2].Position = new Vector3 ( 20, -20, 0);

			floorVerts [3].Position = floorVerts[1].Position;
			floorVerts [4].Position = new Vector3 ( 20,  20, 0);
			floorVerts [5].Position = floorVerts[2].Position;

			int repetitions = 20;

			floorVerts [0].TextureCoordinate = new Vector2 (0, 0);
			floorVerts [1].TextureCoordinate = new Vector2 (0, repetitions);
			floorVerts [2].TextureCoordinate = new Vector2 (repetitions, 0);

			floorVerts [3].TextureCoordinate = floorVerts[1].TextureCoordinate;
			floorVerts [4].TextureCoordinate = new Vector2 (repetitions, repetitions);
			floorVerts [5].TextureCoordinate = floorVerts[2].TextureCoordinate;

			effect = new BasicEffect (graphics.GraphicsDevice);

			base.Initialize ();
		}
Пример #27
0
 public LD(GraphicsDevice gd)
 {
     effect = new BasicEffect(gd);
     effect.VertexColorEnabled = true;
     vertices = new VertexPositionColor[ushort.MaxValue];
     vertexCount = 0;
 }
Пример #28
0
        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);
        }
Пример #29
0
        /// <summary>
        /// Renders the bounding box for debugging purposes.
        /// </summary>
        /// <param name="box">The box 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 lines of the box.</param>
        public static void Render(
            BoundingBox box,
            GraphicsDevice graphicsDevice,
            Matrix view,
            Matrix projection,
            Color color)
        {
            if (box.Min == box.Max)
            {
                return;
            }

            if (effect == null)
            {
                effect = new BasicEffect(graphicsDevice)
                             {TextureEnabled = false, VertexColorEnabled = true, LightingEnabled = false};
            }

            Vector3[] corners = box.GetCorners();
            for (int i = 0; i < 8; i++)
            {
                verts[i].Position = corners[i];
                verts[i].Color = color;
            }

            effect.View = view;
            effect.Projection = projection;

            foreach (EffectPass pass in effect.CurrentTechnique.Passes)
            {
                pass.Apply();
                graphicsDevice.DrawUserIndexedPrimitives(PrimitiveType.LineList, verts, 0, 8, indices, 0,
                                                         indices.Length/2);
            }
        }
Пример #30
0
        public ChunkModule(TrueCraftGame game)
        {
            Game = game;

            ChunkRenderer = new ChunkRenderer(Game.Client.World, Game, Game.BlockRepository);
            Game.Client.ChunkLoaded += (sender, e) => ChunkRenderer.Enqueue(e.Chunk);
            Game.Client.ChunkUnloaded += (sender, e) => UnloadChunk(e.Chunk);
            Game.Client.ChunkModified += (sender, e) => ChunkRenderer.Enqueue(e.Chunk, true);
            ChunkRenderer.MeshCompleted += MeshCompleted;
            ChunkRenderer.Start();

            OpaqueEffect = new BasicEffect(Game.GraphicsDevice);
            OpaqueEffect.TextureEnabled = true;
            OpaqueEffect.Texture = Game.TextureMapper.GetTexture("terrain.png");
            OpaqueEffect.FogEnabled = true;
            OpaqueEffect.FogStart = 512f;
            OpaqueEffect.FogEnd = 1000f;
            OpaqueEffect.FogColor = Color.CornflowerBlue.ToVector3();
            OpaqueEffect.VertexColorEnabled = true;

            TransparentEffect = new AlphaTestEffect(Game.GraphicsDevice);
            TransparentEffect.AlphaFunction = CompareFunction.Greater;
            TransparentEffect.ReferenceAlpha = 127;
            TransparentEffect.Texture = Game.TextureMapper.GetTexture("terrain.png");
            TransparentEffect.VertexColorEnabled = true;

            ChunkMeshes = new List<ChunkMesh>();
            IncomingChunks = new ConcurrentBag<Mesh>();
            ActiveMeshes = new HashSet<Coordinates2D>();
        }
Пример #31
0
 public override void ApplyEffects(Microsoft.Xna.Framework.Graphics.BasicEffect effect)
 {
     //
 }