Exemple #1
0
        } // RenderObjectsToPickerTexture

        #endregion

        #region Render Object To Picker

        /// <summary>
        /// Render Object To Picker.
        /// </summary>
        public void RenderObjectToPicker(GameObject gameObject)
        {
            if (gameObject is GameObject3D)
            {
                GameObject3D gameObject3D = (GameObject3D)gameObject;
                if (gameObject3D.LineRenderer != null)
                {
                    LineManager.Begin3D(gameObject3D.LineRenderer.PrimitiveType, viewMatrix, projectionMatrix);
                    for (int j = 0; j < gameObject3D.LineRenderer.Vertices.Length; j++)
                    {
                        LineManager.AddVertex(Vector3.Transform(gameObject3D.LineRenderer.Vertices[j].Position, gameObject3D.Transform.WorldMatrix), gameObject3D.LineRenderer.Vertices[j].Color);
                    }
                    LineManager.End();
                }
            }
            else if (gameObject is GameObject2D)
            {
                GameObject2D gameObject2D = (GameObject2D)gameObject;
                if (gameObject2D.LineRenderer != null)
                {
                    LineManager.Begin2D(gameObject2D.LineRenderer.PrimitiveType);
                    for (int j = 0; j < gameObject2D.LineRenderer.Vertices.Length; j++)
                    {
                        LineManager.AddVertex(gameObject2D.LineRenderer.Vertices[j].Position, gameObject2D.LineRenderer.Vertices[j].Color);
                    }
                    LineManager.End();
                }
            }
        } // RenderObjectToPicker
Exemple #2
0
    void createGameObject2D()
    {
        // create 3 instances of the class 'GameObject2D'
        // and their names are Peter, David and John.
        GameObject2D peter = new GameObject2D("Peter");
        GameObject2D david = new GameObject2D("David");
        GameObject2D john  = new GameObject2D("John");

        // define a List (C# data structure, as introduced in the lecture)
        // which holds 3 instances.
        // note that, if 'List' is not recognized by Monodeveloper, you need to
        // include another namespace, i.e. 'using ...'
        List <GameObject2D> goList = new List <GameObject2D>();

        goList.Add(peter);
        goList.Add(david);
        goList.Add(john);

        // using the loop structure, foreach, to print names of the 3 instances
        // created earlier.
        foreach (GameObject2D go in goList)
        {
            Debug.Log("name: " + go.Name);
        }
    }
        /// <summary>
        /// Load the resources.
        /// </summary>
        /// <remarks>Remember to call the base implementation of this method.</remarks>
        protected override void LoadContent()
        {
            // Hello World
            helloWorldText = new GameObject2D();
            helloWorldText.AddComponent <HudText>();
            helloWorldText.HudText.Text.Append("Hello World");
            helloWorldText.Transform.LocalPosition = new Vector3(10, 10, 0);
            // Creating a 3D World
            camera = new GameObject3D();
            camera.AddComponent <Camera>();

            /*body = new GameObject3D();
             * body.AddComponent<ModelFilter>();
             * body.ModelFilter.Model = new FileModel("LamborghiniMurcielago\\Murcielago-Body");
             * body.AddComponent<ModelRenderer>();
             * body.ModelRenderer.Material = new Constant();*/
            body = new GameObject3D(new FileModel("LamborghiniMurcielago\\Murcielago-Body"), new Constant());
            camera.Transform.LookAt(new Vector3(5, 0, 10), Vector3.Zero, Vector3.Up);

            body.ModelRenderer.Material = new BlinnPhong();
            ((BlinnPhong)body.ModelRenderer.Material).DiffuseColor = Color.Yellow;
            directionalLight = new GameObject3D();
            directionalLight.AddComponent <DirectionalLight>();
            directionalLight.DirectionalLight.Color     = new Color(250, 250, 140);
            directionalLight.DirectionalLight.Intensity = 1f;
            directionalLight.Transform.LookAt(new Vector3(0.5f, 0.65f, 1.3f), Vector3.Zero, Vector3.Forward);

            camera.Camera.PostProcess = new PostProcess();
            camera.Camera.PostProcess.ToneMapping.ToneMappingFunction = ToneMapping.ToneMappingFunctionEnumerate.FilmicALU;

            base.LoadContent();
        } // Load
Exemple #4
0
 public int CheckOut(GameObject2D sprite)
 {
     if (CurrentState == NoteState.Enter)
     {
         CurrentState = NoteState.Passed;
         return(noteOut.CheckCollision(sprite));
     }
     return(-1);
 }
Exemple #5
0
 public int CheckCollision(GameObject2D sprite)
 {
     if (CurrentState == NoteState.Normal)
     {
         if (noteIn.CheckCollision(sprite) > 0)
         {
             CurrentState = NoteState.Enter;
             return(1);
         }
         return(0);
     }
     return(0);
 }
Exemple #6
0
        void BallCollision(GameObject2D _sender, GameObject2D _other)
        {
            if (_other.objectTag == "handle") //Hit one of the handles
            {
                ballObject.objectVelocity = new Point(ballObject.objectVelocity.X * -1, ballObject.objectVelocity.Y);
            }
            else if (_other.objectTag == "side") //Hit top / bottom of screen
            {
                ballObject.objectVelocity = new Point(ballObject.objectVelocity.X, ballObject.objectVelocity.Y * -1);
            }
            else if (_other.objectTag.Contains("Trigger")) //Hit left or right trigger
            {
                if (_other.objectTag == "leftTrigger")     //Add points to right
                {
                    rightScore++;
                    rightScoreText.text = rightScore.ToString();
                }
                else //Add points to left
                {
                    leftScore++;
                    leftScoreText.text = leftScore.ToString();
                }

                if (leftScore >= victoryScoreAmount || rightScore >= victoryScoreAmount) //Winning conditions
                {
                    gameManager.ChangeScene(1);
                    gameManager.ChangeUi(1);

                    if (leftScore >= victoryScoreAmount) //Left won
                    {
                        victoryText.text = "Left";
                    }
                    else //Right won
                    {
                        victoryText.text = "Right";
                    }
                    victoryText.text += " won";
                }
                else //No winners yet, continue the game
                {
                    ballObject.gameObjectLocation = new Point(200, 100);

                    Random r = new Random();
                    ballObject.objectVelocity = ballVelocities[r.Next(0, ballVelocities.Count)];
                }
            }
            else
            {
                throw new Exception(_other.objectTag + " ball hit something bad");
            }
        }
Exemple #7
0
        public override void Initialize()
        {
            bg = new GameSprite("select\\background");
            bg.Scale(0.5f, 0.5f);
            AddSceneObject(bg);

            pole = new GameObject2D();
            pole.Translate(400, 240);
            AddSceneObject(pole);

            level1        = new GameAnimatedSprite("select\\levelunlockanimated", 4, 80, new Point(78, 76));
            level1.Origin = new Vector2(39, 38);
            level1.Translate(811, 597);
            AddSceneObject(level1);

            level2        = new GameSprite("select\\levellock");
            level2.Origin = new Vector2(39, 38);
            level2.Translate(800, 778);
            AddSceneObject(level2);

            level3        = new GameSprite("select\\levellock");
            level3.Origin = new Vector2(39, 38);
            level3.Translate(693, 755);
            AddSceneObject(level3);

            level4        = new GameSprite("select\\levellock");
            level4.Origin = new Vector2(39, 38);
            level4.Translate(1083, 831);
            AddSceneObject(level4);

            level1_b        = new GameButton("select\\levelunlock", false, true, true);
            level1_b.Origin = new Vector2(39, 38);
            level1_b.Translate(811, 597);
            level1_b.OnClick += () =>
            {
                if (!isLevelSelected)
                {
                    SceneManager.push.Play();
                    CameraManager.getInstance().camera.SetScreenCenter(4, 2);
                    CameraManager.getInstance().camera.Focus = level1_b;

                    level1.PlayAnimation(true);
                    SetBoxDraw(true);

                    isLevelSelected = true;
                }
            };
            AddSceneObject(level1_b);

            InitiateBox();
        }
        private void PlayerProjectile_OnCollision(GameObject2D _sender, GameObject2D _other)
        {
            EnemyShip enemyShip = _other as EnemyShip;

            if (enemyShip != null)
            {
                enemyShip.DoDamage(damage);
                this.Destroy();
            }
            else if (_other.objectTag == "wall")
            {
                this.Destroy();
            }
        }
Exemple #9
0
    public static void MoveTowards(GameObject2D obj, Vector2 dest, float step)
    {
        Vector2 direction = (dest - obj.pos2D).normalized;

        obj.SetPos2D(obj.pos2D + direction * step);
        //PrintXnaVec(obj.pos2D);


        if (Distance(obj.pos2D, dest) <= step)
        {
            //Console.WriteLine(obj.pos2D.X + "," + obj.pos2D.Y);
            //Console.WriteLine(dest.X + "," + dest.Y);
            obj.SetPos2D(new Vector2(dest.x, dest.y));
        }
    }
Exemple #10
0
        private void ScoreBox_OnCollision(GameObject2D _sender, GameObject2D _other)
        {
            EnemyShip enemy = _other as EnemyShip;

            if (enemy != null)
            {
                playerLife--;
                playerLifeText.text = playerLife.ToString();
                _other.Destroy();

                if (playerLife <= 0)
                {
                    gameManager.ChangeScene(1);
                    gameManager.ChangeUi(1);
                }
            }
        }
Exemple #11
0
        public int CheckCollision(GameObject2D sprite)
        {
            if (CurrentState == NoteState.Normal)
            {
                if (note.HitTest(sprite))
                {
                    // Find the bounds of the rectangle intersection
                    float top    = Math.Max(note.BoundingRect.Value.Top, sprite.BoundingRect.Value.Top);
                    float bottom = Math.Min(note.BoundingRect.Value.Bottom, sprite.BoundingRect.Value.Bottom);
                    float left   = Math.Max(note.BoundingRect.Value.Left, sprite.BoundingRect.Value.Left);
                    float right  = Math.Min(note.BoundingRect.Value.Right, sprite.BoundingRect.Value.Right);

                    float width  = right - left;
                    float height = bottom - top;

                    float area = width * height;

                    if (area > 100)
                    {
                        if (area > 800)
                        {
                            if (area >= 1500)
                            {
                                CurrentState = NoteState.Passed;
                                return(1);
                            }
                            CurrentState = NoteState.Passed;
                            return(3);
                        }
                        CurrentState = NoteState.Passed;
                        return(2);
                    }
                    return(0);
                }
                return(0);
            }
            return(0);
        }
Exemple #12
0
        } // RenderObjectToPicker

        /// <summary>
        /// Render Object To Picker.
        /// </summary>
        public void RenderObjectToPicker(GameObject gameObject, Color color)
        {
            if (gameObject is GameObject3D)
            {
                GameObject3D gameObject3D = (GameObject3D)gameObject;
                // Model Renderer)
                if (gameObject3D.ModelFilter != null && gameObject3D.ModelFilter.Model != null)
                {
                    constantShader.Resource.Parameters["diffuseColor"].SetValue(new Vector3(color.R / 255f, color.G / 255f, color.B / 255f));
                    constantShader.Resource.Parameters["worldViewProj"].SetValue(gameObject3D.Transform.WorldMatrix * viewMatrix * projectionMatrix);
                    constantShader.Resource.CurrentTechnique.Passes[0].Apply();
                    gameObject3D.ModelFilter.Model.Render();
                }
                // Lines
                else if (gameObject3D.LineRenderer != null)
                {
                    LineManager.Begin3D(gameObject3D.LineRenderer.PrimitiveType, viewMatrix, projectionMatrix);
                    for (int j = 0; j < gameObject3D.LineRenderer.Vertices.Length; j++)
                    {
                        LineManager.AddVertex(Vector3.Transform(gameObject3D.LineRenderer.Vertices[j].Position, gameObject3D.Transform.WorldMatrix), color);
                    }
                    LineManager.End();
                }
            }
            else
            {
                GameObject2D gameObject2D = (GameObject2D)gameObject;
                if (gameObject2D.LineRenderer != null)
                {
                    LineManager.Begin2D(gameObject2D.LineRenderer.PrimitiveType);
                    for (int j = 0; j < gameObject2D.LineRenderer.Vertices.Length; j++)
                    {
                        LineManager.AddVertex(Vector3.Transform(gameObject2D.LineRenderer.Vertices[j].Position, gameObject2D.Transform.WorldMatrix), color);
                    }
                    LineManager.End();
                }
            }
        } // RenderObjectToPicker
