本文整理汇总了C++中osg::Matrix::setTranslate方法的典型用法代码示例。如果您正苦于以下问题:C++ Matrix::setTranslate方法的具体用法?C++ Matrix::setTranslate怎么用?C++ Matrix::setTranslate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类osg::Matrix
的用法示例。
在下文中一共展示了Matrix::setTranslate方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: createLabeledTorus
OSG::NodeTransitPtr createLabeledTorus(OSG::Vec3f trans, int idx)
{
OSG::NodeTransitPtr node = OSG::Node::create();
OSG::TransformRefPtr xform = OSG::Transform::create();
OSG::Matrix mat;
// --- setup transform ------------------
mat.setIdentity();
mat.setTranslate(trans);
xform->setMatrix(mat);
node->setCore(xform);
// --- setup label ----------------------
OSG::NodeRefPtr labelNode = OSG::Node::create();
OSG::LabelRefPtr label =
(idx) ? createTextLabel(idx) : createIconLabel();
updateLabelParams(label, idx);
labelNode->setCore(label);
// --- add torus ------------------------
labelNode->addChild(OSG::makeTorus(.5, 2, 16, 16));
node->addChild(labelNode);
return node;
}
示例2: MatrixLookAt
OSG_BASE_DLLMAPPING bool MatrixLookAt(OSG::Matrix &result,
OSG::Pnt3f from,
OSG::Pnt3f at,
OSG::Vec3f up )
{
Vec3f view;
Vec3f right;
Vec3f newup;
Vec3f tmp;
view = from - at;
view.normalize();
right = up.cross(view);
if(right.dot(right) < TypeTraits<Real>::getDefaultEps())
{
return true;
}
right.normalize();
newup = view.cross(right);
result.setIdentity ();
result.setTranslate(from[0], from[1], from[2]);
Matrix tmpm;
tmpm.setValue(right, newup, view);
result.mult(tmpm);
return false;
}
示例3: createScene
OSG::NodeTransitPtr createScene(void)
{
// create the scene:
OSG::TransformTransitPtr xform = OSG::Transform::create();
OSG::Matrix mat;
mat.setTranslate(OSG::Vec3f(2,0,0));
xform->setMatrix(mat);
OSG::NodeTransitPtr scene = OSG::Node::create();
scene->addChild(createLabeledScene());
scene->setCore(xform);
OSG::commitChanges();
return scene;
}
示例4: updateClipPlanes
//
// In case the clip plane data change this function is called
//
void updateClipPlanes(const VecClipPlaneData& vec)
{
int sz = vec.size();
for(int i = 0; i < iNumClipPlanes; ++i)
{
OSG::ClipPlaneChunk *clipPlaneChunk =
vecClipPlaneDetails[i]._clipPlaneChunk;
clipPlaneChunk->setEnable(false);
if(i < sz)
{
const ClipPlaneData& data = vec[i];
//
// Update the clip plane chunk
//
clipPlaneChunk->setEquation(data._equation);
clipPlaneChunk->setEnable (data._enabled );
//
// and the plane transform core
//
OSG::Matrix rotMat;
OSG::Vec4f v1(0.f, 0.f, -1.f, 0.f);
OSG::Quaternion q(OSG::Vec3f(v1), OSG::Vec3f(data._equation));
rotMat.setTransform(q);
OSG::Matrix mat;
OSG::Vec3f v2(0.0f, 0.0f, data._equation[3]);
mat.setTranslate(v2);
mat.multLeft(rotMat);
vecClipPlaneDetails[i]._planeTrafoCore->setMatrix(mat);
}
}
}
示例5: createScenegraph
OSG::NodeTransitPtr createScenegraph(void)
{
// At first we load all needed models from file
OSG::NodeRecPtr w_high =
OSG::SceneFileHandler::the()->read("Data/woman_high.wrl");
OSG::NodeRecPtr w_medium =
OSG::SceneFileHandler::the()->read("Data/woman_medium.wrl");
OSG::NodeRecPtr w_low =
OSG::SceneFileHandler::the()->read("Data/woman_low.wrl");
// we check the result
if((w_high == NULL) || (w_medium == NULL)|| (w_low == NULL))
{
std::cout << "It was not possible to load all needed models from file"
<< std::endl;
return OSG::NodeTransitPtr();
}
// now the LOD core
OSG::DistanceLODRecPtr lod = OSG::DistanceLOD::create();
lod->editSFCenter()->setValue(OSG::Pnt3f(0,0,0));
lod->editMFRange()->push_back(200);
lod->editMFRange()->push_back(500);
// the node containing the LOD core. The three models will be
// added as its children
OSG::NodeRecPtr lodNode = OSG::Node::create();
lodNode->setCore(lod);
lodNode->addChild(w_high);
lodNode->addChild(w_medium);
lodNode->addChild(w_low);
// create the node with switch core ********************
OSG::SwitchRecPtr sw = OSG::Switch::create();
//Notice: the first choice is 0
sw->setChoice(0);
OSG::NodeRecPtr switchNode = OSG::Node::create();
switchNode->setCore(sw);
switchNode->addChild(lodNode);
//end switch creation **********************************
OSG::NodeRecPtr root = OSG::Node::create();
root->setCore(OSG::Group::create());
root->addChild(switchNode);
// we know want to extract the mesh geometry out of the graph
// it is sufficent to pass the model only as root for searching
OSG::NodeRecPtr womanGeometry = checkName(w_high);
OSG::GeometryRecPtr geo =
dynamic_cast<OSG::Geometry *>(womanGeometry->getCore());
//new node with "old" geometry core referenced
OSG::NodeRecPtr woman = OSG::Node::create();
woman->setCore(geo);
//translate it a bit to see both women
OSG::NodeRecPtr womanTrans = OSG::Node ::create();
OSG::TransformRecPtr t = OSG::Transform::create();
OSG::Matrix m;
m.setIdentity();
m.setTranslate(OSG::Vec3f(0,0,200));
t->setMatrix(m);
womanTrans->setCore(t);
womanTrans->addChild(woman);
//add it to the root
root->addChild(womanTrans);
return OSG::NodeTransitPtr(root);
}
示例6: updateScene
//.........这里部分代码省略.........
break;
case OSG::Image::OSG_RGB_DXT1:
statElem->set("OSG_RGB_DXT1");
break;
case OSG::Image::OSG_RGBA_DXT1:
statElem->set("OSG_RGBA_DXT1");
break;
case OSG::Image::OSG_RGBA_DXT3:
statElem->set("OSG_RGBA_DXT3");
break;
case OSG::Image::OSG_RGBA_DXT5:
statElem->set("OSG_RGBA_DXT5");
break;
default:
statElem->set("???");
break;
}
statElem = statfg->editCollector()->getElem(textureDataTypeDesc);
switch (imagePtr->getDataType())
{
case OSG::Image::OSG_UINT8_IMAGEDATA:
statElem->set("OSG_UINT8_IMAGEDATA");
break;
case OSG::Image::OSG_UINT16_IMAGEDATA:
statElem->set("OSG_UINT16_IMAGEDATA");
break;
case OSG::Image::OSG_UINT32_IMAGEDATA:
statElem->set("OSG_UINT32_IMAGEDATA");
break;
case OSG::Image::OSG_FLOAT16_IMAGEDATA:
statElem->set("OSG_FLOAT16_IMAGEDATA");
break;
case OSG::Image::OSG_FLOAT32_IMAGEDATA:
statElem->set("OSG_FLOAT32_IMAGEDATA");
break;
case OSG::Image::OSG_INT16_IMAGEDATA:
statElem->set("OSG_INT16_IMAGEDATA");
break;
case OSG::Image::OSG_INT32_IMAGEDATA:
statElem->set("OSG_INT32_IMAGEDATA");
break;
default:
statElem->set("???");
break;
}
ostringstream os;
os << imagePtr->getWidth() << 'x' << imagePtr->getHeight() << 'x' << imagePtr->getDepth();
statfg->editCollector()->getElem(textureSizeDesc)->set(os.str());
statfg->editCollector()->getElem(textureDimensionDesc)->set(imagePtr->getDimension());
statfg->editCollector()->getElem(textureBPPDesc)->set(imagePtr->getBpp());
statfg->editCollector()->getElem(textureMipMapCountDesc)->set(imagePtr->getMipMapCount());
statfg->editCollector()->getElem(textureFrameCountDesc)->set(imagePtr->getFrameCount());
// Put it all together into a Geometry NodeCore.
OSG::GeometryRecPtr geo = OSG::makePlaneGeo(imagePtr->getWidth(), imagePtr->getHeight(), 1, 1);
OSG::NodeRecPtr imageNode = OSG::Node::create();
imageNode->setCore(geo);
OSG::NodeRecPtr transNodePtr = OSG::Node::create();
OSG::TransformRecPtr transPtr = OSG::Transform::create();
OSG::Matrix transMatrix;
transMatrix.setTranslate(0.f, 0.f, -1.f);
transPtr->setMatrix(transMatrix);
transNodePtr->setCore(transPtr);
transNodePtr->addChild(imageNode);
OSG::TextureObjChunkRecPtr texObjChunk = OSG::TextureObjChunk::create();
texObjChunk->setImage(imagePtr);
texObjChunk->setWrapS(GL_CLAMP);
texObjChunk->setWrapT(GL_CLAMP);
texObjChunk->setMagFilter(GL_NEAREST);
texObjChunk->setMinFilter(GL_NEAREST);
OSG::TextureEnvChunkRecPtr texEnvChunk = OSG::TextureEnvChunk::create();
texEnvChunk->setEnvMode(GL_MODULATE);
OSG::MaterialChunkRecPtr matChunk = OSG::MaterialChunk::create();
matChunk->setAmbient(OSG::Color4f(1.f, 1.f, 1.f, 1.f));
matChunk->setDiffuse(OSG::Color4f(1.f, 1.f, 1.f, 1.f));
matChunk->setEmission(OSG::Color4f(0.f, 0.f, 0.f, 1.f));
matChunk->setSpecular(OSG::Color4f(0.f, 0.f, 0.f, 1.f));
matChunk->setShininess(0);
OSG::ChunkMaterialRecPtr m = OSG::ChunkMaterial::create();
m->addChunk(texObjChunk);
m->addChunk(texEnvChunk);
m->addChunk(matChunk);
geo->setMaterial(m);
scene->clearChildren();
scene->addChild(transNodePtr);
if(compressTo != OSG::Image::OSG_INVALID_PF)
{
OSG::SceneFileHandler::the()->write(scene->getChild(0),
"/tmp/comp.osb");
OSG::SceneFileHandler::the()->write(scene->getChild(0),
"/tmp/comp.osg");
}
}
示例7: keyboard
//
// react to keys
//
void keyboard(unsigned char k, int, int)
{
static OSG::Real32 val0 = 0.f;
static OSG::Real32 val1 = 0.f;
static OSG::Real32 x1 = 0.f;
static OSG::Real32 y1 = 0.f;
static OSG::Real32 z1 = 0.f;
static OSG::Real32 x2 = 0.f;
static OSG::Real32 y2 = 0.f;
static OSG::Real32 z2 = 0.f;
switch(k)
{
case ' ':
{
OSG::SceneGraphPrinter sgp(mgr->getRoot());
sgp.printDownTree(std::cout);
}
break;
case '1': // enable/disable clip plane 0
{
vecClipPlaneData[0]._enabled = !vecClipPlaneData[0]._enabled;
updateClipPlanes(vecClipPlaneData);
}
break;
case '2': // enable/disable clip plane 1
{
vecClipPlaneData[1]._enabled = !vecClipPlaneData[1]._enabled;
updateClipPlanes(vecClipPlaneData);
}
break;
case '3': // enable/disable box geometry
{
if(vecGeometries[0] == NULL)
{
OSG::Matrix matrix;
OSG::Vec3f v(10.f, 0.f, 15.f);
matrix.setTranslate(v);
OSG::GeometryRefPtr boxGeo =
OSG::makeBoxGeo(15, 15, 15, 1, 1, 1);
OSG::NodeRefPtr boxTree = buildGeoTree(scene,
boxGeo,
matrix);
vecGeometries[0] = boxTree;
scene->addChild(boxTree);
}
else
{
scene->subChild(vecGeometries[0]);
vecGeometries[0] = NULL;
}
// mgr->showAll();
// mgr->redraw();
}
break;
case '4': // enable/disable torus geometry
{
if (vecGeometries[1] == NULL)
{
OSG::Matrix matrix;
OSG::Vec3f v( 0.f, 10.f, 0.f);
matrix.setTranslate(v);
OSG::GeometryRefPtr torusGeo = OSG::makeTorusGeo(2, 6, 8, 16);
OSG::NodeRefPtr torusTree = buildGeoTree(scene,
torusGeo, matrix);
vecGeometries[1] = torusTree;
scene->addChild(torusTree);
}
else
{
scene->subChild(vecGeometries[1]);
vecGeometries[1] = NULL;
}
// mgr->showAll();
// mgr->redraw();
}
break;
case '5':
{
OSG::SceneFileHandler::the()->write(mgr->getRoot(),
"clipplane_model.osb", true);
}
break;
case 'n': // move clip plane 0 opposite to the normal direction of the plane
{
val0 -= 0.2;
//.........这里部分代码省略.........
示例8: main
int main(int argc, char *argv[])
{
// Init the OpenSG subsystem
OSG::osgInit(argc, argv);
{
// We create a GLUT Window (that is almost the same for most applications)
int winid = setupGLUT(&argc, argv);
OSG::GLUTWindowRecPtr gwin = OSG::GLUTWindow::create();
gwin->setGlutId(winid);
gwin->init();
// Create the face
std::string family = "SANS";
OSG::TextFace::Style style = OSG::TextFace::STYLE_PLAIN;
OSG::UInt32 size = 32;
OSG::TextPixmapFaceRefPtr face =
OSG::TextPixmapFace::create(family, style, size);
if (face == 0)
{
std::cerr << "ERROR: Cannot create face object!" << std::endl;
return -1;
}
// Lay out one single line of text
std::string text = "Hello World!"; // Use UTF-8 encoding!
OSG::TextLayoutParam layoutParam;
layoutParam.horizontal = true;
layoutParam.leftToRight = true;
layoutParam.topToBottom = true;
layoutParam.majorAlignment = OSG::TextLayoutParam::ALIGN_FIRST;
layoutParam.minorAlignment = OSG::TextLayoutParam::ALIGN_FIRST;
layoutParam.spacing = 1.f;
layoutParam.length.push_back(0.f);
layoutParam.maxExtend = 0.f;
OSG::TextLayoutResult layoutResult;
face->layout(text, layoutParam, layoutResult);
// Render the text into an OpenSG image
OSG::Vec2f offset;
OSG::UInt32 border = 1;
OSG::ImageRecPtr imagePtr = face->makeImage(layoutResult, offset, border);
// Create the geometry which we will assign the texture to
OSG::Real32 width = imagePtr->getWidth();
OSG::Real32 height = imagePtr->getHeight();
OSG::NodeRecPtr plane = OSG::makePlane(width, height, 1, 1);
// Create the texture that will hold the image
OSG::SimpleTexturedMaterialRecPtr tex =
OSG::SimpleTexturedMaterial::create();
tex->setImage(imagePtr);
tex->setEnvMode(GL_MODULATE);
tex->setDiffuse(OSG::Color3f(1, 0, 0));
// Assign the texture to the geometry
OSG::GeometryRecPtr geo =
dynamic_cast<OSG::Geometry *>(plane->getCore());
geo->setMaterial(tex);
// Transform the geometry so that the origin of the text is at
// the origin of the world coordinate system
OSG::NodeRecPtr scene = OSG::Node::create();
OSG::TransformRecPtr transformPtr = OSG::Transform::create();
OSG::Matrix m;
m.setTranslate(offset.x() + width / 2, offset.y() - height / 2, 0);
transformPtr->setMatrix(m);
scene->setCore(transformPtr);
scene->addChild(plane);
// Create and setup the SSM
mgr = new OSG::SimpleSceneManager;
mgr->setWindow(gwin);
mgr->setRoot(scene);
// Create a blue background
OSG::SolidBackgroundRecPtr bg = OSG::SolidBackground::create();
bg->setColor(OSG::Color3f(0.1, 0.1, 0.5));
gwin->getPort(0)->setBackground(bg);
mgr->showAll();
OSG::commitChanges();
}
// Give Control to the GLUT Main Loop
glutMainLoop();
return 0;
}