十,从摄像机打印立方体的一个外表面

从摄像机是与主摄像机保持同样的投影矩阵,所以,不用单独设置。如果把漫游器还是在(1,0,0)这个位置,各个从摄像机看向上下左右前后六个面,那么会出现什么现象呢?应该是x正轴打印出来,其他均为空。

为了避免上一节出现的宽度方向有背景,所以应该把从摄像机视口设置为正方形,比如512x512。

运行结果如下
在这里插入图片描述
代码如下:
#include <osg/TextureCubeMap>
#include <osg/TexGen>
#include <osg/TexEnvCombine>
#include <osgUtil/ReflectionMapGenerator>
#include <osgDB/ReadFile>
#include <osgViewer/Viewer>
#include <osg/NodeVisitor>
#include <osg/ShapeDrawable>
#include <osg/Texture2D>
#include <osgGA/TrackballManipulator>
#include <osgDB/WriteFile>
static const char * vertexShader =
{
“in vec3 aPos;\n”
“varying vec3 outPos;”
“void main(void)\n”
“{\n”
“outPos = aPos;\n”
" gl_Position = ftransform();\n"
“}\n”
};

static const char *psShader =
{
“varying vec3 outPos;”
“uniform sampler2D tex0;”
"const vec2 invAtan = vec2(0.1591, 0.3183); "
"vec2 SampleSphericalMap(vec3 v) "
"{ "
" vec2 uv = vec2(atan(v.z, v.x), asin(v.y)); "
" uv *= invAtan; "
" uv += 0.5; "
" return uv; "
"} "

"void main()"
"{"
"vec2 uv = SampleSphericalMap(normalize(outPos)); "
"vec3 color = texture(tex0, uv).rgb;"
"gl_FragColor = vec4(color,1.0);\n"
"}\n"

};
class MyNodeVisitor : public osg::NodeVisitor
{
public:
MyNodeVisitor() : osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN)
{

}
void apply(osg::Geode& geode)
{int count = geode.getNumDrawables();for (int i = 0; i < count; i++){osg::ref_ptr<osg::Geometry> geometry = geode.getDrawable(i)->asGeometry();if (!geometry.valid()){continue;}osg::Array* vertexArray = geometry->getVertexArray();geometry->setVertexAttribArray(1, vertexArray);}traverse(geode);
}

};

