From 6aa2c5686f56cc89b5de9c5f156737939709068c Mon Sep 17 00:00:00 2001 From: Anselme Date: Fri, 3 Jun 2016 11:27:21 +0200 Subject: [PATCH] fixed flat / sphere scaling and mouse move input scaling --- shaders/world.frag.glsl | 1 + shaders/world.vert.glsl | 2 +- src/mainwindow.cpp | 7 +++++++ src/mainwindow.h | 1 + src/mainwindow.ui | 19 +++++++++++++------ src/pixelpipeline.cpp | 16 +++++++++++++--- src/pixelpipeline.h | 5 ++++- 7 files changed, 40 insertions(+), 11 deletions(-) diff --git a/shaders/world.frag.glsl b/shaders/world.frag.glsl index d41e1d8..a99feda 100644 --- a/shaders/world.frag.glsl +++ b/shaders/world.frag.glsl @@ -24,6 +24,7 @@ vec3 phongLighting(in vec3 kd, in vec3 ks, in float ns, in vec3 color, in vec3 n void main() { // looping the world in the shape of a toreiller (infinite flat surface) + //float zoomRatio = mix(1, 1/camera.z, flatSphere); vec2 worldCoord = texCoord*worldSize + camera.xy*worldSize.y + (texCoord-vec2(0.25, 0.5))*surfaceRatio*worldSize; ivec2 nbRevolutions = ivec2(floor(worldCoord / worldSize)); if(abs(mod(nbRevolutions.y, 2)) > 0.5) diff --git a/shaders/world.vert.glsl b/shaders/world.vert.glsl index db0eaec..9665a8d 100644 --- a/shaders/world.vert.glsl +++ b/shaders/world.vert.glsl @@ -18,7 +18,7 @@ void main(void) vec2 flatTexCoord = texCoord; texCoord = mix(texCoord, flatTexCoord, vec2(flatSphere)); normal = inNormal.xyz; - vec4 flatPos = vec4(inTexCoord.x*2 -1, inTexCoord.y*2 -1, 0.0, 1.0); + vec4 flatPos = vec4((inTexCoord.x*2 -1)*camera.z, (inTexCoord.y*2 -1)*camera.z, 0.0, 1.0); vec3 position = vec3(inPosition.xy, inPosition.z - 1); vec4 projPos = mvp * vec4(position*camera.z, 1.0); gl_Position = mix(projPos, flatPos, vec4(flatSphere)); diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 4f2782f..6ed36f1 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -30,6 +30,7 @@ MainWindow::MainWindow(QWidget *parent) : connect(ui->actionPlayPause, SIGNAL(toggled(bool)), this, SLOT(pauseSimu(bool))); connect(ui->actionAction_step, SIGNAL(triggered(bool)), this, SLOT(stepSimu())); connect(ui->actionStop, SIGNAL(triggered(bool)), this, SLOT(stopSimu())); + connect(ui->resetToDefaultAdvanced, SIGNAL(pressed()), this, SLOT(resetAdvancedToDefault())); changeSimSpeed(ui->simSpeedSlider->value()); ui->advancedGroupBox->hide(); } @@ -100,6 +101,12 @@ void MainWindow::stopSimu() delete p_simu; } +void MainWindow::resetAdvancedToDefault() +{ + ui->flatSphereSlider->setValue(0); + ui->surfaceRatioSlider->setValue(50); +} + void MainWindow::pauseSimu(bool pause) { m_paused = pause; diff --git a/src/mainwindow.h b/src/mainwindow.h index faeccd8..5a94c57 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -32,6 +32,7 @@ private slots: void updateSimu(); void stepSimu(); void stopSimu(); + void resetAdvancedToDefault(); void pauseSimu(bool); }; diff --git a/src/mainwindow.ui b/src/mainwindow.ui index 08b94e0..9ec00bf 100644 --- a/src/mainwindow.ui +++ b/src/mainwindow.ui @@ -6,8 +6,8 @@ 0 0 - 744 - 490 + 683 + 499 @@ -190,14 +190,14 @@ 5 - + Spherical / Flat - + true @@ -225,14 +225,14 @@ - + surface ratio - + true @@ -263,6 +263,13 @@ + + + + Reset to default + + + diff --git a/src/pixelpipeline.cpp b/src/pixelpipeline.cpp index 3cc34c6..87f4b40 100644 --- a/src/pixelpipeline.cpp +++ b/src/pixelpipeline.cpp @@ -8,7 +8,6 @@ #include "mapscene.h" #include #include - #define SCROLL_SPEED 0.998f class ToreillerGenerator : public MeshGenerator @@ -150,6 +149,12 @@ void PixelPipeline::resizeGL(int w, int h) m_view = glm::translate(glm::mat4(), glm::vec3(0, 0, -3)); } +void PixelPipeline::cameraMove(int x, int y) +{ + m_camera.x -= 2*x/(m_camera.z*m_width); + m_camera.y += 2*y/(m_camera.z*m_height); +} + void PixelPipeline::cameraZoom(int nbScrolls) { while(nbScrolls != 0) @@ -167,6 +172,11 @@ void PixelPipeline::cameraZoom(int nbScrolls) } if(m_camera.z > m_mapHeight/4) m_camera.z = m_mapHeight/4; - else if(m_camera.z < 0.4f) - m_camera.z = 0.4f; + else if(m_camera.z < 1) + m_camera.z = 1; +} + +Coord PixelPipeline::getToreillerPos(int mouseX, int mouseY) +{ + } diff --git a/src/pixelpipeline.h b/src/pixelpipeline.h index 36bff88..99fb009 100644 --- a/src/pixelpipeline.h +++ b/src/pixelpipeline.h @@ -10,6 +10,7 @@ class Shader; class PixelMesh; class MapScene; class Mesh; +class Coord; class PixelPipeline : public Pipeline { @@ -46,12 +47,14 @@ public: virtual void renderGL(Scene *scene); virtual void resizeGL(int w, int h); - void cameraMove(int x, int y) { m_camera.x -= x/(m_camera.z*m_width); m_camera.y += y/(m_camera.z*m_width); } + void cameraMove(int x, int y); void cameraZoom(int nbScrolls); void setSurfaceRatio(float surfaceRatio) { m_surfaceRatio = surfaceRatio; } void setFlatSphere(float flatSphere) { m_flatSphere = flatSphere; } void setShowToreiller(bool showToreiller) { m_showToreiller = showToreiller; } + + Coord getToreillerPos(int mouseX, int mouseY); }; #endif // PIXELPIPELINE_H