예제 #1
0
        public static float DistanceSquared(Point2d a, Point2d b)
        {
            float xDelta = b.x - a.x;
            float yDelta = b.y - a.y;

            return (xDelta * xDelta) + (yDelta * yDelta);
        }
    public static Point2d GetMousePosition()
    {
        Vector3 unityMousePosition = Input.mousePosition;
        Point2d gameMousePosition = new Point2d(unityMousePosition.x, Screen.height - unityMousePosition.y);

        return gameMousePosition;
    }
 public WidgetEventDispatcher()
 {
     m_mousePosition = new Point2d();
     m_rootWidgetGroup = null;
     m_mouseOverIWidget = null;
     m_mouseDownIWidget = null;
     m_mouseIsDragging = false;
     m_mouseWasDown = false;
 }
예제 #4
0
        public bool ClipRay(
            Point2d rayOrigin,
            Vector2d rayDirection,
            out float clipMinT,
            out float clipMaxT)
        {
            bool intersects = false;
            Vector2d tMin = new Vector2d();
            Vector2d tMax = new Vector2d();

            // Compute the ray intersection times along the x-axis
            if (rayDirection.i > MathConstants.EPSILON)
            {
                // ray has positive x component
                tMin.i = (m_pMin.x - rayOrigin.x) / rayDirection.i;
                tMax.i = (m_pMax.x - rayOrigin.x) / rayDirection.i;
            }
            else if (rayDirection.i < -MathConstants.EPSILON)
            {
                // ray has negative x component
                tMin.i = (m_pMax.x - rayOrigin.x) / rayDirection.i;
                tMax.i = (m_pMin.x - rayOrigin.x) / rayDirection.i;
            }
            else
            {
                // Ray has no x component (parallel to x-axis)
                tMin.i = MathConstants.REAL_MIN;
                tMax.i = MathConstants.REAL_MAX;
            }

            // Compute the ray intersection times along the y-axis
            if (rayDirection.j > MathConstants.EPSILON)
            {
                // ray has positive y component
                tMin.j = (m_pMin.y - rayOrigin.y) / rayDirection.j;
                tMax.j = (m_pMax.y - rayOrigin.y) / rayDirection.j;
            }
            else if (rayDirection.j < -MathConstants.EPSILON)
            {
                // ray has negative y component
                tMin.j = (m_pMax.y - rayOrigin.y) / rayDirection.j;
                tMax.j = (m_pMin.y - rayOrigin.y) / rayDirection.j;
            }
            else
            {
                // Ray has no y component (parallel to y-axis)
                tMin.j = MathConstants.REAL_MIN;
                tMax.j = MathConstants.REAL_MAX;
            }

            // Ray only intersects AABB if minT is before maxT and maxT is non-negative
            clipMinT = tMin.MaxComponent();
            clipMaxT = tMax.MinComponent();
            intersects = clipMinT < clipMaxT && clipMaxT >= 0;

            return intersects;
        }
예제 #5
0
    public void OnCharacterMoveToRequest(float x, float y)
    {
        Point2d pixelPoint = new Point2d(x, y);
        Point3d roomPoint = GameConstants.ConvertPixelPositionToRoomPosition(pixelPoint);

        if (!m_gameWorldModel.IsAsyncRequestPending &&
            m_gameWorldModel.IsEventCursorAtLastEvent &&
            !m_gameWorldModel.IsEventPlaybackActive &&
            m_gameWorldModel.IsWorldPointOnNavMesh(roomPoint))
        {
            m_gameWorldModel.RequestCharacterMove(roomPoint);
        }
    }
예제 #6
0
    public WidgetGroup(WidgetGroup parentGroup, float width, float height, float x, float y)
    {
        m_widgetEventListener = null;
        m_childWidgets = new List<IWidget>() { };
        m_parentWidgetGroup = parentGroup;
        m_localPosition = new Point2d();
        m_worldPosition = new Point2d();
        Width = width;
        Height = height;
        Visible = true;

        if (m_parentWidgetGroup != null)
        {
            m_parentWidgetGroup.AddWidget(this);
        }

        SetLocalPosition(x, y);
    }
