charcoal/Example/MyBuiltinImageScene.cpp

61 lines
1.9 KiB
C++
Raw Normal View History

#include "MyBuiltinImageScene.h"
#include <charcoal/constants.h>
#include <charcoal/TextureFactory.h>
#include <charcoal-builtin/MeshGenerator.h>
#include <charcoal-builtin/TextureGenerator.h>
MyBuiltinImageScene::MyBuiltinImageScene(Application& application)
: image::Scene(application),
m_image(image_loader::load_file(IMAGE_PATH "uber.png")),
m_image_renderable(
meshgenerator::gen_rect_pt<image::Vertex, image::Index>(DRAW_TRIANGLES, (float)m_image.width, (float)m_image.height),
TextureFactory::gen_image_texture(m_image),
texturegenerator::gen_quick_sampler(),
DrawMode::DRAW_TRIANGLES
),
m_camera(m_screen_size),
m_batch(add_batch(&m_image_renderable, 1))
{
add_prerenderable(&m_camera);
set_camera(&m_camera);
}
void MyBuiltinImageScene::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;
{
Poseable2D& pose = m_batch.get_pose(0);
// pose.rotate((float)TAU_1_4 * delta_time); TODO
pose.update_position(vec3(3 * (float)cos(radians), 0.0f, 0.0f));
}
vec3 camera_translation(0.0f, 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;
float camera_rotation = 0.0f;
if (m_input_manager.is_key_down(GLFW_KEY_Z)) camera_rotation += 1;
if (m_input_manager.is_key_down(GLFW_KEY_C)) camera_rotation -= 1;
m_camera.translate(camera_translation * delta_time);
// m_camera.rotate(vec3(0.0f, 0.0f, 1.0f), camera_rotation * (float)TAU_1_8 * delta_time); TODO
}