VCNodeMatrix.h

#pragma once
#include <osgViewer/Viewer>
#include <osgViewer/ViewerEventHandlers>
#include <osgViewer/CompositeViewer>
#include <osgDB/ReadFile>
#include <osg/Geode>
#include <osg/Node>
#include <osgGA/TrackballManipulator>
#include <osg/GraphicsContext>
#include <osg/ShapeDrawable>
#include <osg/Material>
#include <osg/Image>
#include <osg/Texture2D>
#include <osg/TexEnv>
#include <osg/TexGen>
#include <osg/MatrixTransform>
#include <osg/PositionAttitudeTransform>
#include <osg/AnimationPath> class VCNodeMatrix :
public osg::MatrixTransform
{
public:
VCNodeMatrix();
~VCNodeMatrix(); //添加
void addChildVC(osg::Node *nodeParam);
//设置模型转动方式
void rotateObject(const osg::Vec3d & pivot, const osg::Vec3d & axis, float angularVelocity); //模型旋转
void toRotate(float anguarVelocity);
void toRotate(const osg::Matrix &matrixParam); //模型缩放
void scaleModel(float scaleSize);
void scaleModel(const osg::Matrix &matrixParam); //模型移动
void toPosition(osg::Vec3d &pos); //限制模型大小
void adaptModelSize(osg::BoundingSphere &boundingS);
void adaptModelSize(osg::Node *nodePAram); private:
osg::ref_ptr<osg::MatrixTransform> matParam;
osg::BoundingSphere bSphere;
osg::Node *oriNode;
float level;//缩放参数
};

VCNodeMatrix.cpp

#include "VCNodeMatrix.h"

