Пример #1
0
        public void ApplyLight(BasicEffect Effect, Vector3 MeshPosition)
        {
            CreateWorld();

            if (Basic)
            {
                Effect.EnableDefaultLighting();
                return;
            }

            Vector3 Direction = Position - MeshPosition;

            Effect.LightingEnabled = true;                          // Turn on the lighting subsystem.

            Effect.DirectionalLight0.DiffuseColor  = DiffuseColor;  // a reddish light
            Effect.DirectionalLight0.Direction     = Direction;     // coming along the x-axis
            Effect.DirectionalLight0.SpecularColor = SpecularColor; // with green highlights

            Effect.AmbientLightColor = AmbientLightColor;           // Add some overall ambient light.
            Effect.EmissiveColor     = EmissiveColor;               // Sets some strange emmissive lighting.  This just looks weird.
        }
Пример #2
0
        public override void Draw(GameTime gameTime, Camera camera, Matrix parentTransform)
        {
            BasicEffect.World      = World;
            BasicEffect.View       = camera.View;
            BasicEffect.Projection = camera.Projection;
            BasicEffect.EnableDefaultLighting();

            foreach (EffectPass pass in BasicEffect.CurrentTechnique.Passes)
            {
                pass.Apply();
                BasicEffect.GraphicsDevice.DrawUserIndexedPrimitives <VertexPositionNormalTexture>(
                    PrimitiveType.TriangleList, // primitive type
                    Vertices,                   // vertex data
                    0, Vertices.Length,         // indices offset
                    Indices,                    // number of vertices
                    0,                          // index data
                    Indices.Length / 3);        // number of primitives(in this case: triangles)
            }

            base.Draw(gameTime, camera, parentTransform);
        }
Пример #3
0
            public void Draw(Camera camera)
            {
                _effect.EnableDefaultLighting();
                _effect.World          = Matrix.Identity;
                _effect.View           = camera.View;
                _effect.Projection     = camera.Projection;
                _effect.TextureEnabled = true;
                _effect.Texture        = _texture;
                _effect.Alpha          = _transparency;

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

                    _cd.GraphicsDevice.DrawUserIndexedPrimitives
                    <VertexPositionNormalTexture>(
                        PrimitiveType.TriangleList,
                        _vertices, 0, 4,
                        _indices, 0, 2);
                }
            }
Пример #4
0
        public void Draw(Matrix View, Matrix Projection)
        {
            Matrix baseWorld = Matrix.CreateScale(Scale) *
                               Matrix.CreateFromYawPitchRoll(Rotation.Y, Rotation.X, Rotation.Z) *
                               Matrix.CreateTranslation(Position);

            foreach (ModelMesh mesh in Model.Meshes)
            {
                Matrix localWorld = modelTransforms[mesh.ParentBone.Index] * baseWorld;
                foreach (ModelMeshPart meshPart in mesh.MeshParts)
                {
                    BasicEffect effect = (BasicEffect)meshPart.Effect;
                    effect.World      = localWorld;
                    effect.View       = View;
                    effect.Projection = Projection;

                    effect.EnableDefaultLighting();
                }
                mesh.Draw();
            }
        }
Пример #5
0
        public void draw()
        {
            BasicEffect effect = new BasicEffect(game.GraphicsDevice);

            effect.TextureEnabled = true;
            effect.Texture        = terrainTexture;
            effect.EnableDefaultLighting();

            effect.World      = Matrix.CreateScale(scale) * Matrix.CreateFromQuaternion(orientation) * Matrix.CreateTranslation(position);
            effect.View       = game.camera.view;
            effect.Projection = game.camera.projection;

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

                game.GraphicsDevice.Indices = myIndexBuffer;
                game.GraphicsDevice.SetVertexBuffer(myVertexBuffer);
                game.GraphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, vertices.Length, 0, indices.Length / 3);
            }
        }
Пример #6
0
        // Constructor for the player as the shooter
        public Projectile(ProjectGame game, string model_name, Vector3 pos, float velocity, Enemy target, GameObjectType targetType)
        {
            this.game       = game;
            this.pos        = pos;
            this.velocity   = velocity;
            this.target     = target;
            this.targetType = targetType;
            hitRadius       = 5;
            squareHitRadius = hitRadius * hitRadius;
            collisionRadius = squareHitRadius;
            scaling         = 1.5f;

            model       = game.Content.Load <Model>(model_name);
            basicEffect = new BasicEffect(game.GraphicsDevice)
            {
                World      = Matrix.Identity,
                View       = game.camera.View,
                Projection = game.camera.Projection
            };
            BasicEffect.EnableDefaultLighting(model, true);
        }
        public Renderer(GameObject parent, GraphicsDevice graphicsDevice, bool opaque)
            : base(parent)
        {
            if (view == null)
            {
                CalcViewProjMatricies();
            }

            animated = Animation != null ? true : false;

            this.graphicsDevice = graphicsDevice;
            isFlipped           = false;
            flipEffect          = SpriteEffects.None;

            if (animated)
            {
                AnimatedInit();
            }
            else
            {
                StaticInit();
            }

            if (opaque)
            {
                RenderManager.Instance.AddOpaque(this);
            }
            else
            {
                RenderManager.Instance.AddTransparent(this);
            }

            if (shader == null)
            {
                shader = new BasicEffect(graphicsDevice);
                shader.EnableDefaultLighting();
                shader.TextureEnabled  = true;
                shader.LightingEnabled = true;
            }
        }
