renderer.cpp 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. /*
  2. Copyright (C) 1999-2006 Id Software, Inc. and contributors.
  3. For a list of contributors, see the accompanying CONTRIBUTORS file.
  4. This file is part of GtkRadiant.
  5. GtkRadiant 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 2 of the License, or
  8. (at your option) any later version.
  9. GtkRadiant 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. You should have received a copy of the GNU General Public License
  14. along with GtkRadiant; if not, write to the Free Software
  15. Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  16. */
  17. /*
  18. Camera plugin for GtkRadiant
  19. Copyright (C) 2002 Splash Damage Ltd.
  20. */
  21. #include "camera.h"
  22. CRenderer::CRenderer() {
  23. refCount = 1;
  24. m_bHooked = FALSE;
  25. Register();
  26. Initialize();
  27. }
  28. CRenderer::~CRenderer() {
  29. if( m_bHooked )
  30. UnRegister();
  31. }
  32. void CRenderer::Register() {
  33. g_QglTable.m_pfnHookGL2DWindow( this );
  34. g_QglTable.m_pfnHookGL3DWindow( this );
  35. m_bHooked = TRUE;
  36. }
  37. void CRenderer::UnRegister() {
  38. if( g_QglTable.m_nSize ) {
  39. g_QglTable.m_pfnUnHookGL2DWindow( this );
  40. g_QglTable.m_pfnUnHookGL3DWindow( this );
  41. }
  42. m_bHooked = FALSE;
  43. }
  44. void CRenderer::Initialize() {
  45. }
  46. void CRenderer::Draw2D( VIEWTYPE vt ) {
  47. g_QglTable.m_pfn_qglPushAttrib(GL_ALL_ATTRIB_BITS);
  48. g_QglTable.m_pfn_qglPushMatrix();
  49. switch(vt)
  50. {
  51. case XY:
  52. break;
  53. case XZ:
  54. g_QglTable.m_pfn_qglRotatef(270.0f, 1.0f, 0.0f, 0.0f);
  55. break;
  56. case YZ:
  57. g_QglTable.m_pfn_qglRotatef(270.0f, 1.0f, 0.0f, 0.0f);
  58. g_QglTable.m_pfn_qglRotatef(270.0f, 0.0f, 0.0f, 1.0f);
  59. break;
  60. }
  61. CCamera *cam = firstCam;
  62. while( cam ) {
  63. cam->GetCam()->draw( ((Listener && cam == g_pCurrentEditCam) ? true : false) );
  64. cam = cam->GetNext();
  65. }
  66. g_QglTable.m_pfn_qglPopMatrix();
  67. g_QglTable.m_pfn_qglPopAttrib();
  68. }
  69. void CRenderer::Draw3D() {
  70. // FIXME: really need a mainloop callback from the editor core
  71. static long start;
  72. static float cycle;
  73. static long msecs;
  74. static long current;
  75. if( g_iPreviewRunning ) {
  76. if( g_iPreviewRunning == 1 ) {
  77. start = Q_QGetTickCount();
  78. GetCurrentCam()->GetCam()->startCamera( start );
  79. cycle = GetCurrentCam()->GetCam()->getTotalTime();
  80. msecs = (long)(cycle * 1000);
  81. current = start;
  82. g_iPreviewRunning = 2;
  83. }
  84. if( current < start + msecs ) {
  85. float fov;
  86. vec3_t origin = {0.0f, 0.0f, 0.0f}, dir = {0.0f, 0.0f, 0.0f}, angles;
  87. GetCurrentCam()->GetCam()->getCameraInfo( current, &origin[0], &dir[0], &fov );
  88. VectorSet( angles, asin (dir[2])*180/3.14159, atan2 (dir[1], dir[0])*180/3.14159, 0 );
  89. g_CameraTable.m_pfnSetCamera( origin, angles );
  90. current = Q_QGetTickCount();
  91. } else {
  92. g_iPreviewRunning = 0;
  93. GetCurrentCam()->GetCam()->setRunning( false );
  94. g_FuncTable.m_pfnSysUpdateWindows( W_XY_OVERLAY | W_CAMERA );
  95. }
  96. }
  97. g_QglTable.m_pfn_qglPushAttrib(GL_ALL_ATTRIB_BITS);
  98. CCamera *cam = firstCam;
  99. while( cam ) {
  100. cam->GetCam()->draw( ((Listener && cam == g_pCurrentEditCam) ? true : false) );
  101. cam = cam->GetNext();
  102. }
  103. if( g_iPreviewRunning ) {
  104. int x, y, width, height, i;
  105. float degInRad;
  106. g_CameraTable.m_pfnGetCamWindowExtents( &x, &y, &width, &height );
  107. // setup orthographic projection mode
  108. g_QglTable.m_pfn_qglMatrixMode(GL_PROJECTION);
  109. g_QglTable.m_pfn_qglLoadIdentity();
  110. g_QglTable.m_pfn_qglDisable( GL_DEPTH_TEST );
  111. g_QglTable.m_pfn_qglOrtho( 0, (float)width, 0, (float)height, -100, 100 );
  112. g_QglTable.m_pfn_qglMatrixMode( GL_MODELVIEW );
  113. g_QglTable.m_pfn_qglLoadIdentity();
  114. g_QglTable.m_pfn_qglColor3f( 1.f, 1.f, 1.f );
  115. g_QglTable.m_pfn_qglBegin( GL_LINE_LOOP );
  116. g_QglTable.m_pfn_qglVertex2f( 10, 10 );
  117. g_QglTable.m_pfn_qglVertex2f( 40, 10 );
  118. g_QglTable.m_pfn_qglVertex2f( 40, 25 );
  119. g_QglTable.m_pfn_qglVertex2f( 10, 25 );
  120. g_QglTable.m_pfn_qglEnd();
  121. g_QglTable.m_pfn_qglBegin( GL_LINE_LOOP );
  122. for( i = 0; i < 360; i += 60 ) {
  123. degInRad = i * (3.14159265358979323846/180.f);
  124. g_QglTable.m_pfn_qglVertex2f( 18 + cos(degInRad) * 5, 18 + sin(degInRad) * 5 );
  125. }
  126. g_QglTable.m_pfn_qglEnd();
  127. degInRad = (360-((current - start) % 360)) * (3.14159265358979323846/180.f);
  128. g_QglTable.m_pfn_qglBegin( GL_LINES );
  129. g_QglTable.m_pfn_qglVertex2f( 18, 18 );
  130. g_QglTable.m_pfn_qglVertex2f( 18 + cos(degInRad) * 5, 18 + sin(degInRad) * 5 );
  131. g_QglTable.m_pfn_qglVertex2f( 32, 18 );
  132. g_QglTable.m_pfn_qglVertex2f( 32 + cos(degInRad) * 5, 18 + sin(degInRad) * 5 );
  133. g_QglTable.m_pfn_qglEnd();
  134. g_QglTable.m_pfn_qglBegin( GL_LINE_LOOP );
  135. for( i = 0; i < 360; i += 60 ) {
  136. degInRad = i * (3.14159265358979323846/180.f);
  137. g_QglTable.m_pfn_qglVertex2f( 32 + cos(degInRad) * 5, 18 + sin(degInRad) * 5 );
  138. }
  139. g_QglTable.m_pfn_qglEnd();
  140. g_QglTable.m_pfn_qglBegin( GL_LINES );
  141. g_QglTable.m_pfn_qglVertex2f( 40, 22 );
  142. g_QglTable.m_pfn_qglVertex2f( 52, 31 );
  143. g_QglTable.m_pfn_qglVertex2f( 40, 13 );
  144. g_QglTable.m_pfn_qglVertex2f( 52, 4 );
  145. g_QglTable.m_pfn_qglEnd();
  146. }
  147. g_QglTable.m_pfn_qglPopAttrib();
  148. }