OSG setMatrix函数误区

setMatrix是Node模型平移、旋转、缩放的接口函数,功能强大非常好用,但是稍微不注意,连续调用就会发现后面的功能调用将会覆盖之前的功能调用,这种致命错误,有时候总是让人手足无措,解决这个问题,我们可以从osg::MatrixTransform派生一个新类出来。

头文件定义:

#ifndef QNODEMATRIX_H
#define QNODEMATRIX_H

#include<osg/MatrixTransform>
#include <osg/Matrixd>
    class QNodeMatrix:
    public osg::MatrixTransform
{
public:
    QNodeMatrix();

public:
    /*设置模型旋转方式*/
    void rotaing(const osg::Vec3d &pivot, const osg::Vec3d &axis, float angularVelocity);

    /*移动模型*/
    void move(const osg::Vec3d &pos);

    /*限制模型大小*/
    void adapt(osg::BoundingSphere &_bs);
    void adapt(osg::Node *node);

    /*缩放模型*/
    void scale(const osg::Matrix &mat);
    void scale(const float &_scale);

    /*旋转模型*/
    void rotate(const osg::Matrix &mat);
    void rotate(const float angle, const osg::Vec3f &axis);

    /*关联模型*/
    void _addChild(osg::Node *node);

private:
    osg::ref_ptr<osg

猜你喜欢

转载自blog.csdn.net/u012156872/article/details/115376435
今日推荐