本文整理汇总了C++中VMatrix类的典型用法代码示例。如果您正苦于以下问题:C++ VMatrix类的具体用法?C++ VMatrix怎么用?C++ VMatrix使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了VMatrix类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: CameraIdentityMatrix
//-----------------------------------------------------------------------------
// Purpose: Generates a view matrix based on our current yaw, pitch, and roll.
// The view matrix does not consider FOV or clip plane distances.
//-----------------------------------------------------------------------------
void CCamera::BuildViewMatrix()
{
// The camera transformation is produced by multiplying roll * yaw * pitch.
// This will transform a point from world space into quake camera space,
// which is exactly what we want for our view matrix. However, quake
// camera space isn't the same as material system camera space, so
// we're going to have to apply a transformation that goes from quake
// camera space to material system camera space.
CameraIdentityMatrix( m_ViewMatrix );
RotateAroundAxis(m_ViewMatrix, m_fPitch, 0 );
RotateAroundAxis(m_ViewMatrix, m_fRoll, 1);
RotateAroundAxis(m_ViewMatrix, m_fYaw, 2);
// Translate the viewpoint to the world origin.
VMatrix TempMatrix;
TempMatrix.Identity();
TempMatrix.SetTranslation( -m_ViewPoint );
m_ViewMatrix = m_ViewMatrix * TempMatrix;
m_ViewProjMatrix = m_ProjMatrix * m_ViewMatrix;
m_ViewProjMatrix.InverseGeneral( m_InvViewProjMatrix );
}
示例2: GetWorldToScreenMatrixForView
void CEngineTool::CreatePickingRay( const CViewSetup &viewSetup, int x, int y, Vector& org, Vector& forward )
{
// Remap x and y into -1 to 1 normalized space
float xf, yf;
xf = ( 2.0f * (float)x / (float)viewSetup.width ) - 1.0f;
yf = ( 2.0f * (float)y / (float)viewSetup.height ) - 1.0f;
// Flip y axis
yf = -yf;
VMatrix worldToScreen;
GetWorldToScreenMatrixForView( viewSetup, &worldToScreen );
VMatrix screenToWorld;
MatrixInverseGeneral( worldToScreen, screenToWorld );
// Create two points at the normalized mouse x, y pos and at the near and far z planes (0 and 1 depth)
Vector v1, v2;
v1.Init( xf, yf, 0.0f );
v2.Init( xf, yf, 1.0f );
Vector o2;
// Transform the two points by the screen to world matrix
screenToWorld.V3Mul( v1, org ); // ray start origin
screenToWorld.V3Mul( v2, o2 ); // ray end origin
VectorSubtract( o2, org, forward );
forward.NormalizeInPlace();
}
示例3: SetDepthFlashlightParams
static void SetDepthFlashlightParams( CBaseVSShader *pShader, IShaderDynamicAPI *pShaderAPI, const VMatrix& worldToTexture, const FlashlightState_t& flashlightState )
{
float atten[4], pos[4], tweaks[4];
atten[0] = flashlightState.m_fConstantAtten; // Set the flashlight attenuation factors
atten[1] = flashlightState.m_fLinearAtten;
atten[2] = flashlightState.m_fQuadraticAtten;
atten[3] = flashlightState.m_FarZ;
pShaderAPI->SetPixelShaderConstant( PSREG_FLASHLIGHT_ATTENUATION, atten, 1 );
pos[0] = flashlightState.m_vecLightOrigin[0]; // Set the flashlight origin
pos[1] = flashlightState.m_vecLightOrigin[1];
pos[2] = flashlightState.m_vecLightOrigin[2];
pShaderAPI->SetPixelShaderConstant( PSREG_FLASHLIGHT_POSITION_RIM_BOOST, pos, 1 );
pShaderAPI->SetPixelShaderConstant( PSREG_FLASHLIGHT_TO_WORLD_TEXTURE, worldToTexture.Base(), 4 );
// Tweaks associated with a given flashlight
tweaks[0] = ShadowFilterFromState( flashlightState );
tweaks[1] = ShadowAttenFromState( flashlightState );
pShader->HashShadow2DJitter( flashlightState.m_flShadowJitterSeed, &tweaks[2], &tweaks[3] );
pShaderAPI->SetPixelShaderConstant( PSREG_ENVMAP_TINT__SHADOW_TWEAKS, tweaks, 1 );
// Dimensions of screen, used for screen-space noise map sampling
float vScreenScale[4] = {1280.0f / 32.0f, 720.0f / 32.0f, 0, 0};
int nWidth, nHeight;
pShaderAPI->GetBackBufferDimensions( nWidth, nHeight );
vScreenScale[0] = (float) nWidth / 32.0f;
vScreenScale[1] = (float) nHeight / 32.0f;
pShaderAPI->SetPixelShaderConstant( PSREG_FLASHLIGHT_SCREEN_SCALE, vScreenScale, 1 );
if ( IsX360() )
{
pShaderAPI->SetBooleanPixelShaderConstant( 0, &flashlightState.m_nShadowQuality, 1 );
}
}
示例4: MatrixBuildOrtho
void MatrixBuildOrtho( VMatrix& dst, double left, double top, double right, double bottom, double zNear, double zFar )
{
// FIXME: This is being used incorrectly! Should read:
// D3DXMatrixOrthoOffCenterRH( &matrix, left, right, bottom, top, zNear, zFar );
// Which is certainly why we need these extra -1 scales in y. Bleah
// NOTE: The camera can be imagined as the following diagram:
// /z
// /
// /____ x Z is going into the screen
// |
// |
// |y
//
// (0,0,z) represents the upper-left corner of the screen.
// Our projection transform needs to transform from this space to a LH coordinate
// system that looks thusly:
//
// y| /z
// | /
// |/____ x Z is going into the screen
//
// Where x,y lies between -1 and 1, and z lies from 0 to 1
// This is because the viewport transformation from projection space to pixels
// introduces a -1 scale in the y coordinates
// D3DXMatrixOrthoOffCenterRH( &matrix, left, right, top, bottom, zNear, zFar );
dst.Init( 2.0f / ( right - left ), 0.0f, 0.0f, ( left + right ) / ( left - right ),
0.0f, 2.0f / ( bottom - top ), 0.0f, ( bottom + top ) / ( top - bottom ),
0.0f, 0.0f, 1.0f / ( zNear - zFar ), zNear / ( zNear - zFar ),
0.0f, 0.0f, 0.0f, 1.0f );
}
示例5: PanelName
//-----------------------------------------------------------------------------
// Returns the attachment render origin + origin
//-----------------------------------------------------------------------------
void C_VGuiScreen::GetAimEntOrigin( IClientEntity *pAttachedTo, Vector *pOrigin, QAngle *pAngles )
{
C_BaseEntity *pEnt = pAttachedTo->GetBaseEntity();
const char* panelName = PanelName();
vgui::Panel panel = m_PanelWrapper.GetPanel();
if ( Q_strcmp(panelName, "health_screen") == 0 )
{
QAngle weapAngles = pEnt->GetAbsAngles();
Vector weapForward, weapRight, weapUp;
AngleVectors(weapAngles, &weapForward, &weapRight, &weapUp);
VMatrix worldFromPanel;
AngleMatrix(weapAngles, worldFromPanel.As3x4());
MatrixRotate(worldFromPanel, Vector(0, 0, 1), 180.f);
MatrixRotate(worldFromPanel, Vector(1, 0, 0), -90.f);
MatrixAngles(worldFromPanel.As3x4(), *pAngles);
// move it right and over
*pOrigin = pEnt->GetAbsOrigin() + weapRight*1.75 + weapUp*2.3 + weapForward*5;
return;
}
//todo: set alpha per view ... m_PanelWrapper.GetPanel()->SetAlpha(200);
if (pEnt && (m_nAttachmentIndex > 0))
{
{
C_BaseAnimating::AutoAllowBoneAccess boneaccess( true, true );
pEnt->GetAttachment( m_nAttachmentIndex, *pOrigin, *pAngles );
}
if ( IsAttachedToViewModel() )
{
FormatViewModelAttachment( *pOrigin, true );
}
}
else
{
BaseClass::GetAimEntOrigin( pAttachedTo, pOrigin, pAngles );
}
// Msg("%s origin %.1f %.1f %.1f angles %.1f %.1f %.1f \n", PanelName(), pOrigin->x, pOrigin->y, pOrigin->z, pAngles->x, pAngles->y, pAngles->z);
}
示例6: MatrixBuildRotationAboutAxis
//-----------------------------------------------------------------------------
// Purpose: Builds the matrix for a counterclockwise rotation about an arbitrary axis.
//
// | ax2 + (1 - ax2)cosQ axay(1 - cosQ) - azsinQ azax(1 - cosQ) + aysinQ |
// Ra(Q) = | axay(1 - cosQ) + azsinQ ay2 + (1 - ay2)cosQ ayaz(1 - cosQ) - axsinQ |
// | azax(1 - cosQ) - aysinQ ayaz(1 - cosQ) + axsinQ az2 + (1 - az2)cosQ |
//
// Input : mat -
// vAxisOrRot -
// angle -
//-----------------------------------------------------------------------------
void MatrixBuildRotationAboutAxis( VMatrix &dst, const Vector &vAxisOfRot, float angleDegrees )
{
MatrixBuildRotationAboutAxis( vAxisOfRot, angleDegrees, dst.As3x4() );
dst[3][0] = 0;
dst[3][1] = 0;
dst[3][2] = 0;
dst[3][3] = 1;
}
示例7: MatrixBuildPerspective
void MatrixBuildPerspective( VMatrix &dst, float fovX, float fovY, float zNear, float zFar )
{
// FIXME: collapse all of this into one matrix after we figure out what all should be in here.
float width = 2 * zNear * tan( fovX * ( M_PI/180.0f ) * 0.5f );
float height = 2 * zNear * tan( fovY * ( M_PI/180.0f ) * 0.5f );
memset( dst.Base(), 0, sizeof( dst ) );
dst[0][0] = 2.0F * zNear / width;
dst[1][1] = 2.0F * zNear / height;
dst[2][2] = -zFar / ( zNear - zFar );
dst[3][2] = 1.0f;
dst[2][3] = zNear * zFar / ( zNear - zFar );
// negate X and Y so that X points right, and Y points up.
VMatrix negateXY;
negateXY.Identity();
negateXY[0][0] = -1.0f;
negateXY[1][1] = -1.0f;
MatrixMultiply( negateXY, dst, dst );
VMatrix addW;
addW.Identity();
addW[0][3] = 1.0f;
addW[1][3] = 1.0f;
addW[2][3] = 0.0f;
MatrixMultiply( addW, dst, dst );
VMatrix scaleHalf;
scaleHalf.Identity();
scaleHalf[0][0] = 0.5f;
scaleHalf[1][1] = 0.5f;
MatrixMultiply( scaleHalf, dst, dst );
}
示例8: WorldToLocalRotation
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
AngularImpulse WorldToLocalRotation( const VMatrix &localToWorld, const Vector &worldAxis, float rotation )
{
// fix axes of rotation to match axes of vector
Vector rot = worldAxis * rotation;
// since the matrix maps local to world, do a transpose rotation to get world to local
AngularImpulse ang = localToWorld.VMul3x3Transpose( rot );
return ang;
}
示例9: MatrixBuildPerspectiveX
void MatrixBuildPerspectiveX( VMatrix& dst, double flFovX, double flAspect, double flZNear, double flZFar )
{
float flWidth = 2.0f * flZNear * tanf( flFovX * M_PI / 360.0f );
float flHeight = flWidth / flAspect;
dst.Init( 2.0f * flZNear / flWidth, 0.0f, 0.0f, 0.0f,
0.0f, 2.0f * flZNear/ flHeight, 0.0f, 0.0f,
0.0f, 0.0f, flZFar / ( flZNear - flZFar ), flZNear * flZFar / ( flZNear - flZFar ),
0.0f, 0.0f, -1.0f, 0.0f );
}
示例10: VectorMA
//-----------------------------------------------------------------------------
// Computes the position of the canister
//-----------------------------------------------------------------------------
void CEnvHeadcrabCanisterShared::GetPositionAtTime( float flTime, Vector &vecPosition, QAngle &vecAngles )
{
float flDeltaTime = flTime - m_flLaunchTime;
if ( flDeltaTime > m_flFlightTime )
{
flDeltaTime = m_flFlightTime;
}
VMatrix initToWorld;
if ( m_bLaunchedFromWithinWorld || m_bInSkybox )
{
VectorMA( m_vecStartPosition, flDeltaTime * m_flHorizSpeed, m_vecParabolaDirection, vecPosition );
vecPosition.z += m_flInitialZSpeed * flDeltaTime + 0.5f * m_flZAcceleration * flDeltaTime * flDeltaTime;
Vector vecLeft;
CrossProduct( m_vecParabolaDirection, Vector( 0, 0, 1 ), vecLeft );
Vector vecForward;
VectorMultiply( m_vecParabolaDirection, -1.0f, vecForward );
vecForward.z = -(m_flInitialZSpeed + m_flZAcceleration * flDeltaTime) / m_flHorizSpeed; // This is -dz/dx.
VectorNormalize( vecForward );
Vector vecUp;
CrossProduct( vecForward, vecLeft, vecUp );
initToWorld.SetBasisVectors( vecForward, vecLeft, vecUp );
}
else
{
flDeltaTime -= m_flWorldEnterTime;
Vector vecVelocity;
VectorMultiply( m_vecDirection, m_flFlightSpeed, vecVelocity );
VectorMA( m_vecEnterWorldPosition, flDeltaTime, vecVelocity, vecPosition );
MatrixFromAngles( m_vecStartAngles.Get(), initToWorld );
}
VMatrix rotation;
MatrixBuildRotationAboutAxis( rotation, Vector( 1, 0, 0 ), flDeltaTime * ROTATION_SPEED );
VMatrix newAngles;
MatrixMultiply( initToWorld, rotation, newAngles );
MatrixToAngles( newAngles, vecAngles );
}
示例11: NormalizeBasisVectors
VMatrix VMatrix::NormalizeBasisVectors() const
{
Vector vecs[3];
VMatrix mRet;
GetBasisVectors(vecs[0], vecs[1], vecs[2]);
VectorNormalize( vecs[0] );
VectorNormalize( vecs[1] );
VectorNormalize( vecs[2] );
mRet.SetBasisVectors(vecs[0], vecs[1], vecs[2]);
// Set everything but basis vectors to identity.
mRet.m[3][0] = mRet.m[3][1] = mRet.m[3][2] = 0.0f;
mRet.m[3][3] = 1.0f;
return mRet;
}
示例12: SetupProjectionMatrix
void CRenderManager::SetupProjectionMatrix( int nWidth, int nHeight, float flFOV )
{
VMatrix proj;
float flZNear = ZNEAR;
float flZFar = ZFAR;
float flApsectRatio = (nHeight != 0.0f) ? (float)nWidth / (float)nHeight : 100.0f;
float halfWidth = tan( flFOV * M_PI / 360.0 );
float halfHeight = halfWidth / flApsectRatio;
memset( proj.Base(), 0, sizeof( proj ) );
proj[0][0] = 1.0f / halfWidth;
proj[1][1] = 1.0f / halfHeight;
proj[2][2] = flZFar / ( flZNear - flZFar );
proj[3][2] = -1.0f;
proj[2][3] = flZNear * flZFar / ( flZNear - flZFar );
CMatRenderContextPtr pRenderContext( g_pMaterialSystem );
pRenderContext->MatrixMode( MATERIAL_PROJECTION );
pRenderContext->LoadMatrix( proj );
}
示例13: Assert
void CBaseVSShader::SetFlashlightVertexShaderConstants( bool bBump, int bumpTransformVar, bool bDetail, int detailScaleVar, bool bSetTextureTransforms )
{
Assert( !IsSnapshotting() );
VMatrix worldToTexture;
const FlashlightState_t &flashlightState = s_pShaderAPI->GetFlashlightState( worldToTexture );
// Set the flashlight origin
float pos[4];
pos[0] = flashlightState.m_vecLightOrigin[0];
pos[1] = flashlightState.m_vecLightOrigin[1];
pos[2] = flashlightState.m_vecLightOrigin[2];
pos[3] = 1.0f / ( ( 0.6f * flashlightState.m_FarZ ) - flashlightState.m_FarZ ); // DX8 needs this
s_pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_0, pos, 1 );
s_pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_1, worldToTexture.Base(), 4 );
// Set the flashlight attenuation factors
float atten[4];
atten[0] = flashlightState.m_fConstantAtten;
atten[1] = flashlightState.m_fLinearAtten;
atten[2] = flashlightState.m_fQuadraticAtten;
atten[3] = flashlightState.m_FarZAtten;
s_pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_5, atten, 1 );
if ( bDetail )
{
SetVertexShaderTextureScaledTransform( VERTEX_SHADER_SHADER_SPECIFIC_CONST_8, BASETEXTURETRANSFORM, detailScaleVar );
}
if( bSetTextureTransforms )
{
SetVertexShaderTextureTransform( VERTEX_SHADER_SHADER_SPECIFIC_CONST_6, BASETEXTURETRANSFORM );
if( !bDetail && bBump && bumpTransformVar != -1 )
{
SetVertexShaderTextureTransform( VERTEX_SHADER_SHADER_SPECIFIC_CONST_8, bumpTransformVar ); // aliased on top of detail transform
}
}
}
示例14: SetupMatrixOrgAngles
void CStatueProp::VPhysicsUpdate( IPhysicsObject *pPhysics )
{
BaseClass::VPhysicsUpdate( pPhysics );
if ( s_vcollide_wireframe->GetBool() )
{
const CPhysCollide *pCollide = pPhysics->GetCollide();
Vector vecOrigin;
QAngle angAngles;
pPhysics->GetPosition( &vecOrigin, &angAngles );
if ( pCollide )
{
Vector *outVerts;
int vertCount = physcollision->CreateDebugMesh( pCollide, &outVerts );
int triCount = vertCount / 3;
int vert = 0;
VMatrix tmp = SetupMatrixOrgAngles( vecOrigin, angAngles );
int i;
for ( i = 0; i < vertCount; i++ )
{
outVerts[i] = tmp.VMul4x3( outVerts[i] );
}
for ( i = 0; i < triCount; i++ )
{
NDebugOverlay::Line( outVerts[ vert + 0 ], outVerts[ vert + 1 ], 0, 255, 255, false, 0.0f );
NDebugOverlay::Line( outVerts[ vert + 1 ], outVerts[ vert + 2 ], 0, 255, 255, false, 0.0f );
NDebugOverlay::Line( outVerts[ vert + 2 ], outVerts[ vert + 0 ], 0, 255, 255, false, 0.0f );
vert += 3;
}
physcollision->DestroyDebugMesh( vertCount, outVerts );
}
}
}
示例15: MatrixBuildPerspectiveOffCenterX
void MatrixBuildPerspectiveOffCenterX( VMatrix& dst, double flFovX, double flAspect, double flZNear, double flZFar, double bottom, double top, double left, double right )
{
float flWidth = 2.0f * flZNear * tanf( flFovX * M_PI / 360.0f );
float flHeight = flWidth / flAspect;
// bottom, top, left, right are 0..1 so convert to -<val>/2..<val>/2
float flLeft = -(flWidth/2.0f) * (1.0f - left) + left * (flWidth/2.0f);
float flRight = -(flWidth/2.0f) * (1.0f - right) + right * (flWidth/2.0f);
float flBottom = -(flHeight/2.0f) * (1.0f - bottom) + bottom * (flHeight/2.0f);
float flTop = -(flHeight/2.0f) * (1.0f - top) + top * (flHeight/2.0f);
dst.Init( (2.0f * flZNear) / (flRight-flLeft), 0.0f, (flLeft+flRight)/(flRight-flLeft), 0.0f,
0.0f, 2.0f*flZNear/(flTop-flBottom), (flTop+flBottom)/(flTop-flBottom), 0.0f,
0.0f, 0.0f, flZFar/(flZNear-flZFar), flZNear*flZFar/(flZNear-flZFar),
0.0f, 0.0f, -1.0f, 0.0f );
}