1 /* 2 * Copyright 2011-2012 Arx Libertatis Team (see the AUTHORS file) 3 * 4 * This file is part of Arx Libertatis. 5 * 6 * Arx Libertatis is free software: you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License as published by 8 * the Free Software Foundation, either version 3 of the License, or 9 * (at your option) any later version. 10 * 11 * Arx Libertatis is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with Arx Libertatis. If not, see <http://www.gnu.org/licenses/>. 18 */ 19 /* Based on: 20 =========================================================================== 21 ARX FATALIS GPL Source Code 22 Copyright (C) 1999-2010 Arkane Studios SA, a ZeniMax Media company. 23 24 This file is part of the Arx Fatalis GPL Source Code ('Arx Fatalis Source Code'). 25 26 Arx Fatalis Source Code is free software: you can redistribute it and/or modify it under the terms of the GNU General Public 27 License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. 28 29 Arx Fatalis Source Code is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied 30 warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. 31 32 You should have received a copy of the GNU General Public License along with Arx Fatalis Source Code. If not, see 33 <http://www.gnu.org/licenses/>. 34 35 In addition, the Arx Fatalis Source Code is also subject to certain additional terms. You should have received a copy of these 36 additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Arx 37 Fatalis Source Code. If not, please request a copy in writing from Arkane Studios at the address below. 38 39 If you have questions concerning this license or the applicable additional terms, you may contact in writing Arkane Studios, c/o 40 ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. 41 =========================================================================== 42 */ 43 // Code: Cyril Meynier 44 // 45 // Copyright (c) 1999 ARKANE Studios SA. All rights reserved 46 47 #ifndef ARX_GRAPHICS_DATA_MESH_H 48 #define ARX_GRAPHICS_DATA_MESH_H 49 50 #include <set> 51 52 #include "graphics/GraphicsTypes.h" 53 #include "math/Rectangle.h" 54 55 class Entity; 56 57 void specialEE_RTP(TexturedVertex*,TexturedVertex*); 58 void EERIE_CreateMatriceProj(float _fWidth,float _fHeight,float _fFOV,float _fZNear,float _fZFar); 59 60 61 struct ANIM_HANDLE { 62 63 ANIM_HANDLE(); 64 65 res::path path; // empty path means an unallocated slot 66 67 EERIE_ANIM ** anims; 68 short alt_nb; 69 70 long locks; 71 72 }; 73 74 struct EERIE_TRANSFORM { 75 Vec3f pos; 76 float ycos; 77 float ysin; 78 float xsin; 79 float xcos; 80 float use_focal; 81 Vec2f mod; 82 }; 83 84 struct EERIE_CAMERA { 85 86 EERIE_TRANSFORM transform; 87 Vec3f pos; 88 float Ycos; 89 float Ysin; 90 float Xcos; 91 float Xsin; 92 float Zcos; 93 float Zsin; 94 float focal; 95 float use_focal; 96 float Zmul; 97 Vec2f pos2; 98 99 EERIEMATRIX matrix; 100 Anglef angle; 101 102 Vec3f d_pos; 103 Anglef d_angle; 104 Vec3f lasttarget; 105 Vec3f lastpos; 106 Vec3f translatetarget; 107 bool lastinfovalid; 108 Vec3f norm; 109 Color3f fadecolor; 110 Rect clip; 111 float clipz0; 112 float clipz1; 113 Vec2i center; 114 115 float smoothing; 116 long Xsnap; 117 long Zsnap; 118 float Zdiv; 119 120 long clip3D; 121 long type; 122 Color bkgcolor; // TODO was BGR! 123 long nbdrawn; 124 float cdepth; 125 126 Anglef size; 127 128 }; 129 130 struct EERIE_BKG_INFO 131 { 132 char treat; 133 char nothing; 134 short nbpoly; 135 short nbianchors; 136 short nbpolyin; 137 float frustrum_miny; 138 float frustrum_maxy; 139 EERIEPOLY * polydata; 140 EERIEPOLY ** polyin; 141 long * ianchors; // index on anchors list 142 long flags; 143 float tile_miny; 144 float tile_maxy; 145 }; 146 147 struct EERIE_SMINMAX 148 { 149 short min; 150 short max; 151 }; 152 153 #define FBD_TREAT 1 154 #define FBD_NOTHING 2 155 156 struct FAST_BKG_DATA 157 { 158 char treat; 159 char nothing; 160 short nbpoly; 161 short nbianchors; 162 short nbpolyin; 163 long flags; 164 float frustrum_miny; 165 float frustrum_maxy; 166 EERIEPOLY * polydata; 167 EERIEPOLY ** polyin; 168 long * ianchors; // index on anchors list 169 }; 170 #define MAX_BKGX 160 171 #define MAX_BKGZ 160 172 #define BKG_SIZX 100 173 #define BKG_SIZZ 100 174 175 struct ANCHOR_DATA; 176 177 struct EERIE_BACKGROUND 178 { 179 FAST_BKG_DATA fastdata[MAX_BKGX][MAX_BKGZ]; 180 long exist; 181 short Xsize; 182 short Zsize; 183 short Xdiv; 184 short Zdiv; 185 float Xmul; 186 float Zmul; 187 EERIE_BKG_INFO * Backg; 188 Color3f ambient; 189 Color3f ambient255; 190 EERIE_SMINMAX * minmax; 191 long nbanchors; 192 ANCHOR_DATA * anchors; 193 char name[256]; 194 }; 195 196 struct ANIM_USE; 197 198 #define MAX_TRANSPOL 512 199 200 #define CAM_SUBJVIEW 0 201 #define CAM_TOPVIEW 1 202 203 extern long EERIEDrawnPolys; 204 extern Vec3f BBOXMIN,BBOXMAX; 205 extern EERIE_BACKGROUND * ACTIVEBKG; 206 extern EERIE_CAMERA * ACTIVECAM; 207 208 extern float Xratio; 209 extern float Yratio; 210 211 float FirstPolyPosY(float x,float z); 212 void SetActiveCamera(EERIE_CAMERA* cam); 213 // Entity Struct End 214 215 void AcquireLastAnim(Entity * io); 216 void FinishAnim(Entity * io,ANIM_HANDLE * eanim); 217 bool Visible(Vec3f * orgn, Vec3f * dest,EERIEPOLY * epp,Vec3f * hit); 218 void FaceTarget(Entity * io); 219 220 void DebugSphere(float x, float y, float z, float siz, long tim, Color color); 221 222 EERIEPOLY * CheckTopPoly(float x,float y,float z); 223 EERIEPOLY * CheckPolyOnTop(float x,float y,float z); 224 EERIEPOLY * CheckInPoly(float x,float y,float z,float * needY = NULL); 225 EERIEPOLY * EECheckInPoly(const Vec3f * pos,float * needY = NULL); 226 EERIEPOLY * CheckInPolyIn(float x,float y,float z); 227 EERIEPOLY * CheckInPolyPrecis(float x,float y,float z,float * needY = NULL); 228 229 /*! 230 * Check if the given condition is under water. 231 * 232 * @return the lowest water polygon pos is under, or NULL if pos is not under water. 233 */ 234 EERIEPOLY * EEIsUnderWater(const Vec3f * pos); 235 236 /*! 237 * Check if the given condition is under water. 238 * 239 * @return any water polygon pos is under, or NULL if pos is not under water. 240 */ 241 EERIEPOLY * EEIsUnderWaterFast(const Vec3f * pos); 242 243 bool GetTruePolyY(const EERIEPOLY * ep, const Vec3f * pos,float * ret); 244 bool IsAnyPolyThere(float x, float z); 245 bool IsVertexIdxInGroup(EERIE_3DOBJ * eobj,long idx,long grs); 246 EERIEPOLY * GetMinPoly(float x, float y, float z); 247 EERIEPOLY * GetMaxPoly(float x, float y, float z); 248 249 float GetColorz(float x, float y, float z); 250 int PointIn2DPolyXZ(const EERIEPOLY * ep, float x, float z); 251 252 int EERIELaunchRay2(Vec3f * orgn, Vec3f * dest, Vec3f * hit, EERIEPOLY * tp, long flag); 253 int EERIELaunchRay3(Vec3f * orgn, Vec3f * dest, Vec3f * hit, EERIEPOLY * tp, long flag); 254 float GetGroundY(Vec3f * pos); 255 void EE_IRTP(TexturedVertex *in,TexturedVertex *out); 256 void EE_RTT(TexturedVertex *in,TexturedVertex *out); 257 258 void extEE_RTP(TexturedVertex *in,TexturedVertex *out); 259 void MakeColorz(Entity * io); 260 261 void EE_RotateX(TexturedVertex *in,TexturedVertex *out,float c, float s); 262 void EE_RotateY(TexturedVertex *in,TexturedVertex *out,float c, float s); 263 void EE_RotateZ(TexturedVertex *in,TexturedVertex *out,float c, float s); 264 void EE_RTP(TexturedVertex *in,TexturedVertex *out); 265 266 void GetAnimTotalTranslate( ANIM_HANDLE * eanim,long alt_idx,Vec3f * pos); 267 268 long PhysicalDrawBkgVLine(Vec3f * orgn,Vec3f * dest); 269 270 // FAST SAVE LOAD 271 bool FastSceneLoad(const res::path & path); 272 273 //**************************************************************************** 274 // DRAWING FUNCTIONS START 275 276 void DrawEERIEObjEx(EERIE_3DOBJ * eobj, Anglef * angle, Vec3f * pos, Vec3f * scale, Color3f * col); 277 void DrawEERIEObjExEx(EERIE_3DOBJ * eobj, Anglef * angle, Vec3f * pos, Vec3f * scale, int coll); 278 // DRAWING FUNCTIONS END 279 //**************************************************************************** 280 281 282 //**************************************************************************** 283 // BACKGROUND MANAGEMENT FUNCTIONS START 284 long BKG_CountPolys(EERIE_BACKGROUND * eb); 285 long BKG_CountChildPolys(EERIE_BACKGROUND * eb); 286 long BKG_CountIgnoredPolys(EERIE_BACKGROUND * eb); 287 288 #ifdef BUILD_EDIT_LOADSAVE 289 void SceneAddMultiScnToBackground(EERIE_MULTI3DSCENE * ms); 290 #endif 291 292 void ClearBackground(EERIE_BACKGROUND * eb); 293 int InitBkg(EERIE_BACKGROUND * eb, short sx, short sz, short Xdiv, short Zdiv); 294 295 void EERIEAddPoly(TexturedVertex * vert, TexturedVertex * vert2, TextureContainer * tex, long render, float transval); 296 // BACKGROUND MANAGEMENT FUNCTIONS END 297 //**************************************************************************** 298 299 300 //**************************************************************************** 301 // LIGHT FUNCTIONS START 302 void EERIEPrecalcLights(long minx=0,long minz=0,long maxx=99999,long maxz=99999); 303 void EERIERemovePrecalcLights(); 304 void PrecalcDynamicLighting(long x0,long x1,long z0,long z1); 305 void ApplyDynLight(EERIEPOLY *ep); 306 long GetFreeDynLight(); 307 // LIGHT FUNCTIONS END 308 //**************************************************************************** 309 310 311 //**************************************************************************** 312 // CAMERA FUNCTIONS START 313 void SetTargetCamera(EERIE_CAMERA * cam,float x,float y, float z); 314 void PrepareCamera(EERIE_CAMERA *cam); 315 void PrepareActiveCamera(); 316 // CAMERA FUNCTIONS END 317 //**************************************************************************** 318 319 //**************************************************************************** 320 // BBOX FUNCTIONS START 321 void ResetBBox3D(Entity * io); 322 void AddToBBox3D(Entity * io,Vec3f * pos); 323 // BBOX FUNCTIONS END 324 //**************************************************************************** 325 326 void ApplyLight(EERIEPOLY *ep); 327 long MakeTopObjString(Entity * io, std::string& dest); 328 void DeclareEGInfo(float x, float z); 329 bool TryToQuadify(EERIEPOLY * ep,EERIE_3DOBJ * eobj); 330 void ApplyWaterFXToVertex(Vec3f * odtv,TexturedVertex * dtv,float power); 331 int BackFaceCull2D(TexturedVertex * tv); 332 void ResetAnim(ANIM_USE * eanim); 333 334 //************************************************************************************* 335 //************************************************************************************* 336 337 long EERIERTPPoly(EERIEPOLY *ep); 338 339 void EE_RTP3(Vec3f * in, Vec3f * out, EERIE_CAMERA * cam); 340 341 void ReleaseAnimFromIO(Entity * io,long num); 342 343 void ShadowPolys_ClearZone(EERIE_BACKGROUND * eb,long x0, long y0, long x1, long y1); 344 short ANIM_GetAltIdx(ANIM_HANDLE * ah,long old); 345 void ANIM_Set(ANIM_USE * au,ANIM_HANDLE * anim); 346 347 bool LittleAngularDiff(Vec3f * norm,Vec3f * norm2); 348 void RecalcLight(EERIE_LIGHT * el); 349 void CreatePWorld(long x0,long x1,long z0,long z1); 350 void ComputeSworld(); 351 float PtIn2DPolyProj(EERIE_3DOBJ * obj,EERIE_FACE * ef, float x, float z); 352 float PtIn2DPolyProjV2(EERIE_3DOBJ * obj,EERIE_FACE * ef, float x, float z); 353 354 void ResetWorlds(); 355 float GetSWorld(float x,float y,float z); 356 357 void EERIE_ANIMMANAGER_PurgeUnused(); 358 void EERIE_ANIMMANAGER_ReleaseHandle(ANIM_HANDLE * anim); 359 ANIM_HANDLE * EERIE_ANIMMANAGER_Load(const res::path & path); 360 ANIM_HANDLE * EERIE_ANIMMANAGER_Load_NoWarning(const res::path & path); 361 void BkgAddShadowPoly(EERIEPOLY * ep,EERIEPOLY * father); 362 363 EERIEPOLY * GetMinNextPoly(long i,long j,EERIEPOLY * ep); 364 365 long GetVertexPos(Entity * io,long id,Vec3f * pos); 366 void ARX_PrepareBackgroundNRMLs(); 367 void DrawInWorld(); 368 long CountBkgVertex(); 369 void CreateInWorld(); 370 void EERIE_LIGHT_ChangeLighting(); 371 void SetCameraDepth(float depth); 372 373 extern void EERIETreatPoint(TexturedVertex *in,TexturedVertex *out); 374 extern void EERIETreatPoint2(TexturedVertex *in,TexturedVertex *out); 375 bool RayCollidingPoly(Vec3f * orgn,Vec3f * dest,EERIEPOLY * ep,Vec3f * hit); 376 377 void EERIEPOLY_Compute_PolyIn(); 378 void F_PrepareCamera(EERIE_CAMERA * cam); 379 380 float GetTileMinY(long i,long j); 381 float GetTileMaxY(long i,long j); 382 383 #define MAX_FRUSTRUMS 32 384 385 struct EERIE_FRUSTRUM_PLANE 386 { 387 float a; 388 float b; 389 float c; 390 float d; // dist to origin 391 }; 392 393 struct EERIE_FRUSTRUM 394 { 395 EERIE_FRUSTRUM_PLANE plane[4]; 396 long nb; 397 }; 398 399 struct EERIE_FRUSTRUM_DATA 400 { 401 long nb_frustrums; 402 EERIE_FRUSTRUM frustrums[MAX_FRUSTRUMS]; 403 }; 404 405 struct PORTAL_ROOM_DRAW 406 { 407 short count; 408 short flags; 409 EERIE_2D_BBOX bbox; 410 EERIE_FRUSTRUM_DATA frustrum; 411 }; 412 413 // Default Mode for Portals when found 414 #define NPC_ITEMS_AMBIENT_VALUE_255 35 415 416 struct ROOM_DIST_DATA 417 { 418 float distance; // -1 means use truedist 419 Vec3f startpos; 420 Vec3f endpos; 421 }; 422 423 extern ROOM_DIST_DATA * RoomDistance; 424 425 void UpdateIORoom(Entity * io); 426 float SP_GetRoomDist(Vec3f * pos,Vec3f * c_pos,long io_room,long Cam_Room); 427 float CEDRIC_PtIn2DPolyProjV2(EERIE_3DOBJ * obj,EERIE_FACE * ef, float x, float z); 428 void EERIE_PORTAL_ReleaseOnlyVertexBuffer(); 429 void ComputePortalVertexBuffer(); 430 bool GetNameInfo( const std::string& name1,long& type,long& val1,long& val2); 431 432 struct TILE_LIGHTS 433 { 434 short num; 435 short max; 436 EERIE_LIGHT ** el; 437 }; 438 439 #endif // ARX_GRAPHICS_DATA_MESH_H 440