Exemple #13
0
        } // AddGameObjectControlsToInspector

        /// <summary>
        /// Add game object component controls to the specified control.
        /// </summary>
        public static void AddGameObjectControls(GameObject gameObject, ClipControl control)
        {
            if (gameObject == null)
            {
                throw new ArgumentNullException("gameObject");
            }
            if (control == null)
            {
                throw new ArgumentNullException("control");
            }

            #region Name

            var nameLabel = new Label
            {
                Parent    = control,
                Text      = "Name",
                Left      = 10,
                Top       = 10,
                Height    = 25,
                Alignment = Alignment.BottomCenter,
            };
            var nameTextBox = new TextBox
            {
                Parent = control,
                Width  = control.ClientWidth - nameLabel.Width - 12,
                Text   = gameObject.Name,
                Left   = 60,
                Top    = 10,
                Anchor = Anchors.Left | Anchors.Top | Anchors.Right
            };
            var lastSetName = gameObject.Name;
            nameTextBox.KeyDown += delegate(object sender, KeyEventArgs e)
            {
                if (e.Key == Keys.Enter)
                {
                    string oldName = gameObject.Name;
                    gameObject.Name = nameTextBox.Text; //asset.SetUniqueName(window.AssetName);
                    if (oldName != gameObject.Name)
                    {
                        nameTextBox.Text = gameObject.Name; // The name could be change if the name entered was not unique.
                        gameObject.Name  = oldName;         // This is done for the undo.
                        using (Transaction.Create())
                        {
                            // Apply the command and store for the undo feature.
                            ActionManager.SetProperty(gameObject, "Name", nameTextBox.Text);
                            ActionManager.CallMethod(// Redo
                                UserInterfaceManager.Invalidate,
                                // Undo
                                UserInterfaceManager.Invalidate);
                        }
                    }
                    lastSetName = gameObject.Name;
                }
            };
            nameTextBox.FocusLost += delegate
            {
                string oldName = gameObject.Name;
                gameObject.Name = nameTextBox.Text; //asset.SetUniqueName(window.AssetName);
                if (oldName != gameObject.Name)
                {
                    nameTextBox.Text = gameObject.Name; // The name could be change if the name entered was not unique.
                    gameObject.Name  = oldName;         // This is done for the undo.
                    using (Transaction.Create())
                    {
                        // Apply the command and store for the undo feature.
                        ActionManager.SetProperty(gameObject, "Name", nameTextBox.Text);
                        ActionManager.CallMethod(// Redo
                            UserInterfaceManager.Invalidate,
                            // Undo
                            UserInterfaceManager.Invalidate);
                    }
                    lastSetName = gameObject.Name;
                }
            };
            nameTextBox.Draw += delegate
            {
                if (lastSetName != gameObject.Name)
                {
                    lastSetName      = gameObject.Name;
                    nameTextBox.Text = gameObject.Name;
                }
            };

            #endregion

            #region Layer

            var comboBoxLayer = CommonControls.ComboBox("", control);
            comboBoxLayer.MaxItemsShow      = 30;
            comboBoxLayer.ItemIndexChanged += delegate
            {
                // Store new asset.
                if (gameObject.Layer.Number != comboBoxLayer.ItemIndex) // If it change
                {
                    using (Transaction.Create())
                    {
                        // Apply the command and store for the undo feature.
                        ActionManager.SetProperty(gameObject, "Layer", Layer.GetLayerByNumber(comboBoxLayer.ItemIndex));
                        ActionManager.CallMethod(// Redo
                            UserInterfaceManager.Invalidate,
                            // Undo
                            UserInterfaceManager.Invalidate);
                    }
                }
            };
            comboBoxLayer.Draw += delegate
            {
                // Add layer names here because someone could change them.
                comboBoxLayer.Items.Clear();
                for (int i = 0; i < 30; i++)
                {
                    comboBoxLayer.Items.Add(Layer.GetLayerByNumber(i).Name);
                }
                if (comboBoxLayer.ListBoxVisible)
                {
                    return;
                }
                // Identify current index
                comboBoxLayer.ItemIndex = gameObject.Layer.Number;
            };

            #endregion )

            #region Active

            CheckBox active = CommonControls.CheckBox("Active", control, gameObject.Active, gameObject, "Active");
            active.Top = comboBoxLayer.Top + 5;

            #endregion

            if (gameObject is GameObject3D)
            {
                GameObject3D gameObject3D = (GameObject3D)gameObject;

                #region Transform Component

                var panel = CommonControls.PanelCollapsible("Transform", control, 0);
                // Position
                var vector3BoxPosition = CommonControls.Vector3Box("Position", panel, gameObject3D.Transform.LocalPosition, gameObject3D.Transform, "LocalPosition");

                // Orientation.
                // This control has too many special cases, I need to do it manually.
                Vector3 initialValue = new Vector3(gameObject3D.Transform.LocalRotation.GetYawPitchRoll().Y * 180 / (float)Math.PI,
                                                   gameObject3D.Transform.LocalRotation.GetYawPitchRoll().X * 180 / (float)Math.PI,
                                                   gameObject3D.Transform.LocalRotation.GetYawPitchRoll().Z * 180 / (float)Math.PI);
                initialValue.X = (float)Math.Round(initialValue.X, 4);
                initialValue.Y = (float)Math.Round(initialValue.Y, 4);
                initialValue.Z = (float)Math.Round(initialValue.Z, 4);
                var vector3BoxRotation = CommonControls.Vector3Box("Rotation", panel, initialValue);
                vector3BoxRotation.ValueChanged += delegate
                {
                    Vector3 propertyValue = new Vector3(gameObject3D.Transform.LocalRotation.GetYawPitchRoll().Y * 180 / (float)Math.PI,
                                                        gameObject3D.Transform.LocalRotation.GetYawPitchRoll().X * 180 / (float)Math.PI,
                                                        gameObject3D.Transform.LocalRotation.GetYawPitchRoll().Z * 180 / (float)Math.PI);
                    // Round to avoid precision problems.
                    propertyValue.X = (float)Math.Round(propertyValue.X, 4);
                    propertyValue.Y = (float)Math.Round(propertyValue.Y, 4);
                    propertyValue.Z = (float)Math.Round(propertyValue.Z, 4);
                    // I compare the value of the transform property rounded to avoid a precision mismatch.
                    if (propertyValue != vector3BoxRotation.Value)
                    {
                        using (Transaction.Create())
                        {
                            Quaternion newValue = Quaternion.CreateFromYawPitchRoll(vector3BoxRotation.Value.Y * (float)Math.PI / 180,
                                                                                    vector3BoxRotation.Value.X * (float)Math.PI / 180,
                                                                                    vector3BoxRotation.Value.Z * (float)Math.PI / 180);
                            ActionManager.SetProperty(gameObject3D.Transform, "LocalRotation", newValue);
                            ActionManager.CallMethod(// Redo
                                UserInterfaceManager.Invalidate,
                                // Undo
                                UserInterfaceManager.Invalidate);
                        }
                    }
                };
                vector3BoxRotation.Draw += delegate
                {
                    Vector3 localRotationDegrees = new Vector3(gameObject3D.Transform.LocalRotation.GetYawPitchRoll().Y * 180 / (float)Math.PI,
                                                               gameObject3D.Transform.LocalRotation.GetYawPitchRoll().X * 180 / (float)Math.PI,
                                                               gameObject3D.Transform.LocalRotation.GetYawPitchRoll().Z * 180 / (float)Math.PI);
                    // Round to avoid precision problems.
                    localRotationDegrees.X = (float)Math.Round(localRotationDegrees.X, 4);
                    localRotationDegrees.Y = (float)Math.Round(localRotationDegrees.Y, 4);
                    localRotationDegrees.Z = (float)Math.Round(localRotationDegrees.Z, 4);
                    if (vector3BoxRotation.Value != localRotationDegrees)
                    {
                        vector3BoxRotation.Value = localRotationDegrees;
                    }
                };

                // Scale
                var vector3BoxScale = CommonControls.Vector3Box("Scale", panel, gameObject3D.Transform.LocalScale, gameObject3D.Transform, "LocalScale");

                #endregion

                #region Camera

                if (gameObject3D.Camera != null)
                {
                    var panelCamera = CommonControls.PanelCollapsible("Camera", control, 0);
                    CameraControls.AddControls(gameObject3D.Camera, panelCamera);
                }

                #endregion

                #region Model Filter

                if (gameObject3D.ModelFilter != null)
                {
                    var panelModelFilter = CommonControls.PanelCollapsible("Model Filter", control, 0);
                    ModelFilterControls.AddControls(gameObject3D.ModelFilter, panelModelFilter);
                }

                #endregion

                #region Model Renderer

                if (gameObject3D.ModelRenderer != null)
                {
                    var panelModelRenderer = CommonControls.PanelCollapsible("Model Renderer", control, 0);
                    ModelRendererControls.AddControls(gameObject3D.ModelRenderer, panelModelRenderer);
                }

                #endregion

                #region Light

                if (gameObject3D.Light != null)
                {
                    if (gameObject3D.SpotLight != null)
                    {
                        var panelSpotLight = CommonControls.PanelCollapsible("Spot Light", control, 0);
                        SpotLightControls.AddControls(gameObject3D.SpotLight, panelSpotLight);
                    }
                    if (gameObject3D.PointLight != null)
                    {
                        var panelPointLight = CommonControls.PanelCollapsible("Point Light", control, 0);
                        PointLightControls.AddControls(gameObject3D.PointLight, panelPointLight);
                    }
                    if (gameObject3D.DirectionalLight != null)
                    {
                        var panelDirectionalLight = CommonControls.PanelCollapsible("Directional Light", control, 0);
                        DirectionalLightControls.AddControls(gameObject3D.DirectionalLight, panelDirectionalLight);
                    }
                }

                #endregion
            }
            else
            {
                GameObject2D gameObject2D = (GameObject2D)gameObject;
            }
        } // AddGameObjectControls
Exemple #14
0
 public void CreateObject(GameObject2D gameObject)
 {
     Service.CreateGameObject();
 }
Exemple #15
0
 public static MyPoint CenterPosition(this GameObject2D obj)
 {
     return(new MyPoint(obj.Position.X + obj.Size.X / 2, obj.Position.Y + obj.Size.Y / 2));
 }
