示例#1
0
 void Components_ComponentAdded(Type t, Sandbox.Common.Components.MyComponentBase c)
 {
     if (t == typeof(MyPhysicsComponentBase))
     {
         m_physics = c as MyPhysicsBody;
     }
     else if (t == typeof(MySyncComponentBase))
     {
         m_syncObject = c as MySyncComponentBase;
     }
     else if (t == typeof(MyGameLogicComponent))
     {
         m_gameLogic = c as MyGameLogicComponent;
     }
     else if (t == typeof(MyPositionComponentBase))
     {
         m_position = c as MyPositionComponentBase;
     }
     else if (t == typeof(MyHierarchyComponentBase))
     {
         m_hierarchy = c as MyHierarchyComponentBase;
     }
     else if (t == typeof(MyRenderComponentBase))
     {
         m_render = c as MyRenderComponentBase;
     }
 }
示例#2
0
 private void CreateConstraint(MyEntitySubpart subpart, ref HkConstraint constraint, ref HkFixedConstraintData constraintData)
 {
     if (subpart != null)
     {
         bool flag = !Sync.IsServer;
         if (subpart.Physics == null)
         {
             HkShape[] havokCollisionShapes = subpart.ModelCollision.HavokCollisionShapes;
             if ((havokCollisionShapes != null) && (havokCollisionShapes.Length != 0))
             {
                 MyPhysicsBody body = new MyPhysicsBody(subpart, flag ? RigidBodyFlag.RBF_STATIC : (RigidBodyFlag.RBF_UNLOCKED_SPEEDS | RigidBodyFlag.RBF_DOUBLED_KINEMATIC))
                 {
                     IsSubpart = true
                 };
                 subpart.Physics = body;
                 HkShape shape = havokCollisionShapes[0];
                 MyPositionComponentBase positionComp = subpart.PositionComp;
                 Vector3          center     = positionComp.LocalVolume.Center;
                 HkMassProperties properties = HkInertiaTensorComputer.ComputeBoxVolumeMassProperties(positionComp.LocalAABB.HalfExtents, 100f);
                 int collisionFilter         = base.CubeGrid.IsStatic ? 9 : 0x10;
                 body.CreateFromCollisionObject(shape, center, positionComp.WorldMatrix, new HkMassProperties?(properties), collisionFilter);
             }
         }
         if (flag)
         {
             subpart.Physics.Enabled = true;
         }
         else
         {
             base.CreateSubpartConstraint(subpart, out constraintData, out constraint);
             base.CubeGrid.Physics.AddConstraint(constraint);
             constraint.SetVirtualMassInverse(Vector4.Zero, Vector4.One);
         }
     }
 }
示例#3
0
 void Components_ComponentRemoved(Type t, Sandbox.Common.Components.MyComponentBase c)
 {
     if (t == typeof(MyPhysicsComponentBase))
     {
         m_physics = null;
     }
     else if (t == typeof(MySyncComponentBase))
     {
         m_syncObject = null;
     }
     else if (t == typeof(MyGameLogicComponent))
     {
         m_gameLogic = null;
     }
     else if (t == typeof(MyPositionComponentBase))
     {
         m_position = null;
     }
     else if (t == typeof(MyHierarchyComponentBase))
     {
         m_hierarchy = null;
     }
     else if (t == typeof(MyRenderComponentBase))
     {
         m_render = null;
     }
 }
示例#4
0
        public override unsafe void RecreatePhysics()
        {
            if (this.m_detectorPhysics != null)
            {
                this.m_detectorPhysics.Close();
                this.m_detectorPhysics = null;
            }
            if (m_shapes == null)
            {
                m_shapes = new List <HkShape>();
            }
            if (m_detectorVertices == null)
            {
                m_detectorVertices = new Vector3[8];
            }
            m_shapes.Clear();
            BoundingBox             box   = new BoundingBox(-Vector3.One / 2f, Vector3.One / 2f);
            MyPositionComponentBase base2 = base.Container.Get <MyPositionComponentBase>();

            foreach (KeyValuePair <uint, DetectorData> pair in this.m_detectorInteractiveObjects)
            {
                Vector3[] pinned vectorArray;
                try
                {
                    Vector3 *vectorPtr;
                    if (((vectorArray = m_detectorVertices) == null) || (vectorArray.Length == 0))
                    {
                        vectorPtr = null;
                    }
                    else
                    {
                        vectorPtr = vectorArray;
                    }
                    box.GetCornersUnsafe(vectorPtr);
                }
                finally
                {
                    vectorArray = null;
                }
                int index = 0;
                while (true)
                {
                    if (index >= 8)
                    {
                        m_shapes.Add((HkShape) new HkConvexVerticesShape(m_detectorVertices, 8, false, 0f));
                        break;
                    }
                    m_detectorVertices[index] = Vector3.Transform(m_detectorVertices[index], pair.Value.Matrix);
                    index++;
                }
            }
            if (m_shapes.Count > 0)
            {
                HkListShape shape = new HkListShape(m_shapes.GetInternalArray <HkShape>(), m_shapes.Count, HkReferencePolicy.TakeOwnership);
                this.m_detectorPhysics = new MyPhysicsBody(base.Container.Entity, RigidBodyFlag.RBF_DISABLE_COLLISION_RESPONSE);
                HkMassProperties?massProperties = null;
                this.m_detectorPhysics.CreateFromCollisionObject((HkShape)shape, Vector3.Zero, base2.WorldMatrix, massProperties, 15);
                shape.Base.RemoveReference();
            }
        }
