Exemplo n.º 1
0
		public void CreateAndDisposeCapsuleController()
		{
			using (var core = CreatePhysicsAndScene())
			{
				var controllerManager = core.Scene.CreateControllerManager();

				var material = core.Physics.CreateMaterial(0.1f, 0.1f, 0.1f);

				var desc = new BoxControllerDesc()
				{
					Extents = new Math.Vector3(5, 5, 5),
					Material = material
				};

				Assert.IsTrue(desc.IsValid());

				BoxController boxController;
				using (boxController = controllerManager.CreateController<BoxController>(desc))
				{
					Assert.IsNotNull(boxController);
					Assert.IsFalse(boxController.Disposed);
				}

				Assert.IsTrue(boxController.Disposed);
			}
		}
Exemplo n.º 2
0
        public void CreateAndDisposeCapsuleController()
        {
            using (var core = CreatePhysicsAndScene())
            {
                var controllerManager = core.Scene.CreateControllerManager();

                var material = core.Physics.CreateMaterial(0.1f, 0.1f, 0.1f);

                var desc = new BoxControllerDesc()
                {
                    Extents  = new Math.Vector3(5, 5, 5),
                    Material = material
                };

                Assert.IsTrue(desc.IsValid());

                BoxController boxController;
                using (boxController = controllerManager.CreateController <BoxController>(desc))
                {
                    Assert.IsNotNull(boxController);
                    Assert.IsFalse(boxController.Disposed);
                }

                Assert.IsTrue(boxController.Disposed);
            }
        }
