add opengl

This commit is contained in:
Andrey Zimin
2024-05-15 10:57:21 +03:00
parent a0b5e810f7
commit b1d693dbd4
9 changed files with 130 additions and 44 deletions

View File

@@ -55,46 +55,53 @@ namespace sandbox
void opengl_panel::render()
{
// glm::mat4 view = glm::lookAt(cameraPos, cameraPos + cameraFront, cameraUp);
// glm::mat4 projection = glm::perspective(glm::radians(45.0f), 800.0f / 600.0f, 0.1f, 100.0f);
cb_1.use();
// unsigned int viewLoc = glGetUniformLocation(cb_1.get_id(), "view");
// glUniformMatrix4fv(viewLoc, 1, GL_FALSE, glm::value_ptr(view));
// unsigned int projLoc = glGetUniformLocation(cb_1.get_id(), "projection");
// glUniformMatrix4fv(projLoc, 1, GL_FALSE, glm::value_ptr(projection));
m_cb_1.use();
m_cam.update(m_cb_1);
float r = std::sin(glfwGetTime());
float g = std::cos(glfwGetTime());
cb_1.set_color(glm::vec4{ 0.85f, 0.45f, 0.95f, 0.f }); // розовый
cb_1.set_scale(1.0f + std::sin(glfwGetTime()) * 0.2f);
cb_1.set_position(glm::vec3{ 0.f, 0.5, 0.f });
cb_1.render();
m_cb_1.set_color(glm::vec4{ 0.85f, 0.45f, 0.95f, 0.f }); // розовый
m_cb_1.set_scale(1.0f + std::sin(glfwGetTime()) * 0.2f);
m_cb_1.set_position(glm::vec3{ 0.f, 0.5, 0.f });
m_cb_1.render();
r = std::cos(glfwGetTime());
g = std::sin(glfwGetTime());
cb_2.use();
m_cb_2.use();
// unsigned int viewLoc_1 = glGetUniformLocation(cb_2.get_id(), "view");
// glUniformMatrix4fv(viewLoc_1, 1, GL_FALSE, glm::value_ptr(view));
// unsigned int projLoc_1 = glGetUniformLocation(cb_2.get_id(), "projection");
// glUniformMatrix4fv(projLoc_1, 1, GL_FALSE, glm::value_ptr(projection));
m_cam.update(m_cb_2);
cb_2.set_color(glm::vec4{ 0.66f, 0.66f, 0.66f, 0.f }); // серый/белый
cb_2.set_scale(1.0f - std::cos(glfwGetTime()) * 0.2f);
cb_2.set_position(glm::vec3{ r, g, 0.f });
cb_2.render();
m_cb_2.set_color(glm::vec4{ 0.66f, 0.66f, 0.66f, 0.f }); // серый/белый
m_cb_2.set_scale(1.0f - std::cos(glfwGetTime()) * 0.2f);
m_cb_2.set_position(glm::vec3{ r, g, 0.f });
m_cb_2.render();
}
void opengl_panel::on_event(VE::event e)
{
// для событий от перефирии
// if (e.m_type.type() == typeid(VE::event_type))
// {
// auto t = std::any_cast<VE::event_type>(e.m_type);
// if (t != VE::event_type::MOUSE_CURSOR_POSITION)
// hack::log()((int)t);
// }
if (e.m_type.type() == typeid(VE::event_type))
{
auto t = std::any_cast<VE::event_type>(e.m_type);
if (t == VE::event_type::MOUSE_CURSOR_POSITION)
{
auto [pos_x, pos_y] = std::any_cast<std::pair<float, float>>(e.m_data);
m_cam.mouse_callback(pos_x, pos_y);
}
if (t == VE::event_type::KEY_REPEATE || t == VE::event_type::KEY_PRESSED)
{
auto key = std::any_cast<int>(e.m_data);
if (key == VE::key::W)
m_cam.up();
if (key == VE::key::S)
m_cam.down();
if (key == VE::key::A)
m_cam.left();
if (key == VE::key::D)
m_cam.right();
}
}
if (e.m_type.type() == typeid(test_event))
{