示例#5
0
 public override void PositionChanged(MyPositionComponentBase obj)
 {
     if (m_detectorPhysics != null)
     {
         m_detectorPhysics.OnWorldPositionChanged(obj);
     }
 }
示例#6
0
 void Components_ComponentAdded(Type t, MyEntityComponentBase c)
 {
     if ((typeof(MyPhysicsComponentBase)).IsAssignableFrom(t))
     {
         m_physics = c as MyPhysicsBody;
     }
     else if ((typeof(MySyncComponentBase)).IsAssignableFrom(t))
     {
         m_syncObject = c as MySyncComponentBase;
     }
     else if ((typeof(MyGameLogicComponent)).IsAssignableFrom(t))
     {
         m_gameLogic = c as MyGameLogicComponent;
     }
     else if ((typeof(MyPositionComponentBase)).IsAssignableFrom(t))
     {
         m_position = c as MyPositionComponentBase;
         if (m_position == null)
         {
             PositionComp = new MyNullPositionComponent();
         }
     }
     else if ((typeof(MyHierarchyComponentBase)).IsAssignableFrom(t))
     {
         m_hierarchy = c as MyHierarchyComponentBase;
     }
     else if ((typeof(MyRenderComponentBase)).IsAssignableFrom(t))
     {
         m_render = c as MyRenderComponentBase;
         if (m_render == null)
         {
             Render = new MyNullRenderComponent();
         }
     }
 }
        private void PosChanged(MyPositionComponentBase obj)
        {
            var up = AngleToUp;

            _isDumping = up > Definition.EmptyMargin;
            _isFilling = up < Definition.FillMargin;
            CheckNeedsUpdate();
        }
示例#8
0
        void entity_OnPositionChanged(MyPositionComponentBase entity)
        {
            DetectedEntityInfo info;

            if (m_detectedEntities.TryGetValue(entity.Container.Entity as MyEntity, out info))
            {
                info.Moved = true;
            }
        }
示例#9
0
        private void CheckPosition(MyPositionComponentBase obj)
        {
            var test = new BoundingSphereD(Entity.PositionComp.WorldVolume.Center, Definition.ScanRadius);

            if (_cachedRegion.Contains(test) == ContainmentType.Contains)
            {
                return;
            }
            InvalidateCache();
        }
 public override void OnAddedToScene()
 {
     base.OnAddedToScene();
     _updateScheduled   = false;
     _positionComponent = Container.Get <MyPositionComponentBase>();
     OnPhantomEntered  += PhantomEntered;
     _positionComponent.OnPositionChanged += PosChanged;
     PosChanged(_positionComponent);
     CheckNeedsUpdate();
 }
 public override void OnRemovedFromScene()
 {
     OnPhantomEntered -= PhantomEntered;
     if (_positionComponent != null)
     {
         _positionComponent.OnPositionChanged -= PosChanged;
     }
     _positionComponent = null;
     _updateScheduled   = false;
     base.OnRemovedFromScene();
 }
示例#12
0
 public void PositionChanged(MyPositionComponentBase pComp)
 {
     try
     {
         if (PosChangedTick != Comp.Session.Tick)
         {
             UpdatePivotPos();
         }
     }
     catch (Exception ex) { Log.Line($"Exception in PositionChanged: {ex}"); }
 }
示例#13
0
        private void OnModelPositionChanged(MyPositionComponentBase pos)
        {
            // save turret position
            GetTurretOrientation();
            //Logger.Instance.LogMessage("Forward:" + pos.GetOrientation().Forward.ToString());
            // update light
            m_light_emmitter.ReflectorDirection = pos.GetOrientation().Forward;
            m_light_emmitter.ReflectorUp        = pos.GetOrientation().Up;
            m_light_emmitter.Position           = pos.GetPosition() + pos.GetOrientation().Forward *Light_Offset;

            m_light_emmitter.UpdateLight();
        }
