Advertisement
Guest User

Untitled

a guest
Sep 13th, 2012
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 30.53 KB | None | 0 0
  1. //========= Copyright © 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #include "cbase.h"
  8. #include "dt_utlvector_recv.h"
  9. #include "bone_setup.h"
  10. #include "c_ai_basenpc.h"
  11. #include "engine/IVDebugOverlay.h"
  12.  
  13. #include "IVRenderView.h"
  14. #include "view_shared.h"
  15. #include "iviewrender.h"
  16.  
  17. #include "tier0/vprof.h"
  18. #include "soundinfo.h"
  19.  
  20. // TODO: These should be in public by the time the SDK ships
  21. #if 1
  22.     #include "../../common/blobulator/Implicit/ImpDefines.h"
  23.     #include "../../common/blobulator/Implicit/ImpRenderer.h"
  24.     #include "../../common/blobulator/Implicit/ImpTiler.h"
  25.     #include "../../common/blobulator/Implicit/UserFunctions.h"
  26. #else
  27.     #include "../common/blobulator/Implicit/ImpDefines.h"
  28.     #include "../../common/blobulator/Implicit/SweepRenderer2.h"
  29.     #include "../../common/blobulator/Implicit/ImpTiler2.h"
  30.     #include "../../common/blobulator/Implicit/UserFunctions2.h"
  31. #endif
  32. // memdbgon must be the last include file in a .cpp file!!!
  33. #include "tier0/memdbgon.h"
  34.  
  35. //-----------------------------------------------------------------------------
  36. // Purpose:
  37. //-----------------------------------------------------------------------------
  38. class C_NPC_Surface : public C_AI_BaseNPC
  39. {
  40. public:
  41.     DECLARE_CLASS( C_NPC_Surface, C_AI_BaseNPC );
  42.     DECLARE_CLIENTCLASS();
  43.     DECLARE_INTERPOLATION();
  44.  
  45.                     C_NPC_Surface();
  46.     virtual         ~C_NPC_Surface();
  47.  
  48.     // model specific
  49.     virtual void GetRenderBounds( Vector& theMins, Vector& theMaxs );
  50.     virtual bool IsTransparent( void );
  51.     ShadowType_t    ShadowCastType() { return SHADOWS_NONE; }
  52.     bool UsesPowerOfTwoFrameBufferTexture( void );
  53.     bool UsesFullFrameBufferTexture( void );
  54.     virtual int DrawModel( int flags );
  55.  
  56.     virtual bool    GetSoundSpatialization( SpatializationInfo_t& info );
  57.  
  58. #define MAX_SURFACE_ELEMENTS 1000 //200
  59.  
  60.     IMaterial *m_pMaterial;
  61.  
  62.     CUtlVector< Vector  > m_vecSurfacePos;
  63.     CUtlVector< CInterpolatedVar< Vector > > m_iv_vecSurfacePos;
  64.  
  65.     CUtlVector< float > m_flSurfaceV;
  66.     CUtlVector< CInterpolatedVar< float > > m_iv_flSurfaceV;
  67.  
  68.     CUtlVector< float > m_flSurfaceR;
  69.     CUtlVector< CInterpolatedVar< float > > m_iv_flSurfaceR;
  70.  
  71.     int             m_nActiveParticles;
  72.     float           m_flRadius;
  73.  
  74. private:
  75.     C_NPC_Surface( const C_NPC_Surface & ); // not defined, not accessible
  76. };
  77.  
  78.  
  79. //-----------------------------------------------------------------------------
  80. // Purpose: setup network receive table
  81. //-----------------------------------------------------------------------------
  82.  
  83. IMPLEMENT_CLIENTCLASS_DT(C_NPC_Surface, DT_NPC_Surface, CNPC_Surface)
  84.     RecvPropFloat   ( RECVINFO( m_flRadius ) ),
  85.     RecvPropInt     ( RECVINFO( m_nActiveParticles ) ),
  86.     RecvPropUtlVector(
  87.         RECVINFO_UTLVECTOR( m_vecSurfacePos ),
  88.         MAX_SURFACE_ELEMENTS,
  89.         RecvPropVector(NULL, 0, sizeof( Vector ))),
  90.     RecvPropUtlVector(
  91.         RECVINFO_UTLVECTOR( m_flSurfaceV ),
  92.         MAX_SURFACE_ELEMENTS,
  93.         RecvPropFloat(NULL, 0, sizeof( float ))),
  94.     RecvPropUtlVector(
  95.         RECVINFO_UTLVECTOR( m_flSurfaceR ),
  96.         MAX_SURFACE_ELEMENTS,
  97.         RecvPropFloat(NULL, 0, sizeof( float ))),
  98. END_RECV_TABLE()
  99.  
  100. //-----------------------------------------------------------------------------
  101. // Purpose: link networked elements to local data
  102. //-----------------------------------------------------------------------------
  103.  
  104. C_NPC_Surface::C_NPC_Surface()
  105. {
  106.     m_pMaterial = NULL;
  107.  
  108.     m_vecSurfacePos.EnsureCount( MAX_SURFACE_ELEMENTS );
  109.     m_iv_vecSurfacePos.EnsureCount( MAX_SURFACE_ELEMENTS );
  110.  
  111.     m_flSurfaceV.EnsureCount( MAX_SURFACE_ELEMENTS );
  112.     m_iv_flSurfaceV.EnsureCount( MAX_SURFACE_ELEMENTS );
  113.  
  114.     m_flSurfaceR.EnsureCount( MAX_SURFACE_ELEMENTS );
  115.     m_iv_flSurfaceR.EnsureCount( MAX_SURFACE_ELEMENTS );
  116.  
  117.     for (int i = 0; i < MAX_SURFACE_ELEMENTS; i++)
  118.     {
  119.         IInterpolatedVar *pWatcher = &m_iv_vecSurfacePos.Element( i );
  120.         pWatcher->SetDebugName( "m_iv_vecSurfacePos" );
  121.         AddVar( &m_vecSurfacePos.Element( i ), pWatcher, LATCH_ANIMATION_VAR );
  122.  
  123.         pWatcher = &m_iv_flSurfaceV.Element( i );
  124.         pWatcher->SetDebugName( "m_iv_flSurfaceV" );
  125.         AddVar( &m_flSurfaceV.Element( i ), pWatcher, LATCH_ANIMATION_VAR );
  126.  
  127.         pWatcher = &m_iv_flSurfaceR.Element( i );
  128.         pWatcher->SetDebugName( "m_iv_flSurfaceR" );
  129.         AddVar( &m_flSurfaceR.Element( i ), pWatcher, LATCH_ANIMATION_VAR );
  130.     }
  131. }
  132.  
  133. //-----------------------------------------------------------------------------
  134. // Purpose:
  135. //-----------------------------------------------------------------------------
  136.  
  137. C_NPC_Surface::~C_NPC_Surface()
  138. {
  139. }
  140.  
  141.  
  142. //-----------------------------------------------------------------------------
  143. // Purpose: Draw a Sphere
  144. //-----------------------------------------------------------------------------
  145.  
  146. float g_FastSpherePosData[51][8] = {
  147. {  0.0000,  0.0000,  1.0000,  0.0000,  0.0000,  0.0000,  0.0000,  1.0000 },
  148. { -0.0000,  0.5000,  0.8660,  0.2500,  0.1667, -0.0000,  0.5000,  0.8660 },
  149. {  0.5000,  0.0000,  0.8660,  0.0000,  0.1667,  0.5000,  0.0000,  0.8660 },
  150. {  0.0000,  0.0000,  1.0000,  0.5000,  0.0000,  0.0000,  0.0000,  1.0000 },
  151. { -0.5000, -0.0000,  0.8660,  0.5000,  0.1667, -0.5000, -0.0000,  0.8660 },
  152. {  0.0000,  0.0000, -1.0000,  0.0000,  1.0000,  0.0000,  0.0000, -1.0000 },
  153. {  0.5000,  0.0000, -0.8660,  0.0000,  0.8333,  0.5000,  0.0000, -0.8660 },
  154. { -0.0000,  0.5000, -0.8660,  0.2500,  0.8333, -0.0000,  0.5000, -0.8660 },
  155. {  0.0000,  0.0000, -1.0000,  0.5000,  1.0000,  0.0000,  0.0000, -1.0000 },
  156. { -0.5000, -0.0000, -0.8660,  0.5000,  0.8333, -0.5000, -0.0000, -0.8660 },
  157. {  0.0000, -0.5000,  0.8660,  0.7500,  0.1667,  0.0000, -0.5000,  0.8660 },
  158. {  0.0000,  0.0000,  1.0000,  1.0000,  0.0000,  0.0000,  0.0000,  1.0000 },
  159. {  0.5000,  0.0000,  0.8660,  1.0000,  0.1667,  0.5000,  0.0000,  0.8660 },
  160. {  0.0000, -0.5000, -0.8660,  0.7500,  0.8333,  0.0000, -0.5000, -0.8660 },
  161. {  0.0000,  0.0000, -1.0000,  1.0000,  1.0000,  0.0000,  0.0000, -1.0000 },
  162. {  0.5000,  0.0000, -0.8660,  1.0000,  0.8333,  0.5000,  0.0000, -0.8660 },
  163. {  0.6124,  0.6124,  0.5000,  0.1250,  0.3333,  0.6124,  0.6124,  0.5000 },
  164. {  0.8660,  0.0000,  0.5000,  0.0000,  0.3333,  0.8660,  0.0000,  0.5000 },
  165. { -0.0000,  0.8660,  0.5000,  0.2500,  0.3333, -0.0000,  0.8660,  0.5000 },
  166. {  0.8660,  0.0000, -0.5000,  0.0000,  0.6667,  0.8660,  0.0000, -0.5000 },
  167. {  0.6124,  0.6124, -0.5000,  0.1250,  0.6667,  0.6124,  0.6124, -0.5000 },
  168. { -0.0000,  0.8660, -0.5000,  0.2500,  0.6667, -0.0000,  0.8660, -0.5000 },
  169. { -0.6124,  0.6124,  0.5000,  0.3750,  0.3333, -0.6124,  0.6124,  0.5000 },
  170. { -0.8660, -0.0000,  0.5000,  0.5000,  0.3333, -0.8660, -0.0000,  0.5000 },
  171. { -0.6124,  0.6124, -0.5000,  0.3750,  0.6667, -0.6124,  0.6124, -0.5000 },
  172. { -0.8660, -0.0000, -0.5000,  0.5000,  0.6667, -0.8660, -0.0000, -0.5000 },
  173. { -0.6124, -0.6124,  0.5000,  0.6250,  0.3333, -0.6124, -0.6124,  0.5000 },
  174. {  0.0000, -0.8660,  0.5000,  0.7500,  0.3333,  0.0000, -0.8660,  0.5000 },
  175. { -0.6124, -0.6124, -0.5000,  0.6250,  0.6667, -0.6124, -0.6124, -0.5000 },
  176. {  0.0000, -0.8660, -0.5000,  0.7500,  0.6667,  0.0000, -0.8660, -0.5000 },
  177. {  0.6124, -0.6124,  0.5000,  0.8750,  0.3333,  0.6124, -0.6124,  0.5000 },
  178. {  0.8660,  0.0000,  0.5000,  1.0000,  0.3333,  0.8660,  0.0000,  0.5000 },
  179. {  0.6124, -0.6124, -0.5000,  0.8750,  0.6667,  0.6124, -0.6124, -0.5000 },
  180. {  0.8660,  0.0000, -0.5000,  1.0000,  0.6667,  0.8660,  0.0000, -0.5000 },
  181. {  0.9239,  0.3827,  0.0000,  0.0625,  0.5000,  0.9239,  0.3827,  0.0000 },
  182. {  1.0000,  0.0000,  0.0000,  0.0000,  0.5000,  1.0000,  0.0000,  0.0000 },
  183. {  0.7071,  0.7071,  0.0000,  0.1250,  0.5000,  0.7071,  0.7071,  0.0000 },
  184. {  0.3827,  0.9239,  0.0000,  0.1875,  0.5000,  0.3827,  0.9239,  0.0000 },
  185. { -0.0000,  1.0000,  0.0000,  0.2500,  0.5000, -0.0000,  1.0000,  0.0000 },
  186. { -0.3827,  0.9239,  0.0000,  0.3125,  0.5000, -0.3827,  0.9239,  0.0000 },
  187. { -0.7071,  0.7071,  0.0000,  0.3750,  0.5000, -0.7071,  0.7071,  0.0000 },
  188. { -0.9239,  0.3827,  0.0000,  0.4375,  0.5000, -0.9239,  0.3827,  0.0000 },
  189. { -1.0000, -0.0000,  0.0000,  0.5000,  0.5000, -1.0000, -0.0000,  0.0000 },
  190. { -0.9239, -0.3827,  0.0000,  0.5625,  0.5000, -0.9239, -0.3827,  0.0000 },
  191. { -0.7071, -0.7071,  0.0000,  0.6250,  0.5000, -0.7071, -0.7071,  0.0000 },
  192. { -0.3827, -0.9239,  0.0000,  0.6875,  0.5000, -0.3827, -0.9239,  0.0000 },
  193. {  0.0000, -1.0000,  0.0000,  0.7500,  0.5000,  0.0000, -1.0000,  0.0000 },
  194. {  0.3827, -0.9239,  0.0000,  0.8125,  0.5000,  0.3827, -0.9239,  0.0000 },
  195. {  0.7071, -0.7071,  0.0000,  0.8750,  0.5000,  0.7071, -0.7071,  0.0000 },
  196. {  0.9239, -0.3827,  0.0000,  0.9375,  0.5000,  0.9239, -0.3827,  0.0000 },
  197. {  1.0000,  0.0000,  0.0000,  1.0000,  0.5000,  1.0000,  0.0000,  0.0000 }
  198. };
  199.  
  200.  
  201. int g_FastSphereTriData[84][3] = {
  202. { 0, 1, 2 },
  203. { 0, 3, 1 },
  204. { 3, 4, 1 },
  205. { 5, 6, 7 },
  206. { 5, 7, 8 },
  207. { 8, 7, 9 },
  208. { 3, 10, 4 },
  209. { 3, 11, 10 },
  210. { 11, 12, 10 },
  211. { 8, 9, 13 },
  212. { 8, 13, 14 },
  213. { 14, 13, 15 },
  214. { 2, 16, 17 },
  215. { 2, 1, 16 },
  216. { 1, 18, 16 },
  217. { 6, 19, 20 },
  218. { 6, 20, 7 },
  219. { 7, 20, 21 },
  220. { 1, 22, 18 },
  221. { 1, 4, 22 },
  222. { 4, 23, 22 },
  223. { 7, 21, 24 },
  224. { 7, 24, 9 },
  225. { 9, 24, 25 },
  226. { 4, 26, 23 },
  227. { 4, 10, 26 },
  228. { 10, 27, 26 },
  229. { 9, 25, 28 },
  230. { 9, 28, 13 },
  231. { 13, 28, 29 },
  232. { 10, 30, 27 },
  233. { 10, 12, 30 },
  234. { 12, 31, 30 },
  235. { 13, 29, 32 },
  236. { 13, 32, 15 },
  237. { 15, 32, 33 },
  238. { 17, 34, 35 },
  239. { 17, 16, 34 },
  240. { 16, 36, 34 },
  241. { 19, 35, 34 },
  242. { 19, 34, 20 },
  243. { 20, 34, 36 },
  244. { 16, 37, 36 },
  245. { 16, 18, 37 },
  246. { 18, 38, 37 },
  247. { 20, 36, 37 },
  248. { 20, 37, 21 },
  249. { 21, 37, 38 },
  250. { 18, 39, 38 },
  251. { 18, 22, 39 },
  252. { 22, 40, 39 },
  253. { 21, 38, 39 },
  254. { 21, 39, 24 },
  255. { 24, 39, 40 },
  256. { 22, 41, 40 },
  257. { 22, 23, 41 },
  258. { 23, 42, 41 },
  259. { 24, 40, 41 },
  260. { 24, 41, 25 },
  261. { 25, 41, 42 },
  262. { 23, 43, 42 },
  263. { 23, 26, 43 },
  264. { 26, 44, 43 },
  265. { 25, 42, 43 },
  266. { 25, 43, 28 },
  267. { 28, 43, 44 },
  268. { 26, 45, 44 },
  269. { 26, 27, 45 },
  270. { 27, 46, 45 },
  271. { 28, 44, 45 },
  272. { 28, 45, 29 },
  273. { 29, 45, 46 },
  274. { 27, 47, 46 },
  275. { 27, 30, 47 },
  276. { 30, 48, 47 },
  277. { 29, 46, 47 },
  278. { 29, 47, 32 },
  279. { 32, 47, 48 },
  280. { 30, 49, 48 },
  281. { 30, 31, 49 },
  282. { 31, 50, 49 },
  283. { 32, 48, 49 },
  284. { 32, 49, 33 },
  285. { 33, 49, 50 }
  286. };
  287.  
  288.  
  289. void DrawFastSphere( CMeshBuilder &meshBuilder, const Vector &center, float radius, int r, int g, int b )
  290. {
  291.     int i;
  292.  
  293.     int offset = meshBuilder.GetCurrentVertex();
  294.  
  295.     Vector pos;
  296.     for (i = 0; i < 51; i++)
  297.     {
  298.         pos.x = g_FastSpherePosData[i][0] + center.x + g_FastSpherePosData[i][5] * radius;
  299.         pos.y = g_FastSpherePosData[i][1] + center.y + g_FastSpherePosData[i][6] * radius;
  300.         pos.z = g_FastSpherePosData[i][2] + center.z + g_FastSpherePosData[i][7] * radius;
  301.  
  302.         meshBuilder.Position3fv( pos.Base() );
  303.         meshBuilder.Normal3fv( &g_FastSpherePosData[i][5] );
  304.         meshBuilder.TexCoord2fv( 0, &g_FastSpherePosData[i][3] );
  305.         meshBuilder.Color3ub( 255, 255, 255 );
  306.         meshBuilder.AdvanceVertex();
  307.     }
  308.  
  309.     for (i = 0; i < 84; i++)
  310.     {
  311.         meshBuilder.FastIndex( g_FastSphereTriData[i][0] + offset );
  312.         meshBuilder.FastIndex( g_FastSphereTriData[i][1] + offset );
  313.         meshBuilder.FastIndex( g_FastSphereTriData[i][2] + offset );
  314.     }
  315. }
  316.  
  317.  
  318.  
  319.  
  320. //-----------------------------------------------------------------------------
  321. // Purpose: Custom model rendering
  322. //-----------------------------------------------------------------------------
  323.  
  324.  
  325. static ConVar   sv_blr_cubewidth( "blr_cubewidth", "0.8", 0, "Set cubewidth (coarseness of the mesh)" );
  326. static ConVar   sv_blr_render_radius( "blr_render_radius", "1.3", 0, "Set render radius (how far from particle center surface will be)" );
  327. static ConVar   sv_blr_cutoff_radius( "blr_cutoff_radius", "3.3", 0, "Set cutoff radius (how far field extends from each particle)" );
  328.  
  329. static ConVar   sv_surface_center( "surface_center", "0", FCVAR_ARCHIVE, "Adjust render center" );
  330. static ConVar   sv_surface_rotate("surface_rotate", "1", 0, "Whether to rotate for transparency");
  331. static ConVar   sv_surface_testshape( "surface_testshape", "0", 0, "Use a test shape instead of the hydra" );
  332. static ConVar   sv_surface_fountain( "surface_fountain", "0", FCVAR_ARCHIVE, "Turns on settings for rendering the fountain" );
  333.  
  334. static ConVar   sv_surface_draw( "surface_draw", "1", 0, "Draw the surface" );
  335. static ConVar   sv_surface_wireframe( "surface_wireframe", "0", FCVAR_ARCHIVE, "Draw wireframe" );
  336. static ConVar   sv_surface_material("surface_material", "3", FCVAR_ARCHIVE, "Choose a material from 0 to N");
  337. static ConVar   sv_surface_shader("surface_shader", "", FCVAR_ARCHIVE, "Choose a shader");
  338.  
  339. static ConVar   sv_surface_use_tiler("surface_use_tiler", "1", 0, "Use the tiler");
  340. static ConVar   sv_surface_draw_margin("surface_draw_margin", "0", 0, "If tiler is disabled, whether to draw the margin.");
  341. static ConVar   sv_surface_tile("surface_tile", "1", 0, "If tiler is enabled, whether we draw all tiles or just the central one.");
  342. static ConVar   sv_surface_max_tiles( "surface_max_tiles", "-1", 0, "The maximum number of tiles to draw" );
  343. static ConVar   sv_surface_max_slices( "surface_max_slices", "-1", 0, "The maximum number of slices to draw" );
  344.  
  345. static ConVar   sv_surface_calc_uv_and_tan( "surface_calc_uv_and_tan", "1", FCVAR_ARCHIVE, "Calculate UVs and Tangents" );
  346. static ConVar   sv_surface_calc_tan_only( "surface_calc_tan_only", "0", FCVAR_ARCHIVE, "Calculate Only Tangents" );
  347. static ConVar   sv_surface_calc_color( "surface_calc_color", "0", FCVAR_ARCHIVE, "Just interpolate colors" );
  348. static ConVar   sv_surface_calc_hifreq_color( "surface_calc_hifreq_color", "0", FCVAR_ARCHIVE, "Experimental hi-freq colors" );
  349. static ConVar   sv_surface_calc_tile_color( "surface_calc_tile_color", "0", FCVAR_ARCHIVE, "Shows color of the tile" );
  350.  
  351. extern ConVar   mat_wireframe;
  352.  
  353. void C_NPC_Surface::GetRenderBounds( Vector& theMins, Vector& theMaxs )
  354. {
  355.     // BaseClass::GetRenderBounds( theMins, theMaxs );
  356.     if(sv_surface_testshape.GetBool())
  357.     {
  358.         theMins.Init(-300.0f, 0.0f, 100.0f);
  359.         theMaxs.Init(0.0f, 100.0f, 200.0f);
  360.     }
  361.     else
  362.     {
  363.         theMins = m_vecSurfacePos[0];
  364.         theMaxs = m_vecSurfacePos[0];
  365.         float surfaceRadius = m_flRadius * 3.0f;
  366.         for (int i = 0; i < m_nActiveParticles; i++)
  367.         {
  368.             VectorMin( m_vecSurfacePos[i] - Vector( surfaceRadius, surfaceRadius, surfaceRadius ), theMins, theMins );
  369.             VectorMax( m_vecSurfacePos[i] + Vector( surfaceRadius, surfaceRadius, surfaceRadius ), theMaxs, theMaxs );
  370.         }
  371.     }
  372.     theMins -= GetRenderOrigin();
  373.     theMaxs -= GetRenderOrigin();
  374.  
  375.     #if 0
  376.     Vector avg = (theMins + theMaxs) * 0.5f;
  377.     theMins = theMins - ((theMins - avg) * 0.75f);
  378.     theMaxs = theMaxs - ((theMaxs - avg) * 0.75f);
  379.     #endif
  380.  
  381.     #if 0
  382.     Vector fountainOrigin(-1980, -1792, 1);
  383.     theMins = fountainOrigin + Vector(-10, -10, -20);
  384.     theMaxs = fountainOrigin + Vector(10, 10, 50);
  385.     #endif
  386.  
  387.     // Msg( "origin  %.2f %.2f %.2f : mins %.2f %.2f %.2f  : maxs %.2f %.2f %.2f\n", GetRenderOrigin().x, GetRenderOrigin().y, GetRenderOrigin().z, theMins.x, theMins.y, theMins.z, theMaxs.x, theMaxs.y, theMaxs.z );
  388.  
  389.     //debugoverlay->AddBoxOverlay( GetRenderOrigin(), theMins, theMaxs, QAngle( 0, 0, 0 ), 0, 255, 0, 0, 0 );
  390. }
  391.  
  392. bool C_NPC_Surface::IsTransparent()
  393. {
  394.     // TODO: Fix this
  395.     return true;
  396. }
  397.  
  398. bool C_NPC_Surface::UsesPowerOfTwoFrameBufferTexture()
  399. {
  400.     if(!m_pMaterial) return false;
  401.     return m_pMaterial->NeedsPowerOfTwoFrameBufferTexture();
  402. }
  403.  
  404. bool C_NPC_Surface::UsesFullFrameBufferTexture()
  405. {
  406.     if(!m_pMaterial) return false;
  407.     return m_pMaterial->NeedsFullFrameBufferTexture();
  408. }
  409.  
  410. __forceinline float sqr(float a) { return a*a; }
  411.  
  412. Vector lastPoint0Pos;
  413.  
  414. int C_NPC_Surface::DrawModel( int flags )
  415. {
  416. #if !defined( _X360 ) // X360TBD: Enable blobulator for EP3
  417.  
  418.     if (sv_surface_wireframe.GetBool())
  419.     {
  420.         if(sv_surface_material.GetInt() == 0) {
  421.             m_pMaterial = materials->FindMaterial("shadertest/wireframe", TEXTURE_GROUP_OTHER);
  422.         } else {
  423.             m_pMaterial = materials->FindMaterial("shadertest/wireframevertexcolornocull", TEXTURE_GROUP_OTHER);
  424.         }
  425.     }
  426.     else if (strlen( sv_surface_shader.GetString() ) > 0)
  427.     {
  428.         m_pMaterial = materials->FindMaterial( sv_surface_shader.GetString(), TEXTURE_GROUP_OTHER, true );
  429.     }
  430.     else
  431.     {
  432.         if(sv_surface_material.GetInt() == 0) {
  433.             m_pMaterial = materials->FindMaterial( "models/debug/debugwhite", TEXTURE_GROUP_OTHER, true );
  434.         } else if(sv_surface_material.GetInt() == 1) {
  435.             m_pMaterial = materials->FindMaterial( "models/debug/debugwhite2", TEXTURE_GROUP_OTHER, true );
  436.         } else if(sv_surface_material.GetInt() == 2) {
  437.             m_pMaterial = materials->FindMaterial( "models/debug/debugwhite3", TEXTURE_GROUP_OTHER, true );
  438.         } else if(sv_surface_material.GetInt() == 3) {
  439.             m_pMaterial = materials->FindMaterial( "debug/debugvertexcolor", TEXTURE_GROUP_OTHER, true );
  440.         } else if(sv_surface_material.GetInt() == 4) {
  441.             m_pMaterial = materials->FindMaterial( "debug/env_cubemap_model", TEXTURE_GROUP_OTHER, true );
  442.         } else if(sv_surface_material.GetInt() == 5) {
  443.             m_pMaterial = materials->FindMaterial( "debug/env_cubemap_model_translucent_fountain", TEXTURE_GROUP_OTHER, true );
  444.         } else if(sv_surface_material.GetInt() == 6) {
  445.             m_pMaterial = materials->FindMaterial( "models/debug/debugmesh", TEXTURE_GROUP_OTHER, true );
  446.         } else if(sv_surface_material.GetInt() == 7) {
  447.             m_pMaterial = materials->FindMaterial( "models/debug/debugmesh_transparent", TEXTURE_GROUP_OTHER, true );
  448.         } else if(sv_surface_material.GetInt() == 8) {
  449.             m_pMaterial = materials->FindMaterial( "models/ihvtest/tongue_bumped", TEXTURE_GROUP_OTHER, true );
  450.         } else if(sv_surface_material.GetInt() == 9) {
  451.             m_pMaterial = materials->FindMaterial( "models/debug/debugbumps", TEXTURE_GROUP_OTHER, true );
  452.         } else if(sv_surface_material.GetInt() == 10) {
  453.             m_pMaterial = materials->FindMaterial( "debug/env_cubemap_model_translucent_no_bumps", TEXTURE_GROUP_OTHER, true );
  454.         } else {
  455.             //pMaterial = materials->FindMaterial( "effects/tp_refract", TEXTURE_GROUP_OTHER, true );
  456.             //m_pMaterial = materials->FindMaterial( "debug/debugrefract", TEXTURE_GROUP_OTHER, true );
  457.             //m_pMaterial = materials->FindMaterial( "shadertest/water_refract_only", TEXTURE_GROUP_OTHER, true );
  458.             //m_pMaterial = materials->FindMaterial( "nature/sewer_water001", TEXTURE_GROUP_OTHER, true );
  459.            
  460.             m_pMaterial = materials->FindMaterial( "models/shadertest/predator", TEXTURE_GROUP_OTHER, true );
  461.         }
  462.     }
  463.  
  464.     Vector fountainOrigin(-1980, -1792, 1);
  465.     if(sv_surface_fountain.GetBool())
  466.     {
  467.         modelrender->SetupLighting( fountainOrigin );
  468.     }
  469.     else
  470.     {
  471.         modelrender->SetupLighting( GetRenderOrigin() );
  472.         //modelrender->SetupLighting( Vector(0,0,300) );
  473.     }
  474.  
  475.  
  476.     #define MAX_EXTRA_ELEMENTS 400
  477.     static ImpParticle imp_particles[MAX_SURFACE_ELEMENTS + MAX_EXTRA_ELEMENTS]; // This doesn't specify alignment, might have problems with SSE
  478.     int n_particles = 0;
  479.  
  480.     if(sv_surface_testshape.GetBool())
  481.     {
  482.         for (int i = -10; i <= 10; i++)
  483.         {
  484.             ImpParticle* imp_particle = &imp_particles[i+10];
  485.             imp_particle->center.set(i*2.0f*m_flRadius, 0.0f, 0.0f);
  486.             n_particles++;
  487.         }
  488.     }
  489.     else
  490.     {
  491.         for (int i = 0 ; i < m_nActiveParticles; i++)
  492.         {
  493.             ImpParticle* imp_particle = &imp_particles[i];
  494.             imp_particle->center = m_vecSurfacePos[i];
  495.             imp_particle->setFieldScale( m_flSurfaceR[i] );
  496.             imp_particle->interpolants[3] = m_flSurfaceV[i];
  497.             n_particles++;
  498.         }
  499.  
  500.         // This code adds a water surface to the fountain trough
  501.         // using particles that oscillate up and down
  502.         if(sv_surface_fountain.GetBool())
  503.         {
  504.             static float time = 0.0f;
  505.            
  506.             bool paused = m_vecSurfacePos[0] == lastPoint0Pos;
  507.             lastPoint0Pos = m_vecSurfacePos[0]; //((CAI_BaseNPC::m_nDebugBits & bits_debugDisableAI) != 0);
  508.             if(!paused) time += 0.1f;
  509.  
  510.             for (int i = -7; i <= 7; i++)
  511.             for (int j = -7; j <= 7; j++)
  512.             {
  513.                     ImpParticle* imp_particle = &imp_particles[n_particles++];
  514.                     imp_particle->center = fountainOrigin + Vector(i * 2.0f * m_flRadius, j * 2.0f * m_flRadius, 15.0f);
  515.                     float dist = sqrtf(sqr(imp_particle->center[0]) + sqr(imp_particle->center[1]));
  516.                    
  517.                     imp_particle->center[2] += 2.0f*sin(2.0f*time + 2.0f*dist);
  518.                     imp_particle->setFieldScale( 1.0f );
  519.                     imp_particle->interpolants[3] = 0.0f;
  520.             }
  521.             for (int i = -2; i <= 2; i++)
  522.             for (int j = -2; j <= 2; j++)
  523.             {
  524.                     ImpParticle* imp_particle = &imp_particles[n_particles++];
  525.                     imp_particle->center = fountainOrigin + Vector(i * 2.0f * m_flRadius, j * 2.0f * m_flRadius, 15.0f - 2.0f * m_flRadius);
  526.                     imp_particle->setFieldScale( 1.0f );
  527.                     imp_particle->interpolants[3] = 0.0f;
  528.             }
  529.             ImpParticle* imp_particle = &imp_particles[n_particles++];
  530.             imp_particle->center = fountainOrigin + Vector(0.0f, 0.0f, 15.0f - 4.0f * m_flRadius);
  531.             imp_particle->setFieldScale( 1.0f );
  532.             imp_particle->interpolants[3] = 0.0f;
  533.         }
  534.     }
  535.  
  536.  
  537.  
  538.     if( !IsErrorMaterial( m_pMaterial ) )
  539.     {
  540.         if( !sv_surface_draw.GetBool())
  541.         {
  542.             Point3D eye = view->GetViewSetup()->origin;
  543.  
  544.             struct sortParticles_t
  545.             {
  546.                 int no;
  547.                 float dist;
  548.             };
  549.             class C
  550.             {
  551.             public:
  552.                 static bool gt(sortParticles_t a, sortParticles_t b)
  553.                 {
  554.                     return a.dist < b.dist;
  555.                 }
  556.             };
  557.             SmartArray<sortParticles_t> sort_particles;
  558.             sort_particles.ensureCapacity(n_particles);
  559.             sort_particles.size = n_particles;
  560.             for(int i = 0; i < n_particles; i++)
  561.             {
  562.                 sort_particles[i].no = i;
  563.                 sort_particles[i].dist = imp_particles[i].center.length(eye);
  564.             }
  565.             sort_particles.sort<C>();
  566.  
  567.             CMatRenderContextPtr pRenderContext( materials );
  568.            
  569.             pRenderContext->MatrixMode( MATERIAL_MODEL );
  570.             pRenderContext->Bind( m_pMaterial );
  571.  
  572.             IMesh* pMesh = pRenderContext->GetDynamicMesh( true );
  573.  
  574.             int vertMax = min( 24000 / 51, 32768 / (84 * 3) );
  575.  
  576.             int j = 0;
  577.             // Msg( "point %.2f %.2f %.2f\n", m_vecSurfacePos[0].x, m_vecSurfacePos[0].y, m_vecSurfacePos[0].z );
  578.             while (j < n_particles)
  579.             {
  580.                 int total = min( n_particles - j, vertMax );
  581.  
  582.                 CMeshBuilder meshBuilder;
  583.                 meshBuilder.Begin( pMesh, MATERIAL_TRIANGLES, total * 51, total * 84 * 3 );
  584.  
  585.                 int i = 0;
  586.                 while (i < vertMax && j < n_particles)
  587.                 {
  588.                     ImpParticle* imp_particle = &imp_particles[sort_particles[j].no];
  589.                     if (imp_particle->scale > 0.01)
  590.                     {
  591.                         DrawFastSphere( meshBuilder, imp_particle->center.AsVector(), m_flRadius * imp_particle->scale, 255, 255, 255 );
  592.                         i++;
  593.                     }
  594.                     j++;
  595.                 }
  596.  
  597.                 meshBuilder.End();
  598.                 pMesh->Draw();
  599.             }
  600.         }
  601.         else
  602.         {
  603.             // Note: it is not good to have these static variables here.
  604.             static RENDERER_CLASS* sweepRenderer = NULL;
  605.             static ImpTiler* tiler = NULL;
  606.  
  607.             if(!sweepRenderer)
  608.             {
  609.                 sweepRenderer = new RENDERER_CLASS();
  610.                 tiler = new ImpTiler(sweepRenderer);
  611.             }
  612.  
  613.             tiler->setMaxNoTilesToDraw(sv_surface_max_tiles.GetInt());
  614.             sweepRenderer->setMaxNoSlicesToDraw(sv_surface_max_slices.GetInt());
  615.  
  616.             RENDERER_CLASS::setCubeWidth(sv_blr_cubewidth.GetFloat());
  617.             RENDERER_CLASS::setRenderR(sv_blr_render_radius.GetFloat());
  618.             RENDERER_CLASS::setCutoffR(sv_blr_cutoff_radius.GetFloat());
  619.  
  620.             if(sv_surface_calc_uv_and_tan.GetBool())
  621.             {
  622.                 RENDERER_CLASS::setCalcSignFunc(calcSign);
  623.                 RENDERER_CLASS::setCalcSign2Func(calcSign2);
  624.                 RENDERER_CLASS::setCalcCornerFunc(calcCornerNormalColorUVTan);
  625.                 RENDERER_CLASS::setCalcVertexFunc(calcVertexNormalNColorUVTan);
  626.             }
  627.             else if(sv_surface_calc_tan_only.GetBool())
  628.             {
  629.                 RENDERER_CLASS::setCalcSignFunc(calcSign);
  630.                 RENDERER_CLASS::setCalcSign2Func(calcSign2);
  631.                 RENDERER_CLASS::setCalcCornerFunc(calcCornerNormalColorTanNoUV);
  632.                 RENDERER_CLASS::setCalcVertexFunc(calcVertexNormalNColorTanNoUV);
  633.             }
  634.             else if (sv_surface_calc_color.GetBool())
  635.             {
  636.                 RENDERER_CLASS::setCalcSignFunc(calcSign);
  637.                 RENDERER_CLASS::setCalcSign2Func(calcSign2);
  638.                 RENDERER_CLASS::setCalcCornerFunc(calcCornerNormalColor);
  639.                 RENDERER_CLASS::setCalcVertexFunc(calcVertexNormalNColor);
  640.             }
  641.             else if (sv_surface_calc_hifreq_color.GetBool())
  642.             {
  643.                 RENDERER_CLASS::setCalcSignFunc(calcSign);
  644.                 RENDERER_CLASS::setCalcSign2Func(calcSign2);
  645.                 RENDERER_CLASS::setCalcCornerFunc(calcCornerNormalHiFreqColor);
  646.                 RENDERER_CLASS::setCalcVertexFunc(calcVertexNormalNColor);
  647.             }
  648.             else if (sv_surface_calc_tile_color.GetBool())
  649.             {
  650.                 RENDERER_CLASS::setCalcSignFunc(calcSign);
  651.                 RENDERER_CLASS::setCalcSign2Func(calcSign2);
  652.                 RENDERER_CLASS::setCalcCornerFunc(calcCornerNormal);
  653.                 RENDERER_CLASS::setCalcVertexFunc(calcVertexNormalDebugColor);
  654.             }
  655.             else
  656.             {
  657.                 RENDERER_CLASS::setCalcSignFunc(calcSign);
  658.                 RENDERER_CLASS::setCalcSign2Func(calcSign2);
  659.                 RENDERER_CLASS::setCalcCornerFunc(calcCornerNormal);
  660.                 RENDERER_CLASS::setCalcVertexFunc(calcVertexNormal);
  661.             }
  662.                
  663.  
  664.             Vector center;
  665.             if(sv_surface_testshape.GetBool())
  666.             {
  667.                 center.Init(); // set center to 0,0,0
  668.             }
  669.             else if(sv_surface_fountain.GetBool())
  670.             {
  671.                 center = fountainOrigin;
  672.             }
  673.             else
  674.             {
  675.                 center.Init();
  676.  
  677.                 if(sv_surface_center.GetBool())
  678.                 {
  679.                     for(int i = 0; i < m_nActiveParticles; i++)
  680.                     {
  681.                         center += m_vecSurfacePos[i];
  682.                     }
  683.                     center /= m_nActiveParticles;
  684.                 }
  685.             }
  686.  
  687.             Vector transformedCenter = center * (1.0f/m_flRadius);
  688.  
  689.             CMatRenderContextPtr pRenderContext( materials );
  690.             pRenderContext->MatrixMode( MATERIAL_MODEL );
  691.             pRenderContext->Bind( m_pMaterial );
  692.             pRenderContext->PushMatrix();
  693.             pRenderContext->LoadIdentity();
  694.  
  695.             if(sv_surface_testshape.GetBool())
  696.             {
  697.                 pRenderContext->Translate(-150.0f, 50.0f, 150.0f);
  698.             }
  699.             else
  700.             {
  701.                 pRenderContext->Translate(center.x, center.y, center.z);
  702.             }
  703.  
  704.             pRenderContext->Scale(m_flRadius, m_flRadius, m_flRadius);
  705.  
  706.             VMatrix rotationMatrix;
  707.             VMatrix invRotationMatrix;
  708.             Vector transformedEye;
  709.             float angle = 0.0f;
  710.             if(sv_surface_rotate.GetBool())
  711.             {
  712.                 angle = view->GetViewSetup()->angles.y+180.0f;
  713.  
  714.                 //ConMsg("Angle = %f\n", angle);
  715.                 pRenderContext->Rotate(angle, 0.0f, 0.0f, 1.0f);
  716.  
  717.                 //VMatrix rotationMatrix2 = SetupMatrixAngles(view->GetViewSetup()->angles);
  718.                 //pRenderContext->MultMatrix(rotationMatrix2);
  719.                 //VMatrix rotationMatrix = rotationMatrix2.InverseTR(); //SetupMatrixAngles(-(view->GetViewSetup()->angles));
  720.  
  721.                 rotationMatrix = SetupMatrixAxisRot(Vector(0.0f, 0.0f, 1.0f), -angle);
  722.                 invRotationMatrix = SetupMatrixAxisRot(Vector(0.0f, 0.0f, 1.0f), angle);
  723.                 Vector eye = view->GetViewSetup()->origin;
  724.                 transformedEye = (eye-center)*(1.0f/m_flRadius);
  725.                 transformedEye = rotationMatrix.ApplyRotation(transformedEye);
  726.             }
  727.             else
  728.             {
  729.                 rotationMatrix.Identity();
  730.                 invRotationMatrix.Identity();
  731.                 transformedEye.Init();
  732.                 angle = 0.0f;
  733.             }
  734.  
  735.             if(sv_surface_use_tiler.GetBool())
  736.             {
  737.                 tiler->beginFrame(Point3D(0.0f, 0.0f, 0.0f), (void*)&pRenderContext, !(sv_surface_draw_margin.GetBool()));
  738.             }
  739.             else
  740.             {
  741.                 sweepRenderer->beginFrame(!(sv_surface_draw_margin.GetBool()), (void*)&pRenderContext);
  742.                 sweepRenderer->setOffset(Point3D(0.0f, 0.0f, 0.0f));
  743.                 //sweepRenderer->beginTile();
  744.             }
  745.  
  746.             for (int i = 0 ; i < n_particles; i++)
  747.             {
  748.                 ImpParticle* imp_particle = &imp_particles[i];
  749.                 if(imp_particle->scale <= 0.1f) continue;
  750.  
  751.                 Vector vParticle = imp_particle->center.AsVector();
  752.                 //vParticle.Init(imp_particle->center[0], imp_particle->center[1], imp_particle->center[2]);
  753.                 Vector transformedParticle = (vParticle-center) * (1.0f/m_flRadius);
  754.  
  755.                 if(sv_surface_rotate.GetBool())
  756.                 {
  757.                     transformedParticle = rotationMatrix.ApplyRotation(transformedParticle);
  758.                 }
  759.  
  760.                 Point3D pParticle = transformedParticle;
  761.                 Point3D pCenter = transformedCenter;
  762.                 Point3D vec = (pParticle - pCenter);
  763.  
  764.                 imp_particle->center = pParticle;
  765.                 //imp_particle->setFieldScale( max(1.2f - vec.length()/30.0f, 0.25f) );
  766.  
  767.                 // interpolants[0..2] is the color. interpolants[3] is the v coordinate
  768.                 // imp_particle->interpolants[3] = min(max(1.4f - vec.length()/17.0f, 0.0f), 1.0f);
  769.                 // interpolants2[0..2] is the tangent vector.
  770.                 // interpolants3[0..2] and interpolants4[0..2] are the normal and
  771.                 // binormal which are used to generate a u coordinate
  772.                 imp_particle->interpolants2 = vec.unit();
  773.                 imp_particle->interpolants4.set(0.0f, 0.0f, -1.0f);
  774.                 imp_particle->interpolants3 = imp_particle->interpolants2.crossProduct(imp_particle->interpolants4);
  775.                 imp_particle->interpolants3.normalize();
  776.                 imp_particle->interpolants4 = imp_particle->interpolants2.crossProduct(imp_particle->interpolants3);
  777.                 imp_particle->interpolants4.normalize();
  778.                
  779.                 if(sv_surface_use_tiler.GetBool())
  780.                 {
  781.                     tiler->insertParticle(imp_particle);
  782.                 }
  783.                 else
  784.                 {
  785.                     sweepRenderer->addParticle(imp_particle);
  786.                 }
  787.             }
  788.  
  789.             if(sv_surface_use_tiler.GetBool())
  790.             {
  791.                 if(sv_surface_tile.GetBool())
  792.                 {
  793.                     if(sv_surface_rotate.GetBool())
  794.                     {
  795.                         tiler->drawSurfaceSorted(Point3D(transformedEye));
  796.                     }
  797.                     else
  798.                     {
  799.                         tiler->drawSurface();
  800.                     }
  801.                 }
  802.                 else
  803.                 {
  804.                     tiler->drawTile(0,0,0);
  805.                 }
  806.                 tiler->endFrame();
  807.             }
  808.             else
  809.             {
  810.                 sweepRenderer->endTile();
  811.                 sweepRenderer->endFrame();
  812.             }
  813.  
  814.             if(sv_surface_max_tiles.GetInt() > 0 || sv_surface_tile.GetBool()==false)
  815.             {
  816.                 //debugoverlay->AddBoxOverlay( fountainOrigin, Vector(-30, -30, -30), Vector(30, 30, 30), QAngle( 0, 0, 0 ), 0, 255, 0, 0, 0 );
  817.                 Vector overlayCenter = invRotationMatrix.ApplyRotation(tiler->getLastTilesOffset().AsVector() * m_flRadius);
  818.                 Vector mins = (tiler->getRenderDim() * (-0.5f* m_flRadius)).AsVector();
  819.                 Vector maxs = (tiler->getRenderDim() * (0.5f*m_flRadius)).AsVector();
  820.                 debugoverlay->AddBoxOverlay( overlayCenter + fountainOrigin, mins, maxs, QAngle( 0, angle, 0 ), 0, 255, 0, 0, 0 );
  821.  
  822.                 if(sv_surface_max_slices.GetInt() > 0)
  823.                 {
  824.                     Vector sliceMins = mins;
  825.                     Vector sliceMaxs = maxs;
  826.                     sliceMins.x += (sweepRenderer->getLastSliceDrawn() - sweepRenderer->getMarginNCubes()) * sweepRenderer->getCubeWidth() * m_flRadius;
  827.                     sliceMaxs.x = sliceMins.x + sweepRenderer->getCubeWidth() * m_flRadius;
  828.                    
  829.                     debugoverlay->AddBoxOverlay( overlayCenter + fountainOrigin, sliceMins, sliceMaxs, QAngle( 0, angle, 0 ), 255, 0, 0, 0, 0 );
  830.                 }
  831.             }
  832.  
  833.             pRenderContext->PopMatrix();
  834.         }
  835.     }
  836.  
  837.     #endif // !_X360
  838.  
  839.     return 1;
  840. }
  841.  
  842. //-----------------------------------------------------------------------------
  843. // Purpose: move the sound source to a point near the player
  844. //-----------------------------------------------------------------------------
  845.  
  846. bool C_NPC_Surface::GetSoundSpatialization( SpatializationInfo_t& info )
  847. {
  848.     bool bret = BaseClass::GetSoundSpatialization( info );
  849.     // Default things it's audible, put it at a better spot?
  850.     if ( bret )
  851.     {
  852.         // TODO:  Note, this is where you could override the sound position and orientation and use
  853.         //  an attachment points position as the sound source
  854.         // You might have to issue C_BaseAnimating::AllowBoneAccess( true, false ); to allow
  855.         //  bone setup during sound spatialization if you run into asserts...
  856.     }
  857.  
  858.     return bret;
  859. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement