예제 #1
0
 public Ship(
     LifeSpan lifeTime,
     MassInertia massInfo,
     PhysicsState physicsState,
     BodyFlags flags,
     ICollidableBodyPart[] collidableParts,
     ShipMovementInfo movementInfo,
     ShipState shipState,
     ControlableSounds controlableSounds,
     ShipSounds shipSounds,
     ActionList actions,
     IShip[] subShips)
     : base(
         lifeTime,
         massInfo,
         physicsState,
         flags,
         collidableParts,
         movementInfo,
         shipState,
         controlableSounds)
 {
     this.UQMFlags       |= ContFlags.CanDoGravityWhip;
     this.shipSounds      = shipSounds;
     this.subShips        = subShips;
     this.actions         = actions;
     this.controlableType = ControlableType.Ship;
 }
예제 #2
0
 public Ship(
     LifeSpan lifeTime,
     PhysicsState physicsState,
     BodyFlags flags,
     RigidBodyTemplate template,
     ShipMovementInfo movementInfo,
     ShipState shipState,
     ControlableSounds controlableSounds,
     ShipSounds shipSounds,
     ActionList actions,
     IShip[] subShips)
     : base(
         lifeTime,
         physicsState,
         flags,
         template,
         movementInfo,
         shipState,
         controlableSounds)
 {
     this.UQMFlags       |= ContFlags.CanDoGravityWhip;
     this.shipSounds      = shipSounds;
     this.subShips        = subShips;
     this.actions         = actions;
     this.controlableType = ControlableType.Ship;
 }
예제 #3
0
 public virtual void HandlePossibleIntersections(float dt, List <ICollidableBody> collidables)
 {
     if (collidables != null)
     {
         PhysicsState before = null;
         RemoveUnEffectable(collidables);
         int length = ray2DEffects.Count;
         for (int pos = 0; pos < length; ++pos)
         {
             RayICollidableBodyPair pair = GetIntersection(ray2DEffects[pos].RaySegment, collidables);
             if (pair != null && pair.BestIntersectInfo.Intersects)
             {
                 if (pair.ICollidableBody.CollisionState.GenerateRayEvents)
                 {
                     before = new PhysicsState(pair.ICollidableBody.Current);
                 }
                 ray2DEffects[pos].ApplyEffect(dt, pair);
                 if (pair.ICollidableBody.CollisionState.GenerateRayEvents)
                 {
                     pair.ICollidableBody.CollisionState.InterferenceInfos.Add(
                         new InterferenceInfo(new RayCollidableInterferenceInfo(this,
                                                                                pair.RaySegment2D,
                                                                                pair.BestIntersectInfo,
                                                                                before,
                                                                                new PhysicsState(pair.ICollidableBody.Current),
                                                                                pair.ICollidableBody)));
                 }
             }
         }
     }
 }
예제 #4
0
        void CreateBody(Window window)
        {
            lock (lockPhysicsLoop)
            {
                double    angle    = window.Angle;
                Rectangle position = window.Position;
                if (position.Width > 0 && position.Height > 0)
                {
                    PhysicsState state = new PhysicsState(new ALVector2D(angle, position.Left + position.Width / 2, position.Top + position.Height / 2));
                    IShape       shape = new PolygonShape(VertexHelper.CreateRectangle(position.Height, position.Width), 2);
                    MassInfo     mass  = MassInfo.FromPolygon(shape.Vertexes, 1);
                    Body         body  = new Body(state, shape, mass, new Coefficients(0, 1), new Lifespan());
                    body.LinearDamping  = 0.95;
                    body.AngularDamping = 0.95;
                    body.IsCollidable   = false;
                    body.Tag            = window;
                    engine.AddBody(body);
                    windowToBody.Add(window, body);

                    try
                    {
                        dwm.SetWindowMatrix(window.HWnd.ToInt32(), 0f, 0f, 1f, 1f, 0f);
                    }
                    catch (Exception e)
                    {
                        HandleDwmCrash(e);
                    }
                }
            }
        }
