示例#1
0
        //---------------------------------------------------------------------------

        public void PostTick(float deltaTime)
        {
            m_Time += deltaTime;

            TransformComponent transform = GetComponent <TransformComponent>();

            if (transform != null)
            {
                m_Center = CalculateCenter(transform.Location);

                Vector3 distance = Vector3.Zero;

                switch (m_CameraMode)
                {
                case ECameraMode.Split:
                case ECameraMode.Merged:
                    distance = m_Center - transform.Location;
                    transform.MoveBy(distance / 20.0f);
                    break;

                case ECameraMode.Fused:
                    if (m_Other != null)
                    {
                        Vector3 fusedCenter = Vector3.Zero;
                        if (m_Other.GetCenter().X < GetCenter().X)
                        {
                            fusedCenter = (m_Center + m_Other.GetCenter()) / 2.0f + new Vector3(m_MainTarget.Width / 2, 0, 0);
                        }
                        else
                        {
                            fusedCenter = (m_Center + m_Other.GetCenter()) / 2.0f - new Vector3(m_MainTarget.Width / 2, 0, 0);
                        }
                        distance = fusedCenter - transform.Location;

                        if (distance.Length() > 0.0f)
                        {
                            Vector3 speed = (distance / 10.0f).Length() < 2.0f ? Vector3.Normalize(distance) * 2 : distance / 10.0f;
                            if (speed.Length() > distance.Length())
                            {
                                transform.MoveBy(distance);
                            }
                            else
                            {
                                transform.MoveBy(speed);
                            }
                        }
                    }
                    break;
                }
            }
        }
示例#2
0
        //---------------------------------------------------------------------------

        private void TickForce(float deltaTime)
        {
            TransformComponent transform       = GetComponent <TransformComponent>();
            TransformComponent parentTransform = GetComponentInParent <TransformComponent>();

            if (transform != null)
            {
                if (IsGravityAffected)
                {
                    ApplyGravity(deltaTime);
                }

                if (m_Force.Length() < 1.0f)
                {
                    m_RestingTimer += deltaTime;
                    if (m_RestingTimer >= 0.3f)
                    {
                        IsResting = true;
                    }
                }
                else
                {
                    m_RestingTimer = 0.0f;
                    IsResting      = false;
                }

                if (Body != null && Body.BodyType != BodyType.Static)
                {
                    if (Body.Enabled)
                    {
                        Vector3 pos = new Vector3(Body.Position.X * Unit, Body.Position.Y * Unit, transform.Location.Z + m_Force.Z);
                        if (parentTransform != null)
                        {
                            pos -= parentTransform.AbsoluteLocation;
                        }
                        transform.MoveTo(pos);
                    }
                    else
                    {
                        transform.MoveBy(m_Force);
                    }
                }

                m_Force *= Inertia;
                if (UseAbsoluteMovement)
                {
                    Body.LinearVelocity = Vector2.Zero;
                }
            }
        }