private void DumpLayoutGeometry(
            string dumpGeometryPath, 
            DungeonLayout layout)
        {
            GeometryFileWriter fileWriter = new GeometryFileWriter();
            string filename= string.Format("DungeonLayout_Game{0}_Size{1}", layout.GameID, layout.LayoutWorldTemplate.dungeon_size);
            string header = string.Format("DungeonLayout for GameID:{0} DungeonSize: {1}", layout.GameID, layout.LayoutWorldTemplate.dungeon_size);
            string result = SuccessMessages.GENERAL_SUCCESS;
            Vector3d roomSize = new Vector3d(WorldConstants.ROOM_X_SIZE, WorldConstants.ROOM_Y_SIZE, WorldConstants.ROOM_Z_SIZE);

            for (DungeonLayout.RoomIndexIterator iterator = new DungeonLayout.RoomIndexIterator(layout.RoomGrid);
                iterator.Valid;
                iterator.Next())
            {
                DungeonLayout.RoomIndex roomIndex = iterator.Current;
                Room room = layout.GetRoomByIndex(roomIndex);
                AABB3d roomAABB = new AABB3d(room.world_position, room.world_position + roomSize);
                AABB3d shrunkRoomAABB = roomAABB.ScaleAboutCenter(0.5f);
                AABB3d centerAABB = roomAABB.ScaleAboutCenter(0.05f);

                // Add the AABB for this room
                fileWriter.AppendAABB(shrunkRoomAABB);

                // Create portal AABBs to all adjacent rooms
                for (MathConstants.eSignedDirection roomSide = MathConstants.eSignedDirection.first;
                    roomSide < MathConstants.eSignedDirection.count;
                    ++roomSide)
                {
                    if (room.RoomHasPortalOnSide(roomSide))
                    {
                        DungeonLayout.RoomIndex neighborRoomIndex = null;
                        switch (roomSide)
                        {
                            case MathConstants.eSignedDirection.positive_x:
                                neighborRoomIndex = roomIndex.Offset(1, 0, 0);
                                break;
                            case MathConstants.eSignedDirection.negative_x:
                                neighborRoomIndex = roomIndex.Offset(-1, 0, 0);
                                break;
                            case MathConstants.eSignedDirection.positive_y:
                                neighborRoomIndex = roomIndex.Offset(0, 1, 0);
                                break;
                            case MathConstants.eSignedDirection.negative_y:
                                neighborRoomIndex = roomIndex.Offset(0, -1, 0);
                                break;
                            case MathConstants.eSignedDirection.positive_z:
                                neighborRoomIndex = roomIndex.Offset(0, 0, 1);
                                break;
                            case MathConstants.eSignedDirection.negative_z:
                                neighborRoomIndex = roomIndex.Offset(0, 0, -1);
                                break;
                        }

                        Room neighborRoom = layout.GetRoomByIndex(neighborRoomIndex);
                        AABB3d neighborRoomAABB = new AABB3d(neighborRoom.world_position, neighborRoom.world_position + roomSize);
                        AABB3d neighborCenterAABB = neighborRoomAABB.ScaleAboutCenter(0.05f);
                        AABB3d portalAABB = centerAABB.EncloseAABB(neighborCenterAABB);

                        fileWriter.AppendAABB(portalAABB);
                    }
                }

                // TODO: DumpLayoutGeometry: Color the rooms by teleporter pair
            }

            if (!fileWriter.SaveFile(dumpGeometryPath, filename, header, out result))
            {
                _logger.WriteLine("DungeonValidator: WARNING: Failed to save layout geometry file");
                _logger.WriteLine(result);
            }
        }
Example #2
0
 public void Move(Vector3d v)
 {
     m_pMin += v;
     m_pMax += v;
 }
Example #3
0
        public bool ClipRay(
            Point3d rayOrigin,
            Vector3d rayDirection,
            out float clipMinT,
            out float clipMaxT)
        {
            bool intersects = false;
            Vector3d tMin = new Vector3d();
            Vector3d tMax = new Vector3d();

            // 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;
            }

            // Compute the ray intersection times along the z-axis
            if (rayDirection.k > MathConstants.EPSILON)
            {
                // ray has positive z component
                tMin.k = (m_pMin.z - rayOrigin.z) / rayDirection.k;
                tMax.k = (m_pMax.z - rayOrigin.z) / rayDirection.k;
            }
            else if (rayDirection.k < -MathConstants.EPSILON)
            {
                // ray has negative z component
                tMin.k = (m_pMax.z - rayOrigin.z) / rayDirection.k;
                tMax.k = (m_pMin.z - rayOrigin.z) / rayDirection.k;
            }
            else
            {
                // Ray has no z component (parallel to z-axis)
                tMin.k = MathConstants.REAL_MIN;
                tMax.k = 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;
        }
Example #4
0
 public static float GetAngleForVector(Vector3d v)
 {
     // (1, 0) -> 0 degrees
     // (0, 1) -> 90 degrees
     // (-1, 0) -> 180 degrees
     // (0, -1) -> 270 degrees
     return (((float)Math.Atan2(v.j, v.i) + MathConstants.TWO_PI) % MathConstants.TWO_PI) * RADIANS_TO_DEGREES;
 }
Example #5
0
        public static eDirection GetDirectionForVector(Vector3d vector)
        {
            eDirection direction = eDirection.none;

            if (vector.MagnitudeSquared() > EPSILON_SQUARED)
            {
                if (vector.i > 0)
                {
                    if (vector.j > vector.i)
                    {
                        direction = eDirection.down;
                    }
                    else if (vector.j < -vector.i)
                    {
                        direction = eDirection.up;
                    }
                    else
                    {
                        direction = eDirection.right;
                    }
                }
                else
                {
                    if (vector.j > -vector.i)
                    {
                        direction = eDirection.down;
                    }
                    else if (vector.j < vector.i)
                    {
                        direction = eDirection.up;
                    }
                    else
                    {
                        direction = eDirection.left;
                    }
                }
            }

            return direction;
        }
Example #6
0
 public float Cross2d(Vector3d v)
 {
     return i * v.j - v.i * j;
 }
Example #7
0
 public Point3d Offset(Vector3d v)
 {
     return new Point3d(x + v.i, y + v.j, z + v.k);
 }
Example #8
0
 public Vector3d Cross(Vector3d v)
 {
     return new Vector3d(j * v.k - v.j * k, v.i * k - i * v.k, i * v.j - v.i * j);
 }
Example #9
0
 public void Copy(Vector3d v)
 {
     this.i = v.i;
     this.j = v.j;
     this.k = v.k;
 }
Example #10
0
 public Vector3d(Vector3d v)
 {
     this.i = v.i;
     this.j = v.j;
     this.k = v.k;
 }
Example #11
0
        public float NormalizeWithDefault(Vector3d defaultVector)
        {
            float length = Magnitude();

            if (length > MathConstants.EPSILON)
            {
                ScaleBy(1.0f / length);
            }
            else
            {
                Copy(defaultVector);
            }

            return length;
        }
Example #12
0
 public float Dot(Vector3d v)
 {
     return i * v.i + j * v.j + k * v.k;
 }