2 Star 0 Fork 1

LeoPkuCs/PhysLeo

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
GLwindow.cpp 1.87 KB
一键复制 编辑 原始数据 按行查看 历史
#include "Utilities/gl_utilities.h"
#include <QtOpenGL>
#include <iostream>
#include "GLwindow.h"
using namespace Physika;
void GLwindow::initializeGL()
{
if (glewInit() != GLEW_OK)
{
std::cout << "error: can't init glew!\n";
std::exit(EXIT_FAILURE);
}
else {
std::cout << "glew init successful" << std::endl;
}
glVerify(glClearColor(0.0, 0.2, 0.3, 1.0));
glVerify(glShadeModel(GL_SMOOTH));
glVerify(glEnable(GL_DEPTH_TEST));
std::cout << "hahahaha" << std::endl;
Driver::initGLResource();
}
void GLwindow::paintGL()
{
glClearColor(0.2f, 0.3f, 0.3f, 10.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
Driver::draw(dynamic_cast<CameraInterface&>(camera));
}
void GLwindow::resizeGL(int w, int h)
{
glViewport(0, 0, w, h);
camera.setAspect(float(w) / h);
}
void GLwindow::mousePressEvent(QMouseEvent * event)
{
lastPos = event->pos();
}
void GLwindow::mouseMoveEvent(QMouseEvent * event)
{
QPoint pos = event->pos();
QPoint deltaPos = pos - lastPos;
lastPos = pos;
float scale = 0.02f; //sensitivity of the mouse
float camera_radius = glm::length(camera.getFocusPosition() - camera.getPosition());
if (event->buttons() & Qt::LeftButton) {
camera.orbitLeft(deltaPos.x() *scale);
camera.orbitUp(deltaPos.y()*scale);
}
if (event->buttons() & Qt::MiddleButton) {
camera.zoomIn(camera_radius*deltaPos.y()*scale);
}
if (event->buttons() & Qt::RightButton) {
scale *= 0.1f;
camera.translateLeft(camera_radius*deltaPos.x()*scale);
camera.translateUp(camera_radius*deltaPos.y()*scale);
}
}
void GLwindow::wheelEvent(QWheelEvent * event)
{
float scale = 0.02f; //sensitivity of the mouse
float camera_radius = glm::length(camera.getFocusPosition() - camera.getPosition());
QPoint scroll = event->angleDelta();
if (scroll.y() > 0)camera.zoomOut(camera_radius*scale);
else if (scroll.y() < 0)camera.zoomIn(camera_radius*scale);
lastPos = event->pos();
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/LeoPkuCs/PhysLeo.git
git@gitee.com:LeoPkuCs/PhysLeo.git
LeoPkuCs
PhysLeo
PhysLeo
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385