Add Particle Demo
This commit is contained in:
parent
2d0e856124
commit
5ffbe94816
91
test/particle-demo/main.cpp
Normal file
91
test/particle-demo/main.cpp
Normal file
@ -0,0 +1,91 @@
|
|||||||
|
#include "Gedeng/Logger.h"
|
||||||
|
#include "Gedeng/ParticleSystem.h"
|
||||||
|
#include "Gedeng/TextLabel.h"
|
||||||
|
#include "Gedeng/Vector3.h"
|
||||||
|
#define GEDENG_MAIN
|
||||||
|
#include <Gedeng.h>
|
||||||
|
|
||||||
|
class ParticleApp : public Gedeng::Application {
|
||||||
|
public:
|
||||||
|
ParticleApp(unsigned long ms_per_update, unsigned int window_size_x, unsigned int window_size_y,
|
||||||
|
Gedeng::String window_name)
|
||||||
|
: Application(ms_per_update, window_size_x, window_size_y, window_name),
|
||||||
|
camera(Gedeng::Camera(90, 1920, 1080, 0.1, 1000.0)),
|
||||||
|
albedo("Resources/Textures/PavingStones/PavingStones070_2K_Color.jpg", Gedeng::Texture::Settings()),
|
||||||
|
bump("Resources/Textures/PavingStones/PavingStones070_2K_Displacement.jpg", Gedeng::Texture::Settings()),
|
||||||
|
normal("Resources/Textures/PavingStones/PavingStones070_2K_Normal.jpg", Gedeng::Texture::Settings()) {
|
||||||
|
// Move and rotate the camera so we see the quad well
|
||||||
|
// camera.translate(glm::vec3(0.0, 0.0, -1.0));
|
||||||
|
// camera.rotate(180, glm::vec3(0.0, 1.0, 0.0));
|
||||||
|
|
||||||
|
particles.set_position(glm::vec3(0.0f, 0.0f, -5.0f));
|
||||||
|
particles.set_velocity(glm::vec3(-5, 0, -5), glm::vec3(5, 20, 5));
|
||||||
|
particles.set_gravity(glm::vec3(0, -5, 0));
|
||||||
|
particles.set_color(glm::vec3(0.0f, 0.5f, 1.0f));
|
||||||
|
particles.set_lifetime(1.5f, 3.0f);
|
||||||
|
particles.set_size(0.75f);
|
||||||
|
particles.set_interval(0.2f);
|
||||||
|
particles.set_number_of_particles(30);
|
||||||
|
particles.set_texture(&albedo);
|
||||||
|
}
|
||||||
|
|
||||||
|
~ParticleApp() = default;
|
||||||
|
|
||||||
|
void fixed_update(double delta) override {
|
||||||
|
// camera.rotate(delta * 180, glm::vec3(0.0, 1.0, 0.0));
|
||||||
|
}
|
||||||
|
|
||||||
|
void dynamic_update(double delta) override {
|
||||||
|
glClearColor(0.1f, 0.1f, 0.1f, 1.0f);
|
||||||
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
|
|
||||||
|
/* render_shader.use();
|
||||||
|
|
||||||
|
// Camera
|
||||||
|
render_shader.setMat4("projection", camera.get_projection());
|
||||||
|
render_shader.setMat4("view", camera.get_view());
|
||||||
|
render_shader.setVec3("viewPos", camera.get_translation());
|
||||||
|
|
||||||
|
// Lighting
|
||||||
|
render_shader.setVec3("lightPos", glm::vec3(0.0, 1.0, 5.0));
|
||||||
|
|
||||||
|
render_shader.setFloat("number_of_steps", glm::max(0.0f, number_of_steps));
|
||||||
|
render_shader.setFloat("number_of_refinement_steps", glm::max(0.0f, number_of_refinement_steps));
|
||||||
|
render_shader.setFloat("bump_depth", glm::max(0.0f, bump_depth));
|
||||||
|
|
||||||
|
// Textures
|
||||||
|
albedo.bind_to(0);
|
||||||
|
normal.bind_to(1);
|
||||||
|
bump.bind_to(2);
|
||||||
|
|
||||||
|
// Quad which is rendered onto
|
||||||
|
quad_mesh.rotate(delta * 25.0f, glm::normalize(glm::vec3(0.0, 0.0, 1.0)));
|
||||||
|
quad_mesh.render(render_shader);
|
||||||
|
|
||||||
|
debug_text.render_text(25.0f, 25.0f, 1.0f, Gedeng::Vector3(1.0, 1.0, 0.0)); */
|
||||||
|
|
||||||
|
particles.set_camera(camera);
|
||||||
|
particles.update(delta);
|
||||||
|
particles.render();
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
Gedeng::ParticleSystem particles;
|
||||||
|
|
||||||
|
Gedeng::VertexBuffer vertex_rectangle;
|
||||||
|
|
||||||
|
Gedeng::Camera camera;
|
||||||
|
|
||||||
|
Gedeng::Texture albedo;
|
||||||
|
Gedeng::Texture bump;
|
||||||
|
Gedeng::Texture normal;
|
||||||
|
|
||||||
|
Gedeng::QuadMesh quad_mesh;
|
||||||
|
|
||||||
|
Gedeng::TextLabel debug_text;
|
||||||
|
};
|
||||||
|
|
||||||
|
Gedeng::Application *Gedeng::create_application() {
|
||||||
|
GG_CLIENT_INFO("Creating Application");
|
||||||
|
return new ParticleApp(20, 1920, 1080, String("Parallax Demo"));
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user