Skip to content

Commit 6a3b7c1

Browse files
author
phillemann
committed
First version of arrow
1 parent 691f21c commit 6a3b7c1

19 files changed

+338
-12
lines changed

CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ FILE(GLOB_RECURSE physics_files physics/*)
7878
FILE(GLOB_RECURSE nugget_files nugget/*)
7979
FILE(GLOB_RECURSE model_files model/*)
8080
FILE(GLOB_RECURSE json_files json/*)
81-
FILE(GLOB base_files media_path.cpp input_delegator.cpp create_path.cpp vehicle_input.cpp music_controller.cpp machine.cpp application_title.cpp sound_controller.cpp exception.cpp help_needed.cpp create_variables_map.cpp generate_nuggets.cpp random_flat_point.cpp game_cli_options.cpp random_seed.cpp scoped_machine.cpp timed_output.cpp turn_timer.cpp milliseconds_to_string.cpp model_backend.cpp model_instance.cpp static_model_instance.cpp ghost_instance.cpp parse_json_config.cpp)
81+
FILE(GLOB base_files media_path.cpp input_delegator.cpp create_path.cpp vehicle_input.cpp music_controller.cpp machine.cpp application_title.cpp sound_controller.cpp exception.cpp help_needed.cpp create_variables_map.cpp generate_nuggets.cpp random_flat_point.cpp game_cli_options.cpp random_seed.cpp scoped_machine.cpp timed_output.cpp turn_timer.cpp milliseconds_to_string.cpp model_backend.cpp model_instance.cpp static_model_instance.cpp ghost_instance.cpp parse_json_config.cpp arrow.cpp)
8282

8383
SET_SOURCE_FILES_PROPERTIES(
8484
media_path.cpp

arrow.cpp

+140
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
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 &params)
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() {}

arrow.hpp

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#ifndef INSULA_ARROW_HPP_INCLUDED
2+
#define INSULA_ARROW_HPP_INCLUDED
3+
4+
#include "arrow_parameters_fwd.hpp"
5+
#include "nugget/instance_fwd.hpp"
6+
#include "model/object.hpp"
7+
#include "graphics/shader/object_fwd.hpp"
8+
#include "graphics/camera/object_fwd.hpp"
9+
#include "graphics/vec3.hpp"
10+
#include <sge/renderer/device_ptr.hpp>
11+
#include <sge/renderer/texture_ptr.hpp>
12+
#include <fcppt/math/vector/basic_impl.hpp>
13+
14+
namespace insula
15+
{
16+
class arrow
17+
{
18+
public:
19+
arrow(arrow const &) = delete;
20+
arrow &operator=(arrow const &) = delete;
21+
22+
explicit
23+
arrow(
24+
arrow_parameters const &);
25+
26+
void
27+
render();
28+
29+
~arrow();
30+
private:
31+
model::object model_;
32+
sge::renderer::texture_ptr texture_;
33+
graphics::shader::object &model_shader_;
34+
sge::renderer::device_ptr renderer_;
35+
graphics::camera::object &camera_;
36+
nugget::instance const &nuggets_;
37+
graphics::vec3 const offset_;
38+
};
39+
}
40+
41+
#endif

arrow_parameters.hpp

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#ifndef INSULA_ARROW_PARAMETERS_HPP_INCLUDED
2+
#define INSULA_ARROW_PARAMETERS_HPP_INCLUDED
3+
4+
#include "nugget/instance_fwd.hpp"
5+
#include "graphics/shader/object_fwd.hpp"
6+
#include <sge/systems/instance_fwd.hpp>
7+
#include <sge/parse/json/object.hpp>
8+
9+
namespace insula
10+
{
11+
class arrow_parameters
12+
{
13+
public:
14+
sge::systems::instance const &systems;
15+
sge::parse::json::object json;
16+
graphics::shader::object &model_shader;
17+
graphics::camera::object &camera;
18+
nugget::instance const &nuggets;
19+
20+
explicit
21+
arrow_parameters(
22+
sge::systems::instance const &systems,
23+
sge::parse::json::object const &json,
24+
graphics::shader::object &model_shader,
25+
graphics::camera::object &camera,
26+
nugget::instance const &nuggets)
27+
:
28+
systems(systems),
29+
json(json),
30+
model_shader(model_shader),
31+
camera(camera),
32+
nuggets(nuggets)
33+
{
34+
}
35+
};
36+
}
37+
38+
#endif

arrow_parameters_fwd.hpp

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#ifndef INSULA_ARROW_PARAMETERS_FWD_HPP_INCLUDED
2+
#define INSULA_ARROW_PARAMETERS_FWD_HPP_INCLUDED
3+
4+
namespace insula
5+
{
6+
class arrow_parameters;
7+
}
8+
9+
#endif

media/config.json

+7
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,13 @@
106106
"size" : 30
107107
},
108108

109+
"arrow" :
110+
{
111+
"model" : "arrow.md3",
112+
"texture" : "arrow.png",
113+
"offset" : [0.0,2.0,-3.0]
114+
},
115+
109116
"music" :
110117
{
111118
"events" :
File renamed without changes.
File renamed without changes.

model/scoped.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#ifndef INSULA_MODEL_SCOPED_HPP_INCLUDED
2+
23
#define INSULA_MODEL_SCOPED_HPP_INCLUDED
34

45
#include "object_fwd.hpp"

notizen.org

+9-5
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ Hierzu z.B. cgal
184184
** TODO Präfixe in config.json auf Sektionen in json abbilden
185185
** TODO fcppt::assign durch initializer_list ersetzen
186186
** TODO height_map und water mit parameters-Klassen ausstatten
187+
** TODO Die Nuggets sollten sich schön drehen
187188
* Aktivitäten
188189
** TODO Shadow Maps [1/5]
189190
*** DONE Neues uniform-System aufsetzen
@@ -252,18 +253,21 @@ noch überlegen.
252253
** TODO Musiklautstärke muss einstellbar sein
253254
** TODO Mehr Musik
254255
** TODO Konkretes Level bauen, was man auch ausliefern kann
255-
** TODO Nuggets aus game_inner rausziehen
256-
** TODO "Nugget-Indikatoren" einbauen
257256
** TODO Persistente Konsolenhistory
258257
** TODO Partikelsystem
259-
** TODO random_point erweitern
258+
** TODO Looping von Musik fixen
259+
Man kann bei Streamingsounds loop einstellen, das funzt aber nicht richtig
260+
** DONE Nuggets aus game_inner rausziehen
261+
CLOSED: [2010-09-17 Fri 19:40]
262+
** DONE "Nugget-Indikatoren" einbauen
263+
CLOSED: [2010-09-17 Fri 19:40]
264+
** DONE random_point erweitern
265+
CLOSED: [2010-09-17 Fri 19:40]
260266
Die Funktion sollte eine =steepness_range= bekommen (also ein
261267
Intervall in $[0,1]$) und generiert dann mit Hilfe des normalisierten
262268
Gradienten einen Punkt mit dieser Steilheit. Dei Funktion brauch dazu
263269
den normalisierten Gradienten, d.h. =height_map= muss den zur
264270
Verfügung stellen)
265-
** TODO Looping von Musik fixen
266-
Man kann bei Streamingsounds loop einstellen, das funzt aber nicht richtig
267271
** DONE vehicle::speed_kmh muss relativ zu forward sein
268272
CLOSED: [2010-09-12 Sun 20:10]
269273
** DONE Auto-Culling fixen

nugget/instance.cpp

+32
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,14 @@
1313
#include <fcppt/math/matrix/translation.hpp>
1414
#include <fcppt/math/matrix/basic_impl.hpp>
1515
#include <fcppt/math/vector/structure_cast.hpp>
16+
#include <fcppt/math/vector/length.hpp>
17+
#include <fcppt/math/vector/arithmetic.hpp>
1618
#include <fcppt/algorithm/ptr_container_erase.hpp>
19+
#include <fcppt/assert.hpp>
1720
#include <boost/foreach.hpp>
1821
#include <algorithm>
1922
#include <functional>
23+
#include <limits>
2024

2125
insula::nugget::instance::instance(
2226
manager &_manager,
@@ -118,3 +122,31 @@ insula::nugget::instance::physics_callback(
118122
if (models_.size() == 1)
119123
empty_signal_();
120124
}
125+
126+
insula::physics::vec3 const
127+
insula::nugget::instance::closest_nugget(
128+
physics::vec3 const &ref) const
129+
{
130+
FCPPT_ASSERT(!models_.empty());
131+
132+
physics::scalar min_dist =
133+
std::numeric_limits<physics::scalar>::max();
134+
physics::vec3 min;
135+
136+
BOOST_FOREACH(
137+
static_model_instance const &sm,
138+
models_)
139+
{
140+
physics::scalar const new_dist =
141+
fcppt::math::vector::length(
142+
ref - sm.physics_model().position());
143+
144+
if (new_dist < min_dist)
145+
{
146+
min_dist = new_dist;
147+
min = sm.physics_model().position();
148+
}
149+
}
150+
151+
return min;
152+
}

nugget/instance.hpp

+7
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@
66
#include "../physics/vehicle/object_fwd.hpp"
77
#include "../physics/static_model_fwd.hpp"
88
#include "../static_model_instance.hpp"
9+
#include "../physics/vec3.hpp"
910
#include "empty_callback.hpp"
1011
#include <fcppt/signal/object.hpp>
12+
#include <fcppt/math/vector/basic_impl.hpp>
1113
#include <boost/ptr_container/ptr_vector.hpp>
1214
#include <set>
1315

@@ -29,6 +31,11 @@ class instance
2931

3032
void
3133
update();
34+
35+
// We need this to calculate the arrow's orientation
36+
physics::vec3 const
37+
closest_nugget(
38+
physics::vec3 const &) const;
3239
private:
3340
typedef
3441
boost::ptr_vector<static_model_instance>

nugget/manager.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,11 @@ insula::nugget::manager::manager(
5959
},
6060
std::make_shared<model::object>(
6161
params.systems.md3_loader()->load(
62-
create_path(
63-
sge::parse::json::find_member_exn<sge::parse::json::string>(
64-
params.json.members,
65-
FCPPT_TEXT("model")),
66-
FCPPT_TEXT("models/props")),
62+
create_path(
63+
sge::parse::json::find_member_exn<sge::parse::json::string>(
64+
params.json.members,
65+
FCPPT_TEXT("model")),
66+
FCPPT_TEXT("models/props")),
6767
sge::model::load_flags::switch_yz),
6868
params.systems.renderer())),
6969
shape_(

0 commit comments

Comments
 (0)