本文整理汇总了C++中SbMatrix::setRotate方法的典型用法代码示例。如果您正苦于以下问题:C++ SbMatrix::setRotate方法的具体用法?C++ SbMatrix::setRotate怎么用?C++ SbMatrix::setRotate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SbMatrix
的用法示例。
在下文中一共展示了SbMatrix::setRotate方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
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() ;
}
示例2: rotation
void
vpSimulator::getExternalCameraPosition(vpHomogeneousMatrix &cMf)
{
/* SoCamera *camera ;
camera = this->externalView->getCamera() ;*/
SoSFVec3f position = externalCamera->position ;
// get the rotation
SoSFRotation orientation = externalCamera->orientation;
SbVec3f axis ; float angle ;
orientation.getValue(axis,angle) ;
SbRotation rotation(axis,angle) ;
// get the translation
SbVec3f t ;
t = position.getValue() ;
SbMatrix matrix ;
matrix.setRotate(rotation) ;
vpHomogeneousMatrix fMc ;
SbMatrix rotX;
rotX.setRotate (SbRotation (SbVec3f(1.0f, 0.0f, 0.0f), (float)M_PI));
matrix.multLeft (rotX);
for(unsigned int i=0;i<4;i++)
for(unsigned int j=0;j<4;j++)
fMc[j][i]=matrix[(int)i][(int)j];
fMc[0][3] = t[0] ;
fMc[1][3] = t[1] ;
fMc[2][3] = t[2] ;
cMf = fMc.inverse() ;
}
示例3: 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 );
}
示例4: rotateBy
/*!
virtual method which is called from rotateBy().
Appends \a rotation to the element matrix.
*/
void
SoBumpMapMatrixElement::rotateEltBy(const SbRotation & rotation)
{
SbMatrix matrix = SbMatrix::identity();
matrix.setRotate(rotation);
this->bumpMapMatrix.multLeft(matrix);
}
示例5:
SbMatrix
extractRotationMatrix( const SbMatrix& matrix )
{
SbVec3f t, s;
SbRotation r, so;
matrix.getTransform( t, r, s, so );
SbMatrix rotationMatrix;
rotationMatrix.setRotate(r);
return rotationMatrix;
}
示例6: 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;
}
示例7:
/*!
Should be called after motion matrix has been updated by a child
dragger.
*/
void
SoCenterballDragger::transferCenterDraggerMotion(SoDragger * childdragger)
{
if (coin_assert_cast<SoNode *>(childdragger) == XCenterChanger.getValue() ||
coin_assert_cast<SoNode *>(childdragger) == YCenterChanger.getValue() ||
coin_assert_cast<SoNode *>(childdragger) == ZCenterChanger.getValue()) {
// translate part of matrix should not change. Move motion
// into center instead.
SbVec3f transl;
SbMatrix matrix = this->getMotionMatrix();
transl[0] = matrix[3][0];
transl[1] = matrix[3][1];
transl[2] = matrix[3][2];
SbVec3f difftransl = transl - this->savedtransl;
{ // consider rotation before translating
SbRotation rot = this->rotation.getValue();
SbMatrix tmp;
tmp.setRotate(rot.inverse());
tmp.multVecMatrix(difftransl, difftransl);
}
this->centerFieldSensor->detach();
this->center = difftransl + this->savedcenter;
this->centerFieldSensor->attach(&this->center);
matrix[3][0] = this->savedtransl[0];
matrix[3][1] = this->savedtransl[1];
matrix[3][2] = this->savedtransl[2];
SbBool oldval = this->enableValueChangedCallbacks(FALSE);
this->setMotionMatrix(matrix);
this->enableValueChangedCallbacks(oldval);
SoMatrixTransform *mt = SO_GET_ANY_PART(this, "translateToCenter", SoMatrixTransform);
matrix.setTranslate(this->center.getValue());
mt->matrix = matrix;
}
}
示例8: 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);
}
示例9: 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()));
//.........这里部分代码省略.........
示例10: switch
//.........这里部分代码省略.........
HALF_CONV(type2,type1,valType1)
// Simple conversions for most fields:
CONV(Bool,SbBool,Float,float);
CONV(Bool,SbBool,Int32,int32_t);
CONV(Bool,SbBool,Short,short);
CONV(Bool,SbBool,UInt32,uint32_t);
CONV(Bool,SbBool,UShort,unsigned short);
CONV(Color,const SbColor &,Vec3f,const SbVec3f &);
CONV(Float,float,Int32,int32_t);
CONV(Float,float,Short,short);
CONV(Float,float,UInt32,uint32_t);
CONV(Float,float,UShort,unsigned short);
CONV(Int32,int32_t,Short,short);
CONV(Int32,int32_t,UInt32,uint32_t);
CONV(Int32,int32_t,UShort,unsigned short);
CONV(Short,short,UInt32,uint32_t);
CONV(Short,short,UShort,unsigned short);
CONV(UInt32,uint32_t,UShort,unsigned short);
// Some wacky oddball conversions that we have to special-case:
// Float to time can be handled by regular code because SbTime has a
// constructor that takes a float, but time to float needs to be
// special-cased:
HALF_CONV(Float, Time, float);
CASE(SFTime, SFFloat):
((SoSFFloat *)outField)->setValue(
((SoSFTime *)input)->getValue().getValue());
break;
CASE(SFTime, MFFloat):
((SoMFFloat *)outField)->setValue(
((SoSFTime *)input)->getValue().getValue());
break;
CASE(MFTime, SFFloat):
((SoSFFloat *)outField)->setValue(
(*(SoMFTime *)input)[0].getValue());
break;
CASE(MFTime, MFFloat):
for (i = 0; i < ((SoMFTime *)input)->getNum(); i++) {
((SoMFFloat *)outField)->set1Value(i,
(*(SoMFTime *)input)[i].getValue());
}
break;
CASE(SFMatrix, SFRotation):
((SoSFRotation *) outField)->setValue(
SbRotation(((SoSFMatrix *) input)->getValue()));
break;
CASE(SFMatrix, MFRotation):
((SoMFRotation *) outField)->setValue(
SbRotation(((SoSFMatrix *) input)->getValue()));
break;
CASE(MFMatrix, SFRotation):
((SoSFRotation *) outField)->setValue(
SbRotation((* (SoMFMatrix *) input)[0]));
break;
CASE(MFMatrix, MFRotation):
for (i = 0; i < ((SoMFMatrix *)input)->getNum(); i++) {
((SoMFRotation *)outField)->set1Value(i,
SbRotation((* (SoMFMatrix *) input)[i]));
}
break;
CASE(SFRotation, SFMatrix):
matrix.setRotate(((SoSFRotation *)input)->getValue());
((SoSFMatrix *)outField)->setValue(matrix);
break;
CASE(SFRotation, MFMatrix):
matrix.setRotate(((SoSFRotation *)input)->getValue());
((SoSFMatrix *)outField)->setValue(matrix);
break;
CASE(MFRotation, SFMatrix):
matrix.setRotate((*(SoMFRotation *)input)[0]);
((SoSFMatrix *)outField)->setValue(matrix);
break;
CASE(MFRotation, MFMatrix):
for (i = 0; i < ((SoMFRotation *)input)->getNum(); i++) {
matrix.setRotate((*(SoMFRotation *)input)[i]);
((SoMFMatrix *)outField)->set1Value(i, matrix);
}
break;
default:
#ifdef DEBUG
SoDebugError::post("SoBuiltinFieldConverter::doConversion",
"Can't convert type %d to type %d\n",
inType, outType);
#endif
break;
}
}
示例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);
//.........这里部分代码省略.........