/// <summary>
        /// Updates Main Gameplay Loop code here, this is affected by whether or not the scene is paused.
        /// </summary>
        /// <param name="gameTime"></param>
        /// <param name="otherScreenHasFocus"></param>
        /// <param name="coveredByOtherScreen"></param>
        public override void UpdateScene(GameTime gameTime, bool otherScreenHasFocus, bool coveredByOtherScreen)
        {
            character.Update((float)gameTime.ElapsedGameTime.TotalSeconds, vxEngine.InputManager.PreviousKeyboardState,
                             vxEngine.InputManager.KeyboardState, vxEngine.InputManager.PreviousGamePadState, vxEngine.InputManager.GamePadState);

            if (this.IsActive)
            {
                vxEngine.InputManager.ShowCursor = false;
            }
            else
            {
                vxEngine.InputManager.ShowCursor = true;
            }

            //Update grabber
            if (vxEngine.InputManager.MouseState.RightButton == ButtonState.Pressed && !grabber.IsGrabbing)
            {
                //Find the earliest ray hit
                RayCastResult raycastResult;
                if (BEPUPhyicsSpace.RayCast(new Ray(Camera.Position, Camera.WorldMatrix.Forward), 500, rayCastFilter, out raycastResult))
                {
                    var entityCollision = raycastResult.HitObject as EntityCollidable;
                    //If there's a valid ray hit, then grab the connected object!
                    if (entityCollision != null && entityCollision.Entity.IsDynamic)
                    {
                        Console.WriteLine("GRABBING ITEM: {0}", entityCollision.Entity.GetType().ToString());
                        grabber.Setup(entityCollision.Entity, raycastResult.HitData.Location);
                        //grabberGraphic.IsDrawing = true;
                        grabDistance = raycastResult.HitData.T;
                    }
                }
            }

            if (vxEngine.InputManager.MouseState.RightButton == ButtonState.Pressed && grabber.IsUpdating)
            {
                if (grabDistance < 4)
                {
                    grabDistance         = 3;
                    grabber.GoalPosition = Camera.Position + Camera.WorldMatrix.Forward * grabDistance;
                }
            }

            else if (vxEngine.InputManager.MouseState.RightButton == ButtonState.Released && grabber.IsUpdating)
            {
                grabber.Release();
            }

            base.UpdateScene(gameTime, otherScreenHasFocus, coveredByOtherScreen);
        }
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        public override void LoadContent()
        {
            InitialiseLevel();

//			xEnvrio g = new xEnvrio(vxEngine, vxEngine.LoadModel("Models/tech demo/vrtc_techDemo"), Vector3.Zero);
//            g.World *= Matrix.CreateRotationZ(-MathHelper.PiOver2);
//			g.name = "tech demo";
//			g.NormalMap = vxEngine.Game.Content.Load<Texture2D>("Models/tech demo/grass_nm");


            int size    = 100;
            Box baseBox = new Box(new Vector3(0, -5, 0), size, 10, size);

            BEPUPhyicsSpace.Add(baseBox);

            ///////////////////////////////////////////////////////////////////////
            //Initialise Camera Code
            ///////////////////////////////////////////////////////////////////////
            #region Set Up Camera

            base.LoadContent();
            Camera.CameraType = CameraType.CharacterFPS;

            Camera.Position = new Vector3(0, 20, 0);

            character = new CharacterControllerInput(BEPUPhyicsSpace, Camera, vxEngine);

            //Since this is the character playground, turn on the character by default.
            character.Activate();

            //Having the character body visible would be a bit distracting.
            character.CharacterController.Body.Tag = "noDisplayObject";


            //
            //Grabbers
            //
            grabber = new MotorizedGrabSpring();
            BEPUPhyicsSpace.Add(grabber);
            rayCastFilter = RayCastFilter;

            new IndexedPrimTest(vxEngine, new Vector3(0, 0, 0));


            #endregion
        }
