本文整理汇总了C++中osg::Matrix类的典型用法代码示例。如果您正苦于以下问题:C++ Matrix类的具体用法?C++ Matrix怎么用?C++ Matrix使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Matrix类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: readScaleElement
void readScaleElement(FbxPropertyT<FbxDouble3>& prop,
osgAnimation::UpdateMatrixTransform* pUpdate,
osg::Matrix& staticTransform,
FbxScene& fbxScene)
{
FbxDouble3 fbxPropValue = prop.Get();
osg::Vec3d val(
fbxPropValue[0],
fbxPropValue[1],
fbxPropValue[2]);
if (isAnimated(prop, fbxScene))
{
if (!staticTransform.isIdentity())
{
pUpdate->getStackedTransforms().push_back(new osgAnimation::StackedMatrixElement(staticTransform));
staticTransform.makeIdentity();
}
pUpdate->getStackedTransforms().push_back(new osgAnimation::StackedScaleElement("scale", val));
}
else
{
staticTransform.preMultScale(val);
}
}
示例4: fs
void
SoundUpdateCB::operator()( osg::Node* node, osg::NodeVisitor* nv )
{
const osg::FrameStamp* fs( nv->getFrameStamp() );
if( !m_sound_state.valid() || ( fs == NULL ) )
{
// Early exit.
osg::notify(osg::DEBUG_INFO) << "SoundUpdateCB::operator()() No SoundState attached, or invalid FrameStamp." << std::endl;
traverse( node, nv );
return;
}
const double t( fs->getReferenceTime() );
const double time( t - m_last_time );
if(time >= m_sound_manager->getUpdateFrequency())
{
const osg::Matrix m( osg::computeLocalToWorld( nv->getNodePath() ) );
const osg::Vec3 pos = m.getTrans();
m_sound_state->setPosition(pos);
//Calculate velocity
osg::Vec3 velocity(0,0,0);
if (m_first_run)
{
m_first_run = false;
m_last_time = t;
m_last_pos = pos;
}
else
{
velocity = pos - m_last_pos;
m_last_pos = pos;
m_last_time = t;
velocity /= time;
}
if(m_sound_manager->getClampVelocity())
{
float max_vel = m_sound_manager->getMaxVelocity();
float len = velocity.length();
if ( len > max_vel)
{
velocity.normalize();
velocity *= max_vel;
}
}
m_sound_state->setVelocity(velocity);
//Get new direction
osg::Vec3 dir = osg::Vec3( 0., 1., 0. ) * m;
dir.normalize();
m_sound_state->setDirection(dir);
// Only do occlusion calculations if the sound is playing
if (m_sound_state->getPlay() && m_occlude_callback.valid())
m_occlude_callback->apply(m_sound_manager->getListenerMatrix(), pos, m_sound_state.get());
} // if time to update
traverse( node, nv );
}
示例5: intersect
void coTouchIntersection::intersect(const osg::Matrix &handMat, bool mouseHit)
{
cerr << "coTouchIntersection::intersect info: called" << endl;
Vec3 q0, q1, q2, q3, q4, q5;
// 3 line segments for interscetion test hand-object
// of course this test can fail
q0.set(0.0f, -0.5f * handSize, 0.0f);
q1.set(0.0f, 0.5f * handSize, 0.0f);
q2.set(-0.5f * handSize, 0.0f, 0.0f);
q3.set(0.5f * handSize, 0.0f, 0.0f);
q4.set(0.0f, 0.0f, -0.5f * handSize);
q5.set(0.0f, 0.0f, 0.5f * handSize);
// xform the intersection line segment
q0 = handMat.preMult(q0);
q1 = handMat.preMult(q1);
q2 = handMat.preMult(q2);
q3 = handMat.preMult(q3);
q4 = handMat.preMult(q4);
q5 = handMat.preMult(q5);
ref_ptr<LineSegment> ray1 = new LineSegment();
ref_ptr<LineSegment> ray2 = new LineSegment();
ref_ptr<LineSegment> ray3 = new LineSegment();
ray1->set(q0, q1);
ray2->set(q2, q3);
ray3->set(q4, q5);
IntersectVisitor visitor;
visitor.addLineSegment(ray1.get());
visitor.addLineSegment(ray2.get());
visitor.addLineSegment(ray3.get());
cover->getScene()->traverse(visitor);
ref_ptr<LineSegment> hitRay = 0;
if (visitor.getNumHits(ray1.get()))
hitRay = ray1;
else if (visitor.getNumHits(ray2.get()))
hitRay = ray2;
else if (visitor.getNumHits(ray3.get()))
hitRay = ray3;
if (visitor.getNumHits(hitRay.get()))
{
Hit hitInformation = visitor.getHitList(hitRay.get()).front();
cover->intersectionHitPointWorld = hitInformation.getWorldIntersectPoint();
cover->intersectionHitPointLocal = hitInformation.getLocalIntersectPoint();
cover->intersectionMatrix = hitInformation._matrix;
cover->intersectedNode = hitInformation._geode;
// walk up to the root and call all coActions
OSGVruiHit hit(hitInformation, mouseHit);
OSGVruiNode node(cover->intersectedNode.get());
callActions(&node, &hit);
}
}
示例6: display
// redraw the window
void display( void )
{
// create the matrix
OSG::Matrix m;
OSG::Real32 t = glutGet(GLUT_ELAPSED_TIME);
// set the transforms' matrices
m.setTransform(OSG::Vec3f(0,
0,
OSG::osgSin(t / 1000.f) * 1.5),
OSG::Quaternion(OSG::Vec3f (1, 0, 0),
t / 500.f));
cyltrans->setMatrix(m);
m.setTransform(OSG::Vec3f(OSG::osgSin(t / 2000.f),
0,
0),
OSG::Quaternion(OSG::Vec3f (0, 0, 1),
t / 2000.f));
tortrans->setMatrix(m);
mgr->redraw();
}
示例7: readScaleElement
void readScaleElement(KFbxTypedProperty<fbxDouble3>& prop,
osgAnimation::UpdateMatrixTransform* pUpdate,
osg::Matrix& staticTransform)
{
fbxDouble3 fbxPropValue = prop.Get();
osg::Vec3d val(
fbxPropValue[0],
fbxPropValue[1],
fbxPropValue[2]);
if (prop.GetKFCurve(KFCURVENODE_S_X) ||
prop.GetKFCurve(KFCURVENODE_S_Y) ||
prop.GetKFCurve(KFCURVENODE_S_Z))
{
if (!staticTransform.isIdentity())
{
pUpdate->getStackedTransforms().push_back(new osgAnimation::StackedMatrixElement(staticTransform));
staticTransform.makeIdentity();
}
pUpdate->getStackedTransforms().push_back(new osgAnimation::StackedScaleElement("scale", val));
}
else
{
staticTransform.preMultScale(val);
}
}
示例8: getConvexShape
btCollisionShape* VRPhysics::getConvexShape() {
btConvexHullShape* shape = new btConvexHullShape();
OSG::Matrix m;
OSG::Matrix M = vr_obj->getWorldMatrix();
M.invert();
vector<OSG::VRObject*> geos = vr_obj->getObjectListByType("Geometry");
for (auto g : geos) {
OSG::VRGeometry* geo = (OSG::VRGeometry*)g;
if (geo == 0) continue;
if (geo->getMesh() == 0) continue;
OSG::GeoVectorPropertyRecPtr pos = geo->getMesh()->getPositions();
if (pos == 0) continue;
if (geo != vr_obj) {
m = geo->getWorldMatrix();
m.multLeft(M);
}
for (unsigned int i = 0; i<pos->size(); i++) {
OSG::Pnt3f p;
pos->getValue(p,i);
if (geo != vr_obj) m.mult(p,p);
for (int i=0; i<3; i++) p[i] *= scale[i];
shape->addPoint(btVector3(p[0], p[1], p[2]));
}
}
shape->setMargin(collisionMargin);
//cout << "\nConstruct Convex shape for " << vr_obj->getName() << endl;
return shape;
}
示例9: fromBTTransform
OSG::Matrix VRPhysics::fromBTTransform(const btTransform t, OSG::Vec3f scale) {
OSG::Matrix m = fromBTTransform(t);
// apply scale
OSG::Matrix s;
s.setScale(scale);
m.mult(s);
return m;
}
示例10: setTranslation
void Transform::setTranslation(OSG::Real32 x, OSG::Real32 y, OSG::Real32 z)
{
OSG::Matrix m;
m.setTransform(OSG::Vec3f(x,y,z));
// OSG::beginEditCP(_transform);
_transform->setMatrix(m);
// OSG::endEditCP(_transform);
}
示例11: setModelTransformation
void Particles::setModelTransformation(TransformationData trans)
{
OSG::Matrix m;
gmtl::Matrix44f mat;
transformationDataToMatrix(trans, mat);
m.setValue(mat.getData());
beginEditCP(particleModelTrans, Transform::MatrixFieldMask);
particleModelTrans->setMatrix(m);
endEditCP(particleModelTrans, Transform::MatrixFieldMask);
} // Particles
示例12: copyOsgMatrixToLib3dsMatrix
void copyOsgMatrixToLib3dsMatrix(Lib3dsMatrix lib3ds_matrix, const osg::Matrix& osg_matrix)
{
for(int row=0; row<4; ++row)
{
lib3ds_matrix[row][0] = osg_matrix.ptr()[row*4+0];
lib3ds_matrix[row][1] = osg_matrix.ptr()[row*4+1];
lib3ds_matrix[row][2] = osg_matrix.ptr()[row*4+2];
lib3ds_matrix[row][3] = osg_matrix.ptr()[row*4+3];
}
}
示例13: createScene
OSG::NodeTransitPtr createScene(OSG::Window *win)
{
OSG::NodeRecPtr rootN = OSG::makeNodeFor(OSG::Group::create());
// Create ground:
OSG::NodeUnrecPtr groundN = OSG::makePlane(25,25,1,1);
OSG::Matrix m;
OSG::Quaternion q;
q.setValueAsAxisDeg(OSG::Vec3f(1,0,0), -90);
m.setRotate(q);
OSG::TransformUnrecPtr groundTransC = OSG::Transform::create();
groundTransC->setMatrix(m);
OSG::NodeUnrecPtr groundTransN = OSG::makeNodeFor(groundTransC);
groundTransN->addChild(groundN);
rootN->addChild(groundTransN);
// Set ground material:
OSG::SimpleMaterialUnrecPtr mat = OSG::SimpleMaterial::create();
mat->setDiffuse(OSG::Color3f(0.8,0.8,0.8));
dynamic_cast<OSG::Geometry*>(groundN->getCore())->setMaterial(mat);
// // Create figure:
// OSG::NodeUnrecPtr figure1N =
// OSG::SceneFileHandler::the()->read("../Models/Figure.obj");
// G.figure1TransC = OSG::Transform::create();
// OSG::NodeUnrecPtr trans1N = OSG::makeNodeFor(G.figure1TransC);
// trans1N->addChild(figure1N);
// rootN->addChild(trans1N);
OSG::NodeUnrecPtr figureModelA =
OSG::SceneFileHandler::the()->read("../assets/Figure.obj");
BoardGame::Figure* figureA = new BoardGame::Figure();
figureA->setModel(figureModelA);
rootN->addChild(figureA->getRoot());
OSG::NodeUnrecPtr figureModelB =
OSG::SceneFileHandler::the()->read("../assets/Figure.obj");
BoardGame::Figure* figureB = new BoardGame::Figure();
figureB->setModel(figureModelB);
rootN->addChild(figureB->getRoot());
G.selectedNode = figureModelA;
return(OSG::NodeTransitPtr(rootN));
}
示例14: display
// redraw the window
void display( void )
{
// create the matrix
OSG::Matrix m;
OSG::Real32 t = glutGet(GLUT_ELAPSED_TIME );
m.setTransform(OSG::Quaternion(OSG::Vec3f(0,1,0), t / 1000.f));
// set the transform's matrix
trans->setMatrix(m);
OSG::commitChanges();
mgr->redraw();
}
示例15: MatrixOrthogonal
OSG_BEGIN_NAMESPACE
OSG_BASE_DLLMAPPING bool MatrixOrthogonal(OSG::Matrix &result,
OSG::Real32 rLeft,
OSG::Real32 rRight,
OSG::Real32 rBottom,
OSG::Real32 rTop,
OSG::Real32 rNear,
OSG::Real32 rFar)
{
result.setValueTransposed(
2.f / (rRight - rLeft),
0.f,
0.f,
0.f,
0.f,
2.f / (rTop - rBottom),
0.f,
0.f,
0.f,
0.f,
-2.f / (rFar - rNear),
0.f,
-(rRight + rLeft ) / (rRight - rLeft ),
-(rTop + rBottom) / (rTop - rBottom),
-(rFar + rNear ) / (rFar - rNear ),
1.);
return false;
}