fixed flat / sphere scaling and mouse move input scaling

This commit is contained in:
Anselme 2016-06-03 11:27:21 +02:00
parent fc113617c9
commit 6aa2c5686f
7 changed files with 40 additions and 11 deletions

View File

@ -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)

View File

@ -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));

View File

@ -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;

View File

@ -32,6 +32,7 @@ private slots:
void updateSimu();
void stepSimu();
void stopSimu();
void resetAdvancedToDefault();
void pauseSimu(bool);
};

View File

@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>744</width>
<height>490</height>
<width>683</width>
<height>499</height>
</rect>
</property>
<property name="windowTitle">
@ -190,14 +190,14 @@
<property name="bottomMargin">
<number>5</number>
</property>
<item row="0" column="0">
<item row="1" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Spherical / Flat</string>
</property>
</widget>
</item>
<item row="0" column="1">
<item row="1" column="1">
<widget class="QSlider" name="flatSphereSlider">
<property name="enabled">
<bool>true</bool>
@ -225,14 +225,14 @@
</property>
</widget>
</item>
<item row="1" column="0">
<item row="2" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>surface ratio</string>
</property>
</widget>
</item>
<item row="1" column="1">
<item row="2" column="1">
<widget class="QSlider" name="surfaceRatioSlider">
<property name="enabled">
<bool>true</bool>
@ -263,6 +263,13 @@
</property>
</widget>
</item>
<item row="0" column="0" colspan="2">
<widget class="QPushButton" name="resetToDefaultAdvanced">
<property name="text">
<string>Reset to default</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>

View File

@ -8,7 +8,6 @@
#include "mapscene.h"
#include <parametricmesh.h>
#include <glm/ext.hpp>
#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)
{
}

View File

@ -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