std::vector<osg::ref_ptrosg::Image> getImageVectorBysetDomeCorrection(osgViewer::Viewer& viewer)
{
unsigned int screenWidth, screenHeight;
osg::GraphicsContext::WindowingSystemInterface * wsInterface = osg::GraphicsContext::getWindowingSystemInterface();
wsInterface->getScreenResolution(osg::GraphicsContext::ScreenIdentifier(0), screenWidth, screenHeight);

std::vector < osg::ref_ptr<osg::Image>> imageVector;
imageVector.clear();
osg::ref_ptr<osg::GraphicsContext::Traits> traits = new osg::GraphicsContext::Traits;
traits->x = 0;
traits->y = 0;
traits->width = screenWidth;
traits->height = screenHeight;
traits->windowDecoration = false;
traits->doubleBuffer = true;
traits->sharedContext = 0;
traits->readDISPLAY();
traits->setUndefinedScreenDetailsToDefaultScreen();osg::ref_ptr<osg::GraphicsContext> gc = osg::GraphicsContext::createGraphicsContext(traits.get());
if (!gc)
{osg::notify(osg::NOTICE) << "GraphicsWindow has not been created successfully." << std::endl;return imageVector;
}int textureWidth = 512;
int textureHeight = 512;osg::Camera::RenderTargetImplementation renderTargetImplementation = osg::Camera::FRAME_BUFFER_OBJECT;
// front face
{osg::ref_ptr<osg::Camera> camera = new osg::Camera;camera->setName("Front face camera");camera->setGraphicsContext(gc.get());camera->setViewport(new osg::Viewport(0, 0, textureWidth, textureHeight));camera->setAllowEventFocus(false);camera->setRenderTargetImplementation(renderTargetImplementation);camera->setRenderOrder(osg::Camera::PRE_RENDER);osg::ref_ptr<osg::Image> printImage = new osg::Image;printImage->setFileName(camera->getName());printImage->allocateImage(textureWidth, textureHeight, 1, GL_RGBA, GL_UNSIGNED_BYTE);camera->attach(osg::Camera::COLOR_BUFFER0, printImage); //关联采样贴图viewer.addSlave(camera.get(), osg::Matrixd(), osg::Matrixd());imageVector.push_back(printImage);
}// top face
{osg::ref_ptr<osg::Camera> camera = new osg::Camera;camera->setName("Top face camera");camera->setGraphicsContext(gc.get());camera->setViewport(new osg::Viewport(0, 0, textureWidth, textureHeight));camera->setAllowEventFocus(false);camera->setRenderTargetImplementation(renderTargetImplementation);camera->setRenderOrder(osg::Camera::PRE_RENDER);osg::ref_ptr<osg::Image> printImage = new osg::Image;printImage->setFileName(camera->getName());printImage->allocateImage(textureWidth, textureHeight, 1, GL_RGBA, GL_UNSIGNED_BYTE);camera->attach(osg::Camera::COLOR_BUFFER0, printImage); //关联采样贴图viewer.addSlave(camera.get(), osg::Matrixd(), osg::Matrixd::rotate(osg::inDegrees(-90.0f), 1.0, 0.0, 0.0));imageVector.push_back(printImage);
}// left face
{osg::ref_ptr<osg::Camera> camera = new osg::Camera;camera->setName("Left face camera");camera->setGraphicsContext(gc.get());camera->setViewport(new osg::Viewport(0, 0, textureWidth, textureHeight));camera->setAllowEventFocus(false);camera->setRenderTargetImplementation(renderTargetImplementation);camera->setRenderOrder(osg::Camera::PRE_RENDER);osg::ref_ptr<osg::Image> printImage = new osg::Image;printImage->setFileName(camera->getName());printImage->allocateImage(textureWidth, textureHeight, 1, GL_RGBA, GL_UNSIGNED_BYTE);camera->attach(osg::Camera::COLOR_BUFFER0, printImage); //关联采样贴图viewer.addSlave(camera.get(), osg::Matrixd(), osg::Matrixd::rotate(osg::inDegrees(-90.0f), 0.0, 1.0, 0.0) * osg::Matrixd::rotate(osg::inDegrees(-90.0f), 0.0, 0.0, 1.0));imageVector.push_back(printImage);
}// right face
{osg::ref_ptr<osg::Camera> camera = new osg::Camera;camera->setName("Right face camera");camera->setGraphicsContext(gc.get());camera->setViewport(new osg::Viewport(0, 0, textureWidth, textureHeight));camera->setAllowEventFocus(false);camera->setRenderTargetImplementation(renderTargetImplementation);camera->setRenderOrder(osg::Camera::PRE_RENDER);osg::ref_ptr<osg::Image> printImage = new osg::Image;printImage->setFileName(camera->getName());printImage->allocateImage(textureWidth, textureHeight, 1, GL_RGBA, GL_UNSIGNED_BYTE);camera->attach(osg::Camera::COLOR_BUFFER0, printImage); //关联采样贴图viewer.addSlave(camera.get(), osg::Matrixd(), osg::Matrixd::rotate(osg::inDegrees(90.0f), 0.0, 1.0, 0.0) * osg::Matrixd::rotate(osg::inDegrees(90.0f), 0.0, 0.0, 1.0));imageVector.push_back(printImage);
}// bottom face
{osg::ref_ptr<osg::Camera> camera = new osg::Camera;camera->setGraphicsContext(gc.get());camera->setName("Bottom face camera");camera->setViewport(new osg::Viewport(0, 0, textureWidth, textureHeight));camera->setAllowEventFocus(false);camera->setRenderTargetImplementation(renderTargetImplementation);camera->setRenderOrder(osg::Camera::PRE_RENDER);osg::ref_ptr<osg::Image> printImage = new osg::Image;printImage->setFileName(camera->getName());printImage->allocateImage(textureWidth, textureHeight, 1, GL_RGBA, GL_UNSIGNED_BYTE);camera->attach(osg::Camera::COLOR_BUFFER0, printImage); //关联采样贴图viewer.addSlave(camera.get(), osg::Matrixd(), osg::Matrixd::rotate(osg::inDegrees(90.0f), 1.0, 0.0, 0.0) * osg::Matrixd::rotate(osg::inDegrees(180.0f), 0.0, 0.0, 1.0));imageVector.push_back(printImage);
}// back face
{osg::ref_ptr<osg::Camera> camera = new osg::Camera;camera->setName("Back face camera");camera->setGraphicsContext(gc.get());camera->setViewport(new osg::Viewport(0, 0, textureWidth, textureHeight));camera->setAllowEventFocus(false);camera->setRenderTargetImplementation(renderTargetImplementation);camera->setRenderOrder(osg::Camera::PRE_RENDER);osg::ref_ptr<osg::Image> printImage = new osg::Image;printImage->setFileName(camera->getName());printImage->allocateImage(textureWidth, textureHeight, 1, GL_RGBA, GL_UNSIGNED_BYTE);camera->attach(osg::Camera::COLOR_BUFFER0, printImage); //关联采样贴图viewer.addSlave(camera.get(), osg::Matrixd(), osg::Matrixd::rotate(osg::inDegrees(180.0f), 1.0, 0.0, 0.0));imageVector.push_back(printImage);
}viewer.getCamera()->setProjectionMatrixAsPerspective(90.0f, 1.0, 0.1, 10);//viewer.getCamera()->setNearFarRatio(0.0001f);
return imageVector;

}

