| 1 | /* |
| 2 | * Descent 3 |
| 3 | * Copyright (C) 2024 Parallax Software |
| 4 | * |
| 5 | * This program is free software: you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation, either version 3 of the License, or |
| 8 | * (at your option) any later version. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 17 | |
| 18 | --- HISTORICAL COMMENTS FOLLOW --- |
| 19 | |
| 20 | * $Logfile: /DescentIII/Main/editor/HRoom.h $ |
| 21 | * $Revision: 1.1.1.1 $ |
| 22 | * $Date: 2003-08-26 03:57:38 $ |
| 23 | * $Author: kevinb $ |
| 24 | * |
| 25 | * Header for HRoom.cpp |
| 26 | * |
| 27 | * $Log: not supported by cvs2svn $ |
| 28 | * |
| 29 | * 31 9/15/99 1:56p Matt |
| 30 | * Added the option to allow rooms or groups placed on the terrain to |
| 31 | * either align with the terrain or with gravity. |
| 32 | * |
| 33 | * 30 5/08/99 6:39p Matt |
| 34 | * Added a function to delete a face and all faces connected to it. |
| 35 | * |
| 36 | * 29 4/30/99 6:52p Matt |
| 37 | * Added a function to merge an object's geometry into a room. |
| 38 | * |
| 39 | * 28 4/19/99 12:10a Matt |
| 40 | * Added a menu item to delete a vertex from a face. |
| 41 | * |
| 42 | * 27 4/06/99 10:23a Matt |
| 43 | * |
| 44 | * 26 3/31/99 12:58p Matt |
| 45 | * Added snap-point-to-face |
| 46 | * |
| 47 | * 25 3/23/99 5:12p Matt |
| 48 | * Added function to combine rooms. |
| 49 | * |
| 50 | * 24 12/23/98 10:53a Matt |
| 51 | * Added functions to create a face |
| 52 | * |
| 53 | * 23 10/03/98 8:31p Matt |
| 54 | * Added Join Rooms Exact function. |
| 55 | * |
| 56 | * 22 9/09/98 4:07p Matt |
| 57 | * Added Smooth Bridge function |
| 58 | * |
| 59 | * 21 9/07/98 10:58p Matt |
| 60 | * Added snap point to point. |
| 61 | * |
| 62 | * 20 9/04/98 3:34p Matt |
| 63 | * Added groovy vertex snap code |
| 64 | * |
| 65 | * 19 9/03/98 5:29p Matt |
| 66 | * Added code to fix cracks in levels. |
| 67 | * |
| 68 | * 18 9/02/98 5:57p Matt |
| 69 | * Added code to make faces match exactly when forming a portal. This |
| 70 | * should get rid of all remaining cracking problems. |
| 71 | * |
| 72 | * 17 8/28/98 6:21p Matt |
| 73 | * Added a function to flip a face. |
| 74 | * |
| 75 | * 16 6/25/98 7:15p Matt |
| 76 | * Added a function to delete a pair of portals. |
| 77 | * |
| 78 | * 15 6/23/98 2:45p Matt |
| 79 | * Added option when propagating to all faces in a room to only do so to |
| 80 | * ones with the same texture. |
| 81 | * |
| 82 | * 14 6/08/98 12:28p Matt |
| 83 | * Added a function to triangulate a face |
| 84 | * |
| 85 | * 13 5/22/98 4:47p Matt |
| 86 | * Added menu item to propagate a texture to all the faces in a room. |
| 87 | * |
| 88 | * 12 4/27/98 6:41p Matt |
| 89 | * Added code to join all adjacent faces between two rooms |
| 90 | * |
| 91 | * 11 2/16/98 1:27p Matt |
| 92 | * Added function to snap the placed room to a vertex/edge on the base |
| 93 | * room/face |
| 94 | * |
| 95 | * 10 11/05/97 7:13p Matt |
| 96 | * Added join rooms function |
| 97 | * |
| 98 | * 9 10/03/97 3:38p Matt |
| 99 | * Added place and attach code for rooms on the terrain |
| 100 | * |
| 101 | * 8 9/24/97 3:22p Matt |
| 102 | * Added Drop Room function |
| 103 | * |
| 104 | * 7 9/11/97 5:38p Jason |
| 105 | * initial door coding for room engine |
| 106 | * |
| 107 | * 6 8/21/97 6:01p Matt |
| 108 | * Added combine faces & delete room functions |
| 109 | * |
| 110 | * 5 8/18/97 6:59p Matt |
| 111 | * Implemented Place Room/Attach room system |
| 112 | * |
| 113 | * 4 8/04/97 12:46p Matt |
| 114 | * Added BuildBridge() and SetMarkedRoom() |
| 115 | * |
| 116 | * |
| 117 | * 3 8/01/97 6:15p Matt |
| 118 | * Added code to attach rooms |
| 119 | * |
| 120 | * 2 7/22/97 10:33a Matt |
| 121 | * Added AddRoom() |
| 122 | * |
| 123 | * 1 7/21/97 4:48p Matt |
| 124 | * |
| 125 | * $NoKeywords: $ |
| 126 | */ |
| 127 | |
| 128 | #ifndef _HROOM_H |
| 129 | #define _HROOM_H |
| 130 | |
| 131 | #include "room.h" |
| 132 | |
| 133 | // Make the Marked room/face the current room/face |
| 134 | void SetMarkedRoom(); |
| 135 | |
| 136 | // Select next face on current room |
| 137 | void SelectNextFace(); |
| 138 | |
| 139 | // Select previous face on current room |
| 140 | void SelectPrevFace(); |
| 141 | |
| 142 | // Adds a room at the current room/face. The room is created by extuding out from the current face |
| 143 | void AddRoom(); |
| 144 | |
| 145 | // Recomputes the rotation matrix for the placed room (called when the room rotated) |
| 146 | void ComputePlacedRoomMatrix(); |
| 147 | |
| 148 | // Place a room for orientation before attachment |
| 149 | // Parameters: baseroomp - pointer to the room in the mine to which the new room will be attached |
| 150 | // baseface - the face on baseroomp to attach to |
| 151 | // placed_room - the number of the room to be attached |
| 152 | // placed_room_face the face on placed_room that's attached |
| 153 | void PlaceRoom(room *baseroomp, int baseface, int placed_room, int placed_room_face, int placed_room_door); |
| 154 | |
| 155 | // Lined up a placed room. Moves the placed room so the closest vert to basevert lines up exactly, |
| 156 | // and the edge from basevert to basevert+1 lines up with the corresponding edge on the placed room. |
| 157 | void SnapRoom(int basevert); |
| 158 | |
| 159 | // Attach an already-placed room |
| 160 | void AttachRoom(); |
| 161 | |
| 162 | // Creates a new bridge room connecting two rooms |
| 163 | // Parameters: attroomp,attface - one end of the new room |
| 164 | // baseroom,baseface - the other end of the new room |
| 165 | // The new room is created by extruding from attroom/attface |
| 166 | void BuildBridge(room *attroomp, int attface, room *baseroomp, int baseface); |
| 167 | |
| 168 | // Connects two rooms by changing the shape of one room to attach to the other |
| 169 | // Pretty similar to BuildBride(), but doesn't create a new room |
| 170 | // Parameters: attroomp,attface - one end of the new room |
| 171 | // baseroom,baseface - the other end of the new room |
| 172 | void JoinRooms(room *attroomp, int attface, room *baseroomp, int baseface); |
| 173 | |
| 174 | // Connects two rooms if they already match up exactly |
| 175 | // Parameters: attroomp,attface - one end of the new room |
| 176 | // baseroom,baseface - the other end of the new room |
| 177 | void JoinRoomsExact(room *attroomp, int attface, room *baseroomp, int baseface); |
| 178 | |
| 179 | // Combine two faces, if they can be combined |
| 180 | // Parameters: rp - the room the faces are in |
| 181 | // face0,face1 - the two faces |
| 182 | // Returns: true if the faces were combined, else false |
| 183 | // Note: The UV coordinates of the new face are derrived from face0 |
| 184 | bool CombineFaces(room *rp, int face0, int face1); |
| 185 | |
| 186 | // Deletes the given room from the mine |
| 187 | void DeleteRoomFromMine(room *rp); |
| 188 | |
| 189 | // Places a room a short distance from the specified room & face |
| 190 | // The new room is not attached to anything |
| 191 | // Parameters: baseroomp,baseface - the new room is dropped off of this face |
| 192 | // droproom_num - the room to be dropped |
| 193 | void DropRoom(room *baseroomp, int baseface, int droproom_num); |
| 194 | |
| 195 | // Place a room on the terrain for orientation before attachment |
| 196 | // Parameters: cellnum - the cell where the room is being placed |
| 197 | // placed_room - the number of the room to be attached |
| 198 | // placed_room_face the face on placed_room that's attached |
| 199 | void PlaceExternalRoom(int cellnum, int placed_room, int placed_room_face, bool align_to_terrain); |
| 200 | |
| 201 | // Find all the adjacent faces between two rooms and join them |
| 202 | void JoinAllAdjacentFaces(room *rp0, room *rp1); |
| 203 | |
| 204 | // Propagate a texture from one face to all the faces in the room |
| 205 | // If matching_faces_only is set, only propagate if the face has the same texture |
| 206 | void PropagateToAllFaces(room *rp, int facenum, bool matching_faces_only); |
| 207 | |
| 208 | // Splits a face unto triangles, by fanning |
| 209 | // Parameters: rp,facenum - the face to triangulate |
| 210 | // vertnum - the vert that is the base of the fan |
| 211 | void TriangulateFace(room *rp, int facenum, int vertnum); |
| 212 | |
| 213 | // Deletes the connection between two rooms. Deletes both portals. |
| 214 | void DeletePortalPair(room *rp, int portalnum); |
| 215 | |
| 216 | // Flips a face |
| 217 | void FlipFace(room *rp, int facenum); |
| 218 | |
| 219 | // Clips a pair of faces against each other. |
| 220 | // Produces one polygon in each face that is the intersection of the two input faces, |
| 221 | // and zero or more extra polygons, which are parts of the input faces outside the clipping faces. |
| 222 | // The input faces are replaced by the clipped faces, and new faces (formed by the parts of the input |
| 223 | // face outside the clip-against face) are added to the end of the room's facelist. |
| 224 | // This routine assumes that part or all of the being-clipped face is inside the clip-against face |
| 225 | // Parameters: rp0,face0 - the first room:face |
| 226 | // rp1,face1 - the second room:face |
| 227 | // Returns: true if the clip was ok, false if there was an error |
| 228 | bool ClipFacePair(room *rp0, int face0, room *rp1, int face1); |
| 229 | |
| 230 | // Takes two faces which are going to be made into a portal and makes them match exactly |
| 231 | // Alternatively, checks if the two faces can be matched |
| 232 | // After this function the two faces will have exactly the same vertices |
| 233 | // Parameters: rp0,facenum0 - one of the faces |
| 234 | // rp1,facenum1 - the other face |
| 235 | // check_only - if set, doesn't change anything; just checks the faces |
| 236 | // Returns the number of points added to the faces |
| 237 | // If just_checking set, returns true if faces match, else false |
| 238 | int MatchPortalFaces(room *rp0, int facenum0, room *rp1, int facenum1, bool check_only = 0); |
| 239 | |
| 240 | // Attempt to fix the cracks in a level |
| 241 | void FixCracks(); |
| 242 | |
| 243 | // Moves a vertex to lie on a specified edge |
| 244 | void SnapPointToEdge(room *rp, int vertnum, vector *v0, vector *v1); |
| 245 | |
| 246 | // Moves a vertex to lie on a specified plane |
| 247 | void SnapPointToFace(room *rp, int vertnum, vector *v0, vector *normal); |
| 248 | |
| 249 | // If this is not equal to -1, there's a snap that can maybe be undone |
| 250 | extern int Snap_roomnum; |
| 251 | |
| 252 | // Moves a vertex to be conincident with another vertex |
| 253 | void SnapPointToPoint(room *rp, int vertnum, room *snapto_rp, int snapto_vertnum); |
| 254 | |
| 255 | // Undoes the most recently-performed snap |
| 256 | void UndoSnap(); |
| 257 | |
| 258 | // Connects two rooms in a pleasing way |
| 259 | void BuildSmoothBridge(room *rp0, int facenum0, room *rp1, int facenum1); |
| 260 | |
| 261 | // Functions for building a new face |
| 262 | void AddNewFaceVert(); |
| 263 | void StartNewFace(); |
| 264 | void EndNewFace(); |
| 265 | |
| 266 | // Combine the two rooms. base_rp stays, att_rp goes away |
| 267 | // Returns true if combine sucessful, false if can't join |
| 268 | bool CombineRooms(room *base_rp, room *att_rp); |
| 269 | |
| 270 | // Creates a an external room and links the specified faces to it |
| 271 | // Parameters: rp - the room to connect to the new room |
| 272 | // nfaces - how many faces connect to the new room (this becomes the number of |
| 273 | //portals) facenums - the list of faces to connect |
| 274 | void LinkToExternalRoom(room *rp, int nfaces, int *facenums); |
| 275 | |
| 276 | // Deletes a point from a face |
| 277 | // Parameters: rp,facenum - the face we're deleting the point from |
| 278 | // vertindex - the vertex to delete |
| 279 | void DeletePointFromFace(room *rp, int facenum, int vertindex); |
| 280 | |
| 281 | // Incorporates the geometry from the specified object into the specified room. Deletes the object. |
| 282 | // Returns true if worked, false if some error |
| 283 | bool MergeObjectIntoRoom(room *rp, int objnum); |
| 284 | |
| 285 | // Delete all the faces connected to the specified face |
| 286 | void DeleteAllConnectedFaces(room *rp, int facenum); |
| 287 | |
| 288 | #endif // ifndef _HROOM_H |