本文整理汇总了C++中osg::Matrix::setIdentity方法的典型用法代码示例。如果您正苦于以下问题:C++ Matrix::setIdentity方法的具体用法?C++ Matrix::setIdentity怎么用?C++ Matrix::setIdentity使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类osg::Matrix
的用法示例。
在下文中一共展示了Matrix::setIdentity方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: MatrixPerspective
OSG_BASE_DLLMAPPING bool MatrixPerspective(OSG::Matrix &result,
OSG::Real32 rFovy,
OSG::Real32 rAspect,
OSG::Real32 rNear,
OSG::Real32 rFar)
{
Real32 ct = osgTan(rFovy);
bool error = false;
if(rNear > rFar)
{
SWARNING << "MatrixPerspective: near " << rNear << " > far " << rFar
<< "!\n" << std::endl;
error = true;
}
if(rFovy <= TypeTraits<Real32>::getDefaultEps())
{
SWARNING << "MatrixPerspective: fovy " << rFovy << " very small!\n"
<< std::endl;
error = true;
}
if(osgAbs(rNear - rFar) < TypeTraits<Real32>::getDefaultEps())
{
SWARNING << "MatrixPerspective: near " << rNear << " ~= far " << rFar
<< "!\n" << std::endl;
error = true;
}
if(rAspect < TypeTraits<Real32>::getDefaultEps())
{
SWARNING << "MatrixPerspective: aspect ratio " << rAspect
<< " very small!\n" << std::endl;
error = true;
}
if(error)
{
result.setIdentity();
return true;
}
MatrixFrustum( result,
-rNear * ct * rAspect,
rNear * ct * rAspect,
-rNear * ct,
rNear * ct,
rNear,
rFar );
return false;
}
示例4: createClipPlaneDetails
//
// Build the global clip plane state
//
void createClipPlaneDetails(void)
{
for(int i = 0; i < iNumClipPlanes; ++i)
{
ClipPlaneDetails details;
//
// Create clip plane chunk
//
details._planeBeaconNode = OSG::Node::create();
details._planeBeaconNode->setCore(OSG::Transform::create());
container->addContainer(details._planeBeaconNode);
details._clipPlaneChunk = OSG::ClipPlaneChunk::create();
details._clipPlaneChunk->setEquation(OSG::Vec4f(1,0,0,0));
details._clipPlaneChunk->setEnable(false);
details._clipPlaneChunk->setBeacon(details._planeBeaconNode);
//
// Create plane geometry
//
details._planeGeometryCore = OSG::makePlaneGeo(100.f, 100.f, 128, 128);
//
// Create plane transformation core
//
OSG::Matrix mat;
mat.setIdentity();
details._planeTrafoCore = OSG::Transform::create();
details._planeTrafoCore->setMatrix(mat);
//
// Define plane color
//
details._planeColor = planeCol[i];
vecClipPlaneDetails.push_back(details);
}
}
示例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: Animate
void Animate()
{
//Show FPS
//showFpsCounter();
if(bAnim == true)
{
static OSG::Real64 t0 = OSG::getSystemTime();
OSG::Real64 t = OSG::getSystemTime() - t0;
OSG::Real32 rot0 = t * 0.25;
if(rot0 > 360.0)
rot0 -= 360.0;
OSG::Real32 rota = t * 0.5;
if(rota > 360.0)
rota -= 360.0;
OSG::Real32 rotb = t * 1.0;
if(rotb > 360.0)
rotb -= 360.0;
OSG::Real32 rotc = t * 1.5;
if(rotc > 360.0)
rotc -= 360.0;
OSG::Real32 rotd = t * 2.0;
if(rotd > 360.0)
rotd -= 360.0;
// _light2_trans->editMatrix().setTranslate(-100.0*sin(rota),-100.0*cos(rota), 250.0);
//animate Trees
OSG::Quaternion q;
q.setValueAsAxisRad(1, 1, 1, 0.5 * sin(rota));
_tree1_trans->editMatrix().setRotate(q);
_tree1_trans->editMatrix().setScale(OSG::Vec3f(12.0, 12.0, 10.0));
q.setIdentity();
q.setValueAsAxisRad(1, 1, 1, 0.5 * sin(rotc));
_tree2_trans->editMatrix().setRotate(q);
_tree2_trans->editMatrix().setScale(OSG::Vec3f(12.0, 12.0, 10.0));
q.setIdentity();
q.setValueAsAxisRad(1, 1, 1, 0.5 * sin(rotb));
_tree3_trans->editMatrix().setRotate(q);
_tree3_trans->editMatrix().setScale(OSG::Vec3f(12.0, 12.0, 10.0));
q.setIdentity();
q.setValueAsAxisRad(1, 1, 1, 0.5 * sin(rotb));
_tree4_trans->editMatrix().setRotate(q);
_tree4_trans->editMatrix().setScale(OSG::Vec3f(12.0, 12.0, 10.0));
q.setIdentity();
q.setValueAsAxisRad(1, 1, 1, 0.5 * sin(rotc));
_tree5_trans->editMatrix().setRotate(q);
_tree5_trans->editMatrix().setScale(OSG::Vec3f(12.0, 12.0, 10.0));
q.setIdentity();
q.setValueAsAxisRad(1, 1, 1, 0.5 * sin(rotb));
_tree6_trans->editMatrix().setRotate(q);
_tree6_trans->editMatrix().setScale(OSG::Vec3f(12.0, 12.0, 10.0));
q.setIdentity();
q.setValueAsAxisRad(1, 1, 1, 0.5 * sin(rotd));
_tree7_trans->editMatrix().setRotate(q);
_tree7_trans->editMatrix().setScale(OSG::Vec3f(12.0, 12.0, 10.0));
q.setIdentity();
q.setValueAsAxisRad(1, 1, 1, 0.5 * sin(rotb));
_tree8_trans->editMatrix().setRotate(q);
_tree8_trans->editMatrix().setScale(OSG::Vec3f(12.0, 12.0, 10.0));
q.setIdentity();
q.setValueAsAxisRad(1, 1, 1, 0.5 * sin(rotc));
_tree9_trans->editMatrix().setRotate(q);
_tree9_trans->editMatrix().setScale(OSG::Vec3f(12.0, 12.0, 10.0));
q.setIdentity();
{
OSG::Matrix m;
m.setIdentity();
OSG::Vec3f scale(0.15f,0.15f,0.15f);
OSG::Vec3f trans(-40.0 * sin(rotb),-40.0 * cos(rotb),
50.0 + 25.0 * sin(rotd));
q.setValueAsAxisRad(0, 0, 1, -rotb);
m.setTransform(trans, q, scale);
_obj1_trans->setMatrix(m);
}
//.........这里部分代码省略.........
示例7: MatrixStereoPerspective
OSG_BASE_DLLMAPPING bool MatrixStereoPerspective(OSG::Matrix &projection,
OSG::Matrix &projtrans,
OSG::Real32 rFovy,
OSG::Real32 rAspect,
OSG::Real32 rNear,
OSG::Real32 rFar,
OSG::Real32 rZeroparallax,
OSG::Real32 rEyedistance,
OSG::Real32 rWhicheye,
OSG::Real32 rOverlap)
{
Real32 rLeft;
Real32 rRight;
Real32 rTop;
Real32 rBottom;
Real32 gltan;
Real32 rEye = -rEyedistance * (rWhicheye - .5f);
Real32 d;
bool error = false;
if(rNear > rFar)
{
SWARNING << "MatrixPerspective: near " << rNear << " > far " << rFar
<< "!\n" << std::endl;
error = true;
}
if(rFovy <= TypeTraits<Real32>::getDefaultEps())
{
SWARNING << "MatrixPerspective: fovy " << rFovy << " very small!\n"
<< std::endl;
error = true;
}
if(osgAbs(rNear - rFar) < TypeTraits<Real32>::getDefaultEps())
{
SWARNING << "MatrixPerspective: near " << rNear << " ~= far " << rFar
<< "!\n" << std::endl;
error = true;
}
if(rAspect < TypeTraits<Real32>::getDefaultEps())
{
SWARNING << "MatrixPerspective: aspect ratio " << rAspect
<< " very small!\n" << std::endl;
error = true;
}
if(rZeroparallax < TypeTraits<Real32>::getDefaultEps())
{
SWARNING << "MatrixPerspective: zero parallax " << rZeroparallax
<< " very small, setting to 1!\n" << std::endl;
rZeroparallax = 1.f;
error = true;
}
if(error)
{
projection.setIdentity();
projtrans .setIdentity();
return true;
}
/* Calculate upper and lower clipping planes */
rTop = osgTan(rFovy / 2.0f) * rNear;
rBottom = -rTop;
/* Calculate left and right clipping planes */
gltan = osgTan(rFovy / 2.0f) * rAspect;
rLeft = (-gltan + rEye / rZeroparallax) * rNear;
rRight = ( gltan + rEye / rZeroparallax) * rNear;
d = rRight - rLeft;
rLeft += d * (1.f - rOverlap) * (rWhicheye - .5f);
rRight += d * (1.f - rOverlap) * (rWhicheye - .5f);
MatrixFrustum(projection, rLeft, rRight, rBottom, rTop, rNear, rFar);
projtrans.setIdentity();
projtrans[3][0] = rEye;
return false;
}