Fixed heissenbug caused by quat initialization and added sound server.
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
#include <memory>
|
||||
#include <iterator>
|
||||
|
||||
#include "imgui.h"
|
||||
#include "imgui_impl_glfw.h"
|
||||
@@ -7,6 +8,8 @@
|
||||
#include "peripherals_glfw.h"
|
||||
#include "demo/demo_engine.h"
|
||||
#include "timer.h"
|
||||
#include "audio/sound_server.h"
|
||||
#include <bitset>
|
||||
|
||||
using namespace acidrain;
|
||||
using namespace std;
|
||||
@@ -15,30 +18,30 @@ INITIALIZE_EASYLOGGINGPP
|
||||
|
||||
int main() {
|
||||
acidrain::peripherals_glfw peripherals;
|
||||
peripherals.init();
|
||||
peripherals.init(demo_data::screen_width, demo_data::screen_height, "acidrain", false);
|
||||
LOG(INFO) << "peripherals initialized";
|
||||
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
|
||||
const float DEMO_LENGTH_IN_SECONDS = 100;
|
||||
const float DEMO_LENGTH_IN_SECONDS = 1000;
|
||||
|
||||
// --------------------------------------------------------------------------------------
|
||||
// Load resources
|
||||
// --------------------------------------------------------------------------------------
|
||||
|
||||
acidrain::texture_generator tg(256, 256);
|
||||
tg.brick(0, 50, 20, 4, glm::vec4(1), glm::vec4(0));
|
||||
// tg.checker_board(0, 50, glm::vec4(1), glm::vec4(0));
|
||||
// tg.brick(0, 50, 20, 4, glm::vec4(1), glm::vec4(0));
|
||||
tg.checker_board(0, 50, glm::vec4(1), glm::vec4(0));
|
||||
|
||||
shared_ptr<mesh> affectedSphere = mesh_generator::sphere(50, 50);
|
||||
map_transform(affectedSphere, tg, 0, 0, 0.2f);
|
||||
calculate_normals(*affectedSphere.get());
|
||||
shared_ptr<mesh> affected_sphere = mesh_generator::sphere(50, 50);
|
||||
map_transform(affected_sphere, tg, 0, 0, 0.2f);
|
||||
calculate_normals(*affected_sphere);
|
||||
|
||||
// affectedSphere = mesh_generator::cog(0.2, 0.5, 50, 4, 0.1, 0.2, 0.2, 0.1);
|
||||
|
||||
demo_data::meshes.push_back(affectedSphere);
|
||||
demo_data::meshes.push_back(affected_sphere);
|
||||
demo_data::meshes.push_back(mesh_generator::sphere(3, 3));
|
||||
demo_data::meshes.push_back(mesh_generator::grid(30, 30));
|
||||
demo_data::meshes.push_back(mesh_generator::grid(1, 1));
|
||||
demo_data::meshes.push_back(mesh_generator::cube());
|
||||
|
||||
auto mat = std::make_shared<material>();
|
||||
@@ -49,21 +52,21 @@ int main() {
|
||||
mat->shininess = 200;
|
||||
mat->cast_shadows = true;
|
||||
|
||||
auto *textureGenerator1 = new texture_generator(256, 256);
|
||||
// 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);
|
||||
auto *texgen = new texture_generator(256, 256);
|
||||
mat->textures[texture_role::diffuse] = texgen->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);
|
||||
|
||||
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->textures[texture_role::diffuse] = texgen->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);
|
||||
@@ -102,14 +105,14 @@ int main() {
|
||||
// Set up demo parts
|
||||
// --------------------------------------------------------------------------------------
|
||||
|
||||
DemoPartClear demoPartClear;
|
||||
demoPartClear.startTime = 0;
|
||||
demoPartClear.endTime = DEMO_LENGTH_IN_SECONDS;
|
||||
demo_part_clear demoPartClear;
|
||||
demoPartClear.start_time = 0;
|
||||
demoPartClear.end_time = 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;
|
||||
demo_part_scene demoPartScene;
|
||||
demoPartScene.start_time = 0;
|
||||
demoPartScene.end_time = DEMO_LENGTH_IN_SECONDS;
|
||||
demoPartScene.cameraName = "cam1";
|
||||
demoPartScene.lightName = "light1";
|
||||
|
||||
@@ -135,21 +138,21 @@ int main() {
|
||||
back_plane->material_ = demo_data::materials[1];
|
||||
back_plane->position = glm::vec3(0, 5, -5);
|
||||
back_plane->scale = glm::vec3(10);
|
||||
back_plane->rotation = angleAxis(3.141529f, glm::vec3(1.0f, 0.0f, 0.0f));
|
||||
back_plane->rotation = glm::angleAxis(3.141529f, glm::vec3(1.0f, 0.0f, 0.0f));
|
||||
|
||||
auto left_plane = std::make_shared<mesh_node>("left plane");
|
||||
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));
|
||||
left_plane->rotation = glm::angleAxis(-3.141529f / 2.0f, glm::vec3(0.0f, 1.0f, 0.0f));
|
||||
|
||||
auto right_plane = std::make_shared<mesh_node>("right plane");
|
||||
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));
|
||||
right_plane->rotation = glm::angleAxis(3.141529f / 2.0f, glm::vec3(0.0f, 1.0f, 0.0f));
|
||||
|
||||
auto bigSphere = make_shared<mesh_node>("big sphere");
|
||||
bigSphere->mesh_ = demo_data::meshes[0];
|
||||
@@ -178,7 +181,7 @@ int main() {
|
||||
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->diffuse = glm::vec4(0.1, 0.3, 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);
|
||||
@@ -188,8 +191,8 @@ int main() {
|
||||
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);
|
||||
lightNode2->diffuse = glm::vec4(1.0, 0.5, 0.3, 1.0);
|
||||
lightNode2->specular = glm::vec4(1.0, 0.8, 0.1, 1.0);
|
||||
|
||||
scene1->tree->add(ground_plane);
|
||||
scene1->tree->add(back_plane);
|
||||
@@ -213,14 +216,15 @@ int main() {
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
|
||||
|
||||
IMGUI_CHECKVERSION();
|
||||
ImGui::CreateContext();
|
||||
ImGuiIO& io = ImGui::GetIO(); (void)io;
|
||||
ImGui::StyleColorsDark();
|
||||
|
||||
// Setup Platform/Renderer backends
|
||||
ImGui_ImplGlfw_InitForOpenGL(((peripherals_glfw*)&peripherals)->get_window(), true);
|
||||
ImGui_ImplOpenGL3_Init("#version 150");
|
||||
// IMGUI_CHECKVERSION();
|
||||
// ImGui::CreateContext();
|
||||
// ImGuiIO& io = ImGui::GetIO();
|
||||
// (void) io;
|
||||
// ImGui::StyleColorsDark();
|
||||
//
|
||||
// // Setup Platform/Renderer backends
|
||||
// ImGui_ImplGlfw_InitForOpenGL(((peripherals_glfw *) &peripherals)->get_window(), true);
|
||||
// ImGui_ImplOpenGL3_Init("#version 150");
|
||||
|
||||
timer timer1;
|
||||
ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f);
|
||||
@@ -228,56 +232,57 @@ int main() {
|
||||
bool show_another_window = false;
|
||||
|
||||
while (!peripherals.should_close() && timer1.seconds_since_start() < DEMO_LENGTH_IN_SECONDS) {
|
||||
ImGui_ImplOpenGL3_NewFrame();
|
||||
ImGui_ImplGlfw_NewFrame();
|
||||
ImGui::NewFrame();
|
||||
|
||||
{
|
||||
static float f = 0.0f;
|
||||
static int counter = 0;
|
||||
|
||||
ImGui::Begin("Hello, world!"); // Create a window called "Hello, world!" and append into it.
|
||||
|
||||
ImGui::Text("This is some useful text."); // Display some text (you can use a format strings too)
|
||||
ImGui::Checkbox("Demo Window", &show_demo_window); // Edit bools storing our window open/close state
|
||||
ImGui::Checkbox("Another Window", &show_another_window);
|
||||
|
||||
ImGui::SliderFloat("float", &f, 0.0f, 1.0f); // Edit 1 float using a slider from 0.0f to 1.0f
|
||||
ImGui::ColorEdit3("clear color", (float*)&clear_color); // Edit 3 floats representing a color
|
||||
|
||||
if (ImGui::Button("Button")) // Buttons return true when clicked (most widgets return true when edited/activated)
|
||||
counter++;
|
||||
ImGui::SameLine();
|
||||
ImGui::Text("counter = %d", counter);
|
||||
|
||||
ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / ImGui::GetIO().Framerate, ImGui::GetIO().Framerate);
|
||||
ImGui::End();
|
||||
}
|
||||
// ImGui_ImplOpenGL3_NewFrame();
|
||||
// ImGui_ImplGlfw_NewFrame();
|
||||
// ImGui::NewFrame();
|
||||
//
|
||||
// {
|
||||
// static float f = 0.0f;
|
||||
// static int counter = 0;
|
||||
//
|
||||
// ImGui::Begin("Hello, world!"); // Create a window called "Hello, world!" and append into it.
|
||||
//
|
||||
// ImGui::Text("This is some useful text."); // Display some text (you can use a format strings too)
|
||||
// ImGui::Checkbox("Demo Window", &show_demo_window); // Edit bools storing our window open/close state
|
||||
// ImGui::Checkbox("Another Window", &show_another_window);
|
||||
//
|
||||
// ImGui::SliderFloat("float", &f, 0.0f, 1.0f); // Edit 1 float using a slider from 0.0f to 1.0f
|
||||
// ImGui::ColorEdit3("clear color", (float *) &clear_color); // Edit 3 floats representing a color
|
||||
//
|
||||
// if (ImGui::Button(
|
||||
// "Button")) // Buttons return true when clicked (most widgets return true when edited/activated)
|
||||
// counter++;
|
||||
// ImGui::SameLine();
|
||||
// ImGui::Text("counter = %d", counter);
|
||||
//
|
||||
// ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / ImGui::GetIO().Framerate, ImGui::GetIO().Framerate);
|
||||
// ImGui::End();
|
||||
// }
|
||||
|
||||
|
||||
double elapsedSeconds = timer1.seconds_since_start();
|
||||
auto elapsed_seconds = timer1.seconds_since_start();
|
||||
bigSphere->mesh_ = mesh_generator::extrude(mesh_generator::sphere(50, 50), {200, 201, 100, 101, 400, 401}, 0.05,
|
||||
(int) ((sin(elapsedSeconds) + 0.5) * 40));
|
||||
(int) ((sinf(elapsed_seconds) + 0.5f) * 40));
|
||||
|
||||
smallSphere->position = glm::vec3(0, sin(2 * M_PI * 0.13 * elapsedSeconds) * 2.0 + 0.5, 0);
|
||||
smallSphere->position = glm::vec3(0, sin(2 * M_PI * 0.13 * elapsed_seconds) * 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.05 * elapsedSeconds), 2,
|
||||
5 * cos(2 * M_PI * 0.05 * elapsedSeconds));
|
||||
lightNode->position = glm::vec3(5 * cos(2 * M_PI * 0.75 * elapsedSeconds), 2,
|
||||
5 * sin(2 * M_PI * 0.75 * elapsedSeconds));
|
||||
lightNode2->position = glm::vec3(5 * sin(2 * M_PI * 0.05 * elapsed_seconds), 2,
|
||||
5 * cos(2 * M_PI * 0.05 * elapsed_seconds));
|
||||
lightNode->position = glm::vec3(5 * cos(2 * M_PI * 0.75 * elapsed_seconds), 2,
|
||||
5 * sin(2 * M_PI * 0.75 * elapsed_seconds));
|
||||
|
||||
lightMeshNode->position = lightNode2->position;
|
||||
|
||||
bigSphere->rotation *= angleAxis((float) (M_PI / 4.0 * timer1.lap()), normalize(glm::vec3(0.2, 0.5, 0.3)));
|
||||
|
||||
|
||||
demoPartClear.process(demoPartClear.normalizeTime(elapsedSeconds));
|
||||
demoPartScene.process(demoPartScene.normalizeTime(elapsedSeconds));
|
||||
demoPartClear.process(demoPartClear.normalize_time(elapsed_seconds));
|
||||
demoPartScene.process(demoPartScene.normalize_time(elapsed_seconds));
|
||||
|
||||
ImGui::Render();
|
||||
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
|
||||
// ImGui::Render();
|
||||
// ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
|
||||
|
||||
peripherals.swap_buffers();
|
||||
peripherals.poll_events();
|
||||
|
||||
Reference in New Issue
Block a user