本文整理汇总了C++中GfMatrix4d类的典型用法代码示例。如果您正苦于以下问题:C++ GfMatrix4d类的具体用法?C++ GfMatrix4d怎么用?C++ GfMatrix4d使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了GfMatrix4d类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: powf
GlfSimpleLight
HdStLight::_ApproximateAreaLight(SdfPath const &id,
HdSceneDelegate *sceneDelegate)
{
// Get the color of the light
GfVec3f hdc = sceneDelegate->GetLightParamValue(id, HdStLightTokens->color)
.Get<GfVec3f>();
// Extract intensity
float intensity =
sceneDelegate->GetLightParamValue(id, HdLightTokens->intensity)
.Get<float>();
// Extract the exposure of the light
float exposure =
sceneDelegate->GetLightParamValue(id, HdLightTokens->exposure)
.Get<float>();
intensity *= powf(2.0f, GfClamp(exposure, -50.0f, 50.0f));
// Calculate the final color of the light
GfVec4f c(hdc[0]*intensity, hdc[1]*intensity, hdc[2]*intensity, 1.0f);
// Get the transform of the light
GfMatrix4d transform = _params[HdTokens->transform].Get<GfMatrix4d>();
GfVec3d hdp = transform.ExtractTranslation();
GfVec4f p = GfVec4f(hdp[0], hdp[1], hdp[2], 1.0f);
// Create the Glf Simple Light object that will be used by the rest
// of the pipeline. No support for shadows for this translated light.
GlfSimpleLight l;
l.SetPosition(p);
l.SetDiffuse(c);
l.SetHasShadow(false);
return l;
}
示例2:
GfMatrix4d
GfFrustum::ComputeViewMatrix() const
{
GfMatrix4d m;
m.SetLookAt(_position, _rotation);
return m;
}
示例3: ComputeViewInverse
vector<GfVec3d>
GfFrustum::ComputeCornersAtDistance(double d) const
{
const GfVec2d &winMin = _window.GetMin();
const GfVec2d &winMax = _window.GetMax();
vector<GfVec3d> corners;
corners.reserve(4);
if (_projectionType == Perspective) {
// Similar to ComputeCorners
corners.push_back(GfVec3d(d * winMin[0], d * winMin[1], -d));
corners.push_back(GfVec3d(d * winMax[0], d * winMin[1], -d));
corners.push_back(GfVec3d(d * winMin[0], d * winMax[1], -d));
corners.push_back(GfVec3d(d * winMax[0], d * winMax[1], -d));
}
else {
corners.push_back(GfVec3d(winMin[0], winMin[1], -d));
corners.push_back(GfVec3d(winMax[0], winMin[1], -d));
corners.push_back(GfVec3d(winMin[0], winMax[1], -d));
corners.push_back(GfVec3d(winMax[0], winMax[1], -d));
}
// Each corner is then transformed into world space by the inverse
// of the view matrix.
const GfMatrix4d m = ComputeViewInverse();
for (int i = 0; i < 4; i++)
corners[i] = m.Transform(corners[i]);
return corners;
}
示例4: GfMatrix4d
GfMatrix4d
Hdx_UnitTestGLDrawing::GetViewMatrix() const
{
GfMatrix4d viewMatrix;
viewMatrix.SetIdentity();
// rotate from z-up to y-up
viewMatrix *= GfMatrix4d().SetRotate(GfRotation(GfVec3d(1.0,0.0,0.0), -90.0));
viewMatrix *= GfMatrix4d().SetRotate(GfRotation(GfVec3d(0, 1, 0), _rotate[1]));
viewMatrix *= GfMatrix4d().SetRotate(GfRotation(GfVec3d(1, 0, 0), _rotate[0]));
viewMatrix *= GfMatrix4d().SetTranslate(GfVec3d(_translate[0], _translate[1], _translate[2]));
return viewMatrix;
}
示例5:
/* virtual */
void
HdSt_TestLightingShader::SetCamera(GfMatrix4d const &worldToViewMatrix,
GfMatrix4d const &projectionMatrix)
{
for (int i = 0; i < 2; ++i) {
_lights[i].eyeDir
= worldToViewMatrix.TransformDir(_lights[i].dir).GetNormalized();
}
}
示例6: flip
void
GfFrustum::SetPositionAndRotationFromMatrix(
const GfMatrix4d &camToWorldXf)
{
// First conform matrix to be...
GfMatrix4d conformedXf = camToWorldXf;
// ... right handed
if (!conformedXf.IsRightHanded()) {
static GfMatrix4d flip(GfVec4d(-1.0, 1.0, 1.0, 1.0));
conformedXf = flip * conformedXf;
}
// ... and orthonormal
conformedXf.Orthonormalize();
SetRotation(conformedXf.ExtractRotation());
SetPosition(conformedXf.ExtractTranslation());
}
示例7: _RotMatToRotXYZ
// Assumes rotationOrder is XYZ.
static void
_RotMatToRotXYZ(
const GfMatrix4d &rotMat,
GfVec3f *rotXYZ)
{
GfRotation rot = rotMat.ExtractRotation();
GfVec3d angles = rot.Decompose(GfVec3d::ZAxis(),
GfVec3d::YAxis(),
GfVec3d::XAxis());
*rotXYZ = GfVec3f(angles[2], angles[1], angles[0]);
}
示例8: GfDot
GfPlane &
GfPlane::Transform(const GfMatrix4d &matrix)
{
// Compute the point on the plane along the normal from the origin.
GfVec3d pointOnPlane = _distance * _normal;
// Transform the plane normal by the adjoint of the matrix to get
// the new normal. The adjoint (inverse transpose) is used to
// multiply normals so they are not scaled incorrectly.
GfMatrix4d adjoint = matrix.GetInverse().GetTranspose();
_normal = adjoint.TransformDir(_normal).GetNormalized();
// Transform the point on the plane by the matrix.
pointOnPlane = matrix.Transform(pointOnPlane);
// The new distance is the projected distance of the vector to the
// transformed point onto the (unit) transformed normal. This is
// just a dot product.
_distance = GfDot(pointOnPlane, _normal);
return *this;
}
示例9: _RotMatToRotTriplet
// Assumes rotationOrder is XYZ.
static void
_RotMatToRotTriplet(
const GfMatrix4d &rotMat,
GfVec3d *rotTriplet)
{
GfRotation rot = rotMat.ExtractRotation();
GfVec3d angles = rot.Decompose(GfVec3d::ZAxis(),
GfVec3d::YAxis(),
GfVec3d::XAxis());
(*rotTriplet)[0] = angles[2];
(*rotTriplet)[1] = angles[1];
(*rotTriplet)[2] = angles[0];
}
示例10: _MatrixToVectorsWithPivotInvariant
static void
_MatrixToVectorsWithPivotInvariant(
const GfMatrix4d &m,
const GfVec3d pivotPosition,
const GfVec3d pivotOrientation,
GfVec3d *translation,
GfVec3d *rotation,
GfVec3d *scale,
GfVec3d *scaleOrientation)
{
GfMatrix3d pivotOrientMat = _EulerXYZToMatrix3d(pivotOrientation);
GfMatrix4d pp = GfMatrix4d(1.0).SetTranslate( pivotPosition);
GfMatrix4d ppInv = GfMatrix4d(1.0).SetTranslate(-pivotPosition);
GfMatrix4d po = GfMatrix4d(1.0).SetRotate(pivotOrientMat);
GfMatrix4d poInv = GfMatrix4d(1.0).SetRotate(pivotOrientMat.GetInverse());
GfMatrix4d factorMe = po * pp * m * ppInv;
GfMatrix4d scaleOrientMat, factoredRotMat, perspMat;
factorMe.Factor(&scaleOrientMat, scale, &factoredRotMat,
translation, &perspMat);
GfMatrix4d rotMat = factoredRotMat * poInv;
if(not rotMat.Orthonormalize(/* issueWarning */ false))
TF_WARN("Failed to orthonormalize rotMat.");
_RotMatToRotTriplet(rotMat, rotation);
if(not scaleOrientMat.Orthonormalize(/* issueWarning */ false))
TF_WARN("Failed to orthonormalize scaleOrientMat.");
_RotMatToRotTriplet(scaleOrientMat, scaleOrientation);
}
示例11: _IsMatrixIdentity
static
bool
_IsMatrixIdentity(const GfMatrix4d& matrix)
{
const GfMatrix4d IDENTITY(1.0);
const double TOLERANCE = 1e-6;
if (GfIsClose(matrix.GetRow(0), IDENTITY.GetRow(0), TOLERANCE) &&
GfIsClose(matrix.GetRow(1), IDENTITY.GetRow(1), TOLERANCE) &&
GfIsClose(matrix.GetRow(2), IDENTITY.GetRow(2), TOLERANCE) &&
GfIsClose(matrix.GetRow(3), IDENTITY.GetRow(3), TOLERANCE)) {
return true;
}
return false;
}
示例12: _ConvertMatrixToComponents
static void
_ConvertMatrixToComponents(const GfMatrix4d &matrix,
GfVec3d *translation,
GfVec3f *rotation,
GfVec3f *scale)
{
GfMatrix4d rotMat(1.0);
GfVec3d doubleScale(1.0);
GfMatrix4d scaleOrientMatUnused, perspMatUnused;
matrix.Factor(&scaleOrientMatUnused, &doubleScale, &rotMat,
translation, &perspMatUnused);
*scale = GfVec3f(doubleScale[0], doubleScale[1], doubleScale[2]);
if (!rotMat.Orthonormalize(/* issueWarning */ false))
TF_WARN("Failed to orthonormalize rotation matrix.");
_RotMatToRotXYZ(rotMat, rotation);
}
示例13: PxrUsdKatanaReadPointInstancer
//.........这里部分代码省略.........
//
UsdAttribute positionsAttr = instancer.GetPositionsAttr();
if (!positionsAttr.HasValue())
{
_LogAndSetError(instancerAttrMap, "Instancer has no positions");
return;
}
//
// Compute instance transform matrices.
//
const double timeCodesPerSecond = stage->GetTimeCodesPerSecond();
// Gather frame-relative sample times and add them to the current time to
// generate absolute sample times.
//
const std::vector<double> &motionSampleTimes =
data.GetMotionSampleTimes(positionsAttr);
const size_t sampleCount = motionSampleTimes.size();
std::vector<UsdTimeCode> sampleTimes(sampleCount);
for (size_t a = 0; a < sampleCount; ++a)
{
sampleTimes[a] = UsdTimeCode(currentTime + motionSampleTimes[a]);
}
// Get velocityScale from the opArgs.
//
float velocityScale = FnKat::FloatAttribute(
inputAttrs.getChildByName("opArgs.velocityScale")).getValue(1.0f, false);
// XXX Replace with UsdGeomPointInstancer::ComputeInstanceTransformsAtTime.
//
std::vector<std::vector<GfMatrix4d>> xformSamples(sampleCount);
const size_t numXformSamples =
_ComputeInstanceTransformsAtTime(xformSamples, instancer, sampleTimes,
UsdTimeCode(currentTime), timeCodesPerSecond, numInstances,
positionsAttr, velocityScale);
if (numXformSamples == 0) {
_LogAndSetError(instancerAttrMap, "Could not compute "
"sample/topology-invarying instance "
"transform matrix");
return;
}
//
// Compute prototype bounds.
//
bool aggregateBoundsValid = false;
std::vector<double> aggregateBounds;
// XXX Replace with UsdGeomPointInstancer::ComputeExtentAtTime.
//
VtVec3fArray aggregateExtent;
if (_ComputeExtentAtTime(
aggregateExtent, data.GetUsdInArgs(), xformSamples,
motionSampleTimes, protoIndices, protoPaths, primCache,
pruneMaskValues)) {
aggregateBoundsValid = true;
aggregateBounds.resize(6);
aggregateBounds[0] = aggregateExtent[0][0]; // min x
aggregateBounds[1] = aggregateExtent[1][0]; // max x
aggregateBounds[2] = aggregateExtent[0][1]; // min y
aggregateBounds[3] = aggregateExtent[1][1]; // max y
aggregateBounds[4] = aggregateExtent[0][2]; // min z
示例14: SetUseLighting
void
GlfSimpleLightingContext::SetStateFromOpenGL()
{
// import classic GL light's parameters into shaded lights
SetUseLighting(glIsEnabled(GL_LIGHTING));
GfMatrix4d worldToViewMatrix;
glGetDoublev(GL_MODELVIEW_MATRIX, worldToViewMatrix.GetArray());
GfMatrix4d viewToWorldMatrix = worldToViewMatrix.GetInverse();
GLint nLights = 0;
glGetIntegerv(GL_MAX_LIGHTS, &nLights);
GlfSimpleLightVector lights;
lights.reserve(nLights);
GlfSimpleLight light;
for(int i = 0; i < nLights; ++i)
{
int lightName = GL_LIGHT0 + i;
if (glIsEnabled(lightName)) {
GLfloat position[4], color[4];
glGetLightfv(lightName, GL_POSITION, position);
light.SetPosition(GfVec4f(position)*viewToWorldMatrix);
glGetLightfv(lightName, GL_AMBIENT, color);
light.SetAmbient(GfVec4f(color));
glGetLightfv(lightName, GL_DIFFUSE, color);
light.SetDiffuse(GfVec4f(color));
glGetLightfv(lightName, GL_SPECULAR, color);
light.SetSpecular(GfVec4f(color));
lights.push_back(light);
}
}
SetLights(lights);
GlfSimpleMaterial material;
GLfloat color[4], shininess;
glGetMaterialfv(GL_FRONT, GL_AMBIENT, color);
material.SetAmbient(GfVec4f(color));
glGetMaterialfv(GL_FRONT, GL_DIFFUSE, color);
material.SetDiffuse(GfVec4f(color));
glGetMaterialfv(GL_FRONT, GL_SPECULAR, color);
material.SetSpecular(GfVec4f(color));
glGetMaterialfv(GL_FRONT, GL_EMISSION, color);
material.SetEmission(GfVec4f(color));
glGetMaterialfv(GL_FRONT, GL_SHININESS, &shininess);
// clamp to 0.0001, since pow(0,0) is undefined in GLSL.
shininess = std::max(0.0001f, shininess);
material.SetShininess(shininess);
SetMaterial(material);
GfVec4f sceneAmbient;
glGetFloatv(GL_LIGHT_MODEL_AMBIENT, &sceneAmbient[0]);
SetSceneAmbient(sceneAmbient);
}
示例15: ComputeViewDirection
GfFrustum &
GfFrustum::Transform(const GfMatrix4d &matrix)
{
// We'll need the old parameters as we build up the new ones, so, work
// on a newly instantiated frustum. We'll replace the contents of
// this frustum with it once we are done. Note that _dirty is true
// by default, so, there is no need to initialize it here.
GfFrustum frustum;
// Copy the projection type
frustum._projectionType = _projectionType;
// Transform the position of the frustum
frustum._position = matrix.Transform(_position);
// Transform the rotation as follows:
// 1. build view and direction vectors
// 2. transform them with the given matrix
// 3. normalize the vectors and cross them to build an orthonormal frame
// 4. construct a rotation matrix
// 5. extract the new rotation from the matrix
// Generate view direction and up vector
GfVec3d viewDir = ComputeViewDirection();
GfVec3d upVec = ComputeUpVector();
// Transform by matrix
GfVec3d viewDirPrime = matrix.TransformDir(viewDir);
GfVec3d upVecPrime = matrix.TransformDir(upVec);
// Normalize. Save the vec size since it will be used to scale near/far.
double scale = viewDirPrime.Normalize();
upVecPrime.Normalize();
// Cross them to get the third axis. Voila. We have an orthonormal frame.
GfVec3d viewRightPrime = GfCross(viewDirPrime, upVecPrime);
viewRightPrime.Normalize();
// Construct a rotation matrix using the axes.
//
// [ right 0 ]
// [ up 1 ]
// [ -viewDir 0 ]
// [ 0 0 0 1 ]
GfMatrix4d rotMatrix;
rotMatrix.SetIdentity();
// first row
rotMatrix[0][0] = viewRightPrime[0];
rotMatrix[0][1] = viewRightPrime[1];
rotMatrix[0][2] = viewRightPrime[2];
// second row
rotMatrix[1][0] = upVecPrime[0];
rotMatrix[1][1] = upVecPrime[1];
rotMatrix[1][2] = upVecPrime[2];
// third row
rotMatrix[2][0] = -viewDirPrime[0];
rotMatrix[2][1] = -viewDirPrime[1];
rotMatrix[2][2] = -viewDirPrime[2];
// Extract rotation
frustum._rotation = rotMatrix.ExtractRotation();
// Since we applied the matrix to the direction vector, we can use
// its length to find out the scaling that needs to applied to the
// near and far plane.
frustum._nearFar = _nearFar * scale;
// Use the same length to scale the view distance
frustum._viewDistance = _viewDistance * scale;
// Transform the reference plane as follows:
//
// - construct two 3D points that are on the reference plane
// (left/bottom and right/top corner of the reference window)
// - transform the points with the given matrix
// - move the window back to one unit from the viewpoint and
// extract the 2D coordinates that would form the new reference
// window
//
// A note on how we do the last "move" of the reference window:
// Using similar triangles and the fact that the reference window
// is one unit away from the viewpoint, one can show that it's
// sufficient to divide the x and y components of the transformed
// corners by the length of the transformed direction vector.
//
// A 2D diagram helps:
//
// |
// |
// | |
// * ------+------------+
// vp |y1 |
// |
// \--d1--/ |y2
//
// \-------d2----------/
//
// So, y1/y2 = d1/d2 ==> y1 = y2 * d1/d2
//.........这里部分代码省略.........