Skip to content
Snippets Groups Projects
Commit 1630d6a7 authored by Noé's avatar Noé
Browse files

Added throwing projectiles (balls), just left click

parent 5a937a41
No related branches found
No related tags found
No related merge requests found
#include "ball.hpp" #include "ball.hpp"
#include "terrain.hpp" #include "terrain.hpp"
void ball::initialize() void ball::initialize(int n)
{ {
N = 10; N = n;
pos.resize(N); pos.resize(N);
v.resize(N); v.resize(N);
color.resize(N); color.resize(N);
...@@ -18,6 +18,19 @@ void ball::initialize() ...@@ -18,6 +18,19 @@ void ball::initialize()
} }
} }
void ball::add_ball(vec3 new_pos, vec3 new_dir) {
N++;
pos.resize(N);
v.resize(N);
color.resize(N);
color[N-1] = { rand_interval(0.0f, 1.0f), rand_interval(0.0f, 1.0f), rand_interval(0.0f, 1.0f) };
pos[N-1] = new_pos;
v[N-1] = new_dir;
}
void ball::simulate(float dt, float terrain_length) { void ball::simulate(float dt, float terrain_length) {
for (int i = 0; i < N; i++) { for (int i = 0; i < N; i++) {
if (pos[i][2] < -1 || cgp::abs(pos[i][0]) > terrain_length / 2 || cgp::abs(pos[i][1]) > terrain_length / 2) { if (pos[i][2] < -1 || cgp::abs(pos[i][0]) > terrain_length / 2 || cgp::abs(pos[i][1]) > terrain_length / 2) {
......
...@@ -13,8 +13,9 @@ struct ball { ...@@ -13,8 +13,9 @@ struct ball {
mesh_drawable mesh; mesh_drawable mesh;
void initialize(); void initialize(int n);
void simulate(float dt, float terrain_length); void simulate(float dt, float terrain_length);
void add_ball(vec3 new_pos, vec3 new_dir);
}; };
vec3 terrain_orientation(float x, float y, float terrain_length); vec3 terrain_orientation(float x, float y, float terrain_length);
......
...@@ -93,8 +93,9 @@ void scene_structure::initialize() ...@@ -93,8 +93,9 @@ void scene_structure::initialize()
bird1.initialize_bird(); bird1.initialize_bird();
initialize_mvt(); initialize_mvt();
chain1.initialize(); chain1.initialize();
bouncing.initialize(); bouncing.initialize(10); //10 balls
bat1.initialize_bat(); bat1.initialize_bat();
projectiles.initialize(0);
} }
void scene_structure::initialize_mvt() void scene_structure::initialize_mvt()
...@@ -163,6 +164,7 @@ void scene_structure::display_frame() ...@@ -163,6 +164,7 @@ void scene_structure::display_frame()
display_chain(p); display_chain(p);
display_ball(); display_ball();
display_bat(p); display_bat(p);
display_projectiles();
if (gui.display_wireframe) if (gui.display_wireframe)
...@@ -353,6 +355,16 @@ void scene_structure::display_ball() { ...@@ -353,6 +355,16 @@ void scene_structure::display_ball() {
} }
} }
void scene_structure::display_projectiles() {
projectiles.simulate(timer_chain.scale * 0.01f, terrain_length);
for (int i = 0; i < projectiles.N; i++) {
projectiles.mesh.model.translation = projectiles.pos[i];
projectiles.mesh.material.color = projectiles.color[i];
draw(projectiles.mesh, environment);
}
}
void scene_structure::mouse_move_event() void scene_structure::mouse_move_event()
{ {
if (!inputs.keyboard.shift) if (!inputs.keyboard.shift)
...@@ -360,6 +372,10 @@ void scene_structure::mouse_move_event() ...@@ -360,6 +372,10 @@ void scene_structure::mouse_move_event()
} }
void scene_structure::mouse_click_event() void scene_structure::mouse_click_event()
{ {
if (camera_control.inputs->mouse.click.left){
//std::cout << "ball created";
projectiles.add_ball(camera_control.camera_model.position_camera + 2*camera_control.camera_model.front(), 20*camera_control.camera_model.front());
}
camera_control.action_mouse_click(environment.camera_view); camera_control.action_mouse_click(environment.camera_view);
} }
void scene_structure::keyboard_event() void scene_structure::keyboard_event()
......
...@@ -71,6 +71,7 @@ struct scene_structure : cgp::scene_inputs_generic { ...@@ -71,6 +71,7 @@ struct scene_structure : cgp::scene_inputs_generic {
bird bird1; bird bird1;
chain chain1; chain chain1;
bat bat1; bat bat1;
ball projectiles;
// ****************************** // // ****************************** //
// Functions // Functions
...@@ -95,6 +96,7 @@ struct scene_structure : cgp::scene_inputs_generic { ...@@ -95,6 +96,7 @@ struct scene_structure : cgp::scene_inputs_generic {
void draw_segment(vec3 const& a, vec3 const& b); void draw_segment(vec3 const& a, vec3 const& b);
void display_ball(); void display_ball();
void display_projectiles();
}; };
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment