Implement the arrow keys controlling the scaling
This commit is contained in:
parent
f6e0d12287
commit
d1eab0d16f
1 changed files with 29 additions and 5 deletions
|
@ -59,6 +59,10 @@ GLint window_width = 500;
|
|||
GLint window_height = 500;
|
||||
GLdouble pi = 4.0 * atan(1.0);
|
||||
|
||||
// Added state
|
||||
GLdouble scale_x = 1.0, scale_y = 1.0;
|
||||
const GLdouble SCALE_DELTA = 0.05;
|
||||
|
||||
GLFWcursor *hand_cursor, *arrow_cursor; // some different cursors
|
||||
|
||||
GLint NVERTICES = 9; // part of the hard-coded model
|
||||
|
@ -74,9 +78,25 @@ static void error_callback(int error, const char *description) {
|
|||
// keyboard input will be handled
|
||||
static void key_callback(GLFWwindow *window, int key, int scancode, int action,
|
||||
int mods) {
|
||||
if (key == GLFW_KEY_ESCAPE &&
|
||||
action == GLFW_PRESS) // checks to see if the escape key was pressed
|
||||
glfwSetWindowShouldClose(window, GL_TRUE); // closes the window
|
||||
// checks to see if the escape key was pressed
|
||||
if ((key == GLFW_KEY_ESCAPE || key == GLFW_KEY_Q) && action == GLFW_PRESS)
|
||||
// closes the window
|
||||
glfwSetWindowShouldClose(window, GL_TRUE);
|
||||
|
||||
// arrow keys control the scaling of the object
|
||||
if (action == GLFW_PRESS || action == GLFW_REPEAT) {
|
||||
if (key == GLFW_KEY_LEFT || key == GLFW_KEY_A)
|
||||
scale_x -= SCALE_DELTA;
|
||||
|
||||
else if (key == GLFW_KEY_RIGHT || key == GLFW_KEY_D)
|
||||
scale_x += SCALE_DELTA;
|
||||
|
||||
else if (key == GLFW_KEY_UP || key == GLFW_KEY_W)
|
||||
scale_y += SCALE_DELTA;
|
||||
|
||||
else if (key == GLFW_KEY_DOWN || key == GLFW_KEY_S)
|
||||
scale_y -= SCALE_DELTA;
|
||||
}
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
|
@ -240,9 +260,13 @@ int main(int argc, char **argv) {
|
|||
// define/re-define the modelview matrix. In this template, we define M to
|
||||
// be the identity matrix; you will need define M according to the user's
|
||||
// actions.
|
||||
for (i = 0; i < 16; i++) {
|
||||
/* for (i = 0; i < 16; i++) {
|
||||
M[i] = (i % 5 == 0);
|
||||
}
|
||||
}*/
|
||||
M[0] = scale_x;
|
||||
M[5] = scale_y;
|
||||
M[10] = 1.0;
|
||||
M[15] = 1.0;
|
||||
|
||||
// sanity check that your matrix contents are what you expect them to be
|
||||
if (DEBUG_ON)
|
||||
|
|
Loading…
Reference in a new issue