Beispiel #1
0
        /// <summary>
        /// Adds the child.
        /// </summary>
        /// <param name="child">The child.</param>
        /// <param name="preserveWorldPos">if set to <c>true</c> [preserve absolute position].</param>
        public void AddChild(IMyEntity child, bool preserveWorldPos = false, bool insertIntoSceneIfNeeded = true)
        {
            //MyEntities.Remove(child);  // if it's already in the world, remove it

            MyHierarchyComponentBase childHierarchy = child.Components.Get <MyHierarchyComponentBase>();

            childHierarchy.Parent = this;

            if (preserveWorldPos)
            {
                var tmpWorldMatrix = child.WorldMatrix;

                this.Children.Add(childHierarchy);

                child.PositionComp.SetWorldMatrix(tmpWorldMatrix, Entity, true);
            }
            else
            {
                this.Children.Add(childHierarchy);

                MyPositionComponentBase positionComponent      = Container.Get <MyPositionComponentBase>();
                MyPositionComponentBase childPositionComponent = child.Components.Get <MyPositionComponentBase>();

                var m = positionComponent.WorldMatrix;
                childPositionComponent.UpdateWorldMatrix(ref m);
            }

            if (Container.Entity.InScene && !child.InScene && insertIntoSceneIfNeeded)
            {
                child.OnAddedToScene(Container.Entity);
            }
        }
Beispiel #2
0
        protected void RaiseOnPositionChanged(MyPositionComponentBase component)
        {
            var handle = OnPositionChanged;

            if (handle != null)
            {
                handle(component);
            }
        }
Beispiel #3
0
 void Components_ComponentAdded(Type t, MyEntityComponentBase c)
 {
     // TODO: this has to be refactored because it is very dangerous - each component member set here can be overwritten with new one of the same base type
     // (assume more than one GameLogicComponent), components should support aggregates (parameter can be added to MyComponentTypeAttribute).
     if ((typeof(MyPhysicsComponentBase)).IsAssignableFrom(t))
         m_physics = c as MyPhysicsComponentBase;
     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 VRage.Game.Components.MyNullPositionComponent();
     }
     else if ((typeof(MyHierarchyComponentBase)).IsAssignableFrom(t))
         m_hierarchy = c as MyHierarchyComponent<MyEntity>;
     else if ((typeof(MyRenderComponentBase)).IsAssignableFrom(t))
     {
         m_render = c as MyRenderComponentBase;
         if (m_render == null)
             Render = new VRage.Game.Components.MyNullRenderComponent();
     }
     else if ((typeof(MyInventoryBase)).IsAssignableFrom(t))
     {
         OnInventoryComponentAdded(c as MyInventoryBase);
     }
 }
 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();
             }
         }
     }
 }
Beispiel #5
0
 void entity_OnPositionChanged(MyPositionComponentBase entity)
 {
     DetectedEntityInfo info;
     if (m_detectedEntities.TryGetValue(entity.Container.Entity as MyEntity, out info))
     {
         info.Moved = true;
     }
 }
Beispiel #6
0
 public abstract void PositionChanged(MyPositionComponentBase obj);
 protected void RaiseOnPositionChanged(MyPositionComponentBase component)
 {
     var handle = OnPositionChanged;
     if (handle != null)
     {
         handle(component);
     }
 }
 void OnPositionChanged(MyPositionComponentBase obj)
 {
     MatrixD worldMatrix = obj.WorldMatrix;
     if (raycaster != null)
         raycaster.OnWorldPosChanged(ref worldMatrix);
 }
 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;
         }
     }
 }
 private void ControlledEntityPositionChanged(MyPositionComponentBase myPositionComponentBase)
 {
     UpdateGizmoPosition();
 }
 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 UpdateDummyWorld(MyPositionComponentBase windingEntityPositionComponent, WindingData winding)
 {
     winding.LastDummyWorld = winding.CurrentDummyWorld;
     winding.CurrentDummyWorld = MatrixD.Multiply(winding.LocalDummy, windingEntityPositionComponent.WorldMatrix);
 }
 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();
     }
 }