예제 #7
0
 public void SetPointBounds2d(Point2d p0, Point2d p1)
 {
     m_pMin = new Point3d(p0.x, p0.y, 0.0f);
     m_pMax = new Point3d(p1.x, p1.y, 0.0f);
 }
예제 #8
0
 public static Point3d ConvertPixelPositionToRoomPosition(Point2d pixelPosition)
 {
     return ConvertPixelPositionToRoomPosition(pixelPosition.x, pixelPosition.y);
 }
예제 #9
0
    public virtual void UpdateWorldPosition()
    {
        if (m_parentWidgetGroup != null)
        {
            m_worldPosition = m_parentWidgetGroup.WorldPosition.Offset(m_localPosition.x, m_localPosition.y);
        }
        else
        {
            m_worldPosition.Set(m_localPosition.x, m_localPosition.y);
        }

        for (int childIndex = 0; childIndex < m_childWidgets.Count; childIndex++ )
        {
            IWidget widget = m_childWidgets[childIndex];

            widget.UpdateWorldPosition();
        }
    }
    public void OnEnergyTankClicked(Point2d entryPixelPoint, EnergyTankData energyTankData)
    {
        Point3d entryWorldPoint = GameConstants.ConvertPixelPositionToRoomPosition(entryPixelPoint);

        m_gameWorldController.OnEnergyTankClicked(entryWorldPoint, energyTankData);
    }
예제 #11
0
    private void OnHotspotClicked(
        HotspotWidget hotspotWidget,
        WidgetEvent widgetEvent)
    {
        if (m_currentNavRef.IsValid)
        {
            WidgetEvent.MouseClickEventParameters eventParameters =
                widgetEvent.EventParameters as WidgetEvent.MouseClickEventParameters;
            Point2d clickPoint = new Point2d(eventParameters.worldX, eventParameters.worldY);
            HotspotInfo hotspotInfo = hotspotWidget.Userdata as HotspotInfo;

            switch (hotspotInfo.hotspotType)
            {
                case eHotspotType.energy_tank:
                    {
                        EnergyTankData energyTankData = hotspotInfo.hotspotEntity as EnergyTankData;

                        m_contextOverlayController.OnEnergyTankClicked(clickPoint, energyTankData);
                    }
                    break;
                case eHotspotType.portal:
                    {
                        RoomPortal portal = hotspotInfo.hotspotEntity as RoomPortal;

                        m_contextOverlayController.OnPortalClicked(clickPoint, portal);
                    }
                    break;
            }
        }
    }
예제 #12
0
 public AABB2d(AABB2d other)
 {
     this.m_pMin = new Point2d(other.m_pMin);
     this.m_pMax = new Point2d(other.m_pMax);
 }
예제 #13
0
 public AABB2d EncloseAABB(AABB2d other)
 {
     return(new AABB2d(Point2d.Min(m_pMin, other.m_pMin), Point2d.Max(m_pMax, other.m_pMax)));
 }
예제 #14
0
 public Point2d(Point2d p)
 {
     this.x = p.x;
     this.y = p.y;
 }
예제 #15
0
 public static float Distance(Point2d a, Point2d b)
 {
     return (float)Math.Sqrt(Point2d.DistanceSquared(a, b));
 }
예제 #16
0
 public void Move(Vector2d v)
 {
     m_pMin += v;
     m_pMax += v;
 }
예제 #17
0
 public void Set(Point2d p)
 {
     this.x = p.x;
     this.y = p.y;
 }
예제 #18
0
 public Point2d ClipPoint(Point2d p)
 {
     return new Point2d(
         Math.Min(Math.Max(p.x, m_pMin.x), m_pMax.x),
         Math.Min(Math.Max(p.y, m_pMin.y), m_pMax.y));
 }
예제 #19
0
 public AABB2d(AABB2d other)
 {
     this.m_pMin = new Point2d(other.m_pMin);
     this.m_pMax = new Point2d(other.m_pMax);
 }
예제 #20
0
 public AABB2d(Point2d pMin, Point2d pMax)
 {
     this.m_pMin = new Point2d(pMin);
     this.m_pMax = new Point2d(pMax);
 }
예제 #21
0
 public void SetPointBounds(Point2d p0, Point2d p1)
 {
     m_pMin = new Point2d(p0);
     m_pMax = new Point2d(p1);
 }