int main()
{
std::string strHDRImageName = “D:/tutorial/LearnOpenGL-master/LearnOpenGL-master/resources/textures/hdr/newport_loft.hdr”;
osg::ref_ptrosg::Image image = osgDB::readImageFile(strHDRImageName);

int imageWidth = image->s();
int imageHeight = image->t();
osg::ref_ptr<osg::Texture2D> texture = new osg::Texture2D;
texture->setImage(image.get());
//glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB16F, width, height, 0, GL_RGB, GL_FLOAT, data);
//
//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
//texture->osg::ref_ptr<osg::Box> box = new osg::Box(osg::Vec3(0, 0, 0), 1);
osg::ref_ptr<osg::ShapeDrawable> drawable = new osg::ShapeDrawable(box);
osg::ref_ptr<osg::Geode> geode = new osg::Geode;
geode->addDrawable(drawable);
MyNodeVisitor nv;
geode->accept(nv);
osg::ref_ptr<osg::StateSet> stateset = geode->getOrCreateStateSet();
stateset->setTextureAttributeAndModes(0, texture, osg::StateAttribute::OVERRIDE | osg::StateAttribute::ON);//shaderosg::ref_ptr<osg::Shader> vs1 = new osg::Shader(osg::Shader::VERTEX, vertexShader);
osg::ref_ptr<osg::Shader> ps1 = new osg::Shader(osg::Shader::FRAGMENT, psShader);
osg::ref_ptr<osg::Program> program1 = new osg::Program;
program1->addShader(vs1);
program1->addShader(ps1);
program1->addBindAttribLocation("aPos", 1);osg::ref_ptr<osg::Uniform> tex0Uniform = new osg::Uniform("tex0", 0);
stateset->addUniform(tex0Uniform);
stateset->setAttribute(program1, osg::StateAttribute::ON);osgViewer::Viewer viewer;
osg::ref_ptr<osgGA::TrackballManipulator> manipulator = new osgGA::TrackballManipulator();
viewer.setCameraManipulator(manipulator);
osg::Vec3d newEye(1, 0, 0);
osg::Vec3 newCenter(0, 0, 0);
osg::Vec3 newUp(0, 1, 0);
manipulator->setHomePosition(newEye, newCenter, newUp);
osg::ref_ptr<osg::Camera> camera = viewer.getCamera();
std::vector<osg::ref_ptr<osg::Image>> imageVector = getImageVectorBysetDomeCorrection(viewer);
viewer.setSceneData(geode.get());double fovy, aspectRatio, zNear, zFar;
bool bPrinted = false;
while (!viewer.done())
{viewer.frame();camera->getProjectionMatrixAsPerspective(fovy, aspectRatio, zNear, zFar);if (!bPrinted){bPrinted = true;for (int i = 0; i < imageVector.size(); i++){std::string strPrintName = "e:/" + imageVector[i]->getFileName() + ".bmp";osgDB::writeImageFile(*(imageVector[i]), strPrintName);}}
}
return viewer.run();

}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.rhkb.cn/news/142542.html

