C++ openscenegraph在旋转后获取新的矢量值
旋转几何体后如何获取新点C++ openscenegraph在旋转后获取新的矢量值,c++,openscenegraph,C++,Openscenegraph,旋转几何体后如何获取新点 osg::ref_ptr<osg::Vec3Array> points = new osg::Vec3Array; osg::ref_ptr<osg::Geometry> geometry( new osg::Geometry); points->push_back(osg::Vec3(0.0,0.0,0.0)); points->push_back(osg::Vec3(10.0,10.0,0.0)); geometry -&g
osg::ref_ptr<osg::Vec3Array> points = new osg::Vec3Array;
osg::ref_ptr<osg::Geometry> geometry( new osg::Geometry);
points->push_back(osg::Vec3(0.0,0.0,0.0));
points->push_back(osg::Vec3(10.0,10.0,0.0));
geometry ->setVertexArray(points.get());
geometry ->addPrimitiveSet(new osg::DrawArrays(GL_LINES,0, points->size()));
cout<<points[0][1]; //returns the right values 10 10 0
MatrixTransform* transform = new osg::MatrixTransform;
const double angle = 0.8;
const Vec3d axis(0, 0, 1);
transform->setMatrix(Matrix::rotate(angle, axis));
transform->addChild(geometry);
osg::ref_ptr points=新osg::vec3阵列;
osg::ref_ptr几何体(新osg::几何体);
点->推回(osg::Vec3(0.0,0.0,0.0));
点->推回(osg::Vec3(10.0,10.0,0.0));
几何->setVertexArray(points.get());
geometry->addPrimitiveSet(新osg::DrawArray(GL_线,0,点->大小());
coutaddChild(几何);
我试过这个:
Vec3Array *_line= dynamic_cast< osg::Vec3Array*>(transform->getChild(0)->asGeometry()->getVertexArray());
cout<<_line->back(); // it returns equal 10 10 0
Vec3Array*\u line=dynamic\u cast(transform->getChild(0)->asGeometry()->getVertexArray());
cout您看到的是预期的行为:MatrixTransform在每一帧应用于基础几何体,从而移动“可视化”几何体。
如果确实要修改几何体顶点,则需要明确执行以下操作:
const double angle = 0.8;
const Vec3d axis(0, 0, 1);
osg::Matrix mx = Matrix::rotate(angle, axis));
osg::Vec3 originalVx(10.0, 10.0, 0.0);
osg::Vec3 modifiedVx = originalVx * mx;
Vec3Array *_line= dynamic_cast< osg::Vec3Array*>(transform->getChild(0)->asGeometry()->getVertexArray());
*_line[1] = modifiedVx;
const双角度=0.8;
常量向量3D轴(0,0,1);
osg::矩阵mx=矩阵::旋转(角度、轴));
osg::Vec3 originalVx(10.0,10.0,0.0);
osg::Vec3 modifiedVx=原始alvx*mx;
Vec3Array*_line=dynamic\u cast(transform->getChild(0)->asGeometry()->getVertexArray());
*_第[1]行=修改后的DVX;
如果更新是在运行时进行的,则需要弄脏VertexBuffer()并/或在使用时使显示列表无效。谢谢,这就是我的想法,我必须将矩阵乘以每个vertice。因此,矩阵变换对于获得新坐标是无用的。我正在编写运动学代码。