void Update(float secondsElapsed, GLFWwindow* window) { const GLfloat degreesPerSecond = 180.0f; //const GLfloat degreesPerSecond = 0.0f; gDegreesRotated += secondsElapsed * degreesPerSecond; while (gDegreesRotated > 360.0f) gDegreesRotated -= 360.0f; gInstances.front().transform = glm::rotate(glm::mat4(), gDegreesRotated, glm::vec3(0, 1, 0)); //move position of camera based on WASD keys const float moveSpeed = 4.0; //units per second if (glfwGetKey(window, 'S')) { gCamera.offsetPosition(secondsElapsed * moveSpeed * -gCamera.forward()); } else if (glfwGetKey(window, 'W')) { gCamera.offsetPosition(secondsElapsed * moveSpeed * gCamera.forward()); } if (glfwGetKey(window, 'A')) { gCamera.offsetPosition(secondsElapsed * moveSpeed * -gCamera.right()); } else if (glfwGetKey(window, 'D')) { gCamera.offsetPosition(secondsElapsed * moveSpeed * gCamera.right()); } if (glfwGetKey(window, 'Z')) { gCamera.offsetPosition(secondsElapsed * moveSpeed * -glm::vec3(0, 1, 0)); } else if (glfwGetKey(window, 'X')) { gCamera.offsetPosition(secondsElapsed * moveSpeed * glm::vec3(0, 1, 0)); } //move light if (glfwGetKey(window, '1')) gLight.position = gCamera.position(); // change light color if (glfwGetKey(window, '2')) gLight.intensities = glm::vec3(1, 0, 0); //red else if (glfwGetKey(window, '3')) gLight.intensities = glm::vec3(0, 1, 0); //green else if (glfwGetKey(window, '4')) gLight.intensities = glm::vec3(1, 1, 1); //white //rotate camera based on mouse movement const float mouseSensitivity = 0.1f; double mouseX, mouseY; glfwGetCursorPos(window, &mouseX, &mouseY); gCamera.offsetOrientation(mouseSensitivity * (float)mouseY, mouseSensitivity * (float)mouseX); glfwSetCursorPos(window, 0, 0); //reset the mouse, so it doesn't go out of the window const float zoomSensitivity = -0.2f; float fieldOfView = gCamera.fieldOfView() + zoomSensitivity * (float)gScrollY; if (fieldOfView < 5.0f) fieldOfView = 5.0f; if (fieldOfView > 130.0f) fieldOfView = 130.0f; gCamera.setFieldOfView(fieldOfView); gScrollY = 0; }
// update the scene based on the time elapsed since last update static void Update(float secondsElapsed) { //rotate the first instance in `gInstances` const GLfloat degreesPerSecond = 180.0f; gDegreesRotated += secondsElapsed * degreesPerSecond; while(gDegreesRotated > 360.0f) gDegreesRotated -= 360.0f; gInstances.front().transform = glm::rotate(glm::mat4(), gDegreesRotated, glm::vec3(0,1,0)); //move position of camera based on WASD keys, and XZ keys for up and down const float moveSpeed = 4.0; //units per second if(glfwGetKey('S')){ gCamera.offsetPosition(secondsElapsed * moveSpeed * -gCamera.forward()); } else if(glfwGetKey('W')){ gCamera.offsetPosition(secondsElapsed * moveSpeed * gCamera.forward()); } if(glfwGetKey('A')){ gCamera.offsetPosition(secondsElapsed * moveSpeed * -gCamera.right()); } else if(glfwGetKey('D')){ gCamera.offsetPosition(secondsElapsed * moveSpeed * gCamera.right()); } if(glfwGetKey('Z')){ gCamera.offsetPosition(secondsElapsed * moveSpeed * -glm::vec3(0,1,0)); } else if(glfwGetKey('X')){ gCamera.offsetPosition(secondsElapsed * moveSpeed * glm::vec3(0,1,0)); } //move light if(glfwGetKey('1')) gLight.position = gCamera.position(); // change light color if(glfwGetKey('2')) gLight.intensities = glm::vec3(1,0,0); //red else if(glfwGetKey('3')) gLight.intensities = glm::vec3(0,1,0); //green else if(glfwGetKey('4')) gLight.intensities = glm::vec3(1,1,1); //white //rotate camera based on mouse movement const float mouseSensitivity = 0.1f; int mouseX, mouseY; glfwGetMousePos(&mouseX, &mouseY); gCamera.offsetOrientation(mouseSensitivity * mouseY, mouseSensitivity * mouseX); glfwSetMousePos(0, 0); //reset the mouse, so it doesn't go out of the window //increase or decrease field of view based on mouse wheel const float zoomSensitivity = -0.2f; float fieldOfView = gCamera.fieldOfView() + zoomSensitivity * (float)glfwGetMouseWheel(); if(fieldOfView < 5.0f) fieldOfView = 5.0f; if(fieldOfView > 130.0f) fieldOfView = 130.0f; gCamera.setFieldOfView(fieldOfView); glfwSetMouseWheel(0); }
// update the scene based on the time elapsed since last update void Update(float secondsElapsed) { const GLfloat degreesPerSecond = 180.0f; gDegreesRotated += secondsElapsed * degreesPerSecond; while(gDegreesRotated > 360.0f) gDegreesRotated -= 360.0f; // Move position of camera base on WASD keys const float moveSpeed = 3.0; // Units per second; if(glfwGetKey(gWindow, 'S')) { gCamera.offsetPosition(secondsElapsed * moveSpeed * -gCamera.forward()); }else if(glfwGetKey(gWindow, 'W')) { gCamera.offsetPosition(secondsElapsed * moveSpeed * gCamera.forward()); } if(glfwGetKey(gWindow, 'A')) { gCamera.offsetPosition(secondsElapsed * moveSpeed * gCamera.right()); }else if(glfwGetKey(gWindow, 'D')) { gCamera.offsetPosition(secondsElapsed * moveSpeed * -gCamera.right()); } if(glfwGetKey(gWindow, 'Z')) { gCamera.offsetPosition(secondsElapsed * moveSpeed * -gCamera.up()); }else if(glfwGetKey(gWindow, 'X')) { gCamera.offsetPosition(secondsElapsed * moveSpeed * gCamera.up()); } //rotate camera based on mouse movement const float mouseSensitivity = 0.1f; double mouseX, mouseY; glfwGetCursorPos(gWindow, &mouseX, &mouseY); gCamera.offsetOrientation(mouseSensitivity * (float)mouseY, mouseSensitivity * (float)mouseX); glfwSetCursorPos(gWindow, 0, 0); //reset the mouse, so it doesn't go out of the window //increase or decrease field of view based on mouse wheel const float zoomSensitivity = -0.2f; float fieldOfView = gCamera.fieldOfView() + zoomSensitivity * (float)gScrollY; if(fieldOfView < 5.0f) fieldOfView = 5.0f; if(fieldOfView > 130.0f) fieldOfView = 130.0f; gCamera.setFieldOfView(fieldOfView); gScrollY = 0; }
// update the scene based on the time elapsed since last update static void Update(float secondsElapsed) { //rotate the first instance in `gInstances` const GLfloat degreesPerSecond = 180.0f; gDegreesRotated += secondsElapsed * degreesPerSecond; while(gDegreesRotated > 360.0f) gDegreesRotated -= 360.0f; gInstances.front().transform = glm::rotate(glm::mat4(), glm::radians(gDegreesRotated), glm::vec3(0,1,0)); //move position of camera based on WASD keys, and XZ keys for up and down const float moveSpeed = 2.0; //units per second if(glfwGetKey(gWindow, 'S')){ gCamera.offsetPosition(secondsElapsed * moveSpeed * -gCamera.forward()); } else if(glfwGetKey(gWindow, 'W')){ gCamera.offsetPosition(secondsElapsed * moveSpeed * gCamera.forward()); } if(glfwGetKey(gWindow, 'A')){ gCamera.offsetPosition(secondsElapsed * moveSpeed * -gCamera.right()); } else if(glfwGetKey(gWindow, 'D')){ gCamera.offsetPosition(secondsElapsed * moveSpeed * gCamera.right()); } if(glfwGetKey(gWindow, 'Z')){ gCamera.offsetPosition(secondsElapsed * moveSpeed * -glm::vec3(0,1,0)); } else if(glfwGetKey(gWindow, 'X')){ gCamera.offsetPosition(secondsElapsed * moveSpeed * glm::vec3(0,1,0)); } //rotate camera based on mouse movement const float mouseSensitivity = 0.1f; double mouseX, mouseY; glfwGetCursorPos(gWindow, &mouseX, &mouseY); gCamera.offsetOrientation(mouseSensitivity * (float)mouseY, mouseSensitivity * (float)mouseX); glfwSetCursorPos(gWindow, 0, 0); //reset the mouse, so it doesn't go out of the window //increase or decrease field of view based on mouse wheel const float zoomSensitivity = -0.2f; float fieldOfView = gCamera.fieldOfView() + zoomSensitivity * (float)gScrollY; if(fieldOfView < 5.0f) fieldOfView = 5.0f; if(fieldOfView > 130.0f) fieldOfView = 130.0f; gCamera.setFieldOfView(fieldOfView); gScrollY = 0; }
// update the scene based on the time elapsed since last update void Update(float secondsElapsed) { //rotate the cube const GLfloat degreesPerSecond = 180.0f; gDegreesRotated += secondsElapsed * degreesPerSecond; while(gDegreesRotated > 360.0f) gDegreesRotated -= 360.0f; //move position of camera based on WASD keys, and XZ keys for up and down const float moveSpeed = 2.0; //units per second if(glfwGetKey('S')){ gCamera.offsetPosition(secondsElapsed * moveSpeed * -gCamera.forward()); } else if(glfwGetKey('W')){ gCamera.offsetPosition(secondsElapsed * moveSpeed * gCamera.forward()); } if(glfwGetKey('A')){ gCamera.offsetPosition(secondsElapsed * moveSpeed * -gCamera.right()); } else if(glfwGetKey('D')){ gCamera.offsetPosition(secondsElapsed * moveSpeed * gCamera.right()); } if(glfwGetKey('Z')){ gCamera.offsetPosition(secondsElapsed * moveSpeed * -glm::vec3(0,1,0)); } else if(glfwGetKey('X')){ gCamera.offsetPosition(secondsElapsed * moveSpeed * glm::vec3(0,1,0)); } //rotate camera based on mouse movement const float mouseSensitivity = 0.1; int mouseX, mouseY; glfwGetMousePos(&mouseX, &mouseY); gCamera.offsetOrientation(mouseSensitivity * mouseY, mouseSensitivity * mouseX); glfwSetMousePos(0, 0); //reset the mouse, so it doesn't go out of the window //increase or decrease field of view based on mouse wheel const float zoomSensitivity = -0.2; float fieldOfView = gCamera.fieldOfView() + zoomSensitivity * (float)glfwGetMouseWheel(); if(fieldOfView < 5.0f) fieldOfView = 5.0f; if(fieldOfView > 130.0f) fieldOfView = 130.0f; gCamera.setFieldOfView(fieldOfView); glfwSetMouseWheel(0); }