示例#14
0
 private void WakePhysics(MyPositionComponentBase obj)
 {
     if (_gridPositionComponent != null)
     {
         _gridPositionComponent.OnPositionChanged -= WakePhysics;
     }
     if (!_physicsAwake)
     {
         _physicsAwake = true;
         AddFixedUpdate(Simulate);
     }
 }
示例#15
0
 void PositionComp_OnPositionChanged(MyPositionComponentBase obj)
 {
     if (m_collidingEntities.ContainsKey((MyEntity)obj.Container.Entity))
     {
         if (m_frameCounter - m_collidingEntities[(MyEntity)obj.Container.Entity].FrameTime > 20)
         { //Object not contacted with grid for 20 frames
             obj.OnPositionChanged -= PositionComp_OnPositionChanged;
             DynamicWeights.Remove(m_collidingEntities[(MyEntity)obj.Container.Entity].Position);
             m_collidingEntities.Remove((MyEntity)obj.Container.Entity);
             m_needsRecalc = true;
         }
     }
 }
 void PositionComp_OnPositionChanged(MyPositionComponentBase obj)
 {
     //if (m_collidingEntities.ContainsKey((MyEntity)obj.Entity))
     //{
     //    if (m_frameCounter - m_collidingEntities[(MyEntity)obj.Entity].FrameTime > 20)
     //    { //Object not contacted with grid for 20 frames
     //        obj.OnPositionChanged -= PositionComp_OnPositionChanged;
     //        DynamicWeights.Remove(m_collidingEntities[(MyEntity)obj.Entity].Position);
     //        m_collidingEntities.Remove((MyEntity)obj.Entity);
     //        ForceRecalc = true;
     //    }
     //}
 }
 private static void OnCreatedEntityPositionChanged(MyPositionComponentBase obj)
 {
     if (obj.Container.Entity.Save == false)
     {
         MyEncounterId id;
         if (m_entityToEncounterConversion.TryGetValue(obj.Container.Entity, out id))
         {
             Vector3D newPosition = obj.GetPosition();
             if (Vector3D.Distance(id.PlacePosition, newPosition) > m_minDistanceToRecognizeMovement)
             {
                 m_movedOnlyEncounters[id] = obj.GetPosition();
             }
         }
     }
 }
        public void UpdateParts(MyPositionComponentBase pComp)
        {
            if (_azimuthSubpartUpdateTick == Comp.Session.Tick)
            {
                return;
            }
            _azimuthSubpartUpdateTick = Comp.Session.Tick;

            var matrix = AzimuthPart.Entity.WorldMatrix;

            foreach (var part in AzimuthPart.Entity.Subparts)
            {
                //if(!part.Key.Contains(System.AzimuthPartName.String))
                //part.Value.PositionComp.UpdateWorldMatrix(ref matrix);
            }
        }
示例#19
0
        internal void PositionChanged(MyPositionComponentBase pComp)
        {
            try
            {
                if (PosChangedTick != Comp.Session.Tick)
                {
                    UpdatePivotPos();
                }

                if (Comp.UserControlled)
                {
                    ReturingHome = false;
                    IsHome       = false;
                }
            }
            catch (Exception ex) { Log.Line($"Exception in PositionChanged: {ex}"); }
        }
示例#20
0
        private void OnEntityPositionCompPositionChanged(MyPositionComponentBase myPositionComponentBase)
        {
            TriggerType triggerType = this.m_triggerType;

            if (triggerType == TriggerType.AABB)
            {
                Vector3D vctTranlsation = (base.Entity.PositionComp.GetPosition() - this.m_AABB.Matrix.Translation) + this.DefaultTranslation;
                this.m_AABB.Translate(vctTranlsation);
            }
            else
            {
                if (triggerType != TriggerType.Sphere)
                {
                    throw new ArgumentOutOfRangeException();
                }
                this.m_boundingSphere.Center = base.Entity.PositionComp.GetPosition() + this.DefaultTranslation;
            }
        }
