added limits to the zoom scrolling, linked the slides to their features
This commit is contained in:
parent
ee95e2cfb0
commit
e2178df9ea
@ -5,6 +5,8 @@ uniform sampler2DRect colorMap;
|
|||||||
uniform vec3 camera;
|
uniform vec3 camera;
|
||||||
uniform vec2 worldSize;
|
uniform vec2 worldSize;
|
||||||
uniform vec2 screenSize;
|
uniform vec2 screenSize;
|
||||||
|
uniform float flatSphere;
|
||||||
|
uniform float surfaceRatio;
|
||||||
|
|
||||||
in vec2 texCoord;
|
in vec2 texCoord;
|
||||||
in vec3 normal;
|
in vec3 normal;
|
||||||
@ -22,7 +24,7 @@ vec3 phongLighting(in vec3 kd, in vec3 ks, in float ns, in vec3 color, in vec3 n
|
|||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
// looping the world in the shape of a toreiller (infinite flat surface)
|
// looping the world in the shape of a toreiller (infinite flat surface)
|
||||||
vec2 worldCoord = texCoord*worldSize + camera.xy*worldSize.y;
|
vec2 worldCoord = texCoord*worldSize + camera.xy*worldSize.y + (texCoord-vec2(0.25, 0.5))*surfaceRatio*worldSize;
|
||||||
ivec2 nbRevolutions = ivec2(floor(worldCoord / worldSize));
|
ivec2 nbRevolutions = ivec2(floor(worldCoord / worldSize));
|
||||||
if(abs(mod(nbRevolutions.y, 2)) > 0.5)
|
if(abs(mod(nbRevolutions.y, 2)) > 0.5)
|
||||||
{
|
{
|
||||||
@ -34,5 +36,5 @@ void main()
|
|||||||
|
|
||||||
// computing lighting
|
// computing lighting
|
||||||
vec3 lighting = phongLighting(texColor, vec3(0.5), 50, vec3(1), normalize(normal), lightDir, normalize(lightDir+vec3(0, 0, -1)));
|
vec3 lighting = phongLighting(texColor, vec3(0.5), 50, vec3(1), normalize(normal), lightDir, normalize(lightDir+vec3(0, 0, -1)));
|
||||||
outColor = vec4(texColor*0.2 + 0.8*lighting, 1.0);
|
outColor = vec4(mix(lighting, texColor, flatSphere*0.8 + 0.2), 1.0);
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,8 @@ layout(location = 0)in vec3 inPosition;
|
|||||||
layout(location = 2)in vec2 inTexCoord;
|
layout(location = 2)in vec2 inTexCoord;
|
||||||
layout(location = 1)in vec3 inNormal;
|
layout(location = 1)in vec3 inNormal;
|
||||||
|
|
||||||
|
uniform float flatSphere;
|
||||||
|
uniform vec2 screenSize;
|
||||||
uniform mat4 mvp;
|
uniform mat4 mvp;
|
||||||
uniform vec3 camera;
|
uniform vec3 camera;
|
||||||
|
|
||||||
@ -13,6 +15,10 @@ out vec3 normal;
|
|||||||
void main(void)
|
void main(void)
|
||||||
{
|
{
|
||||||
texCoord = vec2(inTexCoord.x/2, inTexCoord.y);
|
texCoord = vec2(inTexCoord.x/2, inTexCoord.y);
|
||||||
|
vec2 flatTexCoord = texCoord;
|
||||||
|
texCoord = mix(texCoord, flatTexCoord, vec2(flatSphere));
|
||||||
normal = inNormal.xyz;
|
normal = inNormal.xyz;
|
||||||
gl_Position = mvp * vec4(inPosition*camera.z, 1.0);
|
vec4 flatPos = vec4(inTexCoord.x*2 -1, inTexCoord.y*2 -1, 0.0, 1.0);
|
||||||
|
vec4 projPos = mvp * vec4(inPosition*camera.z, 1.0);
|
||||||
|
gl_Position = mix(projPos, flatPos, vec4(flatSphere));
|
||||||
}
|
}
|
||||||
|
@ -130,3 +130,16 @@ void DrawWidget::wheelEvent(QWheelEvent *event)
|
|||||||
repaint();
|
repaint();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DrawWidget::setFlatSphere(int value)
|
||||||
|
{
|
||||||
|
if(m_pipeline != NULL)
|
||||||
|
m_pipeline->setFlatSphere(float(value)/100);
|
||||||
|
}
|
||||||
|
|
||||||
|
void DrawWidget::setSurfaceRatio(int value)
|
||||||
|
{
|
||||||
|
float fVal = float(value-50);
|
||||||
|
if(m_pipeline != NULL)
|
||||||
|
m_pipeline->setSurfaceRatio(fVal > 0 ? fVal/25 : fVal/60);
|
||||||
|
}
|
||||||
|
@ -51,6 +51,8 @@ class DrawWidget : public QOpenGLWidget
|
|||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void updateDudesBehavior();
|
void updateDudesBehavior();
|
||||||
|
void setFlatSphere(int);
|
||||||
|
void setSurfaceRatio(int);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // DRAWWIDGET_H
|
#endif // DRAWWIDGET_H
|
||||||
|
@ -21,6 +21,10 @@ MainWindow::MainWindow(QWidget *parent) :
|
|||||||
m_simuTimer->start(m_simSpeed);
|
m_simuTimer->start(m_simSpeed);
|
||||||
connect(ui->startButton, SIGNAL(pressed()), this, SLOT(openSimuDialog()));
|
connect(ui->startButton, SIGNAL(pressed()), this, SLOT(openSimuDialog()));
|
||||||
connect(ui->simSpeedSlider, SIGNAL(valueChanged(int)), this, SLOT(changeSimSpeed(int)));
|
connect(ui->simSpeedSlider, SIGNAL(valueChanged(int)), this, SLOT(changeSimSpeed(int)));
|
||||||
|
connect(ui->flatSphereSlider, SIGNAL(valueChanged(int)), ui->drawWidget, SLOT(setFlatSphere(int)));
|
||||||
|
connect(ui->surfaceRatioSlider, SIGNAL(valueChanged(int)), ui->drawWidget, SLOT(setSurfaceRatio(int)));
|
||||||
|
connect(ui->flatSphereSlider, SIGNAL(valueChanged(int)), ui->drawWidget, SLOT(repaint()));
|
||||||
|
connect(ui->surfaceRatioSlider, SIGNAL(valueChanged(int)), ui->drawWidget, SLOT(repaint()));
|
||||||
connect(ui->pauseButton, SIGNAL(toggled(bool)), this, SLOT(pauseSimu(bool)));
|
connect(ui->pauseButton, SIGNAL(toggled(bool)), this, SLOT(pauseSimu(bool)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -78,7 +78,7 @@
|
|||||||
<item>
|
<item>
|
||||||
<widget class="QToolBox" name="toolBox">
|
<widget class="QToolBox" name="toolBox">
|
||||||
<property name="currentIndex">
|
<property name="currentIndex">
|
||||||
<number>1</number>
|
<number>0</number>
|
||||||
</property>
|
</property>
|
||||||
<widget class="QWidget" name="page_5">
|
<widget class="QWidget" name="page_5">
|
||||||
<property name="geometry">
|
<property name="geometry">
|
||||||
@ -103,11 +103,26 @@
|
|||||||
<item>
|
<item>
|
||||||
<widget class="QSlider" name="flatSphereSlider">
|
<widget class="QSlider" name="flatSphereSlider">
|
||||||
<property name="enabled">
|
<property name="enabled">
|
||||||
<bool>false</bool>
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
<property name="maximum">
|
||||||
|
<number>100</number>
|
||||||
|
</property>
|
||||||
|
<property name="singleStep">
|
||||||
|
<number>2</number>
|
||||||
|
</property>
|
||||||
|
<property name="pageStep">
|
||||||
|
<number>2</number>
|
||||||
</property>
|
</property>
|
||||||
<property name="orientation">
|
<property name="orientation">
|
||||||
<enum>Qt::Horizontal</enum>
|
<enum>Qt::Horizontal</enum>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="tickPosition">
|
||||||
|
<enum>QSlider::TicksBelow</enum>
|
||||||
|
</property>
|
||||||
|
<property name="tickInterval">
|
||||||
|
<number>10</number>
|
||||||
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
@ -120,11 +135,32 @@
|
|||||||
<item>
|
<item>
|
||||||
<widget class="QSlider" name="surfaceRatioSlider">
|
<widget class="QSlider" name="surfaceRatioSlider">
|
||||||
<property name="enabled">
|
<property name="enabled">
|
||||||
<bool>false</bool>
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
<property name="minimum">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<property name="maximum">
|
||||||
|
<number>100</number>
|
||||||
|
</property>
|
||||||
|
<property name="singleStep">
|
||||||
|
<number>10</number>
|
||||||
|
</property>
|
||||||
|
<property name="pageStep">
|
||||||
|
<number>10</number>
|
||||||
|
</property>
|
||||||
|
<property name="value">
|
||||||
|
<number>50</number>
|
||||||
</property>
|
</property>
|
||||||
<property name="orientation">
|
<property name="orientation">
|
||||||
<enum>Qt::Horizontal</enum>
|
<enum>Qt::Horizontal</enum>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="tickPosition">
|
||||||
|
<enum>QSlider::TicksBelow</enum>
|
||||||
|
</property>
|
||||||
|
<property name="tickInterval">
|
||||||
|
<number>10</number>
|
||||||
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
|
@ -36,6 +36,8 @@ PixelPipeline::PixelPipeline(MapScene *map) :
|
|||||||
{
|
{
|
||||||
m_width = 256;
|
m_width = 256;
|
||||||
m_height = 256;
|
m_height = 256;
|
||||||
|
m_surfaceRatio = 1;
|
||||||
|
m_flatSphere = 0;
|
||||||
m_map->setPipeline(this);
|
m_map->setPipeline(this);
|
||||||
m_targetFBO = FrameBuffer::screen;
|
m_targetFBO = FrameBuffer::screen;
|
||||||
m_mapFBO = new FrameBuffer();
|
m_mapFBO = new FrameBuffer();
|
||||||
@ -94,6 +96,8 @@ void PixelPipeline::renderGL(Scene *scene)
|
|||||||
m_renderShader->bindVec3(m_renderShader->getLocation("camera"), m_camera);
|
m_renderShader->bindVec3(m_renderShader->getLocation("camera"), m_camera);
|
||||||
m_renderShader->bindVec2(m_renderShader->getLocation("worldSize"), glm::vec2(m_mapWidth, m_mapHeight));
|
m_renderShader->bindVec2(m_renderShader->getLocation("worldSize"), glm::vec2(m_mapWidth, m_mapHeight));
|
||||||
m_renderShader->bindVec2(m_renderShader->getLocation("screenSize"), glm::vec2(m_width, m_height));
|
m_renderShader->bindVec2(m_renderShader->getLocation("screenSize"), glm::vec2(m_width, m_height));
|
||||||
|
m_renderShader->bindFloat(m_renderShader->getLocation("surfaceRatio"), m_surfaceRatio);
|
||||||
|
m_renderShader->bindFloat(m_renderShader->getLocation("flatSphere"), m_flatSphere);
|
||||||
m_mapTex->bind(0);
|
m_mapTex->bind(0);
|
||||||
m_renderShader->bindInteger(m_renderShader->getLocation("colorMap"), 0);
|
m_renderShader->bindInteger(m_renderShader->getLocation("colorMap"), 0);
|
||||||
|
|
||||||
@ -126,4 +130,8 @@ void PixelPipeline::cameraZoom(int nbScrolls)
|
|||||||
++nbScrolls;
|
++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;
|
||||||
}
|
}
|
||||||
|
@ -24,11 +24,12 @@ private:
|
|||||||
Shader *m_renderShader;
|
Shader *m_renderShader;
|
||||||
int m_width;
|
int m_width;
|
||||||
int m_height;
|
int m_height;
|
||||||
|
float m_surfaceRatio;
|
||||||
|
float m_flatSphere;
|
||||||
glm::vec3 m_camera;
|
glm::vec3 m_camera;
|
||||||
|
|
||||||
Mesh *m_toreiller;
|
Mesh *m_toreiller;
|
||||||
glm::mat4 m_mvp;
|
glm::mat4 m_mvp;
|
||||||
//unsigned int m_vao, m_vbo;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
PixelPipeline(MapScene *map);
|
PixelPipeline(MapScene *map);
|
||||||
@ -42,6 +43,9 @@ public:
|
|||||||
|
|
||||||
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) { m_camera.x -= x/(m_camera.z*m_width); m_camera.y += y/(m_camera.z*m_width); }
|
||||||
void cameraZoom(int nbScrolls);
|
void cameraZoom(int nbScrolls);
|
||||||
|
|
||||||
|
void setSurfaceRatio(float surfaceRatio) { m_surfaceRatio = surfaceRatio; }
|
||||||
|
void setFlatSphere(float flatSphere) { m_flatSphere = flatSphere; }
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // PIXELPIPELINE_H
|
#endif // PIXELPIPELINE_H
|
||||||
|
Loading…
x
Reference in New Issue
Block a user