本文整理汇总了C++中Plane3::project方法的典型用法代码示例。如果您正苦于以下问题:C++ Plane3::project方法的具体用法?C++ Plane3::project怎么用?C++ Plane3::project使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Plane3
的用法示例。
在下文中一共展示了Plane3::project方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: doTransform
void ParaxialTexCoordSystem::doTransform(const Plane3& oldBoundary, const Mat4x4& transformation, BrushFaceAttributes& attribs, bool lockTexture, const Vec3& oldInvariant) {
const Vec3 offset = transformation * Vec3::Null;
const Vec3& oldNormal = oldBoundary.normal;
Vec3 newNormal = transformation * oldNormal - offset;
assert(Math::eq(newNormal.length(), 1.0));
// fix some rounding errors - if the old and new texture axes are almost the same, use the old axis
if (newNormal.equals(oldNormal, 0.01))
newNormal = oldNormal;
if (!lockTexture || attribs.xScale() == 0.0f || attribs.yScale() == 0.0f) {
setRotation(newNormal, attribs.rotation(), attribs.rotation());
return;
}
// calculate the current texture coordinates of the origin
const Vec2f oldInvariantTexCoords = computeTexCoords(oldInvariant, attribs.scale()) + attribs.offset();
// project the texture axes onto the boundary plane along the texture Z axis
const Vec3 boundaryOffset = oldBoundary.project(Vec3::Null, getZAxis());
const Vec3 oldXAxisOnBoundary = oldBoundary.project(m_xAxis * attribs.xScale(), getZAxis()) - boundaryOffset;
const Vec3 oldYAxisOnBoundary = oldBoundary.project(m_yAxis * attribs.yScale(), getZAxis()) - boundaryOffset;
// transform the projected texture axes and compensate the translational component
const Vec3 transformedXAxis = transformation * oldXAxisOnBoundary - offset;
const Vec3 transformedYAxis = transformation * oldYAxisOnBoundary - offset;
const Vec2f textureSize = attribs.textureSize();
const bool preferX = textureSize.x() >= textureSize.y();
/*
const FloatType dotX = transformedXAxis.normalized().dot(oldXAxisOnBoundary.normalized());
const FloatType dotY = transformedYAxis.normalized().dot(oldYAxisOnBoundary.normalized());
const bool preferX = Math::abs(dotX) < Math::abs(dotY);
*/
// obtain the new texture plane norm and the new base texture axes
Vec3 newBaseXAxis, newBaseYAxis, newProjectionAxis;
const size_t newIndex = planeNormalIndex(newNormal);
axes(newIndex, newBaseXAxis, newBaseYAxis, newProjectionAxis);
const Plane3 newTexturePlane(0.0, newProjectionAxis);
// project the transformed texture axes onto the new texture projection plane
const Vec3 projectedTransformedXAxis = newTexturePlane.project(transformedXAxis);
const Vec3 projectedTransformedYAxis = newTexturePlane.project(transformedYAxis);
assert(!projectedTransformedXAxis.nan() &&
!projectedTransformedYAxis.nan());
const Vec3 normalizedXAxis = projectedTransformedXAxis.normalized();
const Vec3 normalizedYAxis = projectedTransformedYAxis.normalized();
// determine the rotation angle from the dot product of the new base axes and the transformed, projected and normalized texture axes
float cosX = static_cast<float>(newBaseXAxis.dot(normalizedXAxis.normalized()));
float cosY = static_cast<float>(newBaseYAxis.dot(normalizedYAxis.normalized()));
assert(!Math::isnan(cosX));
assert(!Math::isnan(cosY));
float radX = std::acos(cosX);
if (crossed(newBaseXAxis, normalizedXAxis).dot(newProjectionAxis) < 0.0)
radX *= -1.0f;
float radY = std::acos(cosY);
if (crossed(newBaseYAxis, normalizedYAxis).dot(newProjectionAxis) < 0.0)
radY *= -1.0f;
// TODO: be smarter about choosing between the X and Y axis rotations - sometimes either
// one can be better
float rad = preferX ? radX : radY;
// for some reason, when the texture plane normal is the Y axis, we must rotation clockwise
if (newIndex == 4)
rad *= -1.0f;
const float newRotation = Math::correct(Math::normalizeDegrees(Math::degrees(rad)), 4);
doSetRotation(newNormal, newRotation, newRotation);
// finally compute the scaling factors
Vec2f newScale = Vec2f(projectedTransformedXAxis.length(),
projectedTransformedYAxis.length()).corrected(4);
// the sign of the scaling factors depends on the angle between the new texture axis and the projected transformed axis
if (m_xAxis.dot(normalizedXAxis) < 0.0)
newScale[0] *= -1.0f;
if (m_yAxis.dot(normalizedYAxis) < 0.0)
newScale[1] *= -1.0f;
// compute the parameters of the transformed texture coordinate system
const Vec3 newInvariant = transformation * oldInvariant;
// determine the new texture coordinates of the transformed center of the face, sans offsets
const Vec2f newInvariantTexCoords = computeTexCoords(newInvariant, newScale);
// since the center should be invariant, the offsets are determined by the difference of the current and
// the original texture coordiknates of the center
const Vec2f newOffset = attribs.modOffset(oldInvariantTexCoords - newInvariantTexCoords).corrected(4);
assert(!newOffset.nan());
assert(!newScale.nan());
assert(!Math::isnan(newRotation));
//.........这里部分代码省略.........