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# ...
随机推荐
- linux网络编程之socket编程(五)
今天继续学习socket网络编程,最近北京阴雨连绵,降温明显,感觉是要立马转入冬季的节奏,天冷晚上得注意多盖点被子哦,言归正传,进入正题: 对于之前写的回射客户/服务器端的程序中,我们是用的read和 ...
- SQL SERVER中如何查找存储过程中一段代码
select b.name ,a.text from syscomments a,sysobjects b where and object_id(b.name)=a.id and b.xtype i ...
- Ajax的简单例子——PHP
PHP PHP是一种创建动态交互性站点的服务器端脚本语言 PHP能够生成动态页面内容 PHP能够创建.打开.读取.写入.删除以及关闭服务器上的文件 PHP能够接收表单数据 PHP能够发送并取回cook ...
- Scrapy框架的八个扩展
一.proxies代理 首先需要在环境变量中设置 from scrapy.contrib.downloadermiddleware.httpproxy import HttpProxyMiddlewa ...
- MySQL 视图 触发器 事务 存储过程 函数 流程控制 索引与慢查询优化
视图 1.什么是视图? 视图就是通过查询得到的一张虚拟表,然后保存下来,下次可直接使用 2.为什么要使用视图? 如果要频繁使用一张虚拟表,可以不用重复查询 3.如何使用视图? create view ...
- Spring顾问、IOC注解和注解增强
一.顾问 通知的一种表现方式(顾问包装通知/增强) Advisor: 名称匹配方法: NameMecthMethodPointcutAdvisor 1.定义了一个业务类 package cn.spri ...
- MySql存储过程参考
Mysql(9)---纪录一次实际开发过程中用到的复杂存储过程 为了尽可能的还原当时为什么需要用到存储过程,下面我写了个详细的文档,我们可以从需求文档出发来分析. 有关存储过程之前也写了两篇文章来做铺 ...
- zabbix主动模式,自定义Key监控 zabbix采集器
主动模式不是只能用模板提供的标准检测器方式 zabbix-agent两种运行方式即主动模式和被动模式.默认被动模式. 两种模式是相对 客户端 角度来说的. 被动模式:等待server来取数据,可以使用 ...
- python中的关键字yield有什么作用?
保存当前运行状态,然后暂停执行,即将函数挂起.yield关键字后面表达式的值作为返回值返回.当使用next(),send()函数从断点处继续执行.
- mac 登陆phpmyadmin 提示 mysqli_real_connect(): (HY000/2002): No such file or directory
我们将下载的phpmyadmin 放在apache目录中,进入phpmyadmin目录, 首先将这个目录中的配置文件改名 sudo mv config.sample.inc.php config.in ...