本文整理汇总了C++中SbMatrix::inverse方法的典型用法代码示例。如果您正苦于以下问题:C++ SbMatrix::inverse方法的具体用法?C++ SbMatrix::inverse怎么用?C++ SbMatrix::inverse使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SbMatrix
的用法示例。
在下文中一共展示了SbMatrix::inverse方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: scaleVec
void
SoXipOverlayTransformBoxManip::scale( SoHandleEventAction* action )
{
// Extract the rotation matrix from the view matrix
SbMatrix rotationMatrix = extractRotationMatrix( mXBoundingBox.getInverse() );
// Get the two control points involved in the computation of the scale
// matrix (the one initially picked by the user and its opposit control
// point.
const SbVec3f& cp3d = mControlPointsCoords->point[ mControlPointId ];
const SbVec3f& opp_cp3d = mControlPointsCoords->point[ (mControlPointId + 4) % 8 ];
// Get the projection in the world of the current mouse position
SbVec3f p3d;
getPoint( action, p3d );
// Project the control points and the mouse world position on a xy plane
SbVec3f p2d, cp2d, opp_cp2d;
rotationMatrix.multVecMatrix( cp3d, cp2d );
rotationMatrix.multVecMatrix( opp_cp3d, opp_cp2d );
rotationMatrix.multVecMatrix( p3d, p2d );
SbVec3f refVec = cp2d - opp_cp2d;
SbVec3f movVec = p2d - opp_cp2d;
SbVec3f scaleVec(1, 1, 1);
for( int i = 0; i < 3; ++ i )
{
if( fabs( refVec[i] ) > 0.001 )
scaleVec[i] = movVec[i] / refVec[i];
}
// Compute the 2D scale matrix
SbMatrix scaleMatrix2D;
scaleMatrix2D.setScale( scaleVec );
// Use the opposit control point to center the shape (scale only regarding
// the picked control point)
SbMatrix centerMatrix;
centerMatrix.setTranslate( opp_cp3d );
mTransformationMatrix = centerMatrix.inverse() // Translate a point to the origin
* rotationMatrix // Rotate the plane to a xy aligned plane
* scaleMatrix2D // Scale the point in this plane
* rotationMatrix.inverse() // Rotate back to initial plane
* centerMatrix; // Undo the first translation
transform( mActionNode );
}
示例2: angleBetweenVectors
void
SoXipOverlayTransformBoxManip::rotate( SoHandleEventAction* action )
{
SbVec3f projPt;
getPoint( action, projPt );
const SbVec3f* point = mControlPointsCoords->point.getValues(0);
SbVec3f center = (point[0] + point[4]) / 2.;
SbVec3f rotateFrom = point[mControlPointId] - center;
SbVec3f rotateTo = projPt - center;
SbVec3f normal = mViewVolume.getPlane(0).getNormal();
SbRotation rotation;
rotation.setValue( normal, angleBetweenVectors( rotateFrom, rotateTo, normal ) );
SbMatrix centerMatrix;
centerMatrix.setTranslate( center );
SbMatrix rotationMatrix;
rotationMatrix.setRotate( rotation );
mTransformationMatrix = centerMatrix.inverse() * rotationMatrix * centerMatrix;
transform( mActionNode );
}
示例3:
void
vpSimulator::moveInternalCamera(vpHomogeneousMatrix &cMf)
{
SbMatrix matrix;
SbRotation rotCam;
SbMatrix rotX;
rotX.setRotate (SbRotation (SbVec3f(1.0f, 0.0f, 0.0f), (float)M_PI));
for(unsigned int i=0;i<4;i++)
for(unsigned int j=0;j<4;j++)
matrix[(int)j][(int)i]=(float)cMf[i][j];
matrix= matrix.inverse();
matrix.multLeft (rotX);
rotCam.setValue(matrix);
internalCamera->ref() ;
internalCamera->orientation.setValue(rotCam);
internalCamera->position.setValue(matrix[3][0],matrix[3][1],matrix[3][2]);
internalCamera->unref() ;
rotX.setRotate (SbRotation (SbVec3f(-1.0f, 0.0f, 0.0f), (float)M_PI));
matrix.multLeft (rotX);
rotCam.setValue(matrix);
internalCameraPosition->ref() ;
internalCameraPosition->rotation.setValue(rotCam);
internalCameraPosition->translation.setValue(matrix[3][0],matrix[3][1],matrix[3][2]);
internalCameraPosition->unref() ;
}
示例4:
// Doc from superclass.
void
SoGeoSeparator::getMatrix(SoGetMatrixAction * action)
{
SbMatrix m = this->getTransform(action->getState());
action->getMatrix() = m;
action->getInverse() = m.inverse();
}
示例5: mprIntersect
SbBool XipGeomUtils::mprIntersect(const SbMatrix & m1, const SbMatrix & m2, SbVec3f line[2], float viewportAspectRatio)
{
SbLine objLine, worldLine;
SbVec3f pt1, pt2;
int pc = 0;
SbPlane p1 = planeFromMatrix(m1);
SbPlane p2 = planeFromMatrix(m2);
float width = viewportAspectRatio < 1.f ? 1.f : viewportAspectRatio;
float height = viewportAspectRatio > 1.f ? 1.f : 1.f / viewportAspectRatio;
const SbLine frameLines[4] =
{
SbLine(SbVec3f(-width, -height, 0), SbVec3f(-width, height, 0)),
SbLine(SbVec3f(-width, -height, 0), SbVec3f( width, -height, 0)),
SbLine(SbVec3f( width, height, 0), SbVec3f(-width, height, 0)),
SbLine(SbVec3f( width, height, 0), SbVec3f( width, -height, 0))
};
// First, get intersecting line of the two planes.
if (!planeIntersect(p1, p2, worldLine)) return FALSE;
// Convert intersection line from world into object space before
// testing against frame lines, which are also in object space.
m1.inverse().multLineMatrix(worldLine, objLine);
SbVec3f normal = objLine.getDirection();
normal.normalize();
objLine = SbLine(objLine.getPosition(), objLine.getPosition() + normal);
// Intersect with the 4 lines of frame.
for (int i = 0; i < 4; i++)
{
//if (objLine.getClosestPoints(frameLines[i], pt1, pt2))
//{
// // Valid intersection point. Convert back to world space.
// m1.multVecMatrix(pt1, pt2);
// line[pc++] = pt2;
// if (pc > 1) break;
//}
if ((1.0f - abs(objLine.getDirection().dot(frameLines[i].getDirection()))) > 0.1f)
{
if (objLine.getClosestPoints(frameLines[i], pt1, pt2))
{
// Valid intersection point. Convert back to world space.
m1.multVecMatrix(pt1, pt2);
line[pc++] = pt2;
if (pc > 1) break;
}
}
}
return (pc == 2);
}
示例6:
bool
XipGeomUtils::isInside(const SbVec3f &u, const SbMatrix &model)
{
SbMatrix inv = model.inverse();
SbVec3f v;
inv.multVecMatrix(u, v);
if ( v[0]<0.0f || v[1]<0.0f || v[2]<0.0f ) return false;
if ( v[0]>1.0f || v[1]>1.0f || v[2]>1.0f ) return false;
return true;
}
示例7: noTranslationLine
SbBool
SbCylinder::intersect(const SbLine &line, SbVec3f &enter, SbVec3f &exit) const
//
////////////////////////////////////////////////////////////////////////
{
// The intersection will actually be done on a radius 1 cylinder
// aligned with the y axis, so we transform the line into that
// space, then intersect, then transform the results back.
// rotation to y axis
SbRotation rotToYAxis(axis.getDirection(), SbVec3f(0,1,0));
SbMatrix mtxToYAxis;
mtxToYAxis.setRotate(rotToYAxis);
// scale to unit space
float scaleFactor = 1.0f/radius;
SbMatrix toUnitCylSpace;
toUnitCylSpace.setScale(SbVec3f(scaleFactor, scaleFactor, scaleFactor));
toUnitCylSpace.multLeft(mtxToYAxis);
// find the given line un-translated
SbVec3f origin = line.getPosition();
origin -= axis.getPosition();
SbLine noTranslationLine(origin, origin + line.getDirection());
// find the un-translated line in unit cylinder's space
SbLine cylLine;
toUnitCylSpace.multLineMatrix(noTranslationLine, cylLine);
// find the intersection on the unit cylinder
SbVec3f cylEnter, cylExit;
SbBool intersected = unitCylinderIntersect(cylLine, cylEnter, cylExit);
if (intersected) {
// transform back to original space
SbMatrix fromUnitCylSpace = toUnitCylSpace.inverse();
fromUnitCylSpace.multVecMatrix(cylEnter, enter);
enter += axis.getPosition();
fromUnitCylSpace.multVecMatrix(cylExit, exit);
exit += axis.getPosition();
}
return intersected;
}
示例8:
void
SoSurroundScale::doAction(SoAction *action)
//
////////////////////////////////////////////////////////////////////////
{
SoState *state = action->getState();
SbMatrix theCtm = SoModelMatrixElement::get(state);
if (cacheOK == FALSE )
updateMySurroundParams( action, theCtm.inverse() );
if (doTranslations)
SoModelMatrixElement::translateBy(state, this, cachedTranslation );
else
cachedTranslation.setValue(0,0,0);
SoModelMatrixElement::scaleBy(state, this, cachedScale );
}
示例9: difftrans
/*! \COININTERNAL */
void
SoCenterballDragger::valueChangedCB(void *, SoDragger * d)
{
SoCenterballDragger * thisp = static_cast<SoCenterballDragger *>(d);
SbMatrix matrix = thisp->getMotionMatrix();
SbVec3f t, s;
SbRotation r, so;
// Eliminate center variable of matrix
if (thisp->savedcenter != SbVec3f(0.0f, 0.0f, 0.0f)) {
SbMatrix trans;
trans.setTranslate(thisp->savedcenter);
matrix.multLeft(trans);
trans.setTranslate(-(thisp->savedcenter));
matrix.multRight(trans);
}
// Do an inverse rotation, using matrix with center eliminated
// to obtain correct translation
matrix.getTransform(t, r, s, so);
SbMatrix rotmat;
rotmat.setRotate(r);
//SbMatrix tmp = matrix;
matrix.multLeft(rotmat.inverse());
// Update center of object if dragger has translated
SbVec3f difftrans(matrix[3][0], matrix[3][1], matrix[3][2]);
if (difftrans != SbVec3f(0.0f, 0.0f, 0.0f)) {
thisp->centerFieldSensor->detach();
thisp->center.setValue(thisp->savedcenter + difftrans);
thisp->centerFieldSensor->attach(&thisp->center);
}
thisp->rotFieldSensor->detach();
if (thisp->rotation.getValue() != r) {
thisp->rotation = r;
}
thisp->rotFieldSensor->attach(&thisp->rotation);
}
示例10: evaluate
void SoXipImageAttributes::evaluate()
{
SoXipDataImage *imgData = image.getValue();
if (imgData)
{
SbXipImage *img = imgData->get();
if (img)
{
SO_ENGINE_OUTPUT(modelMatrix, SoSFMatrix, setValue(img->getModelMatrix()));
SO_ENGINE_OUTPUT(bitsStored, SoSFShort, setValue(img->getBitsStored()));
SO_ENGINE_OUTPUT(width, SoSFShort, setValue(img->getDimStored()[0]));
SO_ENGINE_OUTPUT(height, SoSFShort, setValue(img->getDimStored()[1]));
SO_ENGINE_OUTPUT(depth, SoSFShort, setValue(img->getDimStored()[2]));
SbMatrix modelMat = img->getModelMatrix();
SbVec3f t, s;
SbRotation r, so;
modelMat.getTransform(t, r, s, so);
modelMat.multVecMatrix(SbVec3f(0.5, 0.5, 0.5), t);
// scale MPR model matrix always to max. individual dimension by default
float maxScale = s[0] > s[1] ? s[0] : s[1] > s[2] ? s[1] : s[2];
// modelMat.setTransform(t, r, SbVec3f(maxScale, maxScale, maxScale), so);
// when using get/setTransform, the rotation is derived from normal vector
// but for gantry tilt, we need to compute normal from row and column vector
SbVec3f rot[3];
rot[0] = SbVec3f(modelMat[0][0], modelMat[0][1], modelMat[0][2]);
rot[1] = SbVec3f(modelMat[1][0], modelMat[1][1], modelMat[1][2]);
rot[2] = rot[0].cross(rot[1]);
rot[0].normalize();
rot[1].normalize();
rot[2].normalize();
rot[0] *= maxScale;
rot[1] *= maxScale;
rot[2] *= maxScale;
modelMat = SbMatrix(
rot[0][0], rot[0][1], rot[0][2], 0,
rot[1][0], rot[1][1], rot[1][2], 0,
rot[2][0], rot[2][1], rot[2][2], 0,
t[0], t[1], t[2], 1);
// update engine outputs
SbMatrix tmp = SbMatrix::identity();
// flip default viewing direction
tmp.setRotate(SbRotation(SbVec3f(1, 0, 0), M_PI));
SbMatrix defOrient = tmp * modelMat;
// adjust so plane falls onto original plane
defOrient.getTransform(t, r, s, so);
SbVec3f object;
modelMat = img->getModelMatrix();
modelMat.inverse().multVecMatrix(t, object);
object[0] = int(object[0] * img->getDimStored()[0] + 0.5);
object[1] = int(object[1] * img->getDimStored()[1] + 0.5);
object[2] = int(object[2] * img->getDimStored()[2] + 0.5);
object[0] /= img->getDimStored()[0];
object[1] /= img->getDimStored()[1];
object[2] /= img->getDimStored()[2];
modelMat.multVecMatrix(object, t);
defOrient.setTransform(t, r, s, so);
SO_ENGINE_OUTPUT(defaultOrientation, SoSFMatrix, setValue(defOrient));
SbMatrix ortho1, ortho2, ortho3;
int which = XipGeomUtils::orthoOrientations(defOrient, ortho1, ortho2, ortho3);
SO_ENGINE_OUTPUT(orthoScanOrientation, SoSFShort, setValue(which));
SO_ENGINE_OUTPUT(orthoOrientation1, SoSFMatrix, setValue(ortho1));
SO_ENGINE_OUTPUT(orthoOrientation2, SoSFMatrix, setValue(ortho2));
SO_ENGINE_OUTPUT(orthoOrientation3, SoSFMatrix, setValue(ortho3));
defOrient.getTransform(t, r, s, so);
SO_ENGINE_OUTPUT(defaultCenter, SoSFVec3f, setValue(t));
return;
}
}
SO_ENGINE_OUTPUT(modelMatrix, SoSFMatrix, setValue(SbMatrix::identity()));
SO_ENGINE_OUTPUT(bitsStored, SoSFShort, setValue(0));
SO_ENGINE_OUTPUT(width, SoSFShort, setValue(0));
SO_ENGINE_OUTPUT(height, SoSFShort, setValue(0));
SO_ENGINE_OUTPUT(depth, SoSFShort, setValue(0));
SbMatrix rot1, rot2;
SO_ENGINE_OUTPUT(defaultOrientation, SoSFMatrix, setValue(SbMatrix::identity()));
SO_ENGINE_OUTPUT(orthoScanOrientation, SoSFShort, setValue(0));
SO_ENGINE_OUTPUT(orthoOrientation1, SoSFMatrix, setValue(SbMatrix::identity()));
//.........这里部分代码省略.........
示例11: switch
void
SmTextureText2::buildStringQuad(SoAction * action, int idx, SbVec3f & p0, SbVec3f & p1, SbVec3f & p2, SbVec3f & p3)
{
//FIXME: Support multiple strings at one position (multiline text)
SoState * state = action->getState();
const SbString * strings;
const int numstrings = this->getStrings(state, strings);
const SbVec3f * positions;
const int numpositions = this->getPositions(state, positions);
const float * rotations;
const int numrotations = this->getRotations(state, rotations);
const SbVec3f & offset = this->offset.getValue();
Justification halign = static_cast<Justification>(this->justification.getValue());
VerticalJustification valign = static_cast<VerticalJustification>(this->verticalJustification.getValue());
const SbViewVolume & vv = SoViewVolumeElement::get(state);
const SbViewportRegion & vpr = SoViewportRegionElement::get(state);
SbMatrix modelmatrix = SoModelMatrixElement::get(state);
const SmTextureFont::FontImage * font = SmTextureFontElement::get(state);
SbVec2s vpsize = vpr.getViewportSizePixels();
float px = vpsize[0];
float py = vpsize[1];
SbVec3f world, screen;
modelmatrix.multVecMatrix(positions[idx] + offset, world);
vv.projectToScreen(world, screen);
float up, down, left, right;
float width = static_cast<float>(font->stringWidth(strings[idx]));
switch (halign){
case LEFT:
right = width;
left = 0;
break;
case CENTER:
right = width / 2;
left = -right;
break;
case RIGHT:
right = 0.4f;
left = -(width - 0.4f);
break;
}
left /= px;
right /= px;
float ascent = static_cast<float>(font->getAscent());
float descent = static_cast<float>(font->getDescent());
float height = ascent + descent + 1;
switch(valign){
case TOP:
up = 0;
down = -height;
break;
case VCENTER:
up = height / 2;
down = -up;
break;
case BOTTOM://actually BASELINE
up = ascent;
down = -descent;
break;
}
up /= py;
down /= py;
SbMatrix rotation = SbMatrix::identity();
rotation.setRotate(SbRotation(SbVec3f(0, 0, 1), rotations[numrotations > 1 ? idx : 0]));
SbMatrix translation = SbMatrix::identity();
translation.setTranslate(SbVec3f(screen[0], screen[1], 0));
//need to account for viewport aspect ratio as we are working in normalized screen coords:
float aspectx = px >= py ? 1 : py / px;
float aspecty = py >= px ? 1 : px / py;
SbMatrix scale = SbMatrix::identity();
scale.setScale(SbVec3f(aspectx, aspecty, 1));
SbMatrix invScale = scale.inverse();
//screen coords (offsets from text "anchor" point):
SbVec3f offsets[4];
offsets[0] = SbVec3f(left, down, 0);
offsets[1] = SbVec3f(right, down, 0);
offsets[2] = SbVec3f(right, up, 0);
offsets[3] = SbVec3f(left, up, 0);
SbVec2f screenPos[4];
for (int i = 0; i < 4; i++){
SbVec3f & offset = offsets[i];
invScale.multVecMatrix(offset, offset);
rotation.multVecMatrix(offset, offset);
//.........这里部分代码省略.........
示例12: col
// doc from parent
void
SmTextureText2::GLRender(SoGLRenderAction * action)
{
SoState * state = action->getState();
const SbString * strings;
const int numstrings = this->getStrings(state, strings);
const SbVec3f * positions;
const int numpositions = this->getPositions(state, positions);
const float * rotations;
const int numrotations = this->getRotations(state, rotations);
const int32_t * indices;
const int numindices = this->getStringIndices(state, indices);
const int num = numindices > 0 ? numindices : numstrings;
if ((numstrings == 0) || (numstrings == 1 && strings[0] == "") && numindices == 0) return;
SbBool perpart =
SoMaterialBindingElement::get(state) !=
SoMaterialBindingElement::OVERALL;
if (((numstrings == numpositions) || numindices > 0) &&
SmTextureText2CollectorElement::isCollecting(state)) {
SbMatrix modelmatrix = SoModelMatrixElement::get(state);
const SbVec3f & offset = this->offset.getValue();
SbVec3f pos;
SbColor4f col(SoLazyElement::getDiffuse(state, 0),
1.0f - SoLazyElement::getTransparency(state, 0));
for (int i = 0; i < num; i++) {
const int idx = numindices > 0 ? indices[i] : i;
if (perpart) {
col = SbColor4f(SoLazyElement::getDiffuse(state, idx),
1.0f - SoLazyElement::getTransparency(state, idx));
}
pos = positions[idx] + offset;
modelmatrix.multVecMatrix(pos, pos);
SmTextureText2CollectorElement::add(state,
strings[idx],
SmTextureFontElement::get(state),
pos,
this->maxRange.getValue(),
col,
static_cast<Justification>(this->justification.getValue()),
static_cast<VerticalJustification>(this->verticalJustification.getValue()));
}
// invalidate caches to make sure this node is traversed every frame.
SoCacheElement::invalidate(state);
return;
}
SmTextureFontBundle bundle(action);
SoCacheElement::invalidate(state);
if (!this->shouldGLRender(action)) {
return;
}
// set up my font texture
SoLightModelElement::set(state, SoLightModelElement::BASE_COLOR);
SoMaterialBundle mb(action);
mb.sendFirst(); // make sure we have the correct material
SbMatrix modelmatrix = SoModelMatrixElement::get(state);
SbMatrix inv = modelmatrix.inverse();
SbMatrix normalize(0.5f, 0.0f, 0.0f, 0.0f,
0.0f, 0.5f, 0.0f, 0.0f,
0.0f, 0.0f, 1.0f, 0.0f,
0.5f, 0.5f, 0.0f, 1.0f);
SbMatrix projmatrix =
modelmatrix *
SoViewingMatrixElement::get(state) *
SoProjectionMatrixElement::get(state) *
normalize;
const SbViewVolume & vv = SoViewVolumeElement::get(state);
const SbViewportRegion & vp = SoViewportRegionElement::get(state);
const SbVec2s vpsize = vp.getViewportSizePixels();
const SbVec3f & offset = this->offset.getValue();
SbVec3f tmp;
// Set up new view volume
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
glOrtho(0, vpsize[0], 0, vpsize[1], -1.0f, 1.0f);
glPushAttrib(GL_DEPTH_BUFFER_BIT);
glDepthFunc(GL_LEQUAL);
//.........这里部分代码省略.........
示例13: sizeof
void computeMPRCacheLUT(SoXipCPUMprRender *mprRender, T *volBuf, SoState *state)
{
// Clear the contents of the mpr buffer
memset(mprRender->mMPRBuf, 0, (int)mprRender->mMPRSize[0] * (int)mprRender->mMPRSize[1] * sizeof(float) * 4);
// Get some constant sizes ready
const int volWidth = mprRender->mVolDim[0];
const int volHeight = mprRender->mVolDim[1];
const int volDepth = mprRender->mVolDim[2];
const int volSliceSize = volWidth * volHeight;
const float boundX = volWidth - 1.0f;
const float boundY = volHeight - 1.0f;
const float boundZ = volDepth - 1.0f;
// Get bounding box span and start from model matrix
SbMatrix modelMat = SoModelMatrixElement::get(state);
SbVec3f wSpan, wStart;
SbRotation dummy;
modelMat.getTransform(wStart, dummy, wSpan, dummy);
SbMatrix inv = modelMat.inverse();
// Convert the corner points from worldspace to model space
SbVec3f corners[4];
short i;
for (i = 0; i < 4; ++i)
{
inv.multVecMatrix( mprRender->mCorners[i], corners[i] );
corners[i][0] *= boundX;
corners[i][1] *= boundY;
corners[i][2] *= boundZ;
}
SbVec3f vGrad1((corners[0] - corners[3]) / (mprRender->mMPRSize[1] - 1.0f));
SbVec3f vGrad2((corners[1] - corners[2]) / (mprRender->mMPRSize[1] - 1.0f));
SbVec3f vIntrp1 = corners[3];
SbVec3f vIntrp2 = corners[2];
SbVec3f hGrad;
SbVec3f pos;
// Prepare data cache stuff
float neighboursVol[8];
int lastBaseOffsetVol = -1;
int bitRatio = (int)(powf(2, sizeof(T) * 8) / powf(2, mprRender->mVolBitsUsed));
//
mprCacheElem *cacheElem = mprRender->mMPRCache;
float *mprVal = (float*) mprRender->mMPRBuf;
for (i = 0; i < mprRender->mMPRSize[1]; ++i)
{
hGrad = (vIntrp2 - vIntrp1) / (mprRender->mMPRSize[0] - 1.0f);
pos = vIntrp1;
for (short j = 0; j < mprRender->mMPRSize[0]; ++j)
{
// Check if coord is out of bounds
if (pos[0] >= 0 && pos[0] < boundX &&
pos[1] >= 0 && pos[1] < boundY &&
pos[2] >= 0 && pos[2] < boundZ)
{
cacheElem->volCoord[0] = pos[0];
cacheElem->volCoord[1] = pos[1];
cacheElem->volCoord[2] = pos[2];
T val = (T)(sample3Di(volBuf, cacheElem->volCoord, volWidth, volSliceSize, neighboursVol, lastBaseOffsetVol) * bitRatio);
sampleLut(mprVal, val, mprRender->mLutBuf, mprRender->mLutSize);
cacheElem->mprOffset = mprVal - (float*) mprRender->mMPRBuf;
cacheElem++;
}
mprVal += 4;
pos += hGrad;
}
vIntrp1 += vGrad1;
vIntrp2 += vGrad2;
}
mprRender->mNumCacheElems = cacheElem - mprRender->mMPRCache;
}
示例14: drawNaviCube
void NaviCubeImplementation::drawNaviCube(bool pickMode) {
// initializes stuff here when we actually have a context
// FIXME actually now that we have Qt5, we could probably do this earlier (as we do not need the opengl context)
if (!m_NaviCubeInitialised) {
QtGLWidget* gl = static_cast<QtGLWidget*>(m_View3DInventorViewer->viewport());
if (gl == NULL)
return;
initNaviCube(gl);
m_NaviCubeInitialised = true;
}
SoCamera* cam = m_View3DInventorViewer->getSoRenderManager()->getCamera();
if (!cam)
return;
handleResize();
// Store GL state.
glPushAttrib(GL_ALL_ATTRIB_BITS);
GLfloat depthrange[2];
glGetFloatv(GL_DEPTH_RANGE, depthrange);
GLdouble projectionmatrix[16];
glGetDoublev(GL_PROJECTION_MATRIX, projectionmatrix);
glDepthMask(GL_TRUE);
glDepthRange(0.0, 1.0);
glClearDepth(1.0f);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
glDisable(GL_LIGHTING);
//glDisable(GL_BLEND);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
glEnable(GL_TEXTURE_2D);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
//glTexEnvf(GL_TEXTURE_2D, GL_TEXTURE_ENV_MODE, GL_MODULATE);
glDepthMask(GL_TRUE);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
glShadeModel(GL_SMOOTH);
glEnable(GL_CULL_FACE);
glCullFace(GL_BACK);
glFrontFace(GL_CCW);
glAlphaFunc( GL_GREATER, 0.25);
glEnable( GL_ALPHA_TEST);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
const float NEARVAL = 0.1f;
const float FARVAL = 10.0f;
const float dim = NEARVAL * float(tan(M_PI / 8.0))*1.2;
glFrustum(-dim, dim, -dim, dim, NEARVAL, FARVAL);
SbMatrix mx;
mx = cam->orientation.getValue();
mx = mx.inverse();
mx[3][2] = -5.0;
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadMatrixf((float*) mx);
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
if (pickMode) {
glDisable(GL_BLEND);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glShadeModel(GL_FLAT);
glDisable(GL_DITHER);
glDisable(GL_POLYGON_SMOOTH);
}
else {
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
}
glClear(GL_DEPTH_BUFFER_BIT);
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(3, GL_FLOAT, 0, (void*) m_VertexArray.data());
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glTexCoordPointer(2, GL_FLOAT, 0, m_TextureCoordArray.data());
if (!pickMode) {
// Draw the axes
glDisable(GL_TEXTURE_2D);
float a=1.1f;
//.........这里部分代码省略.........
示例15: pitch
void
SoXipNeheStarGenerator::GLRender(SoGLRenderAction *action)
{
float yawAngle = 0;
static float spinAngle = 0;
float distance = 0;
float pitchAngle = M_PI /2; // tilt the view
SbRotation pitch(SbVec3f(1, 0, 0), pitchAngle); // rotation around X
SbMatrix pitchM;
pitch.getValue(pitchM);
SbRotation yaw = SbRotation::identity();
SbMatrix yawM = SbMatrix::identity();
SbRotation spin = SbRotation::identity();
SbMatrix spinM = SbMatrix::identity();
for (int i = 0; i < MAX_STARS; i++)
{
SoXipNeheStar* star = static_cast<SoXipNeheStar*>(this->getChild(i));
// spin angle for this star
spin.setValue(SbVec3f(0,0,1), spinAngle); // rotation around Z
spin.getValue(spinM);
// yaw angle for this star
//_starInfos[i].angle += ((float(i)/MAX_STARS) * (180 / M_PI));
yawAngle = _starInfos[i].angle;
yaw.setValue(SbVec3f(0,1,0), yawAngle); // rotation around Y
yaw.getValue(yawM);
// let's compose all matrices once to position each star
SbMatrix transM = SbMatrix::identity();
transM.setTranslate(SbVec3f(_starInfos[i].distance,0,0));
SbMatrix transform = spinM * pitchM.inverse() * yawM.inverse() * transM * yawM * pitchM ;
// position the star
star->trans.setValue(transform);
unsigned int color = convertRGBtoHex(_starInfos[i].r, _starInfos[i].g, _starInfos[i].b);
star->color.set1Value(0, color);
star->color.set1Value(1, color);
star->color.set1Value(2, color);
star->color.set1Value(3, color);
spinAngle += ( 0.01f * (M_PI / 180));
// change setting of all stars except the very first one (index 0)
if (i)
{
_starInfos[i].angle += ((float(i)/MAX_STARS) * ( M_PI / 180));
_starInfos[i].distance -= 0.01f;
if (_starInfos[i].distance < 0.0f)
{
_starInfos[i].distance += 5.0f;
_starInfos[i].r= rand() % 255 + 1 ;
_starInfos[i].g= rand() % 255 + 1;
_starInfos[i].b= rand() % 255 + 1;
}
}
}
SoXipKit::GLRender(action);
}