Counter Strike : Global Offensive Source Code
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.

1559 lines
54 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $Workfile: $
  6. // $Date: $
  7. // $NoKeywords: $
  8. //=============================================================================//
  9. #ifndef BUILDDISP_H
  10. #define BUILDDISP_H
  11. #ifdef _WIN32
  12. #pragma once
  13. #endif
  14. #include "commonmacros.h"
  15. #include "tier0/dbg.h"
  16. #include "bspfile.h"
  17. #include "mathlib/mathlib.h"
  18. #include "mathlib/bumpvects.h"
  19. #include "mathlib/vector4d.h"
  20. #include "disp_common.h"
  21. #include "bitvec.h"
  22. #define DISP_ALPHA_PROP_DELTA 382.5f
  23. class CCoreDispInfo;
  24. struct CoreDispBBox_t
  25. {
  26. Vector vMin, vMax;
  27. };
  28. //=========================================================================
  29. //
  30. // Surface Class - interfacing class (fill in with MapFace, dface_t, and
  31. // msurface_t)
  32. //
  33. class CCoreDispSurface
  34. {
  35. public:
  36. enum { QUAD_POINT_COUNT = 4 };
  37. enum { MAX_CORNER_NEIGHBOR_COUNT = 16 };
  38. CCoreDispSurface();
  39. //=========================================================================
  40. //
  41. // initialization
  42. //
  43. void Init( void );
  44. //=========================================================================
  45. //
  46. // parent surface id - index to CMapFace, dface_t, or msurface_t
  47. //
  48. inline void SetHandle( int handle );
  49. inline int GetHandle( void );
  50. //=========================================================================
  51. //
  52. // vertex data - pos, normal, texture, lightmap, alpha, etc...
  53. //
  54. inline void SetPointCount( int count );
  55. inline int GetPointCount( void ) const;
  56. inline void SetPoint( int index, Vector const &pt );
  57. inline void GetPoint( int index, Vector& pt ) const;
  58. inline Vector const& GetPoint( int index ) const;
  59. inline void SetPointNormal( int index, Vector const &normal );
  60. inline void GetPointNormal( int index, Vector &normal );
  61. inline void SetTexCoord( int index, Vector2D const& texCoord );
  62. inline void GetTexCoord( int index, Vector2D& texCoord ) const;
  63. inline void SetLuxelCoord( int bumpIndex, int index, Vector2D const& luxelCoord );
  64. inline void GetLuxelCoord( int bumpIndex, int index, Vector2D& luxelCoord ) const;
  65. inline void SetLuxelCoords( int bumpIndex, Vector2D const coords[4] );
  66. inline void GetLuxelCoords( int bumpIndex, Vector2D coords[4] ) const;
  67. inline void SetLuxelU( int nU ) { m_nLuxelU = nU; }
  68. inline int GetLuxelU( void ) { return m_nLuxelU; }
  69. inline void SetLuxelV( int nV ) { m_nLuxelV = nV; }
  70. inline int GetLuxelV( void ) { return m_nLuxelV; }
  71. bool CalcLuxelCoords( int nLuxels, bool bAdjust, const Vector &vecU, const Vector &vecV );
  72. inline void SetAlpha( int index, float alpha );
  73. inline float GetAlpha( int const index ) const;
  74. //=========================================================================
  75. //
  76. // utils
  77. //
  78. inline void GetNormal( Vector& normal );
  79. inline void SetFlags( int flag );
  80. inline int GetFlags( void );
  81. inline void SetContents( int contents );
  82. inline int GetContents( void );
  83. //=========================================================================
  84. //
  85. // create utils (texture axis not use anymore but here to support older maps)
  86. //
  87. inline void SetSAxis( Vector const &axis );
  88. inline void GetSAxis( Vector &axis );
  89. inline void SetTAxis( Vector const &axis );
  90. inline void GetTAxis( Vector &axis );
  91. inline void SetPointStartIndex( int index );
  92. inline int GetPointStartIndex( void );
  93. inline void SetPointStart( Vector const &pt );
  94. inline void GetPointStart( Vector &pt );
  95. // Used by the tools to set the neighbor data from the BSP file.
  96. void SetNeighborData( const CDispNeighbor edgeNeighbors[4], const CDispCornerNeighbors cornerNeighbors[4] );
  97. void GeneratePointStartIndexFromMappingAxes( Vector const &sAxis, Vector const &tAxis );
  98. int GenerateSurfPointStartIndex( void );
  99. int FindSurfPointStartIndex( void );
  100. void AdjustSurfPointData( void );
  101. // Indexed by CORNER_ defines.
  102. CDispCornerNeighbors* GetCornerNeighbors( int iCorner ) { Assert( iCorner >= 0 && iCorner < ARRAYSIZE( m_CornerNeighbors ) ); return &m_CornerNeighbors[iCorner]; }
  103. const CDispCornerNeighbors* GetCornerNeighbors( int iCorner ) const { Assert( iCorner >= 0 && iCorner < ARRAYSIZE( m_CornerNeighbors ) ); return &m_CornerNeighbors[iCorner]; }
  104. // Indexed by CORNER_ defines.
  105. int GetCornerNeighborCount( int iCorner ) const { return GetCornerNeighbors( iCorner )->m_nNeighbors; }
  106. int GetCornerNeighbor( int iCorner, int iNeighbor ) const { Assert( iNeighbor >= 0 && iNeighbor < GetCornerNeighbors(iCorner)->m_nNeighbors ); return GetCornerNeighbors( iCorner )->m_Neighbors[iNeighbor]; }
  107. CDispNeighbor* GetEdgeNeighbor( int iEdge ) { Assert( iEdge >= 0 && iEdge < ARRAYSIZE( m_EdgeNeighbors ) ); return &m_EdgeNeighbors[iEdge]; }
  108. const CDispNeighbor* GetEdgeNeighbor( int iEdge ) const { Assert( iEdge >= 0 && iEdge < ARRAYSIZE( m_EdgeNeighbors ) ); return &m_EdgeNeighbors[iEdge]; }
  109. protected:
  110. // Utility
  111. bool LongestInU( const Vector &vecU, const Vector &vecV );
  112. int m_Index; // parent face (CMapFace, dface_t, msurface_t) index "handle"
  113. int m_PointCount; // number of points in the face (should be 4!)
  114. Vector m_Points[QUAD_POINT_COUNT]; // points
  115. Vector m_Normals[QUAD_POINT_COUNT]; // normals at points
  116. Vector2D m_TexCoords[QUAD_POINT_COUNT]; // texture coordinates at points
  117. Vector2D m_LuxelCoords[NUM_BUMP_VECTS+1][QUAD_POINT_COUNT]; // lightmap coordinates at points
  118. float m_Alphas[QUAD_POINT_COUNT]; // alpha at points
  119. Vector4D m_MultiBlends[ QUAD_POINT_COUNT ];
  120. Vector4D m_AlphaBlends[ QUAD_POINT_COUNT ];
  121. Vector m_vBlendColors[ QUAD_POINT_COUNT ][ MAX_MULTIBLEND_CHANNELS ];
  122. // Luxels sizes
  123. int m_nLuxelU;
  124. int m_nLuxelV;
  125. // Straight from the BSP file.
  126. CDispNeighbor m_EdgeNeighbors[4];
  127. CDispCornerNeighbors m_CornerNeighbors[4];
  128. int m_Flags; // surface flags - inherited from the "parent" face
  129. int m_Contents; // contents flags - inherited from the "parent" face
  130. Vector sAxis; // used to generate start disp orientation (old method)
  131. Vector tAxis; // used to generate start disp orientation (old method)
  132. int m_PointStartIndex; // index to the starting point -- for saving starting point
  133. Vector m_PointStart; // starting point used to determine the orientation of the displacement map on the surface
  134. };
  135. //-----------------------------------------------------------------------------
  136. //-----------------------------------------------------------------------------
  137. inline void CCoreDispSurface::SetHandle( int handle )
  138. {
  139. m_Index = handle;
  140. }
  141. //-----------------------------------------------------------------------------
  142. //-----------------------------------------------------------------------------
  143. inline int CCoreDispSurface::GetHandle( void )
  144. {
  145. return m_Index;
  146. }
  147. //-----------------------------------------------------------------------------
  148. //-----------------------------------------------------------------------------
  149. inline void CCoreDispSurface::SetPointCount( int count )
  150. {
  151. // quad only -- currently!
  152. if( count != 4 )
  153. return;
  154. m_PointCount = count;
  155. }
  156. //-----------------------------------------------------------------------------
  157. //-----------------------------------------------------------------------------
  158. inline int CCoreDispSurface::GetPointCount( void ) const
  159. {
  160. return m_PointCount;
  161. }
  162. //-----------------------------------------------------------------------------
  163. //-----------------------------------------------------------------------------
  164. inline void CCoreDispSurface::SetPoint( int index, Vector const &pt )
  165. {
  166. Assert( index >= 0 );
  167. Assert( index < QUAD_POINT_COUNT );
  168. VectorCopy( pt, m_Points[index] );
  169. }
  170. //-----------------------------------------------------------------------------
  171. //-----------------------------------------------------------------------------
  172. inline void CCoreDispSurface::GetPoint( int index, Vector &pt ) const
  173. {
  174. Assert( index >= 0 );
  175. Assert( index < QUAD_POINT_COUNT );
  176. VectorCopy( m_Points[index], pt );
  177. }
  178. //-----------------------------------------------------------------------------
  179. //-----------------------------------------------------------------------------
  180. inline Vector const& CCoreDispSurface::GetPoint( int index ) const
  181. {
  182. Assert( index >= 0 );
  183. Assert( index < QUAD_POINT_COUNT );
  184. return m_Points[index];
  185. }
  186. //-----------------------------------------------------------------------------
  187. //-----------------------------------------------------------------------------
  188. inline void CCoreDispSurface::SetPointNormal( int index, Vector const &normal )
  189. {
  190. Assert( index >= 0 );
  191. Assert( index < QUAD_POINT_COUNT );
  192. VectorCopy( normal, m_Normals[index] );
  193. }
  194. //-----------------------------------------------------------------------------
  195. //-----------------------------------------------------------------------------
  196. inline void CCoreDispSurface::GetPointNormal( int index, Vector& normal )
  197. {
  198. Assert( index >= 0 );
  199. Assert( index < QUAD_POINT_COUNT );
  200. VectorCopy( m_Normals[index], normal );
  201. }
  202. //-----------------------------------------------------------------------------
  203. //-----------------------------------------------------------------------------
  204. inline void CCoreDispSurface::SetTexCoord( int index, Vector2D const& texCoord )
  205. {
  206. Assert( index >= 0 );
  207. Assert( index < QUAD_POINT_COUNT );
  208. Vector2DCopy( texCoord, m_TexCoords[index] );
  209. }
  210. //-----------------------------------------------------------------------------
  211. //-----------------------------------------------------------------------------
  212. inline void CCoreDispSurface::GetTexCoord( int index, Vector2D& texCoord ) const
  213. {
  214. Assert( index >= 0 );
  215. Assert( index < QUAD_POINT_COUNT );
  216. Vector2DCopy( m_TexCoords[index], texCoord );
  217. }
  218. //-----------------------------------------------------------------------------
  219. //-----------------------------------------------------------------------------
  220. inline void CCoreDispSurface::SetLuxelCoord( int bumpIndex, int index, Vector2D const& luxelCoord )
  221. {
  222. Assert( index >= 0 );
  223. Assert( index < QUAD_POINT_COUNT );
  224. Assert( bumpIndex >= 0 );
  225. Assert( bumpIndex < NUM_BUMP_VECTS + 1 );
  226. Vector2DCopy( luxelCoord, m_LuxelCoords[bumpIndex][index] );
  227. }
  228. //-----------------------------------------------------------------------------
  229. //-----------------------------------------------------------------------------
  230. inline void CCoreDispSurface::GetLuxelCoord( int bumpIndex, int index, Vector2D& luxelCoord ) const
  231. {
  232. Assert( index >= 0 );
  233. Assert( index < QUAD_POINT_COUNT );
  234. Assert( bumpIndex >= 0 );
  235. Assert( bumpIndex < NUM_BUMP_VECTS + 1 );
  236. Vector2DCopy( m_LuxelCoords[bumpIndex][index], luxelCoord );
  237. }
  238. //-----------------------------------------------------------------------------
  239. //-----------------------------------------------------------------------------
  240. inline void CCoreDispSurface::SetLuxelCoords( int bumpIndex, Vector2D const luxelCoords[4] )
  241. {
  242. Assert( bumpIndex >= 0 );
  243. Assert( bumpIndex < NUM_BUMP_VECTS + 1 );
  244. for( int i=0; i < 4; i++ )
  245. Vector2DCopy( luxelCoords[i], m_LuxelCoords[bumpIndex][i] );
  246. }
  247. //-----------------------------------------------------------------------------
  248. //-----------------------------------------------------------------------------
  249. inline void CCoreDispSurface::GetLuxelCoords( int bumpIndex, Vector2D luxelCoords[4] ) const
  250. {
  251. Assert( bumpIndex >= 0 );
  252. Assert( bumpIndex < NUM_BUMP_VECTS + 1 );
  253. for( int i=0; i < 4; i++ )
  254. Vector2DCopy( m_LuxelCoords[bumpIndex][i], luxelCoords[i] );
  255. }
  256. //-----------------------------------------------------------------------------
  257. //-----------------------------------------------------------------------------
  258. inline void CCoreDispSurface::SetAlpha( int index, float alpha )
  259. {
  260. Assert( index >= 0 );
  261. Assert( index < QUAD_POINT_COUNT );
  262. m_Alphas[index] = alpha;
  263. }
  264. //-----------------------------------------------------------------------------
  265. //-----------------------------------------------------------------------------
  266. inline float CCoreDispSurface::GetAlpha( int const index ) const
  267. {
  268. Assert( index >= 0 );
  269. Assert( index < QUAD_POINT_COUNT );
  270. return m_Alphas[index];
  271. }
  272. //-----------------------------------------------------------------------------
  273. //-----------------------------------------------------------------------------
  274. inline void CCoreDispSurface::SetFlags( int flag )
  275. {
  276. m_Flags = flag;
  277. }
  278. //-----------------------------------------------------------------------------
  279. //-----------------------------------------------------------------------------
  280. inline int CCoreDispSurface::GetFlags( void )
  281. {
  282. return m_Flags;
  283. }
  284. //-----------------------------------------------------------------------------
  285. //-----------------------------------------------------------------------------
  286. inline void CCoreDispSurface::SetContents( int contents )
  287. {
  288. m_Contents = contents;
  289. }
  290. //-----------------------------------------------------------------------------
  291. //-----------------------------------------------------------------------------
  292. inline int CCoreDispSurface::GetContents( void )
  293. {
  294. return m_Contents;
  295. }
  296. //-----------------------------------------------------------------------------
  297. //-----------------------------------------------------------------------------
  298. inline void CCoreDispSurface::SetSAxis( Vector const &axis )
  299. {
  300. VectorCopy( axis, sAxis );
  301. }
  302. //-----------------------------------------------------------------------------
  303. //-----------------------------------------------------------------------------
  304. inline void CCoreDispSurface::GetSAxis( Vector& axis )
  305. {
  306. VectorCopy( sAxis, axis );
  307. }
  308. //-----------------------------------------------------------------------------
  309. //-----------------------------------------------------------------------------
  310. inline void CCoreDispSurface::SetTAxis( Vector const &axis )
  311. {
  312. VectorCopy( axis, tAxis );
  313. }
  314. //-----------------------------------------------------------------------------
  315. //-----------------------------------------------------------------------------
  316. inline void CCoreDispSurface::GetTAxis( Vector& axis )
  317. {
  318. VectorCopy( tAxis, axis );
  319. }
  320. //-----------------------------------------------------------------------------
  321. //-----------------------------------------------------------------------------
  322. inline void CCoreDispSurface::SetPointStartIndex( int index )
  323. {
  324. Assert( index >= 0 );
  325. Assert( index < QUAD_POINT_COUNT );
  326. m_PointStartIndex = index;
  327. }
  328. //-----------------------------------------------------------------------------
  329. //-----------------------------------------------------------------------------
  330. inline int CCoreDispSurface::GetPointStartIndex( void )
  331. {
  332. return m_PointStartIndex;
  333. }
  334. //-----------------------------------------------------------------------------
  335. //-----------------------------------------------------------------------------
  336. inline void CCoreDispSurface::SetPointStart( Vector const& pt )
  337. {
  338. VectorCopy( pt, m_PointStart );
  339. }
  340. //-----------------------------------------------------------------------------
  341. //-----------------------------------------------------------------------------
  342. inline void CCoreDispSurface::GetPointStart( Vector& pt )
  343. {
  344. VectorCopy( m_PointStart, pt );
  345. }
  346. //-----------------------------------------------------------------------------
  347. //-----------------------------------------------------------------------------
  348. inline void CCoreDispSurface::GetNormal( Vector& normal )
  349. {
  350. //
  351. // calculate the displacement surface normal
  352. //
  353. Vector tmp[2];
  354. VectorSubtract( m_Points[1], m_Points[0], tmp[0] );
  355. VectorSubtract( m_Points[3], m_Points[0], tmp[1] );
  356. CrossProduct( tmp[1], tmp[0], normal );
  357. VectorNormalize( normal );
  358. }
  359. //=========================================================================
  360. //
  361. // Node Class (for displacement quad-tree)
  362. //
  363. class CCoreDispNode
  364. {
  365. public:
  366. enum { MAX_NEIGHBOR_NODE_COUNT = 4 };
  367. enum { MAX_NEIGHBOR_VERT_COUNT = 8 };
  368. enum { MAX_SURF_AT_NODE_COUNT = 8 };
  369. //=========================================================================
  370. //
  371. // Initialization
  372. //
  373. void Init( void );
  374. //=========================================================================
  375. //
  376. //
  377. //
  378. inline void SetBoundingBox( Vector const& bMin, Vector const& bMax );
  379. inline void GetBoundingBox( Vector& bMin, Vector& bMax );
  380. inline void SetErrorTerm( float errorTerm );
  381. inline float GetErrorTerm( void );
  382. inline void SetNeighborNodeIndex( int dir, int index );
  383. inline int GetNeighborNodeIndex( int dir );
  384. inline void SetCenterVertIndex( int index );
  385. inline int GetCenterVertIndex( void );
  386. inline void SetNeighborVertIndex( int dir, int index );
  387. inline int GetNeighborVertIndex( int dir );
  388. inline void SetTriBoundingBox( int index, Vector const& bMin, Vector const& bMax );
  389. inline void GetTriBoundingBox( int index, Vector& bMin, Vector& bMax );
  390. inline void SetTriPlane( int index, Vector const& normal, float dist );
  391. inline void GetTriPlane( int index, cplane_t *plane );
  392. inline void SetRayBoundingBox( int index, Vector const& bMin, Vector const& bMax );
  393. inline void GetRayBoundingBox( int index, Vector& bMin, Vector& bMax );
  394. //=========================================================================
  395. //
  396. // Node Functions (friend functions)
  397. //
  398. friend int GetNodeLevel( int index );
  399. friend int GetNodeCount( int power );
  400. friend int GetNodeParent( int index );
  401. friend int GetNodeChild( int power, int index, int direction );
  402. friend int GetNodeNeighborNode( int power, int index, int direction, int level );
  403. friend int GetNodeNeighborNodeFromNeighborSurf( int power, int index, int direction, int level, int neighborOrient );
  404. friend int GetNodeMinNodeAtLevel( int level );
  405. friend void GetDispNodeTriVerts( CCoreDispInfo *pDisp, int nodeIndex, int triIndex, float *v1, float *v2, float *v3 );
  406. friend void GetComponentsFromNodeIndex( int index, int *x, int *y );
  407. friend int GetNodeIndexFromComponents( int x, int y );
  408. protected:
  409. Vector m_BBox[2]; // displacement node bounding box (take into account size of children)
  410. float m_ErrorTerm; // LOD error term (the "precision" of the representation of the surface at this node's level)
  411. int m_VertIndex; // the node's vertex index (center vertex of node)
  412. int m_NeighborVertIndices[MAX_NEIGHBOR_VERT_COUNT]; // all other vertex indices in node (maximally creates 8 trianglar surfaces)
  413. Vector m_SurfBBoxes[MAX_SURF_AT_NODE_COUNT][2]; // surface bounding boxes - old method
  414. cplane_t m_SurfPlanes[MAX_SURF_AT_NODE_COUNT]; // surface plane info - old method
  415. Vector m_RayBBoxes[4][2]; // bounding boxes for ray traces
  416. };
  417. //-----------------------------------------------------------------------------
  418. //-----------------------------------------------------------------------------
  419. inline void CCoreDispNode::SetBoundingBox( Vector const& bMin, Vector const& bMax )
  420. {
  421. VectorCopy( bMin, m_BBox[0] );
  422. VectorCopy( bMax, m_BBox[1] );
  423. }
  424. //-----------------------------------------------------------------------------
  425. //-----------------------------------------------------------------------------
  426. inline void CCoreDispNode::GetBoundingBox( Vector& bMin, Vector& bMax )
  427. {
  428. VectorCopy( m_BBox[0], bMin );
  429. VectorCopy( m_BBox[1], bMax );
  430. }
  431. //-----------------------------------------------------------------------------
  432. //-----------------------------------------------------------------------------
  433. inline void CCoreDispNode::SetErrorTerm( float errorTerm )
  434. {
  435. m_ErrorTerm = errorTerm;
  436. }
  437. //-----------------------------------------------------------------------------
  438. //-----------------------------------------------------------------------------
  439. inline float CCoreDispNode::GetErrorTerm( void )
  440. {
  441. return m_ErrorTerm;
  442. }
  443. //-----------------------------------------------------------------------------
  444. //-----------------------------------------------------------------------------
  445. inline void CCoreDispNode::SetCenterVertIndex( int index )
  446. {
  447. m_VertIndex = index;
  448. }
  449. //-----------------------------------------------------------------------------
  450. //-----------------------------------------------------------------------------
  451. inline int CCoreDispNode::GetCenterVertIndex( void )
  452. {
  453. return m_VertIndex;
  454. }
  455. //-----------------------------------------------------------------------------
  456. //-----------------------------------------------------------------------------
  457. inline void CCoreDispNode::SetNeighborVertIndex( int dir, int index )
  458. {
  459. Assert( dir >= 0 );
  460. Assert( dir < MAX_NEIGHBOR_VERT_COUNT );
  461. m_NeighborVertIndices[dir] = index;
  462. }
  463. //-----------------------------------------------------------------------------
  464. //-----------------------------------------------------------------------------
  465. inline int CCoreDispNode::GetNeighborVertIndex( int dir )
  466. {
  467. Assert( dir >= 0 );
  468. Assert( dir < MAX_NEIGHBOR_VERT_COUNT );
  469. return m_NeighborVertIndices[dir];
  470. }
  471. //-----------------------------------------------------------------------------
  472. //-----------------------------------------------------------------------------
  473. inline void CCoreDispNode::SetTriBoundingBox( int index, Vector const& bMin, Vector const& bMax )
  474. {
  475. Assert( index >= 0 );
  476. Assert( index < MAX_SURF_AT_NODE_COUNT );
  477. VectorCopy( bMin, m_SurfBBoxes[index][0] );
  478. VectorCopy( bMax, m_SurfBBoxes[index][1] );
  479. }
  480. //-----------------------------------------------------------------------------
  481. //-----------------------------------------------------------------------------
  482. inline void CCoreDispNode::GetTriBoundingBox( int index, Vector& bMin, Vector& bMax )
  483. {
  484. Assert( index >= 0 );
  485. Assert( index < MAX_SURF_AT_NODE_COUNT );
  486. VectorCopy( m_SurfBBoxes[index][0], bMin );
  487. VectorCopy( m_SurfBBoxes[index][1], bMax );
  488. }
  489. //-----------------------------------------------------------------------------
  490. //-----------------------------------------------------------------------------
  491. inline void CCoreDispNode::SetTriPlane( int index, Vector const &normal, float dist )
  492. {
  493. Assert( index >= 0 );
  494. Assert( index < MAX_SURF_AT_NODE_COUNT );
  495. VectorCopy( normal, m_SurfPlanes[index].normal );
  496. m_SurfPlanes[index].dist = dist;
  497. }
  498. //-----------------------------------------------------------------------------
  499. //-----------------------------------------------------------------------------
  500. inline void CCoreDispNode::GetTriPlane( int index, cplane_t *plane )
  501. {
  502. Assert( index >= 0 );
  503. Assert( index < MAX_SURF_AT_NODE_COUNT );
  504. VectorCopy( m_SurfPlanes[index].normal, plane->normal );
  505. plane->dist = m_SurfPlanes[index].dist;
  506. }
  507. //-----------------------------------------------------------------------------
  508. //-----------------------------------------------------------------------------
  509. inline void CCoreDispNode::SetRayBoundingBox( int index, Vector const &bMin, Vector const &bMax )
  510. {
  511. Assert( index >= 0 );
  512. Assert( index < 4 );
  513. VectorCopy( bMin, m_RayBBoxes[index][0] );
  514. VectorCopy( bMax, m_RayBBoxes[index][1] );
  515. }
  516. //-----------------------------------------------------------------------------
  517. //-----------------------------------------------------------------------------
  518. inline void CCoreDispNode::GetRayBoundingBox( int index, Vector& bMin, Vector& bMax )
  519. {
  520. Assert( index >= 0 );
  521. Assert( index < 4 );
  522. VectorCopy( m_RayBBoxes[index][0], bMin );
  523. VectorCopy( m_RayBBoxes[index][1], bMax );
  524. }
  525. //=============================================================================
  526. //
  527. // CCoreInfoBuilder - the primary data necessay to derive a displacement surface
  528. // used by WorldCraft (CMapFace, CMapDisp), VRAD (dface_t, ddispinto_t),
  529. // and the engine (msurface_t, CDispInfo)
  530. //
  531. struct CoreDispVert_t
  532. {
  533. Vector m_FieldVector; // displacement vector field
  534. float m_FieldDistance; // the distances along the displacement vector normal
  535. Vector m_SubdivNormal;
  536. Vector m_SubdivPos; // used the create curvature of displacements
  537. // generated displacement surface data
  538. Vector m_Vert; // displacement surface vertices
  539. Vector m_FlatVert;
  540. Vector m_Normal; // displacement surface normals
  541. Vector m_TangentS; // use in calculating the tangent space axes
  542. Vector m_TangentT; // use in calculating the tangent space axes
  543. Vector2D m_TexCoord; // displacement surface texture coordinates
  544. Vector2D m_LuxelCoords[NUM_BUMP_VECTS+1]; // displacement surface lightmap coordinates
  545. // additional per-vertex data
  546. float m_Alpha; // displacement alpha values (per displacement vertex)
  547. Vector4D m_MultiBlend;
  548. Vector4D m_AlphaBlend;
  549. Vector m_vBlendColors[ 4 ];
  550. };
  551. // New, need to use this at the node level
  552. #define COREDISPTRI_TAG_WALKABLE (1<<0)
  553. #define COREDISPTRI_TAG_FORCE_WALKABLE_BIT (1<<1)
  554. #define COREDISPTRI_TAG_FORCE_WALKABLE_VAL (1<<2)
  555. #define COREDISPTRI_TAG_BUILDABLE (1<<3)
  556. #define COREDISPTRI_TAG_FORCE_BUILDABLE_BIT (1<<4)
  557. #define COREDISPTRI_TAG_FORCE_BUILDABLE_VAL (1<<5)
  558. #define COREDISPTRI_TAG_FORCE_REMOVE_BIT (1<<6)
  559. struct CoreDispTri_t
  560. {
  561. unsigned short m_iIndex[3]; // the three indices that make up a triangle
  562. unsigned short m_uiTags; // walkable, buildable, etc.
  563. };
  564. class CCoreDispInfo : public CDispUtilsHelper
  565. {
  566. public:
  567. //
  568. // tree and displacement surface directions
  569. //
  570. enum { WEST = 0,
  571. NORTH = 1,
  572. EAST = 2,
  573. SOUTH = 3,
  574. SOUTHWEST = 4,
  575. SOUTHEAST = 5,
  576. NORTHWEST = 6,
  577. NORTHEAST = 7 };
  578. #if 0
  579. //
  580. // building parameters
  581. //
  582. enum { BUILD_NORMALS = 0x1,
  583. BUILD_TEXCOORDS = 0x2,
  584. BUILD_LIGHTCOORDS = 0x4,
  585. BUILD_LODTREE = 0x8,
  586. BUILD_COLLISION = 0x10,
  587. BUILD_TANGENTSPACE = 0x20 };
  588. #endif
  589. //
  590. // surface info flags
  591. //
  592. enum { SURF_BUMPED = 0x1,
  593. SURF_NOPHYSICS_COLL = 0x2,
  594. SURF_NOHULL_COLL = 0x4,
  595. SURF_NORAY_COLL = 0x8 };
  596. enum { MAX_DISP_POWER = MAX_MAP_DISP_POWER };
  597. enum { MAX_VERT_COUNT = MAX_DISPVERTS };
  598. enum { MAX_NODE_COUNT = 85 };
  599. // Convert from a CDispUtilsHelper.
  600. public:
  601. static CCoreDispInfo* FromDispUtils( CDispUtilsHelper *p ) { return (CCoreDispInfo*)p; }
  602. // CDispUtilsHelper implementation.
  603. public:
  604. virtual CDispNeighbor* GetEdgeNeighbor( int index );
  605. virtual CDispCornerNeighbors* GetCornerNeighbors( int index );
  606. virtual const CPowerInfo* GetPowerInfo() const;
  607. virtual CDispUtilsHelper* GetDispUtilsByIndex( int index );
  608. public:
  609. //=========================================================================
  610. //
  611. // Creation/Destruction
  612. //
  613. CCoreDispInfo();
  614. ~CCoreDispInfo();
  615. void InitSurf( int parentIndex, Vector points[4], Vector normals[4],
  616. Vector2D texCoords[4], Vector2D lightCoords[4][4], int contents, int flags,
  617. bool bGenerateSurfPointStart, Vector& startPoint,
  618. bool bHasMappingAxes, Vector& uAxis, Vector& vAxis );
  619. void InitDispInfo( int power, int minTess, float smoothingAngle, float *alphas, Vector *dispVectorField, float *dispDistances, int nFlags, const CDispMultiBlend *pvMultiBlends );
  620. // This just unpacks the contents of the verts into arrays and calls InitDispInfo.
  621. void InitDispInfo( int power, int minTess, float smoothingAngle, const CDispVert *pVerts, const CDispTri *pTris, int nFlags, const CDispMultiBlend *pvMultiBlends );
  622. // bool Create( int creationFlags );
  623. bool Create( void );
  624. bool CreateWithoutLOD( void );
  625. //=========================================================================
  626. //
  627. // Parameter "Wrappers"
  628. //
  629. CCoreDispSurface* GetSurface() { return &m_Surf; }
  630. const CCoreDispSurface* GetSurface() const { return &m_Surf; }
  631. inline CCoreDispNode *GetNode( int index );
  632. inline void SetPower( int power );
  633. inline int GetPower( void ) const;
  634. inline int GetPostSpacing( void );
  635. inline int GetWidth( void );
  636. inline int GetHeight( void );
  637. inline int GetSize( void ) const;
  638. inline int GetFlags( void ) const;
  639. // Use this disp as a CDispUtils.
  640. void SetDispUtilsHelperInfo( CCoreDispInfo **ppListBase, int listSize );
  641. void SetNeighborData( const CDispNeighbor edgeNeighbors[4], const CDispCornerNeighbors cornerNeighbors[4] ) { GetSurface()->SetNeighborData( edgeNeighbors, cornerNeighbors ); }
  642. // Get a corner point. Indexed by the CORNER_ defines.
  643. const CVertIndex& GetCornerPointIndex( int index ) const { return GetPowerInfo()->GetCornerPointIndex( index ); }
  644. const Vector& GetCornerPoint( int index ) const { return GetVert( VertIndexToInt( GetCornerPointIndex( index ) ) ); }
  645. inline void SetVert( int index, Vector const& vert );
  646. inline void GetVert( int index, Vector& vert ) const;
  647. inline const Vector& GetVert( int index ) const;
  648. inline const Vector& GetVert( const CVertIndex &index ) const;
  649. inline void GetFlatVert( int index, Vector& vert ) const;
  650. inline void SetFlatVert( int index, const Vector &vert );
  651. inline void GetNormal( int index, Vector& normal ) const;
  652. inline const Vector& GetNormal( int index ) const;
  653. inline const Vector& GetNormal( const CVertIndex &index ) const;
  654. inline void SetNormal( int index, Vector const& normal );
  655. inline void SetNormal( const CVertIndex &index, Vector const& normal );
  656. inline void GetTangentS( int index, Vector& tangentS ) const;
  657. inline const Vector &GetTangentS( int index ) const;
  658. inline const Vector &GetTangentS( const CVertIndex &index ) const { return GetTangentS(VertIndexToInt(index)); }
  659. inline void GetTangentT( int index, Vector& tangentT ) const;
  660. inline void SetTangentS( int index, Vector const& vTangentS ) { m_pVerts[index].m_TangentS = vTangentS; }
  661. inline void SetTangentT( int index, Vector const& vTangentT ) { m_pVerts[index].m_TangentT = vTangentT; }
  662. inline void SetTexCoord( int index, Vector2D const& texCoord );
  663. inline void GetTexCoord( int index, Vector2D& texCoord ) const;
  664. inline void SetLuxelCoord( int bumpIndex, int index, Vector2D const& luxelCoord );
  665. inline void GetLuxelCoord( int bumpIndex, int index, Vector2D& luxelCoord ) const;
  666. inline void SetAlpha( int index, float alpha );
  667. inline float GetAlpha( int index );
  668. inline void SetMultiBlend( int index, Vector4D &vBlend, Vector4D &vAlphaBlend, Vector &vColor1, Vector &vColor2, Vector &vColor3, Vector &vColor4 );
  669. inline void SetMultiBlendColor( int index, int nColorIndex, Vector &vColor );
  670. inline void SetMultiBlend( int index, Vector4D &vBlend );
  671. inline void SetAlphaBlend( int index, Vector4D &vAlphaBlend );
  672. inline void GetMultiBlend( int index, Vector4D &vBlend, Vector4D &vAlphaBlend, Vector &vColor1, Vector &vColor2, Vector &vColor3, Vector &vColor4 ) const;
  673. inline void GetMultiBlend( int index, Vector4D &vBlend ) const;
  674. inline void GetAlphaBlend( int index, Vector4D &vAlphaBlend ) const;
  675. int GetTriCount( void );
  676. void GetTriIndices( int iTri, unsigned short &v1, unsigned short &v2, unsigned short &v3 );
  677. void SetTriIndices( int iTri, unsigned short v1, unsigned short v2, unsigned short v3 );
  678. void GetTriPos( int iTri, Vector &v1, Vector &v2, Vector &v3 );
  679. inline void SetTriTag( int iTri, unsigned short nTag ) { m_pTris[iTri].m_uiTags |= nTag; }
  680. inline void ResetTriTag( int iTri, unsigned short nTag ) { m_pTris[iTri].m_uiTags &= ~nTag; }
  681. inline void ToggleTriTag( int iTri, unsigned short nTag ) { m_pTris[iTri].m_uiTags ^= nTag; }
  682. inline bool IsTriTag( int iTri, unsigned short nTag ) { return ( ( m_pTris[iTri].m_uiTags & nTag ) != 0 ); }
  683. inline unsigned short GetTriTagValue( int iTri ) { return m_pTris[iTri].m_uiTags; }
  684. inline void SetTriTagValue( int iTri, unsigned short nVal ) { m_pTris[iTri].m_uiTags = nVal; }
  685. bool IsTriWalkable( int iTri );
  686. bool IsTriBuildable( int iTri );
  687. bool IsTriRemove( int iTri );
  688. inline void SetElevation( float elevation );
  689. inline float GetElevation( void );
  690. inline void ResetFieldVectors( void );
  691. inline void SetFieldVector( int index, Vector const &v );
  692. inline void GetFieldVector( int index, Vector& v );
  693. inline void ResetFieldDistances( void );
  694. inline void SetFieldDistance( int index, float dist );
  695. inline float GetFieldDistance( int index );
  696. inline void ResetSubdivPositions( void );
  697. inline void SetSubdivPosition( int ndx, Vector const &v );
  698. inline void GetSubdivPosition( int ndx, Vector& v );
  699. inline void ResetSubdivNormals( void );
  700. inline void SetSubdivNormal( int ndx, Vector const &v );
  701. inline void GetSubdivNormal( int ndx, Vector &v );
  702. inline void SetRenderIndexCount( int count );
  703. inline int GetRenderIndexCount( void );
  704. inline void SetRenderIndex( int index, int triIndex );
  705. inline int GetRenderIndex( int index );
  706. inline CoreDispVert_t *GetDispVert( int iVert ) { return &m_pVerts[iVert]; }
  707. inline CoreDispVert_t *GetDispVertList();
  708. inline unsigned short *GetRenderIndexList( void );
  709. inline void SetTouched( bool touched );
  710. inline bool IsTouched( void );
  711. void CalcDispSurfCoords( bool bLightMap, int lightmapID );
  712. void GetPositionOnSurface( float u, float v, Vector &vPos, Vector *pNormal, float *pAlpha );
  713. void DispUVToSurf( Vector2D const &dispUV, Vector &vecPoint, Vector *pNormal, float *pAlpha );
  714. void BaseFacePlaneToDispUV( Vector const &planePt, Vector2D &dispUV );
  715. bool SurfToBaseFacePlane( Vector const &surfPt, Vector &planePt );
  716. const CDispCornerNeighbors* GetCornerNeighbors( int iCorner ) const { return GetSurface()->GetCornerNeighbors( iCorner ); }
  717. const CDispNeighbor* GetEdgeNeighbor( int iEdge ) const { return GetSurface()->GetEdgeNeighbor( iEdge ); }
  718. void SetListIndex( int nIndex ) { m_nListIndex = nIndex; }
  719. int GetListIndex( void ) { return m_nListIndex; }
  720. CBitVec<MAX_DISPVERTS>& GetAllowedVerts() { return m_AllowedVerts; }
  721. const CBitVec<MAX_DISPVERTS>& GetAllowedVerts() const { return m_AllowedVerts; }
  722. void AllowedVerts_Clear( void ) { m_AllowedVerts.SetAll(); }
  723. int AllowedVerts_GetNumDWords() const { return m_AllowedVerts.GetNumDWords(); }
  724. unsigned long AllowedVerts_GetDWord(int i) const { return m_AllowedVerts.GetDWord( i ); }
  725. void AllowedVerts_SetDWord(int i, unsigned long val) { m_AllowedVerts.SetDWord( i, val ); }
  726. void Position_Update( int iVert, Vector vecPos );
  727. //=========================================================================
  728. //
  729. // friend functions
  730. //
  731. friend void SmoothNeighboringDispSurfNormals( CCoreDispInfo **ppCoreDispInfoList, int listSize );
  732. private:
  733. // be changed to match the paint normal next pass)
  734. // LOD/collision node data
  735. CCoreDispNode *m_Nodes; // LOD quad-tree nodes
  736. float m_Elevation; // distance along the subdivision normal (should
  737. // defines the size of the displacement surface
  738. int m_Power; // "size" of the displacement map
  739. // base surface data
  740. CCoreDispSurface m_Surf; // surface containing displacement data
  741. // be changed to match the paint normal next pass)
  742. // Vertex data..
  743. CoreDispVert_t *m_pVerts;
  744. // Triangle data..
  745. CoreDispTri_t *m_pTris;
  746. int m_nFlags;
  747. // render specific data
  748. int m_RenderIndexCount; // number of indices used in rendering
  749. unsigned short *m_RenderIndices; // rendering index list (list of triangles)
  750. int m_RenderCounter; // counter to verify surfaces are renderered/collided with only once per frame
  751. // utility data
  752. bool m_bTouched; // touched flag
  753. CCoreDispInfo *m_pNext; // used for chaining
  754. // The list that this disp is in (used for CDispUtils::IHelper implementation).
  755. CCoreDispInfo **m_ppListBase;
  756. int m_ListSize;
  757. CBitVec<MAX_DISPVERTS> m_AllowedVerts; // Built in VBSP. Defines which verts are allowed to exist based on what the neighbors are.
  758. int m_nListIndex;
  759. //=========================================================================
  760. //
  761. // Creation Functions
  762. //
  763. void GenerateDispSurf( void );
  764. void GenerateDispSurfNormals( void );
  765. void GenerateDispSurfTangentSpaces( void );
  766. bool DoesEdgeExist( int indexRow, int indexCol, int direction, int postSpacing );
  767. void CalcNormalFromEdges( int indexRow, int indexCol, bool bIsEdge[4], Vector& normal );
  768. void CalcDispSurfAlphas( void );
  769. void GenerateLODTree( void );
  770. void CalcVertIndicesAtNodes( int nodeIndex );
  771. int GetNodeVertIndexFromParentIndex( int level, int parentVertIndex, int direction );
  772. void CalcNodeInfo( int nodeIndex, int terminationLevel );
  773. void CalcNeighborVertIndicesAtNode( int nodeIndex, int level );
  774. void CalcNeighborNodeIndicesAtNode( int nodeIndex, int level );
  775. void CalcErrorTermAtNode( int nodeIndex, int level );
  776. float GetMaxErrorFromChildren( int nodeIndex, int level );
  777. void CalcBoundingBoxAtNode( int nodeIndex );
  778. void CalcMinMaxBoundingBoxAtNode( int nodeIndex, Vector& bMin, Vector& bMax );
  779. void CalcTriSurfInfoAtNode( int nodeIndex );
  780. void CalcTriSurfIndices( int nodeIndex, int indices[8][3] );
  781. void CalcTriSurfBoundingBoxes( int nodeIndex, int indices[8][3] );
  782. void CalcRayBoundingBoxes( int nodeIndex, int indices[8][3] );
  783. void CalcTriSurfPlanes( int nodeIndex, int indices[8][3] );
  784. void GenerateCollisionData( void );
  785. void GenerateCollisionSurface( void );
  786. void CreateBoundingBoxes( CoreDispBBox_t *pBBox, int count );
  787. void DispUVToSurf_TriTLToBR( Vector &vecPoint, Vector *pNormal, float *pAlpha, float flU, float flV, const Vector &vecIntersectPoint );
  788. void DispUVToSurf_TriBLToTR( Vector &vecPoint, Vector *pNormal, float *pAlpha, float flU, float flV, const Vector &vecIntersectPoint );
  789. void DispUVToSurf_TriTLToBR_1( const Vector &vecIntersectPoint, int nSnapU, int nNextU, int nSnapV, int nNextV, Vector &vecPoint, Vector *pNormal, float *pAlpha, bool bBackup );
  790. void DispUVToSurf_TriTLToBR_2( const Vector &vecIntersectPoint, int nSnapU, int nNextU, int nSnapV, int nNextV, Vector &vecPoint, Vector *pNormal, float *pAlpha, bool bBackup );
  791. void DispUVToSurf_TriBLToTR_1( const Vector &vecIntersectPoint, int nSnapU, int nNextU, int nSnapV, int nNextV, Vector &vecPoint, Vector *pNormal, float *pAlpha, bool bBackup );
  792. void DispUVToSurf_TriBLToTR_2( const Vector &vecIntersectPoint, int nSnapU, int nNextU, int nSnapV, int nNextV, Vector &vecPoint, Vector *pNormal, float *pAlpha, bool bBackup );
  793. void GetTriangleIndicesForDispBBox( int nIndex, int nTris[2][3] );
  794. void BuildTriTLtoBR( int ndx );
  795. void BuildTriBLtoTR( int ndx );
  796. void InitTris( void );
  797. void CreateTris( void );
  798. };
  799. //-----------------------------------------------------------------------------
  800. //-----------------------------------------------------------------------------
  801. inline void CCoreDispInfo::SetPower( int power )
  802. {
  803. m_Power = power;
  804. }
  805. //-----------------------------------------------------------------------------
  806. //-----------------------------------------------------------------------------
  807. inline int CCoreDispInfo::GetPower( void ) const
  808. {
  809. return m_Power;
  810. }
  811. //-----------------------------------------------------------------------------
  812. //-----------------------------------------------------------------------------
  813. inline int CCoreDispInfo::GetPostSpacing( void )
  814. {
  815. return ( ( 1 << m_Power ) + 1 );
  816. }
  817. //-----------------------------------------------------------------------------
  818. //-----------------------------------------------------------------------------
  819. inline int CCoreDispInfo::GetWidth( void )
  820. {
  821. return ( ( 1 << m_Power ) + 1 );
  822. }
  823. //-----------------------------------------------------------------------------
  824. //-----------------------------------------------------------------------------
  825. inline int CCoreDispInfo::GetHeight( void )
  826. {
  827. return ( ( 1 << m_Power ) + 1 );
  828. }
  829. //-----------------------------------------------------------------------------
  830. //-----------------------------------------------------------------------------
  831. inline int CCoreDispInfo::GetSize( void ) const
  832. {
  833. return ( ( ( 1 << m_Power ) + 1 ) * ( ( 1 << m_Power ) + 1 ) );
  834. }
  835. //-----------------------------------------------------------------------------
  836. //-----------------------------------------------------------------------------
  837. inline int CCoreDispInfo::GetFlags( void ) const
  838. {
  839. return m_nFlags;
  840. }
  841. //-----------------------------------------------------------------------------
  842. //-----------------------------------------------------------------------------
  843. inline void CCoreDispInfo::SetVert( int index, Vector const &vert )
  844. {
  845. Assert( index >= 0 );
  846. Assert( index < MAX_VERT_COUNT );
  847. VectorCopy( vert, m_pVerts[index].m_Vert );
  848. }
  849. //-----------------------------------------------------------------------------
  850. //-----------------------------------------------------------------------------
  851. inline void CCoreDispInfo::GetVert( int index, Vector& vert ) const
  852. {
  853. Assert( index >= 0 );
  854. Assert( index < MAX_VERT_COUNT );
  855. VectorCopy( m_pVerts[index].m_Vert, vert );
  856. }
  857. inline const Vector& CCoreDispInfo::GetVert( int index ) const
  858. {
  859. Assert( index >= 0 );
  860. Assert( index < MAX_VERT_COUNT );
  861. return m_pVerts[index].m_Vert;
  862. }
  863. inline const Vector& CCoreDispInfo::GetVert( const CVertIndex &index ) const
  864. {
  865. return GetVert( VertIndexToInt( index ) );
  866. }
  867. //-----------------------------------------------------------------------------
  868. //-----------------------------------------------------------------------------
  869. inline void CCoreDispInfo::GetFlatVert( int index, Vector& vert ) const
  870. {
  871. Assert( index >= 0 );
  872. Assert( index < MAX_VERT_COUNT );
  873. VectorCopy( m_pVerts[index].m_FlatVert, vert );
  874. }
  875. //-----------------------------------------------------------------------------
  876. //-----------------------------------------------------------------------------
  877. inline void CCoreDispInfo::SetFlatVert( int index, const Vector &vert )
  878. {
  879. Assert( index >= 0 );
  880. Assert( index < MAX_VERT_COUNT );
  881. VectorCopy( vert, m_pVerts[index].m_FlatVert );
  882. }
  883. //-----------------------------------------------------------------------------
  884. //-----------------------------------------------------------------------------
  885. inline void CCoreDispInfo::SetNormal( int index, Vector const &normal )
  886. {
  887. Assert( index >= 0 );
  888. Assert( index < MAX_VERT_COUNT );
  889. VectorCopy( normal, m_pVerts[index].m_Normal );
  890. }
  891. inline void CCoreDispInfo::SetNormal( const CVertIndex &index, Vector const &normal )
  892. {
  893. SetNormal( VertIndexToInt( index ), normal );
  894. }
  895. //-----------------------------------------------------------------------------
  896. //-----------------------------------------------------------------------------
  897. inline void CCoreDispInfo::GetNormal( int index, Vector& normal ) const
  898. {
  899. Assert( index >= 0 );
  900. Assert( index < MAX_VERT_COUNT );
  901. VectorCopy( m_pVerts[index].m_Normal, normal );
  902. }
  903. //-----------------------------------------------------------------------------
  904. //-----------------------------------------------------------------------------
  905. inline const Vector& CCoreDispInfo::GetNormal( int index ) const
  906. {
  907. Assert( index >= 0 );
  908. Assert( index < MAX_VERT_COUNT );
  909. return m_pVerts[index].m_Normal;
  910. }
  911. inline const Vector& CCoreDispInfo::GetNormal( const CVertIndex &index ) const
  912. {
  913. return GetNormal( VertIndexToInt( index ) );
  914. }
  915. //-----------------------------------------------------------------------------
  916. //-----------------------------------------------------------------------------
  917. inline void CCoreDispInfo::GetTangentS( int index, Vector& tangentS ) const
  918. {
  919. Assert( index >= 0 );
  920. Assert( index < GetSize() );
  921. VectorCopy( m_pVerts[index].m_TangentS, tangentS );
  922. }
  923. inline const Vector &CCoreDispInfo::GetTangentS( int index ) const
  924. {
  925. Assert( index >= 0 );
  926. Assert( index < GetSize() );
  927. return m_pVerts[index].m_TangentS;
  928. }
  929. //-----------------------------------------------------------------------------
  930. //-----------------------------------------------------------------------------
  931. inline void CCoreDispInfo::GetTangentT( int index, Vector& tangentT ) const
  932. {
  933. Assert( index >= 0 );
  934. Assert( index < GetSize() );
  935. VectorCopy( m_pVerts[index].m_TangentT, tangentT );
  936. }
  937. //-----------------------------------------------------------------------------
  938. //-----------------------------------------------------------------------------
  939. inline void CCoreDispInfo::SetTexCoord( int index, Vector2D const& texCoord )
  940. {
  941. Assert( index >= 0 );
  942. Assert( index < GetSize() );
  943. Vector2DCopy( texCoord, m_pVerts[index].m_TexCoord );
  944. }
  945. //-----------------------------------------------------------------------------
  946. //-----------------------------------------------------------------------------
  947. inline void CCoreDispInfo::GetTexCoord( int index, Vector2D& texCoord ) const
  948. {
  949. Assert( index >= 0 );
  950. Assert( index < GetSize() );
  951. Vector2DCopy( m_pVerts[index].m_TexCoord, texCoord );
  952. }
  953. //-----------------------------------------------------------------------------
  954. //-----------------------------------------------------------------------------
  955. inline void CCoreDispInfo::SetLuxelCoord( int bumpIndex, int index, Vector2D const& luxelCoord )
  956. {
  957. Assert( index >= 0 );
  958. Assert( index < GetSize() );
  959. Assert( bumpIndex >= 0 );
  960. Assert( bumpIndex < NUM_BUMP_VECTS + 1 );
  961. Vector2DCopy( luxelCoord, m_pVerts[index].m_LuxelCoords[bumpIndex] );
  962. }
  963. //-----------------------------------------------------------------------------
  964. //-----------------------------------------------------------------------------
  965. inline void CCoreDispInfo::GetLuxelCoord( int bumpIndex, int index, Vector2D& luxelCoord ) const
  966. {
  967. Assert( index >= 0 );
  968. Assert( index < MAX_VERT_COUNT );
  969. Assert( bumpIndex >= 0 );
  970. Assert( bumpIndex < NUM_BUMP_VECTS + 1 );
  971. Vector2DCopy( m_pVerts[index].m_LuxelCoords[bumpIndex], luxelCoord );
  972. }
  973. //-----------------------------------------------------------------------------
  974. //-----------------------------------------------------------------------------
  975. inline void CCoreDispInfo::SetAlpha( int index, float alpha )
  976. {
  977. Assert( index >= 0 );
  978. Assert( index < MAX_VERT_COUNT );
  979. m_pVerts[index].m_Alpha = alpha;
  980. }
  981. //-----------------------------------------------------------------------------
  982. //-----------------------------------------------------------------------------
  983. inline float CCoreDispInfo::GetAlpha( int index )
  984. {
  985. Assert( index >= 0 );
  986. Assert( index < MAX_VERT_COUNT );
  987. return m_pVerts[index].m_Alpha;
  988. }
  989. inline void CCoreDispInfo::SetMultiBlend( int index, Vector4D &vBlend, Vector4D &vAlphaBlend, Vector &vColor1, Vector &vColor2, Vector &vColor3, Vector &vColor4 )
  990. {
  991. Assert( index >= 0 );
  992. Assert( index < MAX_VERT_COUNT );
  993. m_pVerts[ index ].m_MultiBlend = vBlend;
  994. m_pVerts[ index ].m_AlphaBlend = vAlphaBlend;
  995. m_pVerts[ index ].m_vBlendColors[ 0 ] = vColor1;
  996. m_pVerts[ index ].m_vBlendColors[ 1 ] = vColor2;
  997. m_pVerts[ index ].m_vBlendColors[ 2 ] = vColor3;
  998. m_pVerts[ index ].m_vBlendColors[ 3 ] = vColor4;
  999. }
  1000. void CCoreDispInfo::SetMultiBlendColor( int index, int nColorIndex, Vector &vColor )
  1001. {
  1002. Assert( index >= 0 );
  1003. Assert( index < MAX_VERT_COUNT );
  1004. m_pVerts[ index ].m_vBlendColors[ nColorIndex ] = vColor;
  1005. }
  1006. inline void CCoreDispInfo::SetMultiBlend( int index, Vector4D &vBlend )
  1007. {
  1008. Assert( index >= 0 );
  1009. Assert( index < MAX_VERT_COUNT );
  1010. m_pVerts[ index ].m_MultiBlend = vBlend;
  1011. }
  1012. inline void CCoreDispInfo::SetAlphaBlend( int index, Vector4D &vAlphaBlend )
  1013. {
  1014. Assert( index >= 0 );
  1015. Assert( index < MAX_VERT_COUNT );
  1016. m_pVerts[ index ].m_AlphaBlend = vAlphaBlend;
  1017. }
  1018. inline void CCoreDispInfo::GetMultiBlend( int index, Vector4D &vBlend, Vector4D &vAlphaBlend, Vector &vColor1, Vector &vColor2, Vector &vColor3, Vector &vColor4 ) const
  1019. {
  1020. Assert( index >= 0 );
  1021. Assert( index < MAX_VERT_COUNT );
  1022. vBlend = m_pVerts[ index ].m_MultiBlend;
  1023. vAlphaBlend = m_pVerts[ index ].m_AlphaBlend;
  1024. vColor1 = m_pVerts[ index ].m_vBlendColors[ 0 ];
  1025. vColor2 = m_pVerts[ index ].m_vBlendColors[ 1 ];
  1026. vColor3 = m_pVerts[ index ].m_vBlendColors[ 2 ];
  1027. vColor4 = m_pVerts[ index ].m_vBlendColors[ 3 ];
  1028. }
  1029. inline void CCoreDispInfo::GetMultiBlend( int index, Vector4D &vBlend ) const
  1030. {
  1031. Assert( index >= 0 );
  1032. Assert( index < MAX_VERT_COUNT );
  1033. vBlend = m_pVerts[ index ].m_MultiBlend;
  1034. }
  1035. inline void CCoreDispInfo::GetAlphaBlend( int index, Vector4D &vAlphaBlend ) const
  1036. {
  1037. Assert( index >= 0 );
  1038. Assert( index < MAX_VERT_COUNT );
  1039. vAlphaBlend = m_pVerts[ index ].m_AlphaBlend;
  1040. }
  1041. //-----------------------------------------------------------------------------
  1042. //-----------------------------------------------------------------------------
  1043. inline void CCoreDispInfo::SetElevation( float elevation )
  1044. {
  1045. m_Elevation = elevation;
  1046. }
  1047. //-----------------------------------------------------------------------------
  1048. //-----------------------------------------------------------------------------
  1049. inline float CCoreDispInfo::GetElevation( void )
  1050. {
  1051. return m_Elevation;
  1052. }
  1053. //-----------------------------------------------------------------------------
  1054. //-----------------------------------------------------------------------------
  1055. inline void CCoreDispInfo::ResetFieldVectors( void )
  1056. {
  1057. // Vector normal;
  1058. // m_Surf.GetNormal( normal );
  1059. int size = GetSize();
  1060. for( int i = 0; i < size; i++ )
  1061. {
  1062. m_pVerts[i].m_FieldVector.Init();
  1063. // m_FieldVectors[i] = normal;
  1064. }
  1065. }
  1066. //-----------------------------------------------------------------------------
  1067. //-----------------------------------------------------------------------------
  1068. inline void CCoreDispInfo::SetFieldVector( int index, Vector const &v )
  1069. {
  1070. Assert( index >= 0 );
  1071. Assert( index < MAX_VERT_COUNT );
  1072. VectorCopy( v, m_pVerts[index].m_FieldVector );
  1073. }
  1074. //-----------------------------------------------------------------------------
  1075. //-----------------------------------------------------------------------------
  1076. inline void CCoreDispInfo::GetFieldVector( int index, Vector& v )
  1077. {
  1078. Assert( index >= 0 );
  1079. Assert( index < MAX_VERT_COUNT );
  1080. VectorCopy( m_pVerts[index].m_FieldVector, v );
  1081. }
  1082. //-----------------------------------------------------------------------------
  1083. //-----------------------------------------------------------------------------
  1084. inline void CCoreDispInfo::ResetSubdivPositions( void )
  1085. {
  1086. int size = GetSize();
  1087. for( int i = 0; i < size; i++ )
  1088. {
  1089. m_pVerts[i].m_SubdivPos.Init();
  1090. }
  1091. }
  1092. //-----------------------------------------------------------------------------
  1093. //-----------------------------------------------------------------------------
  1094. inline void CCoreDispInfo::SetSubdivPosition( int ndx, Vector const &v )
  1095. {
  1096. Assert( ndx >= 0 );
  1097. Assert( ndx < MAX_VERT_COUNT );
  1098. m_pVerts[ndx].m_SubdivPos = v;
  1099. }
  1100. //-----------------------------------------------------------------------------
  1101. //-----------------------------------------------------------------------------
  1102. inline void CCoreDispInfo::GetSubdivPosition( int ndx, Vector& v )
  1103. {
  1104. Assert( ndx >= 0 );
  1105. Assert( ndx < MAX_VERT_COUNT );
  1106. v = m_pVerts[ndx].m_SubdivPos;
  1107. }
  1108. //-----------------------------------------------------------------------------
  1109. //-----------------------------------------------------------------------------
  1110. inline void CCoreDispInfo::ResetSubdivNormals( void )
  1111. {
  1112. Vector normal;
  1113. m_Surf.GetNormal( normal );
  1114. int size = GetSize();
  1115. for( int i = 0; i < size; i++ )
  1116. {
  1117. m_pVerts[i].m_SubdivNormal = normal;
  1118. }
  1119. }
  1120. //-----------------------------------------------------------------------------
  1121. //-----------------------------------------------------------------------------
  1122. inline void CCoreDispInfo::SetSubdivNormal( int ndx, Vector const &v )
  1123. {
  1124. Assert( ndx >= 0 );
  1125. Assert( ndx < MAX_VERT_COUNT );
  1126. m_pVerts[ndx].m_SubdivNormal = v;
  1127. }
  1128. //-----------------------------------------------------------------------------
  1129. //-----------------------------------------------------------------------------
  1130. inline void CCoreDispInfo::GetSubdivNormal( int ndx, Vector &v )
  1131. {
  1132. Assert( ndx >= 0 );
  1133. Assert( ndx < MAX_VERT_COUNT );
  1134. v = m_pVerts[ndx].m_SubdivNormal;
  1135. }
  1136. //-----------------------------------------------------------------------------
  1137. //-----------------------------------------------------------------------------
  1138. inline void CCoreDispInfo::ResetFieldDistances( void )
  1139. {
  1140. int size = GetSize();
  1141. for( int i = 0; i < size; i++ )
  1142. {
  1143. m_pVerts[i].m_FieldDistance = 0.0f;
  1144. }
  1145. }
  1146. //-----------------------------------------------------------------------------
  1147. //-----------------------------------------------------------------------------
  1148. inline void CCoreDispInfo::SetFieldDistance( int index, float dist )
  1149. {
  1150. Assert( index >= 0 );
  1151. Assert( index < GetSize() );
  1152. m_pVerts[index].m_FieldDistance = dist;
  1153. }
  1154. //-----------------------------------------------------------------------------
  1155. //-----------------------------------------------------------------------------
  1156. inline float CCoreDispInfo::GetFieldDistance( int index )
  1157. {
  1158. Assert( index >= 0 );
  1159. Assert( index < GetSize() );
  1160. return m_pVerts[index].m_FieldDistance;
  1161. }
  1162. //-----------------------------------------------------------------------------
  1163. //-----------------------------------------------------------------------------
  1164. inline void CCoreDispInfo::SetRenderIndexCount( int count )
  1165. {
  1166. m_RenderIndexCount = count;
  1167. }
  1168. //-----------------------------------------------------------------------------
  1169. //-----------------------------------------------------------------------------
  1170. inline int CCoreDispInfo::GetRenderIndexCount( void )
  1171. {
  1172. return m_RenderIndexCount;
  1173. }
  1174. //-----------------------------------------------------------------------------
  1175. //-----------------------------------------------------------------------------
  1176. inline void CCoreDispInfo::SetRenderIndex( int index, int triIndex )
  1177. {
  1178. Assert( index >= 0 );
  1179. Assert( index < ( MAX_VERT_COUNT*2*3) );
  1180. m_RenderIndices[index] = triIndex;
  1181. }
  1182. //-----------------------------------------------------------------------------
  1183. //-----------------------------------------------------------------------------
  1184. inline int CCoreDispInfo::GetRenderIndex( int index )
  1185. {
  1186. Assert( index >= 0 );
  1187. Assert( index < ( MAX_VERT_COUNT*2*3) );
  1188. return m_RenderIndices[index];
  1189. }
  1190. //-----------------------------------------------------------------------------
  1191. //-----------------------------------------------------------------------------
  1192. inline CoreDispVert_t *CCoreDispInfo::GetDispVertList()
  1193. {
  1194. return m_pVerts;
  1195. }
  1196. //-----------------------------------------------------------------------------
  1197. //-----------------------------------------------------------------------------
  1198. inline unsigned short *CCoreDispInfo::GetRenderIndexList( void )
  1199. {
  1200. return &m_RenderIndices[0];
  1201. }
  1202. //-----------------------------------------------------------------------------
  1203. //-----------------------------------------------------------------------------
  1204. inline void CCoreDispInfo::SetTouched( bool touched )
  1205. {
  1206. m_bTouched = touched;
  1207. }
  1208. //-----------------------------------------------------------------------------
  1209. //-----------------------------------------------------------------------------
  1210. inline bool CCoreDispInfo::IsTouched( void )
  1211. {
  1212. return m_bTouched;
  1213. }
  1214. //-----------------------------------------------------------------------------
  1215. //-----------------------------------------------------------------------------
  1216. inline CCoreDispNode *CCoreDispInfo::GetNode( int index )
  1217. {
  1218. Assert( index >= 0 );
  1219. Assert( index < MAX_NODE_COUNT );
  1220. return &m_Nodes[index];
  1221. }
  1222. bool CalcBarycentricCooefs( Vector const &v0, Vector const &v1, Vector const &v2,
  1223. Vector const &pt, float &c0, float &c1, float &c2 );
  1224. #endif // BUILDDISP_H