diff --git a/OpenGL_Flightsim/src/app.cpp b/OpenGL_Flightsim/src/app.cpp index bce2a44..4a2ebec 100644 --- a/OpenGL_Flightsim/src/app.cpp +++ b/OpenGL_Flightsim/src/app.cpp @@ -6,9 +6,10 @@ #include "flightmodel.h" #include "terrain.h" -#define DRAW_HUD 0 +#define DRAW_HUD 1 #define GROUND_START 1 #define PARTICLES 1 +#define RENDER_LANDING_GEAR 1 const Airfoil NACA_0012(NACA_0012_data); const Airfoil NACA_2412(NACA_2412_data); @@ -201,19 +202,18 @@ void App::init_airplane() #if PARTICLES // afterburner - auto red_blue = gfx::Range(gfx::rgb(0xff0000), gfx::rgb(0x0000ff)); - auto afterburner = gfx::Range(gfx::rgb(0xFFFFD4), gfx::rgb(0xA091A6)); + auto afterburner = gfx::Range(gfx::rgb(0xFFA500), gfx::rgb(0x0000ff)); gfx::ParticleSystem::Config config = {.count = 5000U, - .emitter_radius = 0.35f, + .emitter_radius = 0.3f, .emitter_cone = 0.01f, .speed = gfx::Range(100.0f, 150.0f), - .size = gfx::Range(0.2f, 0.3f), + .size = gfx::Range(0.3f, 0.4f), .lifetime = gfx::Range(0.02f, 0.03f), .color = afterburner }; m_particles = new gfx::ParticleSystem(config, "assets/textures/particle.png"); - m_particles->set_position(glm::vec3(-5.5f, 0.0f, 0.0f)); + m_particles->set_position(glm::vec3(-5.0f, 0.0f, 0.0f)); m_particles->set_rotation(glm::vec3(0.0f, 0.0f, glm::radians(90.0f))); m_falcon->add(m_particles); #endif @@ -247,8 +247,9 @@ void App::init_airplane() m_airplane = new Airplane(mass, inertia, wings, {Engine(thrust)}, collider); -#if 1 - gfx::Object3D* landing_gear = new gfx::Object3D(); +#if RENDER_LANDING_GEAR + landing_gear = new gfx::Object3D(); + std::cout << "landing gear id = " << landing_gear->id << std::endl; m_falcon->add(landing_gear); auto wheel_texture = std::make_shared("assets/textures/container.jpg"); @@ -262,7 +263,8 @@ void App::init_airplane() gfx::Mesh* wheel_mesh = new gfx::Mesh(wheel_geometry, wheel_material); wheel_mesh->visible = true; obj->add(wheel_mesh); - m_falcon->add(obj); + //m_falcon->add(obj); + landing_gear->add(obj); } #endif } @@ -342,6 +344,9 @@ void App::event_keydown(SDL_Keycode key) case SDLK_p: m_paused = !m_paused; break; + case SDLK_g: + landing_gear->visible = !landing_gear->visible; + break; } } @@ -527,10 +532,17 @@ void App::game_loop(float dt) m_hud->batch_clear(); #if PARTICLES + float throttle = glm::clamp(m_airplane->throttle, 0.0f, 1.0f); + m_particles->m_config.lifetime.min_value = 0.005f + 0.02f * throttle; + m_particles->m_config.lifetime.max_value = 0.007f + 0.03f * throttle; + //m_particles->m_config.lifetime.max_value = 0.02f + 0.02f * m_airplane->throttle; m_particles->update(dt, m_cameras[m_cameratype]->get_world_position(), m_airplane->velocity); #endif } + //landing_gear->visible = false; + //m_falcon->visible = false; + m_controller.update(*m_cameras[0], m_falcon->get_position(), dt); m_renderer->render(m_cameras[m_cameratype], m_scene); diff --git a/OpenGL_Flightsim/src/app.h b/OpenGL_Flightsim/src/app.h index 621d2ff..21efc66 100644 --- a/OpenGL_Flightsim/src/app.h +++ b/OpenGL_Flightsim/src/app.h @@ -53,6 +53,7 @@ class App gfx::Object3D* m_camera_attachment; gfx::Object3D* m_runway; + gfx::Object3D* landing_gear; // physics Airplane* m_airplane; diff --git a/OpenGL_Flightsim/src/gfx/object3d.cpp b/OpenGL_Flightsim/src/gfx/object3d.cpp index 15d7c41..1ac35bc 100644 --- a/OpenGL_Flightsim/src/gfx/object3d.cpp +++ b/OpenGL_Flightsim/src/gfx/object3d.cpp @@ -17,8 +17,9 @@ void Object3D::draw(RenderContext& context) draw_self(context); if (wireframe) glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); + + draw_children(context); } - draw_children(context); } void Object3D::draw_self(RenderContext& context) {} @@ -113,7 +114,7 @@ glm::mat4 Object3D::get_transform() const { // this function must only be called after updating the transform if (m_dirty) { - //assert(!m_dirty); + // assert(!m_dirty); } return m_transform; } diff --git a/OpenGL_Flightsim/src/gfx/particles.cpp b/OpenGL_Flightsim/src/gfx/particles.cpp index 23e1ade..d9aec39 100644 --- a/OpenGL_Flightsim/src/gfx/particles.cpp +++ b/OpenGL_Flightsim/src/gfx/particles.cpp @@ -54,7 +54,7 @@ int ParticleSystem::find_unused_particle() void ParticleSystem::update(float dt, const glm::vec3& camera_position, const glm::vec3& emitter_velocity) { - int new_particles = 100; + int new_particles = 200; glm::vec3 world_position = get_world_position(); @@ -67,10 +67,8 @@ void ParticleSystem::update(float dt, const glm::vec3& camera_position, const gl glm::vec4 color = glm::vec4(m_config.color.min_value, 0.0f); auto rotation = get_world_rotation_quat(); - //auto rotation = parent->get_rotation_quat(); - // this needs to be actually relative to the speed that the emitter is moving - float speed = m_config.speed.value(); + float speed = m_config.speed.value(); glm::vec3 direction = vector_in_hemisphere(m_config.emitter_cone); @@ -78,7 +76,7 @@ void ParticleSystem::update(float dt, const glm::vec3& camera_position, const gl particle->distance_from_camera = 1.0f; particle->position = world_position + vector_in_sphere() * m_config.emitter_radius; - particle->velocity = emitter_velocity + velocity ; // TODO: fix this + particle->velocity = emitter_velocity + velocity; // TODO: fix this particle->color = color; particle->size = m_config.size.value(); particle->lifetime = m_config.lifetime.value(); @@ -95,8 +93,8 @@ void ParticleSystem::update(float dt, const glm::vec3& camera_position, const gl if (0 < particle->lifetime) { float t = particle->lifetime / m_config.lifetime.max_value; particle->position += particle->velocity * dt; - particle->size *= 0.99f; - particle->color = glm::vec4(m_config.color.value(t), t); + particle->size *= 0.95f; + particle->color = glm::vec4(m_config.color.value(t), glm::mix(m_config.start_alpha, 0.0f, t)); particle->distance_from_camera = glm::length(particle->position - camera_position); m_particle_count++; } else { @@ -134,7 +132,6 @@ void ParticleSystem::draw_self(RenderContext& context) glm::vec3 up = {view[0][1], view[1][1], view[2][1]}; glm::vec3 right = {view[0][0], view[1][0], view[2][0]}; - // get currently set blend func GLint blendSrc, blendDst; glGetIntegerv(GL_BLEND_SRC, &blendSrc); @@ -149,8 +146,7 @@ void ParticleSystem::draw_self(RenderContext& context) shader->set_uniform("u_Right", right); shader->set_uniform("u_Up", up); - if (m_texture != nullptr) - { + if (m_texture != nullptr) { m_texture->bind(5); shader->set_uniform("u_Texture", 5); } @@ -186,8 +182,6 @@ void ParticleSystem::draw_self(RenderContext& context) // reset blend func glBlendFunc(blendSrc, blendDst); - } - } // namespace gfx diff --git a/OpenGL_Flightsim/src/gfx/particles.h b/OpenGL_Flightsim/src/gfx/particles.h index 54b9a46..cd95aa2 100644 --- a/OpenGL_Flightsim/src/gfx/particles.h +++ b/OpenGL_Flightsim/src/gfx/particles.h @@ -37,16 +37,19 @@ class ParticleSystem : public Object3D Range lifetime = Range(1.0f, 2.0f); Range color = Range(glm::vec3(1.0f), glm::vec3(0.0f)); GLenum blend_src = GL_SRC_ALPHA, blend_dest = GL_ONE; + float start_alpha = 0.5f; }; ParticleSystem(const Config& config, const std::string& path); void draw_self(RenderContext& context) override; void update(float dt, const glm::vec3& camera_position, const glm::vec3& emitter_velocity = glm::vec3(0.0f)); + + Config m_config; + private: int find_unused_particle(); - Config m_config; int m_last_used_particle; int m_particle_count;