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.

468 lines
11 KiB

  1. //-----------------------------------------------------------------------------
  2. // File: FlyingObjects.h
  3. //
  4. // Desc:
  5. //
  6. // Copyright (c) 2000 Microsoft Corporation. All rights reserved.
  7. //-----------------------------------------------------------------------------
  8. #ifndef _FLYINGOBJECTS_H
  9. #define _FLYINGOBJECTS_H
  10. #include "resource.h"
  11. #define PI 3.14159265358979323846f
  12. // double version of PI
  13. #define PI_D 3.14159265358979323846264338327950288419716939937510
  14. #define ONE_OVER_PI (1.0f / PI)
  15. #define ROOT_TWO 1.414213562373f
  16. #define GEN_STRING_SIZE 64
  17. typedef struct _point2d {
  18. FLOAT x;
  19. FLOAT y;
  20. } POINT2D;
  21. typedef struct _ipoint2d {
  22. int x;
  23. int y;
  24. } IPOINT2D;
  25. typedef D3DXVECTOR3 POINT3D;
  26. typedef struct _ipoint3d {
  27. int x;
  28. int y;
  29. int z;
  30. } IPOINT3D;
  31. typedef struct _texpoint2d {
  32. FLOAT s;
  33. FLOAT t;
  34. } TEX_POINT2D;
  35. typedef struct _isize {
  36. int width;
  37. int height;
  38. } ISIZE;
  39. typedef struct _fsize {
  40. FLOAT width;
  41. FLOAT height;
  42. } FSIZE;
  43. typedef struct _glrect {
  44. int x, y;
  45. int width, height;
  46. } GLRECT;
  47. // texture data
  48. typedef struct {
  49. int width;
  50. int height;
  51. DWORD format;
  52. INT components;
  53. float origAspectRatio; // original width/height aspect ratio
  54. unsigned char *data;
  55. DWORD texObj; // texture object
  56. int pal_size;
  57. int iPalRot; // current palette rotation (not used yet)
  58. RGBQUAD *pal;
  59. } TEXTURE, *HTEXTURE;
  60. // texture resource
  61. #define RT_RGB 99
  62. #define RT_MYBMP 100
  63. #define RT_A8 101
  64. // texture resource types
  65. enum {
  66. TEX_UNKNOWN = 0,
  67. TEX_RGB,
  68. TEX_BMP,
  69. TEX_A8
  70. };
  71. typedef struct {
  72. int type;
  73. int name;
  74. } TEX_RES;
  75. typedef struct _MATRIX {
  76. FLOAT M[4][4];
  77. } MATRIX;
  78. //typedef D3DXMATRIX MATRIX;
  79. typedef struct strRGBA {
  80. FLOAT r;
  81. FLOAT g;
  82. FLOAT b;
  83. FLOAT a;
  84. } RGBA;
  85. typedef struct {
  86. BYTE r;
  87. BYTE g;
  88. BYTE b;
  89. } RGB8;
  90. typedef struct {
  91. BYTE r;
  92. BYTE g;
  93. BYTE b;
  94. BYTE a;
  95. } RGBA8;
  96. typedef struct _MATERIAL {
  97. RGBA ka;
  98. RGBA kd;
  99. RGBA ks;
  100. FLOAT specExp;
  101. } MATERIAL;
  102. // texture file info
  103. typedef struct {
  104. int nOffset; // filename offset into pathname
  105. TCHAR szPathName[MAX_PATH]; // texture pathname
  106. } TEXFILE;
  107. // texture file processing messages
  108. typedef struct {
  109. TCHAR szWarningMsg[MAX_PATH];
  110. TCHAR szBitmapSizeMsg[MAX_PATH];
  111. TCHAR szBitmapInvalidMsg[MAX_PATH];
  112. TCHAR szSelectAnotherBitmapMsg[MAX_PATH];
  113. TCHAR szTextureDialogTitle[GEN_STRING_SIZE];
  114. TCHAR szTextureFilter[2*GEN_STRING_SIZE];
  115. TCHAR szBmp[GEN_STRING_SIZE];
  116. TCHAR szDotBmp[GEN_STRING_SIZE];
  117. } TEX_STRINGS;
  118. // Useful macros
  119. #define SS_MAX( a, b ) \
  120. ( a > b ? a : b )
  121. #define SS_MIN( a, b ) \
  122. ( a < b ? a : b )
  123. // macro to round up floating values
  124. #define SS_ROUND_UP( fval ) \
  125. ( (((fval) - (FLOAT)(int)(fval)) > 0.0f) ? (int) ((fval)+1.0f) : (int) (fval) )
  126. // macros to clamp a value within a range
  127. #define SS_CLAMP_TO_RANGE( a, lo, hi ) ( (a < lo) ? lo : ((a > hi) ? hi : a) )
  128. #define SS_CLAMP_TO_RANGE2( a, lo, hi ) \
  129. ( a = (a < lo) ? lo : ((a > hi) ? hi : a) )
  130. // degree<->radian macros
  131. #define ONE_OVER_180 (1.0f / 180.0f)
  132. #define SS_DEG_TO_RAD( a ) ( (a*PI) * ONE_OVER_180 )
  133. #define SS_RAD_TO_DEG( a ) ( (a*180.0f) * ONE_OVER_PI )
  134. extern MATERIAL TeaMaterial[], TexMaterial[], ss_BlackMat;
  135. // color
  136. extern void ss_HsvToRgb(float h, float s, float v, RGBA *color );
  137. // texture file processing
  138. extern void ss_DisableTextureErrorMsgs();
  139. extern void ss_SetTexture( TEXTURE *pTex );
  140. extern void ss_SetTexturePalette( TEXTURE *pTex, int index );
  141. extern void ss_DeleteTexture( TEXTURE *pTex );
  142. extern BOOL ss_LoadTextureResourceStrings();
  143. extern BOOL ss_VerifyTextureFile( TEXFILE *ptf );
  144. extern BOOL ss_SelectTextureFile( HWND hDlg, TEXFILE *ptf );
  145. extern void ss_GetDefaultBmpFile( LPTSTR pszBmpFile );
  146. extern void ss_InitAutoTexture( TEX_POINT2D *pTexRep );
  147. // math functions
  148. extern POINT3D ss_ptZero;
  149. extern void ss_xformPoint(POINT3D *ptOut, POINT3D *ptIn, MATRIX *);
  150. extern void ss_xformNorm(POINT3D *ptOut, POINT3D *ptIn, MATRIX *);
  151. extern void ss_matrixIdent(MATRIX *);
  152. extern void ss_matrixRotate(MATRIX *m, double xTheta, double yTheta, double zTheta);
  153. extern void ss_matrixTranslate(MATRIX *, double xTrans, double yTrans, double zTrans);
  154. extern void ss_matrixMult( MATRIX *m1, MATRIX *m2, MATRIX *m3 );
  155. extern void ss_calcNorm(POINT3D *norm, POINT3D *p1, POINT3D *p2, POINT3D *p3);
  156. extern void ss_normalizeNorm(POINT3D *);
  157. extern void ss_normalizeNorms(POINT3D *, ULONG);
  158. // dialog helper functions
  159. extern int ss_GetTrackbarPos( HWND hDlg, int item );
  160. extern void ss_SetupTrackbar( HWND hDlg, int item, int lo, int hi, int lineSize, int pageSize, int pos );
  161. extern BOOL gbTextureObjects; // from texture.c
  162. //-----------------------------------------------------------------------------
  163. // Name: struct MYVERTEX
  164. // Desc: D3D vertex type for this app
  165. //-----------------------------------------------------------------------------
  166. struct MYVERTEX
  167. {
  168. D3DXVECTOR3 p; // Position
  169. D3DXVECTOR3 n; // Normal
  170. };
  171. #define D3DFVF_MYVERTEX ( D3DFVF_XYZ | D3DFVF_NORMAL )
  172. //-----------------------------------------------------------------------------
  173. // Name: struct MYVERTEX2
  174. // Desc: D3D vertex type for this app
  175. //-----------------------------------------------------------------------------
  176. struct MYVERTEX2
  177. {
  178. D3DXVECTOR3 p; // Position
  179. D3DXVECTOR3 n; // Normal
  180. FLOAT tu, tv; // Vertex texture coordinates
  181. };
  182. #define D3DFVF_MYVERTEX2 ( D3DFVF_XYZ | D3DFVF_NORMAL | D3DFVF_TEX1 )
  183. //-----------------------------------------------------------------------------
  184. // Name: struct MYVERTEX3
  185. // Desc: D3D vertex type for this app
  186. //-----------------------------------------------------------------------------
  187. struct MYVERTEX3
  188. {
  189. D3DXVECTOR3 p; // Position
  190. FLOAT rhw;
  191. DWORD dwDiffuse;
  192. FLOAT tu, tv; // Vertex texture coordinates
  193. };
  194. #define D3DFVF_MYVERTEX3 ( D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_TEX1 )
  195. #define MAX_VERTICES 5000
  196. #define MAX_INDICES 5000
  197. //-----------------------------------------------------------------------------
  198. // Name: struct FLOATRECT
  199. // Desc: Floating viewport rect
  200. //-----------------------------------------------------------------------------
  201. struct FLOATRECT
  202. {
  203. FLOAT xMin;
  204. FLOAT yMin;
  205. FLOAT xSize;
  206. FLOAT ySize;
  207. FLOAT xVel;
  208. FLOAT yVel;
  209. FLOAT xOrigin;
  210. FLOAT yOrigin;
  211. FLOAT xVelMax;
  212. FLOAT yVelMax;
  213. };
  214. #ifndef PI
  215. #define PI 3.14159265358979323846
  216. #endif
  217. // Minimum and maximum number of side subdivisions
  218. #define MINSUBDIV 2
  219. #define MAXSUBDIV 10
  220. // Maximum values allowed
  221. #define MAXSIDES 8
  222. #define MAXSPTS ((MAXSUBDIV+1)*(MAXSUBDIV+1))
  223. #define MAXPTS (MAXSIDES*MAXSPTS)
  224. #define MAXSFACES (MAXSUBDIV*MAXSUBDIV)
  225. #define MAXFACES (MAXSIDES*MAXSFACES)
  226. #define MAXFPTS 4
  227. // Allow floating point type configurability
  228. typedef FLOAT FLT;
  229. typedef struct
  230. {
  231. FLT x, y, z;
  232. } PT3;
  233. extern LPDIRECT3DDEVICE8 m_pd3dDevice;
  234. extern LPDIRECT3DINDEXBUFFER8 m_pIB;
  235. extern LPDIRECT3DVERTEXBUFFER8 m_pVB;
  236. extern LPDIRECT3DVERTEXBUFFER8 m_pVB2;
  237. #define DIMA(a) (sizeof(a)/sizeof(a[0]))
  238. #define PALETTE_PER_MATL 32
  239. #define PALETTE_PER_DIFF 26
  240. #define PALETTE_PER_SPEC 6
  241. #define MATL_MAX 7
  242. typedef struct strFACE {
  243. POINT3D p[4];
  244. POINT3D n[4];
  245. POINT3D fn;
  246. int idMatl;
  247. } FACE;
  248. typedef struct strMFACE {
  249. int p[4];
  250. int material;
  251. POINT3D norm;
  252. } MFACE;
  253. typedef struct strMESH {
  254. int numFaces;
  255. int numPoints;
  256. POINT3D *pts;
  257. POINT3D *norms;
  258. MFACE *faces;
  259. INT listID;
  260. } MESH;
  261. /******************************Public*Routine******************************\
  262. *
  263. * Basic vector math macros
  264. *
  265. * History:
  266. * Wed Jul 19 14:49:49 1995 -by- Drew Bliss [drewb]
  267. * Created
  268. *
  269. \**************************************************************************/
  270. #define V3Sub(a, b, r) \
  271. ((r)->x = (a)->x-(b)->x, (r)->y = (a)->y-(b)->y, (r)->z = (a)->z-(b)->z)
  272. #define V3Add(a, b, r) \
  273. ((r)->x = (a)->x+(b)->x, (r)->y = (a)->y+(b)->y, (r)->z = (a)->z+(b)->z)
  274. #define V3Cross(a, b, r) \
  275. ((r)->x = (a)->y*(b)->z-(b)->y*(a)->z,\
  276. (r)->y = (a)->z*(b)->x-(b)->z*(a)->x,\
  277. (r)->z = (a)->x*(b)->y-(b)->x*(a)->y)
  278. extern FLT V3Len(PT3 *v);
  279. #define MAX_DEVICE_OBJECTS 10
  280. struct DeviceObjects
  281. {
  282. LPDIRECT3DTEXTURE8 m_pTexture;
  283. LPDIRECT3DTEXTURE8 m_pTexture2;
  284. LPDIRECT3DINDEXBUFFER8 m_pIB;
  285. LPDIRECT3DVERTEXBUFFER8 m_pVB; // D3DFVF_MYVERTEX (no tex coords)
  286. LPDIRECT3DVERTEXBUFFER8 m_pVB2; // D3DFVF_MYVERTEX2 (tex coords)
  287. };
  288. extern DeviceObjects* g_pDeviceObjects;
  289. extern FLOATRECT* g_pFloatRect;
  290. extern INT g_xScreenOrigin;
  291. extern INT g_yScreenOrigin;
  292. extern INT g_iDevice;
  293. extern BOOL g_bMoveToOrigin;
  294. extern BOOL g_bAtOrigin;
  295. extern BOOL bSmoothShading;
  296. extern BOOL bFalseColor;
  297. extern BOOL bColorCycle;
  298. extern float fTesselFact;
  299. extern TEXFILE gTexFile;
  300. extern BOOL gbBounce;
  301. extern D3DMATERIAL8 Material[];
  302. extern int NumLights;
  303. extern BOOL newMesh(MESH *, int numFaces, int numPts);
  304. extern void delMesh(MESH *);
  305. extern void revolveSurface(MESH *, POINT3D *curve, int steps);
  306. extern void *SaverAlloc(ULONG);
  307. extern void SaverFree(void *);
  308. #ifndef GL_FRONT
  309. #define GL_FRONT 0x0404
  310. #endif
  311. #ifndef GL_FRONT_AND_BACK
  312. #define GL_FRONT_AND_BACK 0x0408
  313. #endif
  314. #ifndef GL_AMBIENT_AND_DIFFUSE
  315. #define GL_AMBIENT_AND_DIFFUSE 0x1602
  316. #endif
  317. #ifndef GL_SHININESS
  318. #define GL_SHININESS 0x1601
  319. #endif
  320. #ifndef GL_SPECULAR
  321. #define GL_SPECULAR 0x1202
  322. #endif
  323. extern VOID myglMaterialfv(INT face, INT pname, FLOAT* params);
  324. extern VOID myglMaterialf(INT face, INT pname, FLOAT param);
  325. VOID SetProjectionMatrixInfo( BOOL bOrtho, FLOAT fWidth,
  326. FLOAT fHeight, FLOAT fNear, FLOAT fFar );
  327. class CFlyingObjectsScreensaver : public CD3DScreensaver
  328. {
  329. protected:
  330. FLOATRECT m_floatrect;
  331. DeviceObjects m_DeviceObjectsArray[MAX_DEVICE_OBJECTS];
  332. DeviceObjects* m_pDeviceObjects;
  333. public:
  334. // Projection matrix settings
  335. BOOL m_bOrtho;
  336. FLOAT m_fWidth;
  337. FLOAT m_fHeight;
  338. FLOAT m_fNear;
  339. FLOAT m_fFar;
  340. protected:
  341. virtual HRESULT RegisterSoftwareDevice();
  342. virtual VOID SetDevice( UINT iDevice );
  343. virtual VOID DoConfig();
  344. virtual VOID ReadSettings();
  345. virtual HRESULT Render();
  346. virtual HRESULT FrameMove();
  347. virtual HRESULT RestoreDeviceObjects();
  348. virtual HRESULT InvalidateDeviceObjects();
  349. virtual HRESULT ConfirmDevice(D3DCAPS8* pCaps, DWORD dwBehavior,
  350. D3DFORMAT fmtBackBuffer);
  351. VOID WriteSettings( HWND hdlg );
  352. VOID ss_ReadSettings();
  353. BOOL ss_RegistrySetup( int section, int file );
  354. int ss_GetRegistryInt( int name, int iDefault );
  355. VOID ss_GetRegistryString( int name, LPTSTR lpDefault, LPTSTR lpDest, int bufSize );
  356. static BOOL CALLBACK ScreenSaverConfigureDialog(HWND hDlg, UINT message,
  357. WPARAM wParam, LPARAM lParam);
  358. HRESULT SetMaterialColor(FLOAT* pfColors);
  359. BOOL _3dfo_Init(void *data);
  360. void _3dfo_Draw(void *data);
  361. public:
  362. CFlyingObjectsScreensaver();
  363. };
  364. #endif