2022-04-24 09:00:55 +03:00
|
|
|
#include <memory>
|
|
|
|
|
|
2022-04-23 14:48:42 +03:00
|
|
|
#include "peripherals_glfw.h"
|
2022-04-24 07:15:30 +03:00
|
|
|
#include "demo/demo_engine.h"
|
|
|
|
|
#include "timer.h"
|
|
|
|
|
|
|
|
|
|
using namespace acidrain;
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
|
|
INITIALIZE_EASYLOGGINGPP
|
2022-04-23 14:48:42 +03:00
|
|
|
|
|
|
|
|
int main() {
|
2022-04-23 16:41:33 +03:00
|
|
|
acidrain::peripherals_glfw peripherals;
|
|
|
|
|
peripherals.init();
|
2022-04-24 09:00:55 +03:00
|
|
|
LOG(INFO) << "peripherals initialized";
|
2022-04-23 14:48:42 +03:00
|
|
|
|
2022-04-23 16:41:33 +03:00
|
|
|
glDisable(GL_DEPTH_TEST);
|
2022-04-23 14:48:42 +03:00
|
|
|
|
2022-04-24 07:15:30 +03:00
|
|
|
const float DEMO_LENGTH_IN_SECONDS = 100;
|
|
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------------------------
|
|
|
|
|
// Load resources
|
|
|
|
|
// --------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
acidrain::texture_generator tg(256, 256);
|
|
|
|
|
tg.brick(0, 50, 20, 4, glm::vec4(1), glm::vec4(0));
|
|
|
|
|
|
2022-04-24 09:57:52 +03:00
|
|
|
shared_ptr<mesh> affectedSphere = mesh_generator::sphere(10, 10);
|
|
|
|
|
// map_transform(affectedSphere, tg, 0, 0, 1.2f);
|
|
|
|
|
// calculate_normals(*affectedSphere.get());
|
2022-04-24 07:15:30 +03:00
|
|
|
|
2022-04-24 09:57:52 +03:00
|
|
|
// affectedSphere = mesh_generator::cog(0.2, 0.5, 50, 4, 0.1, 0.2, 0.2, 0.1);
|
2022-04-24 07:15:30 +03:00
|
|
|
|
|
|
|
|
demo_data::meshes.push_back(affectedSphere);
|
2022-04-24 09:57:52 +03:00
|
|
|
demo_data::meshes.push_back(mesh_generator::sphere(3, 3));
|
2022-04-24 07:15:30 +03:00
|
|
|
demo_data::meshes.push_back(mesh_generator::grid(30, 30));
|
|
|
|
|
demo_data::meshes.push_back(mesh_generator::cube());
|
|
|
|
|
|
2022-04-24 09:00:55 +03:00
|
|
|
auto mat = std::make_shared<material>();
|
2022-04-24 07:15:30 +03:00
|
|
|
mat->ambient = glm::vec4(0, 0, 0.15, 1);
|
|
|
|
|
mat->diffuse = glm::vec4(1, 1, 1, 1);
|
|
|
|
|
// material->diffuse = glm::vec4(1, 0, 0, 1);
|
|
|
|
|
mat->specular = glm::vec4(0.3, 0.3, 0.3, 1);
|
|
|
|
|
mat->shininess = 200;
|
|
|
|
|
mat->cast_shadows = true;
|
|
|
|
|
|
|
|
|
|
auto *textureGenerator1 = new texture_generator(256, 256);
|
2022-04-24 09:57:52 +03:00
|
|
|
// mat->textures[texture_role::diffuse] = textureGenerator1->checker_board(0, 20,
|
|
|
|
|
// colour(1, 1, 1, 1),
|
|
|
|
|
// colour(0, 0.5, 0.2, 1)).get_texture(0);
|
|
|
|
|
mat->textures[texture_role::diffuse] = textureGenerator1->brick(0,
|
|
|
|
|
50, 20,
|
|
|
|
|
4,
|
|
|
|
|
colour(0.3, 0.1, 0, 1),
|
|
|
|
|
colour(1, 0.3, 0, 1)).get_texture(0);
|
2022-04-24 07:15:30 +03:00
|
|
|
|
|
|
|
|
demo_data::materials.push_back(mat);
|
|
|
|
|
|
|
|
|
|
auto material2 = make_shared<material>();
|
|
|
|
|
material2->ambient = glm::vec4(0, 0, 0.15, 1);
|
|
|
|
|
material2->textures[texture_role::diffuse] = textureGenerator1->get_texture(0);
|
|
|
|
|
// material2->diffuse = glm::vec4(0.2, 1.0, 0.7, 1);
|
|
|
|
|
material2->diffuse = glm::vec4(1, 1, 1, 1);
|
|
|
|
|
material2->specular = glm::vec4(0.3, 0.3, 0.3, 1);
|
|
|
|
|
material2->shininess = 200;
|
|
|
|
|
material2->cast_shadows = false;
|
|
|
|
|
demo_data::materials.push_back(material2);
|
|
|
|
|
|
|
|
|
|
auto material3 = make_shared<material>();
|
|
|
|
|
material3->ambient = glm::vec4(0, 0, 0.15, 1);
|
|
|
|
|
// material3->diffuse = glm::vec4(1.0, 0.7, 0.2, 1);
|
|
|
|
|
material3->diffuse = glm::vec4(1, 1, 1, 1);
|
|
|
|
|
material3->specular = glm::vec4(0.3, 0.3, 0.3, 1);
|
|
|
|
|
material3->shininess = 200;
|
|
|
|
|
material3->cast_shadows = true;
|
|
|
|
|
demo_data::materials.push_back(material3);
|
|
|
|
|
|
|
|
|
|
auto material4 = make_shared<material>();
|
|
|
|
|
material4->ambient = glm::vec4(0, 0, 0.15, 1);
|
|
|
|
|
// material4->diffuse = glm::vec4(1.0, 0.7, 0.2, 1);
|
|
|
|
|
material4->diffuse = glm::vec4(1, 1, 1, 1);
|
|
|
|
|
material4->specular = glm::vec4(0.3, 0.3, 0.3, 1);
|
|
|
|
|
material4->shininess = 200;
|
|
|
|
|
material4->cast_shadows = false;
|
|
|
|
|
demo_data::materials.push_back(material4);
|
|
|
|
|
|
|
|
|
|
auto material5 = make_shared<material>();
|
|
|
|
|
material5->ambient = glm::vec4(0.1, 0.1, 0.15, 1);
|
|
|
|
|
// material4->diffuse = glm::vec4(1.0, 0.7, 0.2, 1);
|
|
|
|
|
material5->diffuse = glm::vec4(1, 1, 1, 1);
|
|
|
|
|
material5->specular = glm::vec4(1, 1, 1, 1);
|
|
|
|
|
material5->shininess = 10;
|
|
|
|
|
material5->cast_shadows = false;
|
|
|
|
|
demo_data::materials.push_back(material5);
|
|
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------------------------
|
|
|
|
|
// Set up demo parts
|
|
|
|
|
// --------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
DemoPartClear demoPartClear;
|
|
|
|
|
demoPartClear.startTime = 0;
|
|
|
|
|
demoPartClear.endTime = DEMO_LENGTH_IN_SECONDS;
|
|
|
|
|
demoPartClear.color = glm::vec4(0.1f, 0.1f, 0.3f, 1.0f);
|
|
|
|
|
|
|
|
|
|
DemoPartScene demoPartScene;
|
|
|
|
|
demoPartScene.startTime = 0;
|
|
|
|
|
demoPartScene.endTime = DEMO_LENGTH_IN_SECONDS;
|
|
|
|
|
demoPartScene.cameraName = "cam1";
|
|
|
|
|
demoPartScene.lightName = "light1";
|
|
|
|
|
|
2022-04-24 09:00:55 +03:00
|
|
|
auto *scene1 = new scene();
|
2022-04-24 07:15:30 +03:00
|
|
|
demoPartScene.scene_ = shared_ptr<scene>(scene1);
|
|
|
|
|
|
2022-04-24 09:57:52 +03:00
|
|
|
auto smallSphere = std::make_shared<mesh_node>("small sphere");
|
2022-04-24 07:15:30 +03:00
|
|
|
smallSphere->mesh_ = demo_data::meshes[1];
|
|
|
|
|
smallSphere->material_ = demo_data::materials[0];
|
|
|
|
|
smallSphere->position = glm::vec3(0, 0, 0);
|
|
|
|
|
smallSphere->scale = glm::vec3(0.5);
|
|
|
|
|
// meshNode->rotation = glm::angleAxis(2.25f , glm::vec3(1.0f, 0.0f, 0.0f));
|
|
|
|
|
|
2022-04-24 09:57:52 +03:00
|
|
|
auto ground_plane = std::make_shared<mesh_node>("ground_plane");
|
2022-04-24 07:15:30 +03:00
|
|
|
ground_plane->mesh_ = demo_data::meshes[2];
|
|
|
|
|
ground_plane->material_ = demo_data::materials[1];
|
|
|
|
|
ground_plane->position = glm::vec3(0, 0, 0);
|
|
|
|
|
ground_plane->scale = glm::vec3(10);
|
|
|
|
|
ground_plane->rotation = glm::angleAxis(3.141529f / 2.0f, glm::vec3(1.0f, 0.0f, 0.0f));
|
2022-04-23 14:48:42 +03:00
|
|
|
|
2022-04-24 09:57:52 +03:00
|
|
|
auto black_plane = std::make_shared<mesh_node>("back plane");
|
2022-04-24 07:15:30 +03:00
|
|
|
black_plane->mesh_ = demo_data::meshes[2];
|
|
|
|
|
black_plane->material_ = demo_data::materials[1];
|
|
|
|
|
black_plane->position = glm::vec3(0, 5, -5);
|
|
|
|
|
black_plane->scale = glm::vec3(10);
|
|
|
|
|
black_plane->rotation = angleAxis(3.141529f, glm::vec3(1.0f, 0.0f, 0.0f));
|
|
|
|
|
|
2022-04-24 09:57:52 +03:00
|
|
|
auto left_plane = std::make_shared<mesh_node>("left plane");
|
2022-04-24 07:15:30 +03:00
|
|
|
left_plane->mesh_ = demo_data::meshes[2];
|
|
|
|
|
left_plane->material_ = demo_data::materials[1];
|
|
|
|
|
left_plane->position = glm::vec3(-5, 5, 0);
|
|
|
|
|
left_plane->scale = glm::vec3(10);
|
|
|
|
|
left_plane->rotation = angleAxis(-3.141529f / 2.0f, glm::vec3(0.0f, 1.0f, 0.0f));
|
|
|
|
|
|
2022-04-24 09:57:52 +03:00
|
|
|
auto right_plane = std::make_shared<mesh_node>("right plane");
|
2022-04-24 07:15:30 +03:00
|
|
|
right_plane->mesh_ = demo_data::meshes[2];
|
|
|
|
|
right_plane->material_ = demo_data::materials[1];
|
|
|
|
|
right_plane->position = glm::vec3(5, 5, 0);
|
|
|
|
|
right_plane->scale = glm::vec3(10);
|
|
|
|
|
right_plane->rotation = angleAxis(3.141529f / 2.0f, glm::vec3(0.0f, 1.0f, 0.0f));
|
|
|
|
|
|
2022-04-24 09:57:52 +03:00
|
|
|
auto bigSphere = make_shared<mesh_node>("big sphere");
|
2022-04-24 07:15:30 +03:00
|
|
|
bigSphere->mesh_ = demo_data::meshes[0];
|
2022-04-24 09:57:52 +03:00
|
|
|
bigSphere->material_ = demo_data::materials[1];
|
2022-04-24 07:15:30 +03:00
|
|
|
bigSphere->position = glm::vec3(-2, 2, 0);
|
|
|
|
|
bigSphere->scale = glm::vec3(0.8);
|
|
|
|
|
bigSphere->rotation = glm::angleAxis(3.141529f / 2.0f, glm::vec3(1.0f, 0.0f, 0.0f));
|
|
|
|
|
|
|
|
|
|
|
2022-04-24 09:57:52 +03:00
|
|
|
auto lightMeshNode = std::make_shared<mesh_node>("light mesh");
|
2022-04-24 07:15:30 +03:00
|
|
|
lightMeshNode->mesh_ = demo_data::meshes[0];
|
|
|
|
|
lightMeshNode->material_ = demo_data::materials[3];
|
|
|
|
|
lightMeshNode->position = glm::vec3(1, 2, 1);
|
|
|
|
|
lightMeshNode->scale = glm::vec3(0.1);
|
|
|
|
|
|
|
|
|
|
auto camNode = std::make_shared<camera_node>();
|
|
|
|
|
camNode->name = "cam1";
|
|
|
|
|
camNode->position = glm::vec3(0, 2, 5);
|
|
|
|
|
camNode->target = glm::vec3(0, 0, 0);
|
|
|
|
|
camNode->fov = 45;
|
|
|
|
|
|
|
|
|
|
auto lightNode = make_shared<light_node>(light_type::spot);
|
|
|
|
|
lightNode->name = "light1";
|
|
|
|
|
lightNode->position = glm::vec3(-5, 5, 0);
|
|
|
|
|
lightNode->spot_target = glm::vec3(0, 0, 0);
|
|
|
|
|
lightNode->spot_cutoff = 50.0f;
|
|
|
|
|
lightNode->spot_exponent = 16.0f;
|
|
|
|
|
lightNode->ambient = glm::vec4(0.1, 0.1, 0.1, 1.0);
|
|
|
|
|
lightNode->diffuse = glm::vec4(0.5, 1.0, 1.0, 1.0);
|
|
|
|
|
lightNode->specular = glm::vec4(0.0, 0.8, 0.1, 1.0);
|
|
|
|
|
|
|
|
|
|
auto lightNode2 = make_shared<light_node>(light_type::spot);
|
|
|
|
|
lightNode2->name = "light2";
|
|
|
|
|
lightNode2->position = glm::vec3(5, 5, 0);
|
|
|
|
|
lightNode2->spot_target = glm::vec3(0, 0, 0);
|
|
|
|
|
lightNode2->spot_cutoff = 50.0f;
|
|
|
|
|
lightNode2->spot_exponent = 16.0f;
|
|
|
|
|
lightNode2->ambient = glm::vec4(0.1, 0.1, 0.1, 1.0);
|
|
|
|
|
lightNode2->diffuse = glm::vec4(1.0, 0.5, 1.0, 1.0);
|
|
|
|
|
lightNode2->specular = glm::vec4(0.0, 0.8, 0.1, 1.0);
|
|
|
|
|
|
|
|
|
|
scene1->tree->add(ground_plane);
|
|
|
|
|
scene1->tree->add(black_plane);
|
|
|
|
|
scene1->tree->add(left_plane);
|
|
|
|
|
scene1->tree->add(right_plane);
|
|
|
|
|
|
|
|
|
|
scene1->tree->add(smallSphere);
|
|
|
|
|
scene1->tree->add(bigSphere);
|
|
|
|
|
scene1->tree->add(lightMeshNode);
|
|
|
|
|
|
|
|
|
|
scene1->tree->add(camNode);
|
|
|
|
|
|
|
|
|
|
scene1->tree->add(lightNode);
|
|
|
|
|
scene1->tree->add(lightNode2);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------------------------
|
|
|
|
|
// Run demo
|
|
|
|
|
// --------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
|
|
|
|
|
|
|
|
|
timer timer1;
|
|
|
|
|
while (!peripherals.should_close() && timer1.seconds_since_start() < DEMO_LENGTH_IN_SECONDS) {
|
|
|
|
|
double elapsedSeconds = timer1.seconds_since_start();
|
|
|
|
|
|
2022-04-24 09:00:55 +03:00
|
|
|
bigSphere->mesh_ = mesh_generator::extrude(mesh_generator::sphere(50, 50), {200, 201, 100, 101, 400, 401}, 0.05,
|
|
|
|
|
(int) ((sin(elapsedSeconds) + 0.5) * 40));
|
|
|
|
|
|
|
|
|
|
smallSphere->position = glm::vec3(0, sin(2 * M_PI * 0.13 * elapsedSeconds) * 2.0 + 0.5, 0);
|
|
|
|
|
// meshNode->position = glm::vec3(0, 0.001, 0);
|
|
|
|
|
// camNode->target = glm::vec3(0, 0.0001, 0);
|
|
|
|
|
// camNode->position = glm::vec3(0, 5, -10);
|
|
|
|
|
lightNode2->position = glm::vec3(5 * sin(2 * M_PI * 0.15 * elapsedSeconds), 2,
|
|
|
|
|
5 * cos(2 * M_PI * 0.15 * elapsedSeconds));
|
|
|
|
|
lightNode->position = glm::vec3(5 * cos(2 * M_PI * 0.75 * elapsedSeconds), 2,
|
|
|
|
|
5 * sin(2 * M_PI * 0.75 * elapsedSeconds));
|
|
|
|
|
|
|
|
|
|
lightMeshNode->position = lightNode2->position;
|
|
|
|
|
|
|
|
|
|
bigSphere->rotation *= angleAxis((float) (M_PI / 4.0 * timer1.lap()), normalize(glm::vec3(0.2, 0.5, 0.3)));
|
|
|
|
|
|
2022-04-24 07:15:30 +03:00
|
|
|
|
|
|
|
|
demoPartClear.process(demoPartClear.normalizeTime(elapsedSeconds));
|
|
|
|
|
demoPartScene.process(demoPartScene.normalizeTime(elapsedSeconds));
|
2022-04-23 14:48:42 +03:00
|
|
|
|
2022-04-23 16:41:33 +03:00
|
|
|
peripherals.swap_buffers();
|
|
|
|
|
peripherals.poll_events();
|
|
|
|
|
}
|
2022-04-23 14:48:42 +03:00
|
|
|
}
|