Osg-Osg实例牛对象局部旋转效果(Qt5.14.2+osgEarht3.6.5+win10)-No10-LocalRotate

相关资料:

https://blog.csdn.net/pizi0475/article/details/5387514    OSG中测试旋转与平移

代码实例:

.pro

 1 QT       += core gui widgets
 2 TARGET = TestOsgQt
 3 TEMPLATE = app
 4 DEFINES += QT_DEPRECATED_WARNINGS
 5 CONFIG += c++11
 6 
 7 SOURCES += \
 8         main.cpp
 9 
10 HEADERS +=
11 
12 OsgDir = D:\\RuanJian\\osg365R
13 CONFIG(release, debug|release) {
14         LIBS += -L$${OsgDir}/lib/ -losgDB -losgViewer -lOpenThreads -losgAnimation -losg \
15                                   -losgEarth -losgEarthAnnotation -losgEarthFeatures -losgEarthSymbology -losgEarthUtil \
16                                   -losgQOpenGL -losgUtil -losgText -losgTerrain -losgSim \
17                                   -losgShadow -losgParticle -losgManipulator -losgGA -losgFX \
18                                   -losgWidget
19 } else {
20         LIBS += -L$${OsgDir}/debug/lib/ -losgDBd -losgViewerd -lOpenThreadsd -losgAnimationd -losgd \
21                                   -losgEarthd -losgEarthAnnotationd -losgEarthFeaturesd -losgEarthSymbologyd -losgEarthUtild \
22                                   -losgQOpenGLd -losgUtild -losgTextd -losgTerraind -losgSimd \
23                                   -losgShadowd -losgParticled -losgManipulatord -losgGAd -losgFXd \
24 }
25 
26 
27 INCLUDEPATH += $${OsgDir}/include
28 DEPENDPATH += $${OsgDir}/include
View Code

main.cpp

 1 #include <QApplication>
 2 
 3 #include <osg/Node>
 4 #include <osg/Group>
 5 #include <osg/Geode>
 6 #include <osg/Geometry>
 7 #include <osg/Texture2D>
 8 #include <osg/StateSet>
 9 #include <osg/PositionAttitudeTransform>
10 #include <osgViewer/Viewer>
11 #include <osgDB/ReadFile>
12 #include <osgParticle/PrecipitationEffect>
13 // 雨雪效果
14 #include <osg/MatrixTransform>
15 // 粒子效果
16 #include <osgParticle/PrecipitationEffect>
17 #include <osgParticle/Particle>
18 #include <osgParticle/LinearInterpolator>
19 #include <osgParticle/ParticleSystem>
20 #include <osgParticle/RandomRateCounter>
21 #include <osgParticle/PointPlacer>
22 #include <osgParticle/RadialShooter>
23 #include <osgParticle/ModularEmitter>
24 #include <osgParticle/ParticleSystemUpdater>
25 #include <osgParticle/ModularProgram>
26 #include <osgUtil/Optimizer>
27 #include <osgUtil/Simplifier>
28 #include <osgParticle/FireEffect>
29 //
30 #include <osg/Fog>
31 #include <osgDB/ReadFile>
32 #include <osgViewer/Viewer>
33 #include <osg/StateSet>
34 #include <osg/StateAttribute>
35 #include <osgViewer/ViewerEventHandlers>
36 #include <osgWidget/ViewerEventHandlers>
37 // 旋转
38 #include <osg/NodeCallback>
39 #include <osg/PositionAttitudeTransform>
40 #include <osgViewer/Viewer>
41 #include <osg/MatrixTransform>
42 #include <osgDB/ReadFile>
43 #include <osgGA/TrackballManipulator>
44 
45 osg::Group* createTrans()
46 {
47     osg::Group* root = new osg::Group;
48     //创建姿态节点
49     osg::PositionAttitudeTransform* posCow = new osg::PositionAttitudeTransform;
50     root->addChild(posCow);
51     //创建变换节点
52     osg::MatrixTransform* matrixCow  = new osg::MatrixTransform;
53     root->addChild(matrixCow);
54     //
55     osg::Node* cow = osgDB::readNodeFile("D:\\osgFiles\\cow.osg");
56     posCow->addChild(cow);
57     osg::Quat quat;
58     //旋转
59     quat.makeRotate(osg::PI_2,osg::Vec3(0.0,0.0,1.0));
60     posCow->setAttitude(quat);
61     //设置位置
62     posCow->setPosition(osg::Vec3(-10,0.0,0.0));
63 
64     matrixCow->addChild(cow);
65     //旋转
66     quat.makeRotate(osg::DegreesToRadians(60.0),osg::Vec3(0.0,0.0,1.0));
67     //设置位置
68     matrixCow->setMatrix(osg::Matrixd::translate(osg::Vec3(10.0,0.0,0.0))*osg::Matrixd::rotate(quat));
69     return root;
70 }
71 
72 int main(int argc, char *argv[])
73 { 
74     //根节点
75     osg::Group* root = new osg::Group();
76     root = createTrans();
77     osgViewer::Viewer viewer;
78     //创建节点到场景中
79     viewer.setUpViewInWindow(50,50,500,400);
80     viewer.setSceneData(root);
81     viewer.realize();
82     return viewer.run();
83 }
View Code

 

posted on 2022-02-10 16:44  疯狂delphi  阅读(59)  评论(0编辑  收藏  举报

导航