void Key ( ESContext *esContext, unsigned char key, bool bIsPressed) { camera.ProcessKeyboard(CameraMovement(key)); }
void Pong::Update(double simLength) { // Swap between models 2D and 3D if (swapProjection) { if (projectionMode == Game::Orthographic) { gameObjectRegister[0]->ChangeModel(modelRegister[0], 1.0f, shaderLocations, "Assets/Textures/WhiteTexture.bmp"); gameObjectRegister[0]->boundingBox.dimensions = glm::vec3(1.0f, 1.0f, 1.0f); gameObjectRegister[0]->boundingBoxOffset = glm::vec3(0.0f, 0.0f, 0.0f); gameObjectRegister[1]->LoadTextures("Assets/Textures/WhiteTexture.bmp"); gameObjectRegister[2]->LoadTextures("Assets/Textures/WhiteTexture.bmp"); gameObjectRegister[3]->LoadTextures("Assets/Textures/WhiteTexture.bmp"); gameObjectRegister[4]->ChangeModel(modelRegister[0], 1.0f, shaderLocations, "Assets/Textures/WhiteTexture.bmp"); gameObjectRegister[5]->LoadTextures("Assets/Textures/BlackTexture.bmp"); } if (projectionMode == Game::Perspective) { gameObjectRegister[0]->ChangeModel(modelRegister[5], 0.005f, shaderLocations, "Assets/Textures/Elephant.bmp"); gameObjectRegister[0]->boundingBox.dimensions = glm::vec3(3.0f, 3.0f, 2.0f); gameObjectRegister[0]->boundingBoxOffset = glm::vec3(0.0f, 0.0f, 0.0f); gameObjectRegister[1]->LoadTextures("Assets/Textures/RedTexture.bmp"); gameObjectRegister[2]->LoadTextures("Assets/Textures/BlueTexture.bmp"); gameObjectRegister[3]->LoadTextures("Assets/Textures/WoodTexture.bmp"); gameObjectRegister[4]->ChangeModel(modelRegister[4], 0.02f, shaderLocations, "Assets/Textures/GraniteTexture.bmp"); gameObjectRegister[5]->LoadTextures("Assets/Textures/NightSkyTexture.bmp"); } swapProjection = false; } // Score Update Ball* tempBallObject = dynamic_cast<Ball*>(gameObjectRegister[0]); // Casts the ball object in the gameobject list so its derived methods can be accessed. GUI* tempGUIObject = dynamic_cast<GUI*>(gameObjectRegister[4]); WorldBounds* tempWorldBoundsObject = dynamic_cast<WorldBounds*>(gameObjectRegister[3]); tempBallObject->UpdateGUIScore(*tempGUIObject); // Updates the score by passing references to the games UI. if (projectionMode == Perspective) { tempGUIObject->UpdateScore(true); tempWorldBoundsObject->UpdateDrawMode(true); } else { tempGUIObject->UpdateScore(false); tempWorldBoundsObject->UpdateDrawMode(false); } bool gameEnd = tempGUIObject->CheckEndCondition(); if (gameEnd) { done = true; } // Update each GameObject. for (int i = 0; i < gameObjectRegister.size(); i++) { gameObjectRegister[i]->Update(simLength, gameObjectRegister); } CameraMovement(); if (followBall) { cameraPosition = glm::vec3(tempBallObject->position.x, tempBallObject->position.y, tempBallObject->position.z + 75.0f); cameraLookAt = tempBallObject->position; } gameObjectRegister.back()->position = cameraPosition; // Update the skybox location, causing it to be infinitely far away. viewMatrix = glm::lookAt(cameraPosition, cameraLookAt, upVector); // Update the view matrix. // Clear the pointers. tempBallObject = nullptr; tempGUIObject = nullptr; tempWorldBoundsObject = nullptr; delete tempBallObject, tempGUIObject, tempWorldBoundsObject; // Deletes the memory pointer to avoid memory leaks. }