/* * 2D Physic Engine * app.cpp: basic application handling. * Based on pikuma.com Learn Game Physics Engine Programming course. * Copyright (c) 2022 986-Studio. All rights reserved. * * Created by Manoƫl Trapier on 07/06/2022. */ #include #include #include #include #include #include void application::parseParameters(int argc, char *argv[]) { // Nothing to do for now } void application::setup() { this->running = graphics::openWindow(); this->millisecsPreviousFrame = SDL_GetTicks(); this->part = new particle(50, 100, 1.0); } void application::input() { SDL_Event event; while(SDL_PollEvent(&event)) { //ImGui_ImplSDL2_ProcessEvent(&event); //ImGuiIO &io = ImGui::GetIO(); switch(event.type) { case SDL_QUIT: this->running = false; break; case SDL_KEYDOWN: if (event.key.keysym.sym == SDLK_ESCAPE) { this->running = false; } break; } } } void application::update() { /* Let's make sure we are running at the expected framerate */ uint32_t now = SDL_GetTicks(); int32_t timeToWait = MILLISECS_PER_FRAME - (now - this->millisecsPreviousFrame); if (timeToWait > 0) // && timeToWait <= MILLISECS_PER_FRAME) { SDL_Delay(timeToWait); } double deltaTime = (SDL_GetTicks() - this->millisecsPreviousFrame) / 1000.0; this->millisecsPreviousFrame = SDL_GetTicks(); this->part->velocity = vec2(100 * deltaTime, 30 * deltaTime); this->part->position += (this->part->velocity); } void application::render() { graphics::clearScreen(0xFF056263); graphics::draw::fillCircle(this->part->position.x, this->part->position.y, 4, 0xFFFFFFFF); graphics::renderFrame(); } void application::destroy() { // Nothing for now. graphics::closeWindow(); delete this->part; }