Ejemplo n.º 1
0
        public void CalculateStartPosition(float elapsedTime, Matrix worldMatrix, float userScale, out Vector3 startOffset, out Vector3 startPosition)
        {
            Vector3 currentOffsetUntransformed;

            Offset.GetInterpolatedValue <Vector3>(elapsedTime, out currentOffsetUntransformed);

            float currentSize;

            Size.GetInterpolatedValue <float>(elapsedTime, out currentSize);
            currentSize *= MyMwcUtils.GetRandomFloat(RadiusMin, RadiusMax) * userScale;

            Vector3 localPos = Vector3.Zero;
            Vector3 worldOffset;

            Vector3.Transform(ref currentOffsetUntransformed, ref worldMatrix, out worldOffset);

            switch (Type)
            {
            case MyParticleEmitterType.Point:
                localPos = Vector3.Zero;
                break;

            case MyParticleEmitterType.Line:
                localPos = Vector3.Forward * MyMwcUtils.GetRandomFloat(0.0f, currentSize);
                break;

            case MyParticleEmitterType.Sphere:
                localPos = MyMwcUtils.GetRandomVector3Normalized() * currentSize;
                break;

            case MyParticleEmitterType.Box:
                float currentSizeHalf = currentSize * 0.5f;
                localPos =
                    new Vector3(
                        MinerWars.CommonLIB.AppCode.Utils.MyMwcUtils.GetRandomFloat(-currentSizeHalf, currentSizeHalf),
                        MinerWars.CommonLIB.AppCode.Utils.MyMwcUtils.GetRandomFloat(-currentSizeHalf, currentSizeHalf),
                        MinerWars.CommonLIB.AppCode.Utils.MyMwcUtils.GetRandomFloat(-currentSizeHalf, currentSizeHalf)
                        );
                break;

            case MyParticleEmitterType.Hemisphere:
                localPos = MyMwcUtils.GetRandomVector3HemisphereNormalized(Vector3.Forward) * currentSize;
                break;

            case MyParticleEmitterType.Circle:
                localPos = MyMwcUtils.GetRandomVector3CircleNormalized() * currentSize;
                break;

            default:
                System.Diagnostics.Debug.Assert(false);
                break;
            }

            Vector3 worldPos;

            if (DirToCamera)
            {
                Matrix WorldView = worldMatrix * MyCamera.ViewMatrix;
                WorldView.Translation += currentOffsetUntransformed;
                Matrix newWorld = WorldView * Matrix.Invert(MyCamera.ViewMatrix);

                Vector3 dir = MyCamera.Position - newWorld.Translation;
                dir.Normalize();

                Matrix matrix = MyMath.MatrixFromDir(dir);
                matrix.Translation = newWorld.Translation;

                Vector3.Transform(ref localPos, ref matrix, out worldPos);

                startOffset   = newWorld.Translation;
                startPosition = worldPos;
            }
            else
            {
                Vector3.TransformNormal(ref localPos, ref worldMatrix, out worldPos);

                startOffset   = worldOffset;
                startPosition = worldOffset + worldPos;
            }
        }