Example #3
0
        public override void LoadContent()
        {
            InitialiseLevel();

            vxScaleCube center = new vxScaleCube(vxEngine, Vector3.One * 1000);

            base.LoadContent();

            InitialiseCamera();

            Cursor = new vxCursor3D(vxEngine);

            //
            //Grabbers
            //
            grabber = new MotorizedGrabSpring();
            BEPUPhyicsSpace.Add(grabber);
            rayCastFilter = RayCastFilter;

            workingPlane = new vxWorkingPlane(vxEngine, vxEngine.Model_Sandbox_WorkingPlane, new Vector3(0, WrkngPln_HeightDelta, 0));

            for (int i = 0; i < Items.Count; i++)
            {
                Items[i].Index = i;
            }
            ConnectedMatrix      = Matrix.Identity;
            CurrentlySelectedKey = "";

            if (this.SandboxGameState == vxEnumSandboxGameState.EditMode)
            {
                this.vxEngine.InputManager.ShowCursor = true;
            }

            vxTabPage tabPage_EngineItems = new vxTabPage(vxEngine, tabControl, "General Items");

            tabControl.AddItem(tabPage_EngineItems);

            ScrollPanel_EngineItems = new vxScrollPanel(new Vector2(0, 0),
                                                        vxEngine.GraphicsDevice.Viewport.Width - 150, vxEngine.GraphicsDevice.Viewport.Height - 75);
            tabPage_EngineItems.AddItem(ScrollPanel_EngineItems);

            RegisterSandboxEntities();
        }
