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

And the objects

parent 562f582f
No related branches found
No related tags found
No related merge requests found
#include "objects/hitbox.hpp"
void hitbox::initialize_hitbox(int _N, std::vector<vec3> _center, std::vector<double> _r) {
N = _N;
center.resize(N);
r.resize(N);
for (int i = 0; i < N; i++) {
center[i] = _center[i];
r[i] = _r[i];
}
}
bool hitbox::is_in_hitbox(vec3 pos, vec3 shift, rotation_transform rot) {
for (int i = 0; i < N; i++) {
if (norm(pos - (rot * center[i] + shift)) < r[i]) return true;
}
return false;
}
\ No newline at end of file
#pragma once
#include "cgp/cgp.hpp"
using namespace cgp;
struct hitbox {
int N;
std::vector<vec3> center;
std::vector<double> r;
void initialize_hitbox(int _N, std::vector<vec3> _center, std::vector<double> _r);
bool is_in_hitbox(vec3 pos, vec3 shift, rotation_transform rot);
};
\ No newline at end of file
#include "objects/projectile.hpp"
#include "terrain.hpp"
#include "settings.hpp"
void projectile::simulateParabolic(float dt) {
if (pos[2] < evaluate_terrain_height(pos[0], pos[1])) {
pos = { 0, 0, -1 };
v = { 0,0,0 };
}else {
pos += v * dt;
v[2] -= 10 * dt;
is_active = false;
}
}
void projectile::simulateStraightLine(float dt) {
if (pos[2] > evaluate_terrain_height(pos[0], pos[1])) {
pos += v * dt;
v[2] -= 0.1 * dt;
}
else is_active = false;
}
#pragma once
#include "cgp/cgp.hpp"
using namespace cgp;
struct projectile {
vec3 v;
vec3 pos;
vec3 color;
float size;
bool change_animation = true;
bool is_active = true;
//projectile types, in global so projectiles also can access it
enum class projectile_type { fire, ice, electric, rock, water };
//for ease of use
std::vector<projectile_type> el_types = { projectile_type::fire, projectile_type::ice, projectile_type::rock, projectile_type::electric, projectile_type::water };
projectile_type elemental_type;
void simulateParabolic(float dt);
void simulateStraightLine(float dt);
};
#include "objects/projectiles.hpp"
#include "terrain.hpp"
void projectiles::initialize()
{
N = 0;
projectiles_prop.resize(N);
mesh.initialize_data_on_gpu(mesh_primitive_sphere(0.1f));
fire_animation = image_load_file("assets/fireframes.png");
fire_grid = image_split_grid(fire_animation, 4, 3);
cgp::mesh sphere_mesh = mesh_primitive_sphere(0.2);
fireball.initialize_data_on_gpu(sphere_mesh);
fireball.texture.initialize_texture_2d_on_gpu(fire_grid[2]);
fireball.texture.update_wrap(GL_REPEAT, GL_REPEAT);
water_animation = image_load_file("assets/water.png");
water_grid = image_split_grid(water_animation, 3, 2);
waterball.initialize_data_on_gpu(sphere_mesh);
waterball.texture.initialize_texture_2d_on_gpu(water_grid[2]);
waterball.texture.update_wrap(GL_REPEAT, GL_REPEAT);
ice_animation = image_load_file("assets/spriteice.png");
ice_grid = image_split_grid(ice_animation, 4, 4);
iceball.initialize_data_on_gpu(sphere_mesh);
iceball.texture.initialize_texture_2d_on_gpu(ice_grid[2]);
iceball.texture.update_wrap(GL_REPEAT, GL_REPEAT);
electro_animation = image_load_file("assets/electroball2.png");
electro_grid = image_split_grid(electro_animation, 1, 1);
electroball.initialize_data_on_gpu(sphere_mesh);
electroball.texture.initialize_texture_2d_on_gpu(electro_grid[0]);
electroball.texture.update_wrap(GL_REPEAT, GL_REPEAT);
rock_animation = image_load_file("assets/rock_debris.png");
rock_grid = image_split_grid(rock_animation, 1, 1);
rockball.initialize_data_on_gpu(sphere_mesh);
rockball.texture.initialize_texture_2d_on_gpu(rock_grid[0]);
rockball.texture.update_wrap(GL_REPEAT, GL_REPEAT);
}
void projectiles::reset() {
N = 0;
projectiles_prop.resize(N);
}
void projectiles::add_ball(vec3 new_pos, vec3 new_dir, int element) {
N++;
projectiles_prop.resize(N);
projectiles_prop[N - 1].is_active = true;
projectiles_prop[N - 1].pos = new_pos;
projectiles_prop[N - 1].v = new_dir;
projectiles_prop[N - 1].elemental_type = el_types[element];
if (projectiles_prop[N - 1].elemental_type == projectile::projectile_type::fire) {
projectiles_prop[N - 1].color = {0.886, 0.345, 0.133};
}else if (projectiles_prop[N - 1].elemental_type == projectile::projectile_type::ice) {
projectiles_prop[N - 1].color = {1,1,1};
}else if (projectiles_prop[N - 1].elemental_type == projectile::projectile_type::rock) {
projectiles_prop[N - 1].color = {0.3,0.22,0.2};
}else if (projectiles_prop[N - 1].elemental_type == projectile::projectile_type::electric) {
projectiles_prop[N - 1].color = {1, 1, 0.2 };
}else if (projectiles_prop[N - 1].elemental_type == projectile::projectile_type::water) {
projectiles_prop[N - 1].color = {0, 0, 1 };
}
}
void projectiles::simulate(float dt) {
for (int i = 0; i < N; i++) {
projectiles_prop[i].simulateStraightLine(dt);
}
for (int i = N-1; i >= 0; i--) {
if (!projectiles_prop[i].is_active) remove_ball(i);
}
}
void projectiles::remove_ball(int i) {
if (N == 1) reset();
else {
projectiles_prop[i] = projectiles_prop[N - 1];
N--;
}
}
#pragma once
#include "cgp/cgp.hpp"
#include "objects/projectile.hpp"
using namespace cgp;
struct projectiles {
int N;
std::vector<projectile> projectiles_prop;
std::vector<projectile::projectile_type> el_types = { projectile::projectile_type::fire, projectile::projectile_type::ice, projectile::projectile_type::rock, projectile::projectile_type::electric, projectile::projectile_type::water };
//Textures
image_structure fire_animation;
std::vector<image_structure> fire_grid;
mesh_drawable fireball;
image_structure water_animation;
std::vector<image_structure> water_grid;
mesh_drawable waterball;
image_structure ice_animation;
std::vector<image_structure> ice_grid;
mesh_drawable iceball;
image_structure electro_animation;
std::vector<image_structure> electro_grid;
mesh_drawable electroball;
image_structure rock_animation;
std::vector<image_structure> rock_grid;
mesh_drawable rockball;
mesh_drawable mesh;
void initialize();
void simulate(float dt);
void add_ball(vec3 new_pos, vec3 new_dir, int element);
void remove_ball(int i);
void reset();
};
#include "objects/sapin.hpp"
#include "environment.hpp"
void sapin::initialize_sapin()
{
cgp::mesh_drawable trunk;
cgp::mesh_drawable branches;
cgp::mesh_drawable foliage;
trunk.initialize_data_on_gpu(mesh_load_file_obj(project::path + "assets/trunk.obj"));
trunk.texture.load_and_initialize_texture_2d_on_gpu(project::path + "assets/trunk.png");
branches.initialize_data_on_gpu(mesh_load_file_obj(project::path + "assets/branches.obj"));
branches.material.color = { 0.45f, 0.41f, 0.34f }; // no textures on branches
foliage.initialize_data_on_gpu(mesh_load_file_obj(project::path + "assets/foliage.obj"));
foliage.texture.load_and_initialize_texture_2d_on_gpu(project::path + "assets/pine.png");
foliage.shader.load(project::path + "shaders/mesh_transparency/vert.glsl", project::path + "shaders/mesh_transparency/frag.glsl"); // set the shader handling transparency for the foliage
foliage.material.phong = { 0.4f, 0.6f, 0, 1 }; // remove specular effect for the billboard
//scale the model
trunk.model.scaling = 0.5f;
branches.model.scaling = 0.5f;
foliage.model.scaling = 0.5f;
sapin.add(trunk, "Trunk");
sapin.add(branches, "Branches", "Trunk");
sapin.add(foliage, "Foliage", "Trunk");
}
\ No newline at end of file
#pragma once
#include "cgp/cgp.hpp"
using namespace cgp;
struct sapin {
hierarchy_mesh_drawable sapin;
void initialize_sapin();
};
\ No newline at end of file
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