Пример #8
0
        protected override void Draw(GameTime gameTime)
        {
            device.Clear(ClearOptions.Target | ClearOptions.DepthBuffer, Color.CornflowerBlue, 1, 0);

            cCross.Draw(fpsCam.ViewMatrix, fpsCam.ProjectionMatrix);

            //draw terrain
            int width  = heightData.GetLength(0);
            int height = heightData.GetLength(1);

            basicEffect.World          = Matrix.Identity;
            basicEffect.View           = fpsCam.ViewMatrix;
            basicEffect.Projection     = fpsCam.ProjectionMatrix;
            basicEffect.Texture        = grassTexture;
            basicEffect.TextureEnabled = true;

            basicEffect.EnableDefaultLighting();
            basicEffect.DirectionalLight0.Direction = new Vector3(1, -1, 1);
            basicEffect.DirectionalLight0.Enabled   = true;
            basicEffect.AmbientLightColor           = new Vector3(0.3f, 0.3f, 0.3f);
            basicEffect.DirectionalLight1.Enabled   = false;
            basicEffect.DirectionalLight2.Enabled   = false;
            basicEffect.SpecularColor = new Vector3(0, 0, 0);

            basicEffect.Begin();
            foreach (EffectPass pass in basicEffect.CurrentTechnique.Passes)
            {
                pass.Begin();

                device.Vertices[0].SetSource(terrainVertexBuffer, 0, VertexPositionNormalTexture.SizeInBytes);
                device.Indices           = terrainIndexBuffer;
                device.VertexDeclaration = myVertexDeclaration;
                device.DrawIndexedPrimitives(PrimitiveType.TriangleStrip, 0, 0, width * height, 0, width * 2 * (height - 1) - 2);

                pass.End();
            }
            basicEffect.End();

            base.Draw(gameTime);
        }
Пример #9
0
        /// <summary>
        /// 如同上面的update
        /// 这个render函数只是将顶点绘制出来,并不需要特定的Effect
        /// 而且在WP7中也是不支持的
        /// WP7中一切都只能用cpu处理
        /// </summary>
        /// <param name="world"></param>
        /// <param name="view"></param>
        /// <param name="proj"></param>
        public void Render(Matrix world, Matrix view, Matrix proj)
        {
            //基本参数设定
            effect.World      = world;
            effect.View       = view;
            effect.Projection = proj;
            //这个并没有多大的作用,应该要disable掉
            effect.EnableDefaultLighting();

            //Miku Model不同于其他一般的Model,他的顺序是倒过来的
            device.RasterizerState = RasterizerState.CullClockwise;
            int currentFaceVertexIndex = 0;

            foreach (EffectPass pass in effect.CurrentTechnique.Passes)
            {
                for (int i = 0; i < materials.Length; i++)
                {
                    //基本参数设计
                    effect.DiffuseColor      = materials[i].Diffuse;
                    effect.Alpha             = materials[i].Alpha;
                    effect.SpecularPower     = materials[i].Shininess;
                    effect.SpecularColor     = materials[i].Specular;
                    effect.AmbientLightColor = materials[i].Ambient;
                    //mmd很多部分都是没有纹理的,都是使用ambient Color和diffuseColor就实现的
                    //很不可思议
                    effect.TextureEnabled = false;
                    if (!string.IsNullOrEmpty(materials[i].Name))
                    {
                        effect.TextureEnabled = true;
                        effect.Texture        = Content.Load <Texture2D>(materials[i].Name.Split('.')[0]);
                    }
                    //每一个Material负责一段vertices
                    pass.Apply();
                    device.DrawUserIndexedPrimitives(PrimitiveType.TriangleList, verticesOnly, 0, verticesOnly.Length, indices, currentFaceVertexIndex, materials[i].FaceVertexCount / 3);
                    //切换到下一个material
                    currentFaceVertexIndex += materials[i].FaceVertexCount;
                }
            }
            device.RasterizerState = RasterizerState.CullCounterClockwise;
        }
Пример #10
0
        public void Draw(GraphicsDevice device)
        {
            device.RenderState.CullMode = CullMode.CullClockwiseFace;

            m_TerrainEffect.TextureEnabled = true;
            m_TerrainEffect.Texture        = m_Texture;

            //조명 효과
            m_TerrainEffect.EnableDefaultLighting();
            m_TerrainEffect.DirectionalLight0.Direction = new Vector3(0.0f, 0.4f, 0.3f);
            m_TerrainEffect.SpecularColor = new Vector3(0.4f, 0.4f, 0.4f);
            m_TerrainEffect.SpecularPower = 8;

            //안개 효과
            m_TerrainEffect.FogEnabled = false;
            m_TerrainEffect.FogColor   = new Vector3(0.15f);
            m_TerrainEffect.FogStart   = 100;
            m_TerrainEffect.FogEnd     = 120;

            m_TerrainEffect.Begin();

            foreach (EffectPass pass in m_TerrainEffect.CurrentTechnique.Passes) // Technique는 Pass를 여러개 가질 수 있습니다. (MultiPass)
            {
                pass.Begin();

                // scene은 반드시 이 사이에 와야 합니다.
                device.Vertices[0].SetSource(m_VertexBuffer, 0, VertexPositionNormalTexture.SizeInBytes);
                device.Indices           = m_IndexBuffer;
                device.VertexDeclaration = new VertexDeclaration(device, VertexPositionNormalTexture.VertexElements);                                    // vertex의 속성을 설정
                device.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, (int)(m_Width * m_Height), 0, (int)((m_Width - 1) * (m_Height - 1) * 2)); // Draw.

                pass.End();
            }

            m_TerrainEffect.End();


            // 비행기 렌더링을 위해서, CullMode를 원상복귀 시킴
            device.RenderState.CullMode = CullMode.CullCounterClockwiseFace;
        }
Пример #11
0
        public void Draw(Matrix view, Matrix projection)
        {
            Matrix baseWorld = Matrix.CreateScale(Scale)
                               * Matrix.CreateFromYawPitchRoll(Rotation.Y, Rotation.X, Rotation.Z)
                               * Matrix.CreateTranslation(Position);

            int i = 0;

            foreach (ModelMesh mesh in model.Meshes)
            {
                if (_hiddenMeshs.Contains(i++))
                {
                    continue;
                }
                Matrix localWorld = modelTransforms[mesh.ParentBone.Index] * baseWorld;
                foreach (ModelMeshPart meshPart in mesh.MeshParts)
                {
                    BasicEffect effect = (BasicEffect)meshPart.Effect;
                    effect.World      = localWorld;
                    effect.View       = view;
                    effect.Projection = projection;
                    if (Alpha < 1)
                    {
                        effect.Alpha = Alpha;
                    }
                    if (CustomTexture != null)
                    {
                        effect.Texture = CustomTexture;
                    }
                    effect.EnableDefaultLighting();
                    if (_dim)
                    {
                        effect.DirectionalLight0.Direction = new Vector3(0.3f, 0, 0.3f);
                        effect.DirectionalLight1.Direction = new Vector3(-0.3f, 0, -0.3f);
                        effect.DirectionalLight2.Enabled   = false;
                    }
                }
                mesh.Draw();
            }
        }
        static Dictionary <string, Texture2D> textures; // helps to store textures only once and get desired texture based on associated object's texture-file-name



        // CONSTRUCT
        public Basic3DObjects(GraphicsDevice GPU, Vector3 UpDirection, ContentManager content) //, Light new_light)
        {
            gpu          = GPU;
            world        = Matrix.Identity;
            basic_effect = new BasicEffect(gpu); //light = new_light;     // <-- TO DO LATER ([if you want] instead of basic_effect)
            verts        = new VertexPositionNormalTexture[65535];
            indices      = new ushort[65535];    // 64K indices for basic objects should be plenty
            Content      = content;
            upDirection  = UpDirection;
            textures     = new Dictionary <string, Texture2D>();
            vertexBuffer = new VertexBuffer(gpu, typeof(VertexPositionNormalTexture), 65535, BufferUsage.WriteOnly);
            indexBuffer  = new IndexBuffer(gpu, typeof(ushort), 65535, BufferUsage.WriteOnly);
            objex        = new List <Obj3D>();

            // I N I T:
            basic_effect.Alpha             = 1f;                               // I think this is default anyway (transparency)
            basic_effect.LightingEnabled   = true;                             // vertex type needs normals for this to work (which we have)
            basic_effect.AmbientLightColor = new Vector3(0.1f, 0.2f, 0.3f);    // medium-dark for dark parts of object
            basic_effect.DiffuseColor      = new Vector3(0.94f, 0.94f, 0.94f); // fairly bright for lit parts of object
            basic_effect.EnableDefaultLighting();                              // make sure lighting is on
            basic_effect.TextureEnabled = true;                                // make sure this is enabled
        }
