2018-09-05 23:10:38 +00:00
|
|
|
#include "MyObjectOrientedScene.h"
|
|
|
|
|
2018-09-10 01:20:56 +00:00
|
|
|
#include <cmath>
|
|
|
|
#include <iostream>
|
2018-09-08 04:06:10 +00:00
|
|
|
|
|
|
|
#include "constants.h"
|
|
|
|
|
2018-09-10 01:20:56 +00:00
|
|
|
#include "Util.h"
|
|
|
|
|
2018-09-07 03:22:40 +00:00
|
|
|
#include "DrawMode.h"
|
|
|
|
#include "MeshFactory.h"
|
|
|
|
|
2018-09-10 15:35:02 +00:00
|
|
|
#define FIRST_VERT -50.0f, 50.0f, 0.0f
|
2018-09-11 00:42:50 +00:00
|
|
|
#define SECOND_VERT 50.0f, 150.0f, 0.0f
|
|
|
|
#define THIRD_VERT -100.0f, -50.0f, 0.0f
|
|
|
|
#define FOURTH_VERT 100.0f, -50.0f, 0.0f
|
2018-09-10 15:35:02 +00:00
|
|
|
|
2018-09-08 04:06:10 +00:00
|
|
|
MyObjectOrientedScene::MyObjectOrientedScene(Application& application)
|
|
|
|
: Scene(application),
|
|
|
|
m_shape(MeshFactory<MyBatchTestShaderProgram::Vertex, MyBatchTestShaderProgram::Index>::gen(
|
2018-09-07 03:22:40 +00:00
|
|
|
DrawMode::DRAW_TRIANGLES,
|
2018-09-10 15:35:02 +00:00
|
|
|
MyBatchTestShaderProgram::Vertex(FIRST_VERT),
|
2018-09-11 00:42:50 +00:00
|
|
|
MyBatchTestShaderProgram::Vertex(SECOND_VERT),
|
|
|
|
MyBatchTestShaderProgram::Vertex(THIRD_VERT),
|
|
|
|
MyBatchTestShaderProgram::Vertex(FOURTH_VERT)
|
2018-09-10 01:20:56 +00:00
|
|
|
), DrawMode::DRAW_TRIANGLES),
|
2018-09-08 04:06:10 +00:00
|
|
|
m_batch(&m_shape, 2),
|
2018-09-11 00:42:50 +00:00
|
|
|
m_camera(vec3(m_screen_size, 2.0f))// TODO: change this back to just m_screen_size
|
2018-09-05 23:10:38 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
MyObjectOrientedScene::~MyObjectOrientedScene()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void MyObjectOrientedScene::init()
|
|
|
|
{
|
|
|
|
m_batch.init();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MyObjectOrientedScene::use()
|
|
|
|
{
|
|
|
|
glEnable(GL_DEPTH_TEST);
|
|
|
|
glDepthFunc(GL_LESS);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MyObjectOrientedScene::unuse()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void MyObjectOrientedScene::update(float delta_time, clock_t clock)
|
|
|
|
{
|
2018-09-08 04:06:10 +00:00
|
|
|
float brightness;
|
|
|
|
float radians;
|
|
|
|
|
2018-09-07 15:45:32 +00:00
|
|
|
clock_t c;
|
2018-09-08 04:06:10 +00:00
|
|
|
const clock_t intervals = 512 * CLOCKS_PER_SEC / 100;
|
|
|
|
const clock_t half_interval = 256 * CLOCKS_PER_SEC / 100;
|
|
|
|
c = clock % intervals;
|
|
|
|
if (c < half_interval)
|
|
|
|
brightness = (float)c / half_interval;
|
|
|
|
else
|
|
|
|
brightness = (float)(intervals - c) / half_interval;
|
|
|
|
|
|
|
|
radians = (float)egm::TAU * c / intervals;
|
|
|
|
|
2018-09-07 04:41:34 +00:00
|
|
|
{
|
2018-09-08 04:06:10 +00:00
|
|
|
MyBatchTestShaderProgram::Color& color = m_batch.get_color(0);
|
|
|
|
color.r = brightness;
|
|
|
|
color.g = brightness;
|
|
|
|
color.b = brightness;
|
|
|
|
color.a = 1.0f;
|
|
|
|
|
2018-09-10 15:35:02 +00:00
|
|
|
Poseable& pose = m_batch.get_pose(0);
|
2018-09-11 00:42:50 +00:00
|
|
|
pose.update_position(vec3(cos(radians) * 50, 2.0f, 0.0f));
|
2018-09-07 04:41:34 +00:00
|
|
|
}
|
2018-09-08 04:06:10 +00:00
|
|
|
|
2018-09-07 04:41:34 +00:00
|
|
|
{
|
2018-09-08 04:06:10 +00:00
|
|
|
MyBatchTestShaderProgram::Color& color = m_batch.get_color(1);
|
|
|
|
color.r = 1.0f - brightness;
|
|
|
|
color.g = 1.0f - brightness;
|
|
|
|
color.b = 1.0f - brightness;
|
|
|
|
color.a = 1.0f;
|
|
|
|
|
2018-09-10 15:35:02 +00:00
|
|
|
Poseable& pose = m_batch.get_pose(1);
|
2018-09-11 00:42:50 +00:00
|
|
|
pose.update_position(vec3(-3.0f, -2.0f, 0.0f));
|
2018-09-07 04:41:34 +00:00
|
|
|
}
|
2018-09-05 23:10:38 +00:00
|
|
|
|
2018-09-10 01:20:56 +00:00
|
|
|
vec2 camera_translation(0.0f, 0.0f);
|
2018-09-08 04:06:10 +00:00
|
|
|
|
|
|
|
if (m_input_manager.is_key_down(GLFW_KEY_W)) camera_translation.y += 1;
|
|
|
|
if (m_input_manager.is_key_down(GLFW_KEY_S)) camera_translation.y -= 1;
|
|
|
|
if (m_input_manager.is_key_down(GLFW_KEY_A)) camera_translation.x -= 1;
|
|
|
|
if (m_input_manager.is_key_down(GLFW_KEY_D)) camera_translation.x += 1;
|
|
|
|
|
2018-09-10 04:42:09 +00:00
|
|
|
m_camera.translate(camera_translation * delta_time * 100.0f);
|
2018-09-10 01:20:56 +00:00
|
|
|
|
2018-09-11 00:42:50 +00:00
|
|
|
const mat4& projection = m_camera.get_projection_matrix();
|
|
|
|
const mat4& camera_orientation = m_camera.get_orientation_matrix();
|
2018-09-10 15:35:02 +00:00
|
|
|
const mat4& world_to_view = m_camera.get_world_to_view_matrix();
|
|
|
|
const mat4& orientation = m_batch.get_pose(0).get_orientation_matrix();
|
2018-09-11 00:42:50 +00:00
|
|
|
|
|
|
|
const mat4 mvp = world_to_view * orientation;
|
|
|
|
|
2018-09-10 15:35:02 +00:00
|
|
|
vec4 first_vert(FIRST_VERT, 1.0f);
|
2018-09-11 00:42:50 +00:00
|
|
|
vec4 second_vert(SECOND_VERT, 1.0f);
|
|
|
|
vec4 third_vert(THIRD_VERT, 1.0f);
|
|
|
|
vec4 fourth_vert(FOURTH_VERT, 1.0f);
|
2018-09-10 15:35:02 +00:00
|
|
|
|
2018-09-10 01:20:56 +00:00
|
|
|
Util::set_console_position(0, 0);
|
2018-09-11 00:42:50 +00:00
|
|
|
std::cout << "Projection" << std::endl;
|
|
|
|
Util::print_matrix(projection);
|
2018-09-10 15:35:02 +00:00
|
|
|
std::cout << "World to View" << std::endl;
|
2018-09-11 00:42:50 +00:00
|
|
|
Util::print_matrix(world_to_view);
|
2018-09-10 15:35:02 +00:00
|
|
|
std::cout << "Pose 0 Orientation" << std::endl;
|
2018-09-11 00:42:50 +00:00
|
|
|
Util::print_matrix(orientation);
|
|
|
|
std::cout << "Full Projection Matrix" << std::endl;
|
|
|
|
Util::print_matrix(world_to_view * orientation);
|
|
|
|
std::cout << " First Second Third Fourth " << std::endl;
|
|
|
|
Util::print_matrix(mat4(mvp * first_vert, mvp * second_vert, mvp * third_vert, mvp * fourth_vert));
|
2018-09-07 04:41:34 +00:00
|
|
|
|
|
|
|
// TODO: Make a prerender function or move this to render
|
|
|
|
m_batch.prerender();
|
2018-09-05 23:10:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MyObjectOrientedScene::render()
|
|
|
|
{
|
|
|
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
|
|
|
m_shader_program.use();
|
2018-09-10 15:35:02 +00:00
|
|
|
glUniformMatrix4fv(6, 1, GL_FALSE, &m_camera.get_world_to_view_matrix()[0][0]);
|
2018-09-05 23:10:38 +00:00
|
|
|
m_batch.render();
|
|
|
|
}
|
2018-09-10 15:35:02 +00:00
|
|
|
|
2018-09-11 00:42:50 +00:00
|
|
|
#undef FIRST_VERT
|
|
|
|
#undef SECOND_VERT
|
|
|
|
#undef THIRD_VERT
|
|
|
|
#undef FOURTH_VERT
|