osg模型部分节点旋转

osg::ref_ptr<osg::Geode> CreateBox()
{
    osg::ref_ptr<osg::Geode> geode = new osg::Geode;
    osg::ref_ptr<osg::TessellationHints> hints = new osg::TessellationHints;
    hints->setDetailRatio(0.5);

    osg::ref_ptr<osg::Material> material = new osg::Material;
    material->setAmbient(osg::Material::FRONT_AND_BACK, osg::Vec4(1.0f, 1.0f, 1.0f, 1.0f));
    material->setDiffuse(osg::Material::FRONT_AND_BACK, osg::Vec4(1.0f, 1.0f, 1.0f, 1.0f));
    material->setSpecular(osg::Material::FRONT_AND_BACK, osg::Vec4(1.0f, 1.0f, 1.0f, 1.0f));
    material->setShininess(osg::Material::FRONT_AND_BACK, 60);

    osg::ref_ptr<osg::Texture2D> texture2D = new osg::Texture2D;
    //设置纹理
    osg::ref_ptr<osg::Image> image = osgDB::readImageFile("D:\\image_1\\arm1.jpg");
    if (image.valid())
    {
        texture2D->setImage(image.get());
    }

    osg::ref_ptr<osg::ShapeDrawable> shape = new osg::ShapeDrawable(new osg::Box(osg::Vec3(0.0, 0.0, 0.0), 1.0, 1.0, 1.0), hints.get());
    shape->setColor(osg::Vec4(100.0f, 255.0f, 0.0f, 0.6));

    geode->getOrCreateStateSet()->setAttributeAndModes(material.get(), osg::StateAttribute::ON);
    geode->getOrCreateStateSet()->setTextureAttributeAndModes(0, texture2D, osg::StateAttribute::ON);
    geode->addDrawable(shape.get());

    return geode;
}
osg::ref_ptr<osg::Geode> CreateSphere()
{
    osg::ref_ptr<osg::Group> _root = new osg::Group;

    //创建一个叶结点对象
    osg::ref_ptr<osg::Geode> geode = new osg::Geode;

    //设置半径和高度
    float _radius = 0.6f;
    float _height = 1.0f;

    //创建精细度对象,精细度越高,细分就越多
    osg::ref_ptr<osg::TessellationHints> hints = new osg::TessellationHints;
    hints->setDetailRatio(0.9f);

    //添加一个球体,第一个参数是预定义的几何体对象,第二个是精细度默认为1
    geode->addDrawable(new osg::ShapeDrawable(new osg::Sphere(osg::Vec3(0.0f, 0.0f, 0.0f), _radius), hints));

    //_root->addChild(geode);

    return geode.get();
}
void rotate2()
{
    v1 = osg::Matrix::rotate(osg::DegreesToRadians(rorate1), 0, 1, 0);
    //osg::Z_AXIS
    //v1 = osg::Matrix::rotate(rorate1, osg::Y_AXIS);
    //rot->setMatrix(osg::Matrix::rotate(osg::DegreesToRadians(rorate1), 0, 1, 0));
    //rot->setMatrix(osg::Matrix::rotate(osg::DegreesToRadians(rorate3), 1, 0, 0));
    rot->setMatrix(v1);
}
void rotate3()
{
    h1 = osg::Matrix::rotate(osg::DegreesToRadians(rorate3), 1, 0, 0);
    //h1 = osg::Matrix::rotate(rorate3, osg::X_AXIS);
    //rot->setMatrix(h1*v1);
    rot->setMatrix(h1);
    //rot->setMatrix(v1*h1);
    //rot->setMatrix(osg::Matrix::rotate(osg::DegreesToRadians(rorate3), 1, 0, 0)*osg::Matrix::rotate(osg::DegreesToRadians(rorate1), 0, 1, 0));
    //rot->setMatrix(osg::Matrix::rotate(osg::DegreesToRadians(rorate1), 0, 1, 0));
}

