pipeline.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. ////////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright 2016 RWS Inc, All Rights Reserved
  4. //
  5. // This program is free software; you can redistribute it and/or modify
  6. // it under the terms of version 2 of the GNU General Public License as published by
  7. // the Free Software Foundation
  8. //
  9. // This program is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU General Public License along
  15. // with this program; if not, write to the Free Software Foundation, Inc.,
  16. // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  17. //
  18. ///////////////////////////////////////////////////////////////
  19. // PIPELINE - History
  20. ///////////////////////////////////////////////////////////////
  21. //
  22. // 07/23/97 JRD Added support for generating shadows. Currently
  23. // all shadows are hard coded to be cast upon the
  24. // plane y = 0, based on postal needs.
  25. //
  26. ///////////////////////////////////////////////////////////////
  27. // This is the highest level considered actually part of the 3d engine.
  28. // It is the highest level control -> it decides how 3d pts map to 2d.
  29. // You can customize 3d efects by instantiating your own versions of the 3d pipeline!
  30. //
  31. #ifndef PIPELINE_H
  32. #define PIPELINE_H
  33. //==================================================
  34. #include "System.h"
  35. #ifdef PATHS_IN_INCLUDES
  36. #include "ORANGE/QuickMath/VectorMath.h"
  37. #include "GREEN/3D/types3d.h"
  38. #include "GREEN/3D/zbuffer.h"
  39. #include "GREEN/3D/render.h"
  40. #include "ORANGE/color/colormatch.h"
  41. #else
  42. #include "vectormath.h"
  43. #include "types3d.h"
  44. #include "zbuffer.h"
  45. #include "render.h"
  46. #include "ColorMatch.h"
  47. #endif
  48. //==================================================
  49. // The point of this class is to hold configurable
  50. // scratch space for doing trsnaformations
  51. //
  52. class RPipeLine
  53. {
  54. public:
  55. //-------------------------------------
  56. RPipeLine();
  57. ~RPipeLine();
  58. short Create(long lScratchSpace=0,short sZBufWidth=0);
  59. short CreateShadow(short sAngleY,double dTanDeclension,short sBufSize = -1);
  60. void Destroy(); // will NOT kill transform scratch space
  61. void Init();
  62. //-------------------------------------
  63. short NotCulled(RP3d *p1,RP3d *p2,RP3d *p3);
  64. void Transform(RSop* pPts,RTransform& tObj);
  65. void TransformShadow(RSop* pPts,RTransform& tObj,
  66. short sHeight = 0,short *psOffX = NULL,short *psOffY = NULL);
  67. // Do NOT use a z-buffer. Return offset to current position to
  68. // draw the image m_pimShadowBuf
  69. void RenderShadow(RImage* pimDst,RMesh* pMesh,UCHAR ucColor); // Unicolored!
  70. void Render(RImage* pimDst,short sDstX,short sDstY,
  71. RMesh* pMesh,UCHAR ucColor); // wire frame!
  72. // Flat shaded
  73. void Render(RImage* pimDst,short sDstX,short sDstY,
  74. RMesh* pMesh,RZBuffer* pZB,RTexture* pColors,
  75. short sOffsetX = 0, // In: 2D offset for pimDst and pZB.
  76. short sOffsetY = 0); // In: 2D offset for pimDst and pZB.
  77. // Note that pFog must be 256 x # of colors.
  78. // the offset value moves the fog towards
  79. // the front of the z-buffer
  80. //
  81. void Render(RImage* pimDst,short sDstX,short sDstY,
  82. RMesh* pMesh,RZBuffer* pZB,RTexture* pColors,
  83. short sFogOffset,RAlpha* pFog,
  84. short sOffsetX = 0, // In: 2D offset for pimDst and pZB.
  85. short sOffsetY = 0); // In: 2D offset for pimDst and pZB.
  86. // WARNING: May be inhomogeneous!
  87. void GetScreenXF(RTransform& tDst)
  88. {
  89. tDst.Make1();
  90. tDst.Mul(m_tScreen.T,m_tView.T);
  91. }
  92. // Strictly for convenience:
  93. //
  94. void ClearClipBuffer();
  95. void ClearShadowBuffer();
  96. // Project a point onto a screen.
  97. void PointToScreen(RTransform& tObj,RP3d& v3d,short &sDstX,short &sDstY)
  98. {
  99. RTransform tFull;
  100. RP3d ptDst;
  101. tFull.Make1();
  102. tFull.Mul(m_tView.T,tObj.T);
  103. tFull.PreMulBy(m_tScreen.T);
  104. tFull.TransformInto(v3d,ptDst);
  105. sDstX = short(ptDst.x);
  106. sDstY = short(ptDst.y);
  107. }
  108. // THIS WILL CHANGE WITH TIME:
  109. // Currently the bounding sphere is described by two points:
  110. //
  111. void BoundingSphereToScreen(RP3d& ptCenter, RP3d& ptRadius,
  112. RTransform& tObj);
  113. //-------------------------------------
  114. // Configurable by instance:
  115. RZBuffer* m_pZB;
  116. RImage* m_pimClipBuf; // For clipping (2 pass rendering)
  117. RTransform m_tScreen; // map to window
  118. RTransform m_tView; // lens
  119. RImage* m_pimShadowBuf; // For drawing shadows
  120. RTransform m_tShadow; // Turn it into a shadow
  121. double m_dShadowScale;// Needed extra parameter
  122. //-------------------------------------
  123. // WARNING: THIS WILL LIKELY CHANGE:
  124. // store a transformed bounding rect for object being rendered:
  125. // These are screend coordinates relative to the center of
  126. // the zbuf square / clipping square
  127. short m_sX; // far cube point
  128. short m_sY;
  129. short m_sZ;
  130. short m_sW;
  131. short m_sH;
  132. short m_sD;
  133. short m_sCenX; // for convenience - the cube center
  134. short m_sCenY; // in 3d screen coordinates
  135. short m_sCenZ;
  136. // TRUE of FALSE
  137. short m_sUseBoundingRect;
  138. //-------------------------------------
  139. // static storage:
  140. // Transformation buffer:
  141. static long ms_lNumPts;
  142. static RP3d* ms_pPts;
  143. static long ms_lNumPipes; // used to free ms_pPts
  144. };
  145. //==================================================
  146. //==================================================
  147. //==================================================
  148. #endif