reset
This commit is contained in:
parent
d5962f10e3
commit
d327791de9
1 changed files with 17 additions and 7 deletions
|
@ -33,6 +33,7 @@ using namespace std;
|
|||
//----------------------------------------------------------------------------
|
||||
// Forward-declaring some functions for later implementation
|
||||
|
||||
void resetEverything();
|
||||
void copyMatrix(GLfloat *a, GLfloat *b);
|
||||
|
||||
/// Print the matrix
|
||||
|
@ -54,7 +55,7 @@ void slow4x4MatrixMultiplyIntoColumnOrder(
|
|||
GLfloat *left, GLfloat *right, GLfloat *result
|
||||
);
|
||||
|
||||
GLfloat *slow4x4MatrixMultiplyAllRowOrder(GLfloat *left, GLfloat *right);
|
||||
GLfloat *matrixMultiply(GLfloat *left, GLfloat *right);
|
||||
|
||||
void handleScaling(int key, int scancode, int action, int mods);
|
||||
void handleRotate(double xpos, double ypos);
|
||||
|
@ -115,10 +116,13 @@ static void error_callback(int error, const char *description) {
|
|||
static void
|
||||
key_callback(GLFWwindow *window, int key, int scancode, int action, int mods) {
|
||||
// checks to see if the escape key was pressed
|
||||
if ((key == GLFW_KEY_ESCAPE || key == GLFW_KEY_Q) && action == GLFW_PRESS)
|
||||
if ((key == GLFW_KEY_ESCAPE || key == GLFW_KEY_Q) && action == GLFW_RELEASE)
|
||||
// closes the window
|
||||
glfwSetWindowShouldClose(window, GL_TRUE);
|
||||
|
||||
if (key == GLFW_KEY_R && action == GLFW_RELEASE)
|
||||
resetEverything();
|
||||
|
||||
// Handle ctrl key press
|
||||
if (key == GLFW_KEY_LEFT_CONTROL)
|
||||
is_ctrl_held = action == GLFW_PRESS;
|
||||
|
@ -336,10 +340,8 @@ int main(int argc, char **argv) {
|
|||
// be the identity matrix; you will need define M according to the user's
|
||||
// actions.
|
||||
|
||||
GLfloat *result1 =
|
||||
slow4x4MatrixMultiplyAllRowOrder(scale_matrix, rotation_matrix);
|
||||
GLfloat *result2 =
|
||||
slow4x4MatrixMultiplyAllRowOrder(translation_matrix, result1);
|
||||
GLfloat *result1 = matrixMultiply(scale_matrix, rotation_matrix);
|
||||
GLfloat *result2 = matrixMultiply(translation_matrix, result1);
|
||||
|
||||
copyMatrix(result2, M);
|
||||
transposeMatrix(M);
|
||||
|
@ -384,6 +386,14 @@ int main(int argc, char **argv) {
|
|||
|
||||
} // end main
|
||||
|
||||
void resetEverything() {
|
||||
scale_x = 1.0;
|
||||
scale_y = 1.0;
|
||||
translate_x = 0;
|
||||
translate_y = 0;
|
||||
rotation_angle = 0;
|
||||
}
|
||||
|
||||
void printMatrix(string name, GLfloat *matrix) {
|
||||
printf(
|
||||
"%s = [%f %f %f %f\n"
|
||||
|
@ -418,7 +428,7 @@ void zeroInitGlfloats(GLfloat *arr, uint32_t len) {
|
|||
}
|
||||
}
|
||||
|
||||
GLfloat *slow4x4MatrixMultiplyAllRowOrder(GLfloat *left, GLfloat *right) {
|
||||
GLfloat *matrixMultiply(GLfloat *left, GLfloat *right) {
|
||||
GLfloat *result = (GLfloat *)malloc(16 * sizeof(GLfloat));
|
||||
|
||||
for (int i = 0; i < 4; ++i) {
|
||||
|
|
Loading…
Reference in a new issue