osg::MatrixTransform 模型基本变换
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 模型基本变换的更多相关文章
- osg fbx模型删除模型中的某几个节点,实现编辑模型的功能
fbx model element count:80 三维视图: {三维} 4294967295 osg::MatrixTransform1 基本墙 wall_240 [361750] 4294967 ...
- osg项目经验1<MFC+OSG中模型点选效果>
点选主要是重载osg的GUIEventHandler, class CPickHandler : public osgGA::GUIEventHandler{ //自定义回调函数名:CPickHand ...
- osg fbx模型点击节点,对应节点染色
class CPickHandler :public osgGA::GUIEventHandler { public: CPickHandler(osgViewer::Viewer *viewer) ...
- osg 线程模型
void ViewerBase::frame(double simulationTime) { if (_done) return; // OSG_NOTICE<<std::endl< ...
- osg fbx 模型结构操作
osg::Node* TeslaManage::findOsgNodeByName(QString &nodeNme) { osg::Node* findNode = NULL; std::v ...
- osg fbx 模型树结构
void Test::printOsgGroup(osg::ref_ptr<osg::Group> &groupParam) { qDebug() <<groupPar ...
- osg fbx模型中任何一个节点染色(着色)
void setNodeStateset(osg::Node *nodeParam) { osg::ref_ptr<osg::StateSet> stateset1 = nodeParam ...
- osg 3ds模型加载与操作
QString item1 = QString::fromStdString(groupParam->getChild(k)->getName()); QStandardItem* ite ...
- osg中使用MatrixTransform来实现模型的平移/旋转/缩放
osg中使用MatrixTransform来实现模型的平移/旋转/缩放 转自:http://www.cnblogs.com/kekec/archive/2011/08/15/2139893.html# ...
随机推荐
- charles 右键菜单
本文参考:charles 右键菜单 在网址/域名上右键 可以获得下面菜单 区域 1 基本操作 :基本的URL复制,文件保存,以及选中文件内搜索 区域 2 重写操作 :重写发送请求(调用接口合适),或者 ...
- GlusterFS分布式存储系统
一,分布式文件系统理论基础 1.1 分布式文件系统出现 计算机通过文件系统管理,存储数据,而现在数据信息爆炸的时代中人们可以获取的数据成指数倍的增长,单纯通过增加硬盘个数来扩展计算机文件系统的存储容量 ...
- 透过CountDownLatch窥探AQS
本文来自公众号“Kahuna”,可搜索Alitaba119,欢迎关注,转载请注明出处,非常感谢 “ A synchronization aid that allows one or more thre ...
- 牛客练习赛33 E. tokitsukaze and Similar String (字符串哈希)
题目链接:https://ac.nowcoder.com/acm/contest/308/E 题意:中文题 见链接 题解:哈希预处理(三哈希模板) #include <bits/stdc++.h ...
- Number of Islands II
Given a n,m which means the row and column of the 2D matrix and an array of pair A( size k). Origina ...
- 002_软件安装之_keil4与keil5共存
目的:实现keil4和keil5的共存 1. Keil4 主要用来开发 C51 程序 2. Keil5 也就是 MDK 主要用来开发 ARM 芯片,如 STM32 系列芯片 3. 资料下载地址:链接: ...
- 遍历器Iterator--指针对象
一. 什么是遍历器 1. 遍历器对象(Iterator) 遍历器对象本质上是一个指针对象,该对象有一个next方法,调用next方法返回一个 含有value和done属性的对象{value: val/ ...
- sql server in和exists 的区别
如图,现在有两个数据集,左边表示#tempTable1,右边表示#tempTable2.现在有以下问题: 1.求两个集的交集? 2.求tempTable1中不属于集#tempTable2的集? 先 ...
- sudo 命令报 unable to resolve host 导致反应速度变慢
1 分析 1.1 字面分析,不能解析主机 1.2 由于修改了本地主机名称所导致 2 解决 2.1 打开 /etc/hosts 2.2 主机名称指向,如你的主机名为 debian 2.3 127.0. ...
- loj #136
最小瓶颈路 做最小生成树是进行特判即可 时间复杂度 n * k #include <bits/stdc++.h> const int N = 1010, M = 1e5 + 10; str ...