本文整理汇总了C++中Mat4::setIdentity方法的典型用法代码示例。如果您正苦于以下问题:C++ Mat4::setIdentity方法的具体用法?C++ Mat4::setIdentity怎么用?C++ Mat4::setIdentity使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mat4
的用法示例。
在下文中一共展示了Mat4::setIdentity方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
Mat4Stack(void)
{
Mat4<T> mat;
mat.setIdentity();
stack.push(mat);
}
示例2: getWorldToNodeTransform
Mat4 AttachNode::getWorldToNodeTransform() const
{
static Mat4 mat;
mat.setIdentity();
auto parent = getParent();
if (parent)
{
mat = parent->getWorldToNodeTransform() * _attachBone->getWorldMat() * Node::getNodeToParentTransform();
}
else
{
mat = _attachBone->getWorldMat() * Node::getNodeToParentTransform();
}
return mat;
}
示例3: AngleAxisd
TEST(Homography3DTest, RotationAndTranslationXYZ) {
Mat x1(4, 5);
x1 << 0, 0, 1, 5, 2,
0, 1, 2, 3, 5,
0, 2, 0, 1, 5,
1, 1, 1, 1, 1;
Mat4 M;
M.setIdentity();
/*
M = AngleAxisd(45.0, Vector3f::UnitZ())
* AngleAxisd(25.0, Vector3f::UnitX())
* AngleAxisd(5.0, Vector3f::UnitZ());*/
// Rotation on x + translation
double angle = 45.0;
Mat4 rot;
rot << 1, 0, 0, 1,
0, cos(angle), -sin(angle), 3,
0, sin(angle), cos(angle), -2,
0, 0, 0, 1;
M *= rot;
// Rotation on y
angle = 25.0;
rot << cos(angle), 0, sin(angle), 0,
0, 1, 0, 0,
-sin(angle), 0, cos(angle), 0,
0, 0, 0, 1;
M *= rot;
// Rotation on z
angle = 5.0;
rot << cos(angle), -sin(angle), 0, 0,
sin(angle), cos(angle), 0, 0,
0, 0, 1, 0,
0, 0, 0, 1;
M *= rot;
Mat x2 = x1;
for (int i = 0; i < x2.cols(); ++i) {
x2.col(i) = M * x1.col(i);
}
Mat4 homography_mat;
EXPECT_TRUE(Homography3DFromCorrespondencesLinear(x1, x2, &homography_mat));
notify(INFO) << "Mat Homography3D " << homography_mat;
notify(INFO) << "Mat GT " << M;
EXPECT_MATRIX_NEAR(homography_mat, M, 1e-8);
}
示例4: calculateBillbaordTransform
bool BillBoard::calculateBillbaordTransform()
{
//Get camera world position
auto camera = Camera::getVisitingCamera();
const Mat4& camWorldMat = camera->getNodeToWorldTransform();
//TODO: use math lib to calculate math lib Make it easier to read and maintain
if (memcmp(_camWorldMat.m, camWorldMat.m, sizeof(float) * 16) != 0 || memcmp(_mvTransform.m, _modelViewTransform.m, sizeof(float) * 16) != 0 || _modeDirty || true)
{
//Rotate based on anchor point
Vec3 anchorPoint(_anchorPointInPoints.x , _anchorPointInPoints.y , 0.0f);
Mat4 localToWorld = _modelViewTransform;
localToWorld.translate(anchorPoint);
//Decide billboard mode
Vec3 camDir;
switch (_mode)
{
case Mode::VIEW_POINT_ORIENTED:
camDir.set(localToWorld.m[12] - camWorldMat.m[12], localToWorld.m[13] - camWorldMat.m[13], localToWorld.m[14] - camWorldMat.m[14]);
break;
case Mode::VIEW_PLANE_ORIENTED:
camWorldMat.transformVector(Vec3(0.0f, 0.0f, -1.0f), &camDir);
break;
default:
CCASSERT(false, "invalid billboard mode");
break;
}
_modeDirty = false;
if (camDir.length() < MATH_TOLERANCE)
{
camDir.set(camWorldMat.m[8], camWorldMat.m[9], camWorldMat.m[10]);
}
camDir.normalize();
Quaternion rotationQuaternion;
this->getNodeToWorldTransform().getRotation(&rotationQuaternion);
Mat4 rotationMatrix;
rotationMatrix.setIdentity();
Vec3 upAxis(rotationMatrix.m[4],rotationMatrix.m[5],rotationMatrix.m[6]);
Vec3 x, y;
camWorldMat.transformVector(upAxis, &y);
Vec3::cross(camDir, y, &x);
x.normalize();
Vec3::cross(x, camDir, &y);
y.normalize();
float xlen = sqrtf(localToWorld.m[0] * localToWorld.m[0] + localToWorld.m[1] * localToWorld.m[1] + localToWorld.m[2] * localToWorld.m[2]);
float ylen = sqrtf(localToWorld.m[4] * localToWorld.m[4] + localToWorld.m[5] * localToWorld.m[5] + localToWorld.m[6] * localToWorld.m[6]);
float zlen = sqrtf(localToWorld.m[8] * localToWorld.m[8] + localToWorld.m[9] * localToWorld.m[9] + localToWorld.m[10] * localToWorld.m[10]);
Mat4 billboardTransform;
billboardTransform.m[0] = x.x * xlen; billboardTransform.m[1] = x.y * xlen; billboardTransform.m[2] = x.z * xlen;
billboardTransform.m[4] = y.x * ylen; billboardTransform.m[5] = y.y * ylen; billboardTransform.m[6] = y.z * ylen;
billboardTransform.m[8] = -camDir.x * zlen; billboardTransform.m[9] = -camDir.y * zlen; billboardTransform.m[10] = -camDir.z * zlen;
billboardTransform.m[12] = localToWorld.m[12]; billboardTransform.m[13] = localToWorld.m[13]; billboardTransform.m[14] = localToWorld.m[14];
billboardTransform.translate(-anchorPoint);
_mvTransform = _modelViewTransform = billboardTransform;
_camWorldMat = camWorldMat;
return true;
}
return false;
}
示例5: draw
void BillBoard::draw(Renderer *renderer, const Mat4 &transform, uint32_t flags)
{
auto camera = Camera::getVisitingCamera();
const Mat4& camWorldMat = camera->getNodeToWorldTransform();
if (memcmp(_camWorldMat.m, camWorldMat.m, sizeof(float) * 16) != 0 || memcmp(_mvTransform.m, transform.m, sizeof(float) * 16) != 0 || _modeDirty)
{
Vec3 anchorPoint(_anchorPointInPoints.x , _anchorPointInPoints.y , 0.0f);
Mat4 localToWorld = transform;
localToWorld.translate(anchorPoint);
Vec3 camDir;
switch (_mode)
{
case Mode::VIEW_POINT_ORIENTED:
camDir = Vec3(localToWorld.m[12] - camWorldMat.m[12], localToWorld.m[13] - camWorldMat.m[13], localToWorld.m[14] - camWorldMat.m[14]);
break;
case Mode::VIEW_PLANE_ORIENTED:
camWorldMat.transformVector(Vec3(0.0f, 0.0f, -1.0f), &camDir);
break;
default:
CCASSERT(false, "invalid billboard mode");
break;
}
_modeDirty = false;
if (camDir.length() < MATH_TOLERANCE)
{
camDir.set(camWorldMat.m[8], camWorldMat.m[9], camWorldMat.m[10]);
}
camDir.normalize();
Quaternion rotationQuaternion;
this->getNodeToWorldTransform().getRotation(&rotationQuaternion);
// fetch the rotation angle of z
float rotationZ = atan2(2*(rotationQuaternion.w*rotationQuaternion.z + rotationQuaternion.x*rotationQuaternion.y),
(1 - 2* (rotationQuaternion.y*rotationQuaternion.y + rotationQuaternion.z *rotationQuaternion.z)));
Mat4 rotationMatrix;
rotationMatrix.setIdentity();
rotationMatrix.rotateZ(rotationZ);
Vec3 upAxis = Vec3(rotationMatrix.m[4],rotationMatrix.m[5],rotationMatrix.m[6]);
Vec3 x, y;
camWorldMat.transformVector(upAxis, &y);
Vec3::cross(camDir, y, &x);
x.normalize();
Vec3::cross(x, camDir, &y);
y.normalize();
float xlen = sqrtf(localToWorld.m[0] * localToWorld.m[0] + localToWorld.m[1] * localToWorld.m[1] + localToWorld.m[2] * localToWorld.m[2]);
float ylen = sqrtf(localToWorld.m[4] * localToWorld.m[4] + localToWorld.m[5] * localToWorld.m[5] + localToWorld.m[6] * localToWorld.m[6]);
float zlen = sqrtf(localToWorld.m[8] * localToWorld.m[8] + localToWorld.m[9] * localToWorld.m[9] + localToWorld.m[10] * localToWorld.m[10]);
_billboardTransform.m[0] = x.x * xlen; _billboardTransform.m[1] = x.y * xlen; _billboardTransform.m[2] = x.z * xlen;
_billboardTransform.m[4] = y.x * ylen; _billboardTransform.m[5] = y.y * ylen; _billboardTransform.m[6] = y.z * ylen;
_billboardTransform.m[8] = -camDir.x * zlen; _billboardTransform.m[9] = -camDir.y * zlen; _billboardTransform.m[10] = -camDir.z * zlen;
_billboardTransform.m[12] = localToWorld.m[12]; _billboardTransform.m[13] = localToWorld.m[13]; _billboardTransform.m[14] = localToWorld.m[14];
_billboardTransform.translate(-anchorPoint);
const Mat4 &viewMat = camWorldMat.getInversed();
_zDepthInView = -(viewMat.m[2] * _billboardTransform.m[12] + viewMat.m[6] * _billboardTransform.m[13] + viewMat.m[10] * _billboardTransform.m[14] + viewMat.m[14]);
_mvTransform = transform;
_camWorldMat = camWorldMat;
}
//FIXME: frustum culling here
{
_quadCommand.init(_zDepthInView, _texture->getName(), getGLProgramState(), _blendFunc, &_quad, 1, _billboardTransform);
_quadCommand.setTransparent(true);
renderer->addCommand(&_quadCommand);
}
}