예제 #22
0
        public void EnclosePoint(Point2d point)
        {
            m_pMin.x = Math.Min(m_pMin.x, point.x);
            m_pMin.y = Math.Min(m_pMin.y, point.y);

            m_pMax.x = Math.Max(m_pMax.x, point.x);
            m_pMax.y = Math.Max(m_pMax.y, point.y);
        }
예제 #23
0
 public void Move(Vector2d v)
 {
     m_pMin += v;
     m_pMax += v;
 }
예제 #24
0
        public static Point2d Interpolate(Point2d a, Point2d b, float u)
        {
            float inv_u = (1.0f - u);

            return new Point2d(inv_u * a.x + u * b.x, inv_u * a.y + u * b.y);
        }
예제 #25
0
 public void SetPointBounds(Point2d p0, Point2d p1)
 {
     m_pMin = new Point2d(p0);
     m_pMax = new Point2d(p1);
 }
예제 #26
0
 public static Point2d Min(Point2d a, Point2d b)
 {
     return new Point2d(Math.Min(a.x, b.x), Math.Min(a.y, b.y));
 }
예제 #27
0
 public bool ContainsPoint(Point2d p)
 {
     return(p.x >= m_pMin.x && p.y >= m_pMin.y &&
            p.x <= m_pMax.x && p.y <= m_pMax.y);
 }
예제 #28
0
 public bool Equals(Point2d other)
 {
     return x == other.x && y == other.y;
 }
    // Model Events
    // View Events
    public void OnPortalClicked(Point2d entryPixelPoint, RoomPortal portal)
    {
        Point3d entryWorldPoint = GameConstants.ConvertPixelPositionToRoomPosition(entryPixelPoint);

        m_gameWorldController.OnPortalClicked(entryWorldPoint, portal);
    }
예제 #30
0
 public void SetLocalPosition(float x, float y)
 {
     m_localPosition = new Point2d(x, y);
     UpdateWorldPosition();
 }
예제 #31
0
    private void UpdateMouseCursor(WidgetEvent widgetEvent)
    {
        if (widgetEvent.EventType == WidgetEvent.eEventType.mouseOver ||
            widgetEvent.EventType == WidgetEvent.eEventType.mouseOut ||
            widgetEvent.EventType == WidgetEvent.eEventType.mouseMove)
        {
            if (widgetEvent.EventSource is HotspotWidget)
            {
                HotspotWidget hotspotWidget = widgetEvent.EventSource as HotspotWidget;
                HotspotInfo hotspotInfo = hotspotWidget.Userdata as HotspotInfo;

                switch (hotspotInfo.hotspotType)
                {
                    case eHotspotType.energy_tank:
                        {
                            EnergyTankData energyTankData = hotspotInfo.hotspotEntity as EnergyTankData;

                            if (energyTankData.ownership != GameConstants.eFaction.player)
                            {
                                // If our faction doesn't control the energy tank, we'll have to hack it
                                SetMouseCursorState(eMouseCursorState.hack_energy_tank);
                            }
                            else if (energyTankData.energy > 0)
                            {
                                // If our faction does control the energy tank, then we can drain it if it has energy
                                SetMouseCursorState(eMouseCursorState.drain_energy_tank);
                            }
                            else
                            {
                                // Otherwise all we can do is walk to it
                                SetMouseCursorState(eMouseCursorState.walk);
                            }
                        }
                        break;
                    case eHotspotType.portal:
                        {
                            Point2d hotspotCenter =
                                hotspotWidget.WorldPosition.Offset(new Vector2d(hotspotWidget.Width / 2.0f, hotspotWidget.Height / 2.0f));
                            Point2d screenCenter = new Point2d(Screen.width / 2.0f, Screen.height / 2.0f);
                            Vector2d vectorToHotspot = hotspotCenter - screenCenter;

                            MathConstants.eDirection currentHotspotDirection = MathConstants.GetDirectionForVector(vectorToHotspot);

                            switch (currentHotspotDirection)
                            {
                                case MathConstants.eDirection.left:
                                    SetMouseCursorState(eMouseCursorState.door_left);
                                    break;
                                case MathConstants.eDirection.right:
                                    SetMouseCursorState(eMouseCursorState.door_right);
                                    break;
                                case MathConstants.eDirection.up:
                                    SetMouseCursorState(eMouseCursorState.door_up);
                                    break;
                                case MathConstants.eDirection.down:
                                    SetMouseCursorState(eMouseCursorState.door_down);
                                    break;
                                default:
                                    SetMouseCursorState(eMouseCursorState.walk);
                                    break;
                            }
                        }
                        break;
                    default:
                        {
                            SetMouseCursorState(eMouseCursorState.defaultCursor);
                        }
                        break;
                }
            }
            else if (widgetEvent.EventSource is TileGridWidget)
            {
                if (m_currentNavRef.IsValid)
                {
                    SetMouseCursorState(eMouseCursorState.walk);
                }
                else
                {
                    SetMouseCursorState(eMouseCursorState.defaultCursor);
                }

            }
            else
            {
                SetMouseCursorState(eMouseCursorState.defaultCursor);
            }
        }
    }
