예제 #1
0
        ////////////////////////////////////////////////////////////////////////////
        //--------------------------------- REVISIONS ------------------------------
        // Date       Name                 Tracking #         Description
        // ---------  -------------------  -------------      ----------------------
        // 13JUN2009  James Shen                              Initial Creation
        ////////////////////////////////////////////////////////////////////////////

        /**
         * Reset the rectangle.
         * @param ff_xmin
         * @param ff_ymin
         * @param ff_xmax
         * @param ff_ymax
         * @return
         */
        public RectangleFP Reset(int ffXmin, int ffYmin, int ffXmax, int ffYmax)
        {
            _ffXmin = MathFP.Min(ffXmin, ffXmax);
            _ffXmax = MathFP.Max(ffXmin, ffXmax);
            _ffYmin = MathFP.Min(ffYmin, ffYmax);
            _ffYmax = MathFP.Max(ffYmin, ffYmax);
            return(this);
        }
예제 #2
0
 public virtual RectangleFP Union(PointFP p)
 {
     if (!IsEmpty())
     {
         Reset(MathFP.Min(ff_xmin, p.X), MathFP.Max(ff_xmax, p.X), MathFP.Min(ff_ymin, p.Y), MathFP.Max(ff_ymax, p.Y));
     }
     return(this);
 }
예제 #3
0
 public virtual RectangleFP Reset(int ff_xmin, int ff_ymin, int ff_xmax, int ff_ymax)
 {
     this.ff_xmin = MathFP.Min(ff_xmin, ff_xmax);
     this.ff_xmax = MathFP.Max(ff_xmin, ff_xmax);
     this.ff_ymin = MathFP.Min(ff_ymin, ff_ymax);
     this.ff_ymax = MathFP.Max(ff_ymin, ff_ymax);
     return(this);
 }
예제 #4
0
        ////////////////////////////////////////////////////////////////////////////
        //--------------------------------- REVISIONS ------------------------------
        // Date       Name                 Tracking #         Description
        // ---------  -------------------  -------------      ----------------------
        // 13JUN2009  James Shen                              Initial Creation
        ////////////////////////////////////////////////////////////////////////////

        /**
         * return the union of the rectangle and the given point.
         * @param p
         * @return
         */
        public RectangleFP Union(PointFP p)
        {
            if (!IsEmpty())
            {
                Reset(MathFP.Min(_ffXmin, p.X), MathFP.Max(_ffXmax, p.X),
                      MathFP.Min(_ffYmin, p.Y), MathFP.Max(_ffYmax, p.Y));
            }
            return(this);
        }
예제 #5
0
 public virtual RectangleFP Union(RectangleFP r)
 {
     if (!r.IsEmpty())
     {
         if (IsEmpty())
         {
             Reset(r);
         }
         else
         {
             Reset(MathFP.Min(ff_xmin, r.ff_xmin), MathFP.Max(ff_xmax, r.ff_xmax), MathFP.Min(ff_ymin, r.ff_ymin), MathFP.Max(ff_ymax, r.ff_ymax));
         }
     }
     return(this);
 }
예제 #6
0
        ////////////////////////////////////////////////////////////////////////////
        //--------------------------------- REVISIONS ------------------------------
        // Date       Name                 Tracking #         Description
        // ---------  -------------------  -------------      ----------------------
        // 13JUN2009  James Shen                              Initial Creation
        ////////////////////////////////////////////////////////////////////////////

        /**
         * Calculate the union of the two rectangle.
         * @param r
         * @return
         */
        public RectangleFP Union(RectangleFP r)
        {
            if (!r.IsEmpty())
            {
                if (IsEmpty())
                {
                    Reset(r);
                }
                else
                {
                    Reset(MathFP.Min(_ffXmin, r._ffXmin),
                          MathFP.Max(_ffXmax, r._ffXmax),
                          MathFP.Min(_ffYmin, r._ffYmin),
                          MathFP.Max(_ffYmax, r._ffYmax));
                }
            }
            return(this);
        }
예제 #7
0
        public override void  LineTo(PointFP point)
        {
            //PointFP a = new PointFP(CurrentPoint);
            PointFP pntTemp = new PointFP(point);

            ff_xmin = MathFP.Min(ff_xmin, CurrentPoint.X);
            ff_xmax = MathFP.Max(ff_xmax, point.X);
            ff_ymin = MathFP.Min(ff_ymin, CurrentPoint.Y);
            ff_ymax = MathFP.Max(ff_ymax, point.Y);

            if (transformMatrix != null)
            {
                pntTemp.Transform(transformMatrix);
                //b.Transform(transformMatrix);
            }

            Scanline(transformedPoint.X, transformedPoint.Y, pntTemp.X, pntTemp.Y);
            transformedPoint = pntTemp;
            base.LineTo(point);
        }
