diff options
Diffstat (limited to 'editcord.c')
-rw-r--r-- | editcord.c | 225 |
1 files changed, 225 insertions, 0 deletions
diff --git a/editcord.c b/editcord.c new file mode 100644 index 0000000..da3097f --- /dev/null +++ b/editcord.c @@ -0,0 +1,225 @@ +/* + + viDOOM - level editor for DOOM + + Copyright (C) 2000 Ian Cowburn (ianc@noddybox.demon.co.uk) + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + ------------------------------------------------------------------------- + + Editor co-ordinate utilities + +*/ +static const char rcs_id[]="$Id$"; + +#include "config.h" +#include "globals.h" + +#include <math.h> + +#include "texture.h" +#include "editvar.h" + +/* ---------------------------------------- MAP DRAWING AND POSITION FUNCTIONS +*/ +int SnapX(int x) +{ + TRACE; + + if (!grid_lock) + return(x); + + if (x>=0) + return (((x+grid_size/2)/grid_size)*grid_size); + else + return (((x-grid_size/2)/grid_size)*grid_size); +} + +int SnapY(int y) +{ + TRACE; + + if (!grid_lock) + return(y); + + if (y>=0) + return (((y+grid_size/2)/grid_size)*grid_size); + else + return (((y-grid_size/2)/grid_size)*grid_size); +} + + +int Len(int x1,int y1,int x2,int y2) +{ + double a,b,c; + + TRACE; + + x2-=x1; + y2-=y1; + x2=ABS(x2); + y2=ABS(y2); + + if (!x2) + return(y2); + else if (!y2) + return(x2); + + a=x2*x2; + b=y2*y2; + c=sqrt(a+b); + return((int)c); +} + + +/* Many thanks to Mathew Wilson (www.mjwilson.demon.co.uk) for this routine +*/ +int LinesCross(int x1_1,int y1_1,int x1_2,int y1_2, + int x2_1,int y2_1,int x2_2,int y2_2) +{ + double x0,y0,x1,y1,u0,v0,u1,v1; + double t; + double m,l; + + x0=(double)x1_1; + y0=(double)y1_1; + u0=(double)x1_2-x1_1; + v0=(double)y1_2-y1_1; + + x1=(double)x2_1; + y1=(double)y2_1; + u1=(double)x2_2-x2_1; + v1=(double)y2_2-y2_1; + + /* Find 1st divisor (to check for zero) + */ + t=(u1*v0)-(v1*u0); + + if (t==0.0) + return(FALSE); + + m=(v0*(x0-x1)-u0*(y0-y1))/t; + + l=(v1*(x0-x1)-u1*(y0-y1))/t; + + if ((l>=0.0)&&(l<=1.0)&&(m>=0.0)&&(m<=1.0)) + return(TRUE); + + return(FALSE); +} + + +int CalcTextureWidth(DirName u,DirName m,DirName l) +{ + int a,b,c; + int w=99999; + + TRACE; + + TextureSize(u,&a,NULL); + TextureSize(m,&b,NULL); + TextureSize(l,&c,NULL); + + if ((a)&&(a<w)) + w=a; + + if ((b)&&(b<w)) + w=b; + + if ((c)&&(c<w)) + w=c; + + if (w==99999) + w=0; + + return(w); +} + + +void LineCalcBounding(EditLine *l) +{ + TRACE; + + l->min_x=MIN(l->v[0]->v.x,l->v[1]->v.x); + l->max_x=MAX(l->v[0]->v.x,l->v[1]->v.x); + l->min_y=MIN(l->v[0]->v.y,l->v[1]->v.y); + l->max_y=MAX(l->v[0]->v.y,l->v[1]->v.y); +} + + +void SectorCalcBounding(EditSect *s) +{ + Iterator i; + Short *f; + EditVert *v; + + TRACE; + + s->min_x=32000; + s->min_y=32000; + s->max_x=-32000; + s->max_y=-32000; + i=ListIterator(s->v); + + while(i) + { + f=IteratorData(i); + v=GETVERT(*f); + + s->min_x=MIN(s->min_x,v->v.x); + s->max_x=MAX(s->max_x,v->v.x); + s->min_y=MIN(s->min_y,v->v.y); + s->max_y=MAX(s->max_y,v->v.y); + + i=IteratorNext(i); + } +} + + +int LineOnDisplay(EditLine *l) +{ + TRACE; + + /* Remember: DOOM Y positions are the reverse of the order on screen + */ + return ((MapToX(l->min_x)<SCRW)&&(MapToX(l->max_x)>=0)&& + (MapToY(l->max_y)<SCRH)&&(MapToY(l->min_y)>=0)); +} + + +int SectorOnDisplay(EditSect *s) +{ + TRACE; + + /* Remember: DOOM Y positions are the reverse of the order on screen + */ + return ((MapToX(s->min_x)<SCRW)&&(MapToX(s->max_x)>=0)&& + (MapToY(s->max_y)<SCRH)&&(MapToY(s->min_y)>=0)); +} + + +int PointOnDisplay(int x,int y,int r) +{ + TRACE; + + /* Remember: DOOM Y positions are the reverse of the order on screen + */ + return ((MapToX(x+r)>=0)&&(MapToX(x-r)<SCRW)&& + (MapToY(y-r)>=0)&&(MapToY(y+r)<SCRH)); +} + + +/* END OF FILE */ |