|
|
@ -37,7 +37,7 @@ void GLWidget::initializeGL() { |
|
|
|
glEnable(GL_PRIMITIVE_RESTART_FIXED_INDEX); |
|
|
|
glEnable(GL_PRIMITIVE_RESTART_FIXED_INDEX); |
|
|
|
glEnable(GL_DEPTH_TEST); |
|
|
|
glEnable(GL_DEPTH_TEST); |
|
|
|
glDepthFunc(GL_LESS); |
|
|
|
glDepthFunc(GL_LESS); |
|
|
|
glDepthMask(GL_TRUE); |
|
|
|
glClearDepth(1); |
|
|
|
glClearColor(.15, .15, .15, 1); |
|
|
|
glClearColor(.15, .15, .15, 1); |
|
|
|
|
|
|
|
|
|
|
|
std::vector<Pendulum*> empty; |
|
|
|
std::vector<Pendulum*> empty; |
|
|
@ -45,12 +45,12 @@ void GLWidget::initializeGL() { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void GLWidget::paintGL() { |
|
|
|
void GLWidget::paintGL() { |
|
|
|
auto p = new QPainter(this); |
|
|
|
QPixmap img(size()); |
|
|
|
p->setRenderHint(QPainter::Antialiasing); |
|
|
|
auto p = new QPainter(&img); |
|
|
|
p->beginNativePainting(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Native OpenGL
|
|
|
|
// Native OpenGL
|
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
|
|
|
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); |
|
|
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); |
|
|
|
|
|
|
|
|
|
|
|
program->bind(); |
|
|
|
program->bind(); |
|
|
@ -75,7 +75,6 @@ void GLWidget::paintGL() { |
|
|
|
|
|
|
|
|
|
|
|
glBindVertexArray(0); |
|
|
|
glBindVertexArray(0); |
|
|
|
} |
|
|
|
} |
|
|
|
p->endNativePainting(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// FPS
|
|
|
|
// FPS
|
|
|
|
{ |
|
|
|
{ |
|
|
@ -105,7 +104,7 @@ bool GLWidget::AnyDialogOpen() { |
|
|
|
|
|
|
|
|
|
|
|
void GLWidget::initGPUMemory(const std::vector<Pendulum *> *pendula) { |
|
|
|
void GLWidget::initGPUMemory(const std::vector<Pendulum *> *pendula) { |
|
|
|
|
|
|
|
|
|
|
|
int segmentCount = std::transform_reduce(pendula->begin(), pendula->end(), 0, [](int prev, int curr){ |
|
|
|
int pointCount = std::transform_reduce(pendula->begin(), pendula->end(), 0, [](int prev, int curr){ |
|
|
|
return prev + curr + 1; |
|
|
|
return prev + curr + 1; |
|
|
|
}, [](const Pendulum * p){ |
|
|
|
}, [](const Pendulum * p){ |
|
|
|
return p->X.size(); |
|
|
|
return p->X.size(); |
|
|
@ -118,8 +117,9 @@ void GLWidget::initGPUMemory(const std::vector<Pendulum *> *pendula) { |
|
|
|
|
|
|
|
|
|
|
|
if (!pendula->empty()){ |
|
|
|
if (!pendula->empty()){ |
|
|
|
|
|
|
|
|
|
|
|
float depth = 1.f - 1.f / float(segmentCount); |
|
|
|
float margin = 0.1f; |
|
|
|
depthOffset = 1.f * 2 / float(segmentCount); |
|
|
|
depthOffset = 2 * (1.f - margin) / float(pointCount); |
|
|
|
|
|
|
|
float depth = (1.f - margin) - (1.f - margin) / float(pointCount) + depthOffset; |
|
|
|
|
|
|
|
|
|
|
|
GLuint index = 0; |
|
|
|
GLuint index = 0; |
|
|
|
for (const auto p : *pendula){ |
|
|
|
for (const auto p : *pendula){ |
|
|
@ -127,8 +127,7 @@ void GLWidget::initGPUMemory(const std::vector<Pendulum *> *pendula) { |
|
|
|
// Origin point
|
|
|
|
// Origin point
|
|
|
|
positions.push_back(0); |
|
|
|
positions.push_back(0); |
|
|
|
positions.push_back(0); |
|
|
|
positions.push_back(0); |
|
|
|
positions.push_back(depth); |
|
|
|
positions.push_back(depth -= depthOffset); |
|
|
|
depth -= depthOffset; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
colors.resize(colors.size() + 3); |
|
|
|
colors.resize(colors.size() + 3); |
|
|
|
float * red = &colors.back() - 2; |
|
|
|
float * red = &colors.back() - 2; |
|
|
@ -143,8 +142,7 @@ void GLWidget::initGPUMemory(const std::vector<Pendulum *> *pendula) { |
|
|
|
Vector pos = p->X[segment]; |
|
|
|
Vector pos = p->X[segment]; |
|
|
|
positions.push_back(float(pos.x)); |
|
|
|
positions.push_back(float(pos.x)); |
|
|
|
positions.push_back(float(pos.y)); |
|
|
|
positions.push_back(float(pos.y)); |
|
|
|
positions.push_back(depth); |
|
|
|
positions.push_back(depth -= depthOffset); |
|
|
|
depth -= depthOffset; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
colors.resize(colors.size() + 3); |
|
|
|
colors.resize(colors.size() + 3); |
|
|
|
red = &colors.back() - 2; |
|
|
|
red = &colors.back() - 2; |
|
|
|