diff options
| author | Joe Ludwig <[email protected]> | 2013-06-26 15:22:04 -0700 |
|---|---|---|
| committer | Joe Ludwig <[email protected]> | 2013-06-26 15:22:04 -0700 |
| commit | 39ed87570bdb2f86969d4be821c94b722dc71179 (patch) | |
| tree | abc53757f75f40c80278e87650ea92808274aa59 /mp/src/game/client/matrixproxy.cpp | |
| download | source-sdk-2013-39ed87570bdb2f86969d4be821c94b722dc71179.tar.xz source-sdk-2013-39ed87570bdb2f86969d4be821c94b722dc71179.zip | |
First version of the SOurce SDK 2013
Diffstat (limited to 'mp/src/game/client/matrixproxy.cpp')
| -rw-r--r-- | mp/src/game/client/matrixproxy.cpp | 182 |
1 files changed, 182 insertions, 0 deletions
diff --git a/mp/src/game/client/matrixproxy.cpp b/mp/src/game/client/matrixproxy.cpp new file mode 100644 index 00000000..3dff3069 --- /dev/null +++ b/mp/src/game/client/matrixproxy.cpp @@ -0,0 +1,182 @@ +//========= Copyright Valve Corporation, All rights reserved. ============//
+//
+// Purpose:
+//
+// $NoKeywords: $
+//=============================================================================//
+#include "cbase.h"
+#include "mathlib/vmatrix.h"
+#include "functionproxy.h"
+#include "materialsystem/imaterialvar.h"
+#include <KeyValues.h>
+#include "materialsystem/imaterial.h"
+#include "toolframework_client.h"
+
+// memdbgon must be the last include file in a .cpp file!!!
+#include "tier0/memdbgon.h"
+
+// forward declarations
+void ToolFramework_RecordMaterialParams( IMaterial *pMaterial );
+
+class C_BaseEntity;
+
+//-----------------------------------------------------------------------------
+// Texture transform proxy
+//-----------------------------------------------------------------------------
+class CTextureTransformProxy : public CResultProxy
+{
+public:
+ bool Init( IMaterial *pMaterial, KeyValues *pKeyValues );
+ void OnBind( void *pC_BaseEntity );
+
+private:
+ IMaterialVar *m_pCenterVar;
+ IMaterialVar *m_pScaleVar;
+ IMaterialVar *m_pRotateVar;
+ IMaterialVar *m_pTranslateVar;
+};
+
+bool CTextureTransformProxy::Init( IMaterial *pMaterial, KeyValues *pKeyValues )
+{
+ // All are optional...
+ m_pCenterVar = NULL;
+ m_pScaleVar = NULL;
+ m_pRotateVar = NULL;
+ m_pTranslateVar = NULL;
+
+ bool bFoundVar;
+ char const* pVarName = pKeyValues->GetString( "centerVar" );
+ if( pVarName && pVarName[0] )
+ {
+ m_pCenterVar = pMaterial->FindVar( pVarName, &bFoundVar, false );
+ }
+
+ pVarName = pKeyValues->GetString( "scaleVar" );
+ if( pVarName && pVarName[0] )
+ {
+ m_pScaleVar = pMaterial->FindVar( pVarName, &bFoundVar, false );
+ }
+
+ pVarName = pKeyValues->GetString( "rotateVar" );
+ if( pVarName && pVarName[0] )
+ {
+ m_pRotateVar = pMaterial->FindVar( pVarName, &bFoundVar, false );
+ }
+
+ pVarName = pKeyValues->GetString( "translateVar" );
+ if( pVarName && pVarName[0] )
+ {
+ m_pTranslateVar = pMaterial->FindVar( pVarName, &bFoundVar, false );
+ }
+
+ return CResultProxy::Init( pMaterial, pKeyValues );
+}
+
+void CTextureTransformProxy::OnBind( void *pC_BaseEntity )
+{
+ Vector2D center( 0.5, 0.5 );
+ Vector2D translation( 0, 0 );
+
+ VMatrix mat, temp;
+
+ if (m_pCenterVar)
+ {
+ m_pCenterVar->GetVecValue( center.Base(), 2 );
+ }
+ MatrixBuildTranslation( mat, -center.x, -center.y, 0.0f );
+
+ if (m_pScaleVar)
+ {
+ Vector2D scale;
+ m_pScaleVar->GetVecValue( scale.Base(), 2 );
+ MatrixBuildScale( temp, scale.x, scale.y, 1.0f );
+ MatrixMultiply( temp, mat, mat );
+ }
+
+ if (m_pRotateVar)
+ {
+ float angle = m_pRotateVar->GetFloatValue( );
+ MatrixBuildRotateZ( temp, angle );
+ MatrixMultiply( temp, mat, mat );
+ }
+ MatrixBuildTranslation( temp, center.x, center.y, 0.0f );
+ MatrixMultiply( temp, mat, mat );
+
+ if (m_pTranslateVar)
+ {
+ m_pTranslateVar->GetVecValue( translation.Base(), 2 );
+ MatrixBuildTranslation( temp, translation.x, translation.y, 0.0f );
+ MatrixMultiply( temp, mat, mat );
+ }
+
+ m_pResult->SetMatrixValue( mat );
+
+ if ( ToolsEnabled() )
+ {
+ ToolFramework_RecordMaterialParams( GetMaterial() );
+ }
+}
+
+
+
+EXPOSE_INTERFACE( CTextureTransformProxy, IMaterialProxy, "TextureTransform" IMATERIAL_PROXY_INTERFACE_VERSION );
+
+
+//-----------------------------------------------------------------------------
+// Rotation proxy
+//-----------------------------------------------------------------------------
+class CMatrixRotateProxy : public CResultProxy
+{
+public:
+ bool Init( IMaterial *pMaterial, KeyValues *pKeyValues );
+ void OnBind( void *pC_BaseEntity );
+
+private:
+ CFloatInput m_Angle;
+ IMaterialVar *m_pAxisVar;
+};
+
+bool CMatrixRotateProxy::Init( IMaterial *pMaterial, KeyValues *pKeyValues )
+{
+ // All are optional...
+ m_pAxisVar = NULL;
+
+ bool bFoundVar;
+ char const* pVarName = pKeyValues->GetString( "axisVar" );
+ if( pVarName && pVarName[0] )
+ {
+ m_pAxisVar = pMaterial->FindVar( pVarName, &bFoundVar, false );
+ }
+
+ if (!m_Angle.Init( pMaterial, pKeyValues, "angle", 0 ))
+ return false;
+
+ return CResultProxy::Init( pMaterial, pKeyValues );
+}
+
+void CMatrixRotateProxy::OnBind( void *pC_BaseEntity )
+{
+ VMatrix mat;
+ Vector axis( 0, 0, 1 );
+ if (m_pAxisVar)
+ {
+ m_pAxisVar->GetVecValue( axis.Base(), 3 );
+ if (VectorNormalize( axis ) < 1e-3)
+ {
+ axis.Init( 0, 0, 1 );
+ }
+ }
+
+ MatrixBuildRotationAboutAxis( mat, axis, m_Angle.GetFloat() );
+ m_pResult->SetMatrixValue( mat );
+
+ if ( ToolsEnabled() )
+ {
+ ToolFramework_RecordMaterialParams( GetMaterial() );
+ }
+}
+
+
+
+EXPOSE_INTERFACE( CMatrixRotateProxy, IMaterialProxy, "MatrixRotate" IMATERIAL_PROXY_INTERFACE_VERSION );
+
|