Use arrow keys to pan and z/Z to zoom in/out to explore the fractal.
This commit is contained in:
parent
2ccd264695
commit
0d55346156
|
@ -39,8 +39,8 @@ static struct uniform_info Uniforms[] = {
|
||||||
{ "Shininess", 1, -1, { 20.0, 0, 0, 0 } },
|
{ "Shininess", 1, -1, { 20.0, 0, 0, 0 } },
|
||||||
/* frag */
|
/* frag */
|
||||||
{ "MaxIterations", 1, -1, { 12, 0, 0, 0 } },
|
{ "MaxIterations", 1, -1, { 12, 0, 0, 0 } },
|
||||||
{ "Zoom", 1, -1, { 0.5, 0, 0, 0 } },
|
{ "Zoom", 1, -1, { 0.125, 0, 0, 0 } },
|
||||||
{ "Xcenter", 1, -1, { -1.0, 0, 0, 0 } },
|
{ "Xcenter", 1, -1, { -1.5, 0, 0, 0 } },
|
||||||
{ "Ycenter", 1, -1, { .005, 0, 0, 0 } },
|
{ "Ycenter", 1, -1, { .005, 0, 0, 0 } },
|
||||||
{ "InnerColor", 3, -1, { 1, 0, 0, 0 } },
|
{ "InnerColor", 3, -1, { 1, 0, 0, 0 } },
|
||||||
{ "OuterColor1", 3, -1, { 0, 1, 0, 0 } },
|
{ "OuterColor1", 3, -1, { 0, 1, 0, 0 } },
|
||||||
|
@ -50,10 +50,10 @@ static struct uniform_info Uniforms[] = {
|
||||||
|
|
||||||
static GLint win = 0;
|
static GLint win = 0;
|
||||||
|
|
||||||
|
|
||||||
static GLfloat xRot = 0.0f, yRot = 0.0f, zRot = 0.0f;
|
static GLfloat xRot = 0.0f, yRot = 0.0f, zRot = 0.0f;
|
||||||
|
|
||||||
|
static GLint uZoom, uXcenter, uYcenter;
|
||||||
|
static GLfloat zoom = 1.0, xCenter = -1.5, yCenter = 0.0;
|
||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -61,6 +61,11 @@ Redisplay(void)
|
||||||
{
|
{
|
||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
|
|
||||||
|
/* set interactive uniform parameters */
|
||||||
|
glUniform1fv_func(uZoom, 1, &zoom);
|
||||||
|
glUniform1fv_func(uXcenter, 1, &xCenter);
|
||||||
|
glUniform1fv_func(uYcenter, 1, &yCenter);
|
||||||
|
|
||||||
glPushMatrix();
|
glPushMatrix();
|
||||||
glRotatef(xRot, 1.0f, 0.0f, 0.0f);
|
glRotatef(xRot, 1.0f, 0.0f, 0.0f);
|
||||||
glRotatef(yRot, 0.0f, 1.0f, 0.0f);
|
glRotatef(yRot, 0.0f, 1.0f, 0.0f);
|
||||||
|
@ -75,6 +80,8 @@ Redisplay(void)
|
||||||
|
|
||||||
glPopMatrix();
|
glPopMatrix();
|
||||||
|
|
||||||
|
glFinish();
|
||||||
|
glFlush();
|
||||||
glutSwapBuffers();
|
glutSwapBuffers();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -110,10 +117,10 @@ Key(unsigned char key, int x, int y)
|
||||||
|
|
||||||
switch(key) {
|
switch(key) {
|
||||||
case 'z':
|
case 'z':
|
||||||
zRot -= 1.0;
|
zoom *= 0.9;
|
||||||
break;
|
break;
|
||||||
case 'Z':
|
case 'Z':
|
||||||
zRot += 1.0;
|
zoom /= 0.9;
|
||||||
break;
|
break;
|
||||||
case 27:
|
case 27:
|
||||||
CleanUp();
|
CleanUp();
|
||||||
|
@ -127,23 +134,23 @@ Key(unsigned char key, int x, int y)
|
||||||
static void
|
static void
|
||||||
SpecialKey(int key, int x, int y)
|
SpecialKey(int key, int x, int y)
|
||||||
{
|
{
|
||||||
const GLfloat step = 3.0f;
|
const GLfloat step = 0.1 * zoom;
|
||||||
|
|
||||||
(void) x;
|
(void) x;
|
||||||
(void) y;
|
(void) y;
|
||||||
|
|
||||||
switch(key) {
|
switch(key) {
|
||||||
case GLUT_KEY_UP:
|
case GLUT_KEY_UP:
|
||||||
xRot -= step;
|
yCenter += step;
|
||||||
break;
|
break;
|
||||||
case GLUT_KEY_DOWN:
|
case GLUT_KEY_DOWN:
|
||||||
xRot += step;
|
yCenter -= step;
|
||||||
break;
|
break;
|
||||||
case GLUT_KEY_LEFT:
|
case GLUT_KEY_LEFT:
|
||||||
yRot -= step;
|
xCenter -= step;
|
||||||
break;
|
break;
|
||||||
case GLUT_KEY_RIGHT:
|
case GLUT_KEY_RIGHT:
|
||||||
yRot += step;
|
xCenter += step;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
glutPostRedisplay();
|
glutPostRedisplay();
|
||||||
|
@ -268,6 +275,10 @@ Init(void)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uZoom = glGetUniformLocation_func(program, "Zoom");
|
||||||
|
uXcenter = glGetUniformLocation_func(program, "Xcenter");
|
||||||
|
uYcenter = glGetUniformLocation_func(program, "Ycenter");
|
||||||
|
|
||||||
assert(glGetError() == 0);
|
assert(glGetError() == 0);
|
||||||
|
|
||||||
glClearColor(0.4f, 0.4f, 0.8f, 0.0f);
|
glClearColor(0.4f, 0.4f, 0.8f, 0.0f);
|
||||||
|
|
Loading…
Reference in New Issue