Exemple #16
0
        } // CreateSaveData

        #endregion

        #region Load Save Data

        /// <summary>
        /// Create the structure that will be serialized.
        /// It stores content managers, assets and game objects.
        /// </summary>
        private static void LoadSaveData(SceneData sceneData)
        {
            // Generate content managers data.
            foreach (var contentManagerData in sceneData.ContentManagersData)
            {
                // Create Content Manager
                AssetContentManager contentManager = new AssetContentManager { Name = contentManagerData.Name };
                foreach (var assetId in contentManagerData.AssetsId)
                {
                    // The not resourced assets are already created and can change the content manager without recreation.
                    foreach (var assetsWithoutResourceData in sceneData.AssetsWithoutResourceData)
                    {
                        if (assetId == assetsWithoutResourceData.Id)
                        {
                            assetsWithoutResourceData.Asset.ChangeContentManager(contentManager);
                            break;
                        }
                    }
                }
            }
            // Recreate game objects (and the transform component)
            foreach (var gameObjectData in sceneData.GameObjectData)
            {
                GameObject gameObject;
                if (gameObjectData.is3D)
                {
                    gameObject = new GameObject3D();
                    ((GameObject3D)gameObject).Transform.LocalMatrix = gameObjectData.LocalMatrix;
                }
                else
                {
                    gameObject = new GameObject2D();
                    ((GameObject2D)gameObject).Transform.LocalMatrix = gameObjectData.LocalMatrix;
                }
                gameObject.Name = gameObjectData.Name;
                gameObject.Layer = Layer.GetLayerByNumber(gameObjectData.LayerNumber);
                gameObject.Active = gameObjectData.Active;
                gameObjectData.NewGameObject = gameObject; // Use to recreate the hierarchy.
                foreach (var componentData in gameObjectData.ComponentData)
                {
                    // Create the component.
                    // Reflection is needed because we can't know the type in compiler time and I don't want to use an inflexible big switch sentence.
                    gameObject.GetType().GetMethod("AddComponent").MakeGenericMethod(componentData.Component.GetType()).Invoke(gameObject, null);
                    // Each serializable property will be copy to the new component.
                    PropertyInfo componentProperty = gameObject.GetType().GetProperty(componentData.Component.GetType().Name);
                    List<PropertyInfo> propertiesName = GetSerializableProperties(componentData.Component.GetType());
                    for (int i = 0; i < propertiesName.Count; i++)
                    {
                        var property = propertiesName[i];
                        Component component = (Component) componentProperty.GetValue(gameObject, null);
                        Object value = property.GetValue(componentData.Component, null);
                        property.SetValue(component, value, null);
                    }
                }
            }
            // Recreate hierarchy.
            foreach (var gameObjectData in sceneData.GameObjectData)
            {
                // If it is has a parent.
                if (gameObjectData.ParentId != long.MaxValue)
                {
                    // Search all loaded game objects
                    foreach (var searchedGameObjectData in sceneData.GameObjectData)
                    {
                        if (searchedGameObjectData.Id == gameObjectData.ParentId)
                        {
                            if (gameObjectData.is3D)
                                ((GameObject3D)gameObjectData.NewGameObject).Parent = (GameObject3D)searchedGameObjectData.NewGameObject;
                            else
                                ((GameObject2D)gameObjectData.NewGameObject).Parent = (GameObject2D)searchedGameObjectData.NewGameObject;
                            break;
                        }
                    }
                }
            }
        } // CreateSaveData
        /// <summary>
        /// Translation gizmo based in Softimage XSI.
        /// </summary>
        internal TranslationGizmo()
        {
            if (constantShader == null)
            {
                constantShader = new Shader("Materials\\PickerConstant");
            }
            // Create the gizmo parts.
            Cone cone = new Cone(0.1f, 0.2f, 10);

            redCone = new GameObject3D(cone, new Constant())
            {
                Layer = Layer.GetLayerByNumber(31)
            };
            greenCone = new GameObject3D(cone, new Constant())
            {
                Layer = Layer.GetLayerByNumber(31)
            };
            blueCone = new GameObject3D(cone, new Constant())
            {
                Layer = Layer.GetLayerByNumber(31)
            };
            lines = new GameObject3D {
                Layer = Layer.GetLayerByNumber(31),
            };
            lines.AddComponent <LineRenderer>();
            lines.LineRenderer.Vertices = new VertexPositionColor[6];
            vertices[0]   = new Vector3(0, 0, 0);
            vertices[1]   = new Vector3(1, 0, 0);
            vertices[2]   = new Vector3(0, 1, 0);
            vertices[3]   = new Vector3(0, 0, 1);
            vertices[4]   = new Vector3(1, 1, 0);
            vertices[5]   = new Vector3(0, 1, 1);
            vertices[6]   = new Vector3(1, 0, 1);
            planeRedGreen = new GameObject3D(new Plane(vertices[2], vertices[0], vertices[4], vertices[1]), new Constant {
                DiffuseColor = new Color(255, 255, 0)
            })
            {
                Layer = Layer.GetLayerByNumber(31),
            };
            planeGreenBlue = new GameObject3D(new Plane(vertices[5], vertices[3], vertices[2], vertices[0]), new Constant {
                DiffuseColor = new Color(0, 255, 255)
            })
            {
                Layer = Layer.GetLayerByNumber(31),
            };
            planeBlueRed = new GameObject3D(new Plane(vertices[0], vertices[3], vertices[1], vertices[6]), new Constant {
                DiffuseColor = new Color(255, 0, 255)
            })
            {
                Layer = Layer.GetLayerByNumber(31),
            };
            planeRedGreenInv = new GameObject3D(new Plane(vertices[4], vertices[1], vertices[2], vertices[0]), new Constant {
                DiffuseColor = new Color(255, 255, 0)
            })
            {
                Layer = Layer.GetLayerByNumber(31),
            };
            planeGreenBlueInv = new GameObject3D(new Plane(vertices[2], vertices[0], vertices[5], vertices[3]), new Constant {
                DiffuseColor = new Color(0, 255, 255)
            })
            {
                Layer = Layer.GetLayerByNumber(31),
            };
            planeBlueRedInv = new GameObject3D(new Plane(vertices[1], vertices[6], vertices[0], vertices[3]), new Constant {
                DiffuseColor = new Color(255, 0, 255)
            })
            {
                Layer = Layer.GetLayerByNumber(31),
            };
            planeAll = new GameObject2D {
                Layer = Layer.GetLayerByNumber(31),
            };
            planeAll.AddComponent <LineRenderer>();
            planeAll.LineRenderer.Vertices = new VertexPositionColor[8];

            redCone.ModelRenderer.Enabled           = false;
            greenCone.ModelRenderer.Enabled         = false;
            blueCone.ModelRenderer.Enabled          = false;
            lines.LineRenderer.Enabled              = false;
            planeRedGreen.ModelRenderer.Enabled     = false;
            planeGreenBlue.ModelRenderer.Enabled    = false;
            planeBlueRed.ModelRenderer.Enabled      = false;
            planeRedGreenInv.ModelRenderer.Enabled  = false;
            planeGreenBlueInv.ModelRenderer.Enabled = false;
            planeBlueRedInv.ModelRenderer.Enabled   = false;
            planeAll.LineRenderer.Enabled           = false;
        } // TranslationGizmo
        /// <summary>
        /// Load the resources.
        /// </summary>
        /// <remarks>Remember to call the base implementation of this method.</remarks>
        protected override void LoadContent()
        {
            mainSceneExecuting = true;

            #region Setup Input Controls

            // Create the virtual buttons to control the scene selection.
            new Button
            {
                Name           = "Next Scene",
                ButtonBehavior = Button.ButtonBehaviors.DigitalInput,
                KeyButton      = new KeyButton(Keys.Right),
            };
            new Button
            {
                Name           = "Next Scene",
                ButtonBehavior = Button.ButtonBehaviors.DigitalInput,
                KeyButton      = new KeyButton(Buttons.DPadRight),
            };
            new Button
            {
                Name           = "Next Scene",
                ButtonBehavior = Button.ButtonBehaviors.AnalogInput,
                AnalogAxis     = AnalogAxes.LeftStickX,
            };
            new Button
            {
                Name           = "Previous Scene",
                ButtonBehavior = Button.ButtonBehaviors.DigitalInput,
                KeyButton      = new KeyButton(Keys.Left),
            };
            new Button
            {
                Name           = "Previous Scene",
                ButtonBehavior = Button.ButtonBehaviors.DigitalInput,
                KeyButton      = new KeyButton(Buttons.DPadLeft),
            };
            new Button
            {
                Name           = "Previous Scene",
                ButtonBehavior = Button.ButtonBehaviors.AnalogInput,
                AnalogAxis     = AnalogAxes.LeftStickX,
                Invert         = true,
            };
            new Button
            {
                Name           = "Load Scene",
                ButtonBehavior = Button.ButtonBehaviors.DigitalInput,
                KeyButton      = new KeyButton(Keys.Enter),
            };
            new Button
            {
                Name           = "Load Scene",
                ButtonBehavior = Button.ButtonBehaviors.DigitalInput,
                KeyButton      = new KeyButton(Buttons.A),
            };
            new Button
            {
                Name           = "Back To Menu",
                ButtonBehavior = Button.ButtonBehaviors.DigitalInput,
                KeyButton      = new KeyButton(Keys.Escape),
            };
            new Button
            {
                Name           = "Back To Menu",
                ButtonBehavior = Button.ButtonBehaviors.DigitalInput,
                KeyButton      = new KeyButton(Buttons.Back),
            };
            new Button
            {
                Name           = "Show Statistics",
                ButtonBehavior = Button.ButtonBehaviors.DigitalInput,
                KeyButton      = new KeyButton(Keys.F1),
            };
            new Button
            {
                Name           = "Show Statistics",
                ButtonBehavior = Button.ButtonBehaviors.DigitalInput,
                KeyButton      = new KeyButton(Buttons.Start),
            };

            #endregion

            #region Intro Video

            // Load and play the intro video...
            introVideo = new GameObject2D();
            introVideo.AddComponent <VideoRenderer>();
            introVideo.VideoRenderer.Video = new Video("LogosIntro");

            #endregion

            #region Statistics

            Layer.GetLayerByNumber(26).Name    = "Statistics Layer";
            Layer.CurrentCreationLayer         = Layer.GetLayerByNumber(26);
            Layer.GetLayerByNumber(26).Visible = false;
            statistics = new GameObject2D();
            statistics.AddComponent <ScriptStatisticsDrawer>();

            #endregion

            // This scene will be assigned to this layer.
            Layer.GetLayerByNumber(25).Name = "Examples Main Scene Layer";
            // But we hide it until the video is over.
            Layer.GetLayerByNumber(25).Visible = false;
            // Creates the scene objects in this layer;
            Layer.CurrentCreationLayer = Layer.GetLayerByNumber(25);

            #region 3D Camera

            // Camera
            examplesCamera = new GameObject3D();
            examplesCamera.AddComponent <Camera>();
            examplesCamera.AddComponent <SoundListener>();
            examplesCamera.Camera.RenderTargetSize = Size.FullScreen;
            examplesCamera.Camera.FarPlane         = 100;
            examplesCamera.Camera.NearPlane        = 1f; // Do not place a small value here, you can destroy performance, not just precision.
            examplesCamera.Transform.LookAt(new Vector3(0, 0, 25), Vector3.Zero, Vector3.Up);
            examplesCamera.Camera.ClearColor  = Color.Black;
            examplesCamera.Camera.FieldOfView = 180 / 6f;
            examplesCamera.Camera.PostProcess = new PostProcess();
            examplesCamera.Camera.PostProcess.ToneMapping.AutoExposureEnabled = false;
            examplesCamera.Camera.PostProcess.ToneMapping.LensExposure        = 0f;
            examplesCamera.Camera.PostProcess.ToneMapping.ToneMappingFunction = ToneMapping.ToneMappingFunctionEnumerate.FilmicALU;
            examplesCamera.Camera.PostProcess.MLAA.EdgeDetection = MLAA.EdgeDetectionType.Color;
            examplesCamera.Camera.PostProcess.MLAA.Enabled       = true;
            examplesCamera.Camera.AmbientLight = new AmbientLight
            {
                Color     = new Color(80, 75, 85),
                Intensity = 5f,
            };

            #endregion

            finalEngineLogo = new GameObject3D(new FileModel("XNAFinalEngine"), new BlinnPhong {
                DiffuseColor = new Color(250, 250, 250)
            });
            finalEngineLogo.Transform.Position   = new Vector3(-37, 6, 0);
            finalEngineLogo.Transform.LocalScale = new Vector3(1.3f, 1.3f, 1.3f);

            xnaLogo = new GameObject3D(new FileModel("XNA"), new BlinnPhong {
                DiffuseColor = new Color(250, 120, 0)
            });
            xnaLogo.Transform.Position   = new Vector3(-37, 6, 0);
            xnaLogo.Transform.LocalScale = new Vector3(1.3f, 1.3f, 1.3f);

            examplesLogo = new GameObject3D(new FileModel("Examples"), new BlinnPhong {
                DiffuseColor = new Color(150, 250, 0)
            });
            examplesLogo.Transform.Position   = new Vector3(40, 5.7f, 0);
            examplesLogo.Transform.LocalScale = new Vector3(1f, 1f, 1f);

            selectOneScene = new GameObject3D(new FileModel("SelectOneScene"), new BlinnPhong {
                DiffuseColor = new Color(150, 250, 0)
            });
            selectOneScene.Transform.Position = new Vector3(6, -55, 0);

            loading = new GameObject3D(new FileModel("Loading"), new BlinnPhong {
                DiffuseColor = new Color(150, 150, 150)
            });
            loading.Transform.Position    = new Vector3(-7, -5, 0);
            loading.ModelRenderer.Enabled = false;

            directionalLight = new GameObject3D();
            directionalLight.AddComponent <DirectionalLight>();
            directionalLight.DirectionalLight.Color     = new Color(190, 110, 150);
            directionalLight.DirectionalLight.Intensity = 1.2f;
            directionalLight.Transform.LookAt(new Vector3(0.6f, 0.05f, 0.6f), Vector3.Zero, Vector3.Forward);

            #region Scene Information

            exampleImage = new GameObject2D[4];
            exampleTitle = new GameObject2D[4];
            exampleText  = new GameObject2D[4];

            #region Warehouse Scene

            exampleImage[0] = new GameObject2D();
            exampleImage[0].AddComponent <HudTexture>();
            exampleImage[0].HudTexture.Texture = new Texture("ExamplesImages\\WarehouseScene");
            exampleImage[0].Transform.Position = new Vector3(75, 250, 0);
            exampleTitle[0] = new GameObject2D();
            exampleTitle[0].AddComponent <HudText>();
            exampleTitle[0].HudText.Text.Append("Warehouse");
            exampleTitle[0].HudText.Font       = new Font("BellGothicTitle");
            exampleTitle[0].Transform.Position = new Vector3(500, 200, 0);
            exampleText[0] = new GameObject2D();
            exampleText[0].AddComponent <HudText>();
            exampleText[0].HudText.Text.Append("This scene shows a Lamborghini Murcielago LP640 in a warehouse.\n\nThe car consists of 430.000 polygons. The scene includes an ambient light with spherical\nharmonic lighting and horizon based ambient occlusion (PC only), one directional light\nwith cascade shadows,two point lights and one spot light with a light mask. The post\nprocessing stage uses tone mapping, morphological antialiasing (MLAA), bloom and film\ngrain. Also a particles system that emits soft tiled particles was placed.\n\nAlmost all the car was modeled by me, with the exception of some interior elements, the\nengine and the rear lights because of my lack of texture experience and time.\n\nMehar Gill (Dog Fight Studios) provides me the warehouse model (originally created\nby igorlmax).\n\nThe reflections do not match the environment. I plan to address this soon.");
            exampleText[0].HudText.Font       = new Font("BellGothicText");
            exampleText[0].Transform.Position = new Vector3(500, 250, 0);

            #endregion

            #region Physics Scene

            exampleImage[1] = new GameObject2D();
            exampleImage[1].AddComponent <HudTexture>();
            exampleImage[1].HudTexture.Texture = new Texture("ExamplesImages\\PhysicsScene");
            exampleImage[1].Transform.Position = new Vector3(75, 250, 0);
            exampleTitle[1] = new GameObject2D();
            exampleTitle[1].AddComponent <HudText>();
            exampleTitle[1].HudText.Text.Append("Physics Demonstration");
            exampleTitle[1].HudText.Font       = new Font("BellGothicTitle");
            exampleTitle[1].Transform.Position = new Vector3(500, 200, 0);
            exampleText[1] = new GameObject2D();
            exampleText[1].AddComponent <HudText>();
            exampleText[1].HudText.Text.Append("Bepu physics library was integrated on the engine through a simple interface that hides the\ncommunication between the physic and graphic world.\n\nThis example shows the interaction between dynamic and kinematic rigid bodies and static\nmeshes. This example also loads a non-centered sphere, the interface implemented detects\nthe offset between the center of mass of the object and the model space center and match\nboth representations without user action.\n\nGarbage generation could be avoided if the initial pools are configured correctly and no other\nmemory allocation should occur. Bepu physics 1.2 has a bug in witch garbage is generated,\nto avoid this we use the developement version of Bepu that fix this bug.\n\n");
            exampleText[1].HudText.Font       = new Font("BellGothicText");
            exampleText[1].Transform.Position = new Vector3(500, 250, 0);

            #endregion

            #region Animation Scene

            exampleImage[2] = new GameObject2D();
            exampleImage[2].AddComponent <HudTexture>();
            exampleImage[2].HudTexture.Texture = new Texture("ExamplesImages\\AnimationScene");
            exampleImage[2].Transform.Position = new Vector3(75, 250, 0);
            exampleTitle[2] = new GameObject2D();
            exampleTitle[2].AddComponent <HudText>();
            exampleTitle[2].HudText.Text.Append("Animations");
            exampleTitle[2].HudText.Font       = new Font("BellGothicTitle");
            exampleTitle[2].Transform.Position = new Vector3(500, 200, 0);
            exampleText[2] = new GameObject2D();
            exampleText[2].AddComponent <HudText>();
            exampleText[2].HudText.Text.Append("This is the simple scene used to test the animation system. It includes three animations:\nwalk, run and shoot. Animation blending is performed in the transition between different\nactions.\n\nDog Fight Studios have shared with us three of their test animations resources. However\nthe animations should not be used in commercial projects.");
            exampleText[2].HudText.Font       = new Font("BellGothicText");
            exampleText[2].Transform.Position = new Vector3(500, 250, 0);

            #endregion

            #region Hellow World Scene

            exampleImage[3] = new GameObject2D();
            exampleImage[3].AddComponent <HudTexture>();
            exampleImage[3].HudTexture.Texture = new Texture("ExamplesImages\\HelloWorldScene");
            exampleImage[3].Transform.Position = new Vector3(75, 250, 0);
            exampleTitle[3] = new GameObject2D();
            exampleTitle[3].AddComponent <HudText>();
            exampleTitle[3].HudText.Text.Append("Hello World");
            exampleTitle[3].HudText.Font       = new Font("BellGothicTitle");
            exampleTitle[3].Transform.Position = new Vector3(500, 200, 0);
            exampleText[3] = new GameObject2D();
            exampleText[3].AddComponent <HudText>();
            exampleText[3].HudText.Text.Append("This is from the documentation's tutorial that shows you how to create a simple scene\nso that you can understand the basic mechanism involved in the creation of a game world.");
            exampleText[3].HudText.Font       = new Font("BellGothicText");
            exampleText[3].Transform.Position = new Vector3(500, 250, 0);

            #endregion

            #region Editor Scene

            /*#if !Xbox
             *  exampleImage[3] = new GameObject2D();
             *  exampleImage[3].AddComponent<HudTexture>();
             *  exampleImage[3].HudTexture.Texture = new Texture("ExamplesImages\\EditorScene");
             *  exampleImage[3].Transform.Position = new Vector3(75, 250, 0);
             *  exampleTitle[3] = new GameObject2D();
             *  exampleTitle[3].AddComponent<HudText>();
             *  exampleTitle[3].HudText.Text.Append("Editor");
             *  exampleTitle[3].HudText.Font = new Font("BellGothicTitle");
             *  exampleTitle[3].Transform.Position = new Vector3(500, 200, 0);
             *  exampleText[3] = new GameObject2D();
             *  exampleText[3].AddComponent<HudText>();
             *  exampleText[3].HudText.Text.Append("Unfortunately the editor is not finished, but most of the key elements are already done and it is\nvery easy to create new windows because everything is parameterized (thanks in part to .NET\nreflection) and its internal code is very clean.\n\nAt the moment it is possible to transform objects in global and local space, configure materials,\nlights, shadows, cameras and the post processing stage. You can also see the scene from\northographic views and perform undo and redo operations over almost all editor commands.\n\nIn the Editor Shortcuts section of the CodePlex documentation there is a list of all useful\nkeyboard shortcuts.");
             *  exampleText[3].HudText.Font = new Font("BellGothicText");
             *  exampleText[3].Transform.Position = new Vector3(500, 250, 0);
             #endif*/

            #endregion

            #endregion

            #region Legend

            demoLegend = new GameObject2D();
            var legend = (HudText)demoLegend.AddComponent <HudText>();
            legend.Color = new Color(0.5f, 0.5f, 0.5f, 1f);
            #if XBOX
            legend.Text.Append("Start to show the statistics\n");
            legend.Text.Append("Back to comeback to this menu");
            #else
            legend.Text.Append("Start or F1 to show the statistics\n");
            legend.Text.Append("Back or Escape to comeback to this menu");
            #endif

            #endregion

            // Set Default Layer.
            Layer.CurrentCreationLayer = Layer.GetLayerByNumber(0);

            MusicManager.LoadAllSong(true);
            MusicManager.Play(1, true);
        } // Load
