コード例 #1
0
        public void DebugDraw(float elapsedTime, Matrix worldMatrix)
        {
            Vector3 currentOffsetUntransformed, currentOffset;

            Offset.GetInterpolatedValue <Vector3>(elapsedTime, out currentOffsetUntransformed);
            Vector3.Transform(ref currentOffsetUntransformed, ref worldMatrix, out currentOffset);
            float currentSize;

            Size.GetInterpolatedValue <float>(elapsedTime, out currentSize);

            switch (Type)
            {
            case MyParticleEmitterType.Point:
            {
                MyDebugDraw.DrawSphereWireframe(currentOffset, 0.1f, new Vector3(1, 1, 0), 1.0f);
            }
            break;

            case MyParticleEmitterType.Line:
            {
                if (DirToCamera)
                {
                    Vector3 dir = MyCamera.Position - currentOffset;
                    dir.Normalize();
                    Matrix  matrix = Matrix.CreateScale(currentSize) * MyMath.MatrixFromDir(dir);
                    Vector3 currentOffsetScaled = Vector3.TransformNormal(Vector3.Forward, matrix);
                    MyDebugDraw.DrawLine3D(worldMatrix.Translation, worldMatrix.Translation + currentOffsetScaled, Color.Yellow, Color.Yellow);
                }
                else
                {
                    Vector3 currentOffsetScaled = Vector3.Transform(Vector3.Up * currentSize, worldMatrix);
                    MyDebugDraw.DrawLine3D(worldMatrix.Translation, currentOffsetScaled, Color.Yellow, Color.Yellow);
                }
            }
            break;

            case MyParticleEmitterType.Sphere:
            {
                MyDebugDraw.DrawSphereWireframe(currentOffset, currentSize, new Vector3(1, 1, 0), 1.0f);
            }
            break;

            case MyParticleEmitterType.Box:
            {
                Matrix matrix = Matrix.CreateScale(currentSize) * Matrix.CreateTranslation(currentOffsetUntransformed) * worldMatrix;
                MyDebugDraw.DrawLowresBoxWireframe(matrix, new Vector3(1, 1, 0), 1.0f);
            }
            break;

            case MyParticleEmitterType.Hemisphere:
            {
                Vector3 worldPos = currentOffset;

                Matrix matrix;

                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.CreateScale(currentSize) * Matrix.CreateRotationX(MathHelper.PiOver2) * MyMath.MatrixFromDir(dir);
                    matrix.Translation = newWorld.Translation;
                }
                else
                {
                    matrix = Matrix.CreateScale(currentSize) * Matrix.CreateTranslation(currentOffsetUntransformed) * worldMatrix;
                }

                MyDebugDraw.DrawHemisphereWireframe(matrix, new Vector3(1, 1, 0), 1.0f);
            }
            break;

            case MyParticleEmitterType.Circle:
            {
                //No debug draw
            }
            break;

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