示例#21
0
        protected void InternalRegisterEntityMovedEvent( )
        {
            try
            {
                MyPositionComponentBase positionComponent = (MyPositionComponentBase)GetEntityPositionObject(BackingObject);
                if (positionComponent == null)
                {
                    return;
                }

                Action <MyPositionComponentBase> action = InternalEntityMovedEvent;
                positionComponent.OnPositionChanged -= action;
                positionComponent.OnPositionChanged += action;
            }
            catch (Exception ex)
            {
                ApplicationLog.BaseLog.Error(ex);
            }
        }
        private void OnEntityPositionCompPositionChanged(MyPositionComponentBase myPositionComponentBase)
        {
            // Update BB position to respective entity position.
            // default translation keeps the relative offset to entity.
            switch (m_triggerType)
            {
            case TriggerType.AABB:
                var translation = Entity.PositionComp.GetPosition() - m_AABB.Matrix.Translation + DefaultTranslation;
                m_AABB.Translate(translation);
                break;

            case TriggerType.Sphere:
                m_boundingSphere.Center = Entity.PositionComp.GetPosition() + DefaultTranslation;
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
示例#23
0
        public override IMyUseObject RaycastDetectors(Vector3D worldFrom, Vector3D worldTo, out float parameter)
        {
            MyPositionComponentBase base2         = base.Container.Get <MyPositionComponentBase>();
            MatrixD      worldMatrixNormalizedInv = base2.WorldMatrixNormalizedInv;
            RayD         ray       = new RayD(worldFrom, worldTo - worldFrom);
            IMyUseObject useObject = null;

            parameter = float.MaxValue;
            foreach (KeyValuePair <uint, DetectorData> pair in this.m_detectorInteractiveObjects)
            {
                MatrixD matrix   = pair.Value.Matrix * base2.WorldMatrix;
                double? nullable = new MyOrientedBoundingBoxD(matrix).Intersects(ref ray);
                if ((nullable != null) && (nullable.Value < ((double)parameter)))
                {
                    parameter = (float)nullable.Value;
                    useObject = pair.Value.UseObject;
                }
            }
            return(useObject);
        }
示例#24
0
        private void OnPositionChanged(MyPositionComponentBase obj)
        {
            var ent = obj.Container?.Entity;

            if (ent == null)
            {
                return;
            }
            var player = MyAPIGateway.Players.GetPlayerControllingEntity(ent);

            if (player == null)
            {
                return;
            }
            HashSet <ResearchStatefulKey> activated;

            if (!_activatedEntries.TryGetValue(player.IdentityId, out activated) || activated.Count == 0)
            {
                return;
            }
            var worldBox = obj.WorldAABB;

            _detectorTree.OverlapAllBoundingBox(ref worldBox, _matchingDetectors);
            if (_matchingDetectors.Count == 0)
            {
                return;
            }
            var playerState = Manager.GetOrCreatePlayer(player);

            foreach (var k in _matchingDetectors)
            {
                if (worldBox.Intersects(k.Detector) && activated.Contains(k.Key))
                {
                    var prs = playerState.PlayerResearchState(k.Key.ResearchKey);
                    prs?.UpdateStatefulStorage(k.Key.StatefulKey, true);
                }
            }
        }
示例#25
0
        public Vector3D GetAimAtPosition(Vector3D startingPosition)
        {
            if (!this.HasTarget())
            {
                return(Vector3D.Zero);
            }
            if (this.m_currentTarget == MyAiTargetEnum.POSITION)
            {
                return(this.m_targetPosition);
            }
            if (this.m_currentTarget == MyAiTargetEnum.ENVIRONMENT_ITEM)
            {
                return(this.m_targetPosition);
            }
            Vector3D position = this.m_targetEntity.PositionComp.GetPosition();

            if (this.m_currentTarget == MyAiTargetEnum.CUBE)
            {
                this.GetLocalCubeProjectedPosition(ref startingPosition);
                position = this.TargetCubeWorldPosition;
            }
            else if (this.m_currentTarget == MyAiTargetEnum.CHARACTER)
            {
                MyPositionComponentBase positionComp = (this.m_targetEntity as MyCharacter).PositionComp;
                position = Vector3D.Transform(positionComp.LocalVolume.Center, positionComp.WorldMatrix);
            }
            else if (this.m_currentTarget == MyAiTargetEnum.VOXEL)
            {
                position = this.m_targetPosition;
            }
            else if (((this.m_currentTarget == MyAiTargetEnum.ENTITY) && (this.m_targetPosition != Vector3D.Zero)) && (this.m_targetEntity is MyFracturedPiece))
            {
                position = this.m_targetPosition;
            }
            return(position);
        }
示例#26
0
        private void BlockMoved(MyBlockComponent block, MyGridDataComponent gridData)
        {
            var nextGridPhys = gridData?.Container?.Get <MyPhysicsComponentBase>();
            var nextGridPos  = gridData?.Container?.Get <MyPositionComponentBase>();

            if (nextGridPos == _gridPositionComponent && nextGridPhys == _gridPhysicsComponent)
            {
                return;
            }
            if (_gridPositionComponent != null)
            {
                _gridPositionComponent.OnPositionChanged -= WakePhysics;
            }
            _gridPhysicsComponent  = nextGridPhys;
            _gridPositionComponent = nextGridPos;
            if (_gridPositionComponent != null)
            {
                WakePhysics(null);
            }
            else
            {
                RemoveFixedUpdate(Simulate);
            }
        }
示例#27
0
 void positionComponent_OnPositionChanged(MyPositionComponentBase obj)
 {
     m_detectorPhysics.OnWorldPositionChanged(obj);
 }
 private void OnPositionChanged(MyPositionComponentBase obj)
 {
     dirty = true;
 }
示例#29
0
 void Components_ComponentRemoved(Type t, MyEntityComponentBase c)
 {
     if (t == typeof(MyPhysicsComponentBase))
         m_physics = null;
     else if (t == typeof(MySyncComponentBase))
         m_syncObject = null;
     else if (t == typeof(MyGameLogicComponent))
         m_gameLogic = null;
     else if (t == typeof(MyPositionComponentBase))
         m_position = null;
     else if (t == typeof(MyHierarchyComponentBase))
         m_hierarchy = null;
     else if (t == typeof(MyRenderComponentBase))
     {
         m_render = null;
     }
 }
示例#30
0
 void Components_ComponentAdded(Type t, MyEntityComponentBase c)
 {
     if (t == typeof(MyPhysicsComponentBase))
         m_physics = c as MyPhysicsBody;
     else if (t == typeof(MySyncComponentBase))
         m_syncObject = c as MySyncComponentBase;
     else if (t == typeof(MyGameLogicComponent))
         m_gameLogic = c as MyGameLogicComponent;
     else if (t == typeof(MyPositionComponentBase))
         m_position = c as MyPositionComponentBase;
     else if (t == typeof(MyHierarchyComponentBase))
         m_hierarchy = c as MyHierarchyComponentBase;
     else if (t == typeof(MyRenderComponentBase))
     {
         m_render = c as MyRenderComponentBase;
     }
 }
示例#31
0
 private void PositionChanged(MyPositionComponentBase pos)
 {
     bubble?.SetPosition(pos.WorldAABB.Center);
 }
 private static void OnCreatedEntityPositionChanged(MyPositionComponentBase obj)
 {
     if (obj.Container.Entity.Save == false)
     {
         MyEncounterId id;
         if (m_entityToEncounterConversion.TryGetValue(obj.Container.Entity, out id))
         {
             Vector3D newPosition = obj.GetPosition();
             if (Vector3D.Distance(id.PlacePosition, newPosition) > m_minDistanceToRecognizeMovement)
             {
                 m_movedOnlyEncounters[id] = obj.GetPosition();
             }
         }
     }
 }
示例#33
0
 void Components_ComponentAdded(Type t, MyEntityComponentBase c)
 {
     if ((typeof(MyPhysicsComponentBase)).IsAssignableFrom(t))
         m_physics = c as MyPhysicsBody;
     else if ((typeof(MySyncComponentBase)).IsAssignableFrom(t))
         m_syncObject = c as MySyncComponentBase;
     else if ((typeof(MyGameLogicComponent)).IsAssignableFrom(t))
         m_gameLogic = c as MyGameLogicComponent;
     else if ((typeof(MyPositionComponentBase)).IsAssignableFrom(t))
     {
         m_position = c as MyPositionComponentBase;
         if (m_position == null)
             PositionComp = new MyNullPositionComponent();
     }
     else if ((typeof(MyHierarchyComponentBase)).IsAssignableFrom(t))
         m_hierarchy = c as MyHierarchyComponentBase;
     else if ((typeof(MyRenderComponentBase)).IsAssignableFrom(t))
     {
         m_render = c as MyRenderComponentBase;
         if (m_render == null)
             Render = new MyNullRenderComponent();
     }
 }
 private void ControlledEntityPositionChanged(MyPositionComponentBase myPositionComponentBase)
 {
     UpdateGizmoPosition();
 }
 private static void UpdateDummyWorld(MyPositionComponentBase windingEntityPositionComponent, WindingData winding)
 {
     winding.LastDummyWorld = winding.CurrentDummyWorld;
     winding.CurrentDummyWorld = MatrixD.Multiply(winding.LocalDummy, windingEntityPositionComponent.WorldMatrix);
 }