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# ...
随机推荐
- CMake---基础练习1
因为卡在一个问题上,几经排除应该可能是CMakeLists.txt写的不正确,但是又生成了可执行文件,运行可执行文件报错.多方排除,应该是CMakeLists.txt加载动态库的时候,函数加载的不全. ...
- 数据结构(python)
列表 list 在头部进行插入是个相当耗时的操作(需要把后边的元素一个一个挪个位置).假如你需要频繁在数组两头增删,list 就不太合适.数组是最常用到的一种线性结构,其实 python 内置了一个 ...
- Mybatis3.0-[tp_28-29]-映射文件-resultMap_自定义结果集映射规则_及关联环境的搭建
笔记要点出错分析与总结工程组织 1.定义接口 EmployeeMapperPlus.java package com.dao; import com.bean.*; public interface ...
- Oracle-查看sql运行状况
查看占io较大的正在运行的session SELECT se.sid, se.serial#, pr.SPID, se.username, se.status, se.terminal, se.pro ...
- QProgressBar 样式
setStyleSheet( "QProgressBar{border:1px solid #FFFFFF;" "height:30;" "backg ...
- 50、[源码]-Spring容器创建-Bean创建完成
50.[源码]-Spring容器创建-Bean创建完成 11.finishBeanFactoryInitialization(beanFactory);初始化所有剩下的单实例bean: beanFac ...
- Spring事务管理器
1.创建实体和接口 public class Bank { private Integer id; private String name; private String manay; public ...
- MyBatis底层实现原理: 动态代理的运用
转载:https://mp.weixin.qq.com/s/_6nyhaWX15mh3mkj8Lb0Zw Mybatis中声明一个interface接口,没有编写任何实现类,Mybatis就能返回接口 ...
- luogu 1593
$Answer = A ^ B $ 的因子之和 将 $A$ 进行质因数分解$A = p_1 ^ {a_1} P_2 ^ {a_2} p_3 ^ {a_3} \cdots p_k ^ {a_k}$ $A ...
- luogu P1382 楼房
二次联通门 : luogu P1382 楼房 /* luogu P1382 楼房 线段树 + 扫描线 + 离散化 正解貌似是堆... MMP...二段式线段树各种错误... 离散化一下横坐标 扫描线扫 ...