Ejemplo n.º 1
0
 public void SetCollision()
 {
     MotionState motionState = new MotionState();
     motionState.Position = Position;
     motionState.Orientation = Quaternion.Identity;
     Entity = new Sphere(motionState, radius, mass);
 }
Ejemplo n.º 2
0
 public void SetCollision()
 {
     var motionState = new MotionState();
     motionState.Position = Position;
     motionState.Orientation = Quaternion.Identity;
     Entity = new Box(motionState, initscale.X, initscale.Y, initscale.Z, mass);
 }
Ejemplo n.º 3
0
		public RigidBody(float mass, MotionState motionState, CollisionShape collisionShape, Vector3 localInertia, float linearDamping, float angularDamping, float friction, float restitution)
		{
			_optionalMotionState = motionState;
			_angularFactor = 1;
			_angularDamping = 0.5f;

			if (motionState != null)
			{
				motionState.GetWorldTransform(out _worldTransform);
			}
			else
			{
				WorldTransform = Matrix.Identity;
			}

			InterpolationWorldTransform = WorldTransform;
			InterpolationLinearVelocity = new Vector3();
			InterpolationAngularVelocity = new Vector3();

			//moved to btCollisionObject
			Friction = friction;
			Restitution = restitution;

			CollisionShape = collisionShape;
			_debugBodyId = UniqueID++;

			//m_internalOwner is to allow upcasting from collision object to rigid body
			Owner = this;

			SetMassProps(mass, localInertia);
			SetDamping(linearDamping, angularDamping);
			UpdateInertiaTensor();
		}
Ejemplo n.º 4
0
 public static MotionState CreateMotionState(Vector3 position, Quaternion orientation, Vector3 velocity)
 {
     MotionState newState = new MotionState();
     newState.Position = position;
     newState.Orientation = orientation;
     newState.LinearVelocity = velocity;
     return newState;
 }
 public MotionPropertiesComponent(GameObject parent, float mass, float maxGroundVelocity, float maxAirVelocity)
     : base(parent)
 {
     this.State = MotionState.Unknown;
     this.MaxGroundSpeed = maxGroundVelocity;
     this.MaxAirSpeed = maxAirVelocity;
     this.Mass = mass;
     this.LastAccelerationVector = Vector2.Zero;
     this.AccelerationVector = Vector2.Zero;
     this._velocityVector = Vector2.Zero;
     this.Impulses = new List<Impulse>();
 }
Ejemplo n.º 6
0
		/// <summary>
		/// 
		/// </summary>
		/// <param name="game"></param>
		/// <param name="space"></param>
		public RigidBody ( Entity entity, World world, float w, float h, float d, float mass ) : base(entity,world)
		{
			this.space	=	((MPWorld)world).PhysSpace;

			var ms	=	new MotionState();
			ms.AngularVelocity	=	MathConverter.Convert( entity.AngularVelocity );
			ms.LinearVelocity	=	MathConverter.Convert( entity.LinearVelocity );
			ms.Orientation		=	MathConverter.Convert( entity.Rotation );
			ms.Position			=	MathConverter.Convert( entity.Position );
			box	=	new Box(  ms, w, h, d, mass );
			box.PositionUpdateMode	=	PositionUpdateMode.Continuous;

			box.Tag	=	entity;

			space.Add( box );
		}
Ejemplo n.º 7
0
        internal void Enable()
        {
            //Turn everything on.
            lock (FlipLocker)
            {

                int initialCount = Math.Max(manager.entities.Count, 64);
                backBuffer = new MotionState[initialCount];
                frontBuffer = new MotionState[initialCount];
                for (int i = 0; i < manager.entities.Count; i++)
                {
                    Entity entity = manager.entities[i];
                    backBuffer[i].Position = entity.position;
                    backBuffer[i].Orientation = entity.orientation;
                    backBuffer[i].LinearVelocity = entity.linearVelocity;
                    backBuffer[i].AngularVelocity = entity.angularVelocity;
                }
                Array.Copy(backBuffer, frontBuffer, backBuffer.Length);
            }
        }
Ejemplo n.º 8
0
    protected override void OnUpdate( FingerGestures.IFingerList touches )
    {
        if( Finger.IsDown )
        {
            if( !wasDown )
            {
                Moves = 0;
                AnchorPos = Finger.Position;
                State = MotionState.Stationary;
            }

            if( Finger.Phase == FingerGestures.FingerPhase.Moved )
            {
                if( State != MotionState.Moving )
                {
                    Vector2 delta = Finger.Position - AnchorPos;

                    // check if we moved beyond the threshold
                    if( delta.sqrMagnitude >= MoveThreshold * MoveThreshold )
                        State = MotionState.Moving;
                    else
                        State = MotionState.Stationary;
                }
            }
            else
            {
                State = MotionState.Stationary;
            }
        }
        else
        {
            State = MotionState.None;
        }

        RaiseEvents();

        PreviousState = State;
        wasDown = Finger.IsDown;
    }
