本文整理汇总了C++中Matrix4x4::Identity方法的典型用法代码示例。如果您正苦于以下问题:C++ Matrix4x4::Identity方法的具体用法?C++ Matrix4x4::Identity怎么用?C++ Matrix4x4::Identity使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Matrix4x4
的用法示例。
在下文中一共展示了Matrix4x4::Identity方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: cos
void Matrix4x4::ArbAxisRotation(Vertex &rotVert, int degrees)
{
float radians = degrees * (float(PI)/180);
rotVert.Normalize();
float xy = rotVert._x * rotVert._y;
float xz = rotVert._x * rotVert._z;
float yz = rotVert._y * rotVert._z;
float xSq = rotVert._x * rotVert._x;
float ySq = rotVert._y * rotVert._y;
float zSq = rotVert._z * rotVert._z;
float oneMincos = (1-cos(radians));
Matrix4x4 matRotate;
matRotate.Identity();
matRotate._11 = xSq * oneMincos + cos(radians);
matRotate._12 = xy * oneMincos + rotVert._z * sin(radians);
matRotate._13 = xz * oneMincos - rotVert._y * sin(radians);
matRotate._21 = xy * oneMincos - rotVert._z * sin(radians);
matRotate._22 = ySq * oneMincos + cos(radians);
matRotate._23 = yz * oneMincos + rotVert._x * sin(radians);
matRotate._31 = xz * oneMincos + rotVert._y * sin(radians);
matRotate._32 = yz * oneMincos - rotVert._x * sin(radians);
matRotate._33 = zSq * oneMincos + cos(radians);
Transformation(matRotate);
}
示例2: InitResourceDX9
bool InitResourceDX9(void)
{
g_orient_matrix.Identity();
LPDIRECT3DDEVICE9 device = GutGetGraphicsDeviceDX9();
if ( !ReInitResourceDX9() )
return false;
g_pPostEffect = GutLoadFXShaderDX9("../../shaders/Posteffect.fx");
if ( NULL==g_pPostEffect )
return false;
g_pWaterEffect = GutLoadFXShaderDX9("../../shaders/Watereffect.fx");
if ( NULL==g_pWaterEffect )
return false;
g_pWaterTexture = GutLoadTexture_DX9("../../textures/lena.tga");
if ( NULL==g_pWaterTexture )
return false;
g_Model_DX9.ConvertToDX9Model(&g_Model);
return true;
}
示例3: View
Matrix4x4 View( Vector3 viewerPosition, Vector3 viewerDirection, Vector3 upVector )
{
Matrix4x4 result;
Vector3 zAxis( viewerDirection - viewerPosition );
zAxis.Normalise();
Vector3 xAxis( CrossProduct( upVector, zAxis ) );
xAxis.Normalise();
Vector3 yAxis( CrossProduct( zAxis, xAxis ) );
result.Identity();
result.m[0][0] = xAxis.x;
result.m[1][0] = yAxis.x;
result.m[2][0] = zAxis.x;
result.m[0][1] = xAxis.y;
result.m[1][1] = yAxis.y;
result.m[2][1] = zAxis.y;
result.m[0][2] = xAxis.z;
result.m[1][2] = yAxis.z;
result.m[2][2] = zAxis.z;
result.m[0][3] = -DotProduct( xAxis, viewerPosition );
result.m[1][3] = -DotProduct( yAxis, viewerPosition );
result.m[2][3] = -DotProduct( zAxis, viewerPosition );
result.m[3][3] = 1;
return result;
}
示例4: AddImpulse
static void AddImpulse(void)
{
static Vector4 vPosition(0.0f, 0.0f, 0.0f, 0.0f);
//Vector4 vDiff = vPosition - g_vPosition;
Vector4 vDiff = g_vPosition - vPosition;
Vector4 vLength = vDiff.Length();
if ( vLength[0]<2.0f )
return;
Vector4 vDir = vDiff / vLength;
Vector4 vVec0(vDir[1],-vDir[0], 0.0f, 0.0f);
Vector4 vVec1(vDir[0], vDir[1], 0.0f, 0.0f);
vPosition = g_vPosition;
Vector4 vVec0_old = g_orient_matrix[0];
Vector4 vVec1_old = g_orient_matrix[1];
Vector4 vVec0_new = VectorLerp(vVec0_old, vVec0, 0.2f);
Vector4 vVec1_new = VectorLerp(vVec1_old, vVec1, 0.2f);
vVec0_new.Normalize();
vVec1_new.Normalize();
Vector4 vVec2_new = Vector3CrossProduct(vVec0_new, vVec1_new);
g_orient_matrix.Identity();
g_orient_matrix[0] = vVec0_new;
g_orient_matrix[1] = vVec1_new;
g_orient_matrix[2] = vVec2_new;
LPDIRECT3DDEVICE9 device = GutGetGraphicsDeviceDX9();
device->SetRenderTarget(0, g_pSurfaces[TEX_HEIGHT1]);
device->SetDepthStencilSurface(NULL);
Matrix4x4 view_matrix = g_Control.GetViewMatrix();
Matrix4x4 world_matrix;
world_matrix.Scale_Replace(g_fRippleSize, g_fRippleSize, 1.0f);
world_matrix[3] = g_vPosition;
Matrix4x4 wvp_matrix = g_orient_matrix * world_matrix * view_matrix * g_proj_matrix;
D3DXHANDLE shader = g_pWaterEffect->GetTechniqueByName("AddImpulse");
D3DXHANDLE wvp_matrix_var = g_pWaterEffect->GetParameterByName(NULL, "wvp_matrix");
D3DXHANDLE force_var = g_pWaterEffect->GetParameterByName(NULL, "fForce");
g_pWaterEffect->SetTechnique(shader);
g_pWaterEffect->SetMatrix(wvp_matrix_var, (D3DXMATRIX *)&wvp_matrix);
g_pWaterEffect->SetFloat(force_var, 0.05f);
g_pWaterEffect->Begin(NULL, 0);
g_pWaterEffect->BeginPass(0);
g_Model_DX9.Render(0);
g_pWaterEffect->EndPass();
g_pWaterEffect->End();
vPosition = g_vPosition;
}
示例5: Position
Matrix4x4 Position( float x, float y, float z )
{
Matrix4x4 result;
result.Identity();
result.m[0][3] = x;
result.m[1][3] = y;
result.m[2][3] = z;
return result;
}
示例6: Roll
Matrix4x4 Roll( float roll )
{
Matrix4x4 result;
result.Identity();
result.m[0][0] = result.m[1][1] = cosf( roll );
result.m[1][0] = -sinf( roll );
result.m[0][1] = sinf( roll );
result.m[2][2] = result.m[3][3] = 1;
return result;
}
示例7: Yaw
Matrix4x4 Yaw( float yaw )
{
Matrix4x4 result;
result.Identity();
result.m[0][0] = result.m[2][2] = cosf( yaw );
result.m[2][0] = -sinf( yaw );
result.m[0][2] = sinf( yaw );
result.m[1][1] = result.m[3][3] = 1;
return result;
}
示例8: Pitch
Matrix4x4 Pitch( float pitch )
{
Matrix4x4 result;
result.Identity();
result.m[1][1] = result.m[2][2] = cosf( pitch );
result.m[1][2] = -sinf( pitch );
result.m[2][1] = sinf( pitch );
result.m[0][0] = result.m[3][3] = 1;
return result;
}
示例9: RenderAttachments
void ModelViewerRender::RenderAttachments()
{
for(uint32 i=0;i<m_pModelMF1->m_Header.m_iNumAttc;++i)
{
Matrix4x4 matrix;
uint32 nBoneCount=m_pModelMF1->m_iNumBones;
uint32 boneID=m_pModelMF1->m_pAttachTags[i].m_iAttachBoneID;
if(m_pDynamicModel!=NULL)
{
if(boneID>=nBoneCount) continue;
float* pBuffer=m_pDynamicModel->getBonesMatrix();
Matrix4x4 boneMatrix;
boneMatrix.Identity();
boneMatrix._11=pBuffer[12*boneID];
boneMatrix._21=pBuffer[12*boneID+1];
boneMatrix._31=pBuffer[12*boneID+2];
boneMatrix._41=pBuffer[12*boneID+3];
boneMatrix._12=pBuffer[12*boneID+4];
boneMatrix._22=pBuffer[12*boneID+5];
boneMatrix._32=pBuffer[12*boneID+6];
boneMatrix._42=pBuffer[12*boneID+7];
boneMatrix._13=pBuffer[12*boneID+8];
boneMatrix._23=pBuffer[12*boneID+9];
boneMatrix._33=pBuffer[12*boneID+10];
boneMatrix._43=pBuffer[12*boneID+11];
matrix=m_pModelMF1->m_pAttachTags[i].m_InitMatTag*boneMatrix*m_pDynamicModel->getModelMatrix();
}
if(m_pStaticModel!=NULL)
{
matrix=m_pModelMF1->m_pAttachTags[i].m_InitMatTag*m_pStaticModel->getModelMatrix();
}
if(m_pStaticModel!=NULL||m_pDynamicModel!=NULL)
{
AABBox aabox=m_pModelMF1->m_MeshAABBox;
float length=(aabox.vcMax-aabox.vcMin).GetLength();
length/=100.0f;
AABBox box;
box.vcCenter.x=matrix._41;
box.vcCenter.y=matrix._42;
box.vcCenter.z=matrix._43;
box.vcMin.x=box.vcCenter.x-length;
box.vcMin.y=box.vcCenter.y-length;
box.vcMin.z=box.vcCenter.z-length;
box.vcMax.x=box.vcCenter.x+length;
box.vcMax.y=box.vcCenter.y+length;
box.vcMax.z=box.vcCenter.z+length;
m_pRenderDevice->GetVertexCacheManager()->RenderBox(box,Colour(0,255,0));
// m_pRenderDevice->GetVertexCacheManager()->RenderDetailSphere(Vector3D(matrix._41,matrix._42,matrix._43),length/100.0f,5,5,Colour(255,255,0));
}
}
}
示例10: RenderFrameDX9
// 使用DirectX 9來繪圖
void RenderFrameDX9(void)
{
LPDIRECT3DDEVICE9 device = GutGetGraphicsDeviceDX9();
// 開始下繪圖指令
device->BeginScene();
// 設定資料格式
device->SetFVF(D3DFVF_XYZ|D3DFVF_TEX1);
//device->Clear(0, NULL, D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER, 0x0, 1.0f, 0);
{
Matrix4x4 IdentityMatrix;
IdentityMatrix.Identity();
device->SetTransform(D3DTS_PROJECTION, (D3DMATRIX *) &IdentityMatrix);
device->SetTransform(D3DTS_VIEW, (D3DMATRIX *) &IdentityMatrix);
device->SetTransform(D3DTS_WORLD, (D3DMATRIX *) &IdentityMatrix);
device->SetTexture(0, g_pTexture0);
// ZBuffer測試條件設為永遠成立
device->SetRenderState(D3DRS_ZFUNC, D3DCMP_ALWAYS);
// 畫出矩形, 同時會清除ZBuffer
device->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP, 2, g_FullScreenQuad, sizeof(Vertex_VT));
// ZBuffer測試條件設為小於
device->SetRenderState(D3DRS_ZFUNC, D3DCMP_LESS);
}
{
device->SetTransform(D3DTS_PROJECTION, (D3DMATRIX *) &g_projection_matrix);
// 鏡頭座標系轉換矩陣
Matrix4x4 view_matrix = GutMatrixLookAtRH(g_eye, g_lookat, g_up);
device->SetTransform(D3DTS_VIEW, (D3DMATRIX *) &view_matrix);
device->SetTransform(D3DTS_WORLD, (D3DMATRIX *) &g_world_matrix);
device->SetTexture(0, g_pTexture1);
// 開啟混色功能
device->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);
// source_blend_factor = 1
device->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_ONE);
// dest_blend_factor = 1
device->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_ONE);
// 混色公式 = source_color * 1 + dest_color * 1
// 畫出矩形
device->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP, 2, g_Quad, sizeof(Vertex_VT));
// 關閉Alpha Test功能
device->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE);
}
// 宣告所有的繪圖指令都下完了
device->EndScene();
// 把背景backbuffer的畫面呈現出來
device->Present( NULL, NULL, NULL, NULL );
}
示例11: Perspective
Matrix4x4 Perspective( float fov, float aspectRatio, float fNear, float fFar )
{
Matrix4x4 result;
float yScale = ( 1 / tan( fov / 2 ) ); // cot( fov / 2 )
float xScale = yScale / aspectRatio;
result.Identity();
result.m[0][0] = xScale;
result.m[1][1] = yScale;
result.m[2][2] = fFar / ( fFar - fNear );
result.m[2][3] = ( -fNear * fFar) / ( fFar - fNear );
result.m[3][2] = 1;
result.m[3][3] = 0;
return result;
}
示例12: RenderParticleEmitter
void ModelViewerRender::RenderParticleEmitter()
{
for(uint32 i=0;i<m_pModelMF1->m_Header.m_iNumParticles;++i)
{
Matrix4x4 matrix;
uint32 nBoneCount=m_pModelMF1->m_iNumBones;
uint32 boneID=m_pModelMF1->m_pParticleEmitter[i].m_iAttachBoneID;
// if(boneID>=nBoneCount) continue;
if(m_pDynamicModel!=NULL)
{
float* pBuffer=m_pDynamicModel->getBonesMatrix();
Matrix4x4 boneMatrix;
boneMatrix.Identity();
boneMatrix._11=pBuffer[12*boneID];
boneMatrix._21=pBuffer[12*boneID+1];
boneMatrix._31=pBuffer[12*boneID+2];
boneMatrix._41=pBuffer[12*boneID+3];
boneMatrix._12=pBuffer[12*boneID+4];
boneMatrix._22=pBuffer[12*boneID+5];
boneMatrix._32=pBuffer[12*boneID+6];
boneMatrix._42=pBuffer[12*boneID+7];
boneMatrix._13=pBuffer[12*boneID+8];
boneMatrix._23=pBuffer[12*boneID+9];
boneMatrix._33=pBuffer[12*boneID+10];
boneMatrix._43=pBuffer[12*boneID+11];
matrix=m_pModelMF1->m_pParticleEmitter[i].m_AbsoluteMatrix*boneMatrix*m_pDynamicModel->getModelMatrix();
}
if(m_pStaticModel!=NULL)
{
matrix=m_pModelMF1->m_pParticleEmitter[i].m_AbsoluteMatrix*m_pStaticModel->getModelMatrix();
}
if(m_pStaticModel!=NULL||m_pDynamicModel!=NULL)
{
AABBox aabox=m_pModelMF1->m_MeshAABBox;
float length=(aabox.vcMax-aabox.vcMin).GetLength();
length*=0.02f;
if((int)(i+1)==ModelViewerConfig::GetInstance()->m_nCurrSelParticle)
m_pRenderDevice->GetVertexCacheManager()->RenderCone(matrix,length,-length,4,Colour(255,0,0));
else
m_pRenderDevice->GetVertexCacheManager()->RenderCone(matrix,length,-length,4,Colour(255,255,255));
}
}
}
示例13:
Matrix4x4 Matrix4x4::ConstructCameraView(const Vector& vecPosition, const Vector& vecDirection, const Vector& vecUp)
{
Matrix4x4 m;
m.Identity();
TAssertNoMsg(fabs(vecDirection.LengthSqr()-1) < 0.0001f);
Vector vecCamSide = vecDirection.Cross(vecUp).Normalized();
Vector vecCamUp = vecCamSide.Cross(vecDirection);
m.SetForwardVector(Vector(vecCamSide.x, vecCamUp.x, -vecDirection.x));
m.SetLeftVector(Vector(vecCamSide.y, vecCamUp.y, -vecDirection.y));
m.SetUpVector(Vector(vecCamSide.z, vecCamUp.z, -vecDirection.z));
m.AddTranslation(-vecPosition);
return m;
}
示例14:
Matrix4x4 Matrix4x4::ProjectOrthographic(float flLeft, float flRight, float flBottom, float flTop, float flNear, float flFar)
{
Matrix4x4 m;
m.Identity();
float flXD = flRight - flLeft;
float flYD = flTop - flBottom;
float flZD = flFar - flNear;
m.m[0][0] = 2.0f / flXD;
m.m[1][1] = 2.0f / flYD;
m.m[2][2] = -2.0f / flZD;
m.m[3][0] = -(flRight + flLeft) / flXD;
m.m[3][1] = -(flTop + flBottom) / flYD;
m.m[3][2] = -(flFar + flNear) / flZD;
return m;
}
示例15:
Matrix4x4 ConvertToMatrix4x4( Quaternion &a )
{
Matrix4x4 result;
result.Identity();
result.m[0][0] = 1 - 2 * a.y * a.y - 2 * a.z * a.z;
result.m[1][0] = 2 * a.x * a.y + 2 * a.z * a.w;
result.m[2][0] = 2 * a.x * a.z - 2 * a.y * a.w;
//result.m[3][0] = 0;
result.m[0][1] = 2 * a.x * a.y - 2 * a.z * a.w;
result.m[1][1] = 1 - 2 * a.x * a.x - 2 * a.z * a.z;
result.m[2][1] = 2 * a.y * a.z + 2 * a.x * a.w;
//result.m[3][1] = 0;
result.m[0][2] = 2 * a.x * a.z + 2 * a.y * a.w;
result.m[1][2] = 2 * a.y * a.z - 2 * a.x * a.w;
result.m[2][2] = 1 - 2 * a.x * a.x - 2 * a.y * a.y;
//result.m[3][2] = 0;
//result.m[0][3] = 0;
//result.m[1][3] = 0;
//result.m[2][3] = 0;
//result.m[3][3] = 0;
return result;
}