예제 #8
0
        public GradientBrushFP(int ff_xmin, int ff_ymin, int ff_xmax, int ff_ymax, int ff_angle, int type)
        {
            bounds.Reset(ff_xmin, ff_ymin,
                         ff_xmax == ff_xmin ? ff_xmin + 1 : ff_xmax,
                         ff_ymax == ff_ymin ? ff_ymin + 1 : ff_ymax);
            matrix = new MatrixFP();
            matrix.Translate(-(ff_xmin + ff_xmax) / 2, -(ff_ymin + ff_ymax) / 2);
            matrix.Rotate(-ff_angle);
            this.type = type;
            if (type == RADIAL_GRADIENT)
            {
                matrix.Scale(MathFP.Div(SingleFP.One, bounds.Width), MathFP.Div(SingleFP.One, bounds.Height));
            }
            int ff_ang = MathFP.Atan(MathFP.Div(bounds.Height, bounds.Width == 0 ? 1 : bounds.Width));
            int ff_len = PointFP.Distance(bounds.Height, bounds.Width);

            ff_length = MathFP.Mul(ff_len, MathFP.Max(
                                       MathFP.Abs(MathFP.Cos(ff_angle - ff_ang)),
                                       MathFP.Abs(MathFP.Cos(ff_angle + ff_ang))));
        }
예제 #9
0
    public override void OnSyncedUpdate()
    {
        base.OnSyncedUpdate();

        if (!m_RunSyncedUpdate)
        {
            return;
        }

        // Get delta time.

        FP deltaTime = TrueSyncManager.deltaTimeMain;

        // Handle attract.

        if (m_Running)
        {
            bool buttonPressed = TrueSyncInput.GetByte(m_ButtonPressedCode) > 0;
            if (buttonPressed)
            {
                FP cost = m_EnergyCostRate * deltaTime;
                cost = MathFP.Max(cost, FP.Zero);

                if (m_Energy != null && m_Energy.CanSpend(cost))
                {
                    m_Energy.Consume(cost);
                }
                else
                {
                    m_Running = false;
                }
            }
            else
            {
                m_Running = false;
            }
        }
        else
        {
            bool buttonDown = TrueSyncInput.HasByte(m_ButtonDownCode);
            if (buttonDown)
            {
                FP cost = m_EnergyCostRate * deltaTime;
                cost = MathFP.Max(cost, FP.Zero);

                if (m_Energy != null && m_Energy.CanSpend(cost))
                {
                    m_Energy.Consume(cost);

                    m_Running = true;
                }
            }
        }

        // Update effector.

        if (m_Running)
        {
            UpdateEffector();
        }
    }
