Ejemplo n.º 1
0
 public Cv_TransformComponent()
 {
     m_OldTransform = Cv_Transform.Identity;
     Transform      = Cv_Transform.Identity;
     Scale          = Vector2.One;
     Origin         = new Vector2(0.5f, 0.5f);
 }
Ejemplo n.º 2
0
        private void RecreateScaleMatrix()
        {
            Cv_Transform newScale = new Cv_Transform(Vector3.Zero, new Vector2((float)Scale, (float)Scale), 0);

            m_ScaleTransform  = newScale;
            m_bDirtyTransform = false;
        }
Ejemplo n.º 3
0
        private void GenerateParticles(float elapsedTime, Cv_Transform worldTransform)
        {
            var particleComponent = (Cv_ParticleEmitterComponent)Component;
            var numParticles      = GetNumParticlesToGenerate(elapsedTime);

            while (numParticles > 0 && m_iNumLiveParticles < MAX_PARTICLES && m_iNumLiveParticles < particleComponent.MaxParticles)
            {
                m_iNumLiveParticles++;
                numParticles--;

                var particle = m_Particles.Last.Value;
                m_Particles.RemoveLast();

                particle.TTL = particleComponent.ParticleLifeTime;

                var variation_x = m_Random.Next((int)-particleComponent.EmitterVariation.X, (int)particleComponent.EmitterVariation.X);
                var variation_y = m_Random.Next((int)-particleComponent.EmitterVariation.Y, (int)particleComponent.EmitterVariation.Y);
                particle.Velocity = (particleComponent.EmitterVelocity + new Vector2(variation_x, variation_y)) * worldTransform.Scale;

                Matrix rot = Matrix.CreateRotationZ(worldTransform.Rotation);
                particle.Velocity = Vector2.Transform(particle.Velocity, rot);

                particle.IsAlive = true;

                float pos_x;
                if (worldTransform.Scale.X >= 0)
                {
                    pos_x = worldTransform.Position.X + m_Random.Next(0, (int)(particleComponent.Width * worldTransform.Scale.X));
                }
                else
                {
                    pos_x = worldTransform.Position.X + m_Random.Next((int)(particleComponent.Width * worldTransform.Scale.X), 0);
                }

                float pos_y;

                if (worldTransform.Scale.Y >= 0)
                {
                    pos_y = worldTransform.Position.Y + m_Random.Next(0, (int)(particleComponent.Height * worldTransform.Scale.Y));
                }
                else
                {
                    pos_y = worldTransform.Position.Y + m_Random.Next((int)(particleComponent.Height * worldTransform.Scale.Y), 0);
                }

                pos_x -= (int)(particleComponent.Width * worldTransform.Scale.X * worldTransform.Origin.X);
                pos_y -= (int)(particleComponent.Height * worldTransform.Scale.Y * worldTransform.Origin.Y);

                var rotation = particleComponent.InitialRotation + worldTransform.Rotation;
                var scale    = particleComponent.InitialScale * worldTransform.Scale;

                particle.Transform       = new Cv_Transform(new Vector3(pos_x, pos_y, Parent.Position.Z), scale, rotation);
                particle.InitialScale    = worldTransform.Scale;
                particle.InitialRotation = worldTransform.Rotation;
                m_Particles.AddFirst(particle);
            }
        }
Ejemplo n.º 4
0
        internal Cv_Transform GetViewTransform(int virtualWidth, int virtualHeight, Cv_Transform rendererTransform)
        {
            if (Component.Owner == null)
            {
                return(Cv_Transform.Identity);
            }

            if (rendererTransform.Scale == Vector2.Zero)
            {
                return(Cv_Transform.Identity);
            }

            if ((virtualWidth > 0 && virtualWidth != m_iPreviousVirtualWidth) ||
                (virtualHeight > 0 && virtualHeight != m_iPreviousVirtualHeight))
            {
                IsViewTransformDirty = true;
            }

            if (WorldTransformChanged || ((Cv_CameraComponent)Component).ZoomChanged)
            {
                IsViewTransformDirty = true;
            }

            if (IsViewTransformDirty)
            {
                var zoom                = ((Cv_CameraComponent)Component).Zoom;
                var worldTransform      = WorldTransform;
                var transform           = Parent.Transform;
                var parentOrigin        = Component.Owner.GetComponent <Cv_TransformComponent>().Origin;
                var parentWorldTranform = Cv_Transform.Identity;

                if (Parent.Parent != null)
                {
                    parentWorldTranform = Parent.Parent.WorldTransform;
                }

                var resTrans = new Vector3(virtualWidth * parentOrigin.X / zoom, virtualHeight * parentOrigin.Y / zoom, 0);
                m_ResTranslationTransform = new Cv_Transform(resTrans, m_ResTranslationTransform.Scale, m_ResTranslationTransform.Rotation, m_ResTranslationTransform.Origin);
                var camScale    = Matrix.CreateScale(zoom, zoom, 1);
                var camRot      = Matrix.CreateRotationZ(-worldTransform.Rotation);
                var camTrans    = Matrix.CreateTranslation(-transform.Position);
                var parentTrans = Matrix.CreateTranslation(-parentWorldTranform.Position / new Vector3(rendererTransform.Scale, 1));

                m_Transform = Cv_Transform.FromMatrix(camScale *
                                                      parentTrans *
                                                      rendererTransform.TransformMatrix *
                                                      camRot *
                                                      camTrans *
                                                      m_ResTranslationTransform.TransformMatrix, m_Transform.Origin);
            }

            m_iPreviousVirtualWidth  = virtualWidth;
            m_iPreviousVirtualHeight = virtualHeight;


            return(m_Transform);
        }
Ejemplo n.º 5
0
        public void PushAndSetTransform(Cv_Transform toWorld)
        {
            Cv_Transform currTransform = Cv_Transform.Identity;

            if (m_TransformStack.Count > 0)
            {
                currTransform = m_TransformStack[m_TransformStack.Count - 1];
            }

            m_TransformStack.Add(Cv_Transform.Multiply(currTransform, toWorld));
        }
Ejemplo n.º 6
0
        public void SetOrigin(Vector2 value, object caller = null)
        {
            if (!Owner)
            {
                return;
            }

            m_OldTransform = Transform;
            Origin         = value;
            var newEvent = new Cv_Event_TransformEntity(Owner.ID, m_OldTransform, Transform.Position, Transform.Scale, value, Transform.Rotation, (caller != null ? caller : this));

            Cv_EventManager.Instance.TriggerEvent(newEvent);
        }
Ejemplo n.º 7
0
        public void ApplyRotation(float rotation, object caller = null)
        {
            if (!Owner)
            {
                return;
            }

            m_OldTransform = Transform;
            Rotation      += rotation;
            var newEvent = new Cv_Event_TransformEntity(Owner.ID, m_OldTransform, Transform.Position, Transform.Scale, Transform.Origin, Rotation, (caller != null ? caller : this));

            Cv_EventManager.Instance.TriggerEvent(newEvent);
        }
Ejemplo n.º 8
0
        public void ApplyScale(Vector2 scale, object caller = null)
        {
            if (!Owner)
            {
                return;
            }

            m_OldTransform = Transform;
            Scale          = Scale * scale;
            var newEvent = new Cv_Event_TransformEntity(Owner.ID, m_OldTransform, Transform.Position, Scale, Transform.Origin, Transform.Rotation, (caller != null ? caller : this));

            Cv_EventManager.Instance.TriggerEvent(newEvent);
        }
Ejemplo n.º 9
0
        public void ApplyVelocity(Vector2 velocity, object caller = null)
        {
            if (!Owner)
            {
                return;
            }

            m_OldTransform = Transform;
            Position       = Position + new Vector3(velocity, 0);
            var newEvent = new Cv_Event_TransformEntity(Owner.ID, m_OldTransform, Position, Transform.Scale, Transform.Origin, Transform.Rotation, (caller != null ? caller : this));

            Cv_EventManager.Instance.TriggerEvent(newEvent);
        }