Exemplo n.º 3
0
        public override void init()
        {
            #region ground
            MeshManager.Singleton.CreatePlane("ground",
                                              ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME,
                                              new Plane(Mogre.Vector3.UNIT_Y, 0),
                                              1500, 1500, 20, 20, true, 1, 5, 5, Mogre.Vector3.UNIT_Z);
            // Create a ground plane
            entities.Add(OgreWindow.Instance.mSceneMgr.CreateEntity("GroundEntity", "ground"));
            entities["GroundEntity"].CastShadows = false;
            entities["GroundEntity"].SetMaterialName("dirt");
            nodes.Add(OgreWindow.Instance.mSceneMgr.RootSceneNode.CreateChildSceneNode("ground"));
            nodes["ground"].AttachObject(entities["GroundEntity"]);
            nodes["ground"].Position = new Mogre.Vector3(0f, 0f, 0f) + Location().toMogre;

            // the actor properties control the mass, position and orientation
            // if you leave the body set to null it will become a static actor and wont move
            ActorDesc actorDesc2 = new ActorDesc();
            actorDesc2.Density           = 4;
            actorDesc2.Body              = null;
            actorDesc2.GlobalPosition    = nodes["ground"].Position;
            actorDesc2.GlobalOrientation = nodes["ground"].Orientation.ToRotationMatrix();


            PhysXHelpers.StaticMeshData meshdata = new PhysXHelpers.StaticMeshData(entities["GroundEntity"].GetMesh());
            actorDesc2.Shapes.Add(PhysXHelpers.CreateTriangleMesh(meshdata));
            Actor actor2 = null;
            try { actor2 = OgreWindow.Instance.scene.CreateActor(actorDesc2); }
            catch (System.AccessViolationException ex) { log(ex.ToString()); }
            if (actor2 != null)
            {
                // create our special actor node to tie together the scene node and actor that we can update its position later
                ActorNode actorNode2 = new ActorNode(nodes["ground"], actor2);
                actors.Add(actorNode2);
            }
            #endregion



            lights.Add(OgreWindow.Instance.mSceneMgr.CreateLight("playerLight"));
            lights["playerLight"].Type           = Light.LightTypes.LT_POINT;
            lights["playerLight"].Position       = Location().toMogre;
            lights["playerLight"].DiffuseColour  = ColourValue.White;
            lights["playerLight"].SpecularColour = ColourValue.White;

            #region drone

            OgreWindow.Instance.skeletons["\\Drone.skeleton"].Load();
            OgreWindow.Instance.meshes["\\Drone.mesh"].Load();
            OgreWindow.Instance.meshes["\\Drone.mesh"].SkeletonName = "\\Drone.skeleton";

            entities.Add(OgreWindow.Instance.mSceneMgr.CreateEntity("drone", "\\Drone.mesh"));

            entities["drone"].CastShadows = true;
            walkState         = entities["drone"].GetAnimationState("walk");
            walkState.Enabled = true;
            walkState.Loop    = true;
            entities["drone"].SetMaterialName("metal");
            nodes.Add(OgreWindow.Instance.mSceneMgr.RootSceneNode.CreateChildSceneNode("drone"));
            nodes["drone"].AttachObject(entities["drone"]);
            nodes["drone"].Position = new Mogre.Vector3(0f, 40f, 0f) + Location().toMogre;
            nodes["drone"].Scale(new Mogre.Vector3(.3f));

            nodes.Add(nodes["drone"].CreateChildSceneNode("orbit0"));
            nodes.Add(nodes["orbit0"].CreateChildSceneNode("orbit"));
            nodes["orbit"].Position = Location().toMogre;
            nodes["orbit"].AttachObject(OgreWindow.Instance.mCamera);
            nodes["drone"].SetFixedYawAxis(true);



            #endregion


            //#region baseball
            //entities.Add(OgreWindow.Instance.mSceneMgr.CreateEntity("baseball", "\\baseball.mesh"));
            //entities["baseball"].SetMaterialName("baseball");
            ////nodes.Add(OgreWindow.Instance.mSceneMgr.RootSceneNode.CreateChildSceneNode("baseball"));
            //nodes.Add(nodes["drone"].CreateChildSceneNode("baseball"));
            //nodes["baseball"].AttachObject(entities["baseball"]);
            //nodes["baseball"].SetScale(.5f, .5f, .5f);
            //nodes["baseball"].SetPosition(-3f, 7f, 3f);
            //// nodes["baseball"].SetScale(5f, 5f, 5f);
            //#endregion

            #region player physics
            bcd     = new BoxControllerDesc();
            control = OgreWindow.Instance.physics.ControllerManager.CreateController(OgreWindow.Instance.scene, bcd); //System.NullReferenceException
            #endregion

            nodes.Add(OgreWindow.Instance.mSceneMgr.RootSceneNode.CreateChildSceneNode("suspensionY"));

            OgreWindow.g_m.MouseMoved += new MouseListener.MouseMovedHandler(mouseMoved);
            middlemousetimer.reset();
            middlemousetimer.start();

            this.btnLimiter_F.reset();
            this.btnLimiter_F.start();

            ready = true;
            new Thread(new ThreadStart(controlThread)).Start();
            new Thread(new ThreadStart(statusUpdaterThread)).Start();

            localY = nodes["drone"]._getDerivedOrientation() * Mogre.Vector3.UNIT_Y;
            localZ = nodes["drone"]._getDerivedOrientation() * Mogre.Vector3.UNIT_Z;
            localX = nodes["drone"]._getDerivedOrientation() * Mogre.Vector3.UNIT_X;

            OgreWindow.Instance.tbTextToSend.GotFocus  += new EventHandler(tbTextToSend_GotFocus);
            OgreWindow.Instance.tbTextToSend.LostFocus += new EventHandler(tbTextToSend_LostFocus);
            OgreWindow.Instance.tbConsole.GotFocus     += new EventHandler(tbConsole_GotFocus);
            OgreWindow.Instance.tbConsole.LostFocus    += new EventHandler(tbConsole_LostFocus);
        }
