//public event JumpEventHandler JumpEvent; public BulletMobState(KinematicCharacterController mobController, Vector3 mobNodePositionUpdate) { this.mobController = mobController; this.mobNodePositionUpdate = mobNodePositionUpdate; }
public override void InitializeDemo() { base.InitializeDemo(); SetCameraDistance(50f); //string filename = @"E:\users\man\bullet\xna-basic-output-1.txt"; //FileStream filestream = File.Open(filename, FileMode.Create, FileAccess.Write, FileShare.Read); //BulletGlobals.g_streamWriter = new StreamWriter(filestream); ///collision configuration contains default setup for memory, collision setup m_collisionConfiguration = new DefaultCollisionConfiguration(); ///use the default collision dispatcher. For parallel processing you can use a diffent dispatcher (see Extras/BulletMultiThreaded) m_dispatcher = new CollisionDispatcher(m_collisionConfiguration); IndexedVector3 worldMin = new IndexedVector3 (-1000,-1000,-1000); IndexedVector3 worldMax = -worldMin; m_broadphase = new AxisSweep3Internal(ref worldMin, ref worldMax, 0xfffe, 0xffff, 16384, null, false); //pairCache = new SortedOverlappingPairCache(); //m_broadphase = new SimpleBroadphase(1000, pairCache); ///the default constraint solver. For parallel processing you can use a different solver (see Extras/BulletMultiThreaded) SequentialImpulseConstraintSolver sol = new SequentialImpulseConstraintSolver(); m_constraintSolver = sol; m_dynamicsWorld = new DiscreteDynamicsWorld(m_dispatcher, m_broadphase, m_constraintSolver, m_collisionConfiguration); m_dynamicsWorld.GetDispatchInfo().SetAllowedCcdPenetration(0.0001f); IndexedVector3 gravity = new IndexedVector3(0, -10, 0); m_dynamicsWorld.SetGravity(ref gravity); ///create a few basic rigid bodies IndexedVector3 halfExtents = new IndexedVector3(50, 50, 50); //IndexedVector3 halfExtents = new IndexedVector3(10, 10, 10); CollisionShape groundShape = new BoxShape(ref halfExtents); //CollisionShape groundShape = new StaticPlaneShape(new IndexedVector3(0,1,0), 50); m_collisionShapes.Add(groundShape); IndexedMatrix groundTransform = IndexedMatrix.CreateTranslation(new IndexedVector3(0, -50, 0)); //IndexedMatrix groundTransform = IndexedMatrix.CreateTranslation(new IndexedVector3(0,-10,0)); float mass = 0f; LocalCreateRigidBody(mass, ref groundTransform, groundShape); #region CharacterController IndexedMatrix startTransform = IndexedMatrix.Identity; //startTransform.setOrigin (btVector3(0.0, 4.0, 0.0)); startTransform._origin = new IndexedVector3(10.210098f,-1.6433364f,16.453260f); m_ghostObject = new PairCachingGhostObject(); m_ghostObject.SetWorldTransform(startTransform); m_broadphase.GetOverlappingPairCache().SetInternalGhostPairCallback(new GhostPairCallback()); float characterHeight=1.75f; float characterWidth =1.75f; ConvexShape capsule = new CapsuleShape(characterWidth,characterHeight); m_ghostObject.SetCollisionShape (capsule); m_ghostObject.SetCollisionFlags (CollisionFlags.CF_CHARACTER_OBJECT); float stepHeight = 0.35f; int upAxis = 1; m_character = new KinematicCharacterController (m_ghostObject,capsule,stepHeight,upAxis); m_dynamicsWorld.AddCollisionObject(m_ghostObject, CollisionFilterGroups.CharacterFilter, CollisionFilterGroups.StaticFilter | CollisionFilterGroups.DefaultFilter); m_dynamicsWorld.AddAction(m_character); #endregion }
public virtual void LoadPlayerController(Entity playerEntity, SceneNode characterNode, object userData, Vector3 mobNodePositionUpdate) { //if (!initialized) //{ // characterToLoad = characterNode; // characterEntityToLoad = playerEntity; // JumpHandlerToLoad = jumpHandler; // MobNodePositionUpdateToLoad = mobNodePositionUpdate; // userDataToLoad = userData; // return; //} if (playerController != null) return; float modelHeight = 2f;// (playerEntity.BoundingBox.Max.Y) / scaleFactor; // AJ: used to subtract minimum from maximum- playerEntity.BoundingBox.Minimum.y System.Console.WriteLine("Player capsule info: modelheight '{0}', boundingbox max '{1}', bounding box min '{2}' and playerPosition '{3}'", modelHeight, playerEntity.BoundingBox.Max.Y, playerEntity.BoundingBox.Min.Y, characterNode.Position); float radius = 1.75f; float height = 1.75f; ConvexShape capsule = new CapsuleShape(radius, height); //ConvexShape capsule = new SphereShape(radius); ghostObject = new PairCachingGhostObject(); Vector3 position = new Vector3(0, 0, 0);//new Vector3(characterNode.Position.X / scaleFactor, (characterNode.Position.Y + 1500) / scaleFactor, characterNode.Position.Z / scaleFactor); //IndexedMatrix worldTransform = IndexedMatrix.CreateTranslation(characterNode.Position.X / scaleFactor, // (characterNode.Position.Y + 1500) / scaleFactor, characterNode.Position.Z / scaleFactor); IndexedMatrix worldTransform = IndexedMatrix.CreateTranslation(position); ghostObject.SetWorldTransform(worldTransform); //broadphase.OverlappingPairCache.SetInternalGhostPairCallback(new GhostPairCallback()); ghostObject.SetCollisionShape(capsule); ghostObject.SetCollisionFlags(CollisionFlags.CF_CHARACTER_OBJECT); float stepHeight = 0.35f; playerController = new KinematicCharacterController(ghostObject, capsule, stepHeight, 1); //characterToLoad = null; BulletMobState mobMovementState = new BulletMobState(playerController, mobNodePositionUpdate); //mobMovementState.JumpEvent += jumpHandler; mobControllers.Add(characterNode, mobMovementState); //m_dynamicsWorld.AddCollisionObject(ghostObject, CollisionFilterGroups.CharacterFilter, CollisionFilterGroups.StaticFilter | CollisionFilterGroups.DefaultFilter); m_dynamicsWorld.AddCollisionObject(ghostObject, CollisionFilterGroups.CharacterFilter, CollisionFilterGroups.StaticFilter | CollisionFilterGroups.DefaultFilter); //m_dynamicsWorld.AddCollisionObject(ghostObject, CollisionFilterGroups.DefaultFilter, CollisionFilterGroups.AllFilter); m_dynamicsWorld.AddAction(playerController); //collisionShapes.Add(capsule); //frozenTime = 0; }