Example #1
0
        private void UpdateLightWorldMatrix()
        {
            if (m_pointLight != null)
            {
                Matrix newMat = m_pointLocalMatrix * base.WorldMatrix;

                m_pointLight.SetPosition(newMat.Translation);
                m_pointLight.ReflectorDirection = newMat.Down;
                m_pointLight.ReflectorDirection = MyMwcUtils.Normalize(m_pointLight.ReflectorDirection);
                m_pointLight.ReflectorUp        = newMat.Right;
                m_pointLight.ReflectorUp        = MyMwcUtils.Normalize(m_pointLight.ReflectorUp);

                // move the light outwards in the direction of the lamp, for purposes of glare
                m_pointLight.SetPosition(m_pointLight.Position + 0.75f * m_pointLight.ReflectorDirection);
            }
        }
Example #2
0
        public override void OnWorldPositionChanged(object source)
        {
            base.OnWorldPositionChanged(source);

            //  Update light position
            if (m_light != null)
            {
                m_light.SetPosition(GetPosition());
                m_light.Color = MyMissileHelperUtil.GetCannonShotLightColor();
                m_light.Range = MyMissileConstants.MISSILE_LIGHT_RANGE;
            }
        }
        public override void UpdateBeforeSimulation()
        {
            base.UpdateBeforeSimulation();

            if (m_elapsedMiliseconds > MyIlluminatingShellsConstants.MAX_LIVING_TIME + MyIlluminatingShellsConstants.DIYNG_TIME)
            {
                if (m_particleEffect != null)
                {
                    m_particleEffect.Stop();
                    m_particleEffect = null;
                }

                //  Free the light
                if (m_light != null)
                {
                    MyLights.RemoveLight(m_light);
                    m_light = null;
                }

                MarkForClose();
            }


            //  Update light position
            if (m_light != null)
            {
                // Aggro near bots
                if (m_light.LightOn)
                {
                    if (this.WorldMatrix.Translation != m_previousPosition)
                    {
                        MyLine line = new MyLine(m_previousPosition, WorldMatrix.Translation);
                        MyDangerZones.Instance.Notify(line, OwnerEntity);
                    }
                }

                if ((m_elapsedMiliseconds > MyIlluminatingShellsConstants.MAX_LIVING_TIME) &&
                    (m_elapsedMiliseconds < MyIlluminatingShellsConstants.MAX_LIVING_TIME + MyIlluminatingShellsConstants.DIYNG_TIME))
                {
                    m_light.LightOn            = MyMwcUtils.GetRandomBool(2);
                    m_particleEffect.UserScale = m_light.LightOn ? 1.0f : 0.001f;
                }

                m_light.SetPosition(GetPosition());
                m_light.Color = MyIlluminatingShellsConstants.LIGHT_COLOR;
                m_light.Range = MyIlluminatingShellsConstants.LIGHT_RADIUS;
            }
        }
Example #4
0
        /// <summary>
        /// Called when [world position changed].
        /// </summary>
        /// <param name="source">The source object that caused this event.</param>
        public override void OnWorldPositionChanged(object source)
        {
            base.OnWorldPositionChanged(source);

            if (Physics != null && m_thrusterCue != null)
            {
                //  Update thruster cue/sound
                MyAudio.UpdateCuePosition(m_thrusterCue, GetPosition(), WorldMatrix.Forward, WorldMatrix.Up,
                                          Physics.LinearVelocity);
            }

            //  Update light position
            if (m_light != null)
            {
                m_light.SetPosition(GetPosition());
                m_light.Color = MyMissileHelperUtil.GetMissileLightColor();
                m_light.Range = MyMissileConstants.MISSILE_LIGHT_RANGE;
            }
        }