Пример #13
0
        private static Dictionary <string, Texture2D> _textures; // helps to store textures only once and get desired texture based on associated object's texture-file-name

        // CONSTRUCTOR
        public Basic3DObjects(GraphicsDevice graphicsDevice, Vector3 upDirection, ContentManager content)
        {
            _graphicsDevice = graphicsDevice;
            _world          = Matrix.Identity;
            _basicEffect    = new BasicEffect(_graphicsDevice);
            _verts          = new VertexPositionNormalTexture[65535];
            _indices        = new ushort[65535];
            _content        = content;
            _upDirection    = upDirection;
            _textures       = new Dictionary <string, Texture2D>();
            _indexBuffer    = new IndexBuffer(_graphicsDevice, typeof(ushort), 65535, BufferUsage.WriteOnly);
            _vertexBuffer   = new VertexBuffer(_graphicsDevice, typeof(VertexPositionNormalTexture), 65535, BufferUsage.WriteOnly);
            Objects         = new List <Object3D>();

            // INIT
            _basicEffect.Alpha             = 1f;                               // I think this is default anyway (transparency)
            _basicEffect.LightingEnabled   = true;                             // vertex type needs normals for this to work (which we have)
            _basicEffect.AmbientLightColor = new Vector3(0.1f, 0.2f, 0.3f);    // medium-dark for dark parts of object
            _basicEffect.DiffuseColor      = new Vector3(0.94f, 0.94f, 0.94f); // fairly bright for lit parts of object
            _basicEffect.EnableDefaultLighting();                              // make sure lighting is on
            _basicEffect.TextureEnabled = true;                                // make sure this is enabled
        }
Пример #14
0
        // Constructor with the enemy as the shooter
        public Projectile(ProjectGame game, Enemy shooter, Vector3 pos, float velocity, Vector3 targetPos, GameObjectType targetType)
        {
            this.game       = game;
            this.shooter    = shooter;
            this.pos        = pos;
            this.velocity   = velocity;
            this.targetPos  = targetPos;
            this.targetType = targetType;
            squareHitRadius = hitRadius * hitRadius;
            collisionRadius = squareHitRadius;
            isTargetPlayer  = true;
            scaling         = 8;

            model       = game.Content.Load <Model>("Sphere");
            basicEffect = new BasicEffect(game.GraphicsDevice)
            {
                World      = Matrix.Identity,
                View       = game.camera.View,
                Projection = game.camera.Projection
            };
            BasicEffect.EnableDefaultLighting(model, true);
        }
        protected override void LoadContent()
        {
            base.LoadContent();

            quad       = new Quad(Vector3.Zero, Vector3.Backward, Vector3.Up, 1, 1);
            View       = Matrix.CreateLookAt(new Vector3(0, 0, 2), Vector3.Zero, Vector3.Up);
            Projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.PiOver4, 4.0f / 3.0f, 1, 500);

            texture    = Game.Content.Load <Texture2D>(Paths.Texture("GlassPane"));
            quadEffect = new BasicEffect(GraphicsDevice);

            if (enableLighting)
            {
                quadEffect.EnableDefaultLighting();
            }

            quadEffect.World          = Matrix.Identity;
            quadEffect.View           = View;
            quadEffect.Projection     = Projection;
            quadEffect.TextureEnabled = true;
            quadEffect.Texture        = texture;
        }
Пример #16
0
        public void Draw(Matrix View, Matrix Projection)
        {
            baseworld = Matrix.CreateScale(Scale) *
                        Matrix.CreateFromQuaternion(Rotation) *
                        Matrix.CreateTranslation(Position);

            Model.CopyAbsoluteBoneTransformsTo(modelTransforms);
            foreach (ModelMesh mesh in Model.Meshes)
            {
                Matrix localWorld = modelTransforms[mesh.ParentBone.Index] * baseworld;
                foreach (ModelMeshPart meshPart in mesh.MeshParts)
                {
                    BasicEffect effect = (BasicEffect)meshPart.Effect;
                    effect.World      = localWorld;
                    effect.View       = View;
                    effect.Projection = Projection;

                    effect.EnableDefaultLighting();
                }
                mesh.Draw();
            }
        }
