⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 scenerygamecomponent.cs

📁 非常优秀的棋牌类游戏源码包含AI及机器的难度调节算法人工智能非常经典
💻 CS
📖 第 1 页 / 共 2 页
字号:
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Storage;
using CustomProcessors;

namespace SceneryComponent.Components
{
    /// <summary>
    /// Escenario
    /// </summary>
    public class SceneryGameComponent : DrawableGameComponent
    {
        /// <summary>
        /// V閞tice para multitextura
        /// </summary>
        public struct VertexMultitextured
        {
            /// <summary>
            /// Posici髇
            /// </summary>
            public Vector3 Position;
            /// <summary>
            /// Normal
            /// </summary>
            public Vector3 Normal;
            /// <summary>
            /// Coordenadas de Textura
            /// </summary>
            public Vector4 TextureCoordinate;
            /// <summary>
            /// Pesos de textura
            /// </summary>
            public Vector4 TexWeights;

            /// <summary>
            /// Tama駉 en bytes
            /// </summary>
            public static int SizeInBytes = (3 + 3 + 4 + 4) * 4;
            /// <summary>
            /// Elementos del v閞tice
            /// </summary>
            public static VertexElement[] VertexElements = new VertexElement[]
             {
                 new VertexElement( 0, 0, VertexElementFormat.Vector3, VertexElementMethod.Default, VertexElementUsage.Position, 0 ),
                 new VertexElement( 0, sizeof(float) * 3, VertexElementFormat.Vector3, VertexElementMethod.Default, VertexElementUsage.Normal, 0 ),
                 new VertexElement( 0, sizeof(float) * 6, VertexElementFormat.Vector4, VertexElementMethod.Default, VertexElementUsage.TextureCoordinate, 0 ),
                 new VertexElement( 0, sizeof(float) * 10, VertexElementFormat.Vector4, VertexElementMethod.Default, VertexElementUsage.TextureCoordinate, 1 ),
             };
        }

        /// <summary>
        /// Mapa de alturas
        /// </summary>
        public class HeightMap
        {
            /// <summary>
            /// Alturas
            /// </summary>
            public readonly float[,] Data;
            /// <summary>
            /// Altura m韓ima
            /// </summary>
            public readonly float Min;
            /// <summary>
            /// Altura m醲ima
            /// </summary>
            public readonly float Max;

            /// <summary>
            /// Anchura
            /// </summary>
            public int Width
            {
                get
                {
                    if (this.Data != null)
                    {
                        return this.Data.GetLength(0);
                    }

                    return 0;
                }
            }
            /// <summary>
            /// Profundidad
            /// </summary>
            public int Deep
            {
                get
                {
                    if (this.Data != null)
                    {
                        return this.Data.GetLength(1);
                    }

                    return 0;
                }
            }

            /// <summary>
            /// Constructor
            /// </summary>
            /// <param name="data">Mapa de alturas</param>
            public HeightMap(float[,] data)
            {
                this.Data = data;

                foreach (float height in data)
                {
                    if (height < Min)
                    {
                        Min = height;
                    }

                    if (height > Max)
                    {
                        Max = height;
                    }
                }
            }
        }

        // Contenidos
        private ContentManager content = null;
        // Efecto para renderizar
        private Effect m_Effect;

        // Declaraci髇 de los v閞tices
        private VertexDeclaration m_VertexDeclaration;
        // Buffer de v閞tices
        private VertexBuffer m_VertexBuffer = null;
        // Buffers de 韓dices
        Dictionary<LOD, IndexBuffer> m_LODIndexBuffers = new Dictionary<LOD, IndexBuffer>();
        // Cantidad total de v閞tices
        private int m_VertexCount = 0;
        // Cantidad total de v閞tices de ancho
        private int m_VertexCountX = 0;
        // Cantidad total de v閞tices de largo
        private int m_VertexCountZ = 0;

        // Nodo principal del escenario
        private SceneryNode m_Root = null;

        /// <summary>
        /// Obtiene la anchura del escenario
        /// </summary>
        public float Width
        {
            get
            {
                if (m_Root != null)
                {
                    Vector3 pointA = new Vector3(m_Root.BoundingBox.Min.X, 0.0f, 0.0f);
                    Vector3 pointB = new Vector3(m_Root.BoundingBox.Max.X, 0.0f, 0.0f);

                    return Vector3.Distance(pointA, pointB);
                }

                return 0.0f;
            }
        }
        /// <summary>
        /// Obtiene la largura del escenario
        /// </summary>
        public float Long
        {
            get
            {
                if (m_Root != null)
                {
                    Vector3 pointA = new Vector3(0.0f, 0.0f, m_Root.BoundingBox.Min.Z);
                    Vector3 pointB = new Vector3(0.0f, 0.0f, m_Root.BoundingBox.Max.Z);

                    return Vector3.Distance(pointA, pointB);
                }

                return 0.0f;
            }
        }
        /// <summary>
        /// Obtiene la altura del escenario
        /// </summary>
        public float Height
        {
            get
            {
                if (m_Root != null)
                {
                    Vector3 pointA = new Vector3(0.0f, m_Root.BoundingBox.Min.Y, 0.0f);
                    Vector3 pointB = new Vector3(0.0f, m_Root.BoundingBox.Max.Y, 0.0f);

                    return Vector3.Distance(pointA, pointB);
                }

                return 0.0f;
            }
        }

        /// <summary>
        /// Obtiene el l韒ite m韓imo de anchura
        /// </summary>
        public float MinWidth
        {
            get
            {
                if(m_Root != null)
                {
                    return m_Root.BoundingBox.Min.X;
                }

                return 0.0f;
            }
        }
        /// <summary>
        /// Obtiene el l韒ite m醲imo de anchura
        /// </summary>
        public float MaxWidth
        {
            get
            {
                if (m_Root != null)
                {
                    return m_Root.BoundingBox.Max.X;
                }

                return 0.0f;
            }
        }
        /// <summary>
        /// Obtiene el l韒ite m韓imo de profundidad
        /// </summary>
        public float MinLong
        {
            get
            {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -