animated 3D birds

This commit is contained in:
Zeno Rogue 2019-04-22 14:41:14 +02:00
parent 7ed3ee6098
commit 8b0c0f58c4
4 changed files with 39 additions and 9 deletions

View File

@ -621,6 +621,29 @@ void disable(hpcshape& sh) {
sh.s = sh.e = 0;
}
void clone_shape(hpcshape& sh, hpcshape& target) {
target = sh;
target.s = isize(hpc);
for(int i=sh.s; i<sh.e; i++) hpc.push_back(hpc[i]);
target.e = isize(hpc);
}
void animate_bird(hpcshape& orig, hpcshape animated[30], ld body) {
for(int i=0; i<30; i++) {
auto& tgt = animated[i];
clone_shape(orig, tgt);
ld alpha = sin(12 * degree * i) * 30 * degree;
for(int i=tgt.s; i<tgt.e; i++) {
if(abs(hpc[i][1]) > body) {
ld off = hpc[i][1] > 0 ? body : -body;
hpc[i][2] += abs(hpc[i][1] - off) * sin(alpha);
hpc[i][1] = off + (hpc[i][1] - off) * cos(alpha);
hpc[i] = normalize(hpc[i]);
}
}
}
}
void make_3d_models() {
if(DIM == 2) return;
shcenter = C0;
@ -776,6 +799,9 @@ void make_3d_models() {
shift_shape(shEyes, (-3.3) * S / -20);
for(int i=shEyes.s; i<shEyes.e; i++) hpc[i] = cspin(0, 2, M_PI/2) * hpc[i];
animate_bird(shEagle, shAnimatedEagle, 0.05*S);
animate_bird(shTinyBird, shAnimatedTinyEagle, 0.05*S/2);
disable(shWolfRearLeg);
disable(shWolfFrontLeg);

View File

@ -1379,13 +1379,15 @@ bool drawMonsterType(eMonster m, cell *where, const transmatrix& V1, color_t col
case moEagle: case moParrot: case moBomberbird: case moAlbatross:
case moTameBomberbird: case moWindCrow: case moTameBomberbirdMoved:
case moSandBird: case moAcidBird:
case moSandBird: case moAcidBird: {
ShadowV(V, shEagle);
auto& sh = DIM == 3 ? shAnimatedEagle[((long long)(ticks) * 30 / 1000) % 30] : shEagle;
if(m == moParrot && DIM == 3)
queuepolyat(VBIRD, shEagle, darkena(col, 0, 0xFF), PPR::SUPERLINE);
queuepolyat(VBIRD, sh, darkena(col, 0, 0xFF), PPR::SUPERLINE);
else
queuepoly(VBIRD, shEagle, darkena(col, 0, 0xFF));
queuepoly(VBIRD, sh, darkena(col, 0, 0xFF));
return false;
}
case moSparrowhawk: case moWestHawk: {
ShadowV(V, shHawk);

View File

@ -1716,6 +1716,8 @@ hpcshape
shPBodyOnly, shPBodyArm, shPBodyHand, shPHeadOnly,
shAnimatedEagle[30], shAnimatedTinyEagle[30],
shDodeca;
vector<hpcshape> shPlainWall3D, shWireframe3D, shWall3D, shMiniWall3D;

View File

@ -27,7 +27,7 @@
#include "rogueviz.h"
namespace hr { extern hpcshape shEagle, shMiniGhost, shGhost, shShark; }
namespace hr { extern hpcshape shEagle, shMiniGhost, shGhost, shShark, shAnimatedEagle[30], shAnimatedTinyEagle[30]; }
namespace rogueviz {
@ -1107,7 +1107,7 @@ color_t darken_a(color_t c) {
return c;
}
void queuedisk(const transmatrix& V, const colorpair& cp, bool legend, const string* info) {
void queuedisk(const transmatrix& V, const colorpair& cp, bool legend, const string* info, int i) {
if(legend && (int) cp.color1 == (int) 0x000000FF && backcolor == 0)
poly_outline = 0x606060FF;
else
@ -1146,10 +1146,10 @@ void queuedisk(const transmatrix& V, const colorpair& cp, bool legend, const str
case 's': queuepoly(V1, shDiskS, darken_a(cp.color2)); return;
case 'q': queuepoly(V1, shDiskSq, darken_a(cp.color2)); return;
case 'm': queuepoly(V1, shDiskM, darken_a(cp.color2)); return;
case 'b': queuepoly(V1, shTinyBird, darken_a(cp.color2)); return;
case 'b': queuepoly(V1, DIM == 3 ? shAnimatedTinyEagle[((long long)(ticks) * 30 / 1000+i) % 30] : shTinyBird, darken_a(cp.color2)); return;
case 'f': queuepoly(V1, shTinyShark, darken_a(cp.color2)); return;
case 'g': queuepoly(V1, shMiniGhost, darken_a(cp.color2)); return;
case 'B': queuepoly(V1, shEagle, darken_a(cp.color2)); return;
case 'B': queuepoly(V1, DIM == 3 ? shAnimatedEagle[((long long)(ticks) * 30 / 1000+i) % 30] : shEagle, darken_a(cp.color2)); return;
case 'F': queuepoly(V1, shShark, darken_a(cp.color2)); return;
case 'G': queuepoly(V1, shGhost, darken_a(cp.color2)); return;
}
@ -1315,7 +1315,7 @@ bool drawVertex(const transmatrix &V, cell *c, shmup::monster *m) {
}
if(!vd.virt) {
queuedisk(V * m->at, ghilite ? colorpair(0xFF0000FF) : vd.cp, false, vd.info);
queuedisk(V * m->at, ghilite ? colorpair(0xFF0000FF) : vd.cp, false, vd.info, i);
}
@ -1430,7 +1430,7 @@ bool rogueviz_hud() {
transmatrix V = atscreenpos(x, y, current_display->radius/4);
poly_outline = OUTLINE_NONE;
queuedisk(V, vd.cp, true, NULL);
queuedisk(V, vd.cp, true, NULL, i);
poly_outline = OUTLINE_DEFAULT;
queuestr(int(x-rad), int(y), 0, rad*(svg::in?5:3)/4, vd.name, forecolor, 0, 16);
}