Ejemplo n.º 10
0
        public Cv_Event_TransformEntity(Cv_EntityID entityID, Cv_Transform oldTransform, Vector3 newPos,
                                        Vector2 newScale, Vector2 newOrigin, float newRotation, object sender) : base(entityID, sender)
        {
            NewPosition = newPos;
            NewScale    = newScale;
            NewRotation = newRotation;
            NewOrigin   = newOrigin;

            OldPosition = oldTransform.Position;
            OldScale    = oldTransform.Scale;
            OldRotation = oldTransform.Rotation;
            OldOrigin   = oldTransform.Origin;
        }
        private void GetInitialTransformAndAlpha()
        {
            m_InitialTransform      = m_TransformComponent.Transform;
            m_iInitialSpriteAlpha   = 255;
            m_iInitialTextAlpha     = 255;
            m_iInitialParticleAlpha = 255;

            if (m_SpriteComponent != null)
            {
                m_iInitialSpriteAlpha = m_SpriteComponent.Color.A;
            }

            if (m_TextComponent != null)
            {
                m_iInitialTextAlpha = m_TextComponent.Color.A;
            }

            if (m_ParticleEmitterComponent != null)
            {
                m_iInitialParticleAlpha = m_ParticleEmitterComponent.Color.A;
            }
        }
Ejemplo n.º 12
0
        internal Cv_SceneNode(Cv_EntityID entityID, Cv_EntityComponent renderComponent, Cv_Transform to, Cv_Transform?from = null)
        {
            Properties           = new Cv_NodeProperties();
            Properties.EntityID  = entityID;
            Properties.ToWorld   = to;
            Properties.FromWorld = (from != null ? from.Value : Cv_Transform.Identity);
            Properties.Name      = renderComponent != null?renderComponent.GetType().Name : "SceneNode";

            Properties.Radius = -1;
            TransformChanged  = true;
            Component         = renderComponent;
            Children          = new List <Cv_SceneNode>();
        }
Ejemplo n.º 13
0
        public override bool VInitialize(XmlElement componentData)
        {
            Cv_Debug.Assert(componentData != null, "Must have valid component data.");

            m_OldTransform = Transform;

            var positionNode = componentData.SelectNodes("Position").Item(0);

            if (positionNode != null)
            {
                float x, y, z;

                x = int.Parse(positionNode.Attributes["x"].Value);
                y = int.Parse(positionNode.Attributes["y"].Value);
                z = int.Parse(positionNode.Attributes["z"].Value);

                var position = new Vector3(x, y, z);
                Position = position;
            }

            var rotationNode = componentData.SelectNodes("Rotation").Item(0);

            if (rotationNode != null)
            {
                float rad;

                rad = float.Parse(rotationNode.Attributes["radians"].Value, CultureInfo.InvariantCulture);

                var rotation = rad;
                Rotation = rotation;
            }

            var scaleNode = componentData.SelectNodes("Scale").Item(0);

            if (scaleNode != null)
            {
                float x, y;

                x = float.Parse(scaleNode.Attributes["x"].Value, CultureInfo.InvariantCulture);
                y = float.Parse(scaleNode.Attributes["y"].Value, CultureInfo.InvariantCulture);

                var scale = new Vector2(x, y);
                Scale = scale;
            }

            var originNode = componentData.SelectNodes("Origin").Item(0);

            if (originNode != null)
            {
                float x, y;

                x = (float)double.Parse(originNode.Attributes["x"].Value, CultureInfo.InvariantCulture);
                y = (float)double.Parse(originNode.Attributes["y"].Value, CultureInfo.InvariantCulture);

                x = Math.Max(0, Math.Min(1, x));
                y = Math.Max(0, Math.Min(1, y));
                var origin = new Vector2(x, y);
                Origin = origin;
            }

            return(true);
        }
Ejemplo n.º 14
0
        public Cv_ParticleEmitterNode(Cv_Entity.Cv_EntityID entityID, Cv_EntityComponent renderComponent, Cv_Transform to, Cv_Transform?from = null) : base(entityID, renderComponent, to, from)
        {
            m_Particles = new LinkedList <Cv_Particle>();

            var particleComponent = (Cv_ParticleEmitterComponent)Component;

            for (var i = 0; i < MAX_PARTICLES; i++)
            {
                m_Particles.AddFirst(new Cv_Particle());
            }

            m_iNumLiveParticles = 0;

            m_Random = new Random();
        }
Ejemplo n.º 15
0
 public Cv_SpriteNode(Cv_EntityID entityID, Cv_RenderComponent renderComponent, Cv_Transform to, Cv_Transform?from = null) : base(entityID, renderComponent, to, from)
 {
 }