Exemplo n.º 1
0
        /// <summary>
        /// Tries to acquire and draw a debug shape for better feedback and visualization.
        /// </summary>
        /// <param name="debugDrawShape">The type of the debug shape (sphere, cone, etc.)</param>
        /// <param name="translation">The shape's translation</param>
        /// <param name="rotation">The shape's rotation</param>
        /// <param name="scale">The shape's non-uniform scaling</param>
        /// <returns><c>true</c> if debug shape can be displayed</returns>
        public bool TryGetDebugDrawShape(ref DebugDrawShape debugDrawShape, ref Vector3 translation, ref Quaternion rotation, ref Vector3 scale)
        {
            foreach (var particleEmitter in Emitters)
            {
                if (!particleEmitter.Enabled)
                {
                    continue;
                }

                foreach (var initializer in particleEmitter.Initializers)
                {
                    if (!initializer.Enabled)
                    {
                        continue;
                    }

                    if (initializer.TryGetDebugDrawShape(out debugDrawShape, out translation, out rotation, out scale))
                    {
                        // Convert to world space if local
                        if (particleEmitter.SimulationSpace == EmitterSimulationSpace.Local)
                        {
                            return(ToWorldSpace(ref translation, ref rotation, ref scale));
                        }

                        return(true);
                    }
                }

                foreach (var updater in particleEmitter.Updaters)
                {
                    if (!updater.Enabled)
                    {
                        continue;
                    }

                    if (updater.TryGetDebugDrawShape(out debugDrawShape, out translation, out rotation, out scale))
                    {
                        // Convert to world space if local
                        if (particleEmitter.SimulationSpace == EmitterSimulationSpace.Local)
                        {
                            return(ToWorldSpace(ref translation, ref rotation, ref scale));
                        }

                        return(true);
                    }
                }
            }

            if (BoundingShape == null)
            {
                return(false);
            }

            if (BoundingShape.TryGetDebugDrawShape(out debugDrawShape, out translation, out rotation, out scale))
            {
                return(ToWorldSpace(ref translation, ref rotation, ref scale));
            }

            return(false);
        }
Exemplo n.º 2
0
 /// <summary>
 /// Attepmts to get a debug shape (shape type and location matrix) for the current module in order to display its boundaries better
 /// </summary>
 /// <param name="debugDrawShape">Type of the debug draw shape</param>
 /// <param name="translation">Translation of the shape</param>
 /// <param name="rotation">Rotation of the shape</param>
 /// <param name="scale">Scaling of the shape</param>
 /// <returns></returns>
 public virtual bool TryGetDebugDrawShape(out DebugDrawShape debugDrawShape, out Vector3 translation, out Quaternion rotation, out Vector3 scale)
 {
     debugDrawShape = DebugDrawShape.None;
     scale          = new Vector3(1, 1, 1);
     translation    = new Vector3(0, 0, 0);
     rotation       = Quaternion.Identity;
     return(false);
 }
Exemplo n.º 3
0
 public override bool TryGetDebugDrawShape(out DebugDrawShape debugDrawShape, out Vector3 translation, out Quaternion rotation, out Vector3 scale)
 {
     debugDrawShape = DebugDrawShape.Cube;
     scale          = (Maximum - Minimum);
     translation    = (Maximum + Minimum) * 0.5f;
     rotation       = new Quaternion(0, 0, 0, 1);
     return(true);
 }
Exemplo n.º 4
0
 /// <summary>
 /// Attepmts to get a debug shape (shape type and location matrix) for the current module in order to display its boundaries better
 /// </summary>
 /// <param name="debugDrawShape">Type of the debug draw shape</param>
 /// <param name="translation">Translation of the shape</param>
 /// <param name="rotation">Rotation of the shape</param>
 /// <param name="scale">Scaling of the shape</param>
 /// <returns></returns>
 public virtual bool TryGetDebugDrawShape(out DebugDrawShape debugDrawShape, out Vector3 translation, out Quaternion rotation, out Vector3 scale)
 {
     debugDrawShape = DebugDrawShape.None;
     scale = new Vector3(1, 1, 1);
     translation = new Vector3(0, 0, 0);
     rotation = Quaternion.Identity;
     return false;
 }
 public override bool TryGetDebugDrawShape(out DebugDrawShape debugDrawShape, out Vector3 translation, out Quaternion rotation, out Vector3 scale)
 {
     debugDrawShape = DebugDrawShape.Cube;
     scale          = new Vector3(Radius, Radius, Radius);
     translation    = new Vector3(0, 0, 0);
     rotation       = new Quaternion(0, 0, 0, 1);
     return(true);
 }
Exemplo n.º 6
0
 /// <summary>
 /// Attepmts to get a debug shape (shape type and location matrix) for the current module in order to display its boundaries better
 /// </summary>
 /// <param name="debugDrawShape">Type of the debug draw shape</param>
 /// <param name="translation">Translation of the shape</param>
 /// <param name="rotation">Rotation of the shape</param>
 /// <param name="scale">Scaling of the shape</param>
 /// <returns></returns>
 public virtual bool TryGetDebugDrawShape(out DebugDrawShape debugDrawShape, out Vector3 translation, out Quaternion rotation, out Vector3 scale)
 {
     debugDrawShape = DebugDrawShape.None;
     scale          = Vector3.One;
     translation    = Vector3.Zero;
     rotation       = Quaternion.Identity;
     return(false);
 }
        public override bool TryGetDebugDrawShape(out DebugDrawShape debugDrawShape, out Vector3 translation, out Quaternion rotation, out Vector3 scale)
        {
            if (!DebugDraw)
                return base.TryGetDebugDrawShape(out debugDrawShape, out translation, out rotation, out scale);

            debugDrawShape = DebugDrawShape.Cube;
            scale = new Vector3(Radius, Radius, Radius);
            translation = new Vector3(0, 0, 0);
            rotation = Quaternion.Identity;
            return true;
        }
        public override bool TryGetDebugDrawShape(out DebugDrawShape debugDrawShape, out Vector3 translation, out Quaternion rotation, out Vector3 scale)
        {
            if (!DebugDraw)
                return base.TryGetDebugDrawShape(out debugDrawShape, out translation, out rotation, out scale);

            debugDrawShape = DebugDrawShape.Cube;
            scale = (Maximum - Minimum);
            translation = (Maximum + Minimum) * 0.5f;
            rotation = Quaternion.Identity;
            return true;
        }
Exemplo n.º 9
0
        public override bool TryGetDebugDrawShape(out DebugDrawShape debugDrawShape, out Vector3 translation, out Quaternion rotation, out Vector3 scale)
        {
            if (!DebugDraw)
            {
                return(base.TryGetDebugDrawShape(out debugDrawShape, out translation, out rotation, out scale));
            }

            debugDrawShape = DebugDrawShape.Cube;
            scale          = new Vector3(Radius, Radius, Radius);
            translation    = Vector3.Zero;
            rotation       = Quaternion.Identity;
            return(true);
        }
Exemplo n.º 10
0
        public override bool TryGetDebugDrawShape(out DebugDrawShape debugDrawShape, out Vector3 translation, out Quaternion rotation, out Vector3 scale)
        {
            if (!DebugDraw)
            {
                return(base.TryGetDebugDrawShape(out debugDrawShape, out translation, out rotation, out scale));
            }

            debugDrawShape = DebugDrawShape.Cube;
            scale          = (Maximum - Minimum);
            translation    = (Maximum + Minimum) * 0.5f;
            rotation       = Quaternion.Identity;
            return(true);
        }
Exemplo n.º 11
0
        public override bool TryGetDebugDrawShape(out DebugDrawShape debugDrawShape, out Vector3 translation, out Quaternion rotation, out Vector3 scale)
        {
            debugDrawShape = DebugDrawShape.Cube;

            rotation = WorldRotation;

            scale       = (VelocityMax - VelocityMin);
            translation = (VelocityMax + VelocityMin) * 0.5f * WorldScale;

            scale *= WorldScale;
            rotation.Rotate(ref translation);
            translation += WorldPosition;

            return(true);
        }
Exemplo n.º 12
0
        public override void Update()
        {
            // Update the locator & shape based on which element from the ParticleSystem is currently selected
            //var pos = Component.ParticleSystem.Translation;
            //var scl = Component.ParticleSystem.UniformScale;
            //var rot = Component.ParticleSystem.Rotation;

            // Update some edit-time settings on the particle system
            {
                var deltaTime = (float)Game.UpdateTime.Elapsed.TotalSeconds;

                var speed = Component.Speed;
                var particleSystemControl = Component.Control;
                particleSystemControl.Update(deltaTime * speed, Component.ParticleSystem);
            }

            if (!IsSelected || !IsEnabled)
            {
                shapeRenderer.SetDebugShape(DebugShapeType.None, ParticlesShapesGroup);

                base.Update();
                return;
            }

            var            pos       = Vector3.Zero;
            var            rot       = Quaternion.Identity;
            var            scl       = Vector3.One;
            DebugDrawShape drawShape = DebugDrawShape.None;

            if (Component.ParticleSystem.TryGetDebugDrawShape(ref drawShape, ref pos, ref rot, ref scl))
            {
                // TODO Invert cones

                shapeRenderer.SetDebugShape((DebugShapeType)drawShape, ParticlesShapesGroup);
                shapeRenderer.SetTransform(pos, rot, scl);

                base.Update();
                return;
            }

            // Last - if nothing else is selected, don't display anything
            shapeRenderer.SetDebugShape(DebugShapeType.None, ParticlesShapesGroup);

            base.Update();
        }
Exemplo n.º 13
0
        public override bool TryGetDebugDrawShape(out DebugDrawShape debugDrawShape, out Vector3 translation, out Quaternion rotation, out Vector3 scale)
        {
            rotation    = new Quaternion(0, 0, 0, 1);
            scale       = new Vector3(1, 1, 1);
            translation = new Vector3(0, 0, 0);

            debugDrawShape = FieldShape?.GetDebugDrawShape(out translation, out rotation, out scale) ?? DebugDrawShape.None;

            rotation *= WorldRotation;

            scale *= WorldScale;

            translation *= WorldScale;
            rotation.Rotate(ref translation);
            translation += WorldPosition;

            return(true);
        }
Exemplo n.º 14
0
        /// <inheritdoc />
        public override bool TryGetDebugDrawShape(out DebugDrawShape debugDrawShape, out Vector3 translation, out Quaternion rotation, out Vector3 scale)
        {
            if (!DebugDraw)
            {
                return(base.TryGetDebugDrawShape(out debugDrawShape, out translation, out rotation, out scale));
            }

            debugDrawShape = DebugDrawShape.Cube;

            rotation = WorldRotation;

            scale       = (PositionMax - PositionMin);
            translation = (PositionMax + PositionMin) * 0.5f * WorldScale;

            scale *= WorldScale;
            rotation.Rotate(ref translation);
            translation += WorldPosition;

            return(true);
        }
Exemplo n.º 15
0
        /// <inheritdoc />
        public override bool TryGetDebugDrawShape(out DebugDrawShape debugDrawShape, out Vector3 translation, out Quaternion rotation, out Vector3 scale)
        {
            if (!DebugDraw)
            {
                return(base.TryGetDebugDrawShape(out debugDrawShape, out translation, out rotation, out scale));
            }

            rotation    = Quaternion.Identity;
            scale       = Vector3.One;
            translation = Vector3.Zero;

            debugDrawShape = FieldShape?.GetDebugDrawShape(out translation, out rotation, out scale) ?? DebugDrawShape.None;

            rotation *= WorldRotation;

            scale *= WorldScale;

            translation *= WorldScale;
            rotation.Rotate(ref translation);
            translation += WorldPosition;

            return(true);
        }
Exemplo n.º 16
0
        public override bool TryGetDebugDrawShape(out DebugDrawShape debugDrawShape, out Vector3 translation, out Quaternion rotation, out Vector3 scale)
        {
            if (!DebugDraw)
            {
                return(base.TryGetDebugDrawShape(out debugDrawShape, out translation, out rotation, out scale));
            }

            debugDrawShape = DebugDrawShape.Cone;

            rotation = WorldRotation;

            scale       = new Vector3(1, -1, 1);
            translation = new Vector3(0, Strength + 1, 0);

            var radiusToStrength = (float)Math.Tan((Angle * Math.PI / 180f)) * (Strength + 1);
            var coneScale        = new Vector3(radiusToStrength, Strength + 1, radiusToStrength);

            scale *= WorldScale * coneScale;
            rotation.Rotate(ref translation);
            translation += WorldPosition;

            return(true);
        }
Exemplo n.º 17
0
        /// <summary>
        /// Tries to acquire and draw a debug shape for better feedback and visualization.
        /// </summary>
        /// <param name="debugDrawShape">The type of the debug shape (sphere, cone, etc.)</param>
        /// <param name="translation">The shape's translation</param>
        /// <param name="rotation">The shape's rotation</param>
        /// <param name="scale">The shape's non-uniform scaling</param>
        /// <returns><c>true</c> if debug shape can be displayed</returns>
        public bool TryGetDebugDrawShape(ref DebugDrawShape debugDrawShape, ref Vector3 translation, ref Quaternion rotation, ref Vector3 scale)
        {
            foreach (var particleEmitter in Emitters)
            {
                foreach (var initializer in particleEmitter.Initializers)
                {
                    if (initializer.TryGetDebugDrawShape(out debugDrawShape, out translation, out rotation, out scale))
                    {
                        // Convert to world space if local
                        if (particleEmitter.SimulationSpace == EmitterSimulationSpace.Local)
                            return ToWorldSpace(ref translation, ref rotation, ref scale);

                        return true;
                    }
                }

                foreach (var updater in particleEmitter.Updaters)
                {
                    if (updater.TryGetDebugDrawShape(out debugDrawShape, out translation, out rotation, out scale))
                    {
                        // Convert to world space if local
                        if (particleEmitter.SimulationSpace == EmitterSimulationSpace.Local)
                            return ToWorldSpace(ref translation, ref rotation, ref scale);

                        return true;
                    }
                }
            }

            if (BoundingShape == null)
                return false;

            if (BoundingShape.TryGetDebugDrawShape(out debugDrawShape, out translation, out rotation, out scale))
                return ToWorldSpace(ref translation, ref rotation, ref scale);

            return false;
        }
Exemplo n.º 18
0
        /// <inheritdoc/>
        public override bool TryGetDebugDrawShape(out DebugDrawShape debugDrawShape, out Vector3 translation, out Quaternion rotation, out Vector3 scale)
        {
            if (!DebugDraw)
                return base.TryGetDebugDrawShape(out debugDrawShape, out translation, out rotation, out scale);

            rotation = Quaternion.Identity;
            scale = new Vector3(1, 1, 1);
            translation = new Vector3(0, 0, 0);

            debugDrawShape = FieldShape?.GetDebugDrawShape(out translation, out rotation, out scale) ?? DebugDrawShape.None;

            rotation *= WorldRotation;

            scale *= WorldScale;

            translation *= WorldScale;
            rotation.Rotate(ref translation);
            translation += WorldPosition;

            return true;
        }
        public override bool TryGetDebugDrawShape(out DebugDrawShape debugDrawShape, out Vector3 translation, out Quaternion rotation, out Vector3 scale)
        {
            if (!DebugDraw)
                return base.TryGetDebugDrawShape(out debugDrawShape, out translation, out rotation, out scale);

            debugDrawShape = DebugDrawShape.Cube;

            rotation = WorldRotation;

            scale = (DirectionMax - DirectionMin);
            translation = (DirectionMax + DirectionMin) * 0.5f * WorldScale;

            scale *= WorldScale;
            rotation.Rotate(ref translation);
            translation += WorldPosition;

            return true;
        }
        public override bool TryGetDebugDrawShape(out DebugDrawShape debugDrawShape, out Vector3 translation, out Quaternion rotation, out Vector3 scale)
        {
            if (!DebugDraw)
                return base.TryGetDebugDrawShape(out debugDrawShape, out translation, out rotation, out scale);

            debugDrawShape = DebugDrawShape.Cone;

            rotation = WorldRotation;

            scale = new Vector3(1, -1, 1);
            translation = new Vector3(0, Strength + 1, 0);

            var radiusToStrength = (float)Math.Tan((Angle * Math.PI / 180f)) * (Strength + 1);
            var coneScale = new Vector3(radiusToStrength, Strength + 1, radiusToStrength);

            scale *= WorldScale * coneScale;
            rotation.Rotate(ref translation);
            translation += WorldPosition;

            return true;
        }