mirror of
https://github.com/alliedmodders/hl2sdk.git
synced 2024-12-23 01:59:43 +08:00
198 lines
4.9 KiB
C++
198 lines
4.9 KiB
C++
//====== Copyright © 1996-2003, Valve Corporation, All rights reserved. =======
|
|
//
|
|
// Purpose:
|
|
//
|
|
//=============================================================================
|
|
|
|
#include "cbase.h"
|
|
#include "shareddefs.h"
|
|
#include "materialsystem/imesh.h"
|
|
#include "materialsystem/imaterial.h"
|
|
#include "view.h"
|
|
#include "iviewrender.h"
|
|
#include "view_shared.h"
|
|
#include "texture_group_names.h"
|
|
#include "vstdlib/icommandline.h"
|
|
|
|
// memdbgon must be the last include file in a .cpp file!!!
|
|
#include "tier0/memdbgon.h"
|
|
|
|
//-----------------------------------------------------------------------------
|
|
// Purpose:
|
|
//-----------------------------------------------------------------------------
|
|
class C_EnvProjectedTexture : public C_BaseEntity
|
|
{
|
|
DECLARE_CLASS( C_EnvProjectedTexture, C_BaseEntity );
|
|
public:
|
|
DECLARE_CLIENTCLASS();
|
|
|
|
virtual void OnDataChanged( DataUpdateType_t updateType );
|
|
void ShutDownLightHandle( void );
|
|
|
|
virtual void Simulate();
|
|
|
|
void UpdateLight( bool bForceUpdate );
|
|
|
|
C_EnvProjectedTexture();
|
|
~C_EnvProjectedTexture();
|
|
|
|
private:
|
|
|
|
ClientShadowHandle_t m_LightHandle;
|
|
|
|
EHANDLE m_hTargetEntity;
|
|
|
|
bool m_bState;
|
|
float m_flLightFOV;
|
|
bool m_bEnableShadows;
|
|
bool m_bLightOnlyTarget;
|
|
bool m_bLightWorld;
|
|
bool m_bCameraSpace;
|
|
color32 m_cLightColor;
|
|
};
|
|
|
|
IMPLEMENT_CLIENTCLASS_DT( C_EnvProjectedTexture, DT_EnvProjectedTexture, CEnvProjectedTexture )
|
|
RecvPropEHandle( RECVINFO( m_hTargetEntity ) ),
|
|
RecvPropBool( RECVINFO( m_bState ) ),
|
|
RecvPropFloat( RECVINFO( m_flLightFOV ) ),
|
|
RecvPropBool( RECVINFO( m_bEnableShadows ) ),
|
|
RecvPropBool( RECVINFO( m_bLightOnlyTarget ) ),
|
|
RecvPropBool( RECVINFO( m_bLightWorld ) ),
|
|
RecvPropBool( RECVINFO( m_bCameraSpace ) ),
|
|
RecvPropInt( RECVINFO( m_cLightColor ) ),
|
|
END_RECV_TABLE()
|
|
|
|
C_EnvProjectedTexture::C_EnvProjectedTexture( void )
|
|
{
|
|
m_LightHandle = CLIENTSHADOW_INVALID_HANDLE;
|
|
}
|
|
|
|
C_EnvProjectedTexture::~C_EnvProjectedTexture( void )
|
|
{
|
|
ShutDownLightHandle();
|
|
}
|
|
|
|
void C_EnvProjectedTexture::ShutDownLightHandle( void )
|
|
{
|
|
// Clear out the light
|
|
if( m_LightHandle != CLIENTSHADOW_INVALID_HANDLE )
|
|
{
|
|
g_pClientShadowMgr->DestroyFlashlight( m_LightHandle );
|
|
m_LightHandle = CLIENTSHADOW_INVALID_HANDLE;
|
|
}
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
// Purpose:
|
|
// Input : updateType -
|
|
//-----------------------------------------------------------------------------
|
|
void C_EnvProjectedTexture::OnDataChanged( DataUpdateType_t updateType )
|
|
{
|
|
UpdateLight( true );
|
|
BaseClass::OnDataChanged( updateType );
|
|
}
|
|
|
|
void C_EnvProjectedTexture::UpdateLight( bool bForceUpdate )
|
|
{
|
|
if ( m_bState == false )
|
|
{
|
|
if ( m_LightHandle != CLIENTSHADOW_INVALID_HANDLE )
|
|
{
|
|
ShutDownLightHandle();
|
|
}
|
|
|
|
return;
|
|
}
|
|
|
|
Vector vPos = GetAbsOrigin();
|
|
Vector vForward;
|
|
FlashlightState_t state;
|
|
|
|
if ( m_hTargetEntity != NULL )
|
|
{
|
|
if ( m_bCameraSpace )
|
|
{
|
|
const QAngle &angles = GetLocalAngles();
|
|
|
|
C_BasePlayer *pPlayer = C_BasePlayer::GetLocalPlayer();
|
|
if( pPlayer )
|
|
{
|
|
const QAngle playerAngles = pPlayer->GetAbsAngles();
|
|
|
|
Vector vPlayerForward;
|
|
AngleVectors( playerAngles, &vPlayerForward );
|
|
|
|
matrix3x4_t mRotMatrix;
|
|
AngleMatrix( angles, mRotMatrix );
|
|
|
|
VectorTransform( vPlayerForward, mRotMatrix, vForward );
|
|
|
|
float dist = (m_hTargetEntity->GetAbsOrigin() - GetAbsOrigin()).Length();
|
|
vPos = m_hTargetEntity->GetAbsOrigin() - vForward*dist;
|
|
|
|
VectorNormalize( vForward );
|
|
}
|
|
}
|
|
else
|
|
{
|
|
vForward = m_hTargetEntity->GetAbsOrigin() - GetAbsOrigin();
|
|
VectorNormalize( vForward );
|
|
}
|
|
}
|
|
else
|
|
{
|
|
AngleVectors( GetAbsAngles(), &vForward );
|
|
}
|
|
|
|
state.m_fHorizontalFOVDegrees = m_flLightFOV;
|
|
state.m_fVerticalFOVDegrees = m_flLightFOV;
|
|
|
|
state.m_vecLightOrigin = vPos;
|
|
state.m_vecLightDirection = vForward;
|
|
|
|
state.m_fQuadraticAtten = 0.0;
|
|
state.m_fLinearAtten = 100;
|
|
state.m_fConstantAtten = 0.0f;
|
|
state.m_Color.Init( (float)m_cLightColor.r/255.0f, (float)m_cLightColor.g/255.0f, (float)m_cLightColor.b/255.0f );
|
|
state.m_NearZ = 1.0f;
|
|
state.m_FarZ = 750;
|
|
|
|
state.m_bEnableShadows = m_bEnableShadows;
|
|
|
|
if( m_LightHandle == CLIENTSHADOW_INVALID_HANDLE )
|
|
{
|
|
m_LightHandle = g_pClientShadowMgr->CreateFlashlight( state );
|
|
}
|
|
else
|
|
{
|
|
if ( m_hTargetEntity != NULL || bForceUpdate == true )
|
|
{
|
|
g_pClientShadowMgr->UpdateFlashlightState( m_LightHandle, state );
|
|
}
|
|
}
|
|
|
|
if( m_bLightOnlyTarget )
|
|
{
|
|
g_pClientShadowMgr->SetFlashlightTarget( m_LightHandle, m_hTargetEntity );
|
|
}
|
|
else
|
|
{
|
|
g_pClientShadowMgr->SetFlashlightTarget( m_LightHandle, NULL );
|
|
}
|
|
|
|
g_pClientShadowMgr->SetFlashlightLightWorld( m_LightHandle, m_bLightWorld );
|
|
|
|
if ( bForceUpdate == false )
|
|
{
|
|
g_pClientShadowMgr->UpdateProjectedTexture( m_LightHandle, true );
|
|
}
|
|
}
|
|
|
|
void C_EnvProjectedTexture::Simulate( void )
|
|
{
|
|
UpdateLight( false );
|
|
|
|
BaseClass::Simulate();
|
|
}
|
|
|