-
Notifications
You must be signed in to change notification settings - Fork 0
/
arrow.cpp
120 lines (106 loc) · 3 KB
/
arrow.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#include "arrow.hpp"
#include "create_path.hpp"
#include "timed_output.hpp"
#include "arrow_parameters.hpp"
#include "graphics/shader/scoped.hpp"
#include "graphics/shader/object.hpp"
#include "graphics/camera/object.hpp"
#include "physics/vec2.hpp"
#include "physics/vec3.hpp"
#include "json/parse_vector.hpp"
#include "model/scoped.hpp"
#include <sge/systems/instance.hpp>
#include <sge/parse/json/array.hpp>
#include <sge/parse/json/find_member_exn.hpp>
#include <sge/parse/json/string.hpp>
#include <sge/parse/json/object.hpp>
#include <sge/model/loader.hpp>
#include <sge/image/create_texture.hpp>
#include <sge/renderer/texture.hpp>
#include <sge/renderer/filter/trilinear.hpp>
#include <sge/renderer/resource_flags_none.hpp>
#include <fcppt/math/matrix/translation.hpp>
#include <fcppt/math/matrix/rotation_y.hpp>
#include <fcppt/math/matrix/matrix.hpp>
#include <fcppt/io/cout.hpp>
#include <fcppt/text.hpp>
insula::arrow::arrow(
arrow_parameters const ¶ms)
:
model_(
params.systems.md3_loader()->load(
create_path(
sge::parse::json::find_member_exn<sge::parse::json::string>(
params.json.members,
FCPPT_TEXT("model")),
FCPPT_TEXT("models")),
sge::model::load_flags::switch_yz),
params.systems.renderer()),
texture_(
sge::image::create_texture(
create_path(
sge::parse::json::find_member_exn<sge::parse::json::string>(
params.json.members,
FCPPT_TEXT("texture")),
FCPPT_TEXT("textures")),
params.systems.renderer(),
params.systems.image_loader(),
sge::renderer::filter::trilinear,
sge::renderer::resource_flags::none)),
model_shader_(
params.model_shader),
renderer_(
params.systems.renderer()),
camera_(
params.camera),
position_callback_(
params.callback),
offset_(
json::parse_vector<graphics::scalar,3,sge::parse::json::float_type>(
sge::parse::json::find_member_exn<sge::parse::json::array>(
params.json.members,
FCPPT_TEXT("offset"))))
{
}
void
insula::arrow::render()
{
model_shader_.update_texture(
"texture",
texture_);
graphics::shader::scoped scoped_shader(
model_shader_);
model::scoped scoped_model(
renderer_,
model_);
physics::vec2 const
forward(
camera_.gizmo().forward().x(),
camera_.gizmo().forward().z());
physics::vec3 const diff =
position_callback_();
/*
nuggets_.closest_nugget(
fcppt::math::vector::structure_cast<physics::vec3>(
camera_.gizmo().position())) -
fcppt::math::vector::structure_cast<physics::vec3>(
camera_.gizmo().position());
*/
physics::vec2 const
to_nugget(
diff.x(),
diff.z());
model_shader_.set_uniform(
"mvp",
camera_.perspective() *
fcppt::math::matrix::translation(
offset_) *
// NOTE: Yes, this is relative to the camera, so not perfectly
// alright, I'll have to fix that some day
fcppt::math::matrix::rotation_y(
// See http://www.euclideanspace.com/maths/geometry/trig/inverse/index.htm
(*fcppt::math::vector::atan2(forward)) - (*fcppt::math::vector::atan2(to_nugget))
));
model_.render();
}
insula::arrow::~arrow() {}