Пример #17
0
        /// <summary>
        /// Once all the geometry has been specified by calling AddVertex and AddIndex,
        /// this method copies the vertex and index data into GPU format buffers, ready
        /// for efficient rendering.
        protected virtual void InitializePrimitive()
        {
            // Create a vertex declaration, describing the format of our vertex data.

            InitializeVertexBuffer(GraphicsDevice);

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

            indexBuffer.SetData(indices.ToArray());

            // Create a BasicEffect, which will be used to render the primitive.
            basicEffect = new BasicEffect(GraphicsDevice);

            basicEffect.EnableDefaultLighting();
            basicEffect.TextureEnabled         = true;
            basicEffect.Texture                = Texture;
            basicEffect.PreferPerPixelLighting = false;
            basicEffect.VertexColorEnabled     = false;
            GraphicsDevice.SamplerStates[0]    = SamplerState.PointClamp;
        }
Пример #18
0
 public Sphere(Matrix transform, Color color, int numVertices, Vector3 Scalar, Vector3 Position, Vector3 RotationAxisSpeed, Vector3 RotationRadiansSpeed)
 {
     this.Transform   = transform;
     this.color       = color;
     this.numVertices = numVertices;
     graphics         = SimPhyGameWorld.World.GraphicsDevice;
     effect           = new BasicEffect(SimPhyGameWorld.Graphics);
     effect.EnableDefaultLighting();
     nvertices = numVertices * numVertices;
     nindices  = numVertices * numVertices * 6;
     vbuffer   = new VertexBuffer(graphics, typeof(VertexPositionColorNormal), nvertices, BufferUsage.WriteOnly);
     ibuffer   = new IndexBuffer(graphics, IndexElementSize.SixteenBits, nindices, BufferUsage.WriteOnly);
     createVertices();
     createIndices();
     vbuffer.SetData <VertexPositionColorNormal>(vertices);
     ibuffer.SetData <short>(indices);
     effect.VertexColorEnabled = true;
     this.scalar               = Scalar;
     this.position             = Position;
     this.rotationAxisSpeed    = RotationAxisSpeed;
     this.rotationRadiansSpeed = RotationRadiansSpeed;
 }
Пример #19
0
        /// <summary>
        /// Once all the geometry has been specified by calling AddVertex and AddIndex,
        /// this method copies the vertex and index data into GPU format buffers, ready
        /// for efficient rendering.
        protected void InitializePrimitive(GraphicsDevice graphicsDevice)
        {
            // Create a vertex declaration, describing the format of our vertex data.

            // Create a vertex buffer, and copy our vertex data into it.
            vertexBuffer = new VertexBuffer(graphicsDevice,
                                            typeof(VertexPositionNormal),
                                            vertices.Count, BufferUsage.None);

            vertexBuffer.SetData(vertices.ToArray());

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

            indexBuffer.SetData(indices.ToArray());

            // Create a BasicEffect, which will be used to render the primitive.
            basicEffect = new BasicEffect(graphicsDevice);

            basicEffect.EnableDefaultLighting();
        }
Пример #20
0
        /// <summary>
        /// Initializes the control.
        /// </summary>
        protected override void Initialize()
        {
            content = new ContentManager(Services, "Content");

            // Hook the idle event to constantly redraw our animation.
            Application.Idle += delegate { Invalidate(); };

            this.monsterTexture = content.Load <Texture2D>(@"mineplayer");
            this.grassTexture   = content.Load <Texture2D>(@"grass");

            this.SetupViewport();

            quad       = new Quad(Vector3.Zero, Vector3.Backward, Vector3.Up, 2, 2);
            quadEffect = new BasicEffect(this.GraphicsDevice);
            quadEffect.EnableDefaultLighting();

            quadEffect.World          = this.World;
            quadEffect.View           = this.View;
            quadEffect.Projection     = this.Projection;
            quadEffect.TextureEnabled = true;
            quadEffect.Texture        = grassTexture;
        }
Пример #21
0
        static Dictionary <string, Texture2D> textures;         // helps to store textures only once and get desired texture based on associated object's texture-file-name

        // Constructor
        public Basic3DObjects(GraphicsDevice GPU, Vector3 UpDirection, ContentManager content) //, Light new_light)
        {
            gpu          = GPU;
            world        = Matrix.Identity;
            basic_effect = new BasicEffect(gpu);                   // light = new_light <-- TO DO LATER [if you want instead of basic_effect)
            verts        = new VertexPositionNormalTexture[65535]; //
            indices      = new ushort[65535];                      // 64K indices for basic objects, you won't need more than this
            Content      = content;
            upDirection  = UpDirection;
            textures     = new Dictionary <string, Texture2D>();
            vertexBuffer = new VertexBuffer(gpu, typeof(VertexPositionNormalTexture), 65535, BufferUsage.WriteOnly);
            indexBuffer  = new IndexBuffer(gpu, typeof(ushort), 65535, BufferUsage.WriteOnly);
            objex        = new List <Obj3D>();

            // Init
            basic_effect.Alpha             = 1;                                // Transparency
            basic_effect.LightingEnabled   = true;                             // Enables lighting
            basic_effect.AmbientLightColor = new Vector3(0.1f, 0.2f, 0.3f);    // medium dark for dark parts of object
            basic_effect.DiffuseColor      = new Vector3(0.94f, 0.94f, 0.94f); // pretty bright for lit parts of object
            basic_effect.EnableDefaultLighting();                              // Lighting is on
            basic_effect.TextureEnabled = true;                                // Enables textures
        }