VCNodeMatrix::VCNodeMatrix()
{
matParam = new osg::MatrixTransform;
addChild(matParam.get());
level = 1.0;
} VCNodeMatrix::~VCNodeMatrix()
{
//delete matParam;
} void VCNodeMatrix::rotateObject(const osg::Vec3d & pivot, const osg::Vec3d & axis, float angularVelocity)
{
setUpdateCallback(new osg::AnimationPathCallback(pivot, axis, angularVelocity));
} //模型旋转
void VCNodeMatrix::toRotate(float anguarVelocity)
{
//setMatrix(matrixParam); } void VCNodeMatrix::toRotate(const osg::Matrix &matrixParam)
{
matParam->setMatrix(matrixParam);
} //模型缩放
void VCNodeMatrix::scaleModel(float scaleSize)
{
matParam->setMatrix(osg::Matrix::scale(scaleSize,scaleSize,scaleSize));
} void VCNodeMatrix::scaleModel(const osg::Matrix &matrixParam)
{
matParam->setMatrix(matrixParam);
} void VCNodeMatrix::addChildVC(osg::Node *nodeParam)
{
oriNode = nodeParam;
bSphere = nodeParam->getBound();
//matParam->addChild(nodeParam);
matParam->addChild(nodeParam);
} //模型移动
void VCNodeMatrix::toPosition(osg::Vec3d &pos)
{
osg::Vec3d vec3d;
vec3d.set(bSphere.center().x()*level, bSphere.center().y()*level, bSphere.center().z()*level);
matParam->setMatrix(osg::Matrix::translate(vec3d)*osg::Matrix::translate(pos));
} //限制模型大小
void VCNodeMatrix::adaptModelSize(osg::BoundingSphere &boundingS)
{
float level = boundingS.radius() / bSphere.radius();
matParam->setMatrix(osg::Matrix::scale(level, level, level)); } void VCNodeMatrix::adaptModelSize(osg::Node *nodeParam)
{
osg::BoundingSphere bsNode = nodeParam->getBound();
level = bsNode.radius() / bSphere.radius();
matParam->setMatrix(osg::Matrix::scale(level, level, level));
}
osg::ref_ptr<VCNodeMatrix> OSG_Qt_Rotating_0624::cretateObj()
{
osg::ref_ptr<VCNodeMatrix> vcnode = new VCNodeMatrix;
osg::ref_ptr<osg::Node> node = osgDB::readNodeFile("D:\\参考手册\\BIM\\osg\\build1.OSGB");
//vcnode->addChild(node.get());
vcnode->addChildVC(node.get()); //vcnode->rotateObject(osg::Vec3d(10.0,0.0,0.0),osg::Z_AXIS,1.0);
//vcnode->toRotate(osg::Matrix::rotate(osg::Quat(2.0,osg::Vec3d(1.0,0.0,0.0))));
//vcnode->toRotate(osg::Matrix::rotate(1.0,osg::Z_AXIS));
//vcnode->toRotate(osg::Matrix::translate(10.0,0.0,0.0));
vcnode->toPosition(osg::Vec3d(20.0, 0.0, 0.0)); //vcnode->adaptModelSize(vcnode.get()); return vcnode;
}

osg::MatrixTransform 模型基本变换的更多相关文章

  1. osg fbx模型删除模型中的某几个节点,实现编辑模型的功能

    fbx model element count:80 三维视图: {三维} 4294967295 osg::MatrixTransform1 基本墙 wall_240 [361750] 4294967 ...

  2. osg项目经验1<MFC+OSG中模型点选效果>

    点选主要是重载osg的GUIEventHandler, class CPickHandler : public osgGA::GUIEventHandler{ //自定义回调函数名:CPickHand ...

  3. osg fbx模型点击节点,对应节点染色

    class CPickHandler :public osgGA::GUIEventHandler { public: CPickHandler(osgViewer::Viewer *viewer) ...

  4. osg 线程模型

    void ViewerBase::frame(double simulationTime) { if (_done) return; // OSG_NOTICE<<std::endl< ...

  5. osg fbx 模型结构操作

    osg::Node* TeslaManage::findOsgNodeByName(QString &nodeNme) { osg::Node* findNode = NULL; std::v ...

  6. osg fbx 模型树结构

    void Test::printOsgGroup(osg::ref_ptr<osg::Group> &groupParam) { qDebug() <<groupPar ...

  7. osg fbx模型中任何一个节点染色(着色)

    void setNodeStateset(osg::Node *nodeParam) { osg::ref_ptr<osg::StateSet> stateset1 = nodeParam ...

  8. osg 3ds模型加载与操作

    QString item1 = QString::fromStdString(groupParam->getChild(k)->getName()); QStandardItem* ite ...

  9. osg中使用MatrixTransform来实现模型的平移/旋转/缩放

    osg中使用MatrixTransform来实现模型的平移/旋转/缩放 转自:http://www.cnblogs.com/kekec/archive/2011/08/15/2139893.html# ...

随机推荐

  1. Vue项目打包发布,配置Nginx

    #user nobody; worker_processes 1; #error_log logs/error.log; #error_log logs/error.log notice; #erro ...

  2. 查看安装的centos的操作系统版本

    cat /etc/redhat-release CentOS Linux release 7.6.1810 (Core)

  3. 【蜂窝】at+qcfg="band"的计算和使用

    查询附件 Quectel_EC25_LTE_模块产品规格书_V1.6 可知当前的蜂窝模块所对应的band频带是什么? eg.1 EC25-AU 当前选择4G 优先, FDD LTE 可看手册QCFG命 ...

  4. 本地python环境检查,插件检查及插件安装

    电脑windows键+r  输入cmd 在python命令模式下 pip list  --可以查看已安装的插件情况 或者用 pip freeze 也可以 卸载插件:pip uninstall *** ...

  5. seo与python大数据结合给文本分词并提取高频词

    最近研究seo和python如何结合,参考网上的一些资料,写的这个程序. 目的:分析某个行业(例如:圆柱模板)用户最关心的一些词,根据需求去自动调整TDK,以及栏目,内容页的规划 使用方法: 1.下载 ...

  6. machine learning(9) -- classification:Decision boundary

    machine learning(9) -- classification:Decision boundary 上图的decision boundary是一条直线,是属于预测函数的一个属性(当参数已经 ...

  7. 【中国剩余定理-入门】-C++

    中国剩余定理也称孙子定理,是中国古代求解一次同余式组(见同余)的方法.是数论中一个重要定理. 这玩意在luogu居然有模板题: [TJOI2009]猜数字 先来看一个问题: 在<孙子算经> ...

  8. 快速幂C++实现

    快速幂模板题 很明显,这个题目不能用简单的\(for\)循环+\(mod\)来完成,因为指数\(p\)已经达到了长整型,直接循环来完成的话肯定会超时的. 那么快速幂就应运而生了. 什么是快速幂呢? 利 ...

  9. 前端利用webuploader实现超大文件分片上传、断点续传

    本人在2010年时使用swfupload为核心进行文件的批量上传的解决方案.见文章:WEB版一次选择多个文件进行批量上传(swfupload)的解决方案. 本人在2013年时使用plupload为核心 ...

  10. loj 2011

    对于第 $i$ 天的询问前 $i - c - 1$ 天都会影响答案主席树维护 #include <iostream> #include <cstdio> #include &l ...