Leaked source code of windows server 2003
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.

144 lines
4.2 KiB

  1. //-----------------------------------------------------------------------------
  2. // File: view.cpp
  3. //
  4. // Desc:
  5. //
  6. // Copyright (c) 2000 Microsoft Corporation. All rights reserved.
  7. //-----------------------------------------------------------------------------
  8. #include "stdafx.h"
  9. //-----------------------------------------------------------------------------
  10. // Name:
  11. // Desc: VIEW constructor
  12. //-----------------------------------------------------------------------------
  13. VIEW::VIEW()
  14. {
  15. m_bProjMode = TRUE;
  16. // set some initial viewing and size params
  17. m_zTrans = -75.0f;
  18. m_viewDist = -m_zTrans;
  19. m_numDiv = NUM_DIV;
  20. assert( m_numDiv >= 2 && "VIEW constructor: not enough divisions\n" );
  21. // Because number of nodes in a dimension is derived from (numDiv-1), and
  22. // can't be 0
  23. m_divSize = 7.0f;
  24. m_persp.viewAngle = D3DX_PI / 2.0f; //90.0f;
  25. m_persp.zNear = 1.0f;
  26. m_yRot = 0.0f;
  27. m_winSize.width = m_winSize.height = 0;
  28. }
  29. //-----------------------------------------------------------------------------
  30. // Name: SetProjMatrix
  31. // Desc: Set Projection matrix
  32. //-----------------------------------------------------------------------------
  33. void VIEW::SetProjMatrix( IDirect3DDevice8* pd3dDevice )
  34. {
  35. // Rotate the camera about the y-axis
  36. D3DXVECTOR3 vFromPt = D3DXVECTOR3( 0.0f, 0.0f, -m_zTrans );
  37. D3DXVECTOR3 vLookatPt = D3DXVECTOR3( 0.0f, 0.0f, 0.0f );
  38. D3DXVECTOR3 vUpVec = D3DXVECTOR3( 0.0f, 1.0f, 0.0f );
  39. D3DXMATRIX matView;
  40. D3DXMatrixLookAtLH( &matView, &vFromPt, &vLookatPt, &vUpVec );
  41. pd3dDevice->SetTransform( D3DTS_VIEW, &matView );
  42. // Set the projection matrix
  43. D3DXMATRIX matProj;
  44. D3DXMatrixPerspectiveFovLH( &matProj, m_persp.viewAngle, m_aspectRatio, m_persp.zNear, m_persp.zFar );
  45. pd3dDevice->SetTransform( D3DTS_PROJECTION, &matProj );
  46. }
  47. //-----------------------------------------------------------------------------
  48. // Name: CalcNodeArraySize
  49. // Desc: Based on the viewing width and height, and numDiv, calculate the x,y,z array
  50. // node dimensions.
  51. //-----------------------------------------------------------------------------
  52. void VIEW::CalcNodeArraySize( IPOINT3D *pNodeDim )
  53. {
  54. // mf: !!! if aspect ratio deviates too much from 1, then nodes will get
  55. // clipped as view rotates
  56. if( m_winSize.width >= m_winSize.height )
  57. {
  58. pNodeDim->x = m_numDiv - 1;
  59. pNodeDim->y = (int) (pNodeDim->x / m_aspectRatio) ;
  60. if( pNodeDim->y < 1 )
  61. pNodeDim->y = 1;
  62. pNodeDim->z = pNodeDim->x;
  63. }
  64. else
  65. {
  66. pNodeDim->y = m_numDiv - 1;
  67. pNodeDim->x = (int) (m_aspectRatio * pNodeDim->y);
  68. if( pNodeDim->x < 1 )
  69. pNodeDim->x = 1;
  70. pNodeDim->z = pNodeDim->y;
  71. }
  72. }
  73. //-----------------------------------------------------------------------------
  74. // Name: SetWinSize
  75. // Desc: Set the window size for the view, derive other view params.
  76. // Return FALSE if new size same as old.
  77. //-----------------------------------------------------------------------------
  78. BOOL VIEW::SetWinSize( int width, int height )
  79. {
  80. if( (width == m_winSize.width) &&
  81. (height == m_winSize.height) )
  82. return FALSE;
  83. m_winSize.width = width;
  84. m_winSize.height = height;
  85. m_aspectRatio = m_winSize.height == 0 ? 1.0f : (float)m_winSize.width/m_winSize.height;
  86. if( m_winSize.width >= m_winSize.height )
  87. {
  88. m_world.x = m_numDiv * m_divSize;
  89. m_world.y = m_world.x / m_aspectRatio;
  90. m_world.z = m_world.x;
  91. }
  92. else
  93. {
  94. m_world.y = m_numDiv * m_divSize;
  95. m_world.x = m_world.y * m_aspectRatio;
  96. m_world.z = m_world.y;
  97. }
  98. m_persp.zFar = m_viewDist + m_world.z*2;
  99. return TRUE;
  100. }
  101. //-----------------------------------------------------------------------------
  102. // Name: SetSceneRotation
  103. // Desc:
  104. //-----------------------------------------------------------------------------
  105. void VIEW::IncrementSceneRotation()
  106. {
  107. m_yRot += 9.73156f;
  108. if( m_yRot >= 360.0f )
  109. // prevent overflow
  110. m_yRot -= 360.0f;
  111. }