原理:就是用openVR驱动各种类型的VR眼镜驱动,然后不断给指定软件截图用opengl渲染到VR眼镜

这个代码的功能了就是后天运行,创建udp广播,收到“close”命令就启动VR渲染,“start”就是关闭渲染

mian.cpp




#include "mainwindow.h"
#include <QApplication>
#include <QSurfaceFormat>
#include <QSettings>
#include<QProcess>
#include<QMessageBox>
#include<QMutex>
#include<QDateTime>
#include<QTextStream>
#include<QFile>
#include<QDir>
static bool FindDog(){QProcess proc;proc.start("tasklist -fi \"imagename eq QVRViewer.exe\"");proc.waitForFinished();QString tmp;tmp = tmp.prepend(proc.readAll());if(tmp.contains("Console")){int step = tmp.indexOf("Console");tmp = tmp.mid(step + 10);if(tmp.contains("Console"))return true;}return false;
}void MessageOutPut(QtMsgType type, const QMessageLogContext &context, const QString &msg)
{static QMutex mutex;mutex.lock();QString text;switch(type){case QtDebugMsg:text = QString("Debug:");break;case QtWarningMsg:text = QString("Warning:");break;case QtCriticalMsg:text = QString("Critical:");break;case QtFatalMsg:text = QString("Fatal:");break;default:break;}QString current_date_time = QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss");QString message = QString("%1 %2%3").arg(current_date_time).arg(text).arg(msg);QFile file("log.txt");file.open(QIODevice::WriteOnly | QIODevice::Append);QTextStream text_stream(&file);text_stream << message << "\r\n";file.flush();file.close();mutex.unlock();}int main(int argc, char *argv[])
{QCoreApplication::setOrganizationName("Skeletonbrain");QCoreApplication::setOrganizationDomain("skeletonbrain.com");QCoreApplication::setApplicationName("QVRViewer");QSurfaceFormat glFormat;glFormat.setVersion(4, 1);glFormat.setProfile(QSurfaceFormat::CoreProfile);
//    glFormat.setSamples(0);glFormat.setSwapInterval(0);glFormat.setOption(QSurfaceFormat::DebugContext);QSurfaceFormat::setDefaultFormat(glFormat);QApplication a(argc, argv);qInstallMessageHandler(MessageOutPut);//安装日志if(FindDog()){QMessageBox box;box.setText("该程序已运行!");box.exec();return 0;}MainWindow w;w.show();w.move(-200,-200);return a.exec();
}
MainWindow.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include<QSystemTrayIcon>
#include <QMainWindow>
#include<QMenu>
#include<QAction>
#include<QTimer>
#include <QUdpSocket>namespace Ui {
class MainWindow;
}class VRView;class MainWindow : public QMainWindow
{Q_OBJECTpublic:explicit MainWindow(QWidget *parent = 0);~MainWindow();private slots:void HandleClose();void FindWindownHwnd();void readPendingDatagrams();
private:Ui::MainWindow *ui;VRView *vr;QSystemTrayIcon *m_trayIcon;QMenu *mMenu;QAction *exitAction;QTimer * tim;QUdpSocket *udpSocket;QString AppName;int  Rport;void initSocket();void ReadConfig();};
mainwindow.cpp