예제 #10
0
파일: LineFP.cs 프로젝트: nakijun/adasg
        public static bool Intersects(LineFP l1, LineFP l2, PointFP intersection)
        {
            int x = SingleFP.NaN;
            int y = SingleFP.NaN;

            if (intersection != null)
            {
                intersection.Reset(x, y);
            }

            int ax0 = l1.P1.X;
            int ax1 = l1.P2.X;
            int ay0 = l1.P1.Y;
            int ay1 = l1.P2.Y;
            int bx0 = l2.P1.X;
            int bx1 = l2.P2.X;
            int by0 = l2.P1.Y;
            int by1 = l2.P2.Y;

            int adx = (ax1 - ax0);
            int ady = (ay1 - ay0);
            int bdx = (bx1 - bx0);
            int bdy = (by1 - by0);

            if (IsZero(adx) && IsZero(bdx))
            {
                return(IsEqual(ax0, bx0));
            }
            else if (IsZero(ady) && IsZero(bdy))
            {
                return(IsEqual(ay0, by0));
            }
            else if (IsZero(adx))
            {
                // A  vertical
                x = ax0;
                y = IsZero(bdy)?by0:MathFP.Mul(MathFP.Div(bdy, bdx), x - bx0) + by0;
            }
            else if (IsZero(bdx))
            {
                // B vertical
                x = bx0;
                y = IsZero(ady)?ay0:MathFP.Mul(MathFP.Div(ady, adx), x - ax0) + ay0;
            }
            else if (IsZero(ady))
            {
                y = ay0;
                x = MathFP.Mul(MathFP.Div(bdx, bdy), y - by0) + bx0;
            }
            else if (IsZero(bdy))
            {
                y = by0;
                x = MathFP.Mul(MathFP.Div(adx, ady), y - ay0) + ax0;
            }
            else
            {
                int xma = MathFP.Div(ady, adx);                 // slope segment A
                int xba = ay0 - (MathFP.Mul(ax0, xma));         // y intercept of segment A

                int xmb = MathFP.Div(bdy, bdx);                 // slope segment B
                int xbb = by0 - (MathFP.Mul(bx0, xmb));         // y intercept of segment B

                // parallel lines?
                if (xma == xmb)
                {
                    // Need trig functions
                    return(xba == xbb);
                }
                else
                {
                    // Calculate points of intersection
                    // At the intersection of line segment A and B, XA=XB=XINT and YA=YB=YINT
                    x = MathFP.Div((xbb - xba), (xma - xmb));
                    y = (MathFP.Mul(xma, x)) + xba;
                }
            }

            // After the point or points of intersection are calculated, each
            // solution must be checked to ensure that the point of intersection lies
            // on line segment A and B.

            int minxa = MathFP.Min(ax0, ax1);
            int maxxa = MathFP.Max(ax0, ax1);

            int minya = MathFP.Min(ay0, ay1);
            int maxya = MathFP.Max(ay0, ay1);

            int minxb = MathFP.Min(bx0, bx1);
            int maxxb = MathFP.Max(bx0, bx1);

            int minyb = MathFP.Min(by0, by1);
            int maxyb = MathFP.Max(by0, by1);

            if (intersection != null)
            {
                intersection.Reset(x, y);
            }
            return((x >= minxa) && (x <= maxxa) && (y >= minya) && (y <= maxya) && (x >= minxb) && (x <= maxxb) && (y >= minyb) && (y <= maxyb));
        }