예제 #5
0
        public override GeneralChange RemoveEffectTypes(EffectTypes types)
        {
            GeneralChange returnvalue = new GeneralChange();
            PhysicsState  psc         = PhysicsStateChange;
            bool          filtered    = false;

            if (((int)types * (int)EffectTypes.Position) != 0)
            {
                if (returnvalue.PhysicsChange == null)
                {
                    returnvalue.PhysicsChange = new PhysicsState();
                }
                returnvalue.PhysicsChange.Position += psc.Position;
                psc.Position = ALVector2D.Zero;
                filtered     = true;
            }
            if (((int)types * (int)EffectTypes.Velocity) != 0)
            {
                if (returnvalue.PhysicsChange == null)
                {
                    returnvalue.PhysicsChange = new PhysicsState();
                }
                returnvalue.PhysicsChange.Velocity += psc.Velocity;
                psc.Velocity = ALVector2D.Zero;
                filtered     = true;
            }
            if (filtered)
            {
                PhysicsStateChange = psc;
            }
            return(returnvalue);
        }
예제 #6
0
        /// <summary>
        /// Called when the <see cref="P:System.Windows.Controls.ContentControl.Content"/> property changes.
        /// </summary>
        /// <param name="oldContent">The old value of the <see cref="P:System.Windows.Controls.ContentControl.Content"/> property.</param>
        /// <param name="newContent">The new value of the <see cref="P:System.Windows.Controls.ContentControl.Content"/> property.</param>
        protected override void OnContentChanged(object oldContent, object newContent)
        {
            timer.IsRunning = false;

            if (Body != null)
            {
                Body.Lifetime.IsExpired = true;
            }

            base.OnContentChanged(oldContent, newContent);

            PhysicsState state = new PhysicsState(new ALVector2D(0, 0, 0));
            IShape       shape = new PolygonShape(VertexHelper.CreateRectangle(5, 5), 1);
            MassInfo     mass  = MassInfo.FromPolygon(shape.Vertexes, 1);

            Body = new Body(state, shape, mass, new Coefficients(0, 1), new Lifespan());
            Body.LinearDamping        = LinearDumping;
            Body.Mass.MomentOfInertia = double.PositiveInfinity;
            Body.Tag = newContent;
            engine.AddBody(Body);

            if (!DesignerProperties.GetIsInDesignMode(this))
            {
                timer.IsRunning = true;
            }
        }
        protected void SpawnWeapon(GameResult gameResult, IControlable collider)
        {
            if (spawned)
            {
                return;
            }
            spawned = true;
            PhysicsState physicsState = new PhysicsState(this.Good);

            physicsState.ForceAccumulator = ALVector2D.Zero;
            physicsState.Acceleration     = ALVector2D.Zero;
            if (collider != null)
            {
                physicsState.Velocity.Linear = collider.Good.Velocity.Linear;
            }
            else
            {
                physicsState.Velocity.Linear = this.current.Velocity.Linear;
            }

            ISolidWeapon newWeapon = (ISolidWeapon)spawn.Clone();

            newWeapon.Current.Set(physicsState);

            newWeapon.SetAllPositions();
            newWeapon.OnCreation(gameResult, this.weaponInfo);
            if (diesOnSpawn)
            {
                this.Kill(gameResult);
            }
        }
예제 #8
0
 public ControlableWave(
     LifeSpan lifeTime,
     float mass,
     PhysicsState physicsState, float initialRadius,
     float expansionRate,
     int[] colors,
     int primaryColor,
     ShipMovementInfo movementInfo,
     ShipState shipState,
     FactionInfo factionInfo,
     ControlableSounds controlableSounds)
     : base(
         lifeTime,
         mass,
         physicsState,
         initialRadius,
         expansionRate)
 {
     this.shipState                        = shipState;
     this.movementInfo                     = movementInfo;
     this.factionInfo                      = factionInfo;
     this.controlableSounds                = controlableSounds;
     this.attachedEffectCollection         = new EffectCollection();
     this.CollisionState.GenerateRayEvents = true;
     this.colors       = colors;
     this.primaryColor = primaryColor;
 }
