void CSDKPlayer::SDKThrowWeaponDir( CWeaponSDKBase *pWeapon, const Vector &vecForward, Vector *pVecThrowDir ) { VMatrix zRot; MatrixBuildRotateZ( zRot, random->RandomFloat( -60.0f, 60.0f ) ); Vector vecThrow; Vector3DMultiply( zRot, vecForward, *pVecThrowDir ); pVecThrowDir->z = random->RandomFloat( -0.5f, 0.5f ); VectorNormalize( *pVecThrowDir ); }
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() ); } }
//----------------------------------------------------------------------------- // Creates a vector material var //----------------------------------------------------------------------------- static IMaterialVar* CreateMatrixMaterialVarFromKeyValue( IMaterial* pMaterial, KeyValues* pKeyValue ) { char const* pScan = pKeyValue->GetString(); // Matrices can be specified one of two ways: // [ # # # # # # # # # # # # # # # # ] // or // center # # scale # # rotate # translate # # VMatrix mat; int count = sscanf( pScan, " [ %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f ]", &mat.m[0][0], &mat.m[0][1], &mat.m[0][2], &mat.m[0][3], &mat.m[1][0], &mat.m[1][1], &mat.m[1][2], &mat.m[1][3], &mat.m[2][0], &mat.m[2][1], &mat.m[2][2], &mat.m[2][3], &mat.m[3][0], &mat.m[3][1], &mat.m[3][2], &mat.m[3][3] ); if (count == 16) { return IMaterialVar::Create( pMaterial, pKeyValue->GetName(), mat ); } Vector2D scale, center; float angle; Vector2D translation; count = sscanf( pScan, " center %f %f scale %f %f rotate %f translate %f %f", ¢er.x, ¢er.y, &scale.x, &scale.y, &angle, &translation.x, &translation.y ); if (count != 7) return NULL; VMatrix temp; MatrixBuildTranslation( mat, -center.x, -center.y, 0.0f ); MatrixBuildScale( temp, scale.x, scale.y, 1.0f ); MatrixMultiply( temp, mat, mat ); MatrixBuildRotateZ( temp, angle ); MatrixMultiply( temp, mat, mat ); MatrixBuildTranslation( temp, center.x + translation.x, center.y + translation.y, 0.0f ); MatrixMultiply( temp, mat, mat ); // Create the variable! return IMaterialVar::Create( pMaterial, pKeyValue->GetName(), mat ); }
//----------------------------------------------------------------------------- // Read in worldcraft data... //----------------------------------------------------------------------------- bool CVGuiScreen::KeyValue( const char *szKeyName, const char *szValue ) { //!! temp hack, until worldcraft is fixed // strip the # tokens from (duplicate) key names char *s = (char *)strchr( szKeyName, '#' ); if ( s ) { *s = '\0'; } if ( FStrEq( szKeyName, "panelname" )) { SetPanelName( szValue ); return true; } // NOTE: Have to do these separate because they set two values instead of one if( FStrEq( szKeyName, "angles" ) ) { Assert( GetMoveParent() == NULL ); QAngle angles; UTIL_StringToVector( angles.Base(), szValue ); // Because the vgui screen basis is strange (z is front, y is up, x is right) // we need to rotate the typical basis before applying it VMatrix mat, rotation, tmp; MatrixFromAngles( angles, mat ); MatrixBuildRotationAboutAxis( rotation, Vector( 0, 1, 0 ), 90 ); MatrixMultiply( mat, rotation, tmp ); MatrixBuildRotateZ( rotation, 90 ); MatrixMultiply( tmp, rotation, mat ); MatrixToAngles( mat, angles ); SetAbsAngles( angles ); return true; } return BaseClass::KeyValue( szKeyName, szValue ); }
static int vmatrix_MatrixBuildRotateZ (lua_State *L) { MatrixBuildRotateZ(luaL_checkvmatrix(L, 1), luaL_checknumber(L, 2)); return 0; }