- floatified vertex coordinates.

Making these double or float doesn't seem to matter at all performance-wise so they use the more precise double format.
This commit is contained in:
Christoph Oelckers 2016-04-03 11:53:31 +02:00
parent f36489098f
commit 7a6039b44c

View file

@ -102,55 +102,60 @@ typedef double vtype;
struct vertex_t struct vertex_t
{ {
private: private:
fixed_t x, y; DVector2 p;
public: public:
void set(fixed_t x, fixed_t y) void set(fixed_t x, fixed_t y)
{ {
this->x = x; p.X = x / 65536.;
this->y = y; p.Y = y / 65536.;
} }
void set(double x, double y) void set(double x, double y)
{ {
this->x = FLOAT2FIXED(x); p.X = x;
this->y = FLOAT2FIXED(y); p.Y = y;
} }
double fX() const double fX() const
{ {
return FIXED2DBL(x); return p.X;
} }
double fY() const double fY() const
{ {
return FIXED2DBL(y); return p.Y;
} }
fixed_t fixX() const fixed_t fixX() const
{ {
return x; return FLOAT2FIXED(p.X);
} }
fixed_t fixY() const fixed_t fixY() const
{ {
return y; return FLOAT2FIXED(p.Y);
} }
DVector2 fPos() DVector2 fPos()
{ {
return{ fX(), fY() }; return { p.X, p.Y };
} }
bool operator== (const vertex_t &other) bool operator== (const vertex_t &other)
{ {
return x == other.x && y == other.y; return p == other.p;
}
bool operator!= (const vertex_t &other)
{
return p != other.p;
} }
void clear() void clear()
{ {
x = y = 0; p.Zero();
} }
}; };
@ -366,12 +371,12 @@ public:
// This is for the software renderer // This is for the software renderer
fixed_t ZatPointFixed(const DVector2 &pos) const 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 fixed_t ZatPointFixed(const vertex_t *v) const
{ {
return FixedMul(ic, -d - DMulScale16(a, v->fixX(), b, v->fixY())); return FLOAT2FIXED(ZatPoint(v));
} }
@ -389,7 +394,7 @@ public:
double ZatPoint(const vertex_t *v) const 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 double ZatPoint(const AActor *ac) const
@ -400,7 +405,7 @@ public:
// Returns the value of z at vertex v if d is equal to dist // Returns the value of z at vertex v if d is equal to dist
double ZatPointDist(const vertex_t *v, double 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, // Flips the plane's vertical orientiation, so that if it pointed up,
// it will point down, and vice versa. // it will point down, and vice versa.