本文整理汇总了C++中Matrix4::Translate方法的典型用法代码示例。如果您正苦于以下问题:C++ Matrix4::Translate方法的具体用法?C++ Matrix4::Translate怎么用?C++ Matrix4::Translate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Matrix4
的用法示例。
在下文中一共展示了Matrix4::Translate方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: if
std::shared_ptr<Mesh> Light::EvaluateVolume()
{
if (m_Mesh) m_Mesh.reset();
if (m_Type == LightType::DIRECTIONAL)
{
m_Mesh = MeshUtil::GetUnitQuad();
}
else if (m_Type == LightType::POINT)
{
m_Mesh = MeshUtil::GetUnitIcoSphere();
}
else
{
float height = m_Radius;
float bottomR = std::tan(m_OutterAngle * 0.5f) * height;
m_Mesh = MeshUtil::CreateCylinder("spotlight_convex", 0.0f, bottomR, height, 5, 20);
Matrix4 matrix;
matrix.Translate(Vector4(0.0f, -height * 0.5f, 0.0f));
MeshUtil::TransformMesh(m_Mesh, matrix);
}
return m_Mesh;
}
示例2: DrawGridScene
void DrawGridScene( std::shared_ptr<RenderingContext> context, const Matrix4& matWorld )
{
Assert( context );
ConstantBuffer& cbuffer = context->GetSharedConstantBuffer();
float scale = model_scale.Float();
size_t columns = grid_size.Int();
float rowFactor = 1.0f / grid_size.Int();
float colFactor = 1.0f / columns;
for ( int row = 0; row < grid_size.Int(); ++row )
{
for ( size_t col = 0; col < columns; ++col )
{
// world transform
Matrix4 matTrans;
matTrans.Translate( ( ( col + 1 ) * colFactor - colFactor * ( columns * 0.5f ) ) * columns,
( ( row + 1 ) * rowFactor - rowFactor * ( columns * 0.5f ) ) * columns,
( ( row + 1 ) * rowFactor - rowFactor * ( columns * 0.5f ) ) * columns );
Matrix4 matScale;
matScale.Scaling( scale, scale, scale );
Matrix4 matNewWorld = matScale * matWorld * matTrans;
cbuffer.SetMatrix4( ConstantBuffer::WorldMatrix, matNewWorld );
// various color
cbuffer.SetVector4( ConstantBuffer::DiffuseColor, Vector4( max( 0.2f, matTrans.A41 * 0.5f + 0.8f ), max( 0.4f, matTrans.A42 * 0.5f + 0.6f ), matTrans.A43 * 0.5f + 1.0f, 1.0f ) );
context->Draw( GetMeshes()[row * columns + col] );
}
}
}
示例3: GetCameraRotationMatrix
Matrix4 Camera3D::GetCameraViewMatrix(){
//get transform matrix
Matrix4 cameraTransformMatrix;
cameraTransformMatrix.Translate(m_position);
cameraTransformMatrix.m_translation.x *= -1.0f; //stopgap fix for -zUP issue
cameraTransformMatrix.m_translation.z *= -1.0f; //stopgap fix for -zUP issue
Matrix4 viewMatrix = /* GetCameraRotationMatrix() * */ cameraTransformMatrix * GetCameraRotationMatrix();
//R*T = rotate around origin, movement correct
//T*R = rotate correct, absolute movement
viewMatrix.Transpose();
//the movement is absolute regardless of rotation for whatever reason...
return viewMatrix;
}
示例4: DrawGridSceneInParallel
void DrawGridSceneInParallel( StlVector<std::shared_ptr<RenderingContext>>& contexts, const Matrix4& matWorld )
{
float scale = model_scale.Float();
size_t rows = grid_size.Int();
size_t columns = grid_size.Int();
float rowFactor = 1.0f / grid_size.Int();
float colFactor = 1.0f / columns;
//using FuncPreRender = std::function<void( std::shared_ptr<RenderingContext> context, const std::shared_ptr<IMesh>& mesh, size_t index )>;
RenderingContext::FuncPreRender funcPreRender(
[=]( std::shared_ptr<RenderingContext> context, size_t index )
{
ConstantBuffer& cbuffer = context->GetSharedConstantBuffer();
// world transform
size_t row = kih::Clamp<size_t>( index / rows, 0, rows - 1 );
size_t col = kih::Clamp<size_t>( index - row * columns, 0, columns - 1 );
Matrix4 matTrans;
matTrans.Translate( ( ( col + 1 ) * colFactor - colFactor * ( columns * 0.5f ) ) * columns,
( ( row + 1 ) * rowFactor - rowFactor * ( columns * 0.5f ) ) * columns,
( ( row + 1 ) * rowFactor - rowFactor * ( columns * 0.5f ) ) * columns );
Matrix4 matScale;
matScale.Scaling( scale, scale, scale );
Matrix4 matNewWorld = matScale * matWorld * matTrans;
cbuffer.SetMatrix4( ConstantBuffer::WorldMatrix, matNewWorld );
// various color
cbuffer.SetVector4( ConstantBuffer::DiffuseColor, Vector4( max( 0.2f, matTrans.A41 * 0.5f + 0.8f ), max( 0.4f, matTrans.A42 * 0.5f + 0.6f ), matTrans.A43 * 0.5f + 1.0f, 1.0f ) );
}
);
RenderingContext::DrawInParallel( contexts, GetMeshes(), grid_size.Int() * grid_size.Int(), funcPreRender );
}