Skip to content
Snippets Groups Projects
Commit 616ad8ee authored by Marie AUDOUARD's avatar Marie AUDOUARD
Browse files

Added dragon files (obj + c/hpp)

parent 989c778f
No related branches found
No related tags found
No related merge requests found
Showing with 108063 additions and 0 deletions
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
#include "dragon.hpp"
#include "environment.hpp"
#include "key_positions_structure.hpp"
#include "interpolation.hpp"
#include "terrain.hpp"
void dragon::initialize_mvt(vec3 p, numarray<vec3> key_positions, numarray<float> key_times)
{
for (int i = 0; i < key_positions.size(); i++) {
key_positions[i] += p;
}
// Initialize the helping structure to display/interact with these positions
keyframe.initialize(key_positions, key_times);
// Set timer bounds
// The timer must span a time interval on which the interpolation can be conducted
// By default, set the minimal time to be key_times[1], and the maximal time to be key_time[N-2] (enables cubic interpolation)
int NT = key_times.size();
timer_mvt.t_min = key_times[0];
timer_mvt.t_max = key_times[NT - 1];
timer_mvt.t = timer_mvt.t_min;
//Dragon hitbox
dragon_hitbox.initialize_hitbox(2, {{0,2.5*size,0},{0,-1.75*size,0.5*size}}, { size*3, size * 1.5});
}
void dragon::update_mvt()
{
// Update the current time
timer_mvt.update();
float t = timer_mvt.t;
// clear trajectory when the timer restart
if (t < timer_mvt.t_min + 0.1f)
keyframe.trajectory.clear();
if (t + 0.1f > timer_mvt.t_max) pos_futur = interpolation(0.01f, keyframe.key_positions, keyframe.key_times, 0.5f);
else pos_futur = interpolation((t + 0.1f), keyframe.key_positions, keyframe.key_times, 0.5f);
// Compute the interpolated position
pos = interpolation(t, keyframe.key_positions, keyframe.key_times, 0.5f);
}
#pragma once
#include "cgp/cgp.hpp"
#include "key_positions_structure.hpp"
#include "hitbox.hpp"
using namespace cgp;
// The entire hierarchy
struct dragon{
double size;
bool isdead;
vec3 pos;
vec3 pos_futur;
hitbox dragon_hitbox;
// Timer used for the interpolation of the position
cgp::timer_interval timer_mvt;
// A helper structure used to store and display the key positions/time
keyframe_structure keyframe;
void initialize_mvt(vec3 p, numarray<vec3> key_positions, numarray<float> key_times);
void update_mvt();
};
\ No newline at end of file
#include "dragons.hpp"
#include "environment.hpp"
#include "key_positions_structure.hpp"
#include "interpolation.hpp"
#include "terrain.hpp"
void dragons::initialize_dragons()
{
// Initialize the temporary mesh_drawable that will be inserted in the hierarchy
mesh_drawable body;
mesh_drawable mouth;
mesh_drawable wing1;
mesh_drawable wing2;
mesh_drawable tailmiddle;
mesh_drawable tailend;
// Create the geometry of the meshes
// Note: this geometry must be set in their local coordinates with respect to their position in the hierarchy (and with respect to their animation)
body.initialize_data_on_gpu(mesh_load_file_obj(project::path + "assets/dragon/dragonbody.obj"));
wing1.initialize_data_on_gpu(mesh_load_file_obj(project::path + "assets/dragon/dragonwl.obj"));
wing2.initialize_data_on_gpu(mesh_load_file_obj(project::path + "assets/dragon/dragonwr.obj"));
mouth.initialize_data_on_gpu(mesh_load_file_obj(project::path + "assets/dragon/dragonmouth.obj"));
tailmiddle.initialize_data_on_gpu(mesh_load_file_obj(project::path + "assets/dragon/dragontailend.obj"));
tailend.initialize_data_on_gpu(mesh_load_file_obj(project::path + "assets/dragon/dragontailmiddle.obj"));
// Scale the model
//body.model.scaling = 0.2f;
//wing1.model.scaling = 0.2f;
//wing2.model.scaling = 0.2f;
// Set the color of some elements
body.material.color = { 0.6,0.15,0.1 };
wing1.material.color = { 0.6,0.15,0.1 };
wing2.material.color = { 0.6,0.15,0.1 };
mouth.material.color = { 0.6,0.15,0.1 };
tailmiddle.material.color = { 0.6,0.15,0.1 };
tailend.material.color = { 0.6,0.15,0.1 };
// Add the elements in the hierarchy
// The syntax is hierarchy.add(mesh_drawable, "name of the parent element", [optional: local translation in the hierarchy])
// Notes:
// - An element must necessarily be added after its parent
// - The first element (without explicit name of its parent) is assumed to be the root.
dragon_mesh.add(body, "Dragon base");
dragon_mesh.add(wing1, "Dragon wing left", "Dragon base");
dragon_mesh.add(wing2, "Dragon wing right", "Dragon base");
dragon_mesh.add(mouth, "Dragon mouth", "Dragon base");
dragon_mesh.add(tailmiddle, "Dragon tailmiddle", "Dragon base");
dragon_mesh.add(tailend, "Dragon tailend", "Dragon tailmiddle");
N = 0;
}
void dragons::update_mvt()
{
for (int i = 0; i < N; i++) {
dragons_prop[i].update_mvt();
}
}
void dragons::add_dragon(vec3 new_pos, float _size, numarray<vec3> key_positions, numarray<float> key_times) {
N++;
dragons_prop.resize(N);
dragons_prop[N - 1].pos = new_pos;
dragons_prop[N - 1].isdead = false;
dragons_prop[N - 1].size = _size;
dragons_prop[N - 1].initialize_mvt(new_pos, key_positions, key_times);
}
#pragma once
#include "cgp/cgp.hpp"
#include "key_positions_structure.hpp"
#include "dragon.hpp"
using namespace cgp;
// The entire hierarchy
struct dragons{
cgp::hierarchy_mesh_drawable dragon_mesh;
int N;
std::vector<dragon> dragons_prop;
void initialize_dragons();
void add_dragon(vec3 new_pos, float _size, numarray<vec3> key_positions, numarray<float> key_times);
void update_mvt();
};
\ 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