예제 #32
0
 public AABB2d()
 {
     m_pMin = new Point2d(MathConstants.REAL_MAX, MathConstants.REAL_MAX);
     m_pMax = new Point2d(MathConstants.REAL_MIN, MathConstants.REAL_MIN);
 }
예제 #33
0
    public void Update()
    {
        if (this.IsActive)
        {
            // Update which waypoint the AI is heading toward
            m_pathfindingComponent.Update();

            // Compute a throttle and a facing toward the waypoint
            m_steeringComponent.Update();

            // Make a local copy of our position
            {
                Point2d pixelPosition = new Point2d(m_characterWidget.LocalX, m_characterWidget.LocalY);

                m_position = GameConstants.ConvertPixelPositionToRoomPosition(pixelPosition);
            }

            // Make a local copy of our facing, if we're moving
            if (!m_steeringComponent.Throttle.IsAlmostZero)
            {
                m_facing.Copy(m_steeringComponent.Facing);
            }

            // Update the animation based on our desired facing and velocity
            m_characterWidget.UpdateAnimation(m_facing, m_steeringComponent.Throttle);
        }
    }
예제 #34
0
 public Point2d ClipPoint(Point2d p)
 {
     return(new Point2d(
                Math.Min(Math.Max(p.x, m_pMin.x), m_pMax.x),
                Math.Min(Math.Max(p.y, m_pMin.y), m_pMax.y)));
 }
예제 #35
0
 public bool ContainsPoint2d(Point2d p)
 {
     return p.x >= m_pMin.x && p.y >= m_pMin.y &&
             p.x <= m_pMax.x && p.y <= m_pMax.y;
 }
예제 #36
0
 public AABB2d(Point2d pMin, Point2d pMax)
 {
     this.m_pMin = new Point2d(pMin);
     this.m_pMax = new Point2d(pMax);
 }
예제 #37
0
    public void Update()
    {
        if (this.IsActive)
        {
            // Update which waypoint the AI is heading toward
            m_pathfindingComponent.Update();

            // Compute a throttle and a facing toward the waypoint
            m_steeringComponent.Update();

            // Make a local copy of our position
            {
                Point2d pixelPosition = new Point2d(m_mobWidget.LocalX, m_mobWidget.LocalY);

                m_position = GameConstants.ConvertPixelPositionToRoomPosition(pixelPosition);
            }

            // Make a local copy of our facing, if we're moving
            if (!m_steeringComponent.Throttle.IsAlmostZero)
            {
                m_facing.Copy(m_steeringComponent.Facing);
            }

            // Update the animation based on our desired facing and velocity
            m_mobWidget.UpdateAnimation(m_facing, m_steeringComponent.Throttle);

            // Hide the vision cone while we' re moving
            m_mobWidget.SetVisionConeVisible(m_steeringComponent.Throttle.IsAlmostZero);

            // Hide the dialog if it timed out
            if (m_dialogTimer >= 0.0f && (Time.time - m_dialogTimer) >= DIALOG_DISPLAY_DURATION)
            {
                m_mobWidget.HideDialog();
                m_dialogTimer = -1.0f;
            }
        }
    }
예제 #38
0
 public AABB2d()
 {
     m_pMin = new Point2d(MathConstants.REAL_MAX, MathConstants.REAL_MAX);
     m_pMax = new Point2d(MathConstants.REAL_MIN, MathConstants.REAL_MIN);
 }