Render.h 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. /* Copyright (c) 2002-2012 Croteam Ltd.
  2. This program is free software; you can redistribute it and/or modify
  3. it under the terms of version 2 of the GNU General Public License as published by
  4. the Free Software Foundation
  5. This program is distributed in the hope that it will be useful,
  6. but WITHOUT ANY WARRANTY; without even the implied warranty of
  7. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  8. GNU General Public License for more details.
  9. You should have received a copy of the GNU General Public License along
  10. with this program; if not, write to the Free Software Foundation, Inc.,
  11. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */
  12. #ifndef SE_INCL_RENDER_H
  13. #define SE_INCL_RENDER_H
  14. #ifdef PRAGMA_ONCE
  15. #pragma once
  16. #endif
  17. #include <Engine/Math/Vector.h>
  18. #include <Engine/Math/Quaternion.h>
  19. #include <Engine/Ska/ModelInstance.h>
  20. #include <Engine/Ska/Skeleton.h>
  21. #include <Engine/Ska/Mesh.h>
  22. #include <Engine/World/WorldRayCasting.h>
  23. #define RMF_WIREFRAME (1UL<<0) // set wireframe on
  24. #define RMF_SHOWTEXTURE (1UL<<1) // show texture
  25. #define RMF_SHOWNORMALS (1UL<<2) // show normalas
  26. #define RMF_SHOWSKELETON (1UL<<3) // show skeleton
  27. #define RMF_SHOWACTIVEBONES (1UL<<4) // show active bones
  28. #define SRMF_ATTACHMENT (1UL<<0) // set for attachment render models
  29. #define SRMF_FOG (1UL<<1) // render in fog
  30. #define SRMF_HAZE (1UL<<2) // render in haze
  31. #define SRMF_SPECTATOR (1UL<<3) // model will not be rendered but shadows might
  32. #define SRMF_INVERTED (1UL<<4) // stretch is inverted
  33. #define SRMF_BBOXSET (1UL<<5) // bounding box has been calculated
  34. #define SRMF_INSIDE (1UL<<6) // doesn't need clipping to frustum
  35. #define SRMF_INMIRROR (1UL<<7) // doesn't need clipping to mirror/warp plane
  36. #define SRMF_WEAPON (1UL<<8) // TEMP: weapon model is rendering so don't use ATI's Truform!
  37. typedef FLOAT FLOAT3[3];
  38. // Rendering structures
  39. struct RenModel
  40. {
  41. CModelInstance *rm_pmiModel;// pointer to model instance
  42. INDEX rm_iParentModelIndex; // index of parent renmodel
  43. INDEX rm_iParentBoneIndex; // index of parent bone this model is attached to
  44. Matrix12 rm_mTransform; // Tranform matrix for models without skeletons
  45. Matrix12 rm_mStrTransform; // Stretch transform matrix for models without skeleton
  46. INDEX rm_iSkeletonLODIndex; // index of current skeleton lod
  47. INDEX rm_iFirstBone; // index if first renbone
  48. INDEX rm_ctBones; // renbones count for this renmodel
  49. INDEX rm_iFirstMesh; // index of first renmesh
  50. INDEX rm_ctMeshes; // meshes count for this renmodel
  51. INDEX rm_iFirstChildModel;
  52. INDEX rm_iNextSiblingModel;
  53. };
  54. struct RenBone
  55. {
  56. SkeletonBone *rb_psbBone; // pointer to skeleton bone
  57. INDEX rb_iParentIndex; // index of parent renbone
  58. INDEX rb_iRenModelIndex; // index of renmodel
  59. AnimPos rb_apPos;
  60. AnimRot rb_arRot;
  61. Matrix12 rb_mTransform; // Transformation matrix for this ren bone
  62. Matrix12 rb_mStrTransform; // Stretched transformation matrix for this ren bone
  63. Matrix12 rb_mBonePlacement; // Placement of bone in absolute space
  64. };
  65. struct RenMorph
  66. {
  67. MeshMorphMap *rmp_pmmmMorphMap;
  68. FLOAT rmp_fFactor;
  69. };
  70. struct RenWeight
  71. {
  72. MeshWeightMap *rw_pwmWeightMap;
  73. INDEX rw_iBoneIndex;
  74. };
  75. struct RenMesh
  76. {
  77. struct MeshInstance *rmsh_pMeshInst;
  78. INDEX rmsh_iRenModelIndex;
  79. INDEX rmsh_iFirstWeight;
  80. INDEX rmsh_ctWeights;
  81. INDEX rmsh_iFirstMorph;
  82. INDEX rmsh_ctMorphs;
  83. INDEX rmsh_iMeshLODIndex; // curent LOD index of msh_aMeshLODs array in Mesh
  84. BOOL rmsh_bTransToViewSpace; // Is mesh transformed to view space
  85. };
  86. // initialize batch model rendering
  87. ENGINE_API void RM_BeginRenderingView(CAnyProjection3D &apr, CDrawPort *pdp);
  88. ENGINE_API void RM_BeginModelRenderingMask( CAnyProjection3D &prProjection,
  89. UBYTE *pubMask, SLONG slMaskWidth, SLONG slMaskHeight);
  90. // cleanup after batch model rendering
  91. ENGINE_API void RM_EndRenderingView( BOOL bRestoreOrtho=TRUE);
  92. ENGINE_API void RM_EndModelRenderingMask(void);
  93. // setup light parameters
  94. ENGINE_API void RM_SetLightColor(COLOR colAmbient, COLOR colLight);
  95. ENGINE_API void RM_SetLightDirection(FLOAT3D &vLightDir);
  96. // LOD factor management
  97. ENGINE_API void RM_SetCurrentDistance(FLOAT fDistFactor);
  98. ENGINE_API FLOAT RM_GetMipFactor(void);
  99. // setup object position
  100. ENGINE_API void RM_SetObjectPlacement(const CPlacement3D &pl);
  101. ENGINE_API void RM_SetObjectPlacement(const FLOATmatrix3D &m, const FLOAT3D &v);
  102. ENGINE_API void RM_SetObjectMatrices(CModelInstance &mi);
  103. // render one SKA model with its children
  104. ENGINE_API void RM_RenderSKA(CModelInstance &mi);
  105. // render one bone in model instance
  106. ENGINE_API void RM_RenderBone(CModelInstance &mi,INDEX iBoneID);
  107. ENGINE_API void RM_RenderColisionBox(CModelInstance &mi,ColisionBox &cb, COLOR col);
  108. // lods
  109. ENGINE_API void RM_SetCustomMeshLodDistance(FLOAT fMeshLod);
  110. ENGINE_API void RM_SetCustomSkeletonLodDistance(FLOAT fSkeletonLod);
  111. ENGINE_API void RM_RenderGround(CTextureObject &to);
  112. // Returns specified renbone
  113. ENGINE_API RenBone *RM_FindRenBone(INDEX iBoneID);
  114. // Returns renbone array and sets renbone count
  115. ENGINE_API RenBone *RM_GetRenBoneArray(INDEX &ctrb);
  116. // Returns true if bone exists and sets two given vectors as start and end point of specified bone
  117. ENGINE_API BOOL RM_GetBoneAbsPosition(CModelInstance &mi,INDEX iBoneID, FLOAT3D &vStartPoint, FLOAT3D &vEndPoint);
  118. // Returns Renbone
  119. ENGINE_API BOOL RM_GetRenBoneAbs(CModelInstance &mi,INDEX iBoneID,RenBone &rb);
  120. ENGINE_API void RM_AddSimpleShadow_View(CModelInstance &mi, const FLOAT fIntensity, const FLOATplane3D &plShadowPlane);
  121. ENGINE_API void RM_GetModelVertices( CModelInstance &mi, CStaticStackArray<FLOAT3D> &avVertices, FLOATmatrix3D &mRotation,
  122. FLOAT3D &vPosition, FLOAT fNormalOffset, FLOAT fDistance);
  123. // test if the ray hit any of model instance's triangles and return
  124. ENGINE_API FLOAT RM_TestRayCastHit( CModelInstance &mi, FLOATmatrix3D &mRotation, FLOAT3D &vPosition,const FLOAT3D &vOrigin, const FLOAT3D &vTarget,FLOAT fOldDistance,INDEX *piBoneID);
  125. ENGINE_API void RM_SetBoneAdjustCallback(void (*pAdjustBones)(void *pData), void *pData);
  126. ENGINE_API void RM_SetShaderParamsAdjustCallback(void (*pAdjustShaderParams)(void *pData, INDEX iSurfaceID, CShader *pShader,ShaderParams &shParams),void *pData);
  127. // Matrix12 operations
  128. ENGINE_API void Matrix12ToQVect(QVect &qv,const Matrix12 &m12);
  129. ENGINE_API void MatrixVectorToMatrix12(Matrix12 &m12,const FLOATmatrix3D &m, const FLOAT3D &v);
  130. ENGINE_API void Matrix12ToMatrixVector(FLOATmatrix3D &c, FLOAT3D &v, const Matrix12 &m12);
  131. ENGINE_API void QVectToMatrix12(Matrix12 &m12, const QVect &qv);
  132. ENGINE_API void MatrixMultiply(Matrix12 &c,const Matrix12 &m, const Matrix12 &n);
  133. ENGINE_API void MatrixMultiplyCP(Matrix12 &c,const Matrix12 &m, const Matrix12 &n);
  134. ENGINE_API void MatrixTranspose(Matrix12 &r, const Matrix12 &m);
  135. ENGINE_API void TransformVertex(GFXVertex &v, const Matrix12 &m);
  136. ENGINE_API void RotateVector(FLOAT3 &v, const Matrix12 &m);
  137. // model flags
  138. ENGINE_API void RM_SetFlags(ULONG ulNewFlags);
  139. ENGINE_API ULONG RM_GetFlags();
  140. ENGINE_API void RM_AddFlag(ULONG ulFlag);
  141. ENGINE_API void RM_RemoveFlag(ULONG ulFlag);
  142. ENGINE_API ULONG &RM_GetRenderFlags();
  143. ENGINE_API void RM_DoFogAndHaze(BOOL bOpaque);
  144. #endif /* include-once check. */