diff --git a/src/gl/data/gl_setup.cpp b/src/gl/data/gl_setup.cpp index a131926949..dfc0c6d47a 100644 --- a/src/gl/data/gl_setup.cpp +++ b/src/gl/data/gl_setup.cpp @@ -472,22 +472,18 @@ static void InitVertexData() // //========================================================================== -static void GetSideVertices(int sdnum, FVector2 *v1, FVector2 *v2) +static void GetSideVertices(int sdnum, DVector2 *v1, DVector2 *v2) { line_t *ln = sides[sdnum].linedef; if (ln->sidedef[0] == &sides[sdnum]) { - v1->X = ln->v1->fx; - v1->Y = ln->v1->fy; - v2->X = ln->v2->fx; - v2->Y = ln->v2->fy; + *v1 = ln->v1->fPos(); + *v2 = ln->v2->fPos(); } else { - v2->X = ln->v1->fx; - v2->Y = ln->v1->fy; - v1->X = ln->v2->fx; - v1->Y = ln->v2->fy; + *v2 = ln->v1->fPos(); + *v1 = ln->v2->fPos(); } } @@ -512,8 +508,6 @@ static void PrepareSegs() // Get floatng point coordinates of vertices for(int i = 0; i < numvertexes; i++) { - vertexes[i].fx = vertexes[i].fX(); - vertexes[i].fy = vertexes[i].fY(); vertexes[i].dirty = true; } @@ -559,7 +553,7 @@ static void PrepareSegs() realsegs++; segcount[sidenum]++; - FVector2 sidestart, sideend, segend(seg->v2->fx, seg->v2->fy); + DVector2 sidestart, sideend, segend = seg->v2->fPos(); GetSideVertices(sidenum, &sidestart, &sideend); sideend -=sidestart; diff --git a/src/gl/data/gl_vertexbuffer.cpp b/src/gl/data/gl_vertexbuffer.cpp index cd0ea5d605..997b347508 100644 --- a/src/gl/data/gl_vertexbuffer.cpp +++ b/src/gl/data/gl_vertexbuffer.cpp @@ -155,11 +155,11 @@ void FFlatVertexBuffer::ImmRenderBuffer(unsigned int primtype, unsigned int offs void FFlatVertex::SetFlatVertex(vertex_t *vt, const secplane_t & plane) { - x = vt->fx; - y = vt->fy; - z = plane.ZatPoint(vt->fx, vt->fy); // this is the original position without polyobject translation. - u = vt->fx/64.f; - v = -vt->fy/64.f; + x = vt->fX(); + y = vt->fY(); + z = plane.ZatPoint(vt); + u = vt->fX()/64.f; + v = -vt->fY()/64.f; } //========================================================================== diff --git a/src/gl/scene/gl_bsp.cpp b/src/gl/scene/gl_bsp.cpp index 613493e2c4..28b08d5361 100644 --- a/src/gl/scene/gl_bsp.cpp +++ b/src/gl/scene/gl_bsp.cpp @@ -374,6 +374,7 @@ static void DoSubsector(subsector_t * sub) // If the mapsections differ this subsector can't possibly be visible from the current view point if (!(currentmapsection[sub->mapsection>>3] & (1 << (sub->mapsection & 7)))) return; + if (sub->flags & SSECF_POLYORG) return; // never render polyobject origin subsectors because their vertices no longer are where one may expect. if (gl_drawinfo->ss_renderflags[sub-subsectors] & SSRF_SEEN) { diff --git a/src/gl/scene/gl_clipper.cpp b/src/gl/scene/gl_clipper.cpp index 57f9fb9ac2..ab4bb83d41 100644 --- a/src/gl/scene/gl_clipper.cpp +++ b/src/gl/scene/gl_clipper.cpp @@ -396,7 +396,6 @@ void R_SetView() angle_t R_PointToPseudoAngle (fixed_t x, fixed_t y) { - // Note: float won't work here as it's less precise than the BAM values being passed as parameters double vecx = double(x-viewx); double vecy = double(y-viewy); @@ -416,6 +415,26 @@ angle_t R_PointToPseudoAngle (fixed_t x, fixed_t y) } +angle_t R_PointToPseudoAngle(double x, double y) +{ + double vecx = x - ViewPos.X; + double vecy = y - ViewPos.Y; + + if (vecx == 0 && vecy == 0) + { + return 0; + } + else + { + double result = vecy / (fabs(vecx) + fabs(vecy)); + if (vecx < 0) + { + result = 2.f - result; + } + return xs_Fix<30>::ToFix(result); + } +} + //----------------------------------------------------------------------------- diff --git a/src/gl/scene/gl_clipper.h b/src/gl/scene/gl_clipper.h index 8092cd2848..7d05cf7017 100644 --- a/src/gl/scene/gl_clipper.h +++ b/src/gl/scene/gl_clipper.h @@ -137,12 +137,13 @@ public: extern Clipper clipper; angle_t R_PointToPseudoAngle (fixed_t x, fixed_t y); +angle_t R_PointToPseudoAngle(double x, double y); void R_SetView(); // Used to speed up angle calculations during clipping inline angle_t vertex_t::GetClipAngle() { - return angletime == Clipper::anglecache? viewangle : (angletime = Clipper::anglecache, viewangle = R_PointToPseudoAngle(x,y)); + return angletime == Clipper::anglecache? viewangle : (angletime = Clipper::anglecache, viewangle = R_PointToPseudoAngle(p.X, p.Y)); } #endif \ No newline at end of file diff --git a/src/gl/scene/gl_flats.cpp b/src/gl/scene/gl_flats.cpp index d234d29c96..40b6a58814 100644 --- a/src/gl/scene/gl_flats.cpp +++ b/src/gl/scene/gl_flats.cpp @@ -174,32 +174,15 @@ void GLFlat::SetupSubsectorLights(int pass, subsector_t * sub, int *dli) void GLFlat::DrawSubsector(subsector_t * sub) { FFlatVertex *ptr = GLRenderer->mVBO->GetBuffer(); - if (plane.plane.isSlope()) + for (unsigned int k = 0; k < sub->numlines; k++) { - for (unsigned int k = 0; k < sub->numlines; k++) - { - vertex_t *vt = sub->firstline[k].v1; - ptr->x = vt->fx; - ptr->y = vt->fy; - ptr->z = plane.plane.ZatPoint(vt->fx, vt->fy) + dz; - ptr->u = vt->fx / 64.f; - ptr->v = -vt->fy / 64.f; - ptr++; - } - } - else - { - float zc = FIXED2FLOAT(plane.plane.Zat0()) + dz; - for (unsigned int k = 0; k < sub->numlines; k++) - { - vertex_t *vt = sub->firstline[k].v1; - ptr->x = vt->fx; - ptr->y = vt->fy; - ptr->z = zc; - ptr->u = vt->fx / 64.f; - ptr->v = -vt->fy / 64.f; - ptr++; - } + vertex_t *vt = sub->firstline[k].v1; + ptr->x = vt->fX(); + ptr->y = vt->fY(); + ptr->z = plane.plane.ZatPoint(vt) + dz; + ptr->u = vt->fX() / 64.f; + ptr->v = -vt->fY() / 64.f; + ptr++; } GLRenderer->mVBO->RenderCurrent(ptr, GL_TRIANGLE_FAN); diff --git a/src/gl/scene/gl_vertex.cpp b/src/gl/scene/gl_vertex.cpp index c0f21adce2..3c41f52bda 100644 --- a/src/gl/scene/gl_vertex.cpp +++ b/src/gl/scene/gl_vertex.cpp @@ -82,8 +82,8 @@ void GLWall::SplitUpperEdge(texcoord * tcs, FFlatVertex *&ptr) float fracfac = sidefrac - glseg.fracleft; - ptr->x = cseg->v2->fx; - ptr->y = cseg->v2->fy; + ptr->x = cseg->v2->fX(); + ptr->y = cseg->v2->fY(); ptr->z = ztop[0] + fact * fracfac; ptr->u = tcs[1].u + facu * fracfac; ptr->v = tcs[1].v + facv * fracfac; @@ -118,8 +118,8 @@ void GLWall::SplitLowerEdge(texcoord * tcs, FFlatVertex *&ptr) float fracfac = sidefrac - glseg.fracleft; - ptr->x = cseg->v2->fx; - ptr->y = cseg->v2->fy; + ptr->x = cseg->v2->fX(); + ptr->y = cseg->v2->fY(); ptr->z = zbottom[0] + facb * fracfac; ptr->u = tcs[0].u + facu * fracfac; ptr->v = tcs[0].v + facv * fracfac; diff --git a/src/gl/utility/gl_geometric.h b/src/gl/utility/gl_geometric.h index 6868dab212..3691d7740c 100644 --- a/src/gl/utility/gl_geometric.h +++ b/src/gl/utility/gl_geometric.h @@ -33,8 +33,8 @@ public: Vector(vertex_t * v) { - SetX(v->fx); - SetY(v->fy); + SetX((float)v->fX()); + SetY((float)v->fY()); SetZ(0); } diff --git a/src/r_defs.h b/src/r_defs.h index d820fbfb9b..6cf07b817f 100644 --- a/src/r_defs.h +++ b/src/r_defs.h @@ -105,48 +105,48 @@ typedef double vtype; struct vertex_t { //private: - fixed_t x, y; + DVector2 p; + //fixed_t x, y; public: void set(fixed_t x, fixed_t y) { - this->x = x; - this->y = y; + p.X = x / 65536.; + p.Y = y / 65536.; } void set(double x, double y) { - this->x = FLOAT2FIXED(x); - this->y = FLOAT2FIXED(y); + p.X = x; + p.Y = y; } double fX() const { - return FIXED2DBL(x); + return p.X; } double fY() const { - return FIXED2DBL(y); + return p.Y; } fixed_t fixX() const { - return x; + return FLOAT2FIXED(p.X); } fixed_t fixY() const { - return y; + return FLOAT2FIXED(p.Y); } DVector2 fPos() { - return{ fX(), fY() }; + return { p.X, p.Y }; } - float fx, fy; // Floating point coordinates of this vertex (excluding polyoblect translation!) angle_t viewangle; // precalculated angle for clipping int angletime; // recalculation time for view angle bool dirty; // something has changed and needs to be recalculated @@ -157,8 +157,7 @@ public: vertex_t() { - x = y = 0; - fx = fy = 0; + p = { 0,0 }; angletime = 0; viewangle = 0; dirty = true; @@ -169,17 +168,17 @@ public: bool operator== (const vertex_t &other) { - return x == other.x && y == other.y; + return p == other.p; } bool operator!= (const vertex_t &other) { - return x != other.x || y != other.y; + return p != other.p; } void clear() { - x = y = 0; + p.Zero(); } angle_t GetClipAngle(); @@ -397,12 +396,12 @@ public: // This is for the software renderer fixed_t ZatPointFixed(const DVector2 &pos) const { - return xs_CRoundToInt((d + a*pos.X + b*pos.Y) * ic / (-65536.0)); + return FLOAT2FIXED(ZatPoint(pos)); } fixed_t ZatPointFixed(const vertex_t *v) const { - return FixedMul(ic, -d - DMulScale16(a, v->fixX(), b, v->fixY())); + return FLOAT2FIXED(ZatPoint(v)); } @@ -420,7 +419,7 @@ public: double ZatPoint(const vertex_t *v) const { - return FIXED2DBL(FixedMul(ic, -d - DMulScale16(a, v->fixX(), b, v->fixY()))); + return (d + a*v->fX() + b*v->fY()) * ic / (-65536.0 * 65536.0); } double ZatPoint(const AActor *ac) const @@ -431,7 +430,7 @@ public: // Returns the value of z at vertex v if d is equal to dist double ZatPointDist(const vertex_t *v, double dist) { - return FIXED2DBL(FixedMul(ic, -FLOAT2FIXED(dist) - DMulScale16(a, v->fixX(), b, v->fixY()))); + return (dist + a*v->fX() + b*v->fY()) * ic / (-65536.0 * 65536.0); } // Flips the plane's vertical orientiation, so that if it pointed up, // it will point down, and vice versa.