psy_commando

c_prop_sfr_vehicle.cpp

Apr 28th, 2012
260
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 7.54 KB | None | 0 0
  1. #include "cbase.h"
  2. #include "c_prop_sfr_vehicle.h"
  3. #include "vehicle_viewblend_shared.h"
  4.  
  5. extern ConVar joy_response_move_vehicle;
  6.  
  7. void RecvProxy_SFRVehicle_LocalVelocityX( const CRecvProxyData *pData, void *pStruct, void *pOut )
  8. {
  9.     C_PropSFRVehicle *pVehicle = (C_PropSFRVehicle *) pStruct;
  10.  
  11.     Assert( pVehicle );
  12.  
  13.     float flNewVel_x = pData->m_Value.m_Float;
  14.    
  15.     Vector vecVelocity = pVehicle->GetLocalVelocity(); 
  16.  
  17.     if( vecVelocity.x != flNewVel_x )   // Should this use an epsilon check?
  18.     {
  19.         //if (vecVelocity.x > 30.0f)
  20.         //{
  21.            
  22.         //}    
  23.         vecVelocity.x = flNewVel_x;
  24.         pVehicle->SetLocalVelocity( vecVelocity );
  25.     }
  26. }
  27.  
  28. void RecvProxy_SFRVehicle_LocalVelocityY( const CRecvProxyData *pData, void *pStruct, void *pOut )
  29. {
  30.     C_PropSFRVehicle *pVehicle = (C_PropSFRVehicle *) pStruct;
  31.  
  32.     Assert( pVehicle );
  33.  
  34.     float flNewVel_y = pData->m_Value.m_Float;
  35.  
  36.     Vector vecVelocity = pVehicle->GetLocalVelocity();
  37.  
  38.     if( vecVelocity.y != flNewVel_y )
  39.     {
  40.         vecVelocity.y = flNewVel_y;
  41.         pVehicle->SetLocalVelocity( vecVelocity );
  42.     }
  43. }
  44.  
  45. void RecvProxy_SFRVehicle_LocalVelocityZ( const CRecvProxyData *pData, void *pStruct, void *pOut )
  46. {
  47.     C_PropSFRVehicle *pVehicle = (C_PropSFRVehicle *) pStruct;
  48.    
  49.     Assert( pVehicle );
  50.  
  51.     float flNewVel_z = pData->m_Value.m_Float;
  52.  
  53.     Vector vecVelocity = pVehicle->GetLocalVelocity();
  54.  
  55.     if( vecVelocity.z != flNewVel_z )
  56.     {
  57.         vecVelocity.z = flNewVel_z;
  58.         pVehicle->SetLocalVelocity( vecVelocity );
  59.     }
  60. }
  61.  
  62.  
  63. IMPLEMENT_CLIENTCLASS_DT(C_PropSFRVehicle, DT_PropSFRVehicle, CPropSFRVehicle)
  64.     RecvPropEHandle( RECVINFO(m_hPlayer) ),
  65.    RecvPropBool( RECVINFO( m_bIsOn ) ),
  66.  
  67.     RecvPropVectorXY( RECVINFO_NAME( m_vecNetworkOrigin, m_vecOrigin ), 0, C_BasePlayer::RecvProxy_LocalOriginXY ),
  68.     RecvPropFloat( RECVINFO_NAME( m_vecNetworkOrigin[2], m_vecOrigin[2] ), 0, C_BasePlayer::RecvProxy_LocalOriginZ ),
  69.  
  70.     RecvPropFloat       ( RECVINFO( m_vecVelocity[0] ), 0, RecvProxy_SFRVehicle_LocalVelocityX ),
  71.     RecvPropFloat       ( RECVINFO( m_vecVelocity[1] ), 0, RecvProxy_SFRVehicle_LocalVelocityY ),
  72.     RecvPropFloat       ( RECVINFO( m_vecVelocity[2] ), 0, RecvProxy_SFRVehicle_LocalVelocityZ ),
  73.  
  74.     //RecvPropFloat( RECVINFO_NAME( m_angNetworkAngles[0], m_angRotation[0] ) ),
  75.     //RecvPropFloat( RECVINFO_NAME( m_angNetworkAngles[1], m_angRotation[1] ) ),
  76.     //RecvPropFloat( RECVINFO_NAME( m_angNetworkAngles[2], m_angRotation[2] ) ),
  77. END_RECV_TABLE();
  78.  
  79.  
  80. C_PropSFRVehicle::C_PropSFRVehicle()
  81. {
  82. }
  83.  
  84. //-----------------------------------------------------------------------------
  85. // By default all driveable vehicles use the curve defined by the convar.
  86. //-----------------------------------------------------------------------------
  87. int C_PropSFRVehicle::GetJoystickResponseCurve() const
  88. {
  89.     return joy_response_move_vehicle.GetInt();
  90. }
  91.  
  92.  
  93. //-----------------------------------------------------------------------------
  94. // Purpose:
  95. //-----------------------------------------------------------------------------
  96. C_BaseCombatCharacter *C_PropSFRVehicle::GetPassenger( int nRole )
  97. {
  98.     if ( nRole == VEHICLE_ROLE_DRIVER )
  99.         return m_hPlayer.Get();
  100.  
  101.     return NULL;
  102. }
  103.  
  104. //-----------------------------------------------------------------------------
  105. // Returns the role of the passenger
  106. //-----------------------------------------------------------------------------
  107. int C_PropSFRVehicle::GetPassengerRole( C_BaseCombatCharacter *pPassenger )
  108. {
  109.     if ( m_hPlayer.Get() == pPassenger )
  110.         return VEHICLE_ROLE_DRIVER;
  111.  
  112.     return VEHICLE_ROLE_NONE;
  113. }
  114.  
  115. //-----------------------------------------------------------------------------
  116. // Should this object cast render-to-texture shadows?
  117. //-----------------------------------------------------------------------------
  118. ShadowType_t C_PropSFRVehicle::ShadowCastType()
  119. {
  120.     CStudioHdr *pStudioHdr = GetModelPtr();
  121.     if ( !pStudioHdr )
  122.         return SHADOWS_NONE;
  123.  
  124.     if ( IsEffectActive(EF_NODRAW | EF_NOSHADOW) )
  125.         return SHADOWS_NONE;
  126.  
  127.     // Always use render-to-texture. We'll always the dirty bits in our think function
  128.     return SHADOWS_RENDER_TO_TEXTURE;
  129. }
  130.  
  131. //-----------------------------------------------------------------------------
  132. // Mark the shadow as dirty while the vehicle is being driven
  133. //-----------------------------------------------------------------------------
  134. void  C_PropSFRVehicle::ClientThink()
  135. {
  136.     // The vehicle is always dirty owing to pose parameters while it's being driven.
  137.     g_pClientShadowMgr->MarkRenderToTextureShadowDirty( GetShadowHandle() );
  138. }
  139.  
  140. //-----------------------------------------------------------------------------
  141. // Futzes with the clip planes
  142. //-----------------------------------------------------------------------------
  143. void C_PropSFRVehicle::GetVehicleClipPlanes( float &flZNear, float &flZFar ) const
  144. {
  145.     // FIXME: Need something a better long-term, this fixes the buggy.
  146.     flZNear = 1;
  147. }
  148.  
  149. //-----------------------------------------------------------------------------
  150. // Purpose:
  151. //-----------------------------------------------------------------------------
  152. void C_PropSFRVehicle::UpdateViewAngles( C_BasePlayer *pLocalPlayer, CUserCmd *pCmd )
  153. {
  154. }
  155.  
  156. void C_PropSFRVehicle::GetVehicleViewPosition( int nRole, Vector *pOrigin, QAngle *pAngles, float *pFOV )
  157. {
  158.     Vector forward(0,0,0), right(0,0,0), up(0,0,0);
  159.     GetVectors( &forward, &right, &up );
  160.  
  161.     if( pOrigin != 0 )
  162.     {
  163.        *pOrigin = GetAbsOrigin();
  164.     }
  165.  
  166.  
  167.     if( pAngles != 0 )
  168.     {
  169.        *pAngles = GetAbsAngles();
  170.     }
  171.  
  172.     if( pFOV != 0 )
  173.     {
  174.        GetVehicleFOV( (*pFOV) );
  175.     }
  176. }
  177.  
  178. //-----------------------------------------------------------------------------
  179. // Renders hud elements
  180. //-----------------------------------------------------------------------------
  181. void C_PropSFRVehicle::DrawHudElements( )
  182. {
  183. }
  184.  
  185. //-----------------------------------------------------------------------------
  186. // Purpose:
  187. //-----------------------------------------------------------------------------
  188. void C_PropSFRVehicle::OnEnteredVehicle( C_BaseCombatCharacter *pPassenger )
  189. {
  190. }
  191.  
  192. #define ROLL_CURVE_ZERO     20      // roll less than this is clamped to zero
  193. #define ROLL_CURVE_LINEAR   90      // roll greater than this is copied out
  194.  
  195. #define PITCH_CURVE_ZERO        10  // pitch less than this is clamped to zero
  196. #define PITCH_CURVE_LINEAR      45  // pitch greater than this is copied out
  197.                                     // spline in between
  198.  
  199. //=============================================================================
  200. //C_PropSFRVehicleWithViewSmoothing
  201. //=============================================================================
  202.  
  203. BEGIN_DATADESC(C_PropSFRVehicleWithViewSmoothing)
  204.    DEFINE_EMBEDDED( m_ViewSmoothingData ),
  205. END_DATADESC();
  206.  
  207.  
  208. C_PropSFRVehicleWithViewSmoothing::C_PropSFRVehicleWithViewSmoothing()
  209. {
  210.     memset( &m_ViewSmoothingData, 0, sizeof( m_ViewSmoothingData ) );
  211.  
  212.     m_ViewSmoothingData.pVehicle = this;
  213.     m_ViewSmoothingData.bClampEyeAngles = true;
  214.     m_ViewSmoothingData.bDampenEyePosition = true;
  215.  
  216.     m_ViewSmoothingData.flPitchCurveZero = PITCH_CURVE_ZERO;
  217.     m_ViewSmoothingData.flPitchCurveLinear = PITCH_CURVE_LINEAR;
  218.     m_ViewSmoothingData.flRollCurveZero = ROLL_CURVE_ZERO;
  219.     m_ViewSmoothingData.flRollCurveLinear = ROLL_CURVE_LINEAR;
  220.  
  221.     m_ViewSmoothingData.flFOV = 75.0;
  222. }
  223.  
  224. void C_PropSFRVehicleWithViewSmoothing::GetVehicleViewPosition( int nRole, Vector *pOrigin, QAngle *pAngles, float *pFOV )
  225. {
  226.     SFRSharedVehicleViewSmoothing( m_hPlayer,
  227.                                 pOrigin, pAngles,
  228.                                 false, false,
  229.                                 GetAbsOrigin(),
  230.                                 &m_ViewSmoothingData,
  231.                                 pFOV );
  232. }
  233.  
  234. void C_PropSFRVehicleWithViewSmoothing::DampenEyePosition( Vector &vecVehicleEyePos, QAngle &vecVehicleEyeAngles )
  235. {
  236. }
Advertisement
Add Comment
Please, Sign In to add comment