int main(int argc, char *argv[]) { process_args(argc, argv); Camera_Reset(); while (1) { if (glfwGetKey(mainWindow, GLFW_KEY_ESCAPE) == GLFW_PRESS || glfwWindowShouldClose(mainWindow) == 1) { break; } process_inputs(); Engine_UpkeepTime(); /* Updates deltaTime */ Engine_Draw(); /* Render */ Engine_Update(); /* Update anything else */ } Engine_Quit(); printf("\nKa3D is now shutting down!\n"); return 0; }
/** * @brief Initialize CMOS VGA Camera Module OV7670 * @param None * @retval ERROR, SUCCESS */ ErrorStatus Camera_Init(void) { uint8_t i; ReturnState *RetState; ErrorStatus Status = ERROR; // Initialize GPIO(DCMI) pins, MCO1(PA8) as output clock for XCLK Camera_HW_Init(); // Reset all Camera Module registers to the default value Camera_Reset(); // Initialize Camera Module registers // Choose between normal and debug camera operation #ifdef Camera_Debug // for debug operation for(i = 0; i < Debug_Register_Num; i++) { Camera_WriteReg(InitBuffer2[i][0], InitBuffer2[i][1]); } #else // for normal operation for(i = 0; i < CHANGE_REG; i++) { Camera_WriteReg(Camera_REG[i][0], Camera_REG[i][1]); } #endif // Verify written data into register in Camera Module if is defined Camera_Verify #ifdef Camera_Verify // Choose between normal and debug camera operation // for debug operation #ifdef Camera_Debug for(i = 0; i < 7; i++) { RetState = Camera_ReadReg(InitBuffer2[i][0]); if(RetState->Data == InitBuffer2[i][1] && RetState->State == SUCCESS) Status = SUCCESS; else Status = ERROR; } // for normal operation #else for(i = 0; i < CHANGE_REG; i++) { RetState = Camera_ReadReg(Camera_REG[i][0]); if(RetState->Data == Camera_REG[i][1] && RetState->State == SUCCESS) Status = SUCCESS; else Status = ERROR; } #endif #else Status = SUCCESS; #endif return(Status); }
void processNormalKeys(unsigned char key, int x, int y) { switch( key ) { case 'w': Camera_StartMove(FORWARD); break; case 'a': Camera_StartMove(LEFT); break; case 's': Camera_StartMove(BACK); break; case 'd': Camera_StartMove(RIGHT); break; case 'q': Camera_StartMove(UP); break; case 'e': Camera_StartMove(DOWN); break; case 'r': World_Reset(); Camera_Reset(); break; case ' ': World_Pause(); break; case 'p': World_Pause(); World_Update( 0.0166666666 ); World_Pause(); break; case 'c': Debug_ClearLines(); break; } }
int process_inputs() { // Get mouse position double xpos, ypos; glfwGetCursorPos(mainWindow, &xpos, &ypos); // Reset mouse position for next frame glfwSetCursorPos(mainWindow, SCREEN_WIDTH/2, SCREEN_HEIGHT/2); // Compute new orientation horizontalAngle += mouseSpeed * (float)( SCREEN_WIDTH/2 - xpos ); verticalAngle += mouseSpeed * (float)( SCREEN_HEIGHT/2 - ypos ); /* If F1, reload */ if (glfwGetKey(mainWindow, GLFW_KEY_F1)) { Engine_Reload(); } /* If F2, reset view */ if (glfwGetKey(mainWindow, GLFW_KEY_F2)) { printf("Camera reset.\n"); Camera_Reset(); } /* If tab, change lookat to next mesh */ if (glfwGetKey(mainWindow, GLFW_KEY_TAB)) { //Camera_LookAtNext(); } /* Move closer */ //if (glfwGetKey(mainWindow, GLFW_KEY_W)) { // ypos = 100; //} /* Move further */ //if (glfwGetKey(mainWindow, GLFW_KEY_S)) { // ypos = -100; //} /* Move left */ //if (glfwGetKey(mainWindow, GLFW_KEY_A)) { // xpos = 100; //} /* Move right */ //if (glfwGetKey(mainWindow, GLFW_KEY_D)) { // xpos = -100; //} // Compute new orientation //horizontalAngle += mouseSpeed * (float)(1024/2 - xpos ); //verticalAngle += mouseSpeed * (float)( 768/2 - ypos ); horizontalAngle += mouseSpeed * xpos; verticalAngle += mouseSpeed * ypos; //printf("horizontalAngle is %f, and verticalAngle is %f.\n", horizontalAngle, verticalAngle); // Direction : Spherical coordinates to Cartesian coordinates conversion float temp1 = cos(verticalAngle) * sin(horizontalAngle); float temp2 = sin(verticalAngle); float temp3 = cos(verticalAngle) * cos(horizontalAngle); kmVec3 direction = {temp1, temp2, temp3}; // Right vector kmVec3 right = { sin(horizontalAngle - 3.14f/2.0f), 0, cos(horizontalAngle - 3.14f/2.0f) }; // Up vector kmVec3 up = *kmVec3Cross(&up, &right, &direction ); // Move forward if (glfwGetKey( mainWindow, GLFW_KEY_UP ) == GLFW_PRESS){ kmVec3Add(&position, &position, kmVec3Scale(&position, &direction, deltaTime * speed)); } // Move backward if (glfwGetKey( mainWindow, GLFW_KEY_DOWN ) == GLFW_PRESS){ kmVec3Subtract(&position, &position, kmVec3Scale(&position, &direction, deltaTime * speed)); } // Strafe right if (glfwGetKey( mainWindow, GLFW_KEY_RIGHT ) == GLFW_PRESS){ kmVec3Add(&position, &position, kmVec3Scale(&position, &right, deltaTime * speed)); } // Strafe left if (glfwGetKey( mainWindow, GLFW_KEY_LEFT ) == GLFW_PRESS){ kmVec3Subtract(&position, &position, kmVec3Scale(&position, &right, deltaTime * speed)); } float FoV = initialFoV; kmMat4PerspectiveProjection(&ProjectionMatrix, FoV, (16.0f / 8.0f), 0.1f, 100.0f); // Camera matrix //ViewMatrix = glm::lookAt( // position, // Camera is here // position+direction, // and looks here : at the same position, plus "direction" // up // Head is up (set to 0,-1,0 to look upside-down) // ); kmVec3 p_eye; p_eye = position; kmVec3 p_ctr; p_ctr = *kmVec3Add(&p_ctr, &position, &direction); kmVec3 p_up; p_up = up; kmMat4LookAt(&ViewMatrix, &p_eye, &p_ctr, &p_up); kmMat4Identity(&ModelMatrix); kmMat4 temp_mat; kmMat4Multiply(&temp_mat, &ViewMatrix, &ModelMatrix); kmMat4Multiply(&MVP, &ProjectionMatrix, &temp_mat ); //printf("Matrix contains:\n"); //printf("%f, %f, %f, %f\n", MVP.mat[0], MVP.mat[1], MVP.mat[2], MVP.mat[3]); //printf("%f, %f, %f, %f\n", MVP.mat[4], MVP.mat[5], MVP.mat[6], MVP.mat[7]); //printf("%f, %f, %f, %f\n", MVP.mat[8], MVP.mat[9], MVP.mat[10], MVP.mat[11]); //printf("%f, %f, %f, %f\n", MVP.mat[12], MVP.mat[13], MVP.mat[14], MVP.mat[15]); return 0; }