예제 #11
0
    // INERNALS

    private void ComputeTimeScale(out FP o_TimeScale)
    {
        o_TimeScale = FP.One;

        //bool slowMotionEnabled;
        //GameSettings.TryGetBoolMain(Settings.s_SlowMotionSetting, out slowMotionEnabled);

        if (m_Reference == null || m_ReferenceTransform == null /*|| !slowMotionEnabled*/)
        {
            return;
        }

        TSVector2 velocity = m_Reference.velocity;

        if (velocity.LengthSquared() < m_MinReferenceSpeed * m_MinReferenceSpeed)
        {
            o_TimeScale = 1f;
            return;
        }

        if (m_UseRaycast)
        {
            TSVector2 rayOrigin    = m_Reference.position;
            TSVector2 rayDirection = velocity.normalized;

            FP speed = velocity.magnitude;

            FP rayDistance = speed * m_TimeToReach;
            rayDistance = MathFP.Max(rayDistance, m_DistanceThreshold);

            TSRaycastHit2D[] raycastHit = TSPhysics2D.Raycast(rayOrigin, rayDirection, rayDistance, m_RaycastMask);

            if (raycastHit == null || raycastHit.Length == 0)
            {
                o_TimeScale = 1f;
                return;
            }

            TSRaycastHit2D hitResult = raycastHit[0];

            FP timeScale = MathFP.GetClampedPercentage(hitResult.distance, m_MinDistance, m_MaxDistance);
            timeScale = MathFP.Max(timeScale, m_MinTimeScale);

            o_TimeScale = timeScale;
        }
        else // Do a simple line check.
        {
            TSVector2 delta = velocity * m_TimeToReach;
            if (delta.magnitude > m_DistanceThreshold)
            {
                delta = delta.normalized * m_DistanceThreshold;
            }

            TSVector2 rayStart = m_Reference.position;
            TSVector2 rayEnd   = rayStart + delta;

            // Check each stored segment.

            for (int segmentIndex = 0; segmentIndex < m_SegmentCount; ++segmentIndex)
            {
                TSVector2 pointA = m_Segments[segmentIndex * 2];
                TSVector2 pointB = m_Segments[segmentIndex * 2 + 1];

                FP        t;
                TSVector2 intersectionPoint;

                if (Test2DSegmentSegment(pointA, pointB, rayStart, rayEnd, out t, out intersectionPoint))
                {
                    TSVector2 distance = intersectionPoint - rayStart;

                    FP timeScale = MathFP.GetClampedPercentage(distance.magnitude, m_MinDistance, m_MaxDistance);
                    timeScale = MathFP.Max(timeScale, m_MinTimeScale);

                    o_TimeScale = timeScale;

                    return;
                }
            }
        }
    }
    public override void OnSyncedUpdate()
    {
        base.OnSyncedUpdate();

        if (!m_RunSyncedUpdate)
        {
            return;
        }

        // Read delta time.

        FP  deltaTime   = TrueSyncManager.deltaTimeMain;
        int currentTick = TrueSyncManager.ticksMain;

        // Update timers.

        UpdateTimers(deltaTime);

        // Read input.

        FP horizontalAxis;
        FP verticalAxis;

        if (m_EnableInputCompression)
        {
            int intX = TrueSyncInput.GetInt(m_HorizontalAxisCode);
            int intY = TrueSyncInput.GetInt(m_VerticalAxisCode);

            horizontalAxis = intX / (FP)s_InputPrecision;
            verticalAxis   = intY / (FP)s_InputPrecision;
        }
        else
        {
            horizontalAxis = TrueSyncInput.GetFP(m_HorizontalAxisCode);
            verticalAxis   = TrueSyncInput.GetFP(m_VerticalAxisCode);
        }

        // Handle actions.

        bool actionRequested = TrueSyncInput.HasByte(m_DashRequestedCode);
        bool cooldownOk      = (m_CooldownTimer == FP.Zero);
        bool energyAvailable = (m_Energy != null && m_Energy.CanSpend(m_DashEnergyCost));

        if (actionRequested && m_DashTickRequest == 0 && energyAvailable && cooldownOk)
        {
            // Cahce dash tick request.

            m_DashTickRequest = currentTick + m_DashTickDelay;

            // Consume energy.

            if (m_Energy != null)
            {
                m_Energy.Consume(m_DashEnergyCost);
            }
        }

        if ((m_DashTickRequest > 0) && (m_DashTickRequest == currentTick))
        {
            // Consume tick input.

            m_DashTickRequest = 0;

            // Override layer, mass and drag.

            int layerOverride = m_DashLayer;

            FP massOverride = m_DashMass;
            FP dragOverride = m_DashDrag;

            SetRigidbodyLayer(layerOverride);

            SetRigidbodyMass(massOverride);
            SetRigidbodyDrag(dragOverride);

            // Apply insant force.

            TSVector2 move = new TSVector2(horizontalAxis, verticalAxis);
            move.Normalize();

            TSVector2 moveForce = move * m_DashAppliedForce;
            m_Rigidbody2D.AddForce(moveForce);

            // Update timers.

            m_DurationTimer = m_DashDuration;
            m_CooldownTimer = MathFP.Max(m_DashCooldown, m_DurationTimer);

            // Raise event.

            if (m_OnDashTriggered != null)
            {
                m_OnDashTriggered();
            }
        }
        else // Handle movement.
        {
            if (m_DurationTimer == FP.Zero)
            {
                // Restore layer, mass and drag.

                SetRigidbodyLayer(m_OriginalLayer);

                SetRigidbodyMass(m_OriginalMass);
                SetRigidbodyDrag(m_OriginalDrag);

                // Compute movement force.

                TSVector2 move      = new TSVector2(horizontalAxis, verticalAxis);
                TSVector2 moveForce = move * m_MoveForce;

                if (m_MaxSpeed > FP.Zero)
                {
                    TSVector2 currentVelocity = m_Rigidbody2D.velocity;

                    TSVector2 moveAcceleration = moveForce / m_Rigidbody2D.mass;        // F = m * a    ==> a = F / m
                    TSVector2 deltaVelocity    = moveAcceleration * deltaTime;          // a = dv / dt  ==> dv = a * dt

                    TSVector2 newVelocity = currentVelocity + deltaVelocity;

                    if (newVelocity.LengthSquared() > m_MaxSpeed * m_MaxSpeed)
                    {
                        // Modulate moveForce in order to reach a maximum speed of m_MaxSpeed.

                        TSVector2 maxVelocity     = newVelocity.normalized * m_MaxSpeed;
                        TSVector2 maxAcceleration = (maxVelocity - currentVelocity) / deltaTime;

                        moveForce = maxAcceleration * m_Rigidbody2D.mass;
                    }
                }

                m_Rigidbody2D.AddForce(moveForce);
            }
        }
    }