Пример #1
0
        public bool Update()
        {
            m_elapsedTime += VRage.Game.MyEngineConstants.UPDATE_STEP_SIZE_IN_SECONDS;

            if (m_elapsedTime >= Life)
            {
                return(false);
            }

            m_normalizedTime += m_elapsedTimeDivider;

            m_velocity += m_generation.GetEffect().Gravity *m_generation.Gravity *VRage.Game.MyEngineConstants.UPDATE_STEP_SIZE_IN_SECONDS;

            m_previousPosition  = m_actualPosition;
            m_actualPosition.X += Velocity.X * VRage.Game.MyEngineConstants.UPDATE_STEP_SIZE_IN_SECONDS;
            m_actualPosition.Y += Velocity.Y * VRage.Game.MyEngineConstants.UPDATE_STEP_SIZE_IN_SECONDS;
            m_actualPosition.Z += Velocity.Z * VRage.Game.MyEngineConstants.UPDATE_STEP_SIZE_IN_SECONDS;

            if (PivotRotation != null && PivotDistance != null)
            {
                MyTransparentGeometry.StartParticleProfilingBlock("Pivot calculation");

                Vector3 rotation;
                float   distance;
                PivotRotation.GetInterpolatedValue <Vector3>(m_normalizedTime, out rotation);
                PivotDistance.GetInterpolatedValue <float>(m_normalizedTime, out distance);
                Quaternion rotationQ = Quaternion.CreateFromYawPitchRoll(MathHelper.ToRadians(rotation.Y), MathHelper.ToRadians(rotation.X), MathHelper.ToRadians(rotation.Z));
                m_actualPivot = Vector3.Transform(Vector3.Forward, rotationQ) * distance;

                MyTransparentGeometry.EndParticleProfilingBlock();
            }

            if (Acceleration != null)
            {
                MyTransparentGeometry.StartParticleProfilingBlock("Acceleration calculation");

                Acceleration.GetInterpolatedValue <Vector3>(m_normalizedTime, out m_actualAcceleration);
                Velocity += m_actualAcceleration * VRage.Game.MyEngineConstants.UPDATE_STEP_SIZE_IN_SECONDS;

                MyTransparentGeometry.EndParticleProfilingBlock();
            }

            m_actualAngle += RotationSpeed * VRage.Game.MyEngineConstants.UPDATE_STEP_SIZE_IN_SECONDS;

            MyUtils.AssertIsValid(m_actualPosition);
            MyUtils.AssertIsValid(m_actualAngle);

            return(true);
        }
Пример #2
0
        public bool Update()
        {
            m_elapsedTime += VRage.Game.MyEngineConstants.UPDATE_STEP_SIZE_IN_SECONDS;

            if (m_elapsedTime >= Life)
            {
                return(false);
            }

            m_normalizedTime += m_elapsedTimeDivider;

            m_velocity += m_generation.GetEffect().Gravity *m_generation.Gravity *VRage.Game.MyEngineConstants.UPDATE_STEP_SIZE_IN_SECONDS;

            m_previousPosition  = m_actualPosition;
            m_actualPosition.X += Velocity.X * VRage.Game.MyEngineConstants.UPDATE_STEP_SIZE_IN_SECONDS;
            m_actualPosition.Y += Velocity.Y * VRage.Game.MyEngineConstants.UPDATE_STEP_SIZE_IN_SECONDS;
            m_actualPosition.Z += Velocity.Z * VRage.Game.MyEngineConstants.UPDATE_STEP_SIZE_IN_SECONDS;

            if (Pivot != null)
            {
                MyTransparentGeometry.StartParticleProfilingBlock("Pivot calculation");

                Pivot.GetInterpolatedValue <Vector3>(m_normalizedTime, out m_actualPivot);

                MyTransparentGeometry.EndParticleProfilingBlock();
            }

            if (Acceleration != null)
            {
                MyTransparentGeometry.StartParticleProfilingBlock("Acceleration calculation");

                Acceleration.GetInterpolatedValue <Vector3>(m_normalizedTime, out m_actualAcceleration);

                Matrix transform = Matrix.Identity;

                if (m_generation.AccelerationReference == MyAccelerationReference.Camera)
                {
                    transform = MyTransparentGeometry.Camera;
                }
                else if (m_generation.AccelerationReference == MyAccelerationReference.Local)
                {
                }
                else if ((m_generation.AccelerationReference == MyAccelerationReference.Velocity))
                {
                    Vector3 actualVelocity = (Vector3)(m_actualPosition - m_previousPosition);

                    if (actualVelocity.LengthSquared() < 0.00001f)
                    {
                        m_actualAcceleration = Vector3.Zero;
                    }
                    else
                    {
                        transform = Matrix.CreateFromDir(Vector3.Normalize(actualVelocity));
                    }
                }
                else if ((m_generation.AccelerationReference == MyAccelerationReference.Gravity))
                {
                    if (m_generation.GetEffect().Gravity.LengthSquared() < 0.00001f)
                    {
                        m_actualAcceleration = Vector3.Zero;
                    }
                    else
                    {
                        transform = Matrix.CreateFromDir(Vector3.Normalize(m_generation.GetEffect().Gravity));
                    }
                }
                else
                {
                    System.Diagnostics.Debug.Fail("Unknown RotationReference enum");
                }

                m_actualAcceleration = Vector3.TransformNormal(m_actualAcceleration, transform);

                Velocity += m_actualAcceleration * VRage.Game.MyEngineConstants.UPDATE_STEP_SIZE_IN_SECONDS;

                MyTransparentGeometry.EndParticleProfilingBlock();
            }

            if (RotationSpeed != null)
            {
                Vector3 rotationSpeed;
                RotationSpeed.GetInterpolatedValue <Vector3>(m_normalizedTime, out rotationSpeed);
                m_actualAngle += new Vector3(MathHelper.ToRadians(rotationSpeed.X), MathHelper.ToRadians(rotationSpeed.Y), MathHelper.ToRadians(rotationSpeed.Z)) * VRage.Game.MyEngineConstants.UPDATE_STEP_SIZE_IN_SECONDS;
            }

            if (PivotRotation != null)
            {
                Vector3 pivotRotation;
                PivotRotation.GetInterpolatedValue <Vector3>(m_normalizedTime, out pivotRotation);
                m_actualPivotRotation += pivotRotation;
            }

            if (ArrayIndex != null)
            {
                ArrayIndex.GetInterpolatedValue <int>(m_normalizedTime, out m_arrayIndex);
            }

            MyUtils.AssertIsValid(m_actualPosition);
            MyUtils.AssertIsValid(m_actualAngle);

            return(true);
        }