完整代码下载地址:http://download.csdn.net/download/xzpblog/10039362
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "vrview.h"
#include"WinWnd.h"
#include <QVBoxLayout>
#include <QSurfaceFormat>
#include <QSettings>
#include <QFileDialog>
#include <QStandardPaths>
#include <QOffscreenSurface>
#include<QSettings>
#include<QMessageBox>
#include<QDebug>
#include<QWindow>
#include<QDesktopWidget>
MainWindow::MainWindow(QWidget *parent) :QMainWindow(parent),ui(new Ui::MainWindow)
{ui->setupUi(this);this->setWindowFlags(Qt::WindowStaysOnTopHint | Qt::FramelessWindowHint | Qt::ToolTip);m_trayIcon = new QSystemTrayIcon(this);m_trayIcon->setIcon(QIcon(":/viewer.ico"));     //设置图标mMenu = new QMenu(this);exitAction = new QAction(QStringLiteral("Exit"),this);mMenu->addAction(exitAction);m_trayIcon->setContextMenu(mMenu);connect(exitAction,SIGNAL(triggered(bool)),this,SLOT(HandleClose()));m_trayIcon->show();m_trayIcon->showMessage("tip","QVRViewer has started",QSystemTrayIcon::Information,1000);ReadConfig();vr = NULL;tim = new QTimer(this);tim->setInterval(100);connect(tim,SIGNAL(timeout()),this,SLOT(FindWindownHwnd()));initSocket();tim->start();
}MainWindow::~MainWindow()
{if(tim->isActive())tim->stop();if(vr != NULL)delete vr;delete ui;
}void MainWindow::HandleClose()
{QApplication::quit();
}void MainWindow::FindWindownHwnd()
{int hwnd = GetWndFromPid(AppName.toLatin1().data());if(hwnd == 0)return;
//    qDebug()<<"find Window:"<<hwnd;if(vr == NULL){if(abs(QWindow::fromWinId(hwnd)->width() - QApplication::desktop()->width()) < 100){tim->stop();qDebug()<<"start vr"<<hwnd;vr = new VRView(hwnd,this);this->setCentralWidget(vr);}}
}void MainWindow::readPendingDatagrams()
{if (udpSocket->hasPendingDatagrams()) {QByteArray datagram;datagram.resize(udpSocket->pendingDatagramSize());udpSocket->readDatagram(datagram.data(), datagram.size(), NULL,NULL);QString cmd = QString::fromLatin1(datagram);qDebug()<<cmd;if(cmd == "close"){tim->start();}else if(cmd == "start"){if(tim->isActive()) tim->stop();if(vr != NULL){delete vr;vr = NULL;}}else{QMessageBox box;box.setText("命令错误:"+cmd);box.exec();}}}void MainWindow::initSocket()
{udpSocket = new QUdpSocket(this);udpSocket->bind(QHostAddress::Any, Rport);connect(udpSocket, SIGNAL(readyRead()), this, SLOT(readPendingDatagrams()));
}void MainWindow::ReadConfig()
{
//    QSettings settings("C:\\Users\\9DVR\\Desktop\\QVR\\config\\cutApp.ini",QSettings::IniFormat);QSettings settings("./config/cutApp.ini",QSettings::IniFormat);settings.beginGroup("cutApp");AppName = settings.value("appName").toString();Rport = settings.value("port").toInt();settings.endGroup();if(AppName.isEmpty() || Rport == 0){QMessageBox box;box.setText("配置文件格式错误");box.exec();this->close();}}
												

基于openVR实现任意软件界面映射到VR眼镜相关推荐

  1. 基于墨刀的软件界面原型设计——小说搜索阅读软件

    1. 现实需求 在当下,小说越来越受到各个年龄段的人们喜欢,人们也希望有一个方便的软件来搜索和阅读小说.因此便有了该app,它的操作简洁,界面美观,为用户提供了良好的易用性. 2. 设计思路 一个小说 ...

  2. 基于墨刀的软件界面原型设计----视频软件

    一.运行截图 二.设计背景 目前市场上的视频app主流基本上是腾讯.优酷.爱奇艺等大公司所垄断.不同的公司拿到不同的影视版权进行播放.由于本人经常看视频,所以做了一个视频app的原型设计 三.设计思路 ...

  3. 基于Axure的跑步软件的界面原型化系统

    基于Axure的跑步软件的界面原型化系统 基于上一篇博客文章对四款跑步运动软件的调研,我使用Axure RP 8制作了一款跑步APP的界面原型化系统,该原型化系统实现了跑步软件的核心功能,以及其他一些 ...

  4. 3D结构光投影测量软件 / 界面 (基于QT)

    3D结构光投影软件/界面 硬件构成 软件构成 界面 硬件构成 系统是由单目相机+单个投影仪构建 相机:Basler相机(分辨率:832 ×\times× 632,最高采集速度>500fps) 投 ...

  5. Autosar MCAL-ADC详解(二)-基于Tc27x的cfg软件

    文章目录 前言 AdcHwUnit AdcGroup Channel Emux Select Group Access Mode 配置 结果指针初始化 结果访问 读取buffer中的结果 Group ...

  6. 基于构件复用的软件方法与COM支持

    基于构件复用的软件方法与COM支持 张颢    华中理工大学计算机学院 摘要 作为研究的热点,近年来提出构件模型层出不穷.出于相互之间互操作性的考虑,必须具备一个公共的构件 底层框架.分析各种实际的因 ...

  7. 基于Android的聊天软件,Socket即时通信,实现用户在线聊天

    基于Android的聊天软件,Socket即时通信,单聊,聊天室,可自行扩展功能,完善细节. [实例功能] 1.运行程序,登录界面, 注册账号功能 2.进入主界面,有通讯录, 个人信息. 3.点击好友 ...

  8. 一种全新的软件界面设计方法

    一种全新的软件界面设计方法 撰文:Aweay 你可转载,拷贝,但必须加入作者署名Aweay,如果用于商业目的,必须经过作者同意. 下载实例代码 关键字:COM MySpy IE SetUIHanlde ...

  9. 基于.NET的分词软件设计与实现V1.0--总体思路及算法实现

    首先介绍一下这个分词软件的总体思路. 查阅了网上的一些相关资料,普遍采用的都是"正向最大匹配算法"和"逆向最大匹配算法",不了解的朋友先来这里看下两个算法的基本 ...

最新文章

  1. linux ”我的草稿“
  2. linux ubuntu R 无法安装rggobi包的原因及解决方案
  3. 洛谷 - P2761 软件补丁问题(spfa+状压)
  4. 一致性 Hash 算法原理总结
  5. SAP Cloud Platform API management Policy Editor的高级用法
  6. Linux服务部署之NTP时间服务器
  7. P4313 文理分科 网络流
  8. python 消息中间件_消息队列中间件 RabbitMQ 详细介绍——安装与基本应用(Python)...
  9. MicroPython (一)点亮我的Led
  10. eclipse项目中关于导入的项目里提示HttpServletRequest 不能引用的解决办法
  11. js将一维数组分割成每三个一组的算法
  12. 动态设置easyui datagrid URL
  13. U盘无法格式化的解决方法
  14. IDEA项目打包几种方式
  15. 面试篇-Spring 拦截器和过滤器的区别?
  16. ExcelVBA之InputBox方法
  17. python --eel开发桌面程序
  18. qt准确获取本机mac和ip地址
  19. Pandas数据分析案例(盛华化工锅炉排放数据可视化分析)
  20. OSG中使用png图片显示透明效果

热门文章

  1. 设计模式01 UML图,软件设计原则,创建型模式
  2. 【英语学习】【WOTD】writhe 释义/词源/示例
  3. 【数据库】DBMS几种进程模型优劣与举例
  4. linux命令(22):linux文件属性详解
  5. Linux常用的命令
  6. 论文笔记:Large Deformation Diffeomorphic Image Registration with Laplacian Pyramid Networks
  7. 解决在qq群下载东西或者压缩包慢的现象,先转发到另一个qq号,然后再下载
  8. 不思议迷宫c语言基础,不思议迷宫新手谜题汇总
  9. 【美菜网】PostgreSQL与MySQL比较
  10. PDF转TXT如何操作?怎么将PDF转TXT在线转换?