示例#1
0
        /// <summary>
        /// Prepare a BasicEffect for rendering
        /// </summary>
        /// <param name="effect"></param>
        protected void PrepareEffect(BasicEffect effect)
        {
            // Do we have a texture? Set the effect as required
            if (ObjectTexture == null)
            {
                // No testure so disable texturing
                effect.TextureEnabled = false;
            }
            else
            {
                // Enable texturing and set the texture into the effect
                effect.TextureEnabled = true;
                if (ObjectTexture != effect.Texture)
                {
                    effect.Texture = ObjectTexture;
                }
            }

            // Set the color and alpha
            effect.DiffuseColor  = ObjectColor.ToVector3();
            effect.SpecularColor = SpecularColor.ToVector3();
            effect.SpecularPower = SpecularPower;
            effect.EmissiveColor = EmissiveColor.ToVector3();
            effect.Alpha         = (float)ObjectColor.A / 255.0f;

            // Apply the transformation matrix
            effect.World = Transformation;

            // Now the effect is ready for the derived class to actually draw the object
        }
        /// <summary>
        /// Prepare a BasicEffect for rendering
        /// </summary>
        /// <param name="effect"></param>
        protected void PrepareEffect(AlphaTestEffect effect)
        {
            if (effect.Texture != ObjectTexture)
            {
                effect.Texture = ObjectTexture;
            }

            // Set the color and alpha
            effect.DiffuseColor = ObjectColor.ToVector3();
            effect.Alpha        = (float)ObjectColor.A / 255.0f;

            // Apply the transformation matrix
            effect.World = Transformation;

            // Now the effect is ready for the derived class to actually draw the object
        }
        /// <summary>
        /// Prepare a BasicEffect for rendering
        /// </summary>
        /// <param name="effect"></param>
        protected void PrepareEffect(BasicEffect effect)
        {
            SetEffectTexture(effect, ObjectTexture);

            // Set the color and alpha
            effect.DiffuseColor  = ObjectColor.ToVector3();
            effect.SpecularColor = SpecularColor.ToVector3();
            effect.SpecularPower = SpecularPower;
            effect.EmissiveColor = EmissiveColor.ToVector3();
            effect.Alpha         = (float)ObjectColor.A / 255.0f;

            // Apply the transformation matrix
            effect.World = Transformation;

            // Now the effect is ready for the derived class to actually draw the object
        }
        /// <summary>
        /// Prepare a BasicEffect for rendering
        /// </summary>
        /// <param name="effect"></param>
        protected void PrepareEffect(EnvironmentMapEffect effect)
        {
            // Apply the texture if we have one and it differs from the active texture
            if (effect.Texture != ObjectTexture && ObjectTexture != null)
            {
                effect.Texture = ObjectTexture;
            }

            // Set the color and alpha
            effect.DiffuseColor  = ObjectColor.ToVector3();
            effect.EmissiveColor = EmissiveColor.ToVector3();
            effect.Alpha         = (float)ObjectColor.A / 255.0f;

            // Set other effect properties
            // Do we have a valid texture?
            if (effect.Texture != null)
            {
                // Yes, so apply the other environment map properties as normal
                effect.EnvironmentMapAmount   = EnvironmentMapAmount;
                effect.EnvironmentMapSpecular = EnvironmentMapSpecular.ToVector3();
                effect.FresnelFactor          = FresnelFactor;
            }
            else
            {
                // No, so make the object completely reflective.
                // Any texture set by other objects will remain but will be entirely hidden by the environment map
                effect.EnvironmentMapAmount   = 1.0f;
                effect.EnvironmentMapSpecular = Vector3.Zero;
                effect.FresnelFactor          = 0.0f;
            }

            // Apply the transformation matrix
            effect.World = Transformation;

            // Now the effect is ready for the derived class to actually draw the object
        }