Example #5
0
        /// <summary>
        /// Updates resource.
        /// </summary>
        public override void UpdateAfterSimulation()
        {
            base.UpdateAfterSimulation();

            if ((!GetParentMinerShip().Config.Engine.On || GetParentMinerShip().Fuel <= 0) &&
                (CurrentState == MyHarvestingDeviceEnum.InVoxel || CurrentState == MyHarvestingDeviceEnum.FindingVoxel))
            {
                StartFastReturningBack();
            }

            if (CurrentState == MyHarvestingDeviceEnum.InsideShip)
            {
                //  Do nothing
                return;
            }

            if (CurrentState == MyHarvestingDeviceEnum.FindingVoxel)
            {
                //  Head in local space
                m_headPositionLocal += this.LocalMatrix.Forward * MyHarvestingTubeConstants.EJECTION_SPEED_IN_METERS_PER_SECOND;
            }
            else if (CurrentState == MyHarvestingDeviceEnum.ReturningBack)
            {
                //  Head in local space
                m_headPositionLocal -= this.LocalMatrix.Forward * MyHarvestingTubeConstants.EJECTION_SPEED_IN_METERS_PER_SECOND;
            }
            else if (CurrentState == MyHarvestingDeviceEnum.FastReturningBack)
            {
                //  Head in local space
                m_headPositionLocal -= this.LocalMatrix.Forward * MyHarvestingTubeConstants.FAST_PULL_BACK_IN_METERS_PER_SECOND;
            }

            //  Transform head position into world space
            Matrix worldMatrix = Parent.WorldMatrix;

            m_harvestingOreHead.LocalMatrix = Matrix.CreateWorld(m_headPositionLocal, m_harvestingOreHead.LocalMatrix.Forward, m_harvestingOreHead.LocalMatrix.Up);
            m_headPositionTransformed       = m_harvestingOreHead.WorldMatrix.Translation;

            //  Distance must carry sign (plus/minus) because when we need to know if head is behind it's starting point when pulling back
            //  IMPORTANT: Forward is in -Z direction, so that's why I subtract position from head and not oppositely

            float distance = this.LocalMatrix.Translation.Z - m_headPositionLocal.Z;

            if (CurrentState == MyHarvestingDeviceEnum.ReturningBack ||
                CurrentState == MyHarvestingDeviceEnum.FastReturningBack)
            {
                if (distance <= MyHarvestingTubeConstants.DISTANCE_TO_PLUG_IN_THE_TUBE)
                {
                    StartInsideShip();
                }
            }
            else
            {
                if (distance >= MyHarvestingTubeConstants.MAX_DISTANCE_OF_HARVESTING_DEVICE)
                {
                    StartReturningBack();
                }
            }

            //  Sphere for head of harvester
            BoundingSphere headSphere = new BoundingSphere(m_headPositionTransformed, m_harvestingOreHead.ModelLod0.BoundingSphere.Radius);

            if (CurrentState == MyHarvestingDeviceEnum.FindingVoxel)
            {
                //  Check if head doesn't collide with anything
                MyEntity sphereResult = MyEntities.GetIntersectionWithSphere(ref headSphere, m_parentMinerShip, null);
                if (sphereResult != null)
                {
                    if (sphereResult is MyVoxelMap)
                    {
                        StartInVoxel((MyVoxelMap)sphereResult);
                    }
                    else
                    {
                        //  Intersection between sphere and anything else but voxels, so we start pulling back quickly
                        StartFastReturningBack();
                    }
                }
            }

            //  If we are connected to voxel check permanently if the voxel is still there
            if ((CurrentState == MyHarvestingDeviceEnum.InVoxel) && (MyMinerGame.TotalGamePlayTimeInMilliseconds - m_lastTimeCheckedForVoxelPresence) > MyHarvestingTubeConstants.INTERVAL_TO_CHECK_FOR_VOXEL_CONNECTION_IN_MILISECONDS)
            {
                m_lastTimeCheckedForVoxelPresence = MyMinerGame.TotalGamePlayTimeInMilliseconds;
                //  Check if head doesn't collide with anything
                MyEntity sphereResult = MyEntities.GetIntersectionWithSphere(ref headSphere, m_parentMinerShip, null);
                if (!(sphereResult is MyVoxelMap))
                {
                    StartFastReturningBack();
                }
            }

            //  If we are connected to voxel we can harvest it
            if (CurrentState == MyHarvestingDeviceEnum.InVoxel)
            {
                m_actualVoxelContent -= m_harvestingSpeed;

                if (m_actualVoxelContent <= 0)
                {
                    StartReleaseVoxel();
                }
            }

            if ((WorldMatrix.Translation - m_headPositionTransformed).Length() > MyMwcMathConstants.EPSILON)
            {
                //  Check if tube doesn't colide with something
                MyLine tubeLine = new MyLine(WorldMatrix.Translation, m_headPositionTransformed, true);
                MyIntersectionResultLineTriangleEx?tubeIntersection = MyEntities.GetIntersectionWithLine(ref tubeLine, this, m_parentMinerShip);

                //  We colide with something and we need fast return back
                if (tubeIntersection != null)
                {
                    StartFastReturningBack();
                }
            }

            if (CurrentState == MyHarvestingDeviceEnum.InVoxel)
            {
                m_parentMinerShip.IncreaseHeadShake(MyHarvestingTubeConstants.SHAKE_DURING_IN_VOXELS);
            }
            else if ((CurrentState == MyHarvestingDeviceEnum.FastReturningBack) ||
                     (CurrentState == MyHarvestingDeviceEnum.FindingVoxel) ||
                     (CurrentState == MyHarvestingDeviceEnum.ReturningBack))
            {
                m_parentMinerShip.IncreaseHeadShake(MyHarvestingTubeConstants.SHAKE_DURING_EJECTION);
            }

            if (m_light != null)
            {
                m_light.SetPosition(m_headPositionTransformed - WorldMatrix.Forward);
            }

            if ((m_tubeMovingCue != null) && (m_tubeMovingCue.Value.IsPlaying == true))
            {
                MyAudio.UpdateCuePosition(m_tubeMovingCue, WorldMatrix.Translation,
                                          WorldMatrix.Forward, WorldMatrix.Up, Parent.Physics.LinearVelocity);
            }

            if ((m_grindingCue != null) && (m_grindingCue.Value.IsPlaying == true))
            {
                MyAudio.UpdateCuePosition(m_grindingCue, m_headPositionTransformed,
                                          WorldMatrix.Forward, WorldMatrix.Up, Parent.Physics.LinearVelocity);
            }

            m_harvestingOreHead.SetData(ref m_worldMatrixForRenderingFromCockpitView);
        }
Example #6
0
 internal void MoveTo(Vector3 position)
 {
     Position = position;
     Light.SetPosition(position);
 }