bool Scene_FrameStarted(FrameEvent evt) { inputKeyboard.Capture(); if (inputKeyboard.IsKeyDown(MOIS.KeyCode.KC_SPACE)) { if (timer <= 0.0) { Vector3 dir, vec; Quaternion camorient = camera.Orientation; vec = new Vector3(0, 0, -1); dir = camorient * vec; Entity ent; SceneNode node; String name; Vector3 pos = camera.Position; name = "Body " + (mEntityCount++); ent = sceneMgr.CreateEntity(name, "ellipsoid.mesh"); node = sceneMgr.RootSceneNode.CreateChildSceneNode(name); node.AttachObject(ent); ent.SetMaterialName("Simple/dirt01"); MogreNewt.Collision col = new MogreNewt.CollisionPrimitives.Ellipsoid(m_World, new Vector3(1, 1, 1)); MogreNewt.Body body = new MogreNewt.Body(m_World, col); Vector3 inertia = MogreNewt.MomentOfInertia.CalcSphereSolid(10.0f, 1.0f); body.SetMassMatrix(10.0f, inertia); body.AttachToNode(node); body.IsGravityEnabled = true; body.SetPositionOrientation(pos, camorient); body.Velocity = dir * 15.0f; timer = 0.2f; } } timer -= evt.timeSinceLastFrame; // --------------------------------------------------------- // -- VEHICLE CONTORLS // --------------------------------------------------------- float torque = 0.0f; Degree steering = new Degree(0); if (inputKeyboard.IsKeyDown(MOIS.KeyCode.KC_I)) { torque += 600.0f; } if (inputKeyboard.IsKeyDown(MOIS.KeyCode.KC_K)) { torque -= 600.0f; } if (inputKeyboard.IsKeyDown(MOIS.KeyCode.KC_J)) { steering += new Degree(30); } if (inputKeyboard.IsKeyDown(MOIS.KeyCode.KC_L)) { steering -= new Degree(30); } //update the vehicle! mCar.setTorqueSteering(torque, steering); if ((inputKeyboard.IsKeyDown(MOIS.KeyCode.KC_Q)) && (!mR)) { mR = true; // rebuild the vehicle if (mCar != null) { mCar.Dispose(); mCar = new SimpleVehicle(sceneMgr, m_World, new Vector3(0, (float)new Random().NextDouble() * 10.0f, 0), Quaternion.IDENTITY); } } if (!inputKeyboard.IsKeyDown(MOIS.KeyCode.KC_Q)) { mR = false; } return(true); }
public PlayerController(Mogre.Node node, Mogre.Entity entity, float mass) { //init logic states for controler initLogicStates(); //force direction m_GoTo = Mogre.Quaternion.IDENTITY; //node to update m_PlayerNode = node; //Ball MogreNewt.ConvexCollision collision = new MogreNewt.CollisionPrimitives.Ellipsoid( Core.Singleton.NewtonWorld, new Mogre.Vector3(0.25f, 0.25f, 0.25f), new Mogre.Quaternion(new Mogre.Radian(1.57f), new Mogre.Vector3(0, 1, 0)), Core.Singleton.GetUniqueBodyId()); Mogre.Vector3 inertia, offset; collision.CalculateInertialMatrix(out inertia, out offset); inertia *= mass;//mass m_MainBody = new MogreNewt.Body(Core.Singleton.NewtonWorld, collision, true); m_MainBody.SetMassMatrix(mass, inertia); m_MainBody.AutoSleep = false; m_MainBody.LinearDamping = 1.0f; m_MainBody.Transformed += BodyTransformCallback; m_MainBody.ForceCallback += BodyForceCallback; m_MainBody.UserData = this; m_MainBody.Type = (int)PhysicsManager.BodyTypes.PLAYER; collision.Dispose(); m_MainBody.MaterialGroupID = Core.Singleton.PhysicsManager.getMaterialID("Player"); //Ball end m_Pose = m_myPoses["normal"]; ///Second helper body Mogre.Vector3 inertia2, offset2; m_Pose.m_collision.CalculateInertialMatrix(out inertia2, out offset2); inertia2 *= 1; m_SecondBody = new MogreNewt.Body(Core.Singleton.NewtonWorld, m_Pose.m_collision, true); m_SecondBody.SetMassMatrix(1, inertia2); m_SecondBody.AutoSleep = false; m_SecondBody.IsGravityEnabled = false; m_SecondBody.SetPositionOrientation(new Mogre.Vector3(0, 1f, 0), Mogre.Quaternion.IDENTITY); m_SecondBody.MaterialGroupID = Core.Singleton.PhysicsManager.getMaterialID("Player"); m_SecondBody.UserData = null; //set Y joint for second body MogreNewt.Joint upVector = new MogreNewt.BasicJoints.UpVector( Core.Singleton.NewtonWorld, m_SecondBody, Mogre.Vector3.UNIT_Y); //connections between player bodies! player_join = new MogreNewt.BasicJoints.BallAndSocket(Core.Singleton.NewtonWorld, m_MainBody, m_SecondBody, new Mogre.Vector3(0, 0, 0)); }