Team Fortress 2 Source Code as on 22/4/2020
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.

1460 lines
51 KiB

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