charcoal/OpenGLEngine/MyBuiltinCubeScene.cpp
elipzer d63f341d89 More builtin abstraction
Got the builtin basicscene to render. For some reason, it seems
like the model matrices are not working correctly. The two shapes
that are supposed to be rendering on screen are not moving around
as they should be.
2018-09-13 19:21:34 -04:00

56 lines
1.5 KiB
C++

#include "MyBuiltinCubeScene.h"
#include "MeshFactory.h"
MyBuiltinCubeScene::MyBuiltinCubeScene(Application& application)
: BasicScene(application),
m_shape(MeshFactory<BasicVertex, BasicIndex>::gen(
DrawMode::DRAW_TRIANGLES,
BasicVertex({ -50.0f, 50.0f, 0.0f }),
BasicVertex({ 50.0f, 150.0f, 0.0f }),
BasicVertex({ -100.0f, -50.0f, 0.0f }),
BasicVertex({ 100.0f, -50.0f, 0.0f })
), DrawMode::DRAW_TRIANGLES),
m_camera(m_screen_size),
m_batch(add_batch(&m_shape, 2))
{
set_camera(&m_camera);
}
void MyBuiltinCubeScene::update(float delta_time, clock_t clock)
{
float brightness;
float radians;
clock_t c;
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)TAU * c / intervals;
{
Poseable& pose = m_batch.get_pose(0);
pose.update_position(vec3(cos(radians) * 50, 0.0f, 0.0f));
}
{
Poseable& pose = m_batch.get_pose(1);
pose.update_position(vec3(0.0f, sin(radians) * 50, 0.0f));
}
vec2 camera_translation(0.0f, 0.0f);
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;
m_camera.translate(camera_translation * delta_time * 100.0f);
}