예제 #9
0
 public ControlableWave(
     LifeSpan lifeTime,
     float mass,
     PhysicsState physicsState,
     float initialRadius,
     float expansionRate,
     int[] colors,
     int primaryColor,
     ShipMovementInfo movementInfo,
     ShipState shipState,
     ControlableSounds controlableSounds,
     IWeaponsLogic weaponInfo)
     : this(
         lifeTime,
         mass,
         physicsState, initialRadius,
         expansionRate,
         colors,
         primaryColor,
         movementInfo,
         shipState, null, controlableSounds)
 {
     this.weaponInfo = weaponInfo;
     this.CollisionState.GenerateCollisionEvents = true;
     this.CollisionState.GenerateContactEvents   = true;
     this.controlableType = ControlableType.Weapon;
 }
예제 #10
0
    IEnumerator JumpWork(float duration)
    {
        state       = PhysicsState.Jumping;
        col.enabled = false;
        var jumpingTime = 0f;

        Vector3 newPos = Vector3.zero;
        var     a      = jumpHeight / (duration * duration / 4);
        var     t      = 0f;

        do
        {
            jumpingTime += Time.deltaTime;
            newPos       = transform.position;
            t            = jumpingTime - duration / 2;

            newPos.z           = -a * t * t + jumpHeight;
            transform.position = newPos;
            yield return(null);
        } while (jumpingTime < duration);

        var posForReset = transform.position;

        posForReset.z      = 0;
        transform.position = posForReset;
        col.enabled        = true;
        state = PhysicsState.OnFloor;
        yield break;
    }
예제 #11
0
        public Controlable(
            LifeSpan lifeTime,
            MassInertia massInfo,
            PhysicsState physicsState,
            BodyFlags flags,
            ICollidableBodyPart[] collidableParts,
            ShipMovementInfo movementInfo,
            ShipState shipState,
            ControlableSounds controlableSounds,
            IWeaponsLogic weaponInfo)
            : this(
                lifeTime,
                massInfo,
                physicsState,
                flags, collidableParts,
                movementInfo,
                shipState,
                controlableSounds)
        {
            this.CollisionState.GenerateCollisionEvents = true;
            this.CollisionState.GenerateContactEvents   = true;
            this.weaponInfo = weaponInfo;

            this.controlableType = ControlableType.Weapon;
        }
예제 #12
0
 public override void OnTargetAttachment(EffectAttachmentResult attachmentResult, IControlable attachie)
 {
     diff = new PhysicsState();
     diff.Position.Linear = attachie.DirectionVector * -distance;;
     diff.Velocity.Linear = -attachie.Current.Velocity.Linear;
     base.OnTargetAttachment(attachmentResult, attachie);
 }
예제 #13
0
        public static Asteroid CreateAsteroid(GameResult gameResult, PhysicsState state)
        {
            Asteroid roid = new Asteroid(Templates[rand.Next(Templates.Length)], state);

            roid.OnCreation(gameResult, new FactionInfo(AsteroidFaction));
            return(roid);
        }
 /// <summary>
 /// Is called when the effect is created.
 /// </summary>
 /// <param name="weaponInfo"></param>
 public override void OnCreation(IWeaponsLogic weaponInfo)
 {
     diff = new PhysicsState();
     // sets a random Linear displacement.
     diff.Position.Linear = Vector2D.FromLengthAndAngle((float)rand.NextDouble() * maxDistance, (float)rand.NextDouble() * 2 * MathHelper.PI);
     base.OnCreation(weaponInfo);
 }
예제 #15
0
    public void PhysicsChange(PhysicsState nextPhysicsState)
    {
        if (physicsState == nextPhysicsState)
        {
            return;
        }
        physicsState = nextPhysicsState;
        switch (physicsState)
        {
        case PhysicsState.NORMAL:
            this.gameObject.layer  = LayerMask.NameToLayer("Limb");
            thisCollider.isTrigger = false;
            break;

        case PhysicsState.FLYINGON:
            this.gameObject.layer  = LayerMask.NameToLayer("Projectile");
            thisCollider.isTrigger = false;
            break;

        case PhysicsState.FLYINGOFF:
            this.gameObject.layer  = LayerMask.NameToLayer("Projectile");
            thisCollider.isTrigger = true;
            break;
        }
    }
예제 #16
0
        private void CreateWalls()
        {
            var wallCoff = new Coefficients(0.8f, 0.95f);
            var wallLife = new Lifespan();

            var flrState = new PhysicsState(new ALVector2D((float)0.0, ((float)ActualWidth) * ((float)0.5), (float)ActualHeight + 100.0));
            var flrShape = new PolygonShape(VertexHelper.CreateRectangle(ActualWidth, 200), 2);
            var bdyFloor = new Body(flrState, flrShape, float.PositiveInfinity, wallCoff, wallLife);

            var ceiState   = new PhysicsState(new ALVector2D((float)0.0, ((float)ActualWidth) * ((float)0.5), -100.0));
            var ceiShape   = new PolygonShape(VertexHelper.CreateRectangle(ActualWidth, 200), 2);
            var bdyCeiling = new Body(ceiState, ceiShape, float.PositiveInfinity, wallCoff, wallLife);

            var lwlState    = new PhysicsState(new ALVector2D((float)0.0, -100.0, ((float)ActualHeight) * ((float)0.5)));
            var lwlShape    = new PolygonShape(VertexHelper.CreateRectangle(200, ActualHeight), 2);
            var bdyLeftWall = new Body(lwlState, lwlShape, float.PositiveInfinity, wallCoff, wallLife);

            var rwlState     = new PhysicsState(new ALVector2D((float)0.0, (float)ActualWidth + 100.0, ((float)ActualHeight) * ((float)0.5)));
            var rwlShape     = new PolygonShape(VertexHelper.CreateRectangle(200, ActualHeight), 2);
            var bdyRightWall = new Body(rwlState, rwlShape, float.PositiveInfinity, wallCoff, wallLife);

            engine.AddBody(bdyFloor);
            engine.AddBody(bdyCeiling);
            engine.AddBody(bdyLeftWall);
            engine.AddBody(bdyRightWall);
        }
예제 #17
0
        private void FragmentationThread(object param)
        {
            try
            {
                lock (this.container.voxels)
                {
                    if (this.tensionCalculation)
                    {
                        StructurePhysicsUpdate(null);
                    }
                    this.physicsAggregatedList = this.GetAggregations((VoxelIngameBuildTask)param);
                }
                this.OrderAggregatedListByAltitude();

                this.lastVoxelCount = this.container.voxels.Count;
                this.currentState   = PhysicsState.ObjectCreation;
            }
            catch (Exception e)
            {
                Debug.LogError("Voxel Physics error: " + e.Message);
            }

            /*finally
             * {
             * //  this.currentState = PhysicsState.ObjectCreation;
             * }   */
        }
예제 #18
0
        private void UpdateEnginePropulsion()
        {
            // Obtain acceleration from input source
            float inputAcceleration = m_InputSrc.ForwardAcceleration;

            // Check there is some input
            if (Mathf.Abs(inputAcceleration) < 1e-6)
            {
                CurrentPhysicsState = Mathf.Abs(ForwardSpeed) < 0.1f
               ? PhysicsState.Idle
               : ForwardSpeed > 0
                  ? PhysicsState.Loose_forward
                  : PhysicsState.Loose_backward;

                // No propulsion needed
                return;
            }

            // Force is in the local z axis
            var force = transform.forward;

            // Adjust acceleration according to framerate
            force *= Time.fixedDeltaTime;

            // Apply input acceleration
            force *= inputAcceleration;

            // Check if we are accelerating in the same direction as we're going
            if (Math.Sign(inputAcceleration) == Math.Sign(ForwardSpeed))
            {
                // Choose the right propulsion direction
                VehicleProperties.PropulsionProperties propulsion;
                if (inputAcceleration > 0)
                {
                    CurrentPhysicsState = PhysicsState.Accelerating_forward;
                    propulsion          = m_VehicleProperties.Engine.ForwardPropulsion;
                }
                else
                {
                    CurrentPhysicsState = PhysicsState.Accelerating_backward;
                    propulsion          = m_VehicleProperties.Engine.BackwardPropulsion;
                }

                // Set engine power according to direction
                force *= propulsion.Power;

                // Reduce engine power the closer we are to the max speed in this direction
                // TODO: add a velocity bias to TopSpeedProgression to reduce wobble in speed
                force *= Mathf.Pow(1 - TopSpeedProgression, propulsion.DecayFactor);
            }
            else
            {
                CurrentPhysicsState = PhysicsState.Braking;
                force *= m_VehicleProperties.BrakesPower;
            }

            // Add final force to rigidbody
            GetComponent <Rigidbody>().AddForce(force);
        }
예제 #19
0
 public Bullet()
 {
     id  = instantiationCounter++;
     phy = new PhysicsState(1);
     off = true;
     t   = 0;
     affectedByGravity = true;
 }
예제 #20
0
 public static void Call(Level lvl, PhysicsState state)
 {
     if (handlers.Count == 0)
     {
         return;
     }
     CallCommon(pl => pl(lvl, state));
 }
예제 #21
0
        public override void ApplyEffect(GameResult gameResult, float dt)
        {
            PhysicsState psc = PhysicsStateChange;

            this.attachie.Current.Position += psc.Position;
            this.attachie.Current.Velocity += psc.Velocity;
            Exhausted = true;
        }
예제 #22
0
 public GameMessageSetState(WorldObject worldObject, PhysicsState state)
     : base(GameMessageOpcode.SetState, GameMessageGroup.Group0A)
 {
     Writer.WriteGuid(worldObject.Guid);
     Writer.Write((uint)state);
     Writer.Write(worldObject.Sequences.GetCurrentSequence(Sequence.SequenceType.ObjectInstance));
     Writer.Write(worldObject.Sequences.GetNextSequence(Sequence.SequenceType.ObjectState));
 }
예제 #23
0
        public void DoFragmentation()
        {
            this.currentState = PhysicsState.Fragmanatation;

            VoxelIngameBuildTask ingameBuildTask = container.ingameBuildTask;

            ThreadPool.QueueUserWorkItem(FragmentationThread, ingameBuildTask);
        }
 public GameMessageSetState(ObjectGuid guid, PhysicsState state, uint logins, uint portals)
     : base(GameMessageOpcode.SetState, GameMessageGroup.Group0A)
 {
     Writer.WriteGuid(guid);
     Writer.Write((uint)state);
     Writer.Write((ushort)logins);
     Writer.Write((ushort)portals);
 }
예제 #25
0
 public void Respawn()
 {
     transform.position = respawnPos;
     state         = PhysicsState.OnFloor;
     body.velocity = Vector2.zero;
     rend.enabled  = true;
     mover.enabled = true;
     col.enabled   = true;
 }
예제 #26
0
 private void ResetPrim (PhysicsObject physicsObject, PhysicsState physicsState, float direction)
 {
     physicsObject.Position = physicsState.Position;
     physicsObject.Orientation = physicsState.Rotation;
     physicsObject.RotationalVelocity = physicsState.AngularVelocity * direction;
     physicsObject.Velocity = physicsState.LinearVelocity * direction;
     physicsObject.ForceSetVelocity (physicsState.LinearVelocity * direction);
     physicsObject.RequestPhysicsterseUpdate ();
 }
예제 #27
0
 private void ResetPrim(PhysicsObject physicsObject, PhysicsState physicsState, float direction)
 {
     physicsObject.Position           = physicsState.Position;
     physicsObject.Orientation        = physicsState.Rotation;
     physicsObject.RotationalVelocity = physicsState.AngularVelocity * direction;
     physicsObject.Velocity           = physicsState.LinearVelocity * direction;
     physicsObject.ForceSetVelocity(physicsState.LinearVelocity * direction);
     physicsObject.RequestPhysicsterseUpdate();
 }
예제 #28
0
 private void DoMoveDataToObjects()
 {
     this.currentState = PhysicsState.MovingDataToObjects;
     if (showDebugMessages)
     {
         Debug.Log("VoxelMax Physics: Move data to objects");
     }
     ThreadPool.QueueUserWorkItem(this.MoveAggregatedVoxelsIntoNewContainers, physicsBuildTask);
 }
예제 #29
0
 public void AddAvatar (PhysicsCharacter prm)
 {
     PhysicsState state = new PhysicsState ();
     state.Position = prm.Position;
     state.AngularVelocity = prm.RotationalVelocity;
     state.LinearVelocity = prm.Velocity;
     state.Rotation = prm.Orientation;
     m_activePrims[prm.UUID] = state;
 }
예제 #30
0
        private void DoFinalization()
        {
            if ((physicsBuildTask != null) && (physicsBuildTask.isReady))
            {
                if (physicsBuildTask.voxelContainerList != null)
                {
                    for (int i = 0; i < physicsBuildTask.voxelContainerList.Count; i++)
                    {
                        physicsBuildTask.voxelContainerList[i].enabled = true;
                        physicsBuildTask.voxelContainerList[i].gameObject.GetComponent <Rigidbody>().mass = physicsBuildTask.voxelContainerList[i].voxels.Count;
                        physicsBuildTask.voxelContainerList[i].CreateBoxColliders(physicsBuildTask.colliders[i]);
                        ///physicsBuildTask.voxelContainerList[i].gameObject.GetComponent<Rigidbody>().drag = physicsBuildTask.voxelContainerList[i].voxels.Count;
                        MeshRenderer meshRenderer = physicsBuildTask.voxelContainerList[i].GetComponent <MeshRenderer>();
                        meshRenderer.enabled = true;
                        physicsBuildTask.voxelContainerList[i].mustRebuildBeforeUpdate = true;
                    }
                }
                this.container.CreateBoxColliders(physicsBuildTask.mainBodyCollider);
                physicsBuildTask = null;
                return;
            }

            if (physicsBuildTask == null)
            {
                if ((!this.container.mustRebuildBeforeUpdate) && (this.IsAllFragmentsRebuilded()))
                {
                    if (showDebugMessages)
                    {
                        Debug.Log("VoxelMax Physics: Reenabling modules");
                    }

                    this.container.mustRebuildBeforeUpdate = true;

                    foreach (VoxelContainer voxContainer in this.fragmentContainers)
                    {
                        Rigidbody    rigidBody    = voxContainer.GetComponent <Rigidbody>();
                        MeshCollider meshCollider = voxContainer.GetComponent <MeshCollider>();
                        VoxelPhysics voxelPhysics = voxContainer.GetComponent <VoxelPhysics>();
                        rigidBody.useGravity = true;
                        if (meshCollider != null)
                        {
                            meshCollider.enabled = true;
                        }
                        voxelPhysics.enabled = true;
                    }

                    //  this.gameObject.GetComponent<MeshCollider>().enabled = true;
                    if (this.gameObject.GetComponent <Rigidbody>() != null)
                    {
                        this.gameObject.GetComponent <Rigidbody>().useGravity = true;
                    }

                    this.currentState = PhysicsState.WaitingForTask;
                }
            }
        }
예제 #31
0
 /*public static ShipInfo GetShipInfo()
  * {
  *  return new ShipInfo("Orz Nemesis", new CreateShipDelegate(Create));
  * }*/
 protected static IShip[] GetSubShips(PhysicsState state, FactionInfo factionInfo)
 {
     IShip[] returnvalue = new IShip[1];
     returnvalue[0] = (IShip)DefaultSubShips[0].Clone();
     returnvalue[0].IgnoreInfo.IsCollidable = false;
     returnvalue[0].Current.Set(state);
     returnvalue[0].SetAllPositions();
     //returnvalue[0].FactionInfo = new FactionInfo(factionInfo);
     return(returnvalue);
 }
예제 #32
0
        public void Switch(PhysicsState state)
        {
            if (CurrentPhysicsState == state)
            {
                return;
            }

            CurrentPhysicsState = state;
            UpdatePhysicsState();
        }
예제 #33
0
    public void ChangeState(PhysicsStateType toState)
    {
        _currentState.Exit();
        ExitStateCallback(_currentStateType);

        _currentStateType = toState;
        _currentState = _stateMap[_currentStateType];

        _currentState.Enter();
        EnterStateCallback(_currentStateType);
    }
예제 #34
0
    void OnTriggerEnter(Collider other)
    {
        if(other.gameObject.tag == "Geometry")
        {

            if(other.bounds.center.y < m_collider.bounds.center.y)
            {
                m_state = PhysicsState.Grounded;
                m_velocity.y = 0.0f;

                float y = other.bounds.max.y + m_collider.bounds.extents.y;

                transform.position = new Vector3(transform.position.x, y, transform.position.z);
            }
            else
            {
                if(m_collider.bounds.center.y < other.bounds.max.y && m_collider.bounds.center.y > other.bounds.min.y)
                {

                    if(other.bounds.center.x > m_collider.bounds.max.y && m_velocity.x > 0.0f)
                    {
                        m_velocity.x = 0.0f;
                    }
                }
            }

            if(other.bounds.min.y > m_collider.bounds.center.y)
            {
                    m_velocity.y = 0.0f;
            }

            // Find the position of the geometry relative to the physics object, then halt progress in that direction
        }

        if(other.gameObject.tag == "Bounds")
        {
            Debug.Log("Bounds hit");
            transform.position = new Vector3(0.0f, 10.0f, 0.0f);
        }
    }
예제 #35
0
    void OnTriggerStay(Collider other)
    {
        if(other.gameObject.tag == "Geometry")
        {

            if(other.bounds.center.y < m_collider.bounds.center.y)
            {
                m_state = PhysicsState.Grounded;

                float y = other.bounds.max.y + m_collider.bounds.extents.y;

                transform.position = new Vector3(transform.position.x, y, transform.position.z);
            }
            else
            {
                if(other.bounds.min.y > m_collider.bounds.max.y)
                {
                    if(m_velocity.y > 0.0f)
                    {
                        m_velocity.y = 0.0f;
                    }
                }

                if(m_collider.bounds.center.y < other.bounds.max.y && m_collider.bounds.center.y > other.bounds.min.y)
                {

                    if(other.bounds.center.x > m_collider.bounds.max.x && m_velocity.x > 0.0f)
                    {
                        m_velocity.x = 0.0f;
                    }
                }

                if(m_collider.bounds.center.y < other.bounds.max.y && m_collider.bounds.center.y > other.bounds.min.y)
                {

                    if(other.bounds.center.x < m_collider.bounds.max.x && m_velocity.x < 0.0f)
                    {
                        m_velocity.x = 0.0f;
                    }
                }
            }

        }
    }
예제 #36
0
 public void AddPrim(PhysicsObject prm)
 {
     PhysicsState state = new PhysicsState
                              {
                                  Position = prm.Position,
                                  AngularVelocity = prm.RotationalVelocity,
                                  LinearVelocity = prm.Velocity,
                                  Rotation = prm.Orientation
                              };
     m_activePrims[prm.UUID] = state;
 }
예제 #37
0
파일: Game.cs 프로젝트: tilpner/hp
        public void Update(double delta, Game game) {
            Vector2f accel = v2f(0, 0);
            if (Math.Abs(Velocity.X) < MAX_WALK_SPEED) {
                if (Keyboard.IsKeyPressed(Keyboard.Key.A)) {
                    accel.X -= (float)Player.SPEED_X * HorizontalInfluence;
                }
                if (Keyboard.IsKeyPressed(Keyboard.Key.D)) {
                    accel.X += (float)Player.SPEED_X * HorizontalInfluence;
                }
            }
            
            if (Keyboard.IsKeyPressed(Keyboard.Key.Space) && NearGround) {
                state = PhysicsState.Midair;
                accel.Y -= (float) (Player.JUMP_SPEED_Y);
            }

            if (state == PhysicsState.Midair) accel += game.level.Gravity;
            // apply unproblematic amount of gravity to facilitate
            // detection of "standing on the ground" state
            else accel += DETECTION_GRAVITY;
            
            // capping
            if (Velocity.Len() > Consts.MAX_VEL) {
                Velocity = Velocity.Norm() * Consts.MAX_VEL;
            }
            
            Level.CollidedWith flags;
            Box = game.level.ResolveCollision(Box, out flags).Check();

            if ((flags & Level.CollidedWith.Bottom) == Level.CollidedWith.Bottom) {
                Velocity.Y = Math.Min(0, Velocity.Y);
                state = PhysicsState.Ground;
            }
            if ((flags & Level.CollidedWith.Left) == Level.CollidedWith.Left) {
                Velocity.X = 0;
            }
            if ((flags & Level.CollidedWith.Right) == Level.CollidedWith.Right) {
                Velocity.X = 0;
            }
            if ((flags & Level.CollidedWith.Top) == Level.CollidedWith.Top) {
                Velocity.Y = Math.Max(0, Velocity.Y);
                state = PhysicsState.Midair;
            }
            if ((int) flags == 0) {
                // No collision, assuming midair
                state = PhysicsState.Midair;
            }

            switch (state) {
                case PhysicsState.Midair:
                    HorizontalInfluence = 0.3F;
                    LastTouchedGround += delta;
                    anim.Speed = 0.3;
                    break;
                case PhysicsState.Ground:
                    Block below = game.level[(int) Math.Floor(Box.Center.X), (int) Math.Ceiling(Box.Center.Y)];
                    var friction = below.Type == null ? 32 : below.Type.Friction;

                    // If we're not walking, apply additional friction
                    if (Math.Abs(accel.X) < 0.1) Velocity.X *= (float)(1 - delta * friction).Clamp(0, 1);
                    Velocity.Y = 0;
                    HorizontalInfluence = 1F;
                    LastTouchedGround = 0;
                    anim.Speed = 1;
                    break;
            }


            // Verlet integration
            Box.Position += (float)delta * (Velocity + (float)delta * accel / 2);
            Velocity += (float)delta * accel;

            if (Math.Abs(Velocity.X) < 1) anim.Reset();
            anim.Flipped = Velocity.X < 0;
            anim.Update(delta * (Velocity.X / 4));
        }
예제 #38
0
    void OnTriggerExit(Collider other)
    {
        if(other.gameObject.tag == "Geometry")
        {
            if(other.gameObject.transform.position.y < transform.position.y)
            {
                    m_state = PhysicsState.Falling;

            }
        }
    }
예제 #39
0
 public void RegisterState(PhysicsStateType state, PhysicsState method)
 {
     if (_stateMap.ContainsKey(state))
     {
         _stateMap[state] = method;
     }
     else
     {
         _stateMap.Add(state, method);
     }
 }