ZClip.cpp 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. /*
  2. ===========================================================================
  3. Doom 3 GPL Source Code
  4. Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
  5. This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
  6. Doom 3 Source Code 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. Doom 3 Source Code 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. You should have received a copy of the GNU General Public License
  15. along with Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>.
  16. In addition, the Doom 3 Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 Source Code. If not, please request a copy in writing from id Software at the address below.
  17. If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
  18. ===========================================================================
  19. */
  20. #include "../../idlib/precompiled.h"
  21. #pragma hdrstop
  22. #include "qe3.h"
  23. #include "Radiant.h"
  24. #include "zclip.h"
  25. CZClip::CZClip()
  26. {
  27. LONG
  28. lSize = sizeof(m_bEnabled);
  29. if (!LoadRegistryInfo("radiant_ZClipEnabled", &m_bEnabled, &lSize))
  30. m_bEnabled = false;
  31. lSize = sizeof(m_iZClipTop);
  32. if (!LoadRegistryInfo("radiant_ZClipTop", &m_iZClipTop, &lSize))
  33. m_iZClipTop = 64;
  34. lSize = sizeof(m_iZClipBottom);
  35. if (!LoadRegistryInfo("radiant_ZClipBottom", &m_iZClipBottom, &lSize))
  36. m_iZClipBottom = -64;
  37. Legalise();
  38. }
  39. CZClip::~CZClip()
  40. {
  41. // TODO: registry save
  42. SaveRegistryInfo("radiant_ZClipEnabled", &m_bEnabled, sizeof(m_bEnabled));
  43. SaveRegistryInfo("radiant_ZClipTop", &m_iZClipTop, sizeof(m_iZClipTop));
  44. SaveRegistryInfo("radiant_ZClipBottom", &m_iZClipBottom, sizeof(m_iZClipBottom));
  45. }
  46. void CZClip::Reset(void)
  47. {
  48. m_iZClipTop = 64; // arb. starting values, but must be at least 64 apart
  49. m_iZClipBottom = -64;
  50. m_bEnabled = false;
  51. Legalise();
  52. }
  53. int CZClip::GetTop(void)
  54. {
  55. return m_iZClipTop;
  56. }
  57. int CZClip::GetBottom(void)
  58. {
  59. return m_iZClipBottom;
  60. }
  61. void CZClip::Legalise(void)
  62. {
  63. // need swapping?
  64. //
  65. if (m_iZClipTop < m_iZClipBottom)
  66. {
  67. int iTemp = m_iZClipTop;
  68. m_iZClipTop = m_iZClipBottom;
  69. m_iZClipBottom = iTemp;
  70. }
  71. // too close together?
  72. //
  73. #define ZCLIP_MIN_SPACING 64
  74. if (abs(m_iZClipTop - m_iZClipBottom) < ZCLIP_MIN_SPACING)
  75. m_iZClipBottom = m_iZClipTop - ZCLIP_MIN_SPACING;
  76. }
  77. void CZClip::SetTop(int iNewZ)
  78. {
  79. m_iZClipTop = iNewZ;
  80. Legalise();
  81. }
  82. void CZClip::SetBottom(int iNewZ)
  83. {
  84. m_iZClipBottom = iNewZ;
  85. Legalise();
  86. }
  87. bool CZClip::IsEnabled(void)
  88. {
  89. return m_bEnabled;
  90. }
  91. bool CZClip::Enable(bool bOnOff)
  92. {
  93. m_bEnabled = !m_bEnabled;
  94. return IsEnabled();
  95. }
  96. #define ZCLIP_BAR_THICKNESS 8
  97. #define ZCLIP_ARROWHEIGHT (ZCLIP_BAR_THICKNESS*8)
  98. void CZClip::Paint(void)
  99. {
  100. float x, y;
  101. int xCam = z.width/4; // hmmm, a rather unpleasant and obscure global name, but it was already called that so...
  102. qglColor3f (ZCLIP_COLOUR);//1.0, 0.0, 1.0);
  103. // draw TOP marker...
  104. //
  105. x = 0;
  106. y = m_iZClipTop;
  107. if (m_bEnabled)
  108. qglBegin(GL_QUADS);
  109. else
  110. qglBegin(GL_LINE_LOOP);
  111. qglVertex3f (x-xCam,y,0);
  112. qglVertex3f (x-xCam,y+ZCLIP_BAR_THICKNESS,0);
  113. qglVertex3f (x+xCam,y+ZCLIP_BAR_THICKNESS,0);
  114. qglVertex3f (x+xCam,y,0);
  115. qglEnd ();
  116. qglColor3f (ZCLIP_COLOUR_DIM);//0.8, 0.0, 0.8);
  117. if (m_bEnabled)
  118. qglBegin(GL_TRIANGLES);
  119. else
  120. qglBegin(GL_LINE_LOOP);
  121. qglVertex3f (x,(y+ZCLIP_BAR_THICKNESS),0);
  122. qglVertex3f (x-xCam,(y+ZCLIP_BAR_THICKNESS)+(ZCLIP_ARROWHEIGHT/2),0);
  123. qglVertex3f (x+xCam,(y+ZCLIP_BAR_THICKNESS)+(ZCLIP_ARROWHEIGHT/2),0);
  124. qglEnd ();
  125. // draw bottom marker...
  126. //
  127. qglColor3f (ZCLIP_COLOUR);//1.0, 0.0, 1.0);
  128. x = 0;
  129. y = m_iZClipBottom;
  130. if (m_bEnabled)
  131. qglBegin(GL_QUADS);
  132. else
  133. qglBegin(GL_LINE_LOOP);
  134. qglVertex3f (x-xCam,y,0);
  135. qglVertex3f (x-xCam,y-ZCLIP_BAR_THICKNESS,0);
  136. qglVertex3f (x+xCam,y-ZCLIP_BAR_THICKNESS,0);
  137. qglVertex3f (x+xCam,y,0);
  138. qglEnd ();
  139. qglColor3f (ZCLIP_COLOUR_DIM);//0.8, 0.0, 0.8);
  140. if (m_bEnabled)
  141. qglBegin(GL_TRIANGLES);
  142. else
  143. qglBegin(GL_LINE_LOOP);
  144. qglVertex3f (x,(y-ZCLIP_BAR_THICKNESS),0);
  145. qglVertex3f (x-xCam,(y-ZCLIP_BAR_THICKNESS)-(ZCLIP_ARROWHEIGHT/2),0);
  146. qglVertex3f (x+xCam,(y-ZCLIP_BAR_THICKNESS)-(ZCLIP_ARROWHEIGHT/2),0);
  147. qglEnd ();
  148. }
  149. ///////////////// eof ///////////////////