Пример #22
0
        public override void Draw(GameTime gameTime)
        {
            BasicEffect    effect = ((Game1)Game).effect;
            Camera         camera = ((Game1)Game).camera;
            GraphicsDevice gd     = ((Game1)Game).GraphicsDevice;

            VertexBuffer vertexBuffer = new VertexBuffer(gd, typeof(VertexPositionNormalTexture), vpc.Length, BufferUsage.None);

            vertexBuffer.SetData(vpc);    //Put verts data into vertexBuffer

            IndexBuffer indexBuffer = new IndexBuffer(gd, IndexElementSize.SixteenBits, sizeof(short) * indices.Length, BufferUsage.None);

            indexBuffer.SetData(indices);


            gd.Indices = indexBuffer;
            gd.SetVertexBuffer(vertexBuffer);   //Choose buffer

            effect.World      = parent;
            effect.View       = camera.view;
            effect.Projection = camera.projection;

            effect.VertexColorEnabled = false;

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

            effect.EnableDefaultLighting();
            effect.LightingEnabled = true;

            //Iterate over every operation
            foreach (EffectPass pass in effect.CurrentTechnique.Passes)
            {
                pass.Apply();
                gd.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, vpc.Length, 0, indices.Length / 3);
            }

            base.Draw(gameTime);
        }
        public void SetDescription(XNABasicShaderDescription desc)
        {
            this.desc = desc;
            if (desc.DefaultLightning)
            {
                effect.EnableDefaultLighting();
            }
            else
            {
                if (effect.LightingEnabled)
                {
                    effect.LightingEnabled   = true;
                    effect.SpecularColor     = desc.SpecularColor;
                    effect.SpecularPower     = desc.SpecularPower;
                    effect.EmissiveColor     = desc.EmissiveColor;
                    effect.AmbientLightColor = desc.AmbientColor;
                }
            }

            effect.TextureEnabled = desc.EnableTexture;
            effect.Alpha          = desc.alpha;
        }
Пример #24
0
        public static void Draw(this Model model, Matrix World, Matrix View, Matrix Projection)
        {
            Matrix[] bones = model.GetAboluteBoneTransforms();

            foreach (ModelMesh mesh in model.Meshes)
            {
                for (int x = 0; x < mesh.Effects.Count; x++)
                {
                    BasicEffect eff = mesh.Effects[x] as BasicEffect;
                    if (eff != null)
                    {
                        eff.World      = bones[mesh.ParentBone.Index] * World;
                        eff.View       = View;
                        eff.Projection = Projection;

                        eff.EnableDefaultLighting();
                        eff.TextureEnabled = true;
                    }
                }
                mesh.Draw();
            }
        }
Пример #25
0
        public void Draw(Matrix worldMatrix, Matrix viewMatrix, Matrix projectionMatrix)
        {
            int width  = heightData.GetLength(0);
            int height = heightData.GetLength(1);

            GraphicsDevice device = terrainVertexBuffer.GraphicsDevice;

            //draw terrain
            basicEffect.World          = worldMatrix;
            basicEffect.View           = viewMatrix;
            basicEffect.Projection     = projectionMatrix;
            basicEffect.Texture        = grassTexture;
            basicEffect.TextureEnabled = true;

            basicEffect.EnableDefaultLighting();
            Vector3 lightDirection = new Vector3(1, -1, 1);

            lightDirection.Normalize();
            basicEffect.DirectionalLight0.Direction = lightDirection;
            basicEffect.DirectionalLight0.Enabled   = true;
            basicEffect.AmbientLightColor           = new Vector3(0.3f, 0.3f, 0.3f);
            basicEffect.DirectionalLight1.Enabled   = false;
            basicEffect.DirectionalLight2.Enabled   = false;
            basicEffect.SpecularColor = new Vector3(0, 0, 0);

            basicEffect.Begin();
            foreach (EffectPass pass in basicEffect.CurrentTechnique.Passes)
            {
                pass.Begin();

                device.Vertices[0].SetSource(terrainVertexBuffer, 0, VertexPositionNormalTexture.SizeInBytes);
                device.Indices           = terrainIndexBuffer;
                device.VertexDeclaration = terrainVertexDeclaration;
                device.DrawIndexedPrimitives(PrimitiveType.TriangleStrip, 0, 0, width * height, 0, width * 2 * (height - 1) - 2);

                pass.End();
            }
            basicEffect.End();
        }