Exemplo n.º 4
0
        public override void init()
        {
            #region ground
            MeshManager.Singleton.CreatePlane("ground",
                ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME,
                new Plane(Mogre.Vector3.UNIT_Y, 0),
                1500, 1500, 20, 20, true, 1, 5, 5, Mogre.Vector3.UNIT_Z);
            // Create a ground plane
            entities.Add(OgreWindow.Instance.mSceneMgr.CreateEntity("GroundEntity", "ground"));
            entities["GroundEntity"].CastShadows = false;
            entities["GroundEntity"].SetMaterialName("dirt");
            nodes.Add(OgreWindow.Instance.mSceneMgr.RootSceneNode.CreateChildSceneNode("ground"));
            nodes["ground"].AttachObject(entities["GroundEntity"]);
            nodes["ground"].Position = new Mogre.Vector3(0f, 0f, 0f) + Location().toMogre;

            // the actor properties control the mass, position and orientation
            // if you leave the body set to null it will become a static actor and wont move
            ActorDesc actorDesc2 = new ActorDesc();
            actorDesc2.Density = 4;
            actorDesc2.Body = null;
            actorDesc2.GlobalPosition = nodes["ground"].Position;
            actorDesc2.GlobalOrientation = nodes["ground"].Orientation.ToRotationMatrix();

            PhysXHelpers.StaticMeshData meshdata = new PhysXHelpers.StaticMeshData(entities["GroundEntity"].GetMesh());
            actorDesc2.Shapes.Add(PhysXHelpers.CreateTriangleMesh(meshdata));
            Actor actor2 = null;
            try { actor2 = OgreWindow.Instance.scene.CreateActor(actorDesc2); }
            catch (System.AccessViolationException ex) { log(ex.ToString()); }
            if (actor2 != null)
            {
                // create our special actor node to tie together the scene node and actor that we can update its position later
                ActorNode actorNode2 = new ActorNode(nodes["ground"], actor2);
                actors.Add(actorNode2);
            }
            #endregion

            lights.Add(OgreWindow.Instance.mSceneMgr.CreateLight("playerLight"));
            lights["playerLight"].Type = Light.LightTypes.LT_POINT;
            lights["playerLight"].Position = Location().toMogre;
            lights["playerLight"].DiffuseColour = ColourValue.White;
            lights["playerLight"].SpecularColour = ColourValue.White;

            #region drone

            OgreWindow.Instance.skeletons["\\Drone.skeleton"].Load();
            OgreWindow.Instance.meshes["\\Drone.mesh"].Load();
            OgreWindow.Instance.meshes["\\Drone.mesh"].SkeletonName = "\\Drone.skeleton";

            entities.Add(OgreWindow.Instance.mSceneMgr.CreateEntity("drone", "\\Drone.mesh"));

            entities["drone"].CastShadows = true;
            walkState = entities["drone"].GetAnimationState("walk");
            walkState.Enabled = true;
            walkState.Loop = true;
            entities["drone"].SetMaterialName("metal");
            nodes.Add(OgreWindow.Instance.mSceneMgr.RootSceneNode.CreateChildSceneNode("drone"));
            nodes["drone"].AttachObject(entities["drone"]);
            nodes["drone"].Position = new Mogre.Vector3(0f, 40f, 0f) + Location().toMogre;
            nodes["drone"].Scale(new Mogre.Vector3(.3f));

            nodes.Add(nodes["drone"].CreateChildSceneNode("orbit0"));
            nodes.Add(nodes["orbit0"].CreateChildSceneNode("orbit"));
            nodes["orbit"].Position = Location().toMogre;
            nodes["orbit"].AttachObject(OgreWindow.Instance.mCamera);
            nodes["drone"].SetFixedYawAxis(true);

            #endregion

            //#region baseball
            //entities.Add(OgreWindow.Instance.mSceneMgr.CreateEntity("baseball", "\\baseball.mesh"));
            //entities["baseball"].SetMaterialName("baseball");
            ////nodes.Add(OgreWindow.Instance.mSceneMgr.RootSceneNode.CreateChildSceneNode("baseball"));
            //nodes.Add(nodes["drone"].CreateChildSceneNode("baseball"));
            //nodes["baseball"].AttachObject(entities["baseball"]);
            //nodes["baseball"].SetScale(.5f, .5f, .5f);
            //nodes["baseball"].SetPosition(-3f, 7f, 3f);
            //// nodes["baseball"].SetScale(5f, 5f, 5f);
            //#endregion

            #region player physics
            bcd = new BoxControllerDesc();
            control = OgreWindow.Instance.physics.ControllerManager.CreateController(OgreWindow.Instance.scene, bcd); //System.NullReferenceException
            #endregion

            nodes.Add(OgreWindow.Instance.mSceneMgr.RootSceneNode.CreateChildSceneNode("suspensionY"));

            OgreWindow.g_m.MouseMoved += new MouseListener.MouseMovedHandler(mouseMoved);
            middlemousetimer.reset();
            middlemousetimer.start();

            this.btnLimiter_F.reset();
            this.btnLimiter_F.start();

            ready = true;
            new Thread(new ThreadStart(controlThread)).Start();
            new Thread(new ThreadStart(statusUpdaterThread)).Start();

            localY = nodes["drone"]._getDerivedOrientation() * Mogre.Vector3.UNIT_Y;
            localZ = nodes["drone"]._getDerivedOrientation() * Mogre.Vector3.UNIT_Z;
            localX = nodes["drone"]._getDerivedOrientation() * Mogre.Vector3.UNIT_X;

            OgreWindow.Instance.tbTextToSend.GotFocus += new EventHandler(tbTextToSend_GotFocus);
            OgreWindow.Instance.tbTextToSend.LostFocus += new EventHandler(tbTextToSend_LostFocus);
            OgreWindow.Instance.tbConsole.GotFocus += new EventHandler(tbConsole_GotFocus);
            OgreWindow.Instance.tbConsole.LostFocus += new EventHandler(tbConsole_LostFocus);
        }
