代码拉取完成,页面将自动刷新
#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();
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。