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 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140
| #include "animation.h"
using namespace std;
CAnimation::CAnimation(const bool& orientation_, const int& offset_, const int& nbr_images_, const char *seq_, const int& nbr_seq_, const string& file_, const SDL_Rect& coord_, const float& coef_resol_) : CGraphic(coord_, coef_resol_), up_down(false), slide_up(0), seq(seq_), nbr_seq(nbr_seq_), offset(offset_), cursor(0) {
// name file completed with sufix like name3.png
string complet_file;
// to convert int to string
CConverter conv;
// init slide image alpha
slide_blk = {1.0f, 1.0f, 1.0f, 1.0f};
try {
for(int i = offset; i < offset + nbr_images_; ++i) {
// we create a complet file like name to name12.png
complet_file = file_ + (conv << (i + 1)) + ".png";
// we create list with images
shared_ptr<CDraw> draw = make_shared<CDraw>(complet_file.c_str(), coord_, coef_resol);
// only texture is saved, not surface because we don't use tests on surface
draw->Free_surface();
// We reverse picture on Y axis
if(orientation_)
draw->reverse_H_SDL();
// Push image in the vector
Vimages.push_back(draw);
}
}
catch(string &caught) {
Vimages.clear();
cerr << caught << endl;
throw;
}
// we update width and height animation values
set_object_properties(Vimages.at(0)->object_properties());
}
CAnimation::~CAnimation() {
Vimages.clear();
}
bool CAnimation::slide_black(float speed) {
// init slide_black to start
if(slide_up == 0 && slide_blk.r == 1.0)
slide_blk = {.0f, .0f, .0f, 1.0f};
// increment up the grey color
if(!slide_up) {
slide_blk.r += speed;
slide_blk.g += speed;
slide_blk.b += speed;
}
// increment down the grey color
if(slide_up == 1) {
slide_blk.r -= speed;
slide_blk.g -= speed;
slide_blk.b -= speed;
}
// to increase down
if(slide_blk.r >= 1.0f) {
slide_up = 1;
return false;
}
// to increase up
if(slide_blk.r <= .0f) {
slide_up = 2;
return false;
}
return true;
}
void CAnimation::show(const int& type_anim, const bool& orientation, const int& step, const float& deep) {
if(seq)
// we show the surface with id = cursor
Vimages.at(seq[cursor])->show_GL(orientation, object_properties(), deep, slide_blk);
else
// we show the surface with a normal seq (1, 2, 3, 4, 5, ...)
Vimages.at(cursor)->show_GL(orientation, object_properties(), deep, slide_blk);
// increment animation
pass(type_anim, step);
}
#if KINECT_COMP == 1
void CAnimation::show_kinect(const int& type_anim, const bool& orientation, const int& step, const float& deep) {
if(seq)
// we show the surface with id = cursor
Vimages.at(seq[cursor])->show_GL_kinect(orientation, object_properties(), deep, slide_blk);
else
// we show the surface with a normal seq (1, 2, 3, 4, 5, ...)
Vimages.at(cursor)->show_GL_kinect(orientation, object_properties(), deep, slide_blk);
// increment animation
pass(type_anim, step);
}
#endif
void CAnimation::show(const int& loop_type, const bool& orientation, const int& step, const TVector2d<float>& scale, const float& rotation, const float& deep) {
if(seq)
// we show the surface with id = cursor
Vimages.at(seq[cursor])->show_GL(orientation, object_properties(), scale, rotation, deep);
else
// we show the surface with a normal seq (1, 2, 3, 4, 5, ...)
Vimages.at(cursor)->show_GL(orientation, object_properties(), scale, rotation, deep);
// increment animation
pass(loop_type, step);
} |
Partager