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.

941 lines
30 KiB

  1. /*******************************************************************************
  2. * DXBounds.h *
  3. *------------*
  4. * Description:
  5. * This is the header file for the bounds helper class implementation.
  6. *-------------------------------------------------------------------------------
  7. * Created By: Edward W. Connell Date: 07/22/97
  8. * Copyright (C) 1997 Microsoft Corporation
  9. * All Rights Reserved
  10. *
  11. *-------------------------------------------------------------------------------
  12. * Revisions:
  13. *
  14. *******************************************************************************/
  15. #ifndef DXBounds_h
  16. #define DXBounds_h
  17. #ifndef _INC_LIMITS
  18. #include <limits.h>
  19. #endif
  20. #ifndef _INC_FLOAT
  21. #include <float.h>
  22. #endif
  23. #ifndef __DXTrans_h__
  24. #include <DXTrans.h>
  25. #endif
  26. #ifndef DXVector_h
  27. #include <DXVector.h>
  28. #endif
  29. //=== Constants ====================================================
  30. #ifdef _ASSERT
  31. #define CHKTYPE() _ASSERT( eType == eBndType )
  32. #else
  33. #define CHKTYPE()
  34. #endif
  35. //=== Class, Enum, Struct and Union Declarations ===================
  36. //=== Enumerated Set Definitions ===================================
  37. //=== Function Type Definitions ====================================
  38. //=== Class, Struct and Union Definitions ==========================
  39. /*** CDXBnds
  40. *
  41. */
  42. #define CDXB_C CDXBnds<TYPE, USTYPE, STTYPE, eBndType>
  43. #define CDXB_T ((STTYPE*)u.D)
  44. #define CDXB_O( OtherBnd ) ((STTYPE*)(OtherBnd).u.D)
  45. template<class TYPE, class USTYPE, class STTYPE, DXBNDTYPE eBndType>
  46. class CDXBnds : public DXBNDS
  47. {
  48. public:
  49. /*--- Constructors ---*/
  50. CDXBnds() { eType = eBndType; SetEmpty(); }
  51. CDXBnds( BOOL bInit ) { eType = eBndType; if (bInit) SetEmpty(); }
  52. CDXBnds( const DXBNDS& Other ) { eType = eBndType; Copy( Other ); }
  53. CDXBnds( const CDXB_C& Other ) { eType = eBndType; Copy( Other ); }
  54. CDXBnds( const RECT & Rect ) { eType = eBndType; SetXYRect( Rect ); }
  55. CDXBnds( TYPE Width, TYPE Height ) { eType = eBndType; SetXYSize( Width, Height ); }
  56. CDXBnds( IDXSurface *pSurface, HRESULT & hr) { _ASSERT(eBndType == DXBT_DISCRETE); eType = eBndType; hr = pSurface->GetBounds(this); }
  57. CDXBnds( IDirect3DRMMeshBuilder3 *pMesh, HRESULT & hr) { _ASSERT(eBndType == DXBT_CONTINUOUS); eType = eBndType; hr = SetToMeshBounds(pMesh); }
  58. CDXBnds( const CDXV_C& VecPoint ) { eType = eBndType; *this = VecPoint; }
  59. HRESULT InitFromSafeArray( SAFEARRAY *psa);
  60. HRESULT GetSafeArray( SAFEARRAY **ppsa ) const;
  61. void SetEmpty();
  62. void Copy( const DXBNDS& Other );
  63. void Copy( const CDXB_C& Other );
  64. /*--- Type casts ---*/
  65. operator STTYPE * () { CHKTYPE(); return CDXB_T; }
  66. operator DXDBNDS& () { CHKTYPE(); return u.D; }
  67. operator DXDBNDS64& () { CHKTYPE(); return u.LD; }
  68. operator DXCBNDS& () { CHKTYPE(); return u.C; }
  69. operator DXCBNDS64& () { CHKTYPE(); return u.LC; }
  70. //--- Access methods
  71. USTYPE Width( DXBNDID i ) const { CHKTYPE(); return (USTYPE)(CDXB_T[i].Max - CDXB_T[i].Min); }
  72. USTYPE Width() const { CHKTYPE(); return (USTYPE)(CDXB_T[DXB_X].Max - CDXB_T[DXB_X].Min); }
  73. USTYPE Height() const { CHKTYPE(); return (USTYPE)(CDXB_T[DXB_Y].Max - CDXB_T[DXB_Y].Min); }
  74. USTYPE Depth() const { CHKTYPE(); return (USTYPE)(CDXB_T[DXB_Z].Max - CDXB_T[DXB_Z].Min); }
  75. USTYPE Duration() const { CHKTYPE(); return (USTYPE)(CDXB_T[DXB_T].Max - CDXB_T[DXB_T].Min); }
  76. TYPE Left() const { CHKTYPE(); return CDXB_T[DXB_X].Min; }
  77. TYPE Right() const { CHKTYPE(); return CDXB_T[DXB_X].Max; }
  78. TYPE Top() const { CHKTYPE(); return CDXB_T[DXB_Y].Min; }
  79. TYPE Bottom() const { CHKTYPE(); return CDXB_T[DXB_Y].Max; }
  80. void SetBounds( TYPE xmin, TYPE xmax, TYPE ymin, TYPE ymax,
  81. TYPE zmin, TYPE zmax, TYPE tmin, TYPE tmax );
  82. void SetXYRect( const RECT& xyRect);
  83. void SetXYSize( const SIZE& xySize);
  84. void SetXYSize( TYPE width, TYPE height);
  85. void SetXYPoint(const POINT& xyPoint);
  86. void Offset( TYPE x, TYPE y, TYPE z, TYPE t );
  87. void Offset( const CDXV_C& v );
  88. void SetPlacement(const CDXV_C& v);
  89. void SetToSize(void);
  90. void GetXYRect( RECT& xyRect ) const;
  91. void GetXYSize( SIZE& xySize ) const;
  92. void GetMinVector( CDXV_C& v ) const;
  93. void GetMaxVector( CDXV_C& v ) const;
  94. void GetSize( CDXB_C& SizeBounds ) const;
  95. CDXB_C Size( void ) const;
  96. //--- Region Functions
  97. void NormalizeBounds();
  98. BOOL BoundsAreEmpty() const;
  99. BOOL BoundsAreNull() const;
  100. BOOL TestIntersect( const CDXB_C& Other ) const;
  101. BOOL IntersectBounds( const CDXB_C& Bounds1, const CDXB_C& Bounds2 );
  102. BOOL IntersectBounds( const CDXB_C& OtherBounds );
  103. void UnionBounds( const CDXB_C& Bounds1, const CDXB_C& Bounds2 );
  104. // Additional Operations
  105. STTYPE& operator[]( int index ) const { CHKTYPE(); return CDXB_T[index]; }
  106. STTYPE& operator[]( long index ) const { CHKTYPE(); return CDXB_T[index]; }
  107. STTYPE& operator[]( USHORT index ) const { CHKTYPE(); return CDXB_T[index]; }
  108. STTYPE& operator[]( DWORD index ) const { CHKTYPE(); return CDXB_T[index]; }
  109. STTYPE& operator[]( DXBNDID index) const { CHKTYPE(); return CDXB_T[index]; }
  110. void operator=(const CDXB_C& Bounds);
  111. void operator=(const CDXV_C& v);
  112. void operator+=(const POINT& point);
  113. void operator-=(const POINT& point);
  114. void operator+=(const SIZE& size);
  115. void operator-=(const SIZE& size);
  116. void operator+=(const CDXV_C& v);
  117. void operator-=(const CDXV_C& v);
  118. void operator+=(const CDXB_C& Bounds);
  119. void operator-=(const CDXB_C& Bounds);
  120. void operator&=(const CDXB_C& Bounds);
  121. void operator|=(const CDXB_C& Bounds);
  122. BOOL operator==(const CDXB_C& Bounds) const;
  123. BOOL operator!=(const CDXB_C& Bounds) const;
  124. // Operators returning CDXDBnds values
  125. CDXB_C operator+(const POINT& point) const;
  126. CDXB_C operator-(const POINT& point) const;
  127. CDXB_C operator+(const SIZE& size) const;
  128. CDXB_C operator-(const SIZE& size) const;
  129. CDXB_C operator+(const CDXV_C& v) const;
  130. CDXB_C operator-(const CDXV_C& v) const;
  131. CDXB_C operator&(const CDXB_C& Bounds2) const;
  132. CDXB_C operator|(const CDXB_C& Bounds2) const;
  133. //
  134. // Helpers to grow bounds from their midpoints.
  135. //
  136. void Scale(TYPE x, TYPE y = 1, TYPE z = 1, TYPE t = 1);
  137. void Scale(const CDXV_C& v);
  138. void Expand(TYPE x, TYPE y = 0, TYPE z = 0, TYPE t = 0);
  139. void Expand(const CDXV_C& v);
  140. // Helpers for DXSurfaces These functions only work with DISCRETE bounds
  141. HRESULT SetToSurfaceBounds(IDXSurface * pDXSurface);
  142. // Helpers for D3DRM Meshes. These functions only work with CONTINUOUS bounds.
  143. HRESULT SetToMeshBounds(IDirect3DRMMeshBuilder3 * pMesh);
  144. };
  145. template<class TYPE, class USTYPE, class STTYPE, DXBNDTYPE eBndType>
  146. void CDXB_C::SetEmpty()
  147. {
  148. CHKTYPE();
  149. memset(CDXB_T, 0, sizeof(STTYPE) * 4);
  150. } /* CDXBnds::SetEmpty() */
  151. template<class TYPE, class USTYPE, class STTYPE, DXBNDTYPE eBndType>
  152. void CDXB_C::Copy( const CDXB_C& Other )
  153. {
  154. CHKTYPE();
  155. memcpy( CDXB_T, CDXB_O(Other), sizeof( STTYPE ) * 4 );
  156. }
  157. template<class TYPE, class USTYPE, class STTYPE, DXBNDTYPE eBndType>
  158. void CDXB_C::Copy( const DXBNDS& Other )
  159. {
  160. CHKTYPE();
  161. if( eBndType == Other.eType )
  162. {
  163. memcpy( CDXB_T, CDXB_O(Other), sizeof( STTYPE ) * 4 );
  164. }
  165. else
  166. {
  167. int i = 4;
  168. switch( Other.eType )
  169. {
  170. case DXBT_DISCRETE:
  171. while( i-- )
  172. {
  173. CDXB_T[i].Min = (TYPE)Other.u.D[i].Min;
  174. CDXB_T[i].Max = (TYPE)Other.u.D[i].Max;
  175. }
  176. break;
  177. case DXBT_DISCRETE64:
  178. while( i-- )
  179. {
  180. CDXB_T[i].Min = (TYPE)Other.u.LD[i].Min;
  181. CDXB_T[i].Max = (TYPE)Other.u.LD[i].Max;
  182. }
  183. break;
  184. case DXBT_CONTINUOUS:
  185. while( i-- )
  186. {
  187. CDXB_T[i].Min = (TYPE)Other.u.C[i].Min;
  188. CDXB_T[i].Max = (TYPE)Other.u.C[i].Max;
  189. }
  190. break;
  191. case DXBT_CONTINUOUS64:
  192. while( i-- )
  193. {
  194. CDXB_T[i].Min = (TYPE)Other.u.LC[i].Min;
  195. CDXB_T[i].Max = (TYPE)Other.u.LC[i].Max;
  196. }
  197. break;
  198. default:
  199. _ASSERT(0);
  200. }
  201. }
  202. } /* CDXBnds::Copy constructor */
  203. template<class TYPE, class USTYPE, class STTYPE, DXBNDTYPE eBndType>
  204. HRESULT CDXB_C::InitFromSafeArray( SAFEARRAY *pSA )
  205. {
  206. CHKTYPE();
  207. HRESULT hr = S_OK;
  208. TYPE *pData;
  209. if( !pSA || ( pSA->cDims != 1 ) ||
  210. ( pSA->cbElements != sizeof(TYPE) ) ||
  211. ( pSA->rgsabound->lLbound != 1 ) ||
  212. ( pSA->rgsabound->cElements != 8 )
  213. )
  214. {
  215. hr = E_INVALIDARG;
  216. }
  217. else
  218. {
  219. hr = SafeArrayAccessData(pSA, (void **)&pData);
  220. if( SUCCEEDED( hr ) )
  221. {
  222. for( int i = 0; i < 4; ++i )
  223. {
  224. CDXB_T[i].Min = pData[i];
  225. CDXB_T[i].Max = pData[i+4];
  226. }
  227. hr = SafeArrayUnaccessData( pSA );
  228. }
  229. }
  230. return hr;
  231. } /* CDXBnds::InitFromSafeArray */
  232. template<class TYPE, class USTYPE, class STTYPE, DXBNDTYPE eBndType>
  233. HRESULT CDXB_C::GetSafeArray( SAFEARRAY **ppSA ) const
  234. {
  235. CHKTYPE();
  236. HRESULT hr = S_OK;
  237. SAFEARRAY *pSA;
  238. if( !ppSA )
  239. {
  240. hr = E_POINTER;
  241. }
  242. else
  243. {
  244. SAFEARRAYBOUND rgsabound;
  245. rgsabound.lLbound = 1;
  246. rgsabound.cElements = 8;
  247. static VARTYPE VTypes[4] = { VT_I4, VT_I8, VT_R4, VT_R8 };
  248. pSA = SafeArrayCreate( VTypes[eBndType], 1, &rgsabound );
  249. if( pSA == NULL )
  250. {
  251. hr = E_OUTOFMEMORY;
  252. }
  253. else
  254. {
  255. TYPE *pData;
  256. hr = SafeArrayAccessData( pSA, (void **)&pData );
  257. if( SUCCEEDED( hr ) )
  258. {
  259. for( int i = 0; i < 4; ++i )
  260. {
  261. pData[i] = CDXB_T[i].Min;
  262. pData[i+4] = CDXB_T[i].Max;
  263. }
  264. hr = SafeArrayUnaccessData( pSA );
  265. }
  266. }
  267. if( SUCCEEDED( hr ) )
  268. {
  269. *ppSA = pSA;
  270. }
  271. }
  272. return hr;
  273. } /* CDXBnds::GetSafeArray */
  274. template<class TYPE, class USTYPE, class STTYPE, DXBNDTYPE eBndType>
  275. void CDXB_C::NormalizeBounds()
  276. {
  277. CHKTYPE();
  278. for( int i = 0; i < 4; ++i )
  279. {
  280. if( CDXB_T[i].Max < CDXB_T[i].Min )
  281. {
  282. TYPE Temp = CDXB_T[i].Min;
  283. CDXB_T[i].Min = CDXB_T[i].Max;
  284. CDXB_T[i].Max = Temp;
  285. }
  286. }
  287. } /* CDXBnds::NormalizeBounds */
  288. template<class TYPE, class USTYPE, class STTYPE, DXBNDTYPE eBndType>
  289. BOOL CDXB_C::IntersectBounds( const CDXB_C& Bounds1, const CDXB_C& Bounds2 )
  290. {
  291. CHKTYPE();
  292. BOOL bDoesIntersect = TRUE;
  293. for( int i = 0; i < 4; ++i )
  294. {
  295. CDXB_T[i].Min = max( CDXB_O( Bounds1 )[i].Min, CDXB_O( Bounds2 )[i].Min );
  296. CDXB_T[i].Max = min( CDXB_O( Bounds1 )[i].Max, CDXB_O( Bounds2 )[i].Max );
  297. if( CDXB_T[i].Max <= CDXB_T[i].Min )
  298. {
  299. //--- no intersection
  300. SetEmpty();
  301. bDoesIntersect = FALSE;
  302. }
  303. }
  304. return bDoesIntersect;
  305. } /* CDXBnds::IntersectBounds */
  306. template<class TYPE, class USTYPE, class STTYPE, DXBNDTYPE eBndType>
  307. BOOL CDXB_C::TestIntersect( const CDXB_C& Other ) const
  308. {
  309. CHKTYPE();
  310. BOOL bDoesIntersect = TRUE;
  311. TYPE BndMin, BndMax;
  312. for( int i = 0; i < 4; ++i )
  313. {
  314. BndMin = max( CDXB_T[i].Min, CDXB_O( Other )[i].Min );
  315. BndMax = min( CDXB_T[i].Max, CDXB_O( Other )[i].Max );
  316. if( BndMax <= BndMin ) bDoesIntersect = FALSE;
  317. }
  318. return bDoesIntersect;
  319. } /* CDXBnds::TestIntersect */
  320. template<class TYPE, class USTYPE, class STTYPE, DXBNDTYPE eBndType>
  321. void CDXB_C::UnionBounds( const CDXB_C& Bounds1, const CDXB_C& Bounds2 )
  322. {
  323. CHKTYPE();
  324. // This assumes the bounds are already normalized.
  325. for( int i = 0; i < 4; ++i )
  326. {
  327. CDXB_T[i].Min = min( CDXB_O( Bounds1 )[i].Min, CDXB_O( Bounds2 )[i].Min );
  328. CDXB_T[i].Max = max( CDXB_O( Bounds1 )[i].Max, CDXB_O( Bounds2 )[i].Max );
  329. }
  330. } /* CDXDBnds::UnionBounds */
  331. template<class TYPE, class USTYPE, class STTYPE, DXBNDTYPE eBndType>
  332. BOOL CDXB_C::IntersectBounds( const CDXB_C& OtherBounds )
  333. {
  334. CHKTYPE();
  335. return IntersectBounds( *this, OtherBounds );
  336. } /* CDXBnds::IntersectBounds */
  337. template<class TYPE, class USTYPE, class STTYPE, DXBNDTYPE eBndType>
  338. BOOL CDXB_C::BoundsAreEmpty() const
  339. {
  340. CHKTYPE();
  341. //--- Must exist in all dimensions
  342. for( int i = 0; i < 4; ++i )
  343. {
  344. if( CDXB_T[i].Max <= CDXB_T[i].Min ) return TRUE;
  345. }
  346. return FALSE;
  347. } /* CDXBnds::BoundsAreEmpty */
  348. template<class TYPE, class USTYPE, class STTYPE, DXBNDTYPE eBndType>
  349. BOOL CDXB_C::BoundsAreNull() const
  350. {
  351. CHKTYPE();
  352. DWORD *pTest = (DWORD *)CDXB_T;
  353. DWORD *pLimit = pTest + (sizeof(STTYPE) * 4 / sizeof(*pTest));
  354. do
  355. {
  356. if (*pTest) return FALSE;
  357. pTest++;
  358. } while (pTest < pLimit);
  359. return TRUE;
  360. } /* CDXDBnds::BoundsAreNull */
  361. // Additional Operations
  362. template<class TYPE, class USTYPE, class STTYPE, DXBNDTYPE eBndType>
  363. void CDXB_C::operator=( const CDXB_C& srcBounds )
  364. {
  365. CHKTYPE();
  366. memcpy(CDXB_T, CDXB_O(srcBounds), sizeof(STTYPE)*4);
  367. } /* CDXDBnds::operator= */
  368. template<class TYPE, class USTYPE, class STTYPE, DXBNDTYPE eBndType>
  369. void CDXB_C::operator=( const CDXV_C& v )
  370. {
  371. CHKTYPE();
  372. for( int i = 0; i < 4; ++i )
  373. {
  374. CDXB_T[i].Min = v[i];
  375. CDXB_T[i].Max = v[i] + 1;
  376. }
  377. } /* CDXDBnds::operator= */
  378. template<class TYPE, class USTYPE, class STTYPE, DXBNDTYPE eBndType>
  379. BOOL CDXB_C::operator==( const CDXB_C& Bounds ) const
  380. {
  381. CHKTYPE();
  382. for( ULONG i = 0; i < 4; ++i )
  383. {
  384. if( ( CDXB_T[i].Min != CDXB_O( Bounds )[i].Min ) ||
  385. ( CDXB_T[i].Max != CDXB_O( Bounds )[i].Max ) )
  386. {
  387. return false;
  388. }
  389. }
  390. return true;
  391. } /* CDXB_C::operator== */
  392. template<class TYPE, class USTYPE, class STTYPE, DXBNDTYPE eBndType>
  393. BOOL CDXB_C::operator!=( const CDXB_C& Bounds ) const
  394. {
  395. CHKTYPE();
  396. for( ULONG i = 0; i < 4; ++i )
  397. {
  398. if( ( CDXB_T[i].Min != CDXB_O( Bounds )[i].Min ) ||
  399. ( CDXB_T[i].Max != CDXB_O( Bounds )[i].Max ) )
  400. {
  401. return true;
  402. }
  403. }
  404. return false;
  405. } /* CDXBnds::operator!= */
  406. template<class TYPE, class USTYPE, class STTYPE, DXBNDTYPE eBndType>
  407. CDXB_C CDXB_C::operator&( const CDXB_C& Bounds2 ) const
  408. {
  409. CHKTYPE();
  410. CDXB_C Result;
  411. Result.IntersectBounds( *this, Bounds2 );
  412. return Result;
  413. } /* CDXBnds::operator& */
  414. template<class TYPE, class USTYPE, class STTYPE, DXBNDTYPE eBndType>
  415. CDXB_C CDXB_C::operator|( const CDXB_C& Bounds2 ) const
  416. {
  417. CHKTYPE();
  418. CDXB_C Result;
  419. Result.UnionBounds( *this, Bounds2 );
  420. return Result;
  421. } /* CDXBnds::operator| */
  422. template<class TYPE, class USTYPE, class STTYPE, DXBNDTYPE eBndType>
  423. void CDXB_C::GetMinVector( CDXV_C& v ) const
  424. {
  425. CHKTYPE();
  426. for( int i = 0; i < 4; ++i )
  427. {
  428. v[i] = CDXB_T[i].Min;
  429. }
  430. } /* CDXBnds::GetMinVector */
  431. template<class TYPE, class USTYPE, class STTYPE, DXBNDTYPE eBndType>
  432. void CDXB_C::GetMaxVector( CDXV_C& v ) const
  433. {
  434. CHKTYPE();
  435. for( int i = 0; i < 4; ++i )
  436. {
  437. v[i] = CDXB_T[i].Max;
  438. }
  439. } /* CDXBnds::GetMaxVector */
  440. template<class TYPE, class USTYPE, class STTYPE, DXBNDTYPE eBndType>
  441. void CDXB_C::GetSize( CDXB_C& SizeBounds ) const
  442. {
  443. CHKTYPE();
  444. SizeBounds.SetEmpty();
  445. SizeBounds[DXB_X].Max = CDXB_T[DXB_X].Max - CDXB_T[DXB_X].Min;
  446. SizeBounds[DXB_Y].Max = CDXB_T[DXB_Y].Max - CDXB_T[DXB_Y].Min;
  447. SizeBounds[DXB_Z].Max = CDXB_T[DXB_Z].Max - CDXB_T[DXB_Z].Min;
  448. SizeBounds[DXB_T].Max = CDXB_T[DXB_T].Max - CDXB_T[DXB_T].Min;
  449. } /* CDXBnds::GetSize */
  450. template<class TYPE, class USTYPE, class STTYPE, DXBNDTYPE eBndType>
  451. CDXB_C CDXB_C::Size( void ) const
  452. {
  453. CHKTYPE();
  454. CDXB_C Size;
  455. Size[DXB_X].Max = CDXB_T[DXB_X].Max - CDXB_T[DXB_X].Min;
  456. Size[DXB_Y].Max = CDXB_T[DXB_Y].Max - CDXB_T[DXB_Y].Min;
  457. Size[DXB_Z].Max = CDXB_T[DXB_Z].Max - CDXB_T[DXB_Z].Min;
  458. Size[DXB_T].Max = CDXB_T[DXB_T].Max - CDXB_T[DXB_T].Min;
  459. return Size;
  460. } /* CDXBnds::Size */
  461. // Operations
  462. template<class TYPE, class USTYPE, class STTYPE, DXBNDTYPE eBndType>
  463. void CDXB_C::SetBounds( TYPE xmin, TYPE xmax, TYPE ymin, TYPE ymax,
  464. TYPE zmin, TYPE zmax, TYPE tmin, TYPE tmax )
  465. {
  466. CHKTYPE();
  467. CDXB_T[DXB_X].Min = xmin;
  468. CDXB_T[DXB_X].Max = xmax;
  469. CDXB_T[DXB_Y].Min = ymin;
  470. CDXB_T[DXB_Y].Max = ymax;
  471. CDXB_T[DXB_Z].Min = zmin;
  472. CDXB_T[DXB_Z].Max = zmax;
  473. CDXB_T[DXB_T].Min = tmin;
  474. CDXB_T[DXB_T].Max = tmax;
  475. } /* CDXBnds::SetBounds */
  476. template<class TYPE, class USTYPE, class STTYPE, DXBNDTYPE eBndType>
  477. void CDXB_C::SetXYRect( const RECT& xyRect )
  478. {
  479. CHKTYPE();
  480. SetEmpty();
  481. CDXB_T[DXB_X].Min = (TYPE)xyRect.left;
  482. CDXB_T[DXB_X].Max = (TYPE)xyRect.right;
  483. CDXB_T[DXB_Y].Min = (TYPE)xyRect.top;
  484. CDXB_T[DXB_Y].Max = (TYPE)xyRect.bottom;
  485. CDXB_T[DXB_Z].Max = 1;
  486. CDXB_T[DXB_T].Max = (TYPE)LONG_MAX;
  487. } /* CDXBnds::SetXYRect */
  488. template<class TYPE, class USTYPE, class STTYPE, DXBNDTYPE eBndType>
  489. void CDXB_C::GetXYRect( RECT& xyRect ) const
  490. {
  491. CHKTYPE();
  492. xyRect.left = CDXB_T[DXB_X].Min;
  493. xyRect.right = CDXB_T[DXB_X].Max;
  494. xyRect.top = CDXB_T[DXB_Y].Min;
  495. xyRect.bottom = CDXB_T[DXB_Y].Max;
  496. } /* CDXBnds::GetXYRect */
  497. template<class TYPE, class USTYPE, class STTYPE, DXBNDTYPE eBndType>
  498. void CDXB_C::GetXYSize( SIZE& xySize ) const
  499. {
  500. CHKTYPE();
  501. xySize.cx = CDXB_T[DXB_X].Max - CDXB_T[DXB_X].Min;
  502. xySize.cy = CDXB_T[DXB_Y].Max - CDXB_T[DXB_Y].Min;
  503. } /* CDXBnds::GetXYSize */
  504. template<class TYPE, class USTYPE, class STTYPE, DXBNDTYPE eBndType>
  505. void CDXB_C::SetXYSize( const SIZE& xySize )
  506. {
  507. CHKTYPE();
  508. SetEmpty();
  509. CDXB_T[DXB_X].Max = (TYPE)xySize.cx;
  510. CDXB_T[DXB_Y].Max = (TYPE)xySize.cy;
  511. CDXB_T[DXB_Z].Max = (TYPE)1;
  512. CDXB_T[DXB_T].Max = (TYPE)LONG_MAX;
  513. } /* CDXBnds::SetXYSize */
  514. template<class TYPE, class USTYPE, class STTYPE, DXBNDTYPE eBndType>
  515. void CDXB_C::SetXYSize( TYPE width, TYPE height )
  516. {
  517. CHKTYPE();
  518. SetEmpty();
  519. CDXB_T[DXB_X].Max = (TYPE)width;
  520. CDXB_T[DXB_Y].Max = (TYPE)height;
  521. CDXB_T[DXB_Z].Max = (TYPE)1;
  522. CDXB_T[DXB_T].Max = (TYPE)LONG_MAX;
  523. } /* CDXBnds::SetXYSize */
  524. template<class TYPE, class USTYPE, class STTYPE, DXBNDTYPE eBndType>
  525. void CDXB_C::SetXYPoint( const POINT& xyPoint )
  526. {
  527. CHKTYPE();
  528. SetEmpty();
  529. CDXB_T[DXB_X].Min = (TYPE)xyPoint.x;
  530. CDXB_T[DXB_X].Max = (TYPE)xyPoint.x + 1;
  531. CDXB_T[DXB_Y].Min = (TYPE)xyPoint.y;
  532. CDXB_T[DXB_Y].Max = (TYPE)xyPoint.y + 1;
  533. CDXB_T[DXB_Z].Max = (TYPE)1;
  534. CDXB_T[DXB_T].Max = (TYPE)LONG_MAX;
  535. } /* CDXDBnds::SetRect */
  536. template<class TYPE, class USTYPE, class STTYPE, DXBNDTYPE eBndType>
  537. void CDXB_C::Offset( TYPE x, TYPE y, TYPE z, TYPE t )
  538. {
  539. CHKTYPE();
  540. CDXB_T[DXB_X].Min += x;
  541. CDXB_T[DXB_X].Max += x;
  542. CDXB_T[DXB_Y].Min += y;
  543. CDXB_T[DXB_Y].Max += y;
  544. CDXB_T[DXB_Z].Min += z;
  545. CDXB_T[DXB_Z].Max += z;
  546. CDXB_T[DXB_T].Min += t;
  547. CDXB_T[DXB_T].Max += t;
  548. } /* CDXBnds::Offset */
  549. template<class TYPE, class USTYPE, class STTYPE, DXBNDTYPE eBndType>
  550. void CDXB_C::SetToSize(void)
  551. {
  552. CHKTYPE();
  553. for( int i = 0; i < 4; ++i )
  554. {
  555. CDXB_T[i].Max -= CDXB_T[i].Min;
  556. CDXB_T[i].Min = 0;
  557. }
  558. }
  559. template<class TYPE, class USTYPE, class STTYPE, DXBNDTYPE eBndType>
  560. void CDXB_C::SetPlacement(const CDXV_C & v)
  561. {
  562. CHKTYPE();
  563. for( int i = 0; i < 4; ++i )
  564. {
  565. CDXB_T[i].Max += (CDXV_O( v )[i] - CDXB_T[i].Min);
  566. CDXB_T[i].Min = CDXV_O( v )[i];
  567. }
  568. } /* CDXBnds::Offset */
  569. template<class TYPE, class USTYPE, class STTYPE, DXBNDTYPE eBndType>
  570. void CDXB_C::Offset( const CDXV_C& v )
  571. {
  572. CHKTYPE();
  573. for( int i = 0; i < 4; ++i )
  574. {
  575. CDXB_T[i].Min += v[i];
  576. CDXB_T[i].Max += v[i];
  577. }
  578. } /* CDXBnds::Offset */
  579. template<class TYPE, class USTYPE, class STTYPE, DXBNDTYPE eBndType>
  580. void CDXB_C::operator+=(const POINT &point)
  581. {
  582. CHKTYPE();
  583. CDXB_T[DXB_X].Min += (TYPE)point.x;
  584. CDXB_T[DXB_X].Max += (TYPE)point.x;
  585. CDXB_T[DXB_Y].Min += (TYPE)point.y;
  586. CDXB_T[DXB_Y].Max += (TYPE)point.y;
  587. } /* CDXBnds::operator+= */
  588. template<class TYPE, class USTYPE, class STTYPE, DXBNDTYPE eBndType>
  589. void CDXB_C::operator-=(const POINT &point)
  590. {
  591. CHKTYPE();
  592. CDXB_T[DXB_X].Min -= (TYPE)point.x;
  593. CDXB_T[DXB_X].Max -= (TYPE)point.x;
  594. CDXB_T[DXB_Y].Min -= (TYPE)point.y;
  595. CDXB_T[DXB_Y].Max -= (TYPE)point.y;
  596. } /* CDXBnds::operator-= */
  597. template<class TYPE, class USTYPE, class STTYPE, DXBNDTYPE eBndType>
  598. void CDXB_C::operator+=(const SIZE &size)
  599. {
  600. CHKTYPE();
  601. CDXB_T[DXB_X].Min += (TYPE)size.cx;
  602. CDXB_T[DXB_X].Max += (TYPE)size.cx;
  603. CDXB_T[DXB_Y].Min += (TYPE)size.cy;
  604. CDXB_T[DXB_Y].Max += (TYPE)size.cy;
  605. } /* CDXBnds::operator+= */
  606. template<class TYPE, class USTYPE, class STTYPE, DXBNDTYPE eBndType>
  607. void CDXB_C::operator-=(const SIZE &size)
  608. {
  609. CHKTYPE();
  610. CDXB_T[DXB_X].Min -= (TYPE)size.cx;
  611. CDXB_T[DXB_X].Max -= (TYPE)size.cx;
  612. CDXB_T[DXB_Y].Min -= (TYPE)size.cy;
  613. CDXB_T[DXB_Y].Max -= (TYPE)size.cy;
  614. } /* CDXBnds::operator-= */
  615. template<class TYPE, class USTYPE, class STTYPE, DXBNDTYPE eBndType>
  616. void CDXB_C::operator+=(const CDXV_C& v)
  617. {
  618. CHKTYPE();
  619. CDXB_T[DXB_X].Min += CDXV_O( v )[DXB_X];
  620. CDXB_T[DXB_X].Max += CDXV_O( v )[DXB_X];
  621. CDXB_T[DXB_Y].Min += CDXV_O( v )[DXB_Y];
  622. CDXB_T[DXB_Y].Max += CDXV_O( v )[DXB_Y];
  623. CDXB_T[DXB_Z].Min += CDXV_O( v )[DXB_Z];
  624. CDXB_T[DXB_Z].Max += CDXV_O( v )[DXB_Z];
  625. CDXB_T[DXB_T].Min += CDXV_O( v )[DXB_T];
  626. CDXB_T[DXB_T].Max += CDXV_O( v )[DXB_T];
  627. } /* CDXBnds::operator+= */
  628. template<class TYPE, class USTYPE, class STTYPE, DXBNDTYPE eBndType>
  629. void CDXB_C::operator-=(const CDXV_C& v)
  630. {
  631. CHKTYPE();
  632. CDXB_T[DXB_X].Min -= CDXV_O( v )[DXB_X];
  633. CDXB_T[DXB_X].Max -= CDXV_O( v )[DXB_X];
  634. CDXB_T[DXB_Y].Min -= CDXV_O( v )[DXB_Y];
  635. CDXB_T[DXB_Y].Max -= CDXV_O( v )[DXB_Y];
  636. CDXB_T[DXB_Z].Min -= CDXV_O( v )[DXB_Z];
  637. CDXB_T[DXB_Z].Max -= CDXV_O( v )[DXB_Z];
  638. CDXB_T[DXB_T].Min -= CDXV_O( v )[DXB_T];
  639. CDXB_T[DXB_T].Max -= CDXV_O( v )[DXB_T];
  640. } /* CDXBnds::operator-= */
  641. template<class TYPE, class USTYPE, class STTYPE, DXBNDTYPE eBndType>
  642. void CDXB_C::operator+=( const CDXB_C& Bounds )
  643. {
  644. CHKTYPE();
  645. CDXB_T[DXB_X].Min += CDXB_O( Bounds )[DXB_X].Min;
  646. CDXB_T[DXB_X].Max += CDXB_O( Bounds )[DXB_X].Max;
  647. CDXB_T[DXB_Y].Min += CDXB_O( Bounds )[DXB_Y].Min;
  648. CDXB_T[DXB_Y].Max += CDXB_O( Bounds )[DXB_Y].Max;
  649. CDXB_T[DXB_Z].Min += CDXB_O( Bounds )[DXB_Z].Min;
  650. CDXB_T[DXB_Z].Max += CDXB_O( Bounds )[DXB_Z].Max;
  651. CDXB_T[DXB_T].Min += CDXB_O( Bounds )[DXB_T].Min;
  652. CDXB_T[DXB_T].Max += CDXB_O( Bounds )[DXB_T].Max;
  653. } /* CDXBnds::operator+= */
  654. template<class TYPE, class USTYPE, class STTYPE, DXBNDTYPE eBndType>
  655. void CDXB_C::operator-=( const CDXB_C& Bounds )
  656. {
  657. CHKTYPE();
  658. CDXB_T[DXB_X].Min -= CDXB_O( Bounds )[DXB_X].Min;
  659. CDXB_T[DXB_X].Max -= CDXB_O( Bounds )[DXB_X].Max;
  660. CDXB_T[DXB_Y].Min -= CDXB_O( Bounds )[DXB_Y].Min;
  661. CDXB_T[DXB_Y].Max -= CDXB_O( Bounds )[DXB_Y].Max;
  662. CDXB_T[DXB_Z].Min -= CDXB_O( Bounds )[DXB_Z].Min;
  663. CDXB_T[DXB_Z].Max -= CDXB_O( Bounds )[DXB_Z].Max;
  664. CDXB_T[DXB_T].Min -= CDXB_O( Bounds )[DXB_T].Min;
  665. CDXB_T[DXB_T].Max -= CDXB_O( Bounds )[DXB_T].Max;
  666. } /* CDXB_C::operator-= */
  667. template<class TYPE, class USTYPE, class STTYPE, DXBNDTYPE eBndType>
  668. void CDXB_C::operator&=( const CDXB_C& Bounds )
  669. {
  670. CHKTYPE();
  671. for( int i = 0; i < 4; ++i )
  672. {
  673. CDXB_T[i].Min = max( CDXB_T[i].Min, CDXB_O( Bounds )[i].Min );
  674. CDXB_T[i].Max = min( CDXB_T[i].Max, CDXB_O( Bounds )[i].Max );
  675. }
  676. } /* CDXB_C::operator&= */
  677. template<class TYPE, class USTYPE, class STTYPE, DXBNDTYPE eBndType>
  678. void CDXB_C::operator|=( const CDXB_C& Bounds )
  679. {
  680. CHKTYPE();
  681. for( long i = 0; i < 4; ++i )
  682. {
  683. CDXB_T[i].Min = min( CDXB_T[i].Min, CDXB_O( Bounds )[i].Min );
  684. CDXB_T[i].Max = max( CDXB_T[i].Max, CDXB_O( Bounds )[i].Max );
  685. }
  686. } /* CDXB_C::operator|= */
  687. // operators returning CDXDBnds values
  688. template<class TYPE, class USTYPE, class STTYPE, DXBNDTYPE eBndType>
  689. CDXB_C CDXB_C::operator+(const POINT &point) const
  690. {
  691. CHKTYPE();
  692. CDXB_C Result( *this );
  693. CDXB_O( Result )[DXB_X].Min += point.x;
  694. CDXB_O( Result )[DXB_X].Max += point.x;
  695. CDXB_O( Result )[DXB_Y].Min += point.y;
  696. CDXB_O( Result )[DXB_Y].Max += point.y;
  697. return Result;
  698. } /* CDXBnds::operator+ */
  699. template<class TYPE, class USTYPE, class STTYPE, DXBNDTYPE eBndType>
  700. CDXB_C CDXB_C::operator-(const POINT &point) const
  701. {
  702. CHKTYPE();
  703. CDXB_C Result( *this );
  704. CDXB_O( Result )[DXB_X].Min -= point.x;
  705. CDXB_O( Result )[DXB_X].Max -= point.x;
  706. CDXB_O( Result )[DXB_Y].Min -= point.y;
  707. CDXB_O( Result )[DXB_Y].Max -= point.y;
  708. return Result;
  709. } /* CDXBnds::operator- */
  710. template<class TYPE, class USTYPE, class STTYPE, DXBNDTYPE eBndType>
  711. CDXB_C CDXB_C::operator+(const SIZE &size) const
  712. {
  713. CHKTYPE();
  714. CDXB_C Result( *this );
  715. CDXB_O( Result )[DXB_X].Min += size.cx;
  716. CDXB_O( Result )[DXB_X].Max += size.cx;
  717. CDXB_O( Result )[DXB_Y].Min += size.cy;
  718. CDXB_O( Result )[DXB_Y].Max += size.cy;
  719. return Result;
  720. } /* CDXBnds::operator+ */
  721. template<class TYPE, class USTYPE, class STTYPE, DXBNDTYPE eBndType>
  722. CDXB_C CDXB_C::operator-( const SIZE &size ) const
  723. {
  724. CHKTYPE();
  725. CDXB_C Result( *this );
  726. CDXB_O( Result )[DXB_X].Min -= size.cx;
  727. CDXB_O( Result )[DXB_X].Max -= size.cx;
  728. CDXB_O( Result )[DXB_Y].Min -= size.cy;
  729. CDXB_O( Result )[DXB_Y].Max -= size.cy;
  730. return Result;
  731. } /* CDXB_C::operator- */
  732. template<class TYPE, class USTYPE, class STTYPE, DXBNDTYPE eBndType>
  733. CDXB_C CDXB_C::operator+(const CDXV_C& v) const
  734. {
  735. CHKTYPE();
  736. CDXB_C Result( *this );
  737. CDXB_O( Result )[DXB_X].Min += CDXV_O( v )[DXB_X];
  738. CDXB_O( Result )[DXB_X].Max += CDXV_O( v )[DXB_X];
  739. CDXB_O( Result )[DXB_Y].Min += CDXV_O( v )[DXB_Y];
  740. CDXB_O( Result )[DXB_Y].Max += CDXV_O( v )[DXB_Y];
  741. CDXB_O( Result )[DXB_Z].Min += CDXV_O( v )[DXB_Z];
  742. CDXB_O( Result )[DXB_Z].Max += CDXV_O( v )[DXB_Z];
  743. CDXB_O( Result )[DXB_T].Min += CDXV_O( v )[DXB_T];
  744. CDXB_O( Result )[DXB_T].Max += CDXV_O( v )[DXB_T];
  745. return Result;
  746. } /* CDXBnds::operator+ */
  747. template<class TYPE, class USTYPE, class STTYPE, DXBNDTYPE eBndType>
  748. CDXB_C CDXB_C::operator-(const CDXV_C& v) const
  749. {
  750. CHKTYPE();
  751. CDXB_C Result( *this );
  752. CDXB_O( Result )[DXB_X].Min -= CDXV_O( v )[DXB_X];
  753. CDXB_O( Result )[DXB_X].Max -= CDXV_O( v )[DXB_X];
  754. CDXB_O( Result )[DXB_Y].Min -= CDXV_O( v )[DXB_Y];
  755. CDXB_O( Result )[DXB_Y].Max -= CDXV_O( v )[DXB_Y];
  756. CDXB_O( Result )[DXB_Z].Min -= CDXV_O( v )[DXB_Z];
  757. CDXB_O( Result )[DXB_Z].Max -= CDXV_O( v )[DXB_Z];
  758. CDXB_O( Result )[DXB_T].Min -= CDXV_O( v )[DXB_T];
  759. CDXB_O( Result )[DXB_T].Max -= CDXV_O( v )[DXB_T];
  760. return Result;
  761. } /* CDXBnds::operator- */
  762. template<class TYPE, class USTYPE, class STTYPE, DXBNDTYPE eBndType>
  763. HRESULT CDXB_C::SetToSurfaceBounds(IDXSurface * pDXSurface)
  764. {
  765. #if (eBndType != DXBT_DISCRETE)
  766. #error SetToSurfacBounds requires a continuous bounds.
  767. #endif
  768. CHKTYPE();
  769. return pDXSurface->GetBounds( this );
  770. }
  771. template<class TYPE, class USTYPE, class STTYPE, DXBNDTYPE eBndType>
  772. HRESULT CDXB_C::SetToMeshBounds(IDirect3DRMMeshBuilder3 * pMesh)
  773. {
  774. #if (eBndType != DXBT_CONTINUOUS)
  775. #error SetToMeshBounds requires a continuous bounds.
  776. #endif
  777. CHKTYPE();
  778. D3DRMBOX Box;
  779. HRESULT hr = pMesh->GetBox(&Box);
  780. u.C[DXB_X].Min = Box.min.x;
  781. u.C[DXB_X].Max = Box.max.x;
  782. u.C[DXB_Y].Min = Box.min.y;
  783. u.C[DXB_Y].Max = Box.max.y;
  784. u.C[DXB_Z].Min = Box.min.z;
  785. u.C[DXB_Z].Max = Box.max.z;
  786. u.C[DXB_T].Min = 0;
  787. u.C[DXB_T].Max = 1.;
  788. return hr;
  789. }
  790. template<class TYPE, class USTYPE, class STTYPE, DXBNDTYPE eBndType>
  791. void CDXB_C::Scale(const CDXV_C& v)
  792. {
  793. CHKTYPE();
  794. for(long i = 0; i < 4; ++i )
  795. {
  796. TYPE mid = (CDXB_T[i].Min + CDXB_T[i].Max) / 2;
  797. TYPE scale = CDXV_O(v)[i] * (CDXB_T[i].Max - mid);
  798. CDXB_T[i].Min = mid - scale;
  799. CDXB_T[i].Max = mid + scale;
  800. }
  801. }
  802. template<class TYPE, class USTYPE, class STTYPE, DXBNDTYPE eBndType>
  803. void CDXB_C::Scale(TYPE x, TYPE y, TYPE z, TYPE t)
  804. {
  805. Scale(CDXV_C(x, y, z, t));
  806. }
  807. template<class TYPE, class USTYPE, class STTYPE, DXBNDTYPE eBndType>
  808. void CDXB_C::Expand(const CDXV_C& v)
  809. {
  810. CHKTYPE();
  811. for(long i = 0; i < 4; ++i )
  812. {
  813. TYPE scale = CDXV_O(v)[i] / 2;
  814. CDXB_T[i].Min -= scale;
  815. CDXB_T[i].Max += scale;
  816. }
  817. }
  818. template<class TYPE, class USTYPE, class STTYPE, DXBNDTYPE eBndType>
  819. void CDXB_C::Expand(TYPE x, TYPE y, TYPE z, TYPE t)
  820. {
  821. Expand(CDXV_C(x, y, z, t));
  822. }
  823. //---
  824. typedef CDXBnds<long, unsigned long, DXDBND, DXBT_DISCRETE> CDXDBnds;
  825. typedef CDXBnds<LONGLONG, ULONGLONG, DXDBND64, DXBT_DISCRETE64> CDXDBnds64;
  826. typedef CDXBnds<float, float, DXCBND, DXBT_CONTINUOUS> CDXCBnds;
  827. typedef CDXBnds<double, double, DXCBND64, DXBT_CONTINUOUS64> CDXCBnds64;
  828. //=== Macro Definitions ============================================
  829. //=== Global Data Declarations =====================================
  830. //=== Function Prototypes ==========================================
  831. #endif /* This must be the last line in the file */