#include "ModelShowWidget.h"
#include "vertices.h"
#include <QTouchEvent>
const unsigned int timeOutmSec=50;
QVector3D viewInitPos(0.0f,5.0f,20.0f);
float _near=0.1f,_far=100.0f;
QMatrix4x4 model;
QMatrix4x4 view;
QMatrix4x4 projection;
QPoint lastPos;
Model *_model = nullptr;
ModelShowWidget::ModelShowWidget(QWidget *parent)
: QOpenGLWidget(parent)
{
QSurfaceFormat format;
format.setDepthBufferSize(24);
QSurfaceFormat::setDefaultFormat(format);
connect(&m_timer,SIGNAL(timeout()),this,SLOT(on_timeout()));
m_timer.start(timeOutmSec);
m_time.start();
m_camera.Position=viewInitPos;
setFocusPolicy(Qt::StrongFocus);
setMouseTracking(true);
//this->setAttribute(Qt::WA_AcceptTouchEvents);
}
ModelShowWidget::~ModelShowWidget()
{
for(auto iter = m_Models.begin();iter!=m_Models.end();iter++){
ModelInfo *modelInfo=&iter.value();
delete modelInfo->model;
}
}
void ModelShowWidget::loadModel(string path)
{
static int i=0;
makeCurrent();
m_Models.clear();
if (_model)
{
delete _model;
_model = nullptr;
}
_model = new Model(this, path.c_str());
//m_camera.Position=cameraPosInit(_model->m_maxY,_model->m_minY);
m_Models["Julian" + QString::number(i++)] =
ModelInfo{ _model,QVector3D(0, 0/*- _model->m_minY*/,0)
,0.0,0.0,0.0,false,QString::fromLocal8Bit("model") + QString::number(i++) };
doneCurrent();
}
void ModelShowWidget::setBrigh(const QString id)
{
foreach(auto modelInfo, m_Models) {
Model *model = modelInfo.model;
if (model->getId(id) >= 0)
m_curLightMesh = model->getId(id);
}
}
void ModelShowWidget::initializeGL()
{
initializeOpenGLFunctions();
//创建VBO和VAO对象,并赋予ID
bool success;
m_ShaderProgram.addShaderFromSourceFile(QOpenGLShader::Vertex,":/shaders/shaders/shapes.vert");
m_ShaderProgram.addShaderFromSourceFile(QOpenGLShader::Fragment,":/shaders/shaders/shapes.frag");
success=m_ShaderProgram.link();
if(!success) qDebug()<<"ERR:"<<m_ShaderProgram.log();
m_SingleColorShaderProgram.addShaderFromSourceFile(QOpenGLShader::Vertex, ":/shaders/shaders/shapes.vert");
m_SingleColorShaderProgram.addShaderFromSourceFile(QOpenGLShader::Fragment, ":/shaders/shaders/singleColor.frag");
success = m_SingleColorShaderProgram.link();
if (!success) qDebug() << "ERR:" << m_SingleColorShaderProgram.log();
// m_BoxDiffuseTex=new
// QOpenGLTexture(QImage(":/images/images/container2.png").mirrored());
m_PlaneDiffuseTex=new
QOpenGLTexture(QImage(":/images/images/wall.jpg").mirrored());
m_PlaneMesh=processMesh(planeVertices,6,m_PlaneDiffuseTex->textureId());
}
void ModelShowWidget::resizeGL(int w, int h)
{
Q_UNUSED(w);
Q_UNUSED(h);
}
void ModelShowWidget::paintGL()
{
model.setToIdentity();
view.setToIdentity();
projection.setToIdentity();
// float time=m_time.elapsed()/50.0;
projection.perspective(m_camera.Zoom,(float)width()/height(),_near,_far);
view=m_camera.GetViewMatrix();
glClearColor(0.1f, 0.1f, 0.1f, 0.5f);
glEnable(GL_DEPTH_TEST);
glEnable(GL_STENCIL_TEST); //开启模板测试
glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);//设置如何更新缓冲
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);//清除模板缓冲
glStencilMask(0x00);//禁止写入
m_ShaderProgram.bind();
m_ShaderProgram.setUniformValue("projection", projection);
m_ShaderProgram.setUniformValue("view", view);
//model.rotate(time, 1.0f, 1.0f, 0.5f);
m_ShaderProgram.setUniformValue("viewPos",m_camera.Position);
// light properties, note that all light colors are set at full intensity
m_ShaderProgram.setUniformValue("light.ambient", 0.7f, 0.7f, 0.7f);
m_ShaderProgram.setUniformValue("light.diffuse", 0.9f, 0.9f, 0.9f);
m_ShaderProgram.setUniformValue("light.specular", 1.0f, 1.0f, 1.0f);
// material properties
m_ShaderProgram.setUniformValue("material.shininess", 32.0f);
m_ShaderProgram.setUniformValue("light.direction", -0.2f, -1.0f, -0.3f);
m_ShaderProgram.setUniformValue("model", model);
m_PlaneMesh->Draw(m_ShaderProgram);
m_SingleColorShaderProgram.bind();
m_SingleColorShaderProgram.setUniformValue("projection", projection);
m_SingleColorShaderProgram.setUniformValue("view", view);
m_SingleColorShaderProgram.release();
foreach(auto modelInfo,m_Models){
model.setToIdentity();
model.translate(modelInfo.worldPos);
model.rotate(modelInfo.pitch,QVector3D(1.0,0.0,0.0));
model.rotate(modelInfo.yaw,QVector3D(0.0,1.0,0.0));
model.rotate(modelInfo.roll,QVector3D(0.0,0.0,1.0));
//第一次绘制,写入模板缓冲区,当物体的片段被渲染时,将模板缓冲更新为1
glStencilFunc(GL_ALWAYS, 1, 0xFF);
glStencilMask(0xFF);
m_ShaderProgram.bind();
m_ShaderProgram.setUniformValue("model", model);
modelInfo.model->Draw(m_ShaderProgram);//渲染物体
m_ShaderProgram.release();
if (m_curLightMesh < 0)
continue;
//第二次绘制的时候,只须绘制不等于1的部分,等于1的部分就不需要绘制,禁用模板写入
glStencilFunc(GL_NOTEQUAL, 1, 0xFF);
glStencilMask(0x00);
float height = modelInfo.model->m_maxY - modelInfo.model->m_minY;
float width = modelInfo.model->m_maxX - modelInfo.model->m_minX;
if (modelInfo.model->m_minY >= 0)
model.translate(0.0f, height / 2, 0.0f);
model.scale(1.1f, 1.0 + 0.05*(width / height));//将物体放大一点点
if (modelInfo.model->m_minY >= 0)
model.translate(0.0f, -height / 2, 0.0f);
m_SingleColorShaderProgram.bind();//使用一个不同的片段着色器,输出一个单独的(边框)颜色。
m_SingleColorShaderProgram.setUniformValue("model", model);
modelInfo.model->Draw(m_SingleColorShaderProgram, m_curLightMesh);//再次绘制物体,但只在它们片段的模板值不等于1时才绘制
//m_SingleColorShaderProgram.release();
//再次启用模板写入和深度测试
glStencilMask(0xFF);
glStencilFunc(GL_ALWAYS, 1, 0xFF);
}
}
void ModelShowWidget::wheelEvent(QWheelEvent *event)
{
m_camera.ProcessMouseScroll(event->angleDelta().y()/120);
}
void ModelShowWidget::keyPressEvent(QKeyEvent *event)
{
float deltaTime=timeOutmSec/1000.0f;
switch (event->key()) {
case Qt::Key_W: m_camera.ProcessKeyboard(FORWARD,deltaTime);break;
case Qt::Key_S: m_camera.ProcessKeyboard(BACKWARD,deltaTime);break;
case Qt::Key_D: m_camera.ProcessKeyboard(RIGHT,deltaTime);break;
case Qt::Key_A: m_camera.ProcessKeyboard(LEFT,deltaTime);break;
case Qt::Key_Q: m_camera.ProcessKeyboard(DOWN,deltaTime);break;
case Qt::Key_E: m_camera.ProcessKeyboard(UP,deltaTime);break;
case Qt::Key_Space: m_camera.Position=viewInitPos;break;
default:break;
}
}
void ModelShowWidget::mouseMoveEvent(QMouseEvent *event)
{
makeCurrent();
if(m_modelMoving){
for(auto iter=m_Models.begin();iter!=m_Models.end();iter++){
ModelInfo *modelInfo=&iter.value();
if(!modelInfo->isSelected)
continue;
// modelInfo->worldPos=
// QVector3D(worldPosFromViewPort(event->pos().x(),event->pos().y()));
}
}else
if (event->buttons() & Qt::RightButton
|| event->buttons() & Qt::LeftButton
|| event->buttons() & Qt::MiddleButton)
{
auto currentPos=event->pos();
QPoint deltaPos=currentPos-lastPos;
lastPos=currentPos;
if(event->buttons() & Qt::RightButton)
m_camera.ProcessMouseMovement(deltaPos.x(),-deltaPos.y());
else
for(auto iter=m_Models.begin();iter!=m_Models.end();iter++){
ModelInfo
没有合适的资源?快使用搜索试试~ 我知道了~
Qt+openglEs2加载3D模型,平移、旋转、拾取模型
共118个文件
h:76个
hpp:9个
inl:8个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
5星 · 超过95%的资源 1 下载量 64 浏览量
2024-01-16
20:08:55
上传
评论 1
收藏 9.95MB ZIP 举报
温馨提示
Qt+openglEs2加载3D模型Qt+openglEs2加载3D模型Qt+openglEs2加载3D模型Qt+openglEs2加载3D模型Qt+openglEs2加载3D模型Qt+openglEs2加载3D模型Qt+openglEs2加载3D模型Qt+openglEs2加载3D模型Qt+openglEs2加载3D模型Qt+openglEs2加载3D模型Qt+openglEs2加载3D模型Qt+openglEs2加载3D模型Qt+openglEs2加载3D模型Qt+openglEs2加载3D模型Qt+openglEs2加载3D模型Qt+openglEs2加载3D模型Qt+openglEs2加载3D模型Qt+openglEs2加载3D模型Qt+openglEs2加载3D模型Qt+openglEs2加载3D模型Qt+openglEs2加载3D模型Qt+openglEs2加载3D模型Qt+openglEs2加载3D模型Qt+openglEs2加载3D模型Qt+openglEs2加载3D模型Qt+openglEs2加载3D模型Qt+openglEs2加载3D模型Qt+openglEs2加载
资源推荐
资源详情
资源评论
收起资源包目录
Qt+openglEs2加载3D模型,平移、旋转、拾取模型 (118个子文件)
ModelShowWidget.cpp 14KB
model.cpp 6KB
mesh.cpp 2KB
mainwindow.cpp 546B
main.cpp 183B
assimp-vc141-mtd.dll 24.12MB
assimp-vc141-mt.dll 5.54MB
.editorconfig 175B
shapes.frag 1KB
singleColor.frag 135B
202312348163455_657abe2f67f122d1f8223a82_j15.glb 1.82MB
material.h 59KB
cimport.h 48KB
config.h 47KB
postprocess.h 33KB
mesh.h 32KB
pstdint.h 30KB
anim.h 17KB
BaseImporter.h 16KB
metadata.h 16KB
types.h 16KB
scene.h 15KB
XmlParser.h 15KB
SceneCombiner.h 14KB
cexport.h 13KB
StreamReader.h 12KB
fast_atof.h 12KB
matrix4x4.h 11KB
Vertex.h 11KB
defs.h 11KB
StringUtils.h 10KB
StreamWriter.h 10KB
BlobIOSystem.h 10KB
ParsingUtils.h 9KB
IOStreamBuffer.h 9KB
light.h 9KB
ByteSwapper.h 9KB
SpatialSort.h 9KB
LineSplitter.h 8KB
MemoryIOWrapper.h 8KB
camera.h 8KB
texture.h 8KB
Exceptional.h 7KB
StringComparison.h 7KB
StandardShapes.h 7KB
matrix3x3.h 6KB
importerdesc.h 6KB
SGSpatialSort.h 6KB
qnan.h 5KB
TinyFormatter.h 5KB
pbrmaterial.h 5KB
vector3.h 5KB
SmallVector.h 5KB
Subdivision.h 5KB
DefaultIOStream.h 5KB
version.h 5KB
cfileio.h 5KB
camera.h 4KB
quaternion.h 4KB
GenericProperty.h 4KB
SkeletonMeshBuilder.h 4KB
Bitmap.h 4KB
Hash.h 4KB
LogAux.h 4KB
SmoothingGroups.h 4KB
DefaultIOSystem.h 4KB
RemoveComments.h 3KB
color4.h 3KB
BundledAssetIOSystem.h 3KB
ZipArchiveIOSystem.h 3KB
vector2.h 3KB
AndroidJNIIOSystem.h 3KB
Profiler.h 3KB
MathFunctions.h 3KB
XMLTools.h 3KB
CreateAnimMesh.h 3KB
commonMetaData.h 3KB
ai_assert.h 3KB
aabb.h 3KB
ColladaMetaData.h 2KB
ModelShowWidget.h 2KB
model.h 1KB
pushpack1.h 1KB
mesh.h 852B
poppack1.h 793B
vertices.h 511B
mainwindow.h 370B
Importer.hpp 31KB
Exporter.hpp 22KB
IOSystem.hpp 12KB
Logger.hpp 11KB
DefaultLogger.hpp 8KB
ProgressHandler.hpp 6KB
IOStream.hpp 5KB
LogStream.hpp 4KB
NullLogger.hpp 3KB
config.h.in 46KB
matrix4x4.inl 24KB
material.inl 13KB
matrix3x3.inl 13KB
共 118 条
- 1
- 2
资源评论
- 唯我动力2024-04-02资源是宝藏资源,实用也是真的实用,感谢大佬分享~
Mr.codeee
- 粉丝: 3w+
- 资源: 59
下载权益
C知道特权
VIP文章
课程特权
开通VIP
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- JSP-JTBC-CMS(SQLITE).rar
- MC3362和MC145151调频无线接收器的设计.pdf
- MiniRenamer-v100.0一款简单易用的批量文件重命名工具(已注册PRO版本).rar
- 小狐狸Ai系统 小狐狸ai付费创作系统V2.8.0 ChatGPT智能机器人
- 公孙离-内衣-肚兜.zipgsl
- 快慢指针判断链表是否有环-go 语言实现
- 学生成绩管理系统的设计与实现-收藏备用.pdf
- JSP+SQL网站流量统计管理系统(源代码+论文).rar
- IBM-PC-XT微机过程...道中模拟量数据的采集和处理.pdf
- JSP+SQL网上选课系统(源代码+论文+答辩PPT).rar
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功