बेसिकइफेक्ट लाइट्स

पेज अद्यतन :
पेज निर्माण की तारीख :

सारांश

मॉडल कैसे प्रदर्शित होता है, यह देखने के लिए BasicEffect के प्रकाश भाग से संबंधित मापदंडों में हेरफेर करें।

ऑपरेटिंग वातावरण

आवश्यकताएँ

समर्थित XNA संस्करण
  • 4.0
समर्थित प्लेटफार्म
  • विंडोज (एक्सपी एसपी 2 या बाद में, विस्टा, 7)
  • एक्सबॉक्स 360
  • विंडोज फोन 7
विंडोज आवश्यक वर्टेक्स शेडर संस्करण 2.0
विंडोज आवश्यक पिक्सेल शेडर संस्करण 2.0

ऑपरेटिंग वातावरण

प्लेटफार्म
  • विंडोज 7
  • एक्सबॉक्स 360
  • विंडोज फोन 7

नमूने के साथ कैसे काम करें

काम करता है कीबोर्डXbox 360 नियंत्रकमाउस स्पर्श
उन पैरामीटर्स का चयन करें जिन्हें आप परिवर्तित करना चाहते हैं ↑、↓ लेफ्ट स्टिक ↑, ↓ बायाँ बटन -
पैरामीटर बदलना ←、→ लेफ्ट स्टिक ←, → ←→ खींचें -

सार तत्व

प्रकाश

रोशनी का उपयोग किसी पदार्थ की छाया का प्रतिनिधित्व करने के लिए किया जाता है। XNA में, रोशनी को पर्यावरण सेटिंग्स में से एक के रूप में सेट नहीं किया जाता है, लेकिन व्यक्तिगत प्रभावों पर सेट किया जाता है।

बेसिकइफेक्ट में तीन समानांतर प्रकाश स्रोत उपलब्ध हैं, और प्रत्येक प्रकाश में निम्नलिखित पैरामीटर हैं:

सक्षम सेट करता है कि प्रकाश उपलब्ध है या नहीं।
डिफ्यूज़कलर प्रकाश का रंग। अंतिम रंग पदार्थ के रंग के साथ संयोजन करके आउटपुट होता है।
SpecularColor परावर्तित प्रकाश का रंग। यह पदार्थ के परावर्तक रंग को प्रभावित करता है।
दिशा प्रकाश की दिशा।

ऐसे गुण भी हैं जो व्यक्तिगत रोशनी के लिए सामान्य हैं।

परिवेशलाइटकलर प्रकाश स्रोत से स्वतंत्र रूप से पदार्थ की चमक सेट करता है।
PreferPerPixelLighting आप निर्दिष्ट कर सकते हैं कि प्रकाश की गणना पिक्सेल में की जाती है या नहीं।

प्रकाश परिवर्तन की छवि

नीचे दी गई छवि रोशनी के विभिन्न मूल्यों को दिखाती है। नमूने में, सभी तीन रोशनी सक्षम हैं, लेकिन नीचे की छवि में, इसे प्रदर्शित करने के लिए केवल एक प्रकाश का उपयोग किया जाता है।

प्रारंभिक अवस्था

नमूना मॉडल डेटा लोड करने के तुरंत बाद यह स्थिति है।

初期状態

फैलाना (लाल) 1
फैलाना (हरा) 0.96
डिफ्यूज़ (नीला) 0.80
स्पेक्युलर (लाल) 1
स्पेक्युलर (हरा) 0.96
स्पेक्युलर (ब्लू) 0.80
दिशा X -0.52
दिशा Y -0.57
दिशा Z -0.62
परिवेश प्रकाश रंग (लाल) 0.05
परिवेश प्रकाश रंग (हरा) 0.09
परिवेश LightColor (नीला) 0.18
PreferPerPixelLighting गलत

DiffuseColor संशोधन

