Browse Source

Add camera tool

master
C. J. Howard 3 years ago
parent
commit
22ea65727c
3 changed files with 77 additions and 1 deletions
  1. +27
    -0
      src/game/bootloader.cpp
  2. +2
    -0
      src/game/context.hpp
  3. +48
    -1
      src/game/states/forage.cpp

+ 27
- 0
src/game/bootloader.cpp View File

@ -673,6 +673,23 @@ void setup_scenes(game::context* ctx)
ctx->splash_billboard->set_translation({0.0f, 0.0f, 0.0f}); ctx->splash_billboard->set_translation({0.0f, 0.0f, 0.0f});
ctx->splash_billboard->update_tweens(); ctx->splash_billboard->update_tweens();
// Create camera flash billboard
material* flash_material = new material();
flash_material->set_shader_program(ctx->resource_manager->load<gl::shader_program>("ui-element-untextured.glsl"));
auto flash_tint = flash_material->add_property<float4>("tint");
flash_tint->set_value(float4{1, 1, 1, 1});
//flash_tint->set_tween_interpolator(ease<float4>::out_quad);
flash_material->set_flags(MATERIAL_FLAG_TRANSLUCENT);
flash_material->update_tweens();
ctx->camera_flash_billboard = new scene::billboard();
ctx->camera_flash_billboard->set_material(flash_material);
ctx->camera_flash_billboard->set_scale({(float)viewport_dimensions[0] * 0.5f, (float)viewport_dimensions[1] * 0.5f, 1.0f});
ctx->camera_flash_billboard->set_translation({0.0f, 0.0f, 0.0f});
ctx->camera_flash_billboard->update_tweens();
// Create depth debug billboard // Create depth debug billboard
/* /*
material* depth_debug_material = new material(); material* depth_debug_material = new material();
@ -755,6 +772,16 @@ void setup_animation(game::context* ctx)
ctx->ui_scene->add_object(ctx->radial_transition_outer->get_billboard()); ctx->ui_scene->add_object(ctx->radial_transition_outer->get_billboard());
ctx->animator->add_animation(ctx->radial_transition_outer->get_animation()); ctx->animator->add_animation(ctx->radial_transition_outer->get_animation());
// Create camera flash animation
ctx->camera_flash_animation = new animation<float>();
{
ctx->camera_flash_animation->set_interpolator(ease<float>::out_sine);
const float duration = 0.5f;
animation_channel<float>* channel = ctx->camera_flash_animation->add_channel(0);
channel->insert_keyframe({0.0f, 1.0f});
channel->insert_keyframe({duration, 0.0f});
}
// Set material pass tweens // Set material pass tweens
ctx->common_final_pass->set_time_tween(ctx->time_tween); ctx->common_final_pass->set_time_tween(ctx->time_tween);
ctx->surface_sky_pass->set_time_tween(ctx->time_tween); ctx->surface_sky_pass->set_time_tween(ctx->time_tween);

+ 2
- 0
src/game/context.hpp View File

@ -188,6 +188,7 @@ struct context
scene::collection* ui_scene; scene::collection* ui_scene;
scene::camera* ui_camera; scene::camera* ui_camera;
scene::billboard* splash_billboard; scene::billboard* splash_billboard;
scene::billboard* camera_flash_billboard;
// Surface scene // Surface scene
scene::collection* surface_scene; scene::collection* surface_scene;
@ -211,6 +212,7 @@ struct context
screen_transition* radial_transition_outer; screen_transition* radial_transition_outer;
animation<float>* equip_tool_animation; animation<float>* equip_tool_animation;
animation<float>* unequip_tool_animation; animation<float>* unequip_tool_animation;
animation<float>* camera_flash_animation;
// Controls // Controls
input::event_router* input_event_router; input::event_router* input_event_router;

+ 48
- 1
src/game/states/forage.cpp View File

@ -34,6 +34,8 @@
#include "entity/components/constraints/three-dof.hpp" #include "entity/components/constraints/three-dof.hpp"
#include "entity/components/constraint-stack.hpp" #include "entity/components/constraint-stack.hpp"
#include "application.hpp" #include "application.hpp"
#include "utility/timestamp.hpp"
#include "animation/animator.hpp"
namespace game { namespace game {
namespace state { namespace state {
@ -258,8 +260,53 @@ void setup_tools(game::context* ctx)
ctx->entity_registry->assign<entity::component::tool>(tool_eid, tool); ctx->entity_registry->assign<entity::component::tool>(tool_eid, tool);
} }
if (!ctx->entities.count("camera_tool"))
{
entity::id tool_eid = ctx->entity_registry->create();
ctx->entities["camera_tool"] = tool_eid;
entity::component::tool tool;
tool.activated = [ctx]()
{
if (!ctx->camera_flash_animation->is_stopped())
return;
std::string path = ctx->screenshots_path + "antkeeper-" + timestamp() + ".png";
ctx->app->save_frame(path);
material_property<float4>* tint = static_cast<material_property<float4>*>(ctx->camera_flash_billboard->get_material()->get_property("tint"));
tint->set_value({1.0f, 1.0f, 1.0f, 1.0f});
ctx->camera_flash_billboard->get_material()->update_tweens();
ctx->ui_scene->add_object(ctx->camera_flash_billboard);
ctx->camera_flash_animation->set_end_callback
(
[ctx]()
{
ctx->ui_scene->remove_object(ctx->camera_flash_billboard);
}
);
ctx->camera_flash_animation->set_frame_callback
(
[ctx, tint](int channel, const float& opacity)
{
tint->set_value({1.0f, 1.0f, 1.0f, opacity});
}
);
ctx->animator->remove_animation(ctx->camera_flash_animation);
ctx->animator->add_animation(ctx->camera_flash_animation);
ctx->camera_flash_animation->rewind();
ctx->camera_flash_animation->play();
};
ctx->entity_registry->assign<entity::component::tool>(tool_eid, tool);
}
// Set active tool // Set active tool
ctx->entities["active_tool"] = ctx->entities["time_tool"];
ctx->entities["active_tool"] = ctx->entities["camera_tool"];
} }
void setup_controls(game::context* ctx) void setup_controls(game::context* ctx)

Loading…
Cancel
Save