コード例 #1
0
ファイル: NoiseSettings.cs プロジェクト: vuchl/Shoot-em-up
 /// <summary>Clones the contents of the other asset into this one</summary>
 public void CopyFrom(NoiseSettings other)
 {
     PositionNoise = new TransformNoiseParams[other.PositionNoise.Length];
     other.PositionNoise.CopyTo(PositionNoise, 0);
     OrientationNoise = new TransformNoiseParams[other.OrientationNoise.Length];
     other.OrientationNoise.CopyTo(OrientationNoise, 0);
 }
コード例 #2
0
 /// <summary>Clones the contents of the other asset into this one</summary>
 public void CopyFrom(NoiseSettings other)
 {
     m_Position = new TransformNoiseParams[other.m_Position.Length];
     other.m_Position.CopyTo(m_Position, 0);
     m_Orientation = new TransformNoiseParams[other.m_Orientation.Length];
     other.m_Orientation.CopyTo(m_Orientation, 0);
 }
コード例 #3
0
        /// <summary>Applies noise to the Correction channel of the CameraState if the
        /// delta time is greater than 0.  Otherwise, does nothing.</summary>
        /// <param name="curState">The current camera state</param>
        /// <param name="deltaTime">How much to advance the perlin noise generator.
        /// Noise is only applied if this value is greater than or equal to 0</param>
        public override void MutateCameraState(ref CameraState curState, float deltaTime)
        {
            if (!IsValid || deltaTime < 0)
            {
                return;
            }

            if (!mInitialized)
            {
                Initialize();
            }

            mNoiseTime += deltaTime * m_FrequencyGain;
            curState.PositionCorrection += curState.CorrectedOrientation * NoiseSettings.GetCombinedFilterResults(
                m_NoiseProfile.PositionNoise, mNoiseTime, mNoiseOffsets) * m_AmplitudeGain;
            Quaternion rotNoise = Quaternion.Euler(NoiseSettings.GetCombinedFilterResults(
                                                       m_NoiseProfile.OrientationNoise, mNoiseTime, mNoiseOffsets) * m_AmplitudeGain);

            if (m_PivotOffset != Vector3.zero)
            {
                Matrix4x4 m = Matrix4x4.Translate(-m_PivotOffset);
                m = Matrix4x4.Rotate(rotNoise) * m;
                m = Matrix4x4.Translate(m_PivotOffset) * m;
                curState.PositionCorrection += curState.CorrectedOrientation * m.MultiplyPoint(Vector3.zero);
            }
            curState.OrientationCorrection = curState.OrientationCorrection * rotNoise;
        }
            public bool GetReaction(
                float deltaTime, Vector3 impulsePos,
                out Vector3 pos, out Quaternion rot)
            {
                if (!m_Initialized)
                {
                    m_Initialized    = true;
                    m_CurrentAmount  = 0;
                    m_CurrentDamping = 0;
                    m_CurrentTime    = CinemachineCore.CurrentTime * m_FrequencyGain;
                    if (m_NoiseOffsets == Vector3.zero)
                    {
                        ReSeed();
                    }
                }

                // Is there any reacting to do?
                pos = Vector3.zero;
                rot = Quaternion.identity;
                var sqrMag = impulsePos.sqrMagnitude;

                if (m_SecondaryNoise == null || (sqrMag < 0.001f && m_CurrentAmount < 0.0001f))
                {
                    return(false);
                }

                // Advance the current reaction time
                if (TargetPositionCache.CacheMode == TargetPositionCache.Mode.Playback &&
                    TargetPositionCache.HasCurrentTime)
                {
                    m_CurrentTime = TargetPositionCache.CurrentTime * m_FrequencyGain;
                }
                else
                {
                    m_CurrentTime += deltaTime * m_FrequencyGain;
                }

                // Adjust the envelope height and duration of the secondary noise,
                // acording to the strength of the incoming signal
                m_CurrentAmount  = Mathf.Max(m_CurrentAmount, Mathf.Sqrt(sqrMag));
                m_CurrentDamping = Mathf.Max(m_CurrentDamping, Mathf.Max(1, Mathf.Sqrt(m_CurrentAmount)) * m_Duration);

                var gain = m_CurrentAmount * m_AmplitudeGain;

                pos = NoiseSettings.GetCombinedFilterResults(
                    m_SecondaryNoise.PositionNoise, m_CurrentTime, m_NoiseOffsets) * gain;
                rot = Quaternion.Euler(NoiseSettings.GetCombinedFilterResults(
                                           m_SecondaryNoise.OrientationNoise, m_CurrentTime, m_NoiseOffsets) * gain);

                m_CurrentAmount  -= Damper.Damp(m_CurrentAmount, m_CurrentDamping, deltaTime);
                m_CurrentDamping -= Damper.Damp(m_CurrentDamping, m_CurrentDamping, deltaTime);
                return(true);
            }
コード例 #5
0
        /// <summary>Applies noise to the Correction channel of the CameraState if the
        /// delta time is greater than 0.  Otherwise, does nothing.</summary>
        /// <param name="curState">The current camera state</param>
        /// <param name="deltaTime">How much to advance the perlin noise generator.
        /// Noise is only applied if this value is greater than or equal to 0</param>
        public override void MutateCameraState(ref CameraState curState, float deltaTime)
        {
            if (!IsValid || deltaTime < 0)
            {
                return;
            }

            if (!mInitialized)
            {
                Initialize();
            }

            mNoiseTime += deltaTime * m_FrequencyGain;
            curState.PositionCorrection += curState.CorrectedOrientation * NoiseSettings.GetCombinedFilterResults(
                m_NoiseProfile.PositionNoise, mNoiseTime, mNoiseOffsets) * m_AmplitudeGain;
            Quaternion rotNoise = Quaternion.Euler(NoiseSettings.GetCombinedFilterResults(
                                                       m_NoiseProfile.OrientationNoise, mNoiseTime, mNoiseOffsets) * m_AmplitudeGain);

            curState.OrientationCorrection = curState.OrientationCorrection * rotNoise;
        }
コード例 #6
0
        /// <summary>Applies noise to the Correction channel of the CameraState if the
        /// delta time is greater than 0.  Otherwise, does nothing.</summary>
        /// <param name="curState">The current camera state</param>
        /// <param name="deltaTime">How much to advance the perlin noise generator.
        /// Noise is only applied if this value is greater than or equal to 0</param>
        public override void MutateCameraState(ref CameraState curState, float deltaTime)
        {
            if (!IsValid || deltaTime < 0)
            {
                return;
            }

            //UnityEngine.Profiling.Profiler.BeginSample("CinemachineBasicMultiChannelPerlin.MutateCameraState");
            if (!mInitialized)
            {
                Initialize();
            }

            mNoiseTime += deltaTime * m_FrequencyGain;
            curState.PositionCorrection += curState.CorrectedOrientation * NoiseSettings.GetCombinedFilterResults(
                m_NoiseProfile.PositionNoise, mNoiseTime, mNoiseOffsets) * m_AmplitudeGain;
            Quaternion rotNoise = Quaternion.Euler(NoiseSettings.GetCombinedFilterResults(
                                                       m_NoiseProfile.OrientationNoise, mNoiseTime, mNoiseOffsets) * m_AmplitudeGain);

            curState.OrientationCorrection = curState.OrientationCorrection * rotNoise;
            //UnityEngine.Profiling.Profiler.EndSample();
        }