Esempio n. 1
0
        public static void Update()
        {
            //  Update only if sun wind is active
            if (IsActive == false)
            {
                return;
            }

            //?
            float dT = ((float)MyMinerGame.TotalGamePlayTimeInMilliseconds - (float)m_timeLastUpdate) / 1000.0f;

            m_timeLastUpdate = MyMinerGame.TotalGamePlayTimeInMilliseconds;

            if ((MyGuiScreenGamePlay.Static.IsEditorActive() && !MyGuiScreenGamePlay.Static.IsIngameEditorActive()) || MyMinerGame.IsPaused())
            {
                return;
            }

            m_deltaTime += dT;

            float traveledDistance = m_speed * m_deltaTime;

            //  If sun wind finished its way, we will turn it off
            if (traveledDistance >= MySunWindConstants.SUN_WIND_LENGTH_TOTAL)
            {
                IsActive = false;
                StopCue();
                return;
            }

            Vector3 campos = MyCamera.Position;

            //  This is plane that goes through sun wind, it's in its middle
            m_planeMiddle       = new MyPlane(m_initialSunWindPosition + m_directionFromSunNormalized * traveledDistance, m_directionFromSunNormalized);
            m_distanceToSunWind = MyUtils.GetDistanceFromPointToPlane(ref campos, ref m_planeMiddle);

            //  We make sure that sound moves always on line that goes through camera. So it's not in the middle of sun wind, more like middle where is camera.
            //  Reason is that I want the sound always go through camera.
            m_positionOnCameraLine = MyCamera.Position - m_directionFromSunNormalized * m_distanceToSunWind;

            Vector3 positionFront = m_positionOnCameraLine + m_directionFromSunNormalized * 5000;
            Vector3 positionBack  = m_positionOnCameraLine + m_directionFromSunNormalized * -5000;

            m_planeFront = new MyPlane(ref positionFront, ref m_directionFromSunNormalized);
            m_planeBack  = new MyPlane(ref positionBack, ref m_directionFromSunNormalized);

            float distanceToFrontPlane = MyUtils.GetDistanceFromPointToPlane(ref campos, ref m_planeFront);
            float distanceToBackPlane  = MyUtils.GetDistanceFromPointToPlane(ref campos, ref m_planeBack);


            Vector3 positionOfSound;

            if ((distanceToFrontPlane <= 0) && (distanceToBackPlane >= 0))
            {
                positionOfSound = MyCamera.Position;
            }
            else if (distanceToFrontPlane > 0)
            {
                positionOfSound = positionFront;
            }
            else
            {
                positionOfSound = positionBack;
            }

            //  Update position of sound. It works like this: we hear coming sound, then we are in the sound and then we hear it coming out.
            MyAudio.UpdateCuePosition(m_burningCue, positionOfSound, m_directionFromSunNormalized, -m_downVector, m_directionFromSunNormalized * m_speed);
            //MySounds.UpdateCuePosition(m_burningCue, positionOfSound, m_directionFromSunNormalized, Vector3.Up, Vector3.Zero);

            //MyLogManager.WriteLine("positionOfSound: " + MyUtils.GetFormatedVector3(positionOfSound, 3));
            //MyLogManager.WriteLine("m_directionFromSunNormalized: " + MyUtils.GetFormatedVector3(m_directionFromSunNormalized, 3));
            //MyLogManager.WriteLine("m_downVector: " + MyUtils.GetFormatedVector3(m_downVector, 3));

            Position = positionOfSound;

            //  Shake player's head
            float distanceToSound;

            Vector3.Distance(ref positionOfSound, ref campos, out distanceToSound);
            float shake = 1 - MathHelper.Clamp(distanceToSound / 1000, 0, 1);

            if (MySession.PlayerShip != null)
            {
                MySession.PlayerShip.IncreaseHeadShake(
                    MathHelper.Lerp(MyHeadShakeConstants.HEAD_SHAKE_AMOUNT_DURING_SUN_WIND_MIN,
                                    MyHeadShakeConstants.HEAD_SHAKE_AMOUNT_DURING_SUN_WIND_MAX, shake));
            }

            for (int i = 0; i < m_sunwindEntities.Count;)
            {
                if (m_sunwindEntities[i].Closed)
                {
                    m_sunwindEntities.RemoveAtFast(i);
                }
                else
                {
                    i++;
                }
            }

            //  Apply force to all objects that aren't static and are hit by sun wind (ignoring voxels and large ships)
            MyEntities.ApplySunWindForce(m_sunwindEntities, ref m_planeFront, ref m_planeBack, DoNotIgnoreTheseTypes, ref m_directionFromSunNormalized);

            //  Start small billboards
            if (m_distanceToSunWind <= MySunWindConstants.SWITCH_LARGE_AND_SMALL_BILLBOARD_DISTANCE)
            {
                Debug.Assert(m_computedMaxDistances == MySunWindConstants.SMALL_BILLBOARDS_SIZE.X * MySunWindConstants.SMALL_BILLBOARDS_SIZE.Y, "Not all small billboard MaxDistances are computed!");
                m_smallBillboardsStarted = true;
            }

            ComputeMaxDistances();
        }