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. 理解serverless无服务

    理解serverless无服务 阅读目录 一:什么是serverless无服务? 二:与传统模式架构区别? 三:serverless优缺点? 四:使用serverless的应用场景有哪些? 回到顶部 ...

  2. SATB深入详解与问题剖析【纯理论】

    延着上一次[https://www.cnblogs.com/webor2006/p/11147893.html]的理论继续. SATB: 在G1中,使用的是SATB(Snapshot-At-The-B ...

  3. Win10开启FTP与配置——(亲测完整无错版)

    #1.控制面板>程序>启用或关闭Windows功能>…(控制面板可在 桌面右键>个性化>主题>桌面图标设置>勾选控制面板>确定) #2.小娜搜索IIS打 ...

  4. BZOJ 4300: 绝世好题 二进制

    对于每一个数字拆位,然后维护一个大小为 30 左右的桶即可. code: #include <bits/stdc++.h> #define N 100006 #define setIO(s ...

  5. About & Ideas & Queries

    About Blog主现高一,文化课和OI啥都不会 本Blog主太懒,所以很多内容都缩在一个文章里,如数学.图论大礼包 https://wenku.baidu.com/view/56d76029647 ...

  6. python 比较运算符和逻辑运算符

    <1> 比较(即关系)运算符 python中的比较运算符如下表 运算符 描述 示例 == 检查两个操作数的值是否相等,如果是则条件变为真. 如a=3,b=3则(a == b) 为 true ...

  7. codeforces626F

    CF626F Group Projects  有n个学生,每个学生有一个能力值ai.现在要把这些学生分成一些(任意数量的)组,每一组的“不和谐度”是该组能力值最大的学生与能力值最小的学生的能力值的差. ...

  8. GB∕T 35658平台过检 已通过最新的部标JT/T 808-2019, JT/T 809-2019标准检测

    2019年交通部GPS平台检测标准发生了重大变化, 原来的796平台功能标准, 变更为GB/T35658标准, 这个标准其实2017年就公布了, 实际上还是796标准, 但是检测项目,以前是可选的, ...

  9. 2.线程--线程安全(synchronized)

    同步锁:synchronized,(缺点:不能手动开锁 解锁)   1.同步代码块 public void run(){ synchronized(this){/使用this关键字表示同一把锁,非静态 ...

  10. Hadoop(3)如何构建HDFS--HA,YARN---HA

    什么是HA? HA的意思是High Availability高可用,指当当前工作中的机器宕机后,会自动处理这个异常,并将工作无缝地转移到其他备用机器上去,以来保证服务的高可用. HA方式安装部署才是最 ...