本文整理汇总了C++中Matrix44f::invert方法的典型用法代码示例。如果您正苦于以下问题:C++ Matrix44f::invert方法的具体用法?C++ Matrix44f::invert怎么用?C++ Matrix44f::invert使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Matrix44f
的用法示例。
在下文中一共展示了Matrix44f::invert方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: unproject
/* transforms clip-space coordinates to object-space coordinates,
where z is within range [0.0 - 1.0] from near-plane to far-plane */
Vec3f Node::unproject(float x, float y, float z) const
{
// get viewport and projection matrix
Area viewport = gl::getViewport();
Matrix44f projection = gl::getProjection();
// find the inverse modelview-projection-matrix
Matrix44f mvp = projection * mWorldTransform;
mvp.invert(0.0f);
// map x and y from window coordinates
Vec4f in(x, float(viewport.getHeight()) - y - 1.0f, z, 1.0f);
in.x = (in.x - viewport.getX1()) / float( viewport.getWidth() );
in.y = (in.y - viewport.getY1()) / float( viewport.getHeight() );
// map to range [-1..1]
in.x = 2.0f * in.x - 1.0f;
in.y = 2.0f * in.y - 1.0f;
in.z = 2.0f * in.z - 1.0f;
//
Vec4f out = mvp * in;
if(out.w != 0.0f) out.w = 1.0f / out.w;
Vec3f result;
result.x = out.x * out.w;
result.y = out.y * out.w;
result.z = out.z * out.w;
return result;
}
示例2:
//----------------------------------------------------------------------------------------------------------------------
ci::Vec3f View::unproject(const ci::Vec3f& point)
{
// Find the inverse Modelview-Projection-Matrix
Matrix44f mInvMVP = ci::gl::getProjection() * ci::gl::getModelView();
mInvMVP.invert();
// Transform to normalized coordinates in the range [-1, 1]
Vec4f pointNormal;
ci::Area viewport = ci::gl::getViewport();
pointNormal.x = (point.x - viewport.getX1()) / viewport.getWidth() * 2.0f - 1.0f;
pointNormal.y = (point.y - viewport.getY1()) / viewport.getHeight() * 2.0f;
pointNormal.z = 2.0f * point.z - 1.0f;
pointNormal.w = 1.0f;
// Find the object's coordinates
Vec4f pointCoord = mInvMVP * pointNormal;
if (pointCoord.w != 0.0f)
{
pointCoord.w = 1.0f / pointCoord.w;
}
// Return coordinate
return Vec3f(pointCoord.x * pointCoord.w,
pointCoord.y * pointCoord.w,
pointCoord.z * pointCoord.w);
}
示例3:
Matrix44f Matrix44f::inverted( void )
{
Matrix44f m = *this;
m.invert();
return m;
}