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.

926 lines
28 KiB

  1. /******************************Module*Header*******************************\
  2. * Module Name: genwin.c
  3. *
  4. * The Windows Logo style of the 3D Flying Objects screen saver.
  5. *
  6. * Animated 3D model of the Microsoft (R) Windows NT (TM) flag logo.
  7. *
  8. * Copyright (c) 1994 Microsoft Corporation
  9. *
  10. \**************************************************************************/
  11. #include <stdlib.h>
  12. #include <windows.h>
  13. #include <string.h>
  14. #include <math.h>
  15. #include <d3dx8.h>
  16. #include "D3DSaver.h"
  17. #include "FlyingObjects.h"
  18. #include "mesh.h"
  19. #define WIN_TOP_BORDER (float)0.1
  20. #define WIN_RIGHT_BORDER WIN_TOP_BORDER
  21. #define WIN_CROSSBAR (0.6522f * WIN_TOP_BORDER)
  22. #define WIN_NUMPIECES 7
  23. #define WIN_NUMCOLUMNS 6
  24. #define WIN_GAP (WIN_TOP_BORDER / 8.0f)
  25. #define WIN_GAP_X (2.0f * WIN_GAP)
  26. #define WIN_HEIGHT ((WIN_GAP * 6.0f) + \
  27. (WIN_NUMPIECES * WIN_TOP_BORDER))
  28. #define WIN_WIDTH (0.7024f * WIN_HEIGHT)
  29. #define WIN_THICKNESS WIN_CROSSBAR
  30. #define WIN_TOTALWIDTH (WIN_TOP_BORDER * 1.1f * (float)WIN_NUMCOLUMNS + \
  31. WIN_WIDTH)
  32. #define BLOCK_TOP 0x0001
  33. #define BLOCK_BOTTOM 0x0002
  34. #define BLOCK_LEFT 0x0004
  35. #define BLOCK_RIGHT 0x0008
  36. #define BLOCK_FRONT 0x0010
  37. #define BLOCK_BACK 0x0020
  38. #define BLOCK_ALL 0x003f
  39. #define DELTA_BLEND 0x2000
  40. #define NO_BLEND 0x1000
  41. #define CUBE_FACES 6
  42. #define CUBE_POINTS 8
  43. #define MAX_FRAMES 20
  44. #define MAXPREC 15
  45. #define S_IPREC 3
  46. static int Frames = 10;
  47. static MESH winMesh[MAX_FRAMES];
  48. static MESH winStreamer[MAX_FRAMES];
  49. static float sinAngle = 0.0f;
  50. static float xTrans = 0.2f;
  51. static int curMatl = 0;
  52. static int iPrec = 10;
  53. static RGBA matlBrightSpecular = {1.0f, 1.0f, 1.0f, 1.0f};
  54. static RGBA matlDimSpecular = {0.3f, 0.3f, 0.3f, 1.0f};
  55. static RGBA matlNoSpecular = {0.0f, 0.0f, 0.0f, 0.0f};
  56. static FLOAT light0Pos[] = {20.0f, -10.0f, 20.0f, 0.0f};
  57. static RGBA light1Ambient = {0.0f, 0.0f, 0.0f, 0.0f};
  58. static RGBA light1Diffuse = {0.4f, 0.4f, 0.4f, 1.0f};
  59. static RGBA light1Specular = {0.0f, 0.0f, 0.0f, 0.0f};
  60. static FLOAT light1Pos[] = {-20.0f, 5.0f, 0.0f, 0.0f};
  61. static RGBA winColors[] = {{0.3f, 0.3f, 0.3f, 1.0f},
  62. {0.94f, 0.37f, 0.13f, 1.0f}, // red
  63. {0.22f, 0.42f, 0.78f, 1.0f}, // blue
  64. {0.35f, 0.71f, 0.35f, 1.0f}, // green
  65. {0.95f, 0.82f, 0.12f, 1.0f}}; // yellow
  66. static int iPtInList(MESH *mesh, int start,
  67. POINT3D *p, POINT3D *norm, BOOL blend)
  68. {
  69. int i;
  70. POINT3D *pts = mesh->pts + start;
  71. if (blend) {
  72. for (i = start; i < mesh->numPoints; i++, pts++) {
  73. if ((pts->x == p->x) && (pts->y == p->y) && (pts->z == p->z)) {
  74. mesh->norms[i].x += norm->x;
  75. mesh->norms[i].y += norm->y;
  76. mesh->norms[i].z += norm->z;
  77. return i;
  78. }
  79. }
  80. } else {
  81. i = mesh->numPoints;
  82. }
  83. mesh->pts[i] = *p;
  84. mesh->norms[i] = *norm;
  85. mesh->numPoints++;
  86. return i;
  87. }
  88. float getZPos(float x)
  89. {
  90. float xAbs = x - xTrans;
  91. float angle = (float) (sinAngle + ((2.0 * PI) * (xAbs / WIN_TOTALWIDTH)));
  92. xAbs += (WIN_TOTALWIDTH / 2.0f);
  93. xAbs = WIN_TOTALWIDTH - xAbs;
  94. return (float)((sin((double)angle) / 4.0) *
  95. sqrt((double)(xAbs / WIN_TOTALWIDTH )));
  96. }
  97. void AddFace(MESH *mesh, int startBlend, POINT3D *pos, float w, float h)
  98. {
  99. #define FACE_VERTEX(i) \
  100. iPtInList(mesh, startBlend, pts + i, &mesh->faces[faceCount].norm, TRUE)
  101. int faceCount = mesh->numFaces;
  102. int numPts = mesh->numPoints;
  103. POINT3D *pts = mesh->pts + numPts;
  104. float zLeft = getZPos(pos->x);
  105. float zRight = getZPos(pos->x + w);
  106. pts->x = (float)pos->x;
  107. pts->y = (float)pos->y;
  108. pts->z = zLeft;
  109. pts++;
  110. pts->x = (float)pos->x;
  111. pts->y = (float)(pos->y + h);
  112. pts->z = zLeft;
  113. pts++;
  114. pts->x = (float)(pos->x + w);
  115. pts->y = (float)(pos->y + h);
  116. pts->z = zRight;
  117. pts++;
  118. pts->x = (float)(pos->x + w);
  119. pts->y = (float)pos->y;
  120. pts->z = zRight;
  121. pts -= 3;
  122. mesh->faces[faceCount].material = curMatl;
  123. ss_calcNorm(&mesh->faces[faceCount].norm, pts + 2, pts + 1, pts);
  124. mesh->faces[faceCount].p[3] = FACE_VERTEX(0);
  125. mesh->faces[faceCount].p[2] = FACE_VERTEX(1);
  126. mesh->faces[faceCount].p[1] = FACE_VERTEX(2);
  127. mesh->faces[faceCount].p[0] = FACE_VERTEX(3);
  128. mesh->numFaces++;
  129. }
  130. #define BLOCK_VERTEX(face, i)\
  131. {\
  132. if (flags & DELTA_BLEND) {\
  133. mesh->faces[faceCount].p[face] = \
  134. iPtInList(mesh, blendStart, &pts[i], &norms[((i & 0x2) >> 1)],\
  135. bBlend);\
  136. } else\
  137. mesh->faces[faceCount].p[face] = \
  138. iPtInList(mesh, blendStart, &pts[i],\
  139. &mesh->faces[faceCount].norm, bBlend);\
  140. }
  141. #define DELTA_FACT (float)10.0
  142. void AddBlock(MESH *mesh, int blendStart, POINT3D *pos,
  143. float w, float h, float d, ULONG flags)
  144. {
  145. POINT3D pts[8];
  146. POINT3D ptsL[8];
  147. POINT3D ptsR[8];
  148. POINT3D norms[2];
  149. POINT3D posPrev;
  150. float zLeft = getZPos(pos->x);
  151. float zRight = getZPos(pos->x + w);
  152. int faceCount = mesh->numFaces;
  153. BOOL bBlend = ((flags & NO_BLEND) == 0);
  154. flags |= DELTA_BLEND;
  155. pts[0].x = (float)pos->x;
  156. pts[0].y = (float)(pos->y + h);
  157. pts[0].z = zLeft;
  158. pts[1].x = (float)pos->x;
  159. pts[1].y = (float)(pos->y + h);
  160. pts[1].z = zLeft + d;
  161. pts[2].x = (float)(pos->x + w);
  162. pts[2].y = (float)(pos->y + h);
  163. pts[2].z = zRight + d;
  164. pts[3].x = (float)(pos->x + w);
  165. pts[3].y = (float)(pos->y + h);
  166. pts[3].z = zRight;
  167. pts[4].x = (float)pos->x;
  168. pts[4].y = (float)pos->y;
  169. pts[4].z = zLeft;
  170. pts[5].x = (float)pos->x;
  171. pts[5].y = (float)pos->y;
  172. pts[5].z = zLeft + d;
  173. pts[6].x = (float)(pos->x + w);
  174. pts[6].y = (float)pos->y;
  175. pts[6].z = zRight + d;
  176. pts[7].x = (float)(pos->x + w);
  177. pts[7].y = (float)pos->y;
  178. pts[7].z = zRight;
  179. if (flags & DELTA_BLEND)
  180. {
  181. float prevW = w;
  182. posPrev = *pos;
  183. w /= DELTA_FACT;
  184. zRight = getZPos(pos->x + w);
  185. ptsL[0].x = (float)pos->x;
  186. ptsL[0].y = (float)(pos->y + h);
  187. ptsL[0].z = zLeft;
  188. ptsL[1].x = (float)pos->x;
  189. ptsL[1].y = (float)(pos->y + h);
  190. ptsL[1].z = zLeft + d;
  191. ptsL[2].x = (float)(pos->x + w);
  192. ptsL[2].y = (float)(pos->y + h);
  193. ptsL[2].z = zRight + d;
  194. ptsL[3].x = (float)(pos->x + w);
  195. ptsL[3].y = (float)(pos->y + h);
  196. ptsL[3].z = zRight;
  197. ptsL[4].x = (float)pos->x;
  198. ptsL[4].y = (float)pos->y;
  199. ptsL[4].z = zLeft;
  200. ptsL[5].x = (float)pos->x;
  201. ptsL[5].y = (float)pos->y;
  202. ptsL[5].z = zLeft + d;
  203. ptsL[6].x = (float)(pos->x + w);
  204. ptsL[6].y = (float)pos->y;
  205. ptsL[6].z = zRight + d;
  206. ptsL[7].x = (float)(pos->x + w);
  207. ptsL[7].y = (float)pos->y;
  208. ptsL[7].z = zRight;
  209. pos->x += (prevW - w);
  210. zLeft = getZPos(pos->x);
  211. zRight = getZPos(pos->x + w);
  212. ptsR[0].x = (float)pos->x;
  213. ptsR[0].y = (float)(pos->y + h);
  214. ptsR[0].z = zLeft;
  215. ptsR[1].x = (float)pos->x;
  216. ptsR[1].y = (float)(pos->y + h);
  217. ptsR[1].z = zLeft + d;
  218. ptsR[2].x = (float)(pos->x + w);
  219. ptsR[2].y = (float)(pos->y + h);
  220. ptsR[2].z = zRight + d;
  221. ptsR[3].x = (float)(pos->x + w);
  222. ptsR[3].y = (float)(pos->y + h);
  223. ptsR[3].z = zRight;
  224. ptsR[4].x = (float)pos->x;
  225. ptsR[4].y = (float)pos->y;
  226. ptsR[4].z = zLeft;
  227. ptsR[5].x = (float)pos->x;
  228. ptsR[5].y = (float)pos->y;
  229. ptsR[5].z = zLeft + d;
  230. ptsR[6].x = (float)(pos->x + w);
  231. ptsR[6].y = (float)pos->y;
  232. ptsR[6].z = zRight + d;
  233. ptsR[7].x = (float)(pos->x + w);
  234. ptsR[7].y = (float)pos->y;
  235. ptsR[7].z = zRight;
  236. *pos = posPrev;
  237. }
  238. if (flags & BLOCK_TOP) {
  239. mesh->faces[faceCount].material = curMatl;
  240. ss_calcNorm(&mesh->faces[faceCount].norm, &pts[0], &pts[1], &pts[2]);
  241. if (flags & DELTA_BLEND) {
  242. ss_calcNorm(&norms[0], &ptsL[0], &ptsL[1], &ptsL[2]);
  243. ss_calcNorm(&norms[1], &ptsR[0], &ptsR[1], &ptsR[2]);
  244. }
  245. BLOCK_VERTEX(0, 0);
  246. BLOCK_VERTEX(1, 1);
  247. BLOCK_VERTEX(2, 2);
  248. BLOCK_VERTEX(3, 3);
  249. faceCount++;
  250. mesh->numFaces++;
  251. }
  252. if (flags & BLOCK_BOTTOM) {
  253. mesh->faces[faceCount].material = curMatl;
  254. ss_calcNorm(&mesh->faces[faceCount].norm, &pts[4], &pts[7], &pts[6]);
  255. if (flags & DELTA_BLEND) {
  256. ss_calcNorm(&norms[0], &ptsL[4], &ptsL[7], &ptsL[6]);
  257. ss_calcNorm(&norms[1], &ptsR[4], &ptsR[7], &ptsR[6]);
  258. }
  259. BLOCK_VERTEX(0, 4);
  260. BLOCK_VERTEX(1, 7);
  261. BLOCK_VERTEX(2, 6);
  262. BLOCK_VERTEX(3, 5);
  263. faceCount++;
  264. mesh->numFaces++;
  265. }
  266. if (flags & BLOCK_LEFT) {
  267. mesh->faces[faceCount].material = curMatl;
  268. ss_calcNorm(&mesh->faces[faceCount].norm, &pts[1], &pts[0], &pts[4]);
  269. if (flags & DELTA_BLEND) {
  270. ss_calcNorm(&norms[0], &ptsL[1], &ptsL[0], &ptsL[4]);
  271. ss_calcNorm(&norms[1], &ptsR[1], &ptsR[0], &ptsR[4]);
  272. }
  273. BLOCK_VERTEX(0, 1);
  274. BLOCK_VERTEX(1, 0);
  275. BLOCK_VERTEX(2, 4);
  276. BLOCK_VERTEX(3, 5);
  277. faceCount++;
  278. mesh->numFaces++;
  279. }
  280. if (flags & BLOCK_RIGHT) {
  281. mesh->faces[faceCount].material = curMatl;
  282. ss_calcNorm(&mesh->faces[faceCount].norm, &pts[3], &pts[2], &pts[6]);
  283. if (flags & DELTA_BLEND) {
  284. ss_calcNorm(&norms[0], &ptsL[3], &ptsL[2], &ptsL[6]);
  285. ss_calcNorm(&norms[1], &ptsR[3], &ptsR[2], &ptsR[6]);
  286. }
  287. BLOCK_VERTEX(0, 3);
  288. BLOCK_VERTEX(1, 2);
  289. BLOCK_VERTEX(2, 6);
  290. BLOCK_VERTEX(3, 7);
  291. faceCount++;
  292. mesh->numFaces++;
  293. }
  294. if (flags & BLOCK_FRONT) {
  295. mesh->faces[faceCount].material = curMatl;
  296. ss_calcNorm(&mesh->faces[faceCount].norm, &pts[0], &pts[3], &pts[7]);
  297. if (flags & DELTA_BLEND) {
  298. ss_calcNorm(&norms[0], &ptsL[0], &ptsL[3], &ptsL[7]);
  299. ss_calcNorm(&norms[1], &ptsR[0], &ptsR[3], &ptsR[7]);
  300. }
  301. BLOCK_VERTEX(0, 0);
  302. BLOCK_VERTEX(1, 3);
  303. BLOCK_VERTEX(2, 7);
  304. BLOCK_VERTEX(3, 4);
  305. faceCount++;
  306. mesh->numFaces++;
  307. }
  308. if (flags & BLOCK_BACK) {
  309. mesh->faces[faceCount].material = curMatl;
  310. ss_calcNorm(&mesh->faces[faceCount].norm, &pts[1], &pts[5], &pts[6]);
  311. if (flags & DELTA_BLEND) {
  312. ss_calcNorm(&norms[0], &ptsL[1], &ptsL[5], &ptsL[6]);
  313. ss_calcNorm(&norms[1], &ptsR[1], &ptsR[5], &ptsR[6]);
  314. }
  315. BLOCK_VERTEX(0, 1);
  316. BLOCK_VERTEX(1, 5);
  317. BLOCK_VERTEX(2, 6);
  318. BLOCK_VERTEX(3, 2);
  319. mesh->numFaces++;
  320. }
  321. }
  322. BOOL genWin(MESH *winMesh, MESH *winStreamer)
  323. {
  324. POINT3D pos, posCenter;
  325. float w, h, d;
  326. float wMax, hMax;
  327. float xpos;
  328. int i, j, prec;
  329. int startBlend;
  330. if( !newMesh(winMesh, CUBE_FACES * iPrec * 20, CUBE_POINTS * iPrec * 20) )
  331. return FALSE;
  332. //
  333. // create window frame
  334. //
  335. w = (WIN_WIDTH - WIN_TOP_BORDER) / (float)iPrec;
  336. h = (float)WIN_TOP_BORDER;
  337. d = (float)WIN_THICKNESS;
  338. // draw top and bottom portions
  339. pos.y = 0.0f;
  340. pos.z = 0.0f;
  341. for (i = 0, pos.x = xTrans, startBlend = winMesh->numPoints;
  342. i < iPrec; i++, pos.x += w)
  343. AddBlock(winMesh, startBlend, &pos, w, h, d, BLOCK_TOP);
  344. for (i = 0, pos.x = xTrans, startBlend = winMesh->numPoints;
  345. i < iPrec; i++, pos.x += w)
  346. AddBlock(winMesh, startBlend, &pos, w, h, d, BLOCK_BOTTOM);
  347. for (i = 0, pos.x = xTrans, startBlend = winMesh->numPoints;
  348. i < iPrec; i++, pos.x += w)
  349. AddBlock(winMesh, startBlend, &pos, w, h, d, BLOCK_FRONT);
  350. for (i = 0, pos.x = xTrans, startBlend = winMesh->numPoints;
  351. i < iPrec; i++, pos.x += w)
  352. AddBlock(winMesh, startBlend, &pos, w, h, d, BLOCK_BACK);
  353. pos.x = xTrans;
  354. AddBlock(winMesh, 0, &pos, w, h, d, BLOCK_LEFT | NO_BLEND);
  355. pos.y = WIN_HEIGHT - WIN_TOP_BORDER;
  356. pos.z = 0.0f;
  357. for (i = 0, pos.x = xTrans, startBlend = winMesh->numPoints;
  358. i < iPrec; i++, pos.x += w)
  359. AddBlock(winMesh, startBlend, &pos, w, h, d, BLOCK_TOP);
  360. for (i = 0, pos.x = xTrans, startBlend = winMesh->numPoints;
  361. i < iPrec; i++, pos.x += w)
  362. AddBlock(winMesh, startBlend, &pos, w, h, d, BLOCK_BOTTOM);
  363. for (i = 0, pos.x = xTrans, startBlend = winMesh->numPoints;
  364. i < iPrec; i++, pos.x += w)
  365. AddBlock(winMesh, startBlend, &pos, w, h, d, BLOCK_FRONT);
  366. for (i = 0, pos.x = xTrans, startBlend = winMesh->numPoints;
  367. i < iPrec; i++, pos.x += w)
  368. AddBlock(winMesh, startBlend, &pos, w, h, d, BLOCK_BACK);
  369. pos.x = xTrans;
  370. AddBlock(winMesh, 0, &pos, w, h, d, BLOCK_LEFT | NO_BLEND);
  371. // draw middle horizontal portions
  372. prec = (iPrec / 2);
  373. w = (WIN_WIDTH - WIN_TOP_BORDER - WIN_CROSSBAR) / 2.0f;
  374. w /= (float)prec;
  375. h = WIN_CROSSBAR;
  376. pos.y = (WIN_HEIGHT - WIN_CROSSBAR) / 2.0f;
  377. pos.z = 0.0f;
  378. for (i = 0, pos.x = xTrans, startBlend = winMesh->numPoints;
  379. i < prec; i++, pos.x += w)
  380. AddBlock(winMesh, startBlend, &pos, w, h, d, BLOCK_TOP);
  381. for (i = 0, pos.x = xTrans, startBlend = winMesh->numPoints;
  382. i < prec; i++, pos.x += w)
  383. AddBlock(winMesh, startBlend, &pos, w, h, d, BLOCK_BOTTOM);
  384. for (i = 0, pos.x = xTrans, startBlend = winMesh->numPoints;
  385. i < prec; i++, pos.x += w)
  386. AddBlock(winMesh, startBlend, &pos, w, h, d, BLOCK_FRONT);
  387. for (i = 0, pos.x = xTrans, startBlend = winMesh->numPoints;
  388. i < prec; i++, pos.x += w)
  389. AddBlock(winMesh, startBlend, &pos, w, h, d, BLOCK_BACK);
  390. xpos = pos.x + WIN_CROSSBAR;
  391. for (i = 0, pos.x = xpos, startBlend = winMesh->numPoints;
  392. i < prec; i++, pos.x += w)
  393. AddBlock(winMesh, startBlend, &pos, w, h, d, BLOCK_TOP);
  394. for (i = 0, pos.x = xpos, startBlend = winMesh->numPoints;
  395. i < prec; i++, pos.x += w)
  396. AddBlock(winMesh, startBlend, &pos, w, h, d, BLOCK_BOTTOM);
  397. for (i = 0, pos.x = xpos, startBlend = winMesh->numPoints;
  398. i < prec; i++, pos.x += w)
  399. AddBlock(winMesh, startBlend, &pos, w, h, d, BLOCK_FRONT);
  400. for (i = 0, pos.x = xpos, startBlend = winMesh->numPoints;
  401. i < prec; i++, pos.x += w)
  402. AddBlock(winMesh, startBlend, &pos, w, h, d, BLOCK_BACK);
  403. pos.x = xTrans;
  404. AddBlock(winMesh, 0, &pos, w, h, d, BLOCK_LEFT | NO_BLEND);
  405. // Draw thick right-hand edge of frame
  406. pos.x = xpos = xTrans + WIN_WIDTH - WIN_RIGHT_BORDER;
  407. pos.y = 0.0f;
  408. pos.z = 0.0f;
  409. w = WIN_RIGHT_BORDER / (float)S_IPREC;
  410. h = WIN_HEIGHT;
  411. AddBlock(winMesh, winMesh->numPoints, &pos, w, h, d, BLOCK_LEFT);
  412. for (i = 0, pos.x = xpos, startBlend = winMesh->numPoints;
  413. i < S_IPREC; i++, pos.x += w)
  414. AddBlock(winMesh, startBlend, &pos, w, h, d, BLOCK_FRONT);
  415. for (i = 0, pos.x = xpos, startBlend = winMesh->numPoints;
  416. i < S_IPREC; i++, pos.x += w)
  417. AddBlock(winMesh, startBlend, &pos, w, h, d, BLOCK_BACK);
  418. for (i = 0, pos.x = xpos, startBlend = winMesh->numPoints;
  419. i < S_IPREC; i++, pos.x += w)
  420. AddBlock(winMesh, startBlend, &pos, w, h, d, BLOCK_TOP);
  421. pos.y = WIN_HEIGHT;
  422. for (i = 0, pos.x = xpos, startBlend = winMesh->numPoints;
  423. i < S_IPREC; i++, pos.x += w)
  424. AddBlock(winMesh, startBlend, &pos, w, h, d, BLOCK_BOTTOM);
  425. pos.y = 0.0f;
  426. pos.x = xTrans + WIN_WIDTH - w;
  427. AddBlock(winMesh, winMesh->numPoints, &pos, w, h, d, BLOCK_RIGHT);
  428. // draw middle-vertical portion of frame
  429. pos.x = xTrans + (WIN_WIDTH - WIN_RIGHT_BORDER) / 2.0f - (WIN_CROSSBAR / 2.0f);
  430. pos.y = WIN_TOP_BORDER;
  431. pos.z = 0.0f;
  432. w = WIN_CROSSBAR;
  433. h = WIN_HEIGHT - 2.0f * WIN_TOP_BORDER;
  434. AddBlock(winMesh, 0, &pos, w, h, d, BLOCK_ALL | NO_BLEND);
  435. //
  436. // add the panels
  437. //
  438. w = (WIN_WIDTH - WIN_RIGHT_BORDER - WIN_CROSSBAR) / 2.0f;
  439. h = (WIN_HEIGHT - 2.0f * WIN_TOP_BORDER - WIN_CROSSBAR) / 2.0f;
  440. w /= (float)(iPrec / 2);
  441. curMatl = 2;
  442. pos.x = xTrans;
  443. pos.y = WIN_TOP_BORDER;
  444. for (i = 0, startBlend = winMesh->numPoints; i < iPrec / 2; i++) {
  445. AddFace(winMesh, startBlend, &pos, w, h);
  446. pos.x += w;
  447. }
  448. curMatl = 4;
  449. pos.x += WIN_CROSSBAR;
  450. for (i = 0, startBlend = winMesh->numPoints; i < iPrec / 2; i++) {
  451. AddFace(winMesh, startBlend, &pos, w, h);
  452. pos.x += w;
  453. }
  454. curMatl = 1;
  455. pos.x = xTrans;
  456. pos.y = WIN_TOP_BORDER + h + WIN_CROSSBAR;
  457. for (i = 0, startBlend = winMesh->numPoints; i < iPrec / 2; i++) {
  458. AddFace(winMesh, startBlend, &pos, w, h);
  459. pos.x += w;
  460. }
  461. curMatl = 3;
  462. pos.x += WIN_CROSSBAR;
  463. for (i = 0, startBlend = winMesh->numPoints; i < iPrec / 2; i++) {
  464. AddFace(winMesh, startBlend, &pos, w, h);
  465. pos.x += w;
  466. }
  467. ss_normalizeNorms(winMesh->norms, winMesh->numPoints);
  468. if( !newMesh(winStreamer, CUBE_FACES * WIN_NUMPIECES * WIN_NUMCOLUMNS,
  469. CUBE_POINTS * WIN_NUMPIECES * WIN_NUMCOLUMNS) )
  470. {
  471. return FALSE;
  472. }
  473. h = hMax = WIN_TOP_BORDER;
  474. w = wMax = WIN_TOP_BORDER * 1.1f;
  475. posCenter.x = pos.x = xTrans - wMax - WIN_GAP_X;
  476. posCenter.y = pos.y = 0.0f;
  477. for (i = 0; i < WIN_NUMCOLUMNS; i++) {
  478. for (j = 0; j < WIN_NUMPIECES; j++) {
  479. if (((j % 3) == 0) || (i == 0))
  480. curMatl = 0;
  481. else if (j < 3)
  482. curMatl = 2;
  483. else
  484. curMatl = 1;
  485. AddBlock(winStreamer, 0, &pos, w, h, d, BLOCK_ALL);
  486. pos.y += (hMax + WIN_GAP);
  487. }
  488. posCenter.x -= (wMax + WIN_GAP_X);
  489. posCenter.y = 0.0f;
  490. h = h * 0.8f;
  491. w = w * 0.8f;
  492. pos.x = posCenter.x;
  493. pos.y = posCenter.y;
  494. pos.x += (wMax - w) / 2.0f;
  495. pos.y += (hMax - h) / 2.0f;
  496. }
  497. ss_normalizeNorms(winStreamer->norms, winStreamer->numPoints);
  498. return TRUE;
  499. }
  500. BOOL initWinScene()
  501. {
  502. int i;
  503. float angleDelta;
  504. iPrec = (int)(fTesselFact * 10.5);
  505. if (iPrec < 5)
  506. iPrec = 5;
  507. if (iPrec > MAXPREC)
  508. iPrec = MAXPREC;
  509. /*
  510. glMatrixMode(GL_PROJECTION);
  511. glLoadIdentity();
  512. glOrtho(-1.0, 1.0, -0.75, 1.25, 0.0, 3.0);
  513. */
  514. SetProjectionMatrixInfo( TRUE, 2.0f, 2.0f, 0.0f, 3.0f );
  515. /*
  516. glTranslatef(0.0f, 0.0f, -1.5f);
  517. */
  518. D3DXMATRIX matView1, matReverseX, matView2;
  519. D3DXVECTOR3 vUpVec( 0.0f, 1.0f, 0.0f );
  520. D3DXVECTOR3 vEyePt(0, 0, 1.5f);
  521. D3DXVECTOR3 vLookatPt(0, 0, 0);
  522. D3DXMatrixLookAtLH( &matView1, &vEyePt, &vLookatPt, &vUpVec );
  523. D3DXMatrixScaling( &matReverseX, -1.0f, 1.0f, 1.0f );
  524. matView2 = matView1 * matReverseX;
  525. m_pd3dDevice->SetTransform( D3DTS_VIEW, &matView2 );
  526. // Light 0
  527. D3DLIGHT8 light;
  528. m_pd3dDevice->GetLight(0, &light);
  529. light.Position.x = light0Pos[0];
  530. light.Position.y = light0Pos[1];
  531. light.Position.z = light0Pos[2];
  532. m_pd3dDevice->SetLight(0, &light);
  533. // Light 1
  534. light.Type = D3DLIGHT_POINT;
  535. light.Ambient.r = light1Ambient.r;
  536. light.Ambient.g = light1Ambient.g;
  537. light.Ambient.b = light1Ambient.b;
  538. light.Ambient.a = light1Ambient.a;
  539. light.Diffuse.r = light1Diffuse.r;
  540. light.Diffuse.g = light1Diffuse.g;
  541. light.Diffuse.b = light1Diffuse.b;
  542. light.Diffuse.a = light1Diffuse.a;
  543. light.Specular.r = light1Specular.r;
  544. light.Specular.g = light1Specular.g;
  545. light.Specular.b = light1Specular.b;
  546. light.Specular.a = light1Specular.a;
  547. light.Position.x = light1Pos[0];
  548. light.Position.y = light1Pos[1];
  549. light.Position.z = light1Pos[2];
  550. m_pd3dDevice->SetLight(1, &light);
  551. m_pd3dDevice->LightEnable(1, TRUE);
  552. /*
  553. glMatrixMode(GL_MODELVIEW);
  554. glFrontFace(GL_CCW);
  555. glEnable(GL_CULL_FACE);
  556. */
  557. m_pd3dDevice->SetRenderState( D3DRS_CULLMODE, D3DCULL_NONE );
  558. Frames = (int)((float)(MAX_FRAMES / 2) * fTesselFact);
  559. if (Frames < 5)
  560. Frames = 5;
  561. if (Frames > MAX_FRAMES)
  562. Frames = MAX_FRAMES;
  563. angleDelta = (float) ((2.0 * PI) / Frames);
  564. sinAngle = 0.0f;
  565. for (i = 0; i < Frames; i++) {
  566. if( !genWin(&winMesh[i], &winStreamer[i]) )
  567. return FALSE;
  568. sinAngle += angleDelta;
  569. }
  570. return TRUE;
  571. }
  572. void delWinScene()
  573. {
  574. int i;
  575. for (i = 0; i < Frames; i++) {
  576. delMesh(&winMesh[i]);
  577. delMesh(&winStreamer[i]);
  578. }
  579. }
  580. void updateWinScene(int flags, FLOAT fElapsedTime)
  581. {
  582. MESH *mesh;
  583. static double mxrot = 23.0;
  584. static double myrot = 23.0;
  585. static double mzrot = 5.7;
  586. static double mxrotInc = 0.0;
  587. static double myrotInc = 3.0;
  588. static double mzrotInc = 0.0;
  589. static FLOAT fH = 0.0f;
  590. static int frameNum = 0;
  591. static FLOAT fFrameNum = 0.0f;
  592. if( fElapsedTime > 0.25f )
  593. fElapsedTime = 0.25f;
  594. FLOAT fTimeFactor = fElapsedTime * 20.0f;
  595. D3DXMATRIX mat1, mat2, mat3, matFinal;
  596. if (bColorCycle) {
  597. ss_HsvToRgb(fH, 1.0f, 1.0f, &winColors[0] );
  598. fH += fTimeFactor;
  599. if( fH >= 360.0f )
  600. fH -= 360.0f;
  601. }
  602. D3DXMatrixRotationX(&mat1, D3DXToRadian((FLOAT)mxrot));
  603. D3DXMatrixRotationY(&mat2, D3DXToRadian((FLOAT)myrot));
  604. D3DXMatrixRotationZ(&mat3, D3DXToRadian((FLOAT)mzrot));
  605. matFinal = mat3 * mat2 * mat1 ;
  606. m_pd3dDevice->SetTransform( D3DTS_WORLD , &matFinal );
  607. curMatl = 0;
  608. myglMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, (FLOAT *) &winColors[0]);
  609. myglMaterialfv(GL_FRONT, GL_SPECULAR, (FLOAT *) &matlBrightSpecular);
  610. myglMaterialf(GL_FRONT, GL_SHININESS, 60.0f);
  611. mesh = &winMesh[frameNum];
  612. {
  613. HRESULT hr;
  614. MESH* pMesh = mesh;
  615. INT numPrims = 0;
  616. INT numIndices = 0;
  617. INT numVertices = 0;
  618. WORD* i;
  619. MYVERTEX* v;
  620. hr = m_pVB->Lock( 0, 0, (BYTE**)&v, 0 );
  621. hr = m_pIB->Lock( 0, MAX_INDICES, (BYTE**)&i, 0 );
  622. m_pd3dDevice->SetVertexShader( D3DFVF_MYVERTEX );
  623. for( int iFace = 0; iFace < pMesh->numFaces; iFace++ )
  624. {
  625. if (pMesh->faces[iFace].material != curMatl)
  626. {
  627. hr = m_pVB->Unlock();
  628. hr = m_pIB->Unlock();
  629. hr = m_pd3dDevice->SetStreamSource( 0, m_pVB, sizeof(MYVERTEX) );
  630. hr = m_pd3dDevice->SetIndices( m_pIB, 0 );
  631. hr = m_pd3dDevice->DrawIndexedPrimitive( D3DPT_TRIANGLELIST, 0, numVertices,
  632. 0, numPrims );
  633. numVertices = 0;
  634. numIndices = 0;
  635. numPrims = 0;
  636. hr = m_pVB->Lock( 0, 0, (BYTE**)&v, 0 );
  637. hr = m_pIB->Lock( 0, MAX_INDICES, (BYTE**)&i, 0 );
  638. curMatl = pMesh->faces[iFace].material;
  639. myglMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR,
  640. (FLOAT *) &matlNoSpecular);
  641. myglMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE,
  642. (FLOAT *) &winColors[curMatl]);
  643. }
  644. v[numVertices+0].p = pMesh->pts[ pMesh->faces[iFace].p[0] ];
  645. v[numVertices+1].p = pMesh->pts[ pMesh->faces[iFace].p[1] ];
  646. v[numVertices+2].p = pMesh->pts[ pMesh->faces[iFace].p[2] ];
  647. v[numVertices+3].p = pMesh->pts[ pMesh->faces[iFace].p[3] ];
  648. if( bSmoothShading )
  649. {
  650. v[numVertices+0].n = pMesh->norms[ pMesh->faces[iFace].p[0] ];
  651. v[numVertices+1].n = pMesh->norms[ pMesh->faces[iFace].p[1] ];
  652. v[numVertices+2].n = pMesh->norms[ pMesh->faces[iFace].p[2] ];
  653. v[numVertices+3].n = pMesh->norms[ pMesh->faces[iFace].p[3] ];
  654. }
  655. else
  656. {
  657. v[numVertices+0].n = pMesh->faces[iFace].norm;
  658. v[numVertices+1].n = pMesh->faces[iFace].norm;
  659. v[numVertices+2].n = pMesh->faces[iFace].norm;
  660. v[numVertices+3].n = pMesh->faces[iFace].norm;
  661. }
  662. i[numIndices++] = numVertices + 0;
  663. i[numIndices++] = numVertices + 1;
  664. i[numIndices++] = numVertices + 2;
  665. i[numIndices++] = numVertices + 2;
  666. i[numIndices++] = numVertices + 0;
  667. i[numIndices++] = numVertices + 3;
  668. numVertices += 4;
  669. numPrims += 2;
  670. }
  671. hr = m_pVB->Unlock();
  672. hr = m_pIB->Unlock();
  673. hr = m_pd3dDevice->SetStreamSource( 0, m_pVB, sizeof(MYVERTEX) );
  674. hr = m_pd3dDevice->SetIndices( m_pIB, 0 );
  675. hr = m_pd3dDevice->DrawIndexedPrimitive( D3DPT_TRIANGLELIST, 0, numVertices,
  676. 0, numPrims );
  677. }
  678. myglMaterialfv(GL_FRONT, GL_SPECULAR, (FLOAT *) &matlDimSpecular);
  679. mesh = &winStreamer[frameNum];
  680. {
  681. HRESULT hr;
  682. MESH* pMesh = mesh;
  683. INT numPrims = 0;
  684. INT numIndices = 0;
  685. INT numVertices = 0;
  686. WORD* i;
  687. MYVERTEX* v;
  688. hr = m_pVB->Lock( 0, 0, (BYTE**)&v, 0 );
  689. hr = m_pIB->Lock( 0, MAX_INDICES, (BYTE**)&i, 0 );
  690. m_pd3dDevice->SetVertexShader( D3DFVF_MYVERTEX );
  691. for( int iFace = 0; iFace < pMesh->numFaces; iFace++ )
  692. {
  693. if (pMesh->faces[iFace].material != curMatl)
  694. {
  695. hr = m_pVB->Unlock();
  696. hr = m_pIB->Unlock();
  697. hr = m_pd3dDevice->SetStreamSource( 0, m_pVB, sizeof(MYVERTEX) );
  698. hr = m_pd3dDevice->SetIndices( m_pIB, 0 );
  699. hr = m_pd3dDevice->DrawIndexedPrimitive( D3DPT_TRIANGLELIST, 0, numVertices,
  700. 0, numPrims );
  701. numVertices = 0;
  702. numIndices = 0;
  703. numPrims = 0;
  704. hr = m_pVB->Lock( 0, 0, (BYTE**)&v, 0 );
  705. hr = m_pIB->Lock( 0, MAX_INDICES, (BYTE**)&i, 0 );
  706. curMatl = pMesh->faces[iFace].material;
  707. myglMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE,
  708. (FLOAT *) &winColors[curMatl]);
  709. }
  710. v[numVertices+0].p = pMesh->pts[ pMesh->faces[iFace].p[0] ];
  711. v[numVertices+1].p = pMesh->pts[ pMesh->faces[iFace].p[1] ];
  712. v[numVertices+2].p = pMesh->pts[ pMesh->faces[iFace].p[2] ];
  713. v[numVertices+3].p = pMesh->pts[ pMesh->faces[iFace].p[3] ];
  714. v[numVertices+0].n = pMesh->faces[iFace].norm;
  715. v[numVertices+1].n = pMesh->faces[iFace].norm;
  716. v[numVertices+2].n = pMesh->faces[iFace].norm;
  717. v[numVertices+3].n = pMesh->faces[iFace].norm;
  718. i[numIndices++] = numVertices + 0;
  719. i[numIndices++] = numVertices + 1;
  720. i[numIndices++] = numVertices + 2;
  721. i[numIndices++] = numVertices + 2;
  722. i[numIndices++] = numVertices + 0;
  723. i[numIndices++] = numVertices + 3;
  724. numVertices += 4;
  725. numPrims += 2;
  726. }
  727. hr = m_pVB->Unlock();
  728. hr = m_pIB->Unlock();
  729. hr = m_pd3dDevice->SetStreamSource( 0, m_pVB, sizeof(MYVERTEX) );
  730. hr = m_pd3dDevice->SetIndices( m_pIB, 0 );
  731. hr = m_pd3dDevice->DrawIndexedPrimitive( D3DPT_TRIANGLELIST, 0, numVertices,
  732. 0, numPrims );
  733. }
  734. mxrot += mxrotInc * fTimeFactor;
  735. myrot += myrotInc * fTimeFactor;
  736. mzrot += mzrotInc * fTimeFactor;
  737. if ((myrot < -45.0 && myrotInc < 0) || (myrot > 45.0 && myrotInc > 0))
  738. myrotInc = -myrotInc;
  739. fFrameNum += fTimeFactor;
  740. frameNum = (INT)fFrameNum;
  741. if (frameNum >= Frames)
  742. {
  743. frameNum = 0;
  744. fFrameNum -= Frames;
  745. }
  746. }