प्रकाश के फैलाना रंग को बदलना। क्योंकि लाल और नीला 0 पर सेट है और हरा 1 पर सेट है, मॉडल का केवल हरा भाग हाइलाइट किया गया है। (लाल और नीले रंग भी धुंधले दिखाई देते हैं, लेकिन यह परिवेश प्रकाश के कारण है।

DiffuseColor 変更

फैलाना (लाल) 0
फैलाना (हरा) 1
डिफ्यूज़ (नीला) 0
स्पेक्युलर (लाल) 1
स्पेक्युलर (हरा) 0.96
स्पेक्युलर (ब्लू) 0.80
दिशा X -0.52
दिशा Y -0.57
दिशा Z -0.62
परिवेश प्रकाश रंग (लाल) 0.05
परिवेश प्रकाश रंग (हरा) 0.09
परिवेश LightColor (नीला) 0.18
PreferPerPixelLighting गलत

SpecularColor बदलें

परावर्तित प्रकाश का रंग बदलना। चूंकि केवल हरा सेट है, परावर्तक भाग का रंग केवल हरा तत्व है।

SpecularColor 変更

फैलाना (लाल) 1
फैलाना (हरा) 0.96
डिफ्यूज़ (नीला) 0.80
स्पेक्युलर (लाल) 0
स्पेक्युलर (हरा) 1
स्पेक्युलर (ब्लू) 0
दिशा X -0.52
दिशा Y -0.57
दिशा Z -0.62
परिवेश प्रकाश रंग (लाल) 0.05
परिवेश प्रकाश रंग (हरा) 0.09
परिवेश LightColor (नीला) 0.18
PreferPerPixelLighting गलत

दिशा परिवर्तन

आप दिशा बदलकर प्रकाश की दिशा बदल सकते हैं। आम तौर पर, केवल अभिविन्यास का उपयोग किया जाता है, इसलिए वेक्टर सामान्यीकृत होता है।

Direction 変更

फैलाना (लाल) 1
फैलाना (हरा) 0.96
डिफ्यूज़ (नीला) 0.80
स्पेक्युलर (लाल) 1
स्पेक्युलर (हरा) 0.96
स्पेक्युलर (ब्लू) 0.80
दिशा X 0.67
दिशा Y 0.54
दिशा Z -0.34
परिवेश प्रकाश रंग (लाल) 0.05
परिवेश प्रकाश रंग (हरा) 0.09
परिवेश LightColor (नीला) 0.18
PreferPerPixelLighting गलत

परिवेशलाइटकलर बदलें

लाल और नीली परिवेश रोशनी को अधिकतम किया जाता है, और हरे रंग को 0 पर सेट किया जाता है। यदि आप उन क्षेत्रों को देखते हैं जहां प्रकाश नहीं चमकता है, तो आप हरे, लाल और नीले रंगों के बीच अंतर स्पष्ट रूप से देख सकते हैं।

AmbientLightColor 変更

फैलाना (लाल) 1
फैलाना (हरा) 0.96
डिफ्यूज़ (नीला) 0.80
स्पेक्युलर (लाल) 1
स्पेक्युलर (हरा) 0.96
स्पेक्युलर (ब्लू) 0.80
दिशा X -0.52
दिशा Y -0.57
दिशा Z -0.62
परिवेश प्रकाश रंग (लाल) 1
परिवेश प्रकाश रंग (हरा) 0
परिवेश LightColor (नीला) 1
PreferPerPixelLighting गलत

PreferPerPixelLighting संशोधन

PreferPerPixelLighting को True पर सेट करें ताकि pixel-दर-पिक्सेल प्रकाश गणनाओं की अनुमति दी जा सके. आरेख में देखना कठिन है, लेकिन शीर्ष-स्तरीय प्रकाश व्यवस्था के मामले में, बहुभुजों की सीमाएं किसी तरह दिखाई देती हैं, लेकिन पिक्सेल-दर-पिक्सेल प्रकाश व्यवस्था के मामले में, बहुत चिकनी छाया व्यक्त की जा सकती है।

वैसे, यदि आप पिक्सेल शेडर 2.0 का समर्थन नहीं करते हैं, तो आप PreferPerPixelLighting गुण का उपयोग नहीं कर सकते। इसके अलावा, यदि आप कई रोशनी का उपयोग करते हैं, तो यह अजीब लग सकता है।

PreferPerPixelLighting 変更

फैलाना (लाल) 1
फैलाना (हरा) 0.96
डिफ्यूज़ (नीला) 0.80
स्पेक्युलर (लाल) 1
स्पेक्युलर (हरा) 0.96
स्पेक्युलर (ब्लू) 0.80
दिशा X -0.52
दिशा Y -0.57
दिशा Z -0.62
परिवेश प्रकाश रंग (लाल) 0.05
परिवेश प्रकाश रंग (हरा) 0.09
परिवेश LightColor (नीला) 0.18
PreferPerPixelLighting सच्चा
प्रति-शीर्ष प्रकाश व्यवस्थाप्रति-पिक्सेल प्रकाश
頂点単位のライティング ピクセル単位のライティング

रोशनी के लिए पैरामीटर वर्ग परिभाषाएँ

चूंकि बेसिकइफेक्ट में कई रोशनी हो सकती हैं, इसलिए हमने प्रकाश पैरामीटर सेट करने के लिए एक वर्ग बनाया है। पैरामीटर वही हैं जो BasicEffect लाइट (BasicDirectionalLight) के लिए सेट किए जा सकते हैं।

/// <summary>
/// ライトパラメータ
/// </summary>
public class LightParameter
{
    /// <summary>
    /// ライト有効フラグ
    /// </summary>
    public bool Enabled;

    /// <summary>
    /// ディフューズカラー
    /// </summary>
    public Vector3 DiffuseColor;

    /// <summary>
    /// スペキュラーカラー
    /// </summary>
    public Vector3 SpecularColor;

    /// <summary>
    /// ライトの方向
    /// </summary>
    public Vector3 Direction;
}

खेत

प्रकाश स्थापित करने के लिए आवश्यक मापदंडों को परिभाषित करता है। चूंकि आप रोशनी के लिए तीन रोशनी सेट कर सकते हैं, सरणी में तत्वों की संख्या भी तीन है। अन्य फ़ील्ड मेनू संचालन, चरित्र प्रदर्शन आदि के लिए उपयोग किए जाते हैं, इसलिए कृपया पूर्ण कोड देखें।

/// <summary>
/// 選択しているライトのインデックス
/// </summary>
private int selectedLightIndex = 0;

/// <summary>
/// ライトのパラメータ
/// </summary>
private LightParameter[] lightParameters = new LightParameter[]
    {
        new LightParameter(),
        new LightParameter(),
        new LightParameter()
    };

/// <summary>
/// アンビエントカラー
/// </summary>
private Vector3 ambientLightColor = Vector3.Zero;

/// <summary>
/// ピクセル単位のライティング
/// </summary>
private bool isPreferPerPixelLighting = false;

डिफ़ॉल्ट लेखन अधिग्रहण

BasicEffect.EnableDefaultLighting विधि XNA फ्रेमवर्क द्वारा निर्दिष्ट प्रकाश के मापदंडों को एक प्रभाव के लिए सेट करती है। इसे एक बार खेत में रखने के लिए हमें यह मान मिल रहा है। (नमूने में, यह कई बार प्राप्त करने के रूप में है, लेकिन इसे सरल बनाया गया है क्योंकि यदि आप इसे अलग से प्राप्त करने के लिए कोड लिखते हैं तो यह लंबा होगा।

// ライトとビュー、プロジェクションはあらかじめ設定しておく
foreach (ModelMesh mesh in this.model.Meshes)
{
    foreach (BasicEffect effect in mesh.Effects)
    {
        // デフォルトのライト適用
        effect.EnableDefaultLighting();

        // ビューマトリックスをあらかじめ設定 ((0, 0, 8) から原点を見る)
        effect.View = Matrix.CreateLookAt(
            new Vector3(0.0f, 0.0f, 8.0f),
            Vector3.Zero,
            Vector3.Up
        );

        // プロジェクションマトリックスをあらかじめ設定
        effect.Projection = Matrix.CreatePerspectiveFieldOfView(
            MathHelper.ToRadians(45.0f),
            (float)this.GraphicsDevice.Viewport.Width /
                (float)this.GraphicsDevice.Viewport.Height,
            1.0f,
            100.0f
        );

        // デフォルトのパラメータを受け取る
        this.lightParameters[0].Enabled = effect.DirectionalLight0.Enabled;
        this.lightParameters[0].DiffuseColor = effect.DirectionalLight0.DiffuseColor;
        this.lightParameters[0].SpecularColor = effect.DirectionalLight0.SpecularColor;
        this.lightParameters[0].Direction = effect.DirectionalLight0.Direction;

        this.lightParameters[1].Enabled = effect.DirectionalLight1.Enabled;
        this.lightParameters[1].DiffuseColor = effect.DirectionalLight1.DiffuseColor;
        this.lightParameters[1].SpecularColor = effect.DirectionalLight1.SpecularColor;
        this.lightParameters[1].Direction = effect.DirectionalLight1.Direction;

        this.lightParameters[2].Enabled = effect.DirectionalLight2.Enabled;
        this.lightParameters[2].DiffuseColor = effect.DirectionalLight2.DiffuseColor;
        this.lightParameters[2].SpecularColor = effect.DirectionalLight2.SpecularColor;
        this.lightParameters[2].Direction = effect.DirectionalLight2.Direction;

        // アンビエントカラー
        this.ambientLightColor = effect.AmbientLightColor;

        // ピクセル単位のライティング
        this.isPreferPerPixelLighting = effect.PreferPerPixelLighting;
    }
}

रोशनी की स्थापना

मैं मॉडल के बेसिकइफेक्ट पर प्रकाश डाल रहा हूं। मान बस BasicEffect के प्रकाश पैरामीटर पर सेट है। प्रकाश पैरामीटर परिवर्तन ऑपरेशन के कोड के लिए, कृपया पूर्ण कोड को अलग से देखें।

foreach (ModelMesh mesh in this.model.Meshes)
{
    foreach (BasicEffect effect in mesh.Effects)
    {
        for (int i = 0; i < this.lightParameters.Length; i++)
        {
            // ライトを取得
            BasicDirectionalLight light = null;

            switch (i)
            {
                case 0:
                    light = effect.DirectionalLight0;
                    break;
                case 1:
                    light = effect.DirectionalLight1;
                    break;
                case 2:
                    light = effect.DirectionalLight2;
                    break;
            }

            // ライト有効フラグ
            light.Enabled = this.lightParameters[i].Enabled;

            // ライトのディフーズカラー
            light.DiffuseColor = this.lightParameters[i].DiffuseColor;

            // ライトのスペキュラーカラー
            light.SpecularColor = this.lightParameters[i].SpecularColor;

            // ライトの方向
            light.Direction = this.lightParameters[i].Direction;
        }

        // アンビエントカラー
        effect.AmbientLightColor = this.ambientLightColor;

        // ピクセル単位のライティング
        effect.PreferPerPixelLighting = this.isPreferPerPixelLighting;

    }
}

BasicEffect.DirectionalLight0 जायदाद

पहला समानांतर प्रकाश स्रोत पैरामीटर प्राप्त करता है। बेसिक डायरेक्शनललाइट मिलना

BasicEffect.DirectionalLight1 जायदाद

दूसरा समानांतर प्रकाश स्रोत पैरामीटर प्राप्त करें। बेसिक डायरेक्शनललाइट मिलना

BasicEffect.DirectionalLight2 जायदाद

तीसरा समानांतर प्रकाश स्रोत पैरामीटर प्राप्त करें। बेसिक डायरेक्शनललाइट मिलना

BasicEffect.AmbientLightColor जायदाद

परिवेश प्रकाश का रंग प्राप्त करता है और सेट करता है। X लाल है, Y हरा है, Z नीला है, और प्रत्येक मान 0.0~1.0 की सीमा में है। वेक्टर3 प्राप्त करें, सेट करें

BasicEffect.PreferPerPixelLighting जायदाद

यदि सही पर सेट किया जाता है, तो प्रकाश गणना प्रति-पिक्सेल के आधार पर की जा सकती है। हालांकि, इस प्रॉपर्टी के सही होने के लिए, उसे पिक्सेल शेडर 2.0 या उसके बाद वाले वर्शन का समर्थन करना होगा. यदि गलत पर सेट किया गया है, तो प्रकाश गणना प्रति-शीर्ष के आधार पर की जाएगी। बूल प्राप्त करें, सेट करें

BasicDirectionalLight.Enabled जायदाद

प्रकाश को सेट और अक्षम करता है। बूल प्राप्त करें, सेट करें

BasicDirectionalLight.DiffuseColor जायदाद

प्रकाश के फैलाना रंग को प्राप्त करता है और सेट करता है। X लाल है, Y हरा है, Z नीला है, और प्रत्येक मान 0.0~1.0 की सीमा में है। वेक्टर3 प्राप्त करें, सेट करें

BasicDirectionalLight.SpecularColor जायदाद

प्रकाश के परावर्तित रंग को प्राप्त करता है और सेट करता है। X लाल है, Y हरा है, Z नीला है, और प्रत्येक मान 0.0~1.0 की सीमा में है। वेक्टर3 प्राप्त करें, सेट करें

BasicDirectionalLight.Direction जायदाद

हो जाता है और प्रकाश की दिशा निर्धारित करता है। वेक्टर3 प्राप्त करें, सेट करें

सभी कोड

using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
#if WINDOWS_PHONE
using Microsoft.Xna.Framework.Input.Touch;
#endif

namespace BasicEffectLight
{
    /// <summary>
    /// ゲームメインクラス
    /// </summary>
    public class GameMain : Microsoft.Xna.Framework.Game
    {
        /// <summary>
        /// ライトパラメータ
        /// </summary>
        public class LightParameter
        {
            /// <summary>
            /// ライト有効フラグ
            /// </summary>
            public bool Enabled;

            /// <summary>
            /// ディフューズカラー
            /// </summary>
            public Vector3 DiffuseColor;

            /// <summary>
            /// スペキュラーカラー
            /// </summary>
            public Vector3 SpecularColor;

            /// <summary>
            /// ライトの方向
            /// </summary>
            public Vector3 Direction;
        }

        /// <summary>
        /// グラフィックデバイス管理クラス
        /// </summary>
        private GraphicsDeviceManager graphics = null;

        /// <summary>
        /// スプライトのバッチ化クラス
        /// </summary>
        private SpriteBatch spriteBatch = null;

        /// <summary>
        /// スプライトでテキストを描画するためのフォント
        /// </summary>
        private SpriteFont font = null;

        /// <summary>
        /// 直前のキーボード入力の状態
        /// </summary>
        private KeyboardState oldKeyboardState = new KeyboardState();

        /// <summary>
        /// 直前のマウスの状態
        /// </summary>
        private MouseState oldMouseState = new MouseState();

        /// <summary>
        /// 直前のゲームパッド入力の状態
        /// </summary>
        private GamePadState oldGamePadState = new GamePadState();

        /// <summary>
        /// モデル
        /// </summary>
        private Model model = null;

        /// <summary>
        /// 選択しているメニューのインデックス
        /// </summary>
        private int selectedMenuIndex = 0;

        /// <summary>
        /// 選択しているライトのインデックス
        /// </summary>
        private int selectedLightIndex = 0;

        /// <summary>
        /// ライトのパラメータ
        /// </summary>
        private LightParameter[] lightParameters = new LightParameter[]
            {
                new LightParameter(),
                new LightParameter(),
                new LightParameter()
            };

        /// <summary>
        /// アンビエントカラー
        /// </summary>
        private Vector3 ambientLightColor = Vector3.Zero;

        /// <summary>
        /// ピクセル単位のライティング
        /// </summary>
        private bool isPreferPerPixelLighting = false;

        /// <summary>
        /// パラメータの最大数
        /// </summary>
        private static int MaxParameterCount = 15;

        /// <summary>
        /// メニューリスト
        /// </summary>
        private static string[] MenuNameList = new string[]
            {
                "LightIndex",
                "Light Enable",
                "DiffuseColor (Red)",
                "DiffuseColor (Green)",
                "DiffuseColor (Blue)",
                "SpecularColor (Red)",
                "SpecularColor (Green)",
                "SpecularColor (Blue)",
                "Direction X",
                "Direction Y",
                "Direction Z",
                "AmbientLightColor (Red)",
                "AmbientLightColor (Green)",
                "AmbientLightColor (Blue)",
                "PreferPerPixelLighting",
            };

        /// <summary>
        /// パラメータテキストリスト
        /// </summary>
        private string[] parameters = new string[MaxParameterCount];


        /// <summary>
        /// GameMain コンストラクタ
        /// </summary>
        public GameMain()
        {
            // グラフィックデバイス管理クラスの作成
            this.graphics = new GraphicsDeviceManager(this);

            // ゲームコンテンツのルートディレクトリを設定
            this.Content.RootDirectory = "Content";

#if WINDOWS_PHONE
            // Windows Phone のデフォルトのフレームレートは 30 FPS
            this.TargetElapsedTime = TimeSpan.FromTicks(333333);

            // バックバッファサイズの設定
            this.graphics.PreferredBackBufferWidth = 480;
            this.graphics.PreferredBackBufferHeight = 800;

            // フルスクリーン表示
            this.graphics.IsFullScreen = true;
#endif

            // ウインドウ上でマウスのポインタを表示するようにする
            this.IsMouseVisible = true;
        }

        /// <summary>
        /// ゲームが始まる前の初期化処理を行うメソッド
        /// グラフィック以外のデータの読み込み、コンポーネントの初期化を行う
        /// </summary>
        protected override void Initialize()
        {
            // TODO: ここに初期化ロジックを書いてください

            // コンポーネントの初期化などを行います
            base.Initialize();
        }

        /// <summary>
        /// ゲームが始まるときに一回だけ呼ばれ
        /// すべてのゲームコンテンツを読み込みます
        /// </summary>
        protected override void LoadContent()
        {
            // テクスチャーを描画するためのスプライトバッチクラスを作成します
            this.spriteBatch = new SpriteBatch(this.GraphicsDevice);

            // フォントをコンテンツパイプラインから読み込む
            this.font = this.Content.Load<SpriteFont>("Font");

            // モデルを作成
            this.model = this.Content.Load<Model>("Model");

            // ライトとビュー、プロジェクションはあらかじめ設定しておく
            foreach (ModelMesh mesh in this.model.Meshes)
            {
                foreach (BasicEffect effect in mesh.Effects)
                {
                    // デフォルトのライト適用
                    effect.EnableDefaultLighting();

                    // ビューマトリックスをあらかじめ設定 ((0, 0, 8) から原点を見る)
                    effect.View = Matrix.CreateLookAt(
                        new Vector3(0.0f, 0.0f, 8.0f),
                        Vector3.Zero,
                        Vector3.Up
                    );

                    // プロジェクションマトリックスをあらかじめ設定
                    effect.Projection = Matrix.CreatePerspectiveFieldOfView(
                        MathHelper.ToRadians(45.0f),
                        (float)this.GraphicsDevice.Viewport.Width /
                            (float)this.GraphicsDevice.Viewport.Height,
                        1.0f,
                        100.0f
                    );

                    // デフォルトのパラメータを受け取る
                    this.lightParameters[0].Enabled = effect.DirectionalLight0.Enabled;
                    this.lightParameters[0].DiffuseColor = effect.DirectionalLight0.DiffuseColor;
                    this.lightParameters[0].SpecularColor = effect.DirectionalLight0.SpecularColor;
                    this.lightParameters[0].Direction = effect.DirectionalLight0.Direction;

                    this.lightParameters[1].Enabled = effect.DirectionalLight1.Enabled;
                    this.lightParameters[1].DiffuseColor = effect.DirectionalLight1.DiffuseColor;
                    this.lightParameters[1].SpecularColor = effect.DirectionalLight1.SpecularColor;
                    this.lightParameters[1].Direction = effect.DirectionalLight1.Direction;

                    this.lightParameters[2].Enabled = effect.DirectionalLight2.Enabled;
                    this.lightParameters[2].DiffuseColor = effect.DirectionalLight2.DiffuseColor;
                    this.lightParameters[2].SpecularColor = effect.DirectionalLight2.SpecularColor;
                    this.lightParameters[2].Direction = effect.DirectionalLight2.Direction;

                    // アンビエントカラー
                    this.ambientLightColor = effect.AmbientLightColor;

                    // ピクセル単位のライティング
                    this.isPreferPerPixelLighting = effect.PreferPerPixelLighting;
                }
            }
        }

        /// <summary>
        /// ゲームが終了するときに一回だけ呼ばれ
        /// すべてのゲームコンテンツをアンロードします
        /// </summary>
        protected override void UnloadContent()
        {
            // TODO: ContentManager で管理されていないコンテンツを
            //       ここでアンロードしてください
        }

        /// <summary>
        /// 描画以外のデータ更新等の処理を行うメソッド
        /// 主に入力処理、衝突判定などの物理計算、オーディオの再生など
        /// </summary>
        /// <param name="gameTime">このメソッドが呼ばれたときのゲーム時間</param>
        protected override void Update(GameTime gameTime)
        {
            // 入力デバイスの状態取得
            KeyboardState keyboardState = Keyboard.GetState();
            MouseState mouseState = Mouse.GetState();
            GamePadState gamePadState = GamePad.GetState(PlayerIndex.One);

            // Xbox 360 コントローラ、Windows Phone の BACK ボタンを押したときに
            // ゲームを終了させます
            if (gamePadState.Buttons.Back == ButtonState.Pressed)
            {
                this.Exit();
            }

            // メニューの選択
            if ((keyboardState.IsKeyDown(Keys.Up) && this.oldKeyboardState.IsKeyUp(Keys.Up)) ||
                (gamePadState.ThumbSticks.Left.Y >= 0.5f &&
                    this.oldGamePadState.ThumbSticks.Left.Y < 0.5f))
            {
                // 選択メニューをひとつ上に移動
                this.selectedMenuIndex =
                    (this.selectedMenuIndex + this.parameters.Length - 1) % this.parameters.Length;
            }
            if ((keyboardState.IsKeyDown(Keys.Down) && this.oldKeyboardState.IsKeyUp(Keys.Down)) ||
                (gamePadState.ThumbSticks.Left.Y <= -0.5f &&
                    this.oldGamePadState.ThumbSticks.Left.Y > -0.5f) ||
                (this.oldMouseState.LeftButton == ButtonState.Pressed &&
                 mouseState.LeftButton == ButtonState.Released))
            {
                // 選択メニューをひとつ下に移動
                this.selectedMenuIndex =
                    (this.selectedMenuIndex + this.parameters.Length + 1) % this.parameters.Length;
            }

            // 各マテリアルの値を操作
            float moveValue = 0.0f;
            if (keyboardState.IsKeyDown(Keys.Left))
            {
                moveValue -= (float)gameTime.ElapsedGameTime.TotalSeconds;
            }
            if (keyboardState.IsKeyDown(Keys.Right))
            {
                moveValue += (float)gameTime.ElapsedGameTime.TotalSeconds;
            }
            if (mouseState.LeftButton == ButtonState.Pressed)
            {
                moveValue += (mouseState.X - this.oldMouseState.X) * 0.005f;
            }
            if (gamePadState.IsConnected)
            {
                moveValue += gamePadState.ThumbSticks.Left.X *
                             (float)gameTime.ElapsedGameTime.TotalSeconds;
            }

            if (moveValue != 0.0f)
            {
                LightParameter selectedLight = this.lightParameters[this.selectedLightIndex];

                switch (this.selectedMenuIndex)
                {
                    case 0:
                        // ライトのインデックス
                        if ((keyboardState.IsKeyDown(Keys.Left) &&
                                this.oldKeyboardState.IsKeyUp(Keys.Left)) ||
                            (mouseState.LeftButton == ButtonState.Pressed &&
                                (mouseState.X - this.oldMouseState.X) >= 5) ||
                            (gamePadState.ThumbSticks.Left.X >= 0.5f &&
                                this.oldGamePadState.ThumbSticks.Left.X < 0.5f))
                        {
                            // ライトのインデックスをひとつ減らす
                            this.selectedLightIndex =
                                (this.selectedLightIndex + this.lightParameters.Length - 1) %
                                    this.lightParameters.Length;
                        }
                        if ((keyboardState.IsKeyDown(Keys.Right) &&
                                this.oldKeyboardState.IsKeyUp(Keys.Right)) ||
                            (mouseState.LeftButton == ButtonState.Pressed &&
                                (mouseState.X - this.oldMouseState.X) <= -5) ||
                            (gamePadState.ThumbSticks.Left.X <= -0.5f &&
                                this.oldGamePadState.ThumbSticks.Left.X > -0.5f))
                        {
                            // ライトのインデックスをひとつ増やす
                            this.selectedLightIndex =
                                (this.selectedLightIndex + this.lightParameters.Length + 1) %
                                    this.lightParameters.Length;
                        }
                        if (mouseState.LeftButton == ButtonState.Pressed)
                        {
                            this.selectedLightIndex = (int)(
                                MathHelper.Clamp((float)mouseState.X / this.GraphicsDevice.Viewport.Width * 3, 0, 2));
                        }
                        break;
                    case 1:
                        // ライト有効フラグ
                        selectedLight.Enabled = (moveValue > 0.0f);
                        break;
                    case 2:
                        // ライトのディフーズカラー(赤)
                        Vector3 diffuseX = selectedLight.DiffuseColor;
                        diffuseX.X = MathHelper.Clamp(diffuseX.X + moveValue, 0.0f, 1.0f);
                        selectedLight.DiffuseColor = diffuseX;
                        break;
                    case 3:
                        // ライトのディフーズカラー(緑)
                        Vector3 diffuseY = selectedLight.DiffuseColor;
                        diffuseY.Y = MathHelper.Clamp(diffuseY.Y + moveValue, 0.0f, 1.0f);
                        selectedLight.DiffuseColor = diffuseY;
                        break;
                    case 4:
                        // ライトのディフーズカラー(青)
                        Vector3 diffuseZ = selectedLight.DiffuseColor;
                        diffuseZ.Z = MathHelper.Clamp(diffuseZ.Z + moveValue, 0.0f, 1.0f);
                        selectedLight.DiffuseColor = diffuseZ;
                        break;
                    case 5:
                        // ライトのスペキュラーカラー(赤)
                        Vector3 specularX = selectedLight.SpecularColor;
                        specularX.X = MathHelper.Clamp(specularX.X + moveValue, 0.0f, 1.0f);
                        selectedLight.SpecularColor = specularX;
                        break;
                    case 6:
                        // ライトのスペキュラーカラー(緑)
                        Vector3 specularY = selectedLight.SpecularColor;
                        specularY.Y = MathHelper.Clamp(specularY.Y + moveValue, 0.0f, 1.0f);
                        selectedLight.SpecularColor = specularY;
                        break;
                    case 7:
                        // ライトのスペキュラーカラー(青)
                        Vector3 specularZ = selectedLight.SpecularColor;
                        specularZ.Z = MathHelper.Clamp(specularZ.Z + moveValue, 0.0f, 1.0f);
                        selectedLight.SpecularColor = specularZ;
                        break;
                    case 8:
                        // ライトの方向X
                        Vector3 directionX = selectedLight.Direction;
                        directionX.X += moveValue;
                        selectedLight.Direction = directionX;
                        break;
                    case 9:
                        // ライトの方向Y
                        Vector3 directionY = selectedLight.Direction;
                        directionY.Y += moveValue;
                        selectedLight.Direction = directionY;
                        break;
                    case 10:
                        // ライトの方向Z
                        Vector3 directionZ = selectedLight.Direction;
                        directionZ.Z += moveValue;
                        selectedLight.Direction = directionZ;
                        break;
                    case 11:
                        // アンビエントカラー(赤)
                        this.ambientLightColor.X =
                            MathHelper.Clamp(this.ambientLightColor.X + moveValue, 0.0f, 1.0f);
                        break;
                    case 12:
                        // アンビエントカラー(緑)
                        this.ambientLightColor.Y =
                            MathHelper.Clamp(this.ambientLightColor.Y + moveValue, 0.0f, 1.0f);
                        break;
                    case 13:
                        // アンビエントカラー(青)
                        this.ambientLightColor.Z =
                            MathHelper.Clamp(this.ambientLightColor.Z + moveValue, 0.0f, 1.0f);
                        break;
                    case 14:
                        // ピクセル単位のライティング
                        this.isPreferPerPixelLighting = (moveValue > 0.0f);
                        break;
                }
            }

            // ライトを設定
            foreach (ModelMesh mesh in this.model.Meshes)
            {
                foreach (BasicEffect effect in mesh.Effects)
                {
                    for (int i = 0; i < this.lightParameters.Length; i++)
                    {
                        // ライトを取得
                        DirectionalLight light = null;

                        switch (i)
                        {
                            case 0:
                                light = effect.DirectionalLight0;
                                break;
                            case 1:
                                light = effect.DirectionalLight1;
                                break;
                            case 2:
                                light = effect.DirectionalLight2;
                                break;
                        }

                        // ライト有効フラグ
                        light.Enabled = this.lightParameters[i].Enabled;

                        // ライトのディフーズカラー
                        light.DiffuseColor = this.lightParameters[i].DiffuseColor;

                        // ライトのスペキュラーカラー
                        light.SpecularColor = this.lightParameters[i].SpecularColor;

                        // ライトの方向
                        light.Direction = this.lightParameters[i].Direction;
                    }

                    // アンビエントカラー
                    effect.AmbientLightColor = this.ambientLightColor;

                    // ピクセル単位のライティング
                    effect.PreferPerPixelLighting = this.isPreferPerPixelLighting;

                }
            }

            // 入力情報を記憶
            this.oldKeyboardState = keyboardState;
            this.oldMouseState = mouseState;
            this.oldGamePadState = gamePadState;

            // 登録された GameComponent を更新する
            base.Update(gameTime);
        }

        /// <summary>
        /// 描画処理を行うメソッド
        /// </summary>
        /// <param name="gameTime">このメソッドが呼ばれたときのゲーム時間</param>
        protected override void Draw(GameTime gameTime)
        {
            // 画面を指定した色でクリアします
            this.GraphicsDevice.Clear(Color.CornflowerBlue);

            // 深度バッファを有効にする
            this.GraphicsDevice.DepthStencilState = DepthStencilState.Default;

            // モデルを描画
            foreach (ModelMesh mesh in this.model.Meshes)
            {
#if WINDOWS_PHONE
                foreach (BasicEffect effect in mesh.Effects)
                {
                    effect.World = Matrix.CreateRotationZ(-MathHelper.PiOver2);
                }
#endif

                mesh.Draw();
            }

            // スプライトの描画準備
            this.spriteBatch.Begin();

            // 操作
            this.spriteBatch.DrawString(this.font,
                "Up, Down : Select Menu",
                new Vector2(20.0f, 20.0f), Color.White);
            this.spriteBatch.DrawString(this.font,
                "Left, right : Change Value",
                new Vector2(20.0f, 45.0f), Color.White);
            this.spriteBatch.DrawString(this.font,
                "MouseClick & Drag :",
                new Vector2(20.0f, 70.0f), Color.White);
            this.spriteBatch.DrawString(this.font,
                "    Select Menu & Change Value",
                new Vector2(20.0f, 95.0f), Color.White);

            // 各メニュー //
            for (int i = 0; i < MenuNameList.Length; i++)
            {
                this.spriteBatch.DrawString(this.font,
                    MenuNameList[i],
                    new Vector2(40.0f, 120.0f + i * 20.0f), Color.White);
            }

            // 各パラメータ //

            LightParameter selectedLight = this.lightParameters[this.selectedLightIndex];

            // ライトのインデックス
            this.parameters[0] = this.selectedLightIndex.ToString();

            // ライトの有効フラグ
            this.parameters[1] = selectedLight.Enabled.ToString();

            // ライトのディフーズカラー(赤)
            this.parameters[2] = selectedLight.DiffuseColor.X.ToString();

            // ライトのディフーズカラー(緑)
            this.parameters[3] = selectedLight.DiffuseColor.Y.ToString();

            // ライトのディフーズカラー(青)
            this.parameters[4] = selectedLight.DiffuseColor.Z.ToString();

            // ライトのスペキュラーカラー(赤)
            this.parameters[5] = selectedLight.SpecularColor.X.ToString();

            // ライトのスペキュラーカラー(緑)
            this.parameters[6] = selectedLight.SpecularColor.Y.ToString();

            // ライトのスペキュラーカラー(青)
            this.parameters[7] = selectedLight.SpecularColor.Z.ToString();

            // ライトの方向X
            this.parameters[8] = selectedLight.Direction.X.ToString();

            // ライトの方向Y
            this.parameters[9] = selectedLight.Direction.Y.ToString();

            // ライトの方向Z
            this.parameters[10] = selectedLight.Direction.Z.ToString();

            // アンビエントカラー(赤)
            this.parameters[11] = this.ambientLightColor.X.ToString();

            // アンビエントカラー(緑)
            this.parameters[12] = this.ambientLightColor.Y.ToString();

            // アンビエントカラー(青)
            this.parameters[13] = this.ambientLightColor.Z.ToString();

            // ピクセル単位のライティング
            this.parameters[14] = this.isPreferPerPixelLighting.ToString();


            for (int i = 0; i < this.parameters.Length; i++)
            {
                this.spriteBatch.DrawString(this.font,
                    this.parameters[i],
                    new Vector2(300.0f, 120.0f + i * 20.0f), Color.White);
            }

            // 選択インデックス
            this.spriteBatch.DrawString(this.font, "*",
                new Vector2(20.0f, 124.0f + this.selectedMenuIndex * 20.0f), Color.White);

            // スプライトの一括描画
            this.spriteBatch.End();

            // 登録された DrawableGameComponent を描画する
            base.Draw(gameTime);
        }
    }
}