Пример #26
0
        protected override void LoadContent()
        {
            // Creates a basic effect
            basicEffect = ToDisposeContent(new BasicEffect(GraphicsDevice)
            {
                View       = Matrix.LookAtRH(new Vector3(0, 0, 5), new Vector3(0, 0, 0), Vector3.UnitY),
                Projection = Matrix.PerspectiveFovRH((float)Math.PI / 4.0f, (float)GraphicsDevice.BackBuffer.Width / GraphicsDevice.BackBuffer.Height, 0.1f, 100.0f),
                World      = Matrix.Identity
            });

            basicEffect.PreferPerPixelLighting = true;
            basicEffect.EnableDefaultLighting();

            // Creates all primitives
            primitives = new List <GeometricPrimitive>
            {
                ToDisposeContent(GeometricPrimitive.Plane.New(GraphicsDevice)),
                ToDisposeContent(GeometricPrimitive.Cube.New(GraphicsDevice)),
                ToDisposeContent(GeometricPrimitive.Sphere.New(GraphicsDevice)),
                ToDisposeContent(GeometricPrimitive.GeoSphere.New(GraphicsDevice)),
                ToDisposeContent(GeometricPrimitive.Cylinder.New(GraphicsDevice)),
                ToDisposeContent(GeometricPrimitive.Torus.New(GraphicsDevice)),
                ToDisposeContent(GeometricPrimitive.Teapot.New(GraphicsDevice))
            };

            // Load a SpriteFont
            arial16BMFont = Content.Load <SpriteFont>("Arial16");

            // Instantiate a SpriteBatch
            spriteBatch = new SpriteBatch(GraphicsDevice);

            // Load the texture
            texture                    = Content.Load <Texture2D>("GeneticaMortarlessBlocks");
            basicEffect.Texture        = texture;
            basicEffect.TextureEnabled = true;

            base.LoadContent();
        }
Пример #27
0
        /// <summary>
        /// Creates a new flat object.
        /// </summary>
        /// <param name="position">Position of the object</param>
        /// <param name="azimuth">Azimuth</param>
        /// <param name="size">Size (width, lenght)</param>
        /// <param name="texture">Used texture</param>
        public FlatObject(PositionInTown position, double azimuth, Vector2 size, Texture2D texture)
            : base(position, azimuth, size)
        {
            this.texture = texture;
            vertices     = new VertexPositionNormalTexture[4];
            indexes      = new short[6];

            Vector2 textureUpperLeft  = new Vector2(0.0f, 0.0f);
            Vector2 textureUpperRight = new Vector2(1.0f, 0.0f);
            Vector2 textureLowerLeft  = new Vector2(0.0f, 1.0f);
            Vector2 textureLowerRight = new Vector2(1.0f, 1.0f);

            for (int i = 0; i < vertices.Length; i++)
            {
                vertices[i].Normal = Vector3.Up;
            }

            vertices[0].Position          = LowerLeftCorner.ToVector3(verticalPosition);
            vertices[0].TextureCoordinate = textureLowerLeft;
            vertices[1].Position          = UpperLeftCorner.ToVector3(verticalPosition);
            vertices[1].TextureCoordinate = textureUpperLeft;
            vertices[2].Position          = LowerRightCorner.ToVector3(verticalPosition);
            vertices[2].TextureCoordinate = textureLowerRight;
            vertices[3].Position          = UpperRightCorner.ToVector3(verticalPosition);
            vertices[3].TextureCoordinate = textureUpperRight;

            indexes[0] = 0;
            indexes[1] = 1;
            indexes[2] = 2;
            indexes[3] = 2;
            indexes[4] = 1;
            indexes[5] = 3;

            quadEffect = new BasicEffect(texture.GraphicsDevice);
            quadEffect.EnableDefaultLighting();
            quadEffect.TextureEnabled = true;
            quadEffect.Texture        = texture;
        }
Пример #28
0
        /// <summary>
        /// This is called when the game should draw itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Draw(GameTime gameTime)
        {
            graphics.GraphicsDevice.RasterizerState = RasterizerState.CullNone;

            graphics.GraphicsDevice.Clear(Color.CornflowerBlue);

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

            effect.EnableDefaultLighting();

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

            Matrix world = Matrix.CreateTranslation(new Vector3(3.0f, 0, -10.0f));

            DrawRectangle(ref world);

            world = Matrix.CreateScale(0.75f) *
                    Matrix.CreateRotationX(MathHelper.ToRadians(15.0f)) *
                    Matrix.CreateRotationY(MathHelper.ToRadians(30.0f)) *
                    Matrix.CreateTranslation(new Vector3(-3.0f, -1.0f, -5.0f));

            DrawRectangle(ref world);

            world = Matrix.CreateTranslation(new Vector3(8.0f, 0, -10.0f));
            DrawRectangle(ref world);

            world = Matrix.CreateTranslation(new Vector3(8.0f, 0, -6.0f));
            DrawRectangle(ref world);

            world = Matrix.CreateRotationY(MathHelper.ToRadians(180f)) *
                    Matrix.CreateTranslation(new Vector3(3.0f, 0, 10.0f));

            DrawRectangle(ref world);

            base.Draw(gameTime);
        }
Пример #29
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()
        {
            // Calculate the screen aspect ratio
            float aspectRatio = (float)GraphicsDevice.Viewport.Width / GraphicsDevice.Viewport.Height;
            // Create a projection matrix
            Matrix projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(45), aspectRatio, 0.1f, 50.0f);

            // Calculate a view matrix (where we are looking from and to)
            Matrix view = Matrix.CreateLookAt(new Vector3(0, 5, 5), new Vector3(0, 0, 0), new Vector3(0, 1, 0));

            // Create and initialize the effect
            _effect = new BasicEffect(GraphicsDevice);
            _effect.VertexColorEnabled = false;
            _effect.TextureEnabled     = true;
            _effect.Projection         = projection;
            _effect.View            = view;
            _effect.World           = Matrix.Identity;
            _effect.LightingEnabled = true;
            _effect.EnableDefaultLighting();
            //_effect.DirectionalLight0.Enabled = true;
            //_effect.DirectionalLight0.Direction = new Vector3(0, 0, -1);
            //_effect.DirectionalLight0.DiffuseColor = Color.White.ToVector3();
            //_effect.DirectionalLight0.SpecularColor = Color.White.ToVector3();

            // Configure the fog
            _effect.FogEnabled = true;
            _effect.FogStart   = 3.0f;
            _effect.FogEnd     = 20.0f;
            _effect.FogColor   = Color.LightGray.ToVector3();

            // Use the fog to create a silhouette instead
            //_effect.FogEnabled = true;
            //_effect.FogStart = 0.0f;
            //_effect.FogEnd = 0.0f;
            //_effect.FogColor = Color.Black.ToVector3();

            base.Initialize();
        }
        private void DrawCurrentNode(Matrix worldMatrix, Matrix viewMatrix, Matrix projectionMatrix)
        {
            //device.RenderState.CullMode = CullMode.CullCounterClockwiseFace;
            //device.RenderState.FillMode = FillMode.WireFrame;

            NodesRendered++;

            basicEffect.World              = worldMatrix;
            basicEffect.View               = viewMatrix;
            basicEffect.Projection         = projectionMatrix;
            basicEffect.Texture            = grassTexture;
            basicEffect.VertexColorEnabled = false;
            basicEffect.TextureEnabled     = true;

            basicEffect.EnableDefaultLighting();
            basicEffect.DirectionalLight0.Direction = new Vector3(1, -1, 1);
            basicEffect.DirectionalLight0.Enabled   = true;
            basicEffect.AmbientLightColor           = new Vector3(0.3f, 0.3f, 0.3f);
            basicEffect.DirectionalLight1.Enabled   = false;
            basicEffect.DirectionalLight2.Enabled   = false;
            basicEffect.SpecularColor = new Vector3(0, 0, 0);

            basicEffect.Begin();
            foreach (EffectPass pass in basicEffect.CurrentTechnique.Passes)
            {
                pass.Begin();

                device.Vertices[0].SetSource(nodeVertexBuffer, 0, VertexPositionNormalTexture.SizeInBytes);
                device.Indices           = nodeIndexBuffer;
                device.VertexDeclaration = new VertexDeclaration(device, VertexPositionNormalTexture.VertexElements);
                device.DrawIndexedPrimitives(PrimitiveType.TriangleStrip, 0, 0, width * height, 0, (width * 2 * (height - 1) - 2));

                pass.End();
            }
            basicEffect.End();

            //XNAUtils.DrawBoundingBox(nodeBoundingBox, device, basicEffect, worldMatrix, viewMatrix, projectionMatrix);
        }
Пример #31
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 );
    }