vec2_t rotatesprite, take 2

git-svn-id: https://svn.eduke32.com/eduke32@5239 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
terminx 2015-05-26 00:47:54 +00:00
parent fe4db15536
commit 54d016902f
6 changed files with 90 additions and 77 deletions

View file

@ -1157,8 +1157,7 @@ FORCE_INLINE int32_t logapproach(int32_t val, int32_t targetval)
return (dif>>1) ? val + (dif>>1) : targetval;
}
void rotatepoint(int32_t xpivot, int32_t ypivot, int32_t x, int32_t y,
int16_t daang, int32_t *x2, int32_t *y2) ATTRIBUTE((nonnull(6,7)));
void rotatepoint(vec2_t pivot, vec2_t p, int16_t daang, vec2_t *p2) ATTRIBUTE((nonnull(4)));
int32_t lastwall(int16_t point);
int32_t nextsectorneighborz(int16_t sectnum, int32_t refz, int16_t topbottom, int16_t direction);
@ -1440,6 +1439,8 @@ FORCE_INLINE void pop_nofog(void)
#endif
}
static vec2_t const zerovec = { 0, 0 };
#ifdef LUNATIC
extern const int32_t engine_main_arrays_are_static;
extern const int32_t engine_v8;

View file

@ -1026,7 +1026,7 @@ void editinput(void)
int32_t mousz, bstatus;
int32_t i, tempint=0;
int32_t goalz, xvect, yvect, hiz, loz, oposz;
int32_t dax, day, hihit, lohit, omlook=mlook;
int32_t hihit, lohit, omlook=mlook;
// 3B 3C 3D 3E 3F 40 41 42 43 44 57 58 46
// F1 F2 F3 F4 F5 F6 F7 F8 F9 F10 F11 F12 SCROLL
@ -1305,27 +1305,27 @@ void editinput(void)
{
hitdata_t hit;
dax = 16384;
day = divscale14(searchx-(xdim>>1), xdim>>1);
rotatepoint(0,0, dax,day, ang, &dax,&day);
vec2_t da = { 16384, divscale14(searchx-(xdim>>1), xdim>>1) };
rotatepoint(zerovec, da, ang, &da);
hitscan((const vec3_t *)&pos,cursectnum, //Start position
dax,day,(scale(searchy,200,ydim)-horiz)*2000, //vector of 3D ang
da.x,da.y,(scale(searchy,200,ydim)-horiz)*2000, //vector of 3D ang
&hit,CLIPMASK1);
if (hit.sect >= 0)
{
dax = hit.pos.x;
day = hit.pos.y;
da.x = hit.pos.x;
da.y = hit.pos.y;
if (gridlock && grid > 0)
{
if (AIMING_AT_WALL || AIMING_AT_MASKWALL)
hit.pos.z &= 0xfffffc00;
else
locktogrid(&dax, &day);
locktogrid(&da.x, &da.y);
}
i = insert_sprite_common(hit.sect, dax, day);
i = insert_sprite_common(hit.sect, da.x, da.y);
if (i < 0)
message("Couldn't insert sprite.");
@ -3157,7 +3157,7 @@ static void draw_square(int32_t dax, int32_t day, int32_t ps, int32_t col)
//// Interactive Scaling
static struct {
int8_t active, rotatep;
int32_t pivx, pivy; // pivot point
vec2_t piv; // pivot point
int32_t dragx, dragy; // dragged point
int32_t xsc, ysc, ang;
} isc;
@ -3166,12 +3166,15 @@ static void isc_transform(int32_t *x, int32_t *y)
{
if (!isc.rotatep)
{
*x = isc.pivx + mulscale16(*x-isc.pivx, isc.xsc);
*y = isc.pivy + mulscale16(*y-isc.pivy, isc.ysc);
*x = isc.piv.x + mulscale16(*x-isc.piv.x, isc.xsc);
*y = isc.piv.y + mulscale16(*y-isc.piv.y, isc.ysc);
}
else
{
rotatepoint(isc.pivx, isc.pivy, *x, *y, isc.ang, x, y);
vec2_t v = { *x, *y };
rotatepoint(isc.piv, v, isc.ang, &v);
*x = v.x;
*y = v.y;
}
}
@ -3554,8 +3557,8 @@ void overheadeditor(void)
maxy = max(maxy, HLMEMBER(i, y));
}
isc.pivx = (minx+maxx)/2;
isc.pivy = (miny+maxy)/2;
isc.piv.x = (minx+maxx)/2;
isc.piv.y = (miny+maxy)/2;
isc.dragx = HLMEMBERX(pointhighlight, x);
isc.dragy = HLMEMBERX(pointhighlight, y);
@ -3571,7 +3574,7 @@ void overheadeditor(void)
if (bstatus&3)
{
// drag/rotate the reference point
const int32_t pivx=isc.pivx, pivy=isc.pivy;
const int32_t pivx=isc.piv.x, pivy=isc.piv.y;
const int32_t dragx=isc.dragx, dragy=isc.dragy;
int32_t mxplc=mousxplc, myplc=mousyplc, xsc=1<<16, ysc=1<<16;
@ -4005,6 +4008,7 @@ void overheadeditor(void)
if (highlightsectorcnt > 0)
{
int32_t smoothRotation = eitherSHIFT, manualAngle = eitherALT;
vec2_t da = { dax, day };
if (manualAngle)
{
@ -4020,24 +4024,25 @@ void overheadeditor(void)
smoothRotation = 1;
}
get_sectors_center(highlightsector, highlightsectorcnt, &dax, &day);
get_sectors_center(highlightsector, highlightsectorcnt, &da.x, &da.y);
if (!smoothRotation)
{
if (gridlock && grid > 0)
locktogrid(&dax, &day);
locktogrid(&da.x, &da.y);
tsign *= 512;
}
for (i=0; i<highlightsectorcnt; i++)
{
for (WALLS_OF_SECTOR(highlightsector[i], j))
rotatepoint(dax,day, wall[j].x,wall[j].y, tsign&2047, &wall[j].x,&wall[j].y);
rotatepoint(da, *(vec2_t *)&wall[j], tsign&2047, (vec2_t *)&wall[j].x);
for (j=headspritesect[highlightsector[i]]; j != -1; j=nextspritesect[j])
{
rotatepoint(dax,day, sprite[j].x,sprite[j].y, tsign&2047, &sprite[j].x,&sprite[j].y);
rotatepoint(da, *(vec2_t *)&sprite[j], tsign&2047, (vec2_t *)&sprite[j].x);
sprite[j].ang = (sprite[j].ang+tsign)&2047;
}
}
@ -8256,15 +8261,17 @@ void getpoint(int32_t searchxe, int32_t searchye, int32_t *x, int32_t *y)
searchxe -= halfxdim16;
searchye -= midydim16;
vec2_t svec = { searchxe ,searchye };
if (m32_sideview)
{
if (m32_sidesin!=0)
searchye = divscale14(searchye, m32_sidesin);
rotatepoint(0,0, searchxe,searchye, -m32_sideang, &searchxe,&searchye);
svec.y = divscale14(svec.y, m32_sidesin);
rotatepoint(zerovec, svec, -m32_sideang, &svec);
}
*x = pos.x + divscale14(searchxe,zoom);
*y = pos.y + divscale14(searchye,zoom);
*x = pos.x + divscale14(svec.x,zoom);
*y = pos.y + divscale14(svec.y,zoom);
inpclamp(x, -editorgridextent, editorgridextent);
inpclamp(y, -editorgridextent, editorgridextent);

View file

@ -13846,7 +13846,7 @@ static int32_t clipsprite_initindex(int32_t curidx, spritetype *curspr, int32_t
{
wal->x *= flipx;
wal->y *= flipy;
rotatepoint(0,0, wal->x,wal->y, rotang, &wal->x,&wal->y);
rotatepoint(zerovec, *(vec2_t *)&wal, rotang, (vec2_t *)&wal);
}
wal->x += curspr->x;
@ -14705,16 +14705,14 @@ void updatesectorz(int32_t x, int32_t y, int32_t z, int16_t *sectnum)
//
// rotatepoint
//
void rotatepoint(int32_t xpivot, int32_t ypivot, int32_t x, int32_t y, int16_t daang, int32_t *x2, int32_t *y2)
void rotatepoint(vec2_t const pivot, vec2_t p, int16_t daang, vec2_t *p2)
{
int32_t dacos, dasin;
dacos = sintable[(daang+2560)&2047];
dasin = sintable[(daang+2048)&2047];
x -= xpivot;
y -= ypivot;
*x2 = dmulscale14(x,dacos,-y,dasin) + xpivot;
*y2 = dmulscale14(y,dacos,x,dasin) + ypivot;
int const dacos = sintable[(daang+2560)&2047];
int const dasin = sintable[(daang+2048)&2047];
p.x -= pivot.x;
p.y -= pivot.y;
p2->x = dmulscale14(p.x, dacos, -p.y, dasin) + pivot.x;
p2->y = dmulscale14(p.y, dacos, p.x, dasin) + pivot.y;
}
@ -16765,11 +16763,13 @@ int32_t scalescreeny(int32_t sy)
// return screen coordinates for BUILD coords x and y (relative to current position)
void screencoords(int32_t *xres, int32_t *yres, int32_t x, int32_t y, int32_t zoome)
{
if (m32_sideview)
rotatepoint(0,0, x,y, m32_sideang, &x,&y);
vec2_t coord = { x, y };
*xres = mulscale14(x,zoome);
*yres = scalescreeny(mulscale14(y,zoome));
if (m32_sideview)
rotatepoint(zerovec, coord, m32_sideang, &coord);
*xres = mulscale14(coord.x, zoome);
*yres = scalescreeny(mulscale14(coord.y, zoome));
}
#if 0
@ -16791,7 +16791,13 @@ int32_t getinvdisplacement(int32_t *dx, int32_t *dy, int32_t dz)
return 1;
dz = (((int64_t)dz * (int64_t)m32_sidecos)/(int64_t)m32_sidesin)>>4;
rotatepoint(0,0, 0,dz, -m32_sideang, dx,dy);
vec2_t v[2] = { { 0, dz }, { *dx, *dy } };
rotatepoint(zerovec, v[0], -m32_sideang, &v[1]);
*dx = v[1].x;
*dy = v[1].y;
return 0;
}
@ -16812,7 +16818,7 @@ void setup_sideview_sincos(void)
m32_sidesin = sintable[m32_sideelev&2047];
m32_sidecos = sintable[(m32_sideelev+512)&2047];
rotatepoint(0,0, m32_viewplane.x,m32_viewplane.y, -m32_sideang, &m32_viewplane.x,&m32_viewplane.y);
rotatepoint(zerovec, *(vec2_t *)&m32_viewplane, -m32_sideang, (vec2_t *)&m32_viewplane);
m32_viewplane.x = mulscale14(m32_viewplane.x, m32_sidecos);
m32_viewplane.y = mulscale14(m32_viewplane.y, m32_sidecos);
m32_viewplane.z = m32_sidesin>>5;

View file

@ -734,7 +734,7 @@ static int32_t move_rotfixed_sprite(int32_t j, int32_t pivotspr, int32_t daang)
A_CheckSpriteTileFlags(sprite[j].picnum, SFLAG_ROTFIXED))) &&
actor[j].t_data[7] == (ROTFIXSPR_MAGIC | pivotspr))
{
rotatepoint(0, 0, actor[j].t_data[8], actor[j].t_data[9], daang & 2047, &sprite[j].x, &sprite[j].y);
rotatepoint(zerovec, *(vec2_t *)&actor[j].t_data[8], daang & 2047, (vec2_t *)&sprite[j].x);
sprite[j].x += sprite[pivotspr].x;
sprite[j].y += sprite[pivotspr].y;
return 0;
@ -747,8 +747,8 @@ static void A_MoveSector(int i)
{
// T1,T2 and T3 are used for all the sector moving stuff!!!
spritetype * const s = &sprite[i];
int j = T2, k = T3;
int32_t tx, ty;
int j = T2;
int const k = T3;
s->x += (s->xvel * (sintable[(s->ang + 512) & 2047])) >> 14;
s->y += (s->xvel * (sintable[s->ang & 2047])) >> 14;
@ -757,8 +757,10 @@ static void A_MoveSector(int i)
for (i = sector[s->sectnum].wallptr; i < endwall; i++)
{
rotatepoint(0, 0, msx[j], msy[j], k & 2047, &tx, &ty);
dragpoint(i, s->x + tx, s->y + ty, 0);
vec2_t const v = { msx[j], msy[j] };
vec2_t t;
rotatepoint(zerovec, v, k & 2047, &t);
dragpoint(i, s->x + t.x, s->y + t.y, 0);
j++;
}
@ -5718,19 +5720,16 @@ ACTOR_STATIC void G_MoveEffectors(void) //STATNUM 3
ps->pos.z += zchange;
rotatepoint(sprite[j].x,sprite[j].y,ps->pos.x,ps->pos.y,(q*l),&m,&x);
vec2_t r;
rotatepoint(*(vec2_t *)&sprite[j],*(vec2_t *)&ps->pos,(q*l),&r);
ps->bobpos.x += m-ps->pos.x;
ps->bobpos.y += x-ps->pos.y;
ps->bobpos.x += r.x-ps->pos.x;
ps->bobpos.y += r.y-ps->pos.y;
ps->pos.x = m;
ps->pos.y = x;
*(vec2_t *)&ps->pos = r;
if (sprite[ps->i].extra <= 0)
{
sprite[ps->i].x = m;
sprite[ps->i].y = x;
}
*(vec2_t *)&sprite[ps->i] = r;
}
}
@ -5753,7 +5752,7 @@ ACTOR_STATIC void G_MoveEffectors(void) //STATNUM 3
actor[p].bpos.y = sprite[p].y;
if (move_rotfixed_sprite(p, j, t[2]))
rotatepoint(sprite[j].x,sprite[j].y,sprite[p].x,sprite[p].y,(q*l),&sprite[p].x,&sprite[p].y);
rotatepoint(*(vec2_t *)&sprite[j], *(vec2_t *)&sprite[p], (q * l), (vec2_t *)&sprite[p].x);
}
}
@ -5936,7 +5935,7 @@ ACTOR_STATIC void G_MoveEffectors(void) //STATNUM 3
#endif
)
{
rotatepoint(s->x,s->y,ps->pos.x,ps->pos.y,q,&ps->pos.x,&ps->pos.y);
rotatepoint(*(vec2_t *)s, *(vec2_t *)&ps->pos, q, (vec2_t *)&ps->pos);
ps->pos.x += m;
ps->pos.y += x;
@ -5979,7 +5978,7 @@ ACTOR_STATIC void G_MoveEffectors(void) //STATNUM 3
}
if (move_rotfixed_sprite(j, s-sprite, t[2]))
rotatepoint(s->x,s->y,sprite[j].x,sprite[j].y,q,&sprite[j].x,&sprite[j].y);
rotatepoint(*(vec2_t *)s,*(vec2_t *)&sprite[j],q,(vec2_t *)&sprite[j].x);
sprite[j].x+= m;
sprite[j].y+= x;

View file

@ -2995,9 +2995,9 @@ nullquote:
Gv_GetManyVars(3, (int32_t *)&vect);
int32_t sectnum = Gv_GetVarX(*insptr++);
int32_t ceilzvar = *insptr++, ceilhitvar = *insptr++, florzvar = *insptr++, florhitvar = *insptr++;
int32_t walldist = Gv_GetVarX(*insptr++), clipmask = Gv_GetVarX(*insptr++);
int const sectnum = Gv_GetVarX(*insptr++);
int const ceilzvar = *insptr++, ceilhitvar = *insptr++, florzvar = *insptr++, florhitvar = *insptr++;
int const walldist = Gv_GetVarX(*insptr++), clipmask = Gv_GetVarX(*insptr++);
int32_t ceilz, ceilhit, florz, florhit;
if (EDUKE32_PREDICT_FALSE((unsigned)sectnum >= (unsigned)numsectors))
@ -3041,7 +3041,7 @@ nullquote:
int32_t retvar=*insptr++;
vec2_t da;
Gv_GetManyVars(2, (int32_t *)&da);
int64_t hypsq = (int64_t)da.x*da.x + (int64_t)da.y*da.y;
int64_t const hypsq = (int64_t)da.x*da.x + (int64_t)da.y*da.y;
if (hypsq > (int64_t)INT32_MAX)
Gv_SetVarX(retvar, (int32_t)sqrt((double)hypsq));
@ -3092,14 +3092,14 @@ nullquote:
int32_t w, f, c;
} vec3dist_t;
int32_t retvar=*insptr++, xvar=*insptr++, yvar=*insptr++;
int const retvar = *insptr++, xvar = *insptr++, yvar = *insptr++;
insptr -= 2;
vec3_t vec3;
Gv_GetManyVars(3, (int32_t *)&vec3);
int32_t sectnumvar=*insptr++;
int const sectnumvar = *insptr++;
vec2_t vec2;
Gv_GetManyVars(2, (int32_t *)&vec2);
@ -3107,7 +3107,7 @@ nullquote:
vec3dist_t dist;
Gv_GetManyVars(3, (int32_t *)&dist);
int32_t clipmask = Gv_GetVarX(*insptr++);
int const clipmask = Gv_GetVarX(*insptr++);
int16_t sectnum = Gv_GetVarX(sectnumvar);
if (EDUKE32_PREDICT_FALSE((unsigned)sectnum >= (unsigned)numsectors))
@ -3117,8 +3117,7 @@ nullquote:
continue;
}
Gv_SetVarX(retvar, clipmovex(&vec3, &sectnum, vec2.x, vec2.y, dist.w, dist.f, dist.c,
clipmask, (tw==CON_CLIPMOVENOSLIDE)));
Gv_SetVarX(retvar, clipmovex(&vec3, &sectnum, vec2.x, vec2.y, dist.w, dist.f, dist.c, clipmask, (tw == CON_CLIPMOVENOSLIDE)));
Gv_SetVarX(sectnumvar, sectnum);
Gv_SetVarX(xvar, vec3.x);
Gv_SetVarX(yvar, vec3.y);
@ -3132,7 +3131,7 @@ nullquote:
vec3_t vect;
Gv_GetManyVars(3, (int32_t *)&vect);
int32_t sectnum = Gv_GetVarX(*insptr++);
int const sectnum = Gv_GetVarX(*insptr++);
vec3_t v;
Gv_GetManyVars(3, (int32_t *) &v);
@ -3169,7 +3168,7 @@ nullquote:
vec3_t vec2;
Gv_GetManyVars(3, (int32_t *) &vec2);
int32_t sect2=Gv_GetVarX(*insptr++), rvar=*insptr++;
int const sect2 = Gv_GetVarX(*insptr++), rvar = *insptr++;
if (EDUKE32_PREDICT_FALSE((unsigned)sect1 >= (unsigned)numsectors || (unsigned)sect2 >= (unsigned)numsectors))
{
@ -3192,7 +3191,7 @@ nullquote:
vec2_t result;
rotatepoint(point[0].x, point[0].y, point[1].x, point[1].y, angle, &result.x, &result.y);
rotatepoint(point[0], point[1], angle, &result);
Gv_SetVarX(x2var, result.x);
Gv_SetVarX(y2var, result.y);

View file

@ -1920,14 +1920,15 @@ badindex:
case CON_ROTATEPOINT:
insptr++;
{
int32_t xpivot=Gv_GetVarX(*insptr++), ypivot=Gv_GetVarX(*insptr++);
int32_t x=Gv_GetVarX(*insptr++), y=Gv_GetVarX(*insptr++), daang=Gv_GetVarX(*insptr++);
vec2_t pivot = { Gv_GetVarX(*insptr++), Gv_GetVarX(*insptr++) };
vec2_t p = { Gv_GetVarX(*insptr++), Gv_GetVarX(*insptr++) } ;
int32_t daang=Gv_GetVarX(*insptr++);
int32_t x2var=*insptr++, y2var=*insptr++;
int32_t x2, y2;
vec2_t p2;
rotatepoint(xpivot,ypivot,x,y,daang,&x2,&y2);
Gv_SetVarX(x2var, x2);
Gv_SetVarX(y2var, y2);
rotatepoint(pivot,p,daang,&p2);
Gv_SetVarX(x2var, p2.x);
Gv_SetVarX(y2var, p2.y);
continue;
}