如若内容造成侵权/违法违规/事实不符,请联系长河编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

LLaMa

文章目录 Problems403 代码文件LLaMA: Open and Efficient Foundation Language Models方法预训练数据结构优化器一些加速的方法 结果Common Sense ReasoningClosed-book Question AnsweringReading ComprehensionMassive Multitask Language Understanding Instruction Finetu…

【实验记录】AGW | Visible-Infrared Re-ID

【RT】Visible Thermal Re-IDDeep Learning for Person Re-identification: A Survey and Outlook中提出了一个针对单/跨模态行人重识别的baseline&#xff1a;AGW 做过两次&#xff0c;在测试阶段有问题&#xff0c;现在再重做一次&#x1f914;Code RTX3090 修改数据集路…

【空间-光谱联合注意网络:多时相遥感图像】

A Spatial–Spectral Joint Attention Network for Change Detection in Multispectral Imagery &#xff08;一种用于多光谱图像变化检测的空间-光谱联合注意网络&#xff09; 变化检测是通过比较双时相图像来确定和评估变化&#xff0c;这是遥感领域的一项具有挑战性的任务…

c++图像的边缘检测

图像的边缘检测 cv::Canny 是 OpenCV 中用于进行边缘检测的函数&#xff0c;特别是用于检测图像中的边缘。Canny 边缘检测是一种广泛使用的技术&#xff0c;它能够识别图像中的边缘&#xff0c;这些边缘通常表示对象之间的边界或图像中的显著特征 void cv::Canny(const cv::M…

【lesson7】git的介绍及使用

文章目录 什么是gitgit的历史git使用在gitee上创建仓库git clone HTTPS地址git add .git add 文件名git commit “日志”git pushgit loggit rm 文件名git statusgit pull 什么是git git是版本控制器&#xff0c;那么什么是版本控制器呢&#xff1f; 下面讲个故事为大家讲解一…

运算放大器(四):输入偏置电流

一、定义 运放输入级一般由 或 MOSFET 构成&#xff0c;理想情况下&#xff0c;运放的输入端没有电流流入。实际上为保证放大器工作在线性范围&#xff0c;运放的输入端一般设计成基极&#xff08;栅极&#xff09;开路&#xff0c;由外电路提供电流的方式&#xff0c;所以需要…

c++-string

文章目录 前言一、STL库介绍二、标准库中的string类1、string类介绍2、string类使用3.1 string类的构造函数3.2 string类对象的容量操作3.3 string类对象的遍历操作3.4 string类对象的访问操作3.5 string类对象的修改操作3.6 string类对象的字符串操作 三、模拟实现string类四、…

Prettier - Code formatter格式化规则文件

文章目录 前言安装使用 前言 先前公司在规范代码时,由于个人业务繁忙跟技术总监是后端出身用的IDEA不熟悉vsCode;以及大多数时都自己一个人负责一个项目,当时并不看重这些;最近在整理vue3tsvite的脚手架模板(平时工作用的react),开始整理格式化代码,方便之后 vue 和 react 中应…

element plus table 拖拽

element plus table 拖拽 sortablejs package.json "sortable.js": "^0.3.0","sortablejs": "^1.14.0", "vuedraggable": "^2.24.3",我的table 是在 el-dialog 里面的 在开发过程中出现过两个问题 1.进入加载 …

【力扣2154】将找到的值乘以 2

&#x1f451;专栏内容&#xff1a;力扣刷题⛪个人主页&#xff1a;子夜的星的主页&#x1f495;座右铭&#xff1a;前路未远&#xff0c;步履不停 目录 一、题目描述二、题目分析 一、题目描述 题目链接&#xff1a;将找到的值乘以 2 给你一个整数数组 nums &#xff0c;另给…

百度实习一面(知识图谱部门)

