|
| 1 | +#include "arrow.hpp" |
| 2 | +#include "create_path.hpp" |
| 3 | +#include "timed_output.hpp" |
| 4 | +#include "nugget/instance.hpp" |
| 5 | +#include "arrow_parameters.hpp" |
| 6 | +#include "graphics/shader/scoped.hpp" |
| 7 | +#include "graphics/shader/object.hpp" |
| 8 | +#include "graphics/camera/object.hpp" |
| 9 | +#include "physics/vec2.hpp" |
| 10 | +#include "physics/vec3.hpp" |
| 11 | +#include "json/parse_vector.hpp" |
| 12 | +#include "model/scoped.hpp" |
| 13 | +#include <sge/systems/instance.hpp> |
| 14 | +#include <sge/parse/json/array.hpp> |
| 15 | +#include <sge/parse/json/find_member_exn.hpp> |
| 16 | +#include <sge/parse/json/string.hpp> |
| 17 | +#include <sge/parse/json/object.hpp> |
| 18 | +#include <sge/model/loader.hpp> |
| 19 | +#include <sge/image/create_texture.hpp> |
| 20 | +#include <sge/renderer/texture.hpp> |
| 21 | +#include <sge/renderer/filter/trilinear.hpp> |
| 22 | +#include <sge/renderer/resource_flags_none.hpp> |
| 23 | +#include <fcppt/math/matrix/arithmetic.hpp> |
| 24 | +#include <fcppt/math/matrix/translation.hpp> |
| 25 | +#include <fcppt/math/matrix/rotation_y.hpp> |
| 26 | +#include <fcppt/math/vector/length.hpp> |
| 27 | +#include <fcppt/math/vector/dot.hpp> |
| 28 | +#include <fcppt/math/vector/basic_impl.hpp> |
| 29 | +#include <fcppt/math/vector/arithmetic.hpp> |
| 30 | +#include <fcppt/math/vector/structure_cast.hpp> |
| 31 | +#include <fcppt/math/vector/normalize.hpp> |
| 32 | +#include <fcppt/math/vector/output.hpp> |
| 33 | +#include <fcppt/math/vector/angle_between.hpp> |
| 34 | +#include <fcppt/io/cout.hpp> |
| 35 | +#include <fcppt/text.hpp> |
| 36 | + |
| 37 | +insula::arrow::arrow( |
| 38 | + arrow_parameters const ¶ms) |
| 39 | +: |
| 40 | + model_( |
| 41 | + params.systems.md3_loader()->load( |
| 42 | + create_path( |
| 43 | + sge::parse::json::find_member_exn<sge::parse::json::string>( |
| 44 | + params.json.members, |
| 45 | + FCPPT_TEXT("model")), |
| 46 | + FCPPT_TEXT("models")), |
| 47 | + sge::model::load_flags::switch_yz), |
| 48 | + params.systems.renderer()), |
| 49 | + texture_( |
| 50 | + sge::image::create_texture( |
| 51 | + create_path( |
| 52 | + sge::parse::json::find_member_exn<sge::parse::json::string>( |
| 53 | + params.json.members, |
| 54 | + FCPPT_TEXT("texture")), |
| 55 | + FCPPT_TEXT("textures")), |
| 56 | + params.systems.renderer(), |
| 57 | + params.systems.image_loader(), |
| 58 | + sge::renderer::filter::trilinear, |
| 59 | + sge::renderer::resource_flags::none)), |
| 60 | + model_shader_( |
| 61 | + params.model_shader), |
| 62 | + renderer_( |
| 63 | + params.systems.renderer()), |
| 64 | + camera_( |
| 65 | + params.camera), |
| 66 | + nuggets_( |
| 67 | + params.nuggets), |
| 68 | + offset_( |
| 69 | + json::parse_vector<graphics::scalar,3,sge::parse::json::float_type>( |
| 70 | + sge::parse::json::find_member_exn<sge::parse::json::array>( |
| 71 | + params.json.members, |
| 72 | + FCPPT_TEXT("offset")))) |
| 73 | +{ |
| 74 | +} |
| 75 | + |
| 76 | +void |
| 77 | +insula::arrow::render() |
| 78 | +{ |
| 79 | + model_shader_.update_texture( |
| 80 | + "texture", |
| 81 | + texture_); |
| 82 | + |
| 83 | + graphics::shader::scoped scoped_shader( |
| 84 | + model_shader_); |
| 85 | + |
| 86 | + model::scoped scoped_model( |
| 87 | + renderer_, |
| 88 | + model_); |
| 89 | + |
| 90 | + physics::vec2 const |
| 91 | + forward( |
| 92 | + camera_.gizmo().forward().x(), |
| 93 | + camera_.gizmo().forward().z()); |
| 94 | + |
| 95 | + physics::vec3 const diff = |
| 96 | + nuggets_.closest_nugget( |
| 97 | + fcppt::math::vector::structure_cast<physics::vec3>( |
| 98 | + camera_.gizmo().position())) - |
| 99 | + fcppt::math::vector::structure_cast<physics::vec3>( |
| 100 | + camera_.gizmo().position()); |
| 101 | + |
| 102 | + physics::vec2 const |
| 103 | + to_nugget( |
| 104 | + diff.x(), |
| 105 | + diff.z()); |
| 106 | + |
| 107 | + model_shader_.set_uniform( |
| 108 | + "mvp", |
| 109 | + camera_.perspective() * |
| 110 | + fcppt::math::matrix::translation( |
| 111 | + offset_) * |
| 112 | + // NOTE: Yes, this is relative to the camera, so not perfectly |
| 113 | + // alright, I'll have to fix that some day |
| 114 | + fcppt::math::matrix::rotation_y( |
| 115 | + std::acos( |
| 116 | + fcppt::math::vector::dot( |
| 117 | + to_nugget, |
| 118 | + forward)/ |
| 119 | + (length(to_nugget)*length(forward)) |
| 120 | + /* *fcppt::math::vector::angle_between<graphics::scalar>( |
| 121 | + to_nugget, |
| 122 | + forward)*/)) |
| 123 | + /* |
| 124 | + fcppt::math::matrix::rotation_y( |
| 125 | + static_cast<graphics::scalar>( |
| 126 | + std::acos( |
| 127 | + fcppt::math::vector::dot( |
| 128 | + fcppt::math::vector::structure_cast<physics::vec3>( |
| 129 | + camera_.gizmo().forward()), |
| 130 | + fcppt::math::vector::normalize( |
| 131 | + fcppt::math::vector::structure_cast<physics::vec3>( |
| 132 | + camera_.gizmo().position()) - |
| 133 | + nuggets_.closest_nugget( |
| 134 | + fcppt::math::vector::structure_cast<physics::vec3>( |
| 135 | + camera_.gizmo().position())))))))*/); |
| 136 | + |
| 137 | + model_.render(); |
| 138 | +} |
| 139 | + |
| 140 | +insula::arrow::~arrow() {} |
0 commit comments