Exemplo n.º 5
0
 public Controller CreateCharacterController(BoxControllerDesc desc)
 {
     return physics.ControllerManager.CreateController(this.scene, desc);
 }
Exemplo n.º 6
0
 public Controller CreateCharacterController(BoxControllerDesc desc)
 {
     return(physics.ControllerManager.CreateController(this.scene, desc));
 }
        public override object Process(Scene scene, Frame node)
        {
            if (scene == null || scene.Physics == null)
            {
                return(null);
            }

            string tag = node.Tag;

            if (tag == null)
            {
                return(null);
            }

            var match = _regex.Match(tag);

            if (!match.Success)
            {
                return(null);
            }

            var obj = node.Component as IFrameMesh;

            if (obj == null)
            {
                return(null);
            }

            CharacterControllerDesc controllerDesc;
            var shapeDesc = obj.Mesh.CreateShapeDescriptor();

            if (shapeDesc.Type == Physics.ShapeType.BOX)
            {
                BoxShapeDesc box = (BoxShapeDesc)shapeDesc;
                controllerDesc = new BoxControllerDesc
                {
                    Extents     = box.Dimensions,
                    Position    = box.LocalPose.Translation + node.GlobalPose.Translation,
                    UpDirection = HeightFieldAxis.Y,
                    SlopeLimit  = (float)Math.Cos(Numerics.ToRadians(45.0f)),
                    Name        = node.Name
                };
            }
            else if (shapeDesc.Type == Physics.ShapeType.CAPSULE)
            {
                CapsuleShapeDesc capsuleShape = (CapsuleShapeDesc)shapeDesc;
                controllerDesc = new CapsuleControllerDesc
                {
                    Height      = capsuleShape.Height,
                    Position    = capsuleShape.LocalPose.Translation + node.GlobalPose.Translation,
                    Radius      = capsuleShape.Radius,
                    UpDirection = HeightFieldAxis.Y,
                    SlopeLimit  = (float)Math.Cos(Numerics.ToRadians(45.0f)),
                    Name        = node.Name
                };
            }
            else
            {
                return(null);
            }

            Frame bindedNode = null;

            if (match.Groups["BINDING"].Success)
            {
                bindedNode = scene.FindNode(match.Groups["BINDING"].Value);
            }
            if (ControllerCreated != null)
            {
                ControllerCreated(controllerDesc, bindedNode);
            }


            var controller = CharacterControllerManager.Instance.CreateController(scene.Physics, controllerDesc);

            if (bindedNode != null)
            {
                bindedNode.BindTo(controller);
            }

            obj.Mesh.Dispose();
            node.Remove();
            node.Dispose();

            return(controller);
        }