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.

293 lines
8.5 KiB

  1. /******************************Module*Header*******************************\
  2. * Module Name: genstrip.c
  3. *
  4. * The Ribbon and 2 Ribbon styles of the 3D Flying Objects screen saver.
  5. *
  6. * Animation of 1 or 2 quad strips floating about.
  7. *
  8. * Copyright (c) 1994 Microsoft Corporation
  9. *
  10. \**************************************************************************/
  11. #include <windows.h>
  12. #include <math.h>
  13. #include <d3dx8.h>
  14. #include "D3DSaver.h"
  15. #include "FlyingObjects.h"
  16. #include "mesh.h"
  17. static MESH stripMesh;
  18. static int iPrec = 40;
  19. void genStrip(FLOAT fTimeFactor)
  20. {
  21. static int counter = 0;
  22. int i;
  23. int facecount;
  24. // Use Hermite basis, pg 488, FVD
  25. static float M[4][4] = {{2.0f, -2.0f, 1.0f, 1.0f},
  26. {-3.0f, 3.0f, -2.0f, -1.0f},
  27. {0.0f, 0.0f, 1.0f, 0.0f},
  28. {1.0f, 0.0f, 0.0f, 0.0f}};
  29. float xx[4], yy[4], zz[4];
  30. float cx[4], cy[4], cz[4];
  31. float d = 1.0f / (float) iPrec;
  32. float t = 0.0f;
  33. float t2, t3;
  34. POINT3D p1(-0.5f, 0.0f, 0.0f);
  35. POINT3D p2(0.5f, 0.0f, 0.0f);
  36. POINT3D v1(1.5f, 1.5f, 0.0f);
  37. POINT3D v2(0.0f, 3.0f, 0.0f);
  38. POINT3D norm;
  39. float sinVal;
  40. float angle;
  41. float angleStep = (float) (PI / iPrec);
  42. static float rotA = 0.0f;
  43. static float rotB = (float) (PI / 2.0);
  44. static float sideSin = 0.0f;
  45. float rotStepA = (float) (PI / (2.0 * iPrec)) * fTimeFactor;
  46. float rotStepB = (float) (PI / (4.0 * iPrec)) * fTimeFactor;
  47. MESH *mesh = &stripMesh;
  48. #define NORMS(x, y) stripMesh.norms[((x) * iPrec) + y]
  49. #define GRID(x, y) stripMesh.pts[((x) * iPrec) + y]
  50. v1.x = (float) (4.0 * cos(rotA));
  51. v1.y = (float) (4.0 * sin(rotA));
  52. p2.x = (float) (0.5 * sin(rotB));
  53. // p2.y = (float) (0.5 * sin(rotB));
  54. rotA += rotStepA;
  55. rotB += rotStepB;
  56. counter++;
  57. if (counter >= (2 * iPrec)) {
  58. rotStepA = -rotStepA;
  59. counter = 0;
  60. }
  61. angle = sideSin;
  62. sideSin += (float) (PI / 80.0);
  63. xx[0] = p1.x;
  64. xx[1] = p2.x;
  65. xx[2] = v1.x;
  66. xx[3] = v2.x;
  67. yy[0] = p1.y;
  68. yy[1] = p2.y;
  69. yy[2] = v1.y;
  70. yy[3] = v2.y;
  71. zz[0] = p1.z;
  72. zz[1] = p2.z;
  73. zz[2] = v1.z;
  74. zz[3] = v2.z;
  75. for (i = 0; i < 4; i++) {
  76. cx[i] = xx[0] * M[i][0] + xx[1] * M[i][1] +
  77. xx[2] * M[i][2] + xx[3] * M[i][3];
  78. cy[i] = yy[0] * M[i][0] + yy[1] * M[i][1] +
  79. yy[2] * M[i][2] + yy[3] * M[i][3];
  80. cz[i] = zz[0] * M[i][0] + zz[1] * M[i][1] +
  81. zz[2] * M[i][2] + zz[3] * M[i][3];
  82. }
  83. for (i = 0; i < iPrec; i++) {
  84. float x, y;
  85. t += d;
  86. t2 = t * t;
  87. t3 = t2 * t;
  88. x = cx[0] * t3 + cx[1] * t2 + cx[2] * t + cx[3];
  89. y = cy[0] * t3 + cy[1] * t2 + cy[2] * t + cy[3];
  90. sinVal = (float) (sin(angle) / 5.0);
  91. if (sinVal < 0.0)
  92. sinVal = -sinVal;
  93. angle += angleStep;
  94. GRID(0, i).x = x;
  95. GRID(0, i).z = y;
  96. GRID(0, i).y = 0.25f; // extrusion // + sinVal;
  97. GRID(1, i).x = x;
  98. GRID(1, i).z = y;
  99. GRID(1, i).y = -0.25f; // - sinVal;
  100. }
  101. stripMesh.numFaces = 0;
  102. for (i = 0; i < 2 * iPrec; i++)
  103. mesh->norms[i] = ss_ptZero;
  104. for (facecount = 0, i = 0; i < (iPrec - 1); i++) {
  105. ss_calcNorm(&norm, &GRID(0, i + 1), &GRID(0, i), &GRID(1, i));
  106. stripMesh.faces[facecount].material = 0;
  107. stripMesh.faces[facecount].norm = norm;
  108. NORMS(0, i).x += norm.x;
  109. NORMS(0, i).y += norm.y;
  110. NORMS(0, i).z += norm.z;
  111. NORMS(1, i).x += norm.x;
  112. NORMS(1, i).y += norm.y;
  113. NORMS(1, i).z += norm.z;
  114. if (i != (iPrec - 1)) {
  115. NORMS(0, i+1).x += norm.x;
  116. NORMS(0, i+1).y += norm.y;
  117. NORMS(0, i+1).z += norm.z;
  118. NORMS(1, i+1).x += norm.x;
  119. NORMS(1, i+1).y += norm.y;
  120. NORMS(1, i+1).z += norm.z;
  121. }
  122. stripMesh.faces[facecount].p[0] = i;
  123. stripMesh.faces[facecount].p[1] = iPrec + i;
  124. stripMesh.faces[facecount].p[2] = i + 1;
  125. stripMesh.faces[facecount].p[3] = iPrec + i + 1;
  126. stripMesh.numFaces++;
  127. facecount++;
  128. }
  129. stripMesh.numPoints = 2 * iPrec;
  130. ss_normalizeNorms(stripMesh.norms, stripMesh.numPoints);
  131. }
  132. BOOL initStripScene()
  133. {
  134. iPrec = (int)(fTesselFact * 40.5);
  135. if (iPrec < 4)
  136. iPrec = 4;
  137. if( !newMesh(&stripMesh, iPrec, 2 * iPrec) )
  138. return FALSE;
  139. /*
  140. D3DXMATRIX matProj;
  141. D3DXMatrixOrthoLH( &matProj, 2.2f, 2.2f, 0.0f, 3.0f );
  142. m_pd3dDevice->SetTransform( D3DTS_PROJECTION, &matProj );
  143. */
  144. SetProjectionMatrixInfo( TRUE, 2.2f, 2.2f, 0.0f, 3.0f );
  145. D3DXMATRIX mat1, mat2, mat3, mat4, matFinal;
  146. D3DXMatrixTranslation(&mat1, 0.0f, 0.0f, 1.5f);
  147. D3DXMatrixRotationX(&mat2, D3DXToRadian(50.0f));
  148. D3DXMatrixRotationY(&mat3, D3DXToRadian(50.0f));
  149. D3DXMatrixRotationZ(&mat4, D3DXToRadian(12.0f));
  150. matFinal = mat4 * mat3 * mat2 * mat1 ;
  151. m_pd3dDevice->SetTransform( D3DTS_VIEW, &matFinal );
  152. // m_pd3dDevice->SetRenderState( D3DRS_CULLMODE, D3DCULL_NONE );
  153. return TRUE;
  154. }
  155. void delStripScene()
  156. {
  157. delMesh(&stripMesh);
  158. }
  159. void updateStripScene(int flags, FLOAT fElapsedTime)
  160. {
  161. static double mxrot = 0.0;
  162. static double myrot = 0.0;
  163. static double mzrot = 0.0;
  164. static double mxrotInc = 0.0;
  165. static double myrotInc = 0.1;
  166. static double mzrotInc = 0.0;
  167. static FLOAT fH = 0.0f;
  168. if( fElapsedTime > 0.25f )
  169. fElapsedTime = 0.25f;
  170. FLOAT fTimeFactor = fElapsedTime * 20.0f;
  171. RGBA color;
  172. D3DXMATRIX mat1, mat2, mat3, mat4, mat5, matFinal;
  173. // This is to deal with when you set maximum size and
  174. // gbBounce is TRUE every frame. If that's happening,
  175. // don't toggle the rotInc's or the scene will jiggle.
  176. static BOOL bBounceLast = FALSE;
  177. if( gbBounce ) {
  178. if( bBounceLast )
  179. {
  180. }
  181. else
  182. {
  183. // floating window bounced off an edge
  184. if (mxrotInc) {
  185. mxrotInc = 0.0;
  186. myrotInc = 0.1;
  187. } else if (myrotInc) {
  188. myrotInc = 0.0;
  189. mzrotInc = 0.1;
  190. } else if (mzrotInc) {
  191. mzrotInc = 0.0;
  192. mxrotInc = 0.1;
  193. }
  194. }
  195. gbBounce = FALSE;
  196. bBounceLast = TRUE;
  197. }
  198. else
  199. {
  200. bBounceLast = FALSE;
  201. }
  202. D3DXMatrixRotationX(&mat1, D3DXToRadian((FLOAT)(mxrot * (180.0 / PI))));
  203. D3DXMatrixRotationY(&mat2, D3DXToRadian((FLOAT)(myrot * (180.0 / PI))));
  204. D3DXMatrixRotationZ(&mat3, D3DXToRadian((FLOAT)(mzrot * (180.0 / PI))));
  205. matFinal = mat3 * mat2 * mat1 ;
  206. m_pd3dDevice->SetTransform( D3DTS_WORLD, &matFinal );
  207. genStrip(fTimeFactor);
  208. if (bColorCycle) {
  209. ss_HsvToRgb(fH, 1.0f, 1.0f, &color );
  210. myglMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE,
  211. (FLOAT *) &color);
  212. fH += fTimeFactor;
  213. if( fH >= 360.0f )
  214. fH -= 360.0f;
  215. } else {
  216. myglMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE,
  217. (FLOAT *) &Material[1].Diffuse);
  218. }
  219. RenderMesh3(&stripMesh, bSmoothShading);
  220. RenderMesh3Backsides(&stripMesh, bSmoothShading);
  221. if (flags & 0x4)
  222. {
  223. D3DXMatrixTranslation(&mat1, 0.05f, 0.0f, 0.0f);
  224. D3DXMatrixRotationX(&mat2, D3DXToRadian((FLOAT)(myrot * (180.0 / PI))));
  225. D3DXMatrixRotationY(&mat3, D3DXToRadian((FLOAT)(mxrot * (180.0 / PI))));
  226. D3DXMatrixRotationZ(&mat4, D3DXToRadian((FLOAT)(mzrot * (180.0 / PI))));
  227. matFinal = mat4 * mat3 * mat2 * mat1 ;
  228. m_pd3dDevice->SetTransform( D3DTS_WORLD , &matFinal );
  229. if (bColorCycle) {
  230. color.r = 1.0f - color.r;
  231. color.g = 1.0f - color.g;
  232. color.b = 1.0f - color.b;
  233. myglMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE,
  234. (FLOAT *) &color);
  235. } else {
  236. myglMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE,
  237. (FLOAT *) &Material[2].Diffuse);
  238. }
  239. RenderMesh3(&stripMesh, bSmoothShading);
  240. RenderMesh3Backsides(&stripMesh, bSmoothShading);
  241. }
  242. mxrot += mxrotInc * fTimeFactor;
  243. myrot += myrotInc * fTimeFactor;
  244. mzrot += mzrotInc * fTimeFactor;
  245. }