本文整理汇总了C++中SbMatrix::setTranslate方法的典型用法代码示例。如果您正苦于以下问题:C++ SbMatrix::setTranslate方法的具体用法?C++ SbMatrix::setTranslate怎么用?C++ SbMatrix::setTranslate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SbMatrix
的用法示例。
在下文中一共展示了SbMatrix::setTranslate方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getMatrix
void SoZoomTranslation::getMatrix(SoGetMatrixAction * action)
{
SbVec3f v;
if(this->translation.getValue() == SbVec3f(0.0f, 0.0f, 0.0f) && this->abPos.getValue() == SbVec3f(0.0f, 0.0f, 0.0f)) {
return;
} else {
SbVec3f absVtr = this->abPos.getValue();
SbVec3f relVtr = this->translation.getValue();
float sf = this->getScaleFactor();
// For Sketcher Keep Z value the same
relVtr[0] = (relVtr[0] != 0) ? sf * relVtr[0] : 0;
relVtr[1] = (relVtr[1] != 0) ? sf * relVtr[1] : 0;
v = absVtr + relVtr;
}
SbMatrix m;
m.setTranslate(v);
action->getMatrix().multLeft(m);
m.setTranslate(-v);
action->getInverse().multRight(m);
}
示例2:
/*! \COININTERNAL */
void
SoCenterballDragger::fieldSensorCB(void * d, SoSensor *)
{
SoCenterballDragger * thisp = static_cast<SoCenterballDragger *>(d);
// Save center variable and translate dragger to correct position
thisp->savedcenter = thisp->center.getValue();
SbMatrix centermat;
centermat.setTranslate(thisp->savedcenter);
SoMatrixTransform * mt =
SO_GET_ANY_PART(thisp, "translateToCenter", SoMatrixTransform);
mt->matrix = centermat;
SbMatrix matrix = thisp->getMotionMatrix();
thisp->workFieldsIntoTransform(matrix);
thisp->setMotionMatrix(matrix);
}
示例3: pitch
SoXipNeheBoxGenerator::SoXipNeheBoxGenerator()
{
SO_NODE_CONSTRUCTOR(SoXipNeheBoxGenerator);
SbRotation pitch(SbVec3f(1, 0, 0), 0); // rotation around X
SbMatrix pitchM;
SbRotation yaw(SbVec3f(0, 1, 0), 0); // rotation around Y
SbMatrix yawM;
SbMatrix transM = SbMatrix::identity(); // translation
SbMatrix compM = SbMatrix::identity();
float xrot = 0;
float yrot = 0;
for (int yloop = 1; yloop < 6 /* number of rows */ ; yloop++)
{
for (int xloop = 0; xloop < yloop; xloop++)
{
// another magic formula from Nehe for the translation...
transM.setTranslate(SbVec3f(1.4f+(float(xloop)*2.8f)-(float(yloop)*1.4f),((6.0f-float(yloop))*2.4f)-7.0f,-20.0f));
pitch.setValue(SbVec3f(1, 0, 0), (M_PI/180) * (45.0f-(2.0f*yloop)+ xrot));
pitch.getValue(pitchM);
yaw.setValue(SbVec3f(0,1,0), (M_PI/180) * (45.0f + yrot));
yaw.getValue(yawM);
compM = yawM * pitchM * transM;
SoXipNeheBox* neheBox = new SoXipNeheBox();
neheBox->transform.setValue(compM);
neheBox->topColor.setValue(topCol[yloop - 1]);
neheBox->boxColor.setValue(boxCol[yloop - 1]);
this->addChild(neheBox);
}
}
}
示例4: getWorldLocation
/*! Gives us a visual indicator of what this contact looks like,
in WORLD COORDINATES. Since this contact has to be transformed
to world coordinates for the sake of grasp analysis, this allows
us to be sure that the transformation makes sense.
It assumes WRENCHES have been computed.
*/
void
VirtualContact::getWorldIndicator(bool useObjectData)
{
vec3 forceVec;
position worldLoc;
if (!useObjectData) {
worldLoc = getWorldLocation();
} else {
vec3 objDist;
getObjectDistanceAndNormal(body2, &objDist, NULL);
worldLoc = getWorldLocation() + objDist;
}
SoTransform* tran = new SoTransform;
SbMatrix tr;
tr.setTranslate( worldLoc.toSbVec3f() );
tran->setMatrix( tr );
SbVec3f *points = (SbVec3f*)calloc(numFCWrenches+1, sizeof(SbVec3f) );
int32_t *cIndex = (int32_t*)calloc(4*numFCWrenches, sizeof(int32_t) );
points[0].setValue(0,0,0);
for (int i=0;i<numFCWrenches;i++) {
//if ( wrench[i].torque.len() != 0 ) continue;
forceVec = wrench[i].force;
forceVec = Body::CONE_HEIGHT * forceVec;
points[i+1].setValue( forceVec.x(), forceVec.y(), forceVec.z() );
cIndex[4*i] = 0;
cIndex[4*i+1] = i + 2;
if ( i == numFCWrenches-1) cIndex[4*i+1] = 1;
cIndex[4*i+2] = i + 1;
cIndex[4*i+3] = -1;
}
SoCoordinate3* coords = new SoCoordinate3;
SoIndexedFaceSet* ifs = new SoIndexedFaceSet;
coords->point.setValues(0,numFCWrenches+1,points);
ifs->coordIndex.setValues(0,4*numFCWrenches,cIndex);
free(points);
free(cIndex);
SoMaterial *coneMat = new SoMaterial;
coneMat->diffuseColor = SbColor(0.0f,0.0f,0.8f);
coneMat->ambientColor = SbColor(0.0f,0.0f,0.2f);
coneMat->emissiveColor = SbColor(0.0f,0.0f,0.4f);
if (mWorldInd) {
body1->getWorld()->getIVRoot()->removeChild(mWorldInd);
}
mWorldInd = new SoSeparator;
mWorldInd->addChild(tran);
mWorldInd->addChild(coneMat);
mWorldInd->addChild(coords);
mWorldInd->addChild(ifs);
body1->getWorld()->getIVRoot()->addChild(mWorldInd);
/*
SoSeparator* cSep = new SoSeparator;
tr.setTranslate( mCenter.toSbVec3f() );
tran = new SoTransform;
tran->setMatrix( tr );
cSep->addChild(tran);
SoSphere* cSphere = new SoSphere();
cSphere->radius = 5;
cSep->addChild(cSphere);
body1->getWorld()->getIVRoot()->addChild(cSep);
*/
}
示例5: 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);
//.........这里部分代码省略.........
示例6: 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);
}