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.

182 lines
5.8 KiB

  1. /*****************************************************************************\
  2. FILE: painting.cpp
  3. DESCRIPTION:
  4. BryanSt 12/24/2000
  5. Copyright (C) Microsoft Corp 2000-2001. All rights reserved.
  6. \*****************************************************************************/
  7. #include "stdafx.h"
  8. #include "util.h"
  9. #include "painting.h"
  10. //-----------------------------------------------------------------------------
  11. // Name: C3DObject()
  12. // Desc: Constructor
  13. //-----------------------------------------------------------------------------
  14. CPainting::CPainting(CMSLogoDXScreenSaver * pMain)
  15. {
  16. // Initialize member variables
  17. m_pMain = pMain;
  18. m_pFrameTexture = NULL;
  19. m_pPaintingTexture = NULL;
  20. m_pObjPainting = NULL;
  21. m_pObjFrame = NULL;
  22. }
  23. CPainting::~CPainting()
  24. {
  25. SAFE_RELEASE(m_pFrameTexture);
  26. SAFE_RELEASE(m_pPaintingTexture);
  27. SAFE_DELETE(m_pObjPainting);
  28. SAFE_DELETE(m_pObjFrame);
  29. }
  30. //-----------------------------------------------------------------------------
  31. // Name: FinalCleanup()
  32. // Desc: Called before the app exits, this function gives the app the chance
  33. // to cleanup after itself.
  34. //-----------------------------------------------------------------------------
  35. HRESULT CPainting::FinalCleanup(void)
  36. {
  37. return S_OK;
  38. }
  39. //-----------------------------------------------------------------------------
  40. // Name: DeleteDeviceObjects()
  41. // Desc: Called when the app is exitting, or the device is being changed,
  42. // this function deletes any device dependant objects.
  43. //-----------------------------------------------------------------------------
  44. HRESULT CPainting::DeleteDeviceObjects(void)
  45. {
  46. return S_OK;
  47. }
  48. //-----------------------------------------------------------------------------
  49. // Name: OneTimeSceneInit()
  50. // Desc: Called during initial app startup, this function performs all the
  51. // permanent initialization.
  52. //-----------------------------------------------------------------------------
  53. HRESULT CPainting::OneTimeSceneInit(void)
  54. {
  55. HRESULT hr = E_OUTOFMEMORY;
  56. m_pObjPainting = new C3DObject(m_pMain);
  57. m_pObjFrame = new C3DObject(m_pMain);
  58. if (m_pObjFrame && m_pObjFrame)
  59. {
  60. hr = S_OK;
  61. }
  62. return hr;
  63. }
  64. HRESULT CPainting::SetPainting(CTexture * pFrameTexture, CTexture * pPaintingTexture, D3DXVECTOR3 vLocationCenter, float fMaxHeight,
  65. float fFrameWidth, float fFrameHeight, D3DXVECTOR3 vNormal, DWORD dwMaxPixelSize)
  66. {
  67. HRESULT hr = E_OUTOFMEMORY;
  68. if (m_pObjPainting && m_pObjFrame && m_pMain && pFrameTexture && pPaintingTexture)
  69. {
  70. D3DXVECTOR3 vWidth;
  71. D3DXVECTOR3 vHeight;
  72. if (vNormal.x)
  73. {
  74. vWidth = D3DXVECTOR3(0, 0, 1);
  75. vHeight = D3DXVECTOR3(0, 1, 0);
  76. }
  77. else if (vNormal.y)
  78. {
  79. vWidth = D3DXVECTOR3(0, 0, 1);
  80. vHeight = D3DXVECTOR3(1, 0, 0);
  81. }
  82. else
  83. {
  84. vWidth = D3DXVECTOR3(1, 0, 0);
  85. vHeight = D3DXVECTOR3(0, 1, 0);
  86. }
  87. IUnknown_Set((IUnknown **) &m_pFrameTexture, (IUnknown *) pFrameTexture);
  88. IUnknown_Set((IUnknown **) &m_pPaintingTexture, (IUnknown *) pPaintingTexture);
  89. DWORD dwPaintingWidth = pPaintingTexture->GetTextureWidth();
  90. DWORD dwPaintingHeight = pPaintingTexture->GetTextureHeight();
  91. float fPaintingRatio = (((float) dwPaintingWidth) / ((float) dwPaintingHeight));
  92. int nWidth = 1;
  93. int nHeight = 1;
  94. m_pMain->GetCurrentScreenSize(&nWidth, &nHeight);
  95. float fMonitorRatio = (((float) nWidth) / ((float) nHeight));
  96. float fPaintingHeight = fMaxHeight;
  97. float fPaintingWidth = (fPaintingHeight * fPaintingRatio);
  98. if (fPaintingRatio > fMonitorRatio)
  99. {
  100. // Oh no, the picture ratio is wider than the screen radio. This will cause
  101. // warpping so it will extend off the right and left. We need to scale it down.
  102. float fScaleDownRatio = (fMonitorRatio / fPaintingRatio);
  103. fPaintingHeight *= fScaleDownRatio;
  104. fPaintingWidth *= fScaleDownRatio;
  105. }
  106. D3DXVECTOR3 vTranslateToCorner = ((-fPaintingWidth/2)*vWidth + (-fPaintingHeight/2)*vHeight);
  107. D3DXVECTOR3 vObjLocation(vLocationCenter + vTranslateToCorner);
  108. D3DXVECTOR3 vObjSize(fPaintingWidth*vWidth + fPaintingHeight*vHeight);
  109. hr = m_pObjPainting->InitPlaneStretch(pPaintingTexture, m_pMain->GetD3DDevice(), vObjLocation, vObjSize, vNormal, 3, 3, dwMaxPixelSize);
  110. D3DXVECTOR3 vFrameSize(D3DXVec3Multiply(vObjSize, (D3DXVECTOR3((fFrameWidth * vWidth) + D3DXVECTOR3(fFrameHeight * vHeight)))));
  111. vObjLocation = (vObjLocation - vFrameSize + ((g_fFudge / -2.0f)* vNormal));
  112. vObjSize = (vObjSize + (2 * vFrameSize));
  113. hr = m_pObjFrame->InitPlaneStretch(pFrameTexture, m_pMain->GetD3DDevice(), vObjLocation, vObjSize, vNormal, 3, 3, dwMaxPixelSize);
  114. }
  115. return hr;
  116. }
  117. //-----------------------------------------------------------------------------
  118. // Name: Render()
  119. // Desc: Called once per frame, the call is the entry point for 3d
  120. // rendering. This function sets up render states, clears the
  121. // viewport, and renders the scene.
  122. //-----------------------------------------------------------------------------
  123. HRESULT CPainting::Render(IDirect3DDevice8 * pD3DDevice, int nPhase)
  124. {
  125. HRESULT hr = E_OUTOFMEMORY;
  126. if (m_pObjFrame && m_pObjPainting)
  127. {
  128. switch (nPhase)
  129. {
  130. case 0:
  131. hr = m_pObjFrame->Render(pD3DDevice);
  132. break;
  133. case 1:
  134. hr = m_pObjPainting->Render(pD3DDevice);
  135. break;
  136. }
  137. }
  138. return hr;
  139. }