3d:: correct eyes

This commit is contained in:
Zeno Rogue 2019-05-11 15:11:55 +02:00
parent 61a2c1a69e
commit 73f53b93a8
3 changed files with 86 additions and 15 deletions

View File

@ -699,6 +699,62 @@ void make_ball(hpcshape& sh, ld rad, int lev) {
add_texture(sh);
}
hyperpoint psmin(hyperpoint H) {
hyperpoint res;
res[2] = asin_auto(H[2]);
ld cs = pow(cos_auto(res[2]), 2);
ld r = sqrt(cs+H[0]*H[0]+H[1]*H[1]);
res[0] = H[0] / r;
res[1] = H[1] / r;
return res;
}
void adjust_eye(hpcshape& eye, hpcshape head, ld shift_eye, ld shift_head, int q, ld zoom=1) {
using namespace hyperpoint_vec;
hyperpoint center = Hypc;
for(int i=eye.s; i<eye.e; i++) if(q == 1 || hpc[i][1] > 0) center += hpc[i];
center = normalize(center);
// center /= (eye.e - eye.s);
ld rad = 0;
for(int i=eye.s; i<eye.e; i++) if(q == 1 || hpc[i][1] > 0) rad += hdist(center, hpc[i]);
rad /= (eye.e - eye.s);
hyperpoint pscenter = psmin(center);
ld pos = 0;
int qty = 0, qtyall = 0;
vector<hyperpoint> pss;
for(int i=head.s; i<head.e; i++) pss.push_back(psmin(zpush(shift_head) * hpc[i]));
ld zmid = 0;
for(hyperpoint& h: pss) zmid += h[2];
zmid /= isize(pss);
ld mindist = 1e9;
for(int i=0; i<isize(pss); i+=3) if(pss[i][2] < zmid || WDIM == 3) {
ld d = sqhypot_d(2, pss[i]-pscenter) + sqhypot_d(2, pss[i+1]-pscenter) + sqhypot_d(2, pss[i+2]-pscenter);
if(d < mindist) mindist = d, pos = min(min(pss[i][2], pss[i+1][2]), pss[i+2][2]), qty++;
qtyall++;
}
println(hlog, "center = ", center);
println(hlog, "qty= ", qty, "/",qtyall, " pos = ", pos, " mindist=", mindist);
make_ball(eye, rad, 0);
transmatrix T = zpush(-shift_eye) * rgpushxto0(center) * zpush(pos);
for(int i=eye.s; i<isize(hpc); i++) hpc[i] = T * hpc[i];
int s = isize(hpc);
if(q == 2)
for(int i=eye.s; i<s; i++) hpcpush(MirrorY * hpc[i]);
finishshape();
// eye.prio = PPR::SUPERLINE;
}
void shift_last_straight(ld z) {
for(int i=last->s; i<isize(hpc); i++) hpc[i] = zpush(z) * hpc[i];
}
void queueball(const transmatrix& V, ld rad, color_t col, eItem what) {
if(what == itOrbSpeed) {
transmatrix V1 = V * cspin(1, 2, M_PI/2);
@ -888,15 +944,6 @@ void make_3d_models() {
make_revolution_cut(shButterflyBody, 180);
shift_shape(shWolf1, -g-0.088 * S);
shift_shape(shWolf2, -g-0.088 * S);
shift_shape(shWolf3, -g-0.098 * S);
shift_shape(shFamiliarEye, -g-0.088 * S);
shift_shape(shWolfEyes, -g+(-0.088 - 0.01 * 0.9) * S);
shift_shape(shEyes, -g+(-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);
@ -982,6 +1029,24 @@ void make_3d_models() {
shift_shape(shMagicSword, geom3::ABODY);
shift_shape(shMagicShovel, geom3::ABODY);
adjust_eye(shSlimeEyes, shSlime, geom3::FLATEYE, 0, 2, 2);
adjust_eye(shGhostEyes, shGhost, geom3::GHOST, geom3::GHOST, 2, WDIM == 2 ? 2 : 4);
adjust_eye(shMiniEyes, shMiniGhost, geom3::GHOST, geom3::GHOST, 2, 2);
adjust_eye(shWormEyes, shWormHead, 0, 0, 2, 4);
adjust_eye(shDragonEyes, shDragonHead, 0, 0, 2, 4);
adjust_eye(shKrakenEye, shKrakenHead, 0, 0, 1);
adjust_eye(shKrakenEye2, shKrakenEye, 0, 0, 1, 2);
adjust_eye(shWolf1, shDogHead, geom3::AHEAD, geom3::AHEAD, 1);
adjust_eye(shWolf2, shDogHead, geom3::AHEAD, geom3::AHEAD, 1);
adjust_eye(shWolf3, shDogHead, geom3::AHEAD, geom3::AHEAD, 1);
adjust_eye(shFamiliarEye, shWolfHead, geom3::AHEAD, geom3::AHEAD, 1);
adjust_eye(shWolfEyes, shWolfHead, geom3::AHEAD, geom3::AHEAD, 1);
adjust_eye(shReptileEye, shReptileHead, geom3::AHEAD, geom3::AHEAD, 1);
}
#undef S

View File

@ -1310,6 +1310,10 @@ bool drawMonsterType(eMonster m, cell *where, const transmatrix& V1, color_t col
}
queuepoly(VAHEAD, shWolfHead, darkena(col, 0, 0xFF));
queuepoly(VAHEAD, shWolfEyes, darkena(col, 3, 0xFF));
if(DIM == 3) {
queuepoly(VAHEAD, shFamiliarEye, 0xFF);
queuepoly(VAHEAD * Mirror, shFamiliarEye, 0xFF);
}
return false;
}
@ -1678,13 +1682,13 @@ bool drawMonsterType(eMonster m, cell *where, const transmatrix& V1, color_t col
case moGhost: case moSeep: case moFriendlyGhost: {
if(m == moFriendlyGhost) col = fghostcolor(where);
queuepolyat(VGHOST, shGhost, darkena(col, 0, m == moFriendlyGhost ? 0xC0 : 0x80), DIM == 3 ? PPR::SUPERLINE : shGhost.prio);
queuepolyat(VGHOST, shEyes, 0xFF, DIM == 3 ? PPR::SUPERLINE : shEyes.prio);
queuepolyat(VGHOST, shGhostEyes, 0xFF, DIM == 3 ? PPR::SUPERLINE : shEyes.prio);
return false;
}
case moVineSpirit: {
queuepoly(VGHOST, shGhost, 0xD0D0D0C0 | UNTRANS);
queuepoly(VGHOST, shEyes, 0xFF0000FF);
queuepolyat(VGHOST, shGhostEyes, 0xFF0000FF, DIM == 3 ? PPR::SUPERLINE : shGhostEyes.prio);
return false;
}
@ -1700,7 +1704,7 @@ bool drawMonsterType(eMonster m, cell *where, const transmatrix& V1, color_t col
case moSlime: {
queuepoly(VFISH, shSlime, darkena(col, 0, 0x80));
queuepoly(VSLIMEEYE, shEyes, 0xFF);
queuepoly(VSLIMEEYE, shSlimeEyes, 0xFF);
return false;
}
@ -1918,13 +1922,13 @@ bool drawMonsterType(eMonster m, cell *where, const transmatrix& V1, color_t col
case moWorm: case moWormwait: case moHexSnake: {
queuepoly(V, shWormHead, darkena(col, 0, 0xFF));
queuepolyat(V, shEyes, 0xFF, PPR::ONTENTACLE_EYES);
queuepolyat(V, shWormEyes, 0xFF, PPR::ONTENTACLE_EYES);
return false;
}
case moDragonHead: {
queuepoly(V, shDragonHead, darkena(col, 0, 0xFF));
queuepolyat(V, shEyes, 0xFF, PPR::ONTENTACLE_EYES);
queuepolyat(V, shDragonEyes, 0xFF, PPR::ONTENTACLE_EYES);
int noscolor = 0xFF0000FF;
queuepoly(V, shDragonNostril, noscolor);
queuepoly(V * Mirror, shDragonNostril, noscolor);
@ -1977,7 +1981,7 @@ bool drawMonsterType(eMonster m, cell *where, const transmatrix& V1, color_t col
queuepoly(VFISH, shJelly, darkena(col, 0, 0xD0));
queuepolyat(VBODY, shJelly, darkena(col, 0, 0xD0), PPR::MONSTER_BODY);
queuepolyat(VHEAD, shJelly, darkena(col, 0, 0xD0), PPR::MONSTER_HEAD);
queuepolyat(VHEAD, shEyes, 0xFF, PPR::MONSTER_HEAD);
queuepolyat(VHEAD, shSlimeEyes, 0xFF, PPR::MONSTER_HEAD);
}
else if(isDemon(m)) {
const transmatrix VBS = VBODY * otherbodyparts(V, darkena(col, 0, 0xC0), m, footphase);

View File

@ -1683,6 +1683,7 @@ hpcshape
shWestHat1, shWestHat2, shGunInHand,
shKnightArmor, shKnightCloak, shWightCloak,
shGhost, shEyes, shSlime, shJelly, shJoint, shWormHead, shTentHead, shShark, shWormSegment, shSmallWormSegment, shWormTail, shSmallWormTail,
shSlimeEyes, shDragonEyes, shWormEyes, shGhostEyes,
shMiniGhost, shMiniEyes,
shHedgehogBlade, shHedgehogBladePlayer,
shWolfBody, shWolfHead, shWolfLegs, shWolfEyes,
@ -3047,6 +3048,7 @@ void buildpolys() {
bshape(shEyes, PPR::MONSTER_EYE0, scalefactor, 135);
bshape(shMiniEyes, PPR::MONSTER_EYE0, scalefactor/3, 135);
bshape(shShark, PPR::MONSTER_BODY, scalefactor, 136);
shSlimeEyes = shDragonEyes = shWormEyes = shGhostEyes = shEyes;
bshape(shTinyShark, PPR::MONSTER_BODY, scalefactor / 2, 136);
bshape(shBugBody, PPR::MONSTER_BODY, scalefactor, 137);
bshape(shBugArmor, PPR::MONSTER_ARMOR0, scalefactor, 138);