百度面经&#xff08;知识图谱部&#xff09;一面 1.自我介绍 介绍完了&#xff0c;打开共享&#xff0c;对着简历一点一点问 2.ffmpeg在项目中是怎么使用的 回答了ffmpeg在项目中使用的命令&#xff0c;用来干了什么 3.为什么使用toml配置&#xff0c;了解过yml配置吗&am…

Mock.js之Element-ui搭建首页导航与左侧菜单

&#x1f3ac; 艳艳耶✌️&#xff1a;个人主页 &#x1f525; 个人专栏 &#xff1a;《Spring与Mybatis集成整合》《springMvc使用》 ⛺️ 生活的理想&#xff0c;为了不断更新自己 ! 1、Mock.js的使用 1.1.什么是Mock.js Mock.js是一个模拟数据的生成器&#xff0c;用来帮助前…

【前端面试题】2023年 国庆 前端面试真题之JS篇

人的一生&#xff0c;总是难免有浮沉。不会永远如旭日东升&#xff0c;也不会永远痛苦潦倒。反复地一浮一沉&#xff0c;对于一个人来说&#xff0c;正是磨练。因此&#xff0c;浮在上面的&#xff0c;不必骄傲&#xff1b;沉在底下的&#xff0c;更用不着悲观。必须以率直、谦…

Linux内核源码分析 (B.2)深入理解 Linux 物理内存管理

Linux内核源码分析 (B.2)深入理解 Linux 物理内存管理 文章目录 Linux内核源码分析 (B.2)深入理解 Linux 物理内存管理1. 前文回顾2. 从 CPU 角度看物理内存模型2.1 FLATMEM 平坦内存模型2.2 DISCONTIGMEM 非连续内存模型2.3 SPARSEMEM 稀疏内存模型2.3.1 物理内存热插拔 3. 从…

DM8归档管理

开启归档 归档的格式&#xff1a; ARCH_NAME_DB_MAGIC[SEQNO]_日期时间.log ARCH_NAME 是在 dmarch.ini中配置的 LOCAL/REMOTE 归档名称 DB_MAGIC 是生成日志的数据库魔数 SEQNO 代表DSC 节点号&#xff0c;日期时间是归档日志文件的创建时间。 eg&#xff1a;ARCHIVE_LOCAL1_…

解决kali beef启动失败问题及实战

文章目录 一、解决方法二、靶场实战应用1.首先打开dvwa这个靶场&#xff0c;设置难度为low2.打开xss-stored3.准备payload4.提交payload5.利用 一、解决方法 首先需卸载 ruby apt remove ruby 卸载 beef apt remove beef-xss 重新安装ruby apt-get install ruby apt-get insta…

Swift SwiftUI 修改 List 背景颜色

Preview: Code: .listRowBackground(Color(.yellow)).scrollContentBackground(.hidden) .background(.linearGradient(colors: [.white, .accentColor], startPoint: .top, endPoint: .bottom))喜欢或对你有帮助&#xff0c;点个赞吧&#xff0c;自己先点个嘿嘿。 有错误或者…

JVM高级性能调试

标准的JVM是配置为了高吞吐量&#xff0c;吞吐量是为了科学计算和后台运行使用&#xff0c;而互联网商业应用&#xff0c;更多是为追求更短的响应时间&#xff0c;更低的延迟Latency&#xff08;说白了就是更快速度&#xff09;&#xff0c;当用户打开网页没有快速响应&#xf…

Android StringFog 字符串自动加密

一、StringFog 作用 一款自动对dex/aar/jar文件中的字符串进行加密Android插件工具&#xff0c;正如名字所言&#xff0c;给字符串加上一层雾霭&#xff0c;使人难以窥视其真面目。可以用于增加反编译难度&#xff0c;防止字符串代码重复。 支持java/kotlin。支持app打包生成…

Labelme分割标注软件

Labelme分割标注软件 1、环境配置与安装1.1 创建conda虚拟环境(建议)1.2 安装Labelme 2、简单使用2.1 创建label标签文件2.2 启动labelme2.3 打开文件/文件夹2.4 设置保存结果路径2.5 标注目标2.6 保存json文件格式 3 格式转换3.1 转换语义分割标签3.2 转换实例分割标签 相关重…