Exemple #1
0
    private void CreatePortalHotspots(RoomData room)
    {
        foreach (RoomPortal portalEntry in room.RoomPortals)
        {
            AABB2d  boundingBox = new AABB2d();
            Point2d screenP0    = ClientGameConstants.ConvertRoomPositionToScreenPosition(portalEntry.boundingBox.Min);
            Point2d screenP1    = ClientGameConstants.ConvertRoomPositionToScreenPosition(portalEntry.boundingBox.Max);

            boundingBox.EnclosePoint(screenP0);
            boundingBox.EnclosePoint(screenP1);

            m_hotspotWidgets.Add(
                new HotspotWidget(m_rootWidgetGroup,
                                  "Portal" + portalEntry.portal_id.ToString(),
                                  boundingBox.Extents.i,
                                  boundingBox.Extents.j,
                                  boundingBox.Min.x,
                                  boundingBox.Min.y,
                                  new HotspotInfo {
                hotspotType = eHotspotType.portal, hotspotEntity = portalEntry
            }));
        }
    }
Exemple #2
0
    private void CreateEnergyTankHotspots(RoomData room)
    {
        foreach (EnergyTankData energyTankData in room.EnergyTankMap.Values)
        {
            AABB2d  boundingBox = new AABB2d();
            Point2d screenP0    = ClientGameConstants.ConvertRoomPositionToScreenPosition(energyTankData.boundingBox.Min);
            Point2d screenP1    = ClientGameConstants.ConvertRoomPositionToScreenPosition(energyTankData.boundingBox.Max);

            boundingBox.EnclosePoint(screenP0);
            boundingBox.EnclosePoint(screenP1);

            m_hotspotWidgets.Add(
                new HotspotWidget(m_rootWidgetGroup,
                                  "EnergyTank" + energyTankData.energy_tank_id.ToString(),
                                  boundingBox.Extents.i,
                                  boundingBox.Extents.j,
                                  boundingBox.Min.x,
                                  boundingBox.Min.y,
                                  new HotspotInfo {
                hotspotType = eHotspotType.energy_tank, hotspotEntity = energyTankData
            }));
        }
    }
Exemple #3
0
        public bool Raycast(
            Point3d start,
            NavRef startNavRef,
            Point3d end,
            NavRef endNavRef,
            out float t)
        {
            bool hit = false;

            if (!startNavRef.IsValid || !endNavRef.IsValid)
            {
                hit = true;
                t   = 0.0f;
            }
            else if (startNavRef.Equals(endNavRef))
            {
                hit = false;
                t   = 1.0f;
            }
            else
            {
                uint maxRaycastIteration = m_rowCount + m_colomnCount;
                uint iterationCount      = 0;

                NavRef   currentNavRef        = startNavRef;
                AABB2d   currentNavCellBounds = ComputeNavCellBounds2d((uint)currentNavRef.NavCellIndex);
                Point2d  start2d      = start.ToPoint2d();
                Vector2d rayDirection = (end - start).ToVector2d();
                float    tEpsilon     = MathConstants.POSITIONAL_EPSILON / rayDirection.Magnitude();

                t = 0.0f;

                while (t < 1.0f && !hit)
                {
                    float clipMinT = 0.0f;
                    float clipMaxT = 0.0f;

                    // Compute where the ray exists the bounding box of the cell
                    if (!currentNavCellBounds.ClipRay(
                            start2d,
                            rayDirection,
                            out clipMinT,
                            out clipMaxT))
                    {
                        // If we failed to clip against the bounds that we were suppose to be inside of,
                        // just use the current t and rely on the positional epsilon advancement to get
                        // us back on track
                        Debug.Assert(false, "Raycast didn't clip against box it was suppose to intersect");
                        clipMinT = t;
                        clipMaxT = t;
                    }

                    if (clipMaxT < 1.0f)
                    {
                        // If we haven't gotten to the end of the ray yet, try to advance to the next nav cell
                        Point2d newTestPoint = start2d + rayDirection * (clipMaxT + tEpsilon);

                        // Find the adjacent neighboring cell, if any
                        currentNavRef = ComputeNavRefAtPoint(newTestPoint);

                        if (currentNavRef.IsValid)
                        {
                            currentNavCellBounds = ComputeNavCellBounds2d((uint)currentNavRef.NavCellIndex);

                            if (currentNavRef.Equals(endNavRef))
                            {
                                t   = 1.0f;
                                hit = false;
                            }
                            else
                            {
                                t   = Math.Min(clipMaxT + tEpsilon, 1.0f);
                                hit = false;
                            }
                        }
                        else
                        {
                            t   = clipMaxT;
                            hit = true;
                        }
                    }
                    else
                    {
                        // Made it all the way to the end without hitting anything
                        t   = 1.0f;
                        hit = false;
                    }

                    // Safety iteration max to prevent infinite loops
                    iterationCount++;
                    if (iterationCount > maxRaycastIteration)
                    {
                        // Something funky happened. Just assume we can see to the end
                        Debug.Assert(false, "Raycast hit iteration limit");
                        t   = 1.0f;
                        hit = false;
                        break;
                    }
                }
            }

            return(hit);
        }