Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

171 lines
4.1 KiB

  1. /******************************Module*Header*******************************\
  2. * Module Name: view.cxx
  3. *
  4. * Copyright (c) 1995 Microsoft Corporation
  5. *
  6. \**************************************************************************/
  7. #include <stdio.h>
  8. #include <string.h>
  9. #include <stdlib.h>
  10. #include <math.h>
  11. #include <sys/types.h>
  12. #include <sys/timeb.h>
  13. #include <time.h>
  14. #include <windows.h>
  15. #include "sspipes.h"
  16. #include "view.h"
  17. /******************************Public*Routine******************************\
  18. * VIEW constructor
  19. *
  20. * Nov. 95 [marcfo]
  21. *
  22. \**************************************************************************/
  23. VIEW::VIEW()
  24. {
  25. bProjMode = GL_TRUE;
  26. // set some initial viewing and size params
  27. //mf: these should be defines
  28. zTrans = -75.0f;
  29. viewDist = -zTrans;
  30. numDiv = NUM_DIV;
  31. SS_ASSERT( numDiv >= 2, "VIEW constructor: not enough divisions\n" );
  32. // Because number of nodes in a dimension is derived from (numDiv-1), and
  33. // can't be 0
  34. divSize = 7.0f;
  35. persp.viewAngle = 90.0f;
  36. persp.zNear = 1.0f;
  37. yRot = 0.0f;
  38. winSize.width = winSize.height = 0;
  39. }
  40. /******************************Public*Routine******************************\
  41. * SetProjMatrix
  42. *
  43. * Set GL view parameters
  44. *
  45. * Nov. 95 [marcfo]
  46. *
  47. \**************************************************************************/
  48. void
  49. VIEW::SetGLView()
  50. {
  51. glViewport(0, 0, winSize.width, winSize.height );
  52. SetProjMatrix();
  53. }
  54. /******************************Public*Routine******************************\
  55. * SetProjMatrix
  56. *
  57. * Set Projection matrix
  58. *
  59. * Nov. 95 [marcfo]
  60. *
  61. \**************************************************************************/
  62. void
  63. VIEW::SetProjMatrix()
  64. {
  65. glMatrixMode(GL_PROJECTION);
  66. glLoadIdentity();
  67. persp.zFar = viewDist + world.z*2;
  68. if( bProjMode ) {
  69. gluPerspective( persp.viewAngle,
  70. aspectRatio,
  71. persp.zNear, persp.zFar );
  72. }
  73. else {
  74. glOrtho( -world.x/2, world.x/2, -world.y/2, world.y/2,
  75. -world.z, world.z );
  76. }
  77. glMatrixMode(GL_MODELVIEW);
  78. }
  79. /******************************Public*Routine******************************\
  80. * CalcNodeArraySize
  81. *
  82. * Based on the viewing width and height, and numDiv, calculate the x,y,z array
  83. * node dimensions.
  84. *
  85. \**************************************************************************/
  86. void
  87. VIEW::CalcNodeArraySize( IPOINT3D *pNodeDim )
  88. {
  89. // mf: !!! if aspect ratio deviates too much from 1, then nodes will get
  90. // clipped as view rotates
  91. if( winSize.width >= winSize.height ) {
  92. pNodeDim->x = numDiv - 1;
  93. pNodeDim->y = (int) (pNodeDim->x / aspectRatio) ;
  94. if( pNodeDim->y < 1 )
  95. pNodeDim->y = 1;
  96. pNodeDim->z = pNodeDim->x;
  97. }
  98. else {
  99. pNodeDim->y = numDiv - 1;
  100. pNodeDim->x = (int) (aspectRatio * pNodeDim->y);
  101. if( pNodeDim->x < 1 )
  102. pNodeDim->x = 1;
  103. pNodeDim->z = pNodeDim->y;
  104. }
  105. }
  106. /******************************Public*Routine******************************\
  107. * SetWinSize
  108. *
  109. * Set the window size for the view, derive other view params.
  110. *
  111. * Return FALSE if new size same as old.
  112. \**************************************************************************/
  113. BOOL
  114. VIEW::SetWinSize( int width, int height )
  115. {
  116. if( (width == winSize.width) &&
  117. (height == winSize.height) )
  118. return FALSE;
  119. winSize.width = width;
  120. winSize.height = height;
  121. aspectRatio = winSize.height == 0 ? 1.0f : (float)winSize.width/winSize.height;
  122. if( winSize.width >= winSize.height ) {
  123. world.x = numDiv * divSize;
  124. world.y = world.x / aspectRatio;
  125. world.z = world.x;
  126. }
  127. else {
  128. world.y = numDiv * divSize;
  129. world.x = world.y * aspectRatio;
  130. world.z = world.y;
  131. }
  132. return TRUE;
  133. }
  134. /******************************Public*Routine******************************\
  135. * SetSceneRotation
  136. *
  137. \**************************************************************************/
  138. void
  139. VIEW::IncrementSceneRotation()
  140. {
  141. yRot += 9.73156f;
  142. if( yRot >= 360.0f )
  143. // prevent overflow
  144. yRot -= 360.0f;
  145. }