原文地址:https://www.cnblogs.com/herd/p/11308129.html

时间: 2024-08-09 01:32:58

osg模型部分节点旋转的相关文章

osg中使用MatrixTransform来实现模型的平移/旋转/缩放

osg中使用MatrixTransform来实现模型的平移/旋转/缩放 转自:http://www.cnblogs.com/kekec/archive/2011/08/15/2139893.html#undefined MatrixTransform是从Transform - Group继承而来,因此可以在它的下面挂接Node对象. 通过设置其矩阵,来实现其下子节点的模型变换. -- 用局部坐标系来理解(局部坐标系又称惯性坐标系,其与模型的相对位置在变换的过程中始终不变) 如下代码: // 创建

OSG模型简单控制

OSG模型简单控制 转自:http://milkcu.sintune.net/blog/archives/1392673560.html 结点基本操作 添加结点 OSG中使用osg::Node和osg::Group装载模型,Node是Group的父类. 可以通过下面代码再场景中显示多个模型: #include <osgDB/ReadFile> #include <osgViewer/Viewer> #include <osg/Node> int main(void) {

OSG 实现跟随节点的相机(转)

本章教程将继续使用回调和节点路径(NodePath)来检索节点的世界坐标. 本章目标: 在一个典型的仿真过程中,用户可能需要从场景中的各种车辆和人物里选择一个进行跟随.本章将介绍一种将摄像机“依附”到场景图形节点的方法.此时视口的摄像机将跟随节点的世界坐标进行放置. ---------------------------------------------------------------------- 概述: 视口类包括了一系列的矩阵控制器(osgGA::MatrixManipulator)

JS(六)DOM模型之节点

一.简介 通过js dom找到某个元素,对该元素增加子节点,或删除该元素的子节点. 二.示例 1.动态增加和删除节点元素 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta content="text/css" c

MFC加载osg模型

创建MFC单文档项目, OSGObject.h #pragma once #include <osgViewer\Viewer> #include <osgDB\ReadFile> #include <osgViewer\api\Win32\GraphicsWindowWin32> #include <osgGA\TrackballManipulator> #include <osg\Group> class COSGObject { publi

Qt + OpenSenceGraph(osg) 加载OSG模型

原文地址:https://www.cnblogs.com/herd/p/9944716.html

OSG节点更新与事件回调

OSG中的节点主要使用回调(CallBack)来完成用户临时.需要每帧执行的工作.根据回调功能被调用的时机划分为更新回调(Update CallBack)和人机交互时间回调(Event CallBack).前者在每一帧中系统遍历到当前节点时调用,后者则由交互事件触发,如操作键盘.鼠标.关闭窗口.改变窗口大小等动作.回调类基类是osg::NodeCallBack(),主要函数如下: //虚函数,回调函数主要操作在此函数中,子类应当重写,已完成相应操作 void operator()(Node* n

通过OSG实现对模型的日照模拟

目录 1. 加载模型 2. 光照 1) 环境反射 2) 漫反射 3) 日照方向 (1) 太阳高度角和太阳方位角 (2) 计算过程 4) 改进实现 3. 阴影 4. 太阳高度角与太阳方位角的计算 1) 太阳高度角计算公式 2) 太阳方位角计算公式 3) 太阳赤纬计算公式 4) 时角计算公式 5) 真太阳时 5. 参考文献 1. 加载模型 通过OpenSceneGraph加载一个倾斜摄影的场景模型数据: #include <iostream> #include <Windows.h>

JavaScript---网络编程(6)-Dom和Bom模型概念讲解(节点获取,window对象)

本节讲Dom和Bom模型概念讲解(节点获取,window对象). out.js: 写了2个输出到页面的函数. function println(param){ document.write(param+"<br/>"); } function print(param){ document.write(param); } window对象中的方式: 方法: confirm : bConfirmed = window.confirm( [sMessage]) 显示一个确认对话框