Exemple #19
0
        /// <summary>
        /// Load the resources.
        /// </summary>
        protected override void LoadContent()
        {

            #region Camera
            
            camera = new GameObject3D();
            camera.AddComponent<Camera>();
            camera.AddComponent<SoundListener>();
            camera.Camera.RenderTargetSize = Size.FullScreen;
            camera.Camera.FarPlane = 300;
            camera.Camera.NearPlane = 1f; // Do not place a small value here, you can destroy performance, not just precision.
            camera.Transform.LookAt(new Vector3(0, 0, 15), Vector3.Zero, Vector3.Up);
            WarehouseCameraScript script = (WarehouseCameraScript)camera.AddComponent<WarehouseCameraScript>();
            //script.SetPosition(new Vector3(0, 3, 18), new Vector3(0, 1.5f, 2.2f));
            script.SetPosition(new Vector3(10, 3, 18), new Vector3(0, 1.5f, 3.2f));
            camera.Camera.ClearColor = Color.Black;
            camera.Camera.FieldOfView = 180 / 7f;
            camera.Camera.PostProcess = new PostProcess();
            camera.Camera.PostProcess.ToneMapping.AutoExposureEnabled = false;
            camera.Camera.PostProcess.ToneMapping.LensExposure = -0.5f;
            camera.Camera.PostProcess.ToneMapping.ToneMappingFunction = ToneMapping.ToneMappingFunctionEnumerate.FilmicALU;
            camera.Camera.PostProcess.MLAA.EdgeDetection = MLAA.EdgeDetectionType.Color;
            camera.Camera.PostProcess.MLAA.Enabled = true;
            camera.Camera.PostProcess.Bloom.Enabled = true;
            camera.Camera.PostProcess.Bloom.Threshold = 3f;
            camera.Camera.PostProcess.FilmGrain.Enabled = true;
            camera.Camera.PostProcess.FilmGrain.Strength = 0.15f;
            /*camera.Camera.PostProcess.AdjustLevels.Enabled = true;
            camera.Camera.PostProcess.AdjustLevels.InputGamma = 0.9f;
            camera.Camera.PostProcess.AdjustLevels.InputWhite = 0.95f;*/
            camera.Camera.PostProcess.AnamorphicLensFlare.Enabled = false;
            camera.Camera.PostProcess.ColorCorrection.Enabled = true;
            camera.Camera.PostProcess.ColorCorrection.FirstLookupTable = new LookupTable("LookupTableWarehouse"); // A little more red and blue.
            camera.Camera.AmbientLight = new AmbientLight
            {
                SphericalHarmonicLighting = SphericalHarmonicL2.GenerateSphericalHarmonicFromCubeTexture(new TextureCube("FactoryCatwalkRGBM") { IsRgbm = true, RgbmMaxRange = 50, }),
                Color = new Color(10, 10, 10),
                Intensity = 2f,
                AmbientOcclusionStrength = 1.5f
            };
            //camera.Camera.Sky = new Skydome { Texture = new Texture("HotPursuitSkydome") };
            //camera.Camera.Sky = new Skybox { TextureCube = new TextureCube("FactoryCatwalkRGBM") { IsRgbm = true, RgbmMaxRange = 50, } };
            #if !XBOX
                camera.Camera.AmbientLight.AmbientOcclusion = new HorizonBasedAmbientOcclusion
                {
                    NumberSteps = 12,
                    NumberDirections = 12,
                    Radius = 0.003f, // Bigger values produce more cache misses and you don’t want GPU cache misses, trust me.
                    LineAttenuation = 1.0f,
                    Contrast = 1.1f,
                    AngleBias = 0.1f,
                    Quality = HorizonBasedAmbientOcclusion.QualityType.HighQuality,
                    TextureSize = Size.TextureSize.HalfSize,
                };
            #endif

            #region Test Split Screen
            /*
            camera.Camera.NormalizedViewport = new RectangleF(0, 0, 1, 0.5f);
            camera2 = new GameObject3D();
            camera2.AddComponent<Camera>();
            camera2.Camera.MasterCamera = camera.Camera;
            camera2.Camera.ClearColor = Color.Black;
            camera2.Camera.FieldOfView = 180 / 8.0f;
            camera2.Camera.NormalizedViewport = new RectangleF(0, 0.5f, 1, 0.5f);
            camera2.Transform.LookAt(new Vector3(-5, 5, -15), new Vector3(0, 3, 0), Vector3.Up);
            camera2.Camera.AmbientLight = camera.Camera.AmbientLight;
            camera2.Camera.PostProcess = new PostProcess();
            camera2.Camera.PostProcess.ToneMapping.AutoExposureEnabled = true;
            camera2.Camera.PostProcess.ToneMapping.LensExposure = 0.5f;
            camera2.Camera.PostProcess.ToneMapping.ToneMappingFunction = ToneMapping.ToneMappingFunctionEnumerate.FilmicALU;
            camera2.Camera.PostProcess.MLAA.EdgeDetection = MLAA.EdgeDetectionType.Color;
            camera2.Camera.PostProcess.MLAA.Enabled = true;
            camera2.Camera.PostProcess.Bloom.Enabled = true;
            camera2.Camera.PostProcess.Bloom.Threshold = 3f;
            camera2.Camera.PostProcess.FilmGrain.Enabled = true;
            camera2.Camera.PostProcess.FilmGrain.Strength = 0.15f;
            */
            #endregion

            #endregion
            
            #region Models
            
            #if XBOX
                warehouseWalls = new GameObject3D(new FileModel("Warehouse\\WarehouseWallsXbox"),
                                                  new BlinnPhong
                                                      {
                                                          DiffuseTexture = new Texture("Warehouse\\Warehouse-DiffuseXbox"),
                                                          SpecularTexture = new Texture("Warehouse\\Warehouse-SpecularXbox"),
                                                          SpecularIntensity = 3,
                                                          SpecularPower = 30000,
                                                      });
                warehouseRoof  = new GameObject3D(new FileModel("Warehouse\\WarehouseRoofXbox"),  
                                                  new BlinnPhong
                                                      {
                                                          DiffuseTexture = new Texture("Warehouse\\MetalRoof-DiffuseXbox")
                                                      });
                warehouseRoof1 = new GameObject3D(new FileModel("Warehouse\\WarehouseRoof1Xbox"),
                                                  new BlinnPhong
                                                  {
                                                      DiffuseTexture = new Texture("Warehouse\\MetalRoof2-DiffuseXbox")
                                                  });

                warehouseWood = new GameObject3D(new FileModel("Warehouse\\WarehouseWoodXbox"),
                                                 new BlinnPhong
                                                 {
                                                     DiffuseTexture = new Texture("Warehouse\\Wood-DiffuseXbox")
                                                 });

                warehouseWood2 = new GameObject3D(new FileModel("Warehouse\\WarehouseWood2Xbox"),
                                                  new BlinnPhong
                                                  {
                                                      DiffuseTexture = new Texture("Warehouse\\Wood2-DiffuseXbox")
                                                  });

                warehouseBrokenWindow = new GameObject3D(new FileModel("Warehouse\\WarehouseBrokenWindowXbox"),
                                                 new BlinnPhong
                                                 {
                                                     DiffuseTexture = new Texture("Warehouse\\Window-DiffuseXbox")
                                                 });

                warehouseWindow = new GameObject3D(new FileModel("Warehouse\\WarehouseWindowXbox"),
                                                  new BlinnPhong
                                                  {
                                                      DiffuseTexture = new Texture("Warehouse\\Window-DiffuseXbox")
                                                  });
                warehouseGround = new GameObject3D(new FileModel("Warehouse\\WarehouseGroundXbox"),
                                                  new BlinnPhong
                                                  {
                                                      DiffuseTexture = new Texture("Warehouse\\Ground-DiffuseXbox"),
                                                      NormalTexture = new Texture("Warehouse\\Ground-NormalsXbox"),
                                                      SpecularIntensity = 0.7f
                                                  });
            #else
                warehouseWalls = new GameObject3D(new FileModel("Warehouse\\WarehouseWalls"),
                                                  new BlinnPhong
                                                      {
                                                          DiffuseTexture = new Texture("Warehouse\\Warehouse-Diffuse"),
                                                          SpecularTexture = new Texture("Warehouse\\Warehouse-Specular"),
                                                          SpecularIntensity = 3,
                                                          SpecularPower = 30000,
                                                      });
                warehouseRoof  = new GameObject3D(new FileModel("Warehouse\\WarehouseRoof"),  
                                                  new BlinnPhong
                                                      {
                                                          DiffuseTexture = new Texture("Warehouse\\MetalRoof-Diffuse")
                                                      });
                warehouseRoof1 = new GameObject3D(new FileModel("Warehouse\\WarehouseRoof1"),
                                                  new BlinnPhong
                                                  {
                                                      DiffuseTexture = new Texture("Warehouse\\MetalRoof2-Diffuse")
                                                  });

                warehouseWood = new GameObject3D(new FileModel("Warehouse\\WarehouseWood"),
                                                 new BlinnPhong
                                                 {
                                                     DiffuseTexture = new Texture("Warehouse\\Wood-Diffuse")
                                                 });

                warehouseWood2 = new GameObject3D(new FileModel("Warehouse\\WarehouseWood2"),
                                                  new BlinnPhong
                                                  {
                                                      DiffuseTexture = new Texture("Warehouse\\Wood2-Diffuse")
                                                  });

                warehouseBrokenWindow = new GameObject3D(new FileModel("Warehouse\\WarehouseBrokenWindow"),
                                                 new BlinnPhong
                                                 {
                                                     DiffuseTexture = new Texture("Warehouse\\Window-Diffuse")
                                                 });

                warehouseWindow = new GameObject3D(new FileModel("Warehouse\\WarehouseWindow"),
                                                  new BlinnPhong
                                                  {
                                                      DiffuseTexture = new Texture("Warehouse\\Window-Diffuse")
                                                  });
                warehouseGround = new GameObject3D(new FileModel("Warehouse\\WarehouseGround"),
                                                  new BlinnPhong
                                                  {
                                                      DiffuseTexture = new Texture("Warehouse\\Ground-Diffuse"),
                                                      NormalTexture = new Texture("Warehouse\\Ground-Normals"),
                                                      SpecularIntensity = 0.7f
                                                  });
            #endif

            #endregion
            
            #region Shadows and Lights

            Shadow.DistributeShadowCalculationsBetweenFrames = true;
            
            directionalLight = new GameObject3D();
            directionalLight.AddComponent<DirectionalLight>();
            directionalLight.DirectionalLight.Color = new Color(190, 190, 150);
            directionalLight.DirectionalLight.Intensity = 9.2f;
            directionalLight.Transform.LookAt(new Vector3(0.3f, 0.95f, -0.3f), Vector3.Zero, Vector3.Forward);
            DirectionalLight.Sun = directionalLight.DirectionalLight;
            directionalLight.DirectionalLight.Shadow = new CascadedShadow
            {
                Filter = Shadow.FilterType.PcfPosion,
                LightDepthTextureSize = Size.Square512X512,
                ShadowTextureSize = Size.TextureSize.FullSize, // Lower than this could produce artifacts if the light is too intense.
                DepthBias = 0.0025f,
                FarPlaneSplit1 = 15,
                FarPlaneSplit2 = 40,
                FarPlaneSplit3 = 100,
                //FarPlaneSplit4 = 150
            };
            /*directionalLight.DirectionalLight.Shadow = new BasicShadow
            {
                Filter = Shadow.FilterType.PcfPosion,
                LightDepthTextureSize = Size.Square512X512,
                ShadowTextureSize = Size.TextureSize.FullSize, // Lower than this could produce artifacts if the light is to intense.
                DepthBias = 0.0025f,
                Range = 100,
            };*/
            
            pointLight = new GameObject3D();
            pointLight.AddComponent<PointLight>();
            pointLight.PointLight.Color = new Color(180, 190, 230);
            pointLight.PointLight.Intensity = 0.3f;
            pointLight.PointLight.Range = 60;
            pointLight.Transform.Position = new Vector3(4.8f, 1.5f, 10);
            //pointLight.PointLight.Shadow = new CubeShadow { LightDepthTextureSize = 512, };

            pointLight = new GameObject3D();
            pointLight.AddComponent<PointLight>();
            pointLight.PointLight.Color = new Color(130, 130, 190);
            pointLight.PointLight.Intensity = 0.7f;
            pointLight.PointLight.Range = 60;
            pointLight.Transform.Position = new Vector3(-4.8f, 0, -4);

            /*pointLightClipVolumeTest = new GameObject3D();
            pointLightClipVolumeTest.AddComponent<PointLight>();
            pointLightClipVolumeTest.PointLight.Color = new Color(250, 20, 20);
            pointLightClipVolumeTest.PointLight.Intensity = 2f;
            pointLightClipVolumeTest.PointLight.Range = 60;
            pointLightClipVolumeTest.PointLight.ClipVolume = new FileModel("ClipVolume");
            pointLightClipVolumeTest.PointLight.RenderClipVolumeInLocalSpace = true;
            pointLightClipVolumeTest.Transform.Position = new Vector3(26f, 7, 35);*/

            spotLight = new GameObject3D();
            spotLight.AddComponent<SpotLight>();
            spotLight.SpotLight.Color = new Color(0, 250, 0);
            spotLight.SpotLight.Intensity = 0.5f;
            spotLight.SpotLight.Range = 40; // I always forget to set the light range lower than the camera far plane.
            spotLight.Transform.Position = new Vector3(0, 16, 15);
            spotLight.Transform.Rotate(new Vector3(-80, 0, 0));
            spotLight.SpotLight.LightMaskTexture = new Texture("LightMasks\\TestLightMask");
            /*spotLight.SpotLight.Shadow = new BasicShadow
            {
                Filter = Shadow.FilterType.PcfPosion,
                LightDepthTextureSize = Size.Square512X512,
                ShadowTextureSize = Size.TextureSize.FullSize,
                DepthBias = 0.0005f,
            };*/
            
            #endregion
            
            #region Lamborghini Murcielago LP640
           
            lamborghiniMurcielagoLoader = new LamborghiniMurcielagoLoader();
            lamborghiniMurcielagoLoader.LoadContent();
            lamborghiniMurcielagoLoader.LamborghiniMurcielago.Transform.LocalScale = new Vector3(1.2f, 1.2f, 1.2f);
            lamborghiniMurcielagoLoader.LamborghiniMurcielago.Transform.LocalPosition = new Vector3(0, 1.4f, 2.35f);
            lamborghiniMurcielagoLoader.TiresAngle = -40;
            
            #endregion

            #region Particles
            
            // Pit particles
            GameObject3D particles = new GameObject3D();
            particles.AddComponent<ParticleEmitter>();
            particles.AddComponent<ParticleRenderer>();
            particles.ParticleEmitter.MaximumNumberParticles = 75;
            particles.Transform.LocalPosition = new Vector3(-1.2f, 0, -13);
            particles.ParticleEmitter.Duration = 50f;
            particles.ParticleEmitter.EmitterVelocitySensitivity = 1;
            particles.ParticleEmitter.MinimumHorizontalVelocity = 1;
            particles.ParticleEmitter.MaximumHorizontalVelocity = 2f;
            particles.ParticleEmitter.MinimumVerticalVelocity = 1;
            particles.ParticleEmitter.MaximumVerticalVelocity = 2;
            particles.ParticleRenderer.Texture = new Texture("Particles\\Smoke");
            particles.ParticleRenderer.SoftParticles = true;
            particles.ParticleRenderer.FadeDistance = 25.0f;
            particles.ParticleRenderer.BlendState = BlendState.NonPremultiplied;
            particles.ParticleRenderer.DurationRandomness = 0.1f;
            particles.ParticleRenderer.Gravity = new Vector3(0, 1, 5);
            particles.ParticleRenderer.EndVelocity = 0.75f;
            particles.ParticleRenderer.MinimumColor = Color.Red;
            particles.ParticleRenderer.MaximumColor = Color.White;
            particles.ParticleRenderer.RotateSpeed = new Vector2(-0.3f, 0.25f);
            particles.ParticleRenderer.StartSize = new Vector2(25, 30);
            particles.ParticleRenderer.EndSize = new Vector2(75, 100);
            particles.ParticleRenderer.TilesX = 1;
            particles.ParticleRenderer.TilesY = 1;
            particles.ParticleRenderer.AnimationRepetition = 1;

            particles = new GameObject3D();
            particles.AddComponent<ParticleEmitter>();
            particles.AddComponent<ParticleRenderer>();
            particles.ParticleEmitter.MaximumNumberParticles = 75;
            particles.Transform.LocalPosition = new Vector3(-3.2f, 0, 13);
            particles.ParticleEmitter.Duration = 50f;
            particles.ParticleEmitter.EmitterVelocitySensitivity = 1;
            particles.ParticleEmitter.MinimumHorizontalVelocity = 1;
            particles.ParticleEmitter.MaximumHorizontalVelocity = 2f;
            particles.ParticleEmitter.MinimumVerticalVelocity = 1;
            particles.ParticleEmitter.MaximumVerticalVelocity = 2;
            particles.ParticleRenderer.Texture = new Texture("Particles\\Smoke");
            particles.ParticleRenderer.SoftParticles = true;
            particles.ParticleRenderer.FadeDistance = 25.0f;
            particles.ParticleRenderer.BlendState = BlendState.NonPremultiplied;
            particles.ParticleRenderer.DurationRandomness = 0.1f;
            particles.ParticleRenderer.Gravity = new Vector3(0, 1, -5);
            particles.ParticleRenderer.EndVelocity = 0.75f;
            particles.ParticleRenderer.MinimumColor = Color.Red;
            particles.ParticleRenderer.MaximumColor = Color.White;
            particles.ParticleRenderer.RotateSpeed = new Vector2(-0.2f, 0.2f);
            particles.ParticleRenderer.StartSize = new Vector2(25, 50);
            particles.ParticleRenderer.EndSize = new Vector2(75, 100);
            particles.ParticleRenderer.TilesX = 1;
            particles.ParticleRenderer.TilesY = 1;
            particles.ParticleRenderer.AnimationRepetition = 1;
            
            #endregion

            #region Statistics

            Layer.GetLayerByNumber(26).Name = "Statistics Layer";
            GameObject2D statistics = new GameObject2D();
            statistics.AddComponent<ScriptStatisticsDrawer>();

            #endregion

            #region Legend
            /*
            demoLegend = new GameObject2D();
            var legend = (HudText)demoLegend.AddComponent<HudText>();
            legend.Color = new Color(0.1f, 0.1f, 0.1f, 1f);
            #if XBOX
                legend.Text.Append("A to open the doors\n");
                legend.Text.Append("Left stick to rotate the wheels");
            #else
                legend.Text.Append("Space or A to open the doors\n");
                legend.Text.Append("Left and right cursors or left stick to rotate the wheels\n");
                legend.Text.Append("Left mouse button or right stick to move the camera");
            #endif*/
            
            #endregion
            
        } // Load