Ejemplo n.º 9
0
 ///<summary>
 /// Gets the states of all entities atomically.
 ///</summary>
 ///<param name="states">Entity states.</param>
 ///<exception cref="InvalidOperationException">Thrown when the array is too small.</exception>
 public void GetStates(MotionState[] states)
 {
     lock (FlipLocker)
     {
         if (states.Length < manager.entities.Count)
         {
             throw new ArgumentException("Array is not large enough to hold the buffer.", "states");
         }
         Array.Copy(frontBuffer, states, manager.entities.Count);
     }
 }
Ejemplo n.º 10
0
        internal void Add(Entity e)
        {

            //Don't need to lock since the parent manager handles it.
            if (frontBuffer.Length <= e.BufferedStates.motionStateIndex)
            {
                var newStates = new MotionState[frontBuffer.Length * 2]; //TODO: shifty
                frontBuffer.CopyTo(newStates, 0);
                frontBuffer = newStates;
            }
            frontBuffer[e.BufferedStates.motionStateIndex].Position = e.position;
            frontBuffer[e.BufferedStates.motionStateIndex].Orientation = e.orientation;

            if (backBuffer.Length <= e.BufferedStates.motionStateIndex)
            {
                var newStates = new MotionState[backBuffer.Length * 2]; //TODO: shifty
                backBuffer.CopyTo(newStates, 0);
                backBuffer = newStates;
            }
            backBuffer[e.BufferedStates.motionStateIndex].Position = e.position;
            backBuffer[e.BufferedStates.motionStateIndex].Orientation = e.orientation;
        }
Ejemplo n.º 11
0
 public StateChangeEventArgs(MotionState oldState, MotionState state)
 {
     Previous = oldState;
     Current = state;
 }
Ejemplo n.º 12
0
        public override void PrepareForIteration(float timestep)
        {
            RigidBody body;
            float depth;

            bool collidesWithLadder = world.CollisionSystem.Raycast(Body1.Position + JVector.Forward * (FeetPosition - 0.1f),
                new JVector(0, 1, 0),
                (b, n, f) => b != Body1 && (b.BroadphaseTag & (int)BodyTags.Ghost) == 0,
                out body, out normal, out depth);
            bool collidesWithGround = world.CollisionSystem.Raycast(Body1.Position + new JVector(0, 0.5f, 0) + JVector.Forward * (FeetPosition - 0.1f),
                JVector.Forward,
                (b, n, f) => b != Body1 && (b.BroadphaseTag & (int)BodyTags.Ghost) == 0,
                out body, out normal, out depth);
            BodyWalkingOn = ((!collidesWithGround || depth > 0.2f) ? null : body);
            var oldState = State;
            switch (oldState)
            {
                case MotionState.Grounded:
                    if (BodyWalkingOn != null)
                    {
                        if (tryClimb)
                        {
                            State = MotionState.Climbing;
                            tryClimb = false;
                        }
                        else if (Body1.LinearVelocity.Z < JumpVelocity && tryJump) State = MotionState.Jumping;
                    }
                    else if (-Body1.LinearVelocity.Z < FallVelocity) State = MotionState.Falling;
                    break;
                case MotionState.Jumping:
                    if (-Body1.LinearVelocity.Z < FallVelocity) State = MotionState.Falling;
                    else if (depth < 0.1f && Body1.LinearVelocity.Z < 0.0f) State = MotionState.Grounded;
                    break;
                case MotionState.Falling:
                    if (BodyWalkingOn != null && depth < 0.1f && Body1.LinearVelocity.Z < 0.0f) State = MotionState.Grounded;
                    break;
                case MotionState.Climbing:
                    if (BodyWalkingOn == null && !collidesWithLadder)
                        State = MotionState.Grounded;
                    break;
            }
            if (State != oldState)
            {
                if (StateChanged != null) StateChanged(this, new StateChangeEventArgs(oldState, State));
                Log.WriteLine(LogLevel.Debug, "switched from {0} to {1}", oldState, State);
            }
        }
Ejemplo n.º 13
0
 public static MotionState CreateMotionState(Vector3 position, Quaternion orientation)
 {
     MotionState newState = new MotionState();
     newState.Position = position;
     newState.Orientation = orientation;
     return newState;
 }