Example #4
0
        /// <summary>
        /// Updates Main Gameplay Loop code here, this is affected by whether or not the scene is paused.
        /// </summary>
        /// <param name="gameTime"></param>
        /// <param name="otherScreenHasFocus"></param>
        /// <param name="coveredByOtherScreen"></param>
        public override void UpdateScene(GameTime gameTime, bool otherScreenHasFocus, bool coveredByOtherScreen)
        {
            ParentEntityPlaceHolder = null;

            if (vxEngine.InputManager.IsNewMouseButtonPress(MouseButtons.MiddleButton))
            {
                vxEngine.Mouse_ClickPos = new Vector2(vxEngine.InputManager.MouseState.X, vxEngine.InputManager.MouseState.Y);
            }

            if (IsActive)
            {
                //If it's in Testing Mode, Update the Vehicle and Chase Camera
                if (SandboxGameState == vxEnumSandboxGameState.Running)
                {
                    //drop it out of view
                    workingPlane.Position = OutofSight;
                }

                //Update If In Edit Mode
                if (SandboxGameState == vxEnumSandboxGameState.EditMode)
                {
                    MouseWorld = Matrix.Identity;

                    //Reset to Negative One each loop
                    Index   = -1;
                    AddMode = vxEnumAddMode.OnPlane;

                    Ray Ray_Mouse = vxGeometryHelper.CalculateCursorRay(vxEngine, Camera.Projection, Camera.View);
                    if (!grabber.IsGrabbing)
                    {
                        Cursor.Update(gameTime, Ray_Mouse);

                        if (Cursor.IsMouseHovering == false)
                        {
                            //Next Find the earliest ray hit
                            RayCastResult raycastResult;
                            if (BEPUPhyicsSpace.RayCast(Ray_Mouse, 5000, rayCastFilter, out raycastResult))
                            {
                                var entityCollision = raycastResult.HitObject as EntityCollidable;

                                //Set the Index of the Highlited Item
                                if (raycastResult.HitObject.Tag != null)
                                {
                                    if (raycastResult.HitObject.Tag.GetType() == typeof(int))
                                    {
                                        //Unselect The Previous Selection
                                        if (Index > -1)
                                        {
                                            if (Items[Index] != null)
                                            {
                                                Items[Index].SelectionState = vxEnumSelectionState.Unseleced;
                                            }
                                        }

                                        Vector3 pnt  = raycastResult.HitData.Location;
                                        Vector3 nrml = raycastResult.HitData.Normal;

                                        nrml.Normalize();



                                        //Get Index of Currently Selected Item
                                        Index = Convert.ToInt32(raycastResult.HitObject.Tag);
                                        if (Index < Items.Count)
                                        {
                                            if (Items[Index] != null)
                                            {
                                                Items[Index].SelectionState = vxEnumSelectionState.Hover;

                                                if (Items[Index].GetType() == typeof(vxSnapBox))
                                                {
                                                    if (temp_part != null && entityCollision != null)
                                                    {
                                                        temp_part.SetMesh(entityCollision.WorldTransform.Matrix, false, false);
                                                        ParentEntityPlaceHolder = Items[Index];
                                                        Index = -2;
                                                        vxDebugShapeRenderer.AddBoundingBox(raycastResult.HitObject.BoundingBox, Color.HotPink);
                                                    }
                                                }

                                                else
                                                {
                                                    if (temp_part != null && IsSurface(Items[Index]))
                                                    {
                                                        vxDebugShapeRenderer.AddBoundingSphere(
                                                            new BoundingSphere(pnt, 1), Color.Blue);

                                                        vxDebugShapeRenderer.AddLine(
                                                            pnt, pnt + 5 * nrml, Color.LimeGreen);

                                                        Vector3 fwd = Vector3.Cross(Vector3.UnitX + Vector3.UnitZ, nrml);
                                                        fwd.Normalize();

                                                        AddMode    = vxEnumAddMode.OnSurface;
                                                        MouseWorld = Matrix.CreateWorld(pnt, fwd, nrml);
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }

                    //If Index still equals -1, then it isn't over any elements, and a new element can be added.
                    int_intersc_previous = int_intersc;

                    if (SandboxGameState == vxEnumSandboxGameState.EditMode)
                    {
                        if (Ray_Mouse.Intersects(workingPlane.WrknPlane) != null)
                        {
                            Vector3 intersection = (float)Ray_Mouse.Intersects(workingPlane.WrknPlane) * Ray_Mouse.Direction + Ray_Mouse.Position;
                            int_intersc = new Vector3((int)intersection.X, (int)intersection.Y, (int)intersection.Z);
                        }

                        if (temp_part != null && Index > -2)
                        {
                            if (AddMode == vxEnumAddMode.OnSurface && temp_part.CanBePlacedOnSurface == true)
                            {
                                temp_part.SetMesh(MouseWorld, false, false);
                            }
                            else
                            {
                                temp_part.Position = int_intersc;
                                temp_part.SetMesh(false, false);
                            }
                        }
                    }

                    else
                    {
                        //Get it WAYYYY out of the scene
                        int_intersc = OutofSight;
                    }



                    // Update Cursor
                    //**********************************************************

                    Vector3 CursorAverage = Vector3.Zero;
                    for (int ind = 0; ind < SelectedItems.Count; ind++)
                    {
                        SelectedItems[ind].SelectionState = vxEnumSelectionState.Selected;
                        CursorAverage += SelectedItems[ind].World.Translation;
                    }

                    //Only Set the Cursor Position if the Mouse is Up, otherwise, the cursor sets the entity positions
                    if (SelectedItems.Count > 0 && vxEngine.InputManager.MouseState.LeftButton == ButtonState.Released)
                    {
                        CursorAverage  /= SelectedItems.Count;
                        Cursor.Position = CursorAverage;
                    }
                }

                if (vxEngine.InputManager.MouseState.MiddleButton == ButtonState.Pressed)
                {
                    Mouse.SetPosition((int)vxEngine.Mouse_ClickPos.X, (int)vxEngine.Mouse_ClickPos.Y);
                }
            }
            base.UpdateScene(gameTime, otherScreenHasFocus, coveredByOtherScreen);
        }
        /// <summary>
        /// Updates the state of the game. This method checks the vxGameBaseScreen.IsActive
        /// property, so the game will stop updating when the pause menu is active,
        /// or if you tab away to a different application.
        /// </summary>
        public sealed override void Update(GameTime gameTime, bool otherScreenHasFocus,
                                           bool coveredByOtherScreen)
        {
            base.Update(gameTime, otherScreenHasFocus, false);


            // Gradually fade in or out depending on whether we are covered by the pause screen.
            if (coveredByOtherScreen && IsPausable)
            {
                pauseAlpha = Math.Min(pauseAlpha + 1f / 32, 1);
            }
            else
            {
                pauseAlpha = Math.Max(pauseAlpha - 1f / 32, 0);
            }

            if (IsActive || IsPausable == false)
            {
                #region Set Debug Info

                BEPUDebugDrawer.Update();

                // check for other keys pressed on keyboard
                if (vxEngine.InputManager.IsNewKeyPress(Keys.P))
                {
                    var previousSceneShadowMode = mSceneShadowMode;
                    mSceneShadowMode = nextEnumValue(mSceneShadowMode);

                    if (previousSceneShadowMode < vxEnumSceneShadowMode.BlockPattern && mSceneShadowMode >= vxEnumSceneShadowMode.BlockPattern ||
                        previousSceneShadowMode >= vxEnumSceneShadowMode.BlockPattern && mSceneShadowMode < vxEnumSceneShadowMode.BlockPattern)
                    {
                        vxEngine.Renderer.swapShadowMapWithBlockTexture();
                    }

                    foreach (vxEntity entity in Entities)
                    {
                        ((vxEntity3D)entity).renderShadowSplitIndex = mSceneShadowMode >= vxEnumSceneShadowMode.SplitColors;
                    }
                }

                vxEngine.Renderer.mSnapShadowMaps = true;
                if (vxEngine.InputManager.IsNewKeyPress(Keys.F))
                {
                    vxEngine.Renderer.mSnapShadowMaps = !vxEngine.Renderer.mSnapShadowMaps;
                }
                //vxConsole.WriteToInGameDebug("f:" + vxEngine.Renderer.mSnapShadowMaps);

                if (vxEngine.InputManager.IsNewKeyPress(Keys.T))
                {
                    foreach (vxEntity entity in Entities)
                    {
                        ((vxEntity3D)entity).TextureEnabled = !((vxEntity3D)entity).TextureEnabled;
                    }
                }

                #endregion


                //Update Audio Manager
                //**********************************************************************************************
                AudioManager.Listener.Position = Camera.Position / 100;
                AudioManager.Listener.Forward  = Camera.View.Forward;
                AudioManager.Listener.Up       = Camera.View.Up;
                AudioManager.Listener.Velocity = Camera.View.Forward;


                // Update Physics
                //**********************************************************************************************

                // Start measuring time for "Physics".
                vxEngine.DebugSystem.TimeRuler.BeginMark("Physics", Color.LimeGreen);

                //Update the Physics System.
                //vxConsole.WriteToInGameDebug(((float)gameTime.ElapsedGameTime.Milliseconds)/1000);
                //vxConsole.WriteToInGameDebug((float)gameTime.ElapsedGameTime.TotalSeconds);
                //BEPUPhyicsSpace.Update ((float)gameTime.ElapsedGameTime.TotalSeconds);
                BEPUPhyicsSpace.Update();

                // Stop measuring time for "Draw".
                vxEngine.DebugSystem.TimeRuler.EndMark("Physics");



                // Update the Scene
                //**********************************************************************************************
                UpdateScene(gameTime, otherScreenHasFocus, false);



                // Update Scene Entities
                //**********************************************************************************************
                for (int i = 0; i < Entities.Count; i++)
                {
                    Entities [i].Update(gameTime);

                    if (Entities [i].KeepUpdating == false)
                    {
                        Entities.RemoveAt(i);
                    }
                }

                // Update Particle System
                //**********************************************************************************************
                ParticleSystem.Update(gameTime);


                // Update Camera
                //**********************************************************************************************
                UpdateCameraChaseTarget();
                Camera.Update(gameTime);


                vxEngine.Renderer.setLightPosition(-LightPositions);

                // Tell the lensflare component where our camera is positioned.
                lensFlare.LightDir   = SunEmitter.LightDirection;
                lensFlare.View       = Camera.View;
                lensFlare.Projection = Camera.Projection;
            }
            else
            {
                vxEngine.InputManager.ShowCursor = true;
            }
        }
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        public override void LoadContent()
        {
            //Load Global Content First
            if (vxEngine.HasContentBeenLoaded == false)
            {
                vxEngine.LoadGlobalContent(vxEngine.Game.Content);
            }

            InitialiseLevel();
            d = new Envrio(vxEngine, vxEngine.vxContentManager.LoadModel("Models/courtyard/td_courtyard"), new Vector3(20, 0, 0));
            //d = new Envrio(vxEngine, vxEngine.vxContentManager.LoadModel("Models/castle/mdl_castle"), new Vector3(20, 0, 0));
            //d.NormalMap = vxEngine.Game.Content.Load<Texture2D>("Models/courtyard/crtyrd_bricks_nm");
            //d.SpecularMap = vxEngine.Game.Content.Load<Texture2D>("Models/courtyard/crtyrd_bricks_sm");
            d.SpecularIntensity = 1;

            waterItems.Add(new vxWaterEntity(vxEngine, Vector3.Up, new Vector3(500, 1, 500)));

            vxModel mod = vxEngine.vxContentManager.LoadModel("Models/cbe/cbe");

            new Envrio(vxEngine, mod, new Vector3(-5, 5, 0));
            //mod.SetTexturePackLevel(vxEnumQuality.Low);
            //mod.SetTexturePackLevel(vxEnumQuality.High);
            //mod.SetTexturePackLevel(vxEnumQuality.Ultra);
            //mod.SetTexturePackLevel(vxEnumQuality.Medium);

            //vxTexture2D newtexture = new vxTexture2D(vxEngine, "Models/cbe/Cube_dds");

            int size    = 100;
            Box baseBox = new Box(new Vector3(0, -5, 0), size, 10, size);

            BEPUPhyicsSpace.Add(baseBox);

            ///////////////////////////////////////////////////////////////////////
            //Initialise Camera Code
            ///////////////////////////////////////////////////////////////////////
            #region Set Up Camera

            base.LoadContent();


            Camera.CameraType  = CameraType.Orbit;
            Camera.OrbitTarget = new Vector3(0, 1.5f, 0);
            //Camera.OrbitZoom = -375;

            //
            //Grabbers
            //
            grabber = new MotorizedGrabSpring();
            BEPUPhyicsSpace.Add(grabber);
            rayCastFilter = RayCastFilter;

            IsPausable = false;

            #endregion

            int          height = 3;
            ConcreteCube cc     = new ConcreteCube((GameEngine)vxEngine, new Vector3(0, 5, 0));
            cc.SetMesh(Matrix.CreateTranslation(new Vector3(0, height, 0)), true, true);

            cc = new ConcreteCube((GameEngine)vxEngine, new Vector3(0, 5, 4f));
            cc.SetMesh(Matrix.CreateTranslation(new Vector3(0, height, 5f)), true, true);

            cc = new ConcreteCube((GameEngine)vxEngine, new Vector3(0, 5, 4f));
            cc.SetMesh(Matrix.CreateTranslation(new Vector3(0, height, -5f)), true, true);
        }
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        public override void LoadContent()
        {
            InitialiseLevel();


            ///////////////////////////////////////////////////////////////////////
            //Initialise Camera Code
            ///////////////////////////////////////////////////////////////////////
            #region Set Up Camera

            base.LoadContent();
            Camera.CameraType = CameraType.CharacterFPS;

            character = new CharacterControllerInput(BEPUPhyicsSpace, Camera, vxEngine);

            //Since this is the character playground, turn on the character by default.
            character.Activate();

            //Having the character body visible would be a bit distracting.
            character.CharacterController.Body.Tag = "noDisplayObject";

            SimulationStart();
            SimulationStop();

            //
            //Grabbers
            //
            grabber = new MotorizedGrabSpring();
            BEPUPhyicsSpace.Add(grabber);
            rayCastFilter = RayCastFilter;


            #endregion

            DoFog   = true;
            FogNear = 20;
            FogFar  = Camera.FarPlane / 4;

            Envrio envr = new Envrio(vxEngine, vxEngine.vxContentManager.LoadModel("Models/courtyard/td_courtyard"), Vector3.Zero);

            //Envrio envr = new Envrio(vxEngine, vxEngine.vxContentManager.LoadModel("Models/castle/mdl_castle"), new Vector3(0, 1, 0));

            //waterItems.Add(new vxWaterEntity(vxEngine, Vector3.Up, new Vector3(50, 0.25f, 50)));


            envr.SpecularIntensity = 1;
            //envr.SpecularIntensity = 100;
            //envr.SpecularPower = 5f;
            //envr.DoFog = false;

            light = new vxLightEntity(vxEngine, new Vector3(0, 2, 0), LightType.Point, Color.Orange, 10, 1);

            //This is a little convenience method used to extract vertices and indices from a model.
            //It doesn't do anything special; any approach that gets valid vertices and indices will work.

                        #if !TECHDEMO_PLTFRM_GL
            ModelDataExtractor.GetVerticesAndIndicesFromModel(envr.vxModel.ModelMain, out staticTriangleVertices, out staticTriangleIndices);

            //var staticMesh = new StaticMesh(staticTriangleVertices, staticTriangleIndices, new AffineTransform(Matrix3X3.CreateFromAxisAngle(Vector3.Up, MathHelper.Pi), new Vector3(0, -10, 0)));
            var staticMesh = new StaticMesh(staticTriangleVertices, staticTriangleIndices,
                                            new AffineTransform(new Vector3(1),
                                                                Quaternion.CreateFromRotationMatrix(Matrix.CreateRotationX(-MathHelper.PiOver2) * Matrix.CreateRotationY(0)),
                                                                new Vector3(0)));
            staticMesh.Sidedness = TriangleSidedness.Counterclockwise;

            BEPUPhyicsSpace.Add(staticMesh);
            BEPUDebugDrawer.Add(staticMesh);
                        #endif

            int size = 100;
            BEPUPhyicsSpace.Add(new Box(new Vector3(0, -5, 0), size, 10, size));

            vxTabPage Straights = new vxTabPage(vxEngine, tabControl, "Items");
            tabControl.AddItem(Straights);

            vxScrollPanel ScrollPanel_GeneralItemsPage = new vxScrollPanel(new Vector2(0, 0),
                                                                           vxEngine.GraphicsDevice.Viewport.Width - 150, vxEngine.GraphicsDevice.Viewport.Height - 75);

            //Cubes
            ScrollPanel_GeneralItemsPage.AddItem(new vxScrollPanelSpliter(vxEngine, "Items"));
            ScrollPanel_GeneralItemsPage.AddItem(RegisterNewSandboxItem(WoodenCrate.EntityDescription));

            //Add the scrollpanel to the slider tab page.
            Straights.AddItem(ScrollPanel_GeneralItemsPage);

            //IndexedCubeTest cube = new IndexedCubeTest(vxEngine, new Vector3(4, 4, 0));


            Teapot t = new Teapot((GameEngine)vxEngine, new Vector3(4, 4, 0));
            t.SetMesh(Matrix.CreateTranslation(new Vector3(4, 2, 0)), true, true);

            ConcreteCube cc = new ConcreteCube((GameEngine)vxEngine, new Vector3(0, 5, 0));
            cc.SetMesh(Matrix.CreateTranslation(new Vector3(0, 2, 0)), true, true);


            ModelObjs mo = new ModelObjs((GameEngine)vxEngine, new Vector3(-4, 4, 0));
            mo.SetMesh(Matrix.CreateTranslation(new Vector3(0, 2, 8)), true, true);

            vxEngine.InputManager.ShowCursor = true;
        }