Exemple #20
0
        /// <summary>
        /// Load the resources.
        /// </summary>
        /// <remarks>Remember to call the base implementation of this method.</remarks>
        protected override void LoadContent()
        {
            #region Setup Input Controls

            buttons = new Button[4];

            // Create the virtual buttons to control the scene selection.
            buttons[0] = new Button
            {
                Name           = "Attack",
                ButtonBehavior = Button.ButtonBehaviors.DigitalInput,
                KeyButton      = new KeyButton(Keys.Space),
            };
            buttons[1] = new Button
            {
                Name           = "Attack",
                ButtonBehavior = Button.ButtonBehaviors.DigitalInput,
                KeyButton      = new KeyButton(Buttons.RightTrigger),
            };
            axis = new Axis
            {
                Name         = "Walk",
                AnalogAxis   = AnalogAxes.LeftStickY,
                AxisBehavior = Axis.AxisBehaviors.AnalogInput,
            };
            buttons[2] = new Button
            {
                Name           = "WalkPC",
                KeyButton      = new KeyButton(Keys.W),
                ButtonBehavior = Button.ButtonBehaviors.DigitalInput
            };
            buttons[3] = new Button
            {
                Name           = "RunPC",
                KeyButton      = new KeyButton(Keys.LeftShift),
                ButtonBehavior = Button.ButtonBehaviors.DigitalInput
            };

            #endregion

            #region Camera

            camera = new GameObject3D();
            camera.AddComponent <Camera>();
            camera.AddComponent <SoundListener>();
            camera.Camera.RenderTargetSize = Size.FullScreen;
            camera.Camera.FarPlane         = 100;
            camera.Camera.NearPlane        = 1f;
            camera.Transform.LookAt(new Vector3(-10, 10, 20), new Vector3(0, 5, 0), Vector3.Up);
            //ScriptCustomCameraScript script = (ScriptCustomCameraScript)camera.AddComponent<ScriptCustomCameraScript>();
            //script.SetPosition(new Vector3(0, 10, 20), new Vector3(0, 5, 0));
            camera.Camera.ClearColor  = Color.Black;
            camera.Camera.FieldOfView = 180 / 6f;
            camera.Camera.PostProcess = new PostProcess();
            camera.Camera.PostProcess.ToneMapping.AutoExposureEnabled = true;
            camera.Camera.PostProcess.MLAA.Enabled       = true;
            camera.Camera.PostProcess.MLAA.EdgeDetection = MLAA.EdgeDetectionType.Color;
            camera.Camera.PostProcess.Bloom.Threshold    = 3.5f;
            camera.Camera.AmbientLight = new AmbientLight
            {
                SphericalHarmonicLighting = SphericalHarmonicL2.GenerateSphericalHarmonicFromCubeTexture(new TextureCube("FactoryCatwalkRGBM")
                {
                    IsRgbm = true, RgbmMaxRange = 50,
                }),
                Color     = new Color(10, 10, 10),
                Intensity = 5f,
            };
            //camera.Camera.Sky = new Skybox { TextureCube = new TextureCube("FactoryCatwalkRGBM") { IsRgbm = true, RgbmMaxRange = 50, } };

            #endregion

            #region Models

            dude = new GameObject3D(new FileModel("DudeWalk"), new BlinnPhong());
            // One material for mesh part.
            dude.ModelRenderer.MeshMaterials    = new Material[5];
            dude.ModelRenderer.MeshMaterials[0] = new BlinnPhong {
                DiffuseTexture = new Texture("Dude\\head"), NormalTexture = new Texture("Dude\\headN"), SpecularTexture = new Texture("Dude\\headS"), SpecularPowerFromTexture = false, SpecularPower = 300
            };
            dude.ModelRenderer.MeshMaterials[2] = new BlinnPhong {
                DiffuseTexture = new Texture("Dude\\jacket"), NormalTexture = new Texture("Dude\\jacketN"), SpecularTexture = new Texture("Dude\\jacketS"), SpecularPowerFromTexture = false, SpecularPower = 300
            };
            dude.ModelRenderer.MeshMaterials[3] = new BlinnPhong {
                DiffuseTexture = new Texture("Dude\\pants"), NormalTexture = new Texture("Dude\\pantsN"), SpecularTexture = new Texture("Dude\\pantsS"), SpecularPowerFromTexture = false, SpecularPower = 300
            };
            dude.ModelRenderer.MeshMaterials[1] = new BlinnPhong {
                DiffuseTexture = new Texture("Dude\\upBodyC"), NormalTexture = new Texture("Dude\\upbodyN"), SpecularTexture = new Texture("Dude\\upbodyCS"), SpecularPowerFromTexture = false, SpecularPower = 300
            };
            dude.ModelRenderer.MeshMaterials[4] = new BlinnPhong {
                DiffuseTexture = new Texture("Dude\\upBodyC"), NormalTexture = new Texture("Dude\\upbodyN"), SpecularTexture = new Texture("Dude\\upbodyCS"), SpecularPowerFromTexture = false, SpecularPower = 300
            };
            dude.Transform.LocalScale = new Vector3(0.1f, 0.1f, 0.1f);
            // Add animations.
            dude.AddComponent <ModelAnimations>();
            ModelAnimation modelAnimation;
            // First DudeAttack.
            #if XBOX
            modelAnimation          = new ModelAnimation("DudeAttackXbox"); // Be aware to select the correct content processor when you add your fbx files on the solution.
            modelAnimation.WrapMode = WrapMode.ClampForever;
            dude.ModelAnimations.AddAnimationClip(modelAnimation);
            #else
            modelAnimation          = new ModelAnimation("DudeAttack"); // Be aware to select the correct content processor when you add your fbx files on the solution.
            modelAnimation.WrapMode = WrapMode.ClampForever;
            dude.ModelAnimations.AddAnimationClip(modelAnimation);
            #endif
            // Then DudeRun.
            #if XBOX
            modelAnimation          = new ModelAnimation("DudeRunXbox"); // Be aware to select the correct content processor when you add your fbx files on the solution.
            modelAnimation.WrapMode = WrapMode.Loop;
            dude.ModelAnimations.AddAnimationClip(modelAnimation);
            #else
            modelAnimation          = new ModelAnimation("DudeRun"); // Be aware to select the correct content processor when you add your fbx files on the solution.
            modelAnimation.WrapMode = WrapMode.Loop;
            dude.ModelAnimations.AddAnimationClip(modelAnimation);
            #endif
            // Set the parameters from the animation that it is stored in DudeWalk (this animation is added automatically by the system).
            dude.ModelAnimations["Take 001"].WrapMode = WrapMode.Loop;

            // Load the rifle model.
            rifle = new GameObject3D(new FileModel("Rifle"), new BlinnPhong {
                DiffuseColor = new Color(15, 15, 15), SpecularPower = 100, SpecularIntensity = 0.01f
            });

            // And a floor
            floor = new GameObject3D(new FileModel("Terrain/TerrainLOD0Grid"),
                                     new BlinnPhong
            {
                SpecularPower     = 300,
                DiffuseColor      = new Color(250, 250, 250),
                SpecularIntensity = 0.0f,
            })
            {
                Transform = { LocalScale = new Vector3(5, 5, 5) }
            };

            #endregion

            #region Shadows and Lights

            Shadow.DistributeShadowCalculationsBetweenFrames = true;

            directionalLight = new GameObject3D();
            directionalLight.AddComponent <DirectionalLight>();
            directionalLight.DirectionalLight.Color     = new Color(250, 250, 140);
            directionalLight.DirectionalLight.Intensity = 25f;
            directionalLight.Transform.LookAt(new Vector3(-0.75f, 0.85f, -1.3f), Vector3.Zero, Vector3.Forward);
            directionalLight.DirectionalLight.Shadow = new CascadedShadow
            {
                Filter = Shadow.FilterType.PcfPosion,
                LightDepthTextureSize = Size.Square1024X1024,
            };
            DirectionalLight.Sun = directionalLight.DirectionalLight;

            #endregion

            #region Dog Fight Studios

            // Dog Fight Studios share their animations and the scene logic.
            GameObject2D dogFightStudios = new GameObject2D();
            dogFightStudios.AddComponent <HudTexture>();
            dogFightStudios.HudTexture.Texture = new Texture("DogFightStudios");
            dogFightStudios.Transform.Position = new Vector3(-55, -80, 0);

            #endregion
        } // Load
        /// <summary>
        /// Check that it works in 3D space and a camera component exists.
        /// </summary>
        public override void Load()
        {
            Color backgroundColor = new Color(0.05f, 0.05f, 0.05f, 0.6f);

            #region Frames Per Second

            // Black background
            Rectangle screenRect = new Rectangle(positionX - 5, positionY - 5, linesWidth * framesPerSecondNumberOfElements + 10, elementsHeight + 25);
            framesPerSecondBackground = new GameObject2D();
            framesPerSecondBackground.AddComponent <LineRenderer>();
            framesPerSecondBackground.LineRenderer.PrimitiveType = PrimitiveType.TriangleList;
            framesPerSecondBackground.LineRenderer.Vertices      = new VertexPositionColor[6];
            framesPerSecondBackground.LineRenderer.Vertices[0]   = new VertexPositionColor(new Vector3(screenRect.X, screenRect.Y, 0), backgroundColor);
            framesPerSecondBackground.LineRenderer.Vertices[2]   = new VertexPositionColor(new Vector3(screenRect.X, screenRect.Y + screenRect.Height, 0), backgroundColor);
            framesPerSecondBackground.LineRenderer.Vertices[1]   = new VertexPositionColor(new Vector3(screenRect.X + screenRect.Width, screenRect.Y, 0), backgroundColor);
            framesPerSecondBackground.LineRenderer.Vertices[4]   = new VertexPositionColor(new Vector3(screenRect.X + screenRect.Width, screenRect.Y, 0), backgroundColor);
            framesPerSecondBackground.LineRenderer.Vertices[3]   = new VertexPositionColor(new Vector3(screenRect.X, screenRect.Y + screenRect.Height, 0), backgroundColor);
            framesPerSecondBackground.LineRenderer.Vertices[5]   = new VertexPositionColor(new Vector3(screenRect.X + screenRect.Width, screenRect.Y + screenRect.Height, 0), backgroundColor);

            // Graph
            framesPerSecondLines = new GameObject2D();
            framesPerSecondLines.AddComponent <LineRenderer>();
            framesPerSecondLines.LineRenderer.Vertices = new VertexPositionColor[framesPerSecondNumberOfElements * 2 + 6];
            for (int i = 0; i < framesPerSecondNumberOfElements - 1; i++)
            {
                framesPerSecondLines.LineRenderer.Vertices[i * 2]     = new VertexPositionColor(new Vector3(positionX + i * linesWidth, positionY + elementsHeight, 0), Color.Red);
                framesPerSecondLines.LineRenderer.Vertices[i * 2 + 1] = new VertexPositionColor(new Vector3(positionX + (i + 1) * linesWidth, positionY + elementsHeight, 0), Color.Red);
            }
            // White lines
            framesPerSecondLines.LineRenderer.Vertices[framesPerSecondNumberOfElements * 2 - 2] = new VertexPositionColor(new Vector3(positionX, positionY, 0), new Color(1f, 1f, 1f, 0));
            framesPerSecondLines.LineRenderer.Vertices[framesPerSecondNumberOfElements * 2 - 1] = new VertexPositionColor(new Vector3(positionX, positionY + elementsHeight + 1, 0), Color.White);
            framesPerSecondLines.LineRenderer.Vertices[framesPerSecondNumberOfElements * 2]     = new VertexPositionColor(new Vector3(positionX, positionY + elementsHeight + 1, 0), Color.White);
            framesPerSecondLines.LineRenderer.Vertices[framesPerSecondNumberOfElements * 2 + 1] = new VertexPositionColor(new Vector3(positionX + linesWidth * framesPerSecondNumberOfElements, positionY + elementsHeight + 1, 0), new Color(1f, 1f, 1f, 0));
            // Bad and Good Threshold Lines
            framesPerSecondLines.LineRenderer.Vertices[framesPerSecondNumberOfElements * 2 + 2] = new VertexPositionColor(new Vector3(positionX, positionY + elementsHeight - 20, 0), new Color(1, 0, 0, 0.1f));
            framesPerSecondLines.LineRenderer.Vertices[framesPerSecondNumberOfElements * 2 + 3] = new VertexPositionColor(new Vector3(positionX + linesWidth * framesPerSecondNumberOfElements, positionY + elementsHeight - framesPerSecondBadThreshold, 0), new Color(1, 0, 0, 0.1f));
            framesPerSecondLines.LineRenderer.Vertices[framesPerSecondNumberOfElements * 2 + 4] = new VertexPositionColor(new Vector3(positionX, positionY + elementsHeight - 40, 0), new Color(1, 1, 0, 0.1f));
            framesPerSecondLines.LineRenderer.Vertices[framesPerSecondNumberOfElements * 2 + 5] = new VertexPositionColor(new Vector3(positionX + linesWidth * framesPerSecondNumberOfElements, positionY + elementsHeight - framesPerSecondGoodThreshold, 0), new Color(1, 1, 0, 0.1f));
            // I use a chronometer to update the frames per second graph one time for second.
            chronometer = new Chronometer(Chronometer.TimeSpaceEnum.FrameTime);
            chronometer.Start();
            // Frames Per Second Text
            framesPerSecondText = new GameObject2D();
            framesPerSecondText.AddComponent <HudText>();
            framesPerSecondText.HudText.Text.Append("Frames Per Second ");
            framesPerSecondText.Transform.LocalPosition = new Vector3(positionX, positionY + elementsHeight + 5, 0);

            #endregion

            #region Draw Calls

            int drawCallsPositionX = positionX + linesWidth * framesPerSecondNumberOfElements + 5 + 10;

            // Black background
            screenRect          = new Rectangle(drawCallsPositionX - 5, positionY - 5, linesWidth * drawCallsNumberOfElements + 10, elementsHeight + 25);
            drawCallsBackground = new GameObject2D();
            drawCallsBackground.AddComponent <LineRenderer>();
            drawCallsBackground.LineRenderer.PrimitiveType = PrimitiveType.TriangleList;
            drawCallsBackground.LineRenderer.Vertices      = new VertexPositionColor[6];
            drawCallsBackground.LineRenderer.Vertices[0]   = new VertexPositionColor(new Vector3(screenRect.X, screenRect.Y, -0.1f), backgroundColor);
            drawCallsBackground.LineRenderer.Vertices[2]   = new VertexPositionColor(new Vector3(screenRect.X, screenRect.Y + screenRect.Height, -0.1f), backgroundColor);
            drawCallsBackground.LineRenderer.Vertices[1]   = new VertexPositionColor(new Vector3(screenRect.X + screenRect.Width, screenRect.Y, -0.1f), backgroundColor);
            drawCallsBackground.LineRenderer.Vertices[4]   = new VertexPositionColor(new Vector3(screenRect.X + screenRect.Width, screenRect.Y, -0.1f), backgroundColor);
            drawCallsBackground.LineRenderer.Vertices[3]   = new VertexPositionColor(new Vector3(screenRect.X, screenRect.Y + screenRect.Height, -0.1f), backgroundColor);
            drawCallsBackground.LineRenderer.Vertices[5]   = new VertexPositionColor(new Vector3(screenRect.X + screenRect.Width, screenRect.Y + screenRect.Height, -0.1f), backgroundColor);

            // Graph
            drawCallsLines = new GameObject2D();
            drawCallsLines.AddComponent <LineRenderer>();
            drawCallsLines.LineRenderer.Vertices = new VertexPositionColor[drawCallsNumberOfElements * 2 + 6];
            for (int i = 0; i < drawCallsNumberOfElements - 1; i++)
            {
                drawCallsLines.LineRenderer.Vertices[i * 2]     = new VertexPositionColor(new Vector3(drawCallsPositionX + i * linesWidth, positionY + elementsHeight, 0), Color.Green);
                drawCallsLines.LineRenderer.Vertices[i * 2 + 1] = new VertexPositionColor(new Vector3(drawCallsPositionX + (i + 1) * linesWidth, positionY + elementsHeight, 0), Color.Green);
            }
            // White lines
            drawCallsLines.LineRenderer.Vertices[drawCallsNumberOfElements * 2 - 2] = new VertexPositionColor(new Vector3(drawCallsPositionX, positionY, 0), new Color(1f, 1f, 1f, 0));
            drawCallsLines.LineRenderer.Vertices[drawCallsNumberOfElements * 2 - 1] = new VertexPositionColor(new Vector3(drawCallsPositionX, positionY + elementsHeight + 1, 0), Color.White);
            drawCallsLines.LineRenderer.Vertices[drawCallsNumberOfElements * 2]     = new VertexPositionColor(new Vector3(drawCallsPositionX, positionY + elementsHeight + 1, 0), Color.White);
            drawCallsLines.LineRenderer.Vertices[drawCallsNumberOfElements * 2 + 1] = new VertexPositionColor(new Vector3(drawCallsPositionX + linesWidth * drawCallsNumberOfElements, positionY + elementsHeight + 1, 0), new Color(1f, 1f, 1f, 0));
            // Bad and Good Threshold Lines
            drawCallsLines.LineRenderer.Vertices[drawCallsNumberOfElements * 2 + 2] = new VertexPositionColor(new Vector3(drawCallsPositionX, positionY + elementsHeight - 20, 0), new Color(1, 0, 0, 0.1f));
            drawCallsLines.LineRenderer.Vertices[drawCallsNumberOfElements * 2 + 3] = new VertexPositionColor(new Vector3(drawCallsPositionX + linesWidth * drawCallsNumberOfElements, positionY + elementsHeight - 20, 0), new Color(1, 0, 0, 0.1f));
            drawCallsLines.LineRenderer.Vertices[drawCallsNumberOfElements * 2 + 4] = new VertexPositionColor(new Vector3(drawCallsPositionX, positionY + elementsHeight - 40, 0), new Color(1, 1, 0, 0.1f));
            drawCallsLines.LineRenderer.Vertices[drawCallsNumberOfElements * 2 + 5] = new VertexPositionColor(new Vector3(drawCallsPositionX + linesWidth * drawCallsNumberOfElements, positionY + elementsHeight - 40, 0), new Color(1, 1, 0, 0.1f));
            // Text
            drawCallsText = new GameObject2D();
            drawCallsText.AddComponent <HudText>();
            drawCallsText.HudText.Text.Append("Average Draw Calls ");
            drawCallsText.Transform.LocalPosition = new Vector3(drawCallsPositionX, positionY + elementsHeight + 5, 0);

            #endregion

            #region Triangles Drawn

            int trianglesDrawnPositionX = drawCallsPositionX + linesWidth * drawCallsNumberOfElements + 5 + 10;

            // Black background
            screenRect = new Rectangle(trianglesDrawnPositionX - 5, positionY - 5, linesWidth * trianglesDrawnNumberOfElements + 10, elementsHeight + 25);
            trianglesDrawnBackground = new GameObject2D();
            trianglesDrawnBackground.AddComponent <LineRenderer>();
            trianglesDrawnBackground.LineRenderer.PrimitiveType = PrimitiveType.TriangleList;
            trianglesDrawnBackground.LineRenderer.Vertices      = new VertexPositionColor[6];
            trianglesDrawnBackground.LineRenderer.Vertices[0]   = new VertexPositionColor(new Vector3(screenRect.X, screenRect.Y, -0.1f), backgroundColor);
            trianglesDrawnBackground.LineRenderer.Vertices[2]   = new VertexPositionColor(new Vector3(screenRect.X, screenRect.Y + screenRect.Height, -0.1f), backgroundColor);
            trianglesDrawnBackground.LineRenderer.Vertices[1]   = new VertexPositionColor(new Vector3(screenRect.X + screenRect.Width, screenRect.Y, -0.1f), backgroundColor);
            trianglesDrawnBackground.LineRenderer.Vertices[4]   = new VertexPositionColor(new Vector3(screenRect.X + screenRect.Width, screenRect.Y, -0.1f), backgroundColor);
            trianglesDrawnBackground.LineRenderer.Vertices[3]   = new VertexPositionColor(new Vector3(screenRect.X, screenRect.Y + screenRect.Height, -0.1f), backgroundColor);
            trianglesDrawnBackground.LineRenderer.Vertices[5]   = new VertexPositionColor(new Vector3(screenRect.X + screenRect.Width, screenRect.Y + screenRect.Height, -0.1f), backgroundColor);

            // Graph
            trianglesDrawnLines = new GameObject2D();
            trianglesDrawnLines.AddComponent <LineRenderer>();
            trianglesDrawnLines.LineRenderer.Vertices = new VertexPositionColor[trianglesDrawnNumberOfElements * 2 + 6];
            for (int i = 0; i < trianglesDrawnNumberOfElements - 1; i++)
            {
                trianglesDrawnLines.LineRenderer.Vertices[i * 2]     = new VertexPositionColor(new Vector3(trianglesDrawnPositionX + i * linesWidth, positionY + elementsHeight, 0), Color.Red);
                trianglesDrawnLines.LineRenderer.Vertices[i * 2 + 1] = new VertexPositionColor(new Vector3(trianglesDrawnPositionX + (i + 1) * linesWidth, positionY + elementsHeight, 0), Color.Red);
            }
            // White lines
            trianglesDrawnLines.LineRenderer.Vertices[trianglesDrawnNumberOfElements * 2 - 2] = new VertexPositionColor(new Vector3(trianglesDrawnPositionX, positionY, 0), new Color(1f, 1f, 1f, 0));
            trianglesDrawnLines.LineRenderer.Vertices[trianglesDrawnNumberOfElements * 2 - 1] = new VertexPositionColor(new Vector3(trianglesDrawnPositionX, positionY + elementsHeight + 1, 0), Color.White);
            trianglesDrawnLines.LineRenderer.Vertices[trianglesDrawnNumberOfElements * 2]     = new VertexPositionColor(new Vector3(trianglesDrawnPositionX, positionY + elementsHeight + 1, 0), Color.White);
            trianglesDrawnLines.LineRenderer.Vertices[trianglesDrawnNumberOfElements * 2 + 1] = new VertexPositionColor(new Vector3(trianglesDrawnPositionX + linesWidth * trianglesDrawnNumberOfElements, positionY + elementsHeight + 1, 0), new Color(1f, 1f, 1f, 0));
            // Bad and Good Threshold Lines
            trianglesDrawnLines.LineRenderer.Vertices[trianglesDrawnNumberOfElements * 2 + 2] = new VertexPositionColor(new Vector3(trianglesDrawnPositionX, positionY + elementsHeight - 20, 0), new Color(1, 0, 0, 0.1f));
            trianglesDrawnLines.LineRenderer.Vertices[trianglesDrawnNumberOfElements * 2 + 3] = new VertexPositionColor(new Vector3(trianglesDrawnPositionX + linesWidth * trianglesDrawnNumberOfElements, positionY + elementsHeight - 20, 0), new Color(1, 0, 0, 0.1f));
            trianglesDrawnLines.LineRenderer.Vertices[trianglesDrawnNumberOfElements * 2 + 4] = new VertexPositionColor(new Vector3(trianglesDrawnPositionX, positionY + elementsHeight - 40, 0), new Color(1, 1, 0, 0.1f));
            trianglesDrawnLines.LineRenderer.Vertices[trianglesDrawnNumberOfElements * 2 + 5] = new VertexPositionColor(new Vector3(trianglesDrawnPositionX + linesWidth * trianglesDrawnNumberOfElements, positionY + elementsHeight - 40, 0), new Color(1, 1, 0, 0.1f));
            // Text
            trianglesDrawnText = new GameObject2D();
            trianglesDrawnText.AddComponent <HudText>();
            trianglesDrawnText.HudText.Text.Append("Average Triangles Drawn ");
            trianglesDrawnText.Transform.LocalPosition = new Vector3(trianglesDrawnPositionX, positionY + elementsHeight + 5, 0);

            #endregion

            #region Managed Memory Used

            int managedMemoryUsedPositionX = trianglesDrawnPositionX + linesWidth * trianglesDrawnNumberOfElements + 5 + 10;

            // Black background
            screenRect = new Rectangle(managedMemoryUsedPositionX - 5, positionY - 5, linesWidth * managedMemoryUsedNumberOfElements + 10, elementsHeight + 25);
            managedMemoryUsedBackground = new GameObject2D();
            managedMemoryUsedBackground.AddComponent <LineRenderer>();
            managedMemoryUsedBackground.LineRenderer.PrimitiveType = PrimitiveType.TriangleList;
            managedMemoryUsedBackground.LineRenderer.Vertices      = new VertexPositionColor[6];
            managedMemoryUsedBackground.LineRenderer.Vertices[0]   = new VertexPositionColor(new Vector3(screenRect.X, screenRect.Y, -0.1f), backgroundColor);
            managedMemoryUsedBackground.LineRenderer.Vertices[2]   = new VertexPositionColor(new Vector3(screenRect.X, screenRect.Y + screenRect.Height, -0.1f), backgroundColor);
            managedMemoryUsedBackground.LineRenderer.Vertices[1]   = new VertexPositionColor(new Vector3(screenRect.X + screenRect.Width, screenRect.Y, -0.1f), backgroundColor);
            managedMemoryUsedBackground.LineRenderer.Vertices[4]   = new VertexPositionColor(new Vector3(screenRect.X + screenRect.Width, screenRect.Y, -0.1f), backgroundColor);
            managedMemoryUsedBackground.LineRenderer.Vertices[3]   = new VertexPositionColor(new Vector3(screenRect.X, screenRect.Y + screenRect.Height, -0.1f), backgroundColor);
            managedMemoryUsedBackground.LineRenderer.Vertices[5]   = new VertexPositionColor(new Vector3(screenRect.X + screenRect.Width, screenRect.Y + screenRect.Height, -0.1f), backgroundColor);

            // Graph
            managedMemoryUsedLines = new GameObject2D();
            managedMemoryUsedLines.AddComponent <LineRenderer>();
            managedMemoryUsedLines.LineRenderer.Vertices = new VertexPositionColor[managedMemoryUsedNumberOfElements * 2 + 6];
            for (int i = 0; i < managedMemoryUsedNumberOfElements - 1; i++)
            {
                managedMemoryUsedLines.LineRenderer.Vertices[i * 2]     = new VertexPositionColor(new Vector3(managedMemoryUsedPositionX + i * linesWidth, positionY + elementsHeight, 0), new Color(100, 255, 100));
                managedMemoryUsedLines.LineRenderer.Vertices[i * 2 + 1] = new VertexPositionColor(new Vector3(managedMemoryUsedPositionX + (i + 1) * linesWidth, positionY + elementsHeight, 0), new Color(100, 255, 100));
            }
            // White lines
            managedMemoryUsedLines.LineRenderer.Vertices[managedMemoryUsedNumberOfElements * 2 - 2] = new VertexPositionColor(new Vector3(managedMemoryUsedPositionX, positionY, 0), new Color(1f, 1f, 1f, 0));
            managedMemoryUsedLines.LineRenderer.Vertices[managedMemoryUsedNumberOfElements * 2 - 1] = new VertexPositionColor(new Vector3(managedMemoryUsedPositionX, positionY + elementsHeight + 1, 0), Color.White);
            managedMemoryUsedLines.LineRenderer.Vertices[managedMemoryUsedNumberOfElements * 2]     = new VertexPositionColor(new Vector3(managedMemoryUsedPositionX, positionY + elementsHeight + 1, 0), Color.White);
            managedMemoryUsedLines.LineRenderer.Vertices[managedMemoryUsedNumberOfElements * 2 + 1] = new VertexPositionColor(new Vector3(managedMemoryUsedPositionX + linesWidth * managedMemoryUsedNumberOfElements, positionY + elementsHeight + 1, 0), new Color(1f, 1f, 1f, 0));
            // Bad and Good Threshold Lines
            managedMemoryUsedLines.LineRenderer.Vertices[managedMemoryUsedNumberOfElements * 2 + 2] = new VertexPositionColor(new Vector3(managedMemoryUsedPositionX, positionY + elementsHeight - 20, 0), new Color(1, 0, 0, 0.1f));
            managedMemoryUsedLines.LineRenderer.Vertices[managedMemoryUsedNumberOfElements * 2 + 3] = new VertexPositionColor(new Vector3(managedMemoryUsedPositionX + linesWidth * managedMemoryUsedNumberOfElements, positionY + elementsHeight - -20, 0), new Color(1, 0, 0, 0.1f));
            managedMemoryUsedLines.LineRenderer.Vertices[managedMemoryUsedNumberOfElements * 2 + 4] = new VertexPositionColor(new Vector3(managedMemoryUsedPositionX, positionY + elementsHeight - 40, 0), new Color(1, 1, 0, 0.1f));
            managedMemoryUsedLines.LineRenderer.Vertices[managedMemoryUsedNumberOfElements * 2 + 5] = new VertexPositionColor(new Vector3(managedMemoryUsedPositionX + linesWidth * managedMemoryUsedNumberOfElements, positionY + elementsHeight - 40, 0), new Color(1, 1, 0, 0.1f));
            // Text
            managedMemoryUsedText = new GameObject2D();
            managedMemoryUsedText.AddComponent <HudText>();
            managedMemoryUsedText.HudText.Text.Append("Managed Memory Used ");
            managedMemoryUsedText.Transform.LocalPosition = new Vector3(managedMemoryUsedPositionX, positionY + elementsHeight + 5, 0);

            #endregion

            #region Garbage Collections

            int garbageCollectionsPositionX = managedMemoryUsedPositionX + linesWidth * managedMemoryUsedNumberOfElements + 5 + 10;

            // Black background
            screenRect = new Rectangle(garbageCollectionsPositionX - 5, positionY - 5, linesWidth * garbageCollectionsNumberOfElements + 10, elementsHeight + 25);
            garbageCollectionsBackground = new GameObject2D();
            garbageCollectionsBackground.AddComponent <LineRenderer>();
            garbageCollectionsBackground.LineRenderer.PrimitiveType = PrimitiveType.TriangleList;
            garbageCollectionsBackground.LineRenderer.Vertices      = new VertexPositionColor[6];
            garbageCollectionsBackground.LineRenderer.Vertices[0]   = new VertexPositionColor(new Vector3(screenRect.X, screenRect.Y, -0.1f), backgroundColor);
            garbageCollectionsBackground.LineRenderer.Vertices[2]   = new VertexPositionColor(new Vector3(screenRect.X, screenRect.Y + screenRect.Height, -0.1f), backgroundColor);
            garbageCollectionsBackground.LineRenderer.Vertices[1]   = new VertexPositionColor(new Vector3(screenRect.X + screenRect.Width, screenRect.Y, -0.1f), backgroundColor);
            garbageCollectionsBackground.LineRenderer.Vertices[4]   = new VertexPositionColor(new Vector3(screenRect.X + screenRect.Width, screenRect.Y, -0.1f), backgroundColor);
            garbageCollectionsBackground.LineRenderer.Vertices[3]   = new VertexPositionColor(new Vector3(screenRect.X, screenRect.Y + screenRect.Height, -0.1f), backgroundColor);
            garbageCollectionsBackground.LineRenderer.Vertices[5]   = new VertexPositionColor(new Vector3(screenRect.X + screenRect.Width, screenRect.Y + screenRect.Height, -0.1f), backgroundColor);

            // Graph
            garbageCollectionsLines = new GameObject2D();
            garbageCollectionsLines.AddComponent <LineRenderer>();
            garbageCollectionsLines.LineRenderer.Vertices = new VertexPositionColor[garbageCollectionsNumberOfElements * 2 + 2];
            for (int i = 0; i < garbageCollectionsNumberOfElements - 1; i++)
            {
                garbageCollectionsLines.LineRenderer.Vertices[i * 2]     = new VertexPositionColor(new Vector3(garbageCollectionsPositionX + i * linesWidth, positionY + elementsHeight, 0), new Color(100, 255, 100));
                garbageCollectionsLines.LineRenderer.Vertices[i * 2 + 1] = new VertexPositionColor(new Vector3(garbageCollectionsPositionX + (i + 1) * linesWidth, positionY + elementsHeight, 0), new Color(100, 255, 100));
            }
            // White lines
            garbageCollectionsLines.LineRenderer.Vertices[garbageCollectionsNumberOfElements * 2 - 2] = new VertexPositionColor(new Vector3(garbageCollectionsPositionX, positionY, 0), new Color(1f, 1f, 1f, 0));
            garbageCollectionsLines.LineRenderer.Vertices[garbageCollectionsNumberOfElements * 2 - 1] = new VertexPositionColor(new Vector3(garbageCollectionsPositionX, positionY + elementsHeight + 1, 0), Color.White);
            garbageCollectionsLines.LineRenderer.Vertices[garbageCollectionsNumberOfElements * 2]     = new VertexPositionColor(new Vector3(garbageCollectionsPositionX, positionY + elementsHeight + 1, 0), Color.White);
            garbageCollectionsLines.LineRenderer.Vertices[garbageCollectionsNumberOfElements * 2 + 1] = new VertexPositionColor(new Vector3(garbageCollectionsPositionX + linesWidth * garbageCollectionsNumberOfElements, positionY + elementsHeight + 1, 0), new Color(1f, 1f, 1f, 0));
            // Text
            garbageCollectionsText = new GameObject2D();
            garbageCollectionsText.AddComponent <HudText>();
            garbageCollectionsText.HudText.Text.Append("Garbage Collections ");
            garbageCollectionsText.Transform.LocalPosition = new Vector3(garbageCollectionsPositionX, positionY + elementsHeight + 5, 0);

            #endregion

            #region User Interface Text

            // Black background
            screenRect = new Rectangle(positionX - 5, positionY + elementsHeight + 25, 520, 15);
            userInterfaceGarbageBackground = new GameObject2D();
            userInterfaceGarbageBackground.AddComponent <LineRenderer>();
            userInterfaceGarbageBackground.LineRenderer.PrimitiveType = PrimitiveType.TriangleList;
            userInterfaceGarbageBackground.LineRenderer.Vertices      = new VertexPositionColor[6];
            userInterfaceGarbageBackground.LineRenderer.Vertices[0]   = new VertexPositionColor(new Vector3(screenRect.X, screenRect.Y, -0.1f), backgroundColor);
            userInterfaceGarbageBackground.LineRenderer.Vertices[2]   = new VertexPositionColor(new Vector3(screenRect.X, screenRect.Y + screenRect.Height, -0.1f), backgroundColor);
            userInterfaceGarbageBackground.LineRenderer.Vertices[1]   = new VertexPositionColor(new Vector3(screenRect.X + screenRect.Width, screenRect.Y, -0.1f), backgroundColor);
            userInterfaceGarbageBackground.LineRenderer.Vertices[4]   = new VertexPositionColor(new Vector3(screenRect.X + screenRect.Width, screenRect.Y, -0.1f), backgroundColor);
            userInterfaceGarbageBackground.LineRenderer.Vertices[3]   = new VertexPositionColor(new Vector3(screenRect.X, screenRect.Y + screenRect.Height, -0.1f), backgroundColor);
            userInterfaceGarbageBackground.LineRenderer.Vertices[5]   = new VertexPositionColor(new Vector3(screenRect.X + screenRect.Width, screenRect.Y + screenRect.Height, -0.1f), backgroundColor);

            userInterfaceGarbageText = new GameObject2D();
            userInterfaceGarbageText.AddComponent <HudText>();
            userInterfaceGarbageText.HudText.Text.Append("The User Interface generates a lot of garbage collections. Do not use it in game time.");
            userInterfaceGarbageText.HudText.Color           = Color.Gray;
            userInterfaceGarbageText.Transform.LocalPosition = new Vector3(positionX, positionY + elementsHeight + 25, 0);

            #endregion
        } // Load
        /// <summary>
        /// Load the resources.
        /// </summary>
        protected override void LoadContent()
        {
            hitMaterial = new BlinnPhong {
                DiffuseColor = new Color(0.10f, 0.10f, 0.85f)
            };
            mat1 = new BlinnPhong {
                DiffuseColor = new Color(0.85f, 0.65f, 0f)
            };
            mat2 = new BlinnPhong {
                DiffuseColor = new Color(0.5f, 0.9f, 0.5f)
            };

            #region Physics Simulation Settings

            // Setup gravity.
            PhysicsManager.Gravity = new Vector3(0, -9.81f, 0);

            #endregion

            #region Camera

            camera = new GameObject3D();
            camera.AddComponent <Camera>();
            camera.AddComponent <SoundListener>();
            camera.Transform.LookAt(Vector3.Zero, Vector3.Forward, Vector3.Up);
            var script = (ScriptCustomCameraScript)camera.AddComponent <ScriptCustomCameraScript>();
            script.SetPosition(new Vector3(0, 15, 45), new Vector3(0, 5, 0));
            camera.Camera.RenderTargetSize = Size.FullScreen;
            camera.Camera.FarPlane         = 500;
            camera.Camera.NearPlane        = 1f;
            camera.Camera.ClearColor       = Color.Black;
            camera.Camera.FieldOfView      = 180f / 7f;
            camera.Camera.PostProcess      = new PostProcess();
            camera.Camera.PostProcess.ToneMapping.ToneMappingFunction = ToneMapping.ToneMappingFunctionEnumerate.FilmicALU;
            camera.Camera.PostProcess.ToneMapping.AutoExposureEnabled = false;
            camera.Camera.PostProcess.ToneMapping.LensExposure        = 0f;
            camera.Camera.PostProcess.MLAA.EdgeDetection          = MLAA.EdgeDetectionType.Both;
            camera.Camera.PostProcess.MLAA.Enabled                = false;
            camera.Camera.PostProcess.Bloom.Threshold             = 2;
            camera.Camera.PostProcess.FilmGrain.Enabled           = true;
            camera.Camera.PostProcess.FilmGrain.Strength          = 0.03f;
            camera.Camera.PostProcess.AnamorphicLensFlare.Enabled = false;
            camera.Camera.AmbientLight = new AmbientLight
            {
                Color     = new Color(20, 20, 25),
                Intensity = 0.5f,
                AmbientOcclusionStrength = 1f
            };

            #endregion

            #region Models and Physics

            // Make the floor (Kinematic) //
            // First, we create a bepu box entity that we will be used in our rigidbody component.
            // Notice that we don't specify the mass, so we are creating a kinematic entity.
            // Kinematic rigidbodies are moved through the transform component of the gameobject which it belongs.
            // Kinematic rigidbodies don't respond to collisions and can't collide with other kinematic rigidbodies. However, they can
            // collide with dynamic rigidbodies affecting them.
            var bepuGround = new Box(Vector3.Zero, 50, 1, 50);
            // Now, we create the game object and we add a rigidbody component to it.
            floor = new GameObject3D(new XNAFinalEngine.Assets.Box(50, 1, 50), new BlinnPhong {
                SpecularIntensity = 0.3f, SpecularPower = 200
            });
            var floorRb = (RigidBody)floor.AddComponent <RigidBody>();
            // Finally, we set the entity created previously to the rigidbody component
            floorRb.Entity = bepuGround;

            // Make a Cube (Dynamic) //
            // Now, we create a 1x1x1 bepu box entity that will appear 20 units above the floor.
            // Notice that this time we specify the entity's mass in order to create a dynamic entity.
            // Dynamic rigidbodies are affected by gravity and respond to collisions with other rigidbodies.
            // Dynamic rigidbodies are under the control of physics so they don't have to be moved or rotated through the transform component.
            var bepuCube = new Box(new Vector3(0, 20, 2), 1, 1, 1, 1);
            cube = new GameObject3D(new XNAFinalEngine.Assets.Box(1, 1, 1), new BlinnPhong {
                DiffuseColor = new Color(0.8f, 0.8f, 0.85f)
            });
            var cubeRb = (RigidBody)cube.AddComponent <RigidBody>();
            cubeRb.Entity = bepuCube;
            // Create a script for test collisions
            var          crt     = (CollisionResponseTestScript)cube.AddComponent <CollisionResponseTestScript>();
            GameObject2D debugGo = new GameObject2D();
            debugGo.Transform.Position = new Vector3(15f, Screen.Height - 90, 0f);
            crt.DebugText = (HudText)debugGo.AddComponent <HudText>();

            // Make an obstacle (Kinematic) //
            var bepuObstacle = new Box(new Vector3(0.5f, 1f, 0.5f), 4, 1, 1.5f);
            obstacle = new GameObject3D(new XNAFinalEngine.Assets.Box(4, 1, 1.5f), new BlinnPhong {
                DiffuseColor = new Color(0.9f, 0.2f, 0.15f), SpecularPower = 20
            });
            obstacle.Transform.Position = new Vector3(0.5f, 1f, 0.5f);
            var obstacleRb = (RigidBody)obstacle.AddComponent <RigidBody>();
            obstacleRb.Entity = bepuObstacle;

            // Make a wall of boxes //
            MakeWall(6, 9);

            // Make a sphere obstacle (Dynamic) //
            // The sphere model is not center in its model space, instead is displaced 10 units on Z.
            GameObject3D sphere;
            // First we creates this sphere with no physics representation.
            //sphere = new GameObject3D(new FileModel("SphereTransformed"), new BlinnPhong { DiffuseColor = new Color(1f, 0f, 0f), SpecularPower = 20 });
            // Then we creates the same sphere and asign a dynamic physic object representation.
            sphere = new GameObject3D(new FileModel("SphereTransformed"), new BlinnPhong {
                DiffuseColor = new Color(0.79f, 0.75f, 0.2f), SpecularPower = 20
            });
            // The initial motion state place the sphere just a little above.
            MotionState motionState = new MotionState {
                Position = new Vector3(0f, 10f, 0f), Orientation = Quaternion.Identity
            };
            // We create the physic object. The offset that creates Bepu is hide transparently.
            // Moreover the initial motion state takes in consideration this offset and places the sphere in the same x, z coordinates as the other sphere.
            ((RigidBody)sphere.AddComponent <RigidBody>()).CreateDynamicEntityFromModelFilter(motionState, 1);

            // Static mesh.
            var lamboBody = new GameObject3D(new FileModel("LamborghiniMurcielago\\Murcielago-Body"
#if XBOX
                                                           + "Xbox"
#endif
                                                           ), new BlinnPhong {
                DiffuseColor = Color.Gray
            });
            lamboBody.Transform.Position = new Vector3(-3, 3, 3);
            ((StaticCollider)lamboBody.AddComponent <StaticCollider>()).CreateStaticCollidableFromModelFilter();

            // Very Simple Crosshair //
            GameObject2D crosshair = new GameObject2D();
            crosshair.Transform.Position = new Vector3(Screen.Width / 2f, Screen.Height / 2f, 0f);
            var crossText = (HudText)crosshair.AddComponent <HudText>();
            crossText.Text.Append("+");

            #endregion

            #region Shadows and Lights

            Shadow.DistributeShadowCalculationsBetweenFrames = true;

            var pointLight = new GameObject3D();
            pointLight.AddComponent <PointLight>();
            pointLight.PointLight.Color     = new Color(180, 200, 250);
            pointLight.PointLight.Intensity = 4f;
            pointLight.PointLight.Range     = 60;
            pointLight.Transform.Position   = new Vector3(4.8f, 10f, 10);
            pointLight.PointLight.Shadow    = new CubeShadow {
                LightDepthTextureSize = 1024
            };

            var pointLight2 = new GameObject3D();
            pointLight2.AddComponent <PointLight>();
            pointLight2.PointLight.Color     = new Color(100, 110, 170);
            pointLight2.PointLight.Intensity = 1f;
            pointLight2.PointLight.Range     = 30;
            pointLight2.Transform.Position   = new Vector3(-12f, 10, -3);

            #endregion

            #region Demo Legend

            #region Legend Background

            Texture2D bg      = new Texture2D(EngineManager.Device, 1, 1, false, SurfaceFormat.Color);
            Color[]   bgColor = new Color[] { new Color(0f, 0f, 0f, 0.55f) };
            bg.SetData(bgColor);

            var bgTexture        = new XNAFinalEngine.Assets.Texture(bg);
            var backgroundLegend = new GameObject2D();
            backgroundLegend.Transform.Position = new Vector3(0f, 0f, 1f);
            var bgHudTex = (HudTexture)backgroundLegend.AddComponent <HudTexture>();
            bgHudTex.Texture = bgTexture;
            bgHudTex.DestinationRectangle = new Rectangle(0, Screen.Height - 115, Screen.Width, Screen.Height);

            #endregion

            var demoLegend = new GameObject2D();
            demoLegend.Transform.Position = new Vector3(Screen.Width - 380f, Screen.Height - 105f, 0f);
            var legend = (HudText)demoLegend.AddComponent <HudText>();
            legend.Color = new Color(1f, 1f, 1f, 1f);
            legend.Text.Append(" Controls\n");
            legend.Text.Append("\n");
            legend.Text.Append("- Press Left Ctrl to fire a Blue box.\n");
            legend.Text.Append("- Press Space to apply an Up impulse to the white box.\n");
            legend.Text.Append("- Press Left Shift to cast a ray that paints yellow and \n");
            legend.Text.Append("  applies an Up impulse to the GO that hits.\n");
            legend.Text.Append("- Press keys A, S, W, D, Q, E to move and rotate the red box");

            #endregion
        } // LoadContent
Exemple #23
0
 public static void ResolveCollision(GameObject2D obj1, GameObject2D obj2)
 {
     obj1.SetPos2D(new Vector2(obj1.lastPosNoCol.x, obj1.lastPosNoCol.y));
     obj2.SetPos2D(new Vector2(obj2.lastPosNoCol.x, obj2.lastPosNoCol.y));
 }
Exemple #24
0
        /// <summary>
        /// Scale gizmo based in Softimage XSI.
        /// </summary>
        internal ScaleGizmo()
        {
            // Create the gizmo parts.
            Box box = new Box(0.15f, 0.15f, 0.15f);

            redBox = new GameObject3D(box, new Constant())
            {
                Layer = Layer.GetLayerByNumber(31)
            };
            greenBox = new GameObject3D(box, new Constant())
            {
                Layer = Layer.GetLayerByNumber(31)
            };
            blueBox = new GameObject3D(box, new Constant())
            {
                Layer = Layer.GetLayerByNumber(31)
            };
            lines = new GameObject3D {
                Layer = Layer.GetLayerByNumber(31),
            };
            lines.AddComponent <LineRenderer>();
            lines.LineRenderer.Vertices = new VertexPositionColor[6];
            vertices[0]   = new Vector3(0, 0, 0);
            vertices[1]   = new Vector3(1, 0, 0);
            vertices[2]   = new Vector3(0, 1, 0);
            vertices[3]   = new Vector3(0, 0, 1);
            vertices[4]   = new Vector3(1, 1, 0);
            vertices[5]   = new Vector3(0, 1, 1);
            vertices[6]   = new Vector3(1, 0, 1);
            planeRedGreen = new GameObject3D(new Plane(vertices[2], vertices[0], vertices[4], vertices[1]), new Constant {
                DiffuseColor = new Color(255, 255, 0)
            })
            {
                Layer = Layer.GetLayerByNumber(31),
            };
            planeGreenBlue = new GameObject3D(new Plane(vertices[5], vertices[3], vertices[2], vertices[0]), new Constant {
                DiffuseColor = new Color(0, 255, 255)
            })
            {
                Layer = Layer.GetLayerByNumber(31),
            };
            planeBlueRed = new GameObject3D(new Plane(vertices[0], vertices[3], vertices[1], vertices[6]), new Constant {
                DiffuseColor = new Color(255, 0, 255)
            })
            {
                Layer = Layer.GetLayerByNumber(31),
            };
            planeRedGreenInv = new GameObject3D(new Plane(vertices[4], vertices[1], vertices[2], vertices[0]), new Constant {
                DiffuseColor = new Color(255, 255, 0)
            })
            {
                Layer = Layer.GetLayerByNumber(31),
            };
            planeGreenBlueInv = new GameObject3D(new Plane(vertices[2], vertices[0], vertices[5], vertices[3]), new Constant {
                DiffuseColor = new Color(0, 255, 255)
            })
            {
                Layer = Layer.GetLayerByNumber(31),
            };
            planeBlueRedInv = new GameObject3D(new Plane(vertices[1], vertices[6], vertices[0], vertices[3]), new Constant {
                DiffuseColor = new Color(255, 0, 255)
            })
            {
                Layer = Layer.GetLayerByNumber(31),
            };
            planeAll = new GameObject2D {
                Layer = Layer.GetLayerByNumber(31),
            };
            planeAll.AddComponent <LineRenderer>();
            planeAll.LineRenderer.Vertices = new VertexPositionColor[8];

            redBox.ModelRenderer.Enabled            = false;
            greenBox.ModelRenderer.Enabled          = false;
            blueBox.ModelRenderer.Enabled           = false;
            lines.LineRenderer.Enabled              = false;
            planeRedGreen.ModelRenderer.Enabled     = false;
            planeGreenBlue.ModelRenderer.Enabled    = false;
            planeBlueRed.ModelRenderer.Enabled      = false;
            planeRedGreenInv.ModelRenderer.Enabled  = false;
            planeGreenBlueInv.ModelRenderer.Enabled = false;
            planeBlueRedInv.ModelRenderer.Enabled   = false;
            planeAll.LineRenderer.Enabled           = false;
        } // ScaleGizmo