public override void UpdateBeforeSimulation()
        {
            base.UpdateBeforeSimulation();

            if (ResourceSink != null)
            {
                ResourceSink.Update();
            }

            if (IsWorking)
            {
                foreach (IMyEntity entityInterface in m_containedEntities)
                {
                    MyEntity       entity    = entityInterface as MyEntity;
                    MyCharacter    character = entity as MyCharacter;
                    IMyVirtualMass mass      = entity as IMyVirtualMass;

                    var naturalGravityMultiplier = MyGravityProviderSystem.CalculateHighestNaturalGravityMultiplierInPoint(entity.WorldMatrix.Translation);
                    var gravity = GetWorldGravity(entity.WorldMatrix.Translation) * MyGravityProviderSystem.CalculateArtificialGravityStrengthMultiplier(naturalGravityMultiplier);

                    if (mass != null && entity.Physics.RigidBody.IsActive)
                    {
                        if (MyDebugDrawSettings.ENABLE_DEBUG_DRAW && MyDebugDrawSettings.DEBUG_DRAW_MISCELLANEOUS)
                        {
                            MyRenderProxy.DebugDrawSphere(entity.WorldMatrix.Translation, 0.2f, mass.IsWorking ? Color.Blue : Color.Red, 1.0f, false);
                        }
                        if (mass.IsWorking && entity.Physics.RigidBody.IsActive)
                        {
                            ((IMyEntity)mass.CubeGrid).Physics.AddForce(MyPhysicsForceType.APPLY_WORLD_FORCE, gravity * mass.VirtualMass, entity.WorldMatrix.Translation, null);
                        }
                    }
                    else if (!entity.Physics.IsKinematic &&
                             !entity.Physics.IsStatic &&
                             entity.Physics.RigidBody2 == null && //jn: TODO this is actualy check for large grid
                             character == null)
                    {
                        if (entity.Physics.RigidBody != null && entity.Physics.RigidBody.IsActive)
                        {
                            //<ib.change> increase gravity for floating objects
                            //entity.Physics.AddForce(MyPhysicsForceType.APPLY_WORLD_FORCE, gravity * entity.Physics.RigidBody.Mass, null, null);
                            if (entity is MyFloatingObject)
                            {
                                var   floatingEntity = entity as MyFloatingObject;
                                float w = (floatingEntity.HasConstraints()) ? 2.0f : 1.0f;
                                entity.Physics.AddForce(MyPhysicsForceType.APPLY_WORLD_FORCE, w * gravity * entity.Physics.RigidBody.Mass, null, null);
                            }
                            else
                            {
                                entity.Physics.AddForce(MyPhysicsForceType.APPLY_WORLD_FORCE, gravity * entity.Physics.RigidBody.Mass, null, null);
                            }
                        }
                    }
                }
            }
        }
Esempio n. 2
0
        internal void TrySpawnWalkingParticles(ref HkContactPointEvent value)
        {
            if (!MyFakes.ENABLE_WALKING_PARTICLES)
            {
                return;
            }

            var oldCheckTime = m_lastWalkParticleCheckTime;

            m_lastWalkParticleCheckTime   = MySandboxGame.TotalGamePlayTimeInMilliseconds;
            m_walkParticleSpawnCounterMs -= m_lastWalkParticleCheckTime - oldCheckTime;
            if (m_walkParticleSpawnCounterMs > 0)
            {
                return;
            }

            var naturalGravityMultiplier = MyGravityProviderSystem.CalculateHighestNaturalGravityMultiplierInPoint(Entity.PositionComp.WorldMatrix.Translation);

            if (naturalGravityMultiplier <= 0f)
            {
                m_walkParticleSpawnCounterMs = m_walkParticleGravityDelay;
                return;
            }

            var character = Entity as MyCharacter;

            if (character.JetpackComp != null && character.JetpackComp.Running)
            {
                m_walkParticleSpawnCounterMs = m_walkParticleJetpackOffDelay;
                return;
            }

            var currentMovementState = character.GetCurrentMovementState();

            if (currentMovementState.GetDirection() == MyCharacterMovement.NoDirection || currentMovementState == MyCharacterMovementEnum.Falling)
            {
                m_walkParticleSpawnCounterMs = m_walkParticleDefaultDelay;
                return;
            }

            var otherPhysicsBody = value.GetOtherEntity(character).Physics as MyVoxelPhysicsBody;        //value.Base.BodyA.UserObject == character.Physics ? value.Base.BodyB.UserObject : value.Base.BodyA.UserObject)) as MyVoxelPhysicsBody;

            if (otherPhysicsBody == null)
            {
                return;
            }

            MyStringId movementType;

            const int walkParticleWalkDelay   = 500;
            const int walkParticleRunDelay    = 275;
            const int walkParticleSprintDelay = 250;

            switch (currentMovementState.GetSpeed())
            {
            case MyCharacterMovement.NormalSpeed:
                movementType = MyMaterialPropertiesHelper.CollisionType.Walk;
                m_walkParticleSpawnCounterMs = walkParticleWalkDelay;
                break;

            case MyCharacterMovement.Fast:
                movementType = MyMaterialPropertiesHelper.CollisionType.Run;
                m_walkParticleSpawnCounterMs = walkParticleRunDelay;
                break;

            case MyCharacterMovement.VeryFast:
                movementType = MyMaterialPropertiesHelper.CollisionType.Sprint;
                m_walkParticleSpawnCounterMs = walkParticleSprintDelay;
                break;

            default:
                movementType = MyMaterialPropertiesHelper.CollisionType.Walk;
                m_walkParticleSpawnCounterMs = m_walkParticleDefaultDelay;
                break;
            }

            var spawnPosition = otherPhysicsBody.ClusterToWorld(value.ContactPoint.Position);

            MyVoxelMaterialDefinition voxelMaterialDefinition = otherPhysicsBody.m_voxelMap.GetMaterialAt(ref spawnPosition);

            if (voxelMaterialDefinition == null)
            {
                return;
            }

            MyMaterialPropertiesHelper.Static.TryCreateCollisionEffect(
                movementType,
                spawnPosition,
                value.ContactPoint.Normal,
                m_characterMaterial,
                MyStringHash.GetOrCompute(voxelMaterialDefinition.MaterialTypeName));
        }
Esempio n. 3
0
 internal void TrySpawnWalkingParticles(ref HkContactPointEvent value)
 {
     if (MyFakes.ENABLE_WALKING_PARTICLES)
     {
         int lastWalkParticleCheckTime = this.m_lastWalkParticleCheckTime;
         this.m_lastWalkParticleCheckTime   = MySandboxGame.TotalGamePlayTimeInMilliseconds;
         this.m_walkParticleSpawnCounterMs -= this.m_lastWalkParticleCheckTime - lastWalkParticleCheckTime;
         if (this.m_walkParticleSpawnCounterMs <= 0)
         {
             if (MyGravityProviderSystem.CalculateHighestNaturalGravityMultiplierInPoint(base.Entity.PositionComp.WorldMatrix.Translation) <= 0f)
             {
                 this.m_walkParticleSpawnCounterMs = 0x2710;
             }
             else
             {
                 MyCharacter entity = base.Entity as MyCharacter;
                 if (entity.JetpackRunning)
                 {
                     this.m_walkParticleSpawnCounterMs = 0x7d0;
                 }
                 else
                 {
                     MyCharacterMovementEnum currentMovementState = entity.GetCurrentMovementState();
                     if ((currentMovementState.GetDirection() == 0) || (currentMovementState == MyCharacterMovementEnum.Falling))
                     {
                         this.m_walkParticleSpawnCounterMs = 0x3e8;
                     }
                     else
                     {
                         MyVoxelPhysicsBody physics = value.GetOtherEntity(entity).Physics as MyVoxelPhysicsBody;
                         if (physics != null)
                         {
                             MyStringId walk;
                             ushort     speed = currentMovementState.GetSpeed();
                             if (speed == 0)
                             {
                                 walk = MyMaterialPropertiesHelper.CollisionType.Walk;
                                 this.m_walkParticleSpawnCounterMs = 500;
                             }
                             else if (speed == 0x400)
                             {
                                 walk = MyMaterialPropertiesHelper.CollisionType.Run;
                                 this.m_walkParticleSpawnCounterMs = 0x113;
                             }
                             else if (speed != 0x800)
                             {
                                 walk = MyMaterialPropertiesHelper.CollisionType.Walk;
                                 this.m_walkParticleSpawnCounterMs = 0x3e8;
                             }
                             else
                             {
                                 walk = MyMaterialPropertiesHelper.CollisionType.Sprint;
                                 this.m_walkParticleSpawnCounterMs = 250;
                             }
                             Vector3D worldPosition = physics.ClusterToWorld(value.ContactPoint.Position);
                             MyVoxelMaterialDefinition materialAt = physics.m_voxelMap.GetMaterialAt(ref worldPosition);
                             if (materialAt != null)
                             {
                                 MyMaterialPropertiesHelper.Static.TryCreateCollisionEffect(walk, worldPosition, value.ContactPoint.Normal, ID_CHARACTER, materialAt.MaterialTypeNameHash, null);
                             }
                         }
                     }
                 }
             }
         }
     }
 }
Esempio n. 4
0
 internal void TrySpawnWalkingParticles()
 {
     if (MyFakes.ENABLE_WALKING_PARTICLES)
     {
         int lastWalkParticleCheckTime = this.m_lastWalkParticleCheckTime;
         this.m_lastWalkParticleCheckTime   = MySandboxGame.TotalGamePlayTimeInMilliseconds;
         this.m_walkParticleSpawnCounterMs -= this.m_lastWalkParticleCheckTime - lastWalkParticleCheckTime;
         if (this.m_walkParticleSpawnCounterMs <= 0)
         {
             if (MyGravityProviderSystem.CalculateHighestNaturalGravityMultiplierInPoint(base.Entity.PositionComp.WorldMatrix.Translation) <= 0f)
             {
                 this.m_walkParticleSpawnCounterMs = 0x2710;
             }
             else
             {
                 MyCharacter entity = base.Entity as MyCharacter;
                 if (entity.JetpackRunning)
                 {
                     this.m_walkParticleSpawnCounterMs = 0x7d0;
                 }
                 else
                 {
                     MyCharacterMovementEnum currentMovementState = entity.GetCurrentMovementState();
                     if ((currentMovementState.GetDirection() == 0) || (currentMovementState == MyCharacterMovementEnum.Falling))
                     {
                         this.m_walkParticleSpawnCounterMs = 0x3e8;
                     }
                     else
                     {
                         Vector3D          up       = base.Entity.PositionComp.WorldMatrix.Up;
                         Vector3D          from     = base.Entity.PositionComp.WorldMatrix.Translation + (0.2 * up);
                         MyPhysics.HitInfo?nullable = MyPhysics.CastRay(from, (base.Entity.PositionComp.WorldMatrix.Translation + (0.2 * up)) - (0.5 * up), 0x1c);
                         if (nullable != null)
                         {
                             MyVoxelPhysicsBody physics = nullable.Value.HkHitInfo.GetHitEntity().Physics as MyVoxelPhysicsBody;
                             if (physics != null)
                             {
                                 MyStringId walk;
                                 ushort     speed = currentMovementState.GetSpeed();
                                 if (speed == 0)
                                 {
                                     walk = MyMaterialPropertiesHelper.CollisionType.Walk;
                                     this.m_walkParticleSpawnCounterMs = 500;
                                 }
                                 else if (speed == 0x400)
                                 {
                                     walk = MyMaterialPropertiesHelper.CollisionType.Run;
                                     this.m_walkParticleSpawnCounterMs = 0x113;
                                 }
                                 else if (speed != 0x800)
                                 {
                                     walk = MyMaterialPropertiesHelper.CollisionType.Walk;
                                     this.m_walkParticleSpawnCounterMs = 0x3e8;
                                 }
                                 else
                                 {
                                     walk = MyMaterialPropertiesHelper.CollisionType.Sprint;
                                     this.m_walkParticleSpawnCounterMs = 250;
                                 }
                                 Vector3D position = nullable.Value.Position;
                                 MyVoxelMaterialDefinition materialAt = physics.m_voxelMap.GetMaterialAt(ref position);
                                 if (materialAt != null)
                                 {
                                     MyMaterialPropertiesHelper.Static.TryCreateCollisionEffect(walk, position, (Vector3)up, ID_CHARACTER, materialAt.MaterialTypeNameHash, null);
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
 }
        private void DrawAtmosphericEntryEffect()
        {
            var naturalGravity          = MyGravityProviderSystem.CalculateNaturalGravityInPoint(m_grid.PositionComp.GetPosition());
            var naturalGravityMagnitude = naturalGravity.Length();

            bool noPhysics        = m_grid.Physics == null;
            bool recentlyHitVoxel = MySandboxGame.TotalGamePlayTimeInMilliseconds - m_lastVoxelContactTime < m_atmosphericEffectVoxelContactDelay;
            bool notNearPlanet    = naturalGravityMagnitude <= 0;
            bool tooLowSpeed      = !noPhysics && (m_grid.Physics.LinearVelocity.Length() < m_atmosphericEffectMinSpeed);

            if (noPhysics || recentlyHitVoxel || notNearPlanet || tooLowSpeed)
            {
                if (m_atmosphericEffect != null)
                {
                    MyParticlesManager.RemoveParticleEffect(m_atmosphericEffect);
                    m_atmosphericEffect = null;
                }

                return;
            }
            var currentVelocity          = m_grid.Physics.LinearVelocity;
            var currentVelocityDirection = Vector3.Normalize(currentVelocity);
            var currentSpeed             = currentVelocity.Length();

            if (m_atmosphericEffect == null)
            {
                if (!MyParticlesManager.TryCreateParticleEffect(52, out m_atmosphericEffect))
                {
                    return;
                }
            }

            BoundingBox worldAABB           = (BoundingBox)m_grid.PositionComp.WorldAABB;
            var         aabbCenter          = worldAABB.Center;
            var         directionFaceCenter = new Vector3();

            Debug.Assert(m_tmpCornerList.Count == 0);
            foreach (var corner in worldAABB.GetCorners())
            {
                var centerToCorner = corner - aabbCenter;
                if (centerToCorner.Dot(currentVelocityDirection) > 0.01f)
                {
                    m_tmpCornerList.Add(corner);
                    directionFaceCenter += corner;
                    if (m_tmpCornerList.Count == 4)
                    {
                        break;
                    }
                }
            }
            if (m_tmpCornerList.Count > 0)
            {
                directionFaceCenter /= m_tmpCornerList.Count;
            }

            Plane plane = new Plane(directionFaceCenter, -currentVelocityDirection);

            m_tmpCornerList.Clear();
            var   startPosition     = m_grid.Physics.CenterOfMassWorld;
            float?intersectDistance = new Ray(startPosition, currentVelocityDirection).Intersects(plane);

            m_lastWorkingIntersectDistance = intersectDistance ?? m_lastWorkingIntersectDistance;
            var intersectPoint = startPosition + 0.875f * currentVelocityDirection * m_lastWorkingIntersectDistance;

            Matrix worldMatrix = Matrix.Identity;

            worldMatrix.Translation = intersectPoint;
            worldMatrix.Forward     = currentVelocityDirection;
            var forwardPerpendicular = Vector3.Transform(currentVelocityDirection, Quaternion.CreateFromAxisAngle(m_grid.PositionComp.WorldMatrix.Left, (float)Math.PI / 2.0f));

            worldMatrix.Up   = Vector3.Normalize(Vector3.Reject(m_grid.PositionComp.WorldMatrix.Left, forwardPerpendicular));
            worldMatrix.Left = worldMatrix.Up.Cross(worldMatrix.Forward);

            var atmosphericDensityMultiplier = MyGravityProviderSystem.CalculateHighestNaturalGravityMultiplierInPoint(m_grid.PositionComp.GetPosition());

            m_atmosphericEffect.UserScale           = (float)worldAABB.ProjectedArea(currentVelocityDirection) / (float)Math.Pow(38.0 * m_grid.GridSize, 2.0);
            m_atmosphericEffect.UserAxisScale       = Vector3.Normalize(new Vector3(1.0f, 1.0f, 1.0f + 1.5f * (m_grid.Physics.LinearVelocity.Length() - m_atmosphericEffectMinSpeed) / (MyGridPhysics.ShipMaxLinearVelocity() - m_atmosphericEffectMinSpeed)));
            m_atmosphericEffect.WorldMatrix         = worldMatrix;
            m_atmosphericEffect.UserColorMultiplier = new Vector4(MathHelper.Clamp((currentSpeed - m_atmosphericEffectMinSpeed) / (m_atmosphericEffectMinSpeed * 0.5f) * (float)Math.Pow(atmosphericDensityMultiplier, 1.5), 0.0f, m_atmosphericEffectMinFade));
        }
Esempio n. 6
0
        private unsafe void DrawAtmosphericEntryEffect()
        {
            int  num1;
            bool flag  = (MySandboxGame.TotalGamePlayTimeInMilliseconds - this.m_lastVoxelContactTime) < 0x1388;
            bool flag2 = !(MyGravityProviderSystem.CalculateNaturalGravityInPoint(this.m_grid.PositionComp.GetPosition()).Length() != 0f);
            bool flag1 = ReferenceEquals(this.m_grid.Physics, null);

            if (!flag1)
            {
                num1 = (int)(this.m_grid.Physics.LinearVelocity.Length() < 75f);
            }
            else
            {
                num1 = 0;
            }
            bool flag3 = (bool)num1;

            if (((flag1 | flag) | flag2) | flag3)
            {
                if (this.m_atmosphericEffect != null)
                {
                    MyParticlesManager.RemoveParticleEffect(this.m_atmosphericEffect, false);
                    this.m_atmosphericEffect = null;
                }
            }
            else
            {
                Vector3     linearVelocity = this.m_grid.Physics.LinearVelocity;
                Vector3     v         = Vector3.Normalize(linearVelocity);
                float       num2      = linearVelocity.Length();
                BoundingBox worldAABB = (BoundingBox)this.m_grid.PositionComp.WorldAABB;
                Vector3     center    = worldAABB.Center;
                Vector3     position  = new Vector3();
                foreach (Vector3 vector8 in worldAABB.GetCorners())
                {
                    Vector3 vector9 = vector8 - center;
                    if (vector9.Dot(v) > 0.01f)
                    {
                        m_tmpCornerList.Add(vector8);
                        position += vector8;
                        if (m_tmpCornerList.Count == 4)
                        {
                            break;
                        }
                    }
                }
                if (m_tmpCornerList.Count > 0)
                {
                    position /= (float)m_tmpCornerList.Count;
                }
                Plane plane = new Plane(position, -v);
                m_tmpCornerList.Clear();
                Vector3D centerOfMassWorld = this.m_grid.Physics.CenterOfMassWorld;
                float?   nullable2         = new Ray((Vector3)centerOfMassWorld, v).Intersects(plane);
                this.m_lastWorkingIntersectDistance = (nullable2 != null) ? nullable2.GetValueOrDefault() : this.m_lastWorkingIntersectDistance;
                Matrix identity = Matrix.Identity;
                identity.Translation = (Vector3)(centerOfMassWorld + ((0.875f * v) * this.m_lastWorkingIntersectDistance));
                identity.Forward     = v;
                Vector3 direction = Vector3.Transform(v, Quaternion.CreateFromAxisAngle((Vector3)this.m_grid.PositionComp.WorldMatrix.Left, 1.570796f));
                identity.Up = Vector3.Normalize(Vector3.Reject((Vector3)this.m_grid.PositionComp.WorldMatrix.Left, direction));
                Matrix *matrixPtr1 = (Matrix *)ref identity;
                matrixPtr1.Left = identity.Up.Cross(identity.Forward);
                float num3 = MyGravityProviderSystem.CalculateHighestNaturalGravityMultiplierInPoint(this.m_grid.PositionComp.GetPosition());
                if ((this.m_atmosphericEffect != null) || MyParticlesManager.TryCreateParticleEffect("Dummy", identity, out this.m_atmosphericEffect))
                {
                    this.m_atmosphericEffect.UserScale           = worldAABB.ProjectedArea(v) / ((float)Math.Pow(38.0 * this.m_grid.GridSize, 2.0));
                    this.m_atmosphericEffect.UserAxisScale       = Vector3.Normalize(new Vector3(1f, 1f, 1f + ((1.5f * (this.m_grid.Physics.LinearVelocity.Length() - 75f)) / (MyGridPhysics.ShipMaxLinearVelocity() - 75f))));
                    this.m_atmosphericEffect.UserColorMultiplier = new Vector4(MathHelper.Clamp((float)(((num2 - 75f) / 37.5f) * ((float)Math.Pow((double)num3, 1.5))), (float)0f, (float)0.85f));
                }
            }
        }