Clean up love’s internal Vector code a bit, and rename it to Vector2 so it’s more obvious what it is.

--HG--
branch : minor
This commit is contained in:
Alex Szpakowski
2017-05-16 22:07:01 -03:00
parent 135d928922
commit ac697ddb0f
25 changed files with 486 additions and 384 deletions
+3 -3
View File
@@ -373,7 +373,7 @@ float Font::getHeight() const
return (float) floorf(height / pixelDensity + 0.5f);
}
std::vector<Font::DrawCommand> Font::generateVertices(const ColoredCodepoints &codepoints, const Colorf &constantcolor, std::vector<GlyphVertex> &vertices, float extra_spacing, Vector offset, TextInfo *info)
std::vector<Font::DrawCommand> Font::generateVertices(const ColoredCodepoints &codepoints, const Colorf &constantcolor, std::vector<GlyphVertex> &vertices, float extra_spacing, Vector2 offset, TextInfo *info)
{
// Spacing counter and newline handling.
float dx = offset.x;
@@ -534,7 +534,7 @@ std::vector<Font::DrawCommand> Font::generateVerticesFormatted(const ColoredCode
const auto &line = lines[i];
float width = (float) widths[i];
love::Vector offset(0.0f, floorf(y));
love::Vector2 offset(0.0f, floorf(y));
float extraspacing = 0.0f;
maxwidth = std::max(width, maxwidth);
@@ -621,7 +621,7 @@ void Font::printv(graphics::Graphics *gfx, const Matrix4 &t, const std::vector<D
GlyphVertex *vertexdata = (GlyphVertex *) data.stream[0];
memcpy(vertexdata, &vertices[cmd.startvertex], sizeof(GlyphVertex) * cmd.vertexcount);
m.transform(vertexdata, &vertices[cmd.startvertex], cmd.vertexcount);
m.transformXY(vertexdata, &vertices[cmd.startvertex], cmd.vertexcount);
}
}
+1 -1
View File
@@ -101,7 +101,7 @@ public:
virtual ~Font();
std::vector<DrawCommand> generateVertices(const ColoredCodepoints &codepoints, const Colorf &constantColor, std::vector<GlyphVertex> &vertices,
float extra_spacing = 0.0f, Vector offset = {}, TextInfo *info = nullptr);
float extra_spacing = 0.0f, Vector2 offset = {}, TextInfo *info = nullptr);
std::vector<DrawCommand> generateVerticesFormatted(const ColoredCodepoints &text, const Colorf &constantColor, float wrap, AlignMode align,
std::vector<GlyphVertex> &vertices, TextInfo *info = nullptr);
+9 -9
View File
@@ -622,7 +622,7 @@ Graphics::StreamVertexData Graphics::requestStreamDraw(const StreamDrawRequest &
{
int components = getFormatPositionComponents(fmt);
if (components > 0 && components < 3)
throw love::Exception("Obly affine 2D transforms are supported with auto-batched draws.");
throw love::Exception("Only affine 2D transforms are supported with auto-batched draws.");
}
}
@@ -820,7 +820,7 @@ void Graphics::points(const float *coords, const Colorf *colors, size_t numpoint
StreamVertexData data = requestStreamDraw(req);
const Matrix4 &t = getTransform();
t.transform((Vector *) data.stream[0], (const Vector *) coords, req.vertexCount);
t.transformXY((Vector2 *) data.stream[0], (const Vector2 *) coords, req.vertexCount);
Color *colordata = (Color *) data.stream[1];
@@ -1104,7 +1104,7 @@ void Graphics::polygon(DrawMode mode, const float *coords, size_t count)
StreamVertexData data = requestStreamDraw(req);
const Matrix4 &t = getTransform();
t.transform((Vector *) data.stream[0], (const Vector *) coords, req.vertexCount);
t.transformXY((Vector2 *) data.stream[0], (const Vector2 *) coords, req.vertexCount);
Color c = toColor(getColor());
Color *colordata = (Color *) data.stream[1];
@@ -1243,19 +1243,19 @@ void Graphics::replaceTransform(love::math::Transform *transform)
pixelScaleStack.back() = (sx + sy) / 2.0;
}
Vector Graphics::transformPoint(Vector point)
Vector2 Graphics::transformPoint(Vector2 point)
{
Vector p;
transformStack.back().transform(&p, &point, 1);
Vector2 p;
transformStack.back().transformXY(&p, &point, 1);
return p;
}
Vector Graphics::inverseTransformPoint(Vector point)
Vector2 Graphics::inverseTransformPoint(Vector2 point)
{
Vector p;
Vector2 p;
// TODO: We should probably cache the inverse transform so we don't have to
// re-calculate it every time this is called.
transformStack.back().inverse().transform(&p, &point, 1);
transformStack.back().inverse().transformXY(&p, &point, 1);
return p;
}
+2 -2
View File
@@ -743,8 +743,8 @@ public:
void applyTransform(love::math::Transform *transform);
void replaceTransform(love::math::Transform *transform);
Vector transformPoint(Vector point);
Vector inverseTransformPoint(Vector point);
Vector2 transformPoint(Vector2 point);
Vector2 inverseTransformPoint(Vector2 point);
virtual void flushStreamDraws() = 0;
StreamVertexData requestStreamDraw(const StreamDrawRequest &request);
+45 -45
View File
@@ -168,11 +168,11 @@ ParticleSystem::~ParticleSystem()
void ParticleSystem::resetOffset()
{
if (quads.empty())
offset = love::Vector(float(texture->getWidth())*0.5f, float(texture->getHeight())*0.5f);
offset = love::Vector2(float(texture->getWidth())*0.5f, float(texture->getHeight())*0.5f);
else
{
Quad::Viewport v = quads[0]->getViewport();
offset = love::Vector(v.x*0.5f, v.y*0.5f);
offset = love::Vector2(v.x*0.5f, v.y*0.5f);
}
}
@@ -253,7 +253,7 @@ void ParticleSystem::initParticle(Particle *p, float t)
float min,max;
// Linearly interpolate between the previous and current emitter position.
love::Vector pos = prevPosition + (position - prevPosition) * t;
love::Vector2 pos = prevPosition + (position - prevPosition) * t;
min = particleLifeMin;
max = particleLifeMax;
@@ -275,58 +275,58 @@ void ParticleSystem::initParticle(Particle *p, float t)
switch (areaSpreadDistribution)
{
case DISTRIBUTION_UNIFORM:
rand_x = (float) rng.random(-areaSpread.getX(), areaSpread.getX());
rand_y = (float) rng.random(-areaSpread.getY(), areaSpread.getY());
rand_x = (float) rng.random(-areaSpread.x, areaSpread.x);
rand_y = (float) rng.random(-areaSpread.y, areaSpread.y);
p->position.x += cosf(areaSpreadAngle) * rand_x - sinf(areaSpreadAngle) * rand_y;
p->position.y += sinf(areaSpreadAngle) * rand_x + cosf(areaSpreadAngle) * rand_y;
break;
case DISTRIBUTION_NORMAL:
rand_x = (float) rng.randomNormal(areaSpread.getX());
rand_y = (float) rng.randomNormal(areaSpread.getY());
rand_x = (float) rng.randomNormal(areaSpread.x);
rand_y = (float) rng.randomNormal(areaSpread.y);
p->position.x += cosf(areaSpreadAngle) * rand_x - sinf(areaSpreadAngle) * rand_y;
p->position.y += sinf(areaSpreadAngle) * rand_x + cosf(areaSpreadAngle) * rand_y;
break;
case DISTRIBUTION_ELLIPSE:
rand_x = (float) rng.random(-1, 1);
rand_y = (float) rng.random(-1, 1);
min = areaSpread.getX() * (rand_x * sqrt(1 - 0.5f*pow(rand_y, 2)));
max = areaSpread.getY() * (rand_y * sqrt(1 - 0.5f*pow(rand_x, 2)));
min = areaSpread.x * (rand_x * sqrt(1 - 0.5f*pow(rand_y, 2)));
max = areaSpread.y * (rand_y * sqrt(1 - 0.5f*pow(rand_x, 2)));
p->position.x += cosf(areaSpreadAngle) * min - sinf(areaSpreadAngle) * max;
p->position.y += sinf(areaSpreadAngle) * min + cosf(areaSpreadAngle) * max;
break;
case DISTRIBUTION_BORDER_ELLIPSE:
rand_x = (float) rng.random(0, LOVE_M_PI * 2);
min = cosf(rand_x) * areaSpread.getX();
max = sinf(rand_x) * areaSpread.getY();
min = cosf(rand_x) * areaSpread.x;
max = sinf(rand_x) * areaSpread.y;
p->position.x += cosf(areaSpreadAngle) * min - sinf(areaSpreadAngle) * max;
p->position.y += sinf(areaSpreadAngle) * min + cosf(areaSpreadAngle) * max;
break;
case DISTRIBUTION_BORDER_RECTANGLE:
rand_x = (float) rng.random((areaSpread.getX() + areaSpread.getY()) * -2, (areaSpread.getX() + areaSpread.getY()) * 2);
rand_y = areaSpread.getY() * 2;
rand_x = (float) rng.random((areaSpread.x + areaSpread.y) * -2, (areaSpread.x + areaSpread.y) * 2);
rand_y = areaSpread.y * 2;
if (rand_x < -rand_y)
{
min = rand_x + rand_y + areaSpread.getX();
p->position.x += cosf(areaSpreadAngle) * min - sinf(areaSpreadAngle) * -areaSpread.getY();
p->position.y += sinf(areaSpreadAngle) * min + cosf(areaSpreadAngle) * -areaSpread.getY();
min = rand_x + rand_y + areaSpread.x;
p->position.x += cosf(areaSpreadAngle) * min - sinf(areaSpreadAngle) * -areaSpread.y;
p->position.y += sinf(areaSpreadAngle) * min + cosf(areaSpreadAngle) * -areaSpread.y;
}
else if (rand_x < 0)
{
max = rand_x + areaSpread.getY();
p->position.x += cosf(areaSpreadAngle) * -areaSpread.getX() - sinf(areaSpreadAngle) * max;
p->position.y += sinf(areaSpreadAngle) * -areaSpread.getX() + cosf(areaSpreadAngle) * max;
max = rand_x + areaSpread.y;
p->position.x += cosf(areaSpreadAngle) * -areaSpread.x - sinf(areaSpreadAngle) * max;
p->position.y += sinf(areaSpreadAngle) * -areaSpread.x + cosf(areaSpreadAngle) * max;
}
else if (rand_x < rand_y)
{
max = rand_x - areaSpread.getY();
p->position.x += cosf(areaSpreadAngle) * areaSpread.getX() - sinf(areaSpreadAngle) * max;
p->position.y += sinf(areaSpreadAngle) * areaSpread.getX() + cosf(areaSpreadAngle) * max;
max = rand_x - areaSpread.y;
p->position.x += cosf(areaSpreadAngle) * areaSpread.x - sinf(areaSpreadAngle) * max;
p->position.y += sinf(areaSpreadAngle) * areaSpread.x + cosf(areaSpreadAngle) * max;
}
else
{
min = rand_x - rand_y - areaSpread.getX();
p->position.x += cosf(areaSpreadAngle) * min - sinf(areaSpreadAngle) * areaSpread.getY();
p->position.y += sinf(areaSpreadAngle) * min + cosf(areaSpreadAngle) * areaSpread.getY();
min = rand_x - rand_y - areaSpread.x;
p->position.x += cosf(areaSpreadAngle) * min - sinf(areaSpreadAngle) * areaSpread.y;
p->position.y += sinf(areaSpreadAngle) * min + cosf(areaSpreadAngle) * areaSpread.y;
}
break;
case DISTRIBUTION_NONE:
@@ -336,7 +336,7 @@ void ParticleSystem::initParticle(Particle *p, float t)
// Determine if the origin of each particle is the center of the area
if (areaSpreadIsRelativeDirection)
dir += atan2(p->position.y - pos.getY(), p->position.x - pos.getX());
dir += atan2(p->position.y - pos.y, p->position.x - pos.x);
p->origin = pos;
@@ -344,7 +344,7 @@ void ParticleSystem::initParticle(Particle *p, float t)
max = speedMax;
float speed = (float) rng.random(min, max);
p->velocity = love::Vector(cosf(dir), sinf(dir)) * speed;
p->velocity = love::Vector2(cosf(dir), sinf(dir)) * speed;
p->linearAcceleration.x = (float) rng.random(linearAccelerationMin.x, linearAccelerationMax.x);
p->linearAcceleration.y = (float) rng.random(linearAccelerationMin.y, linearAccelerationMax.y);
@@ -554,36 +554,36 @@ void ParticleSystem::getParticleLifetime(float &min, float &max) const
void ParticleSystem::setPosition(float x, float y)
{
position = love::Vector(x, y);
position = love::Vector2(x, y);
prevPosition = position;
}
const love::Vector &ParticleSystem::getPosition() const
const love::Vector2 &ParticleSystem::getPosition() const
{
return position;
}
void ParticleSystem::moveTo(float x, float y)
{
position = love::Vector(x, y);
position = love::Vector2(x, y);
}
void ParticleSystem::setAreaSpread(AreaSpreadDistribution distribution, float x, float y)
{
areaSpread = love::Vector(x, y);
areaSpread = love::Vector2(x, y);
areaSpreadDistribution = distribution;
}
void ParticleSystem::setAreaSpread(AreaSpreadDistribution distribution, float x, float y, float angle)
{
areaSpread = love::Vector(x, y);
areaSpread = love::Vector2(x, y);
areaSpreadDistribution = distribution;
areaSpreadAngle = angle;
}
void ParticleSystem::setAreaSpread(AreaSpreadDistribution distribution, float x, float y, float angle, bool isRelativeDirection)
{
areaSpread = love::Vector(x, y);
areaSpread = love::Vector2(x, y);
areaSpreadDistribution = distribution;
areaSpreadAngle = angle;
areaSpreadIsRelativeDirection = isRelativeDirection;
@@ -594,7 +594,7 @@ ParticleSystem::AreaSpreadDistribution ParticleSystem::getAreaSpreadDistribution
return areaSpreadDistribution;
}
const love::Vector &ParticleSystem::getAreaSpreadParameters() const
const love::Vector2 &ParticleSystem::getAreaSpreadParameters() const
{
return areaSpread;
}
@@ -664,11 +664,11 @@ void ParticleSystem::setLinearAcceleration(float x, float y)
void ParticleSystem::setLinearAcceleration(float xmin, float ymin, float xmax, float ymax)
{
linearAccelerationMin = love::Vector(xmin, ymin);
linearAccelerationMax = love::Vector(xmax, ymax);
linearAccelerationMin = love::Vector2(xmin, ymin);
linearAccelerationMax = love::Vector2(xmax, ymax);
}
void ParticleSystem::getLinearAcceleration(love::Vector &min, love::Vector &max) const
void ParticleSystem::getLinearAcceleration(love::Vector2 &min, love::Vector2 &max) const
{
min = linearAccelerationMin;
max = linearAccelerationMax;
@@ -793,11 +793,11 @@ float ParticleSystem::getSpinVariation() const
void ParticleSystem::setOffset(float x, float y)
{
offset = love::Vector(x, y);
offset = love::Vector2(x, y);
defaultOffset = false;
}
love::Vector ParticleSystem::getOffset() const
love::Vector2 ParticleSystem::getOffset() const
{
return offset;
}
@@ -950,8 +950,8 @@ void ParticleSystem::update(float dt)
else
{
// Temp variables.
love::Vector radial, tangential;
love::Vector ppos = p->position;
love::Vector2 radial, tangential;
love::Vector2 ppos = p->position;
// Get vector from particle center to particle.
radial = ppos - p->origin;
@@ -963,9 +963,9 @@ void ParticleSystem::update(float dt)
// Calculate tangential acceleration.
{
float a = tangential.getX();
tangential.setX(-tangential.getY());
tangential.setY(a);
float a = tangential.x;
tangential.x = -tangential.y;
tangential.y = a;
}
// Resize tangential.
@@ -1075,7 +1075,7 @@ bool ParticleSystem::prepareDraw(Graphics *gfx, const Matrix4 &m)
// particle vertices are image vertices transformed by particle info
t.setTransformation(p->position.x, p->position.y, p->angle, p->size, p->size, offset.x, offset.y, 0.0f, 0.0f);
t.transform(pVerts, textureVerts, 4);
t.transformXY(pVerts, textureVerts, 4);
// Particle colors are stored as floats (0-1) but vertex colors are
// unsigned bytes (0-255).
+14 -14
View File
@@ -182,7 +182,7 @@ public:
/**
* Returns the position of the emitter.
**/
const love::Vector &getPosition() const;
const love::Vector2 &getPosition() const;
/**
* Moves the position of the center of the emitter.
@@ -249,7 +249,7 @@ public:
/**
* Returns area spread parameters.
**/
const love::Vector &getAreaSpreadParameters() const;
const love::Vector2 &getAreaSpreadParameters() const;
/**
* Returns the angle of the area distribution (in radians).
@@ -338,7 +338,7 @@ public:
* @param[out] min The minimum acceleration.
* @param[out] max The maximum acceleration.
**/
void getLinearAcceleration(love::Vector &min, love::Vector &max) const;
void getLinearAcceleration(love::Vector2 &min, love::Vector2 &max) const;
/**
* Sets the radial acceleration (the acceleration towards the particle emitter).
@@ -480,7 +480,7 @@ public:
/**
* Returns of the particle offset.
**/
love::Vector getOffset() const;
love::Vector2 getOffset() const;
/**
* Sets the color of the particles.
@@ -586,13 +586,13 @@ protected:
float lifetime;
float life;
love::Vector position;
love::Vector2 position;
// Particles gravitate towards this point.
love::Vector origin;
love::Vector2 origin;
love::Vector velocity;
love::Vector linearAcceleration;
love::Vector2 velocity;
love::Vector2 linearAcceleration;
float radialAcceleration;
float tangentialAcceleration;
@@ -648,12 +648,12 @@ protected:
float emitCounter;
// The relative position of the particle emitter.
love::Vector position;
love::Vector prevPosition;
love::Vector2 position;
love::Vector2 prevPosition;
// Emission area spread.
AreaSpreadDistribution areaSpreadDistribution;
love::Vector areaSpread;
love::Vector2 areaSpread;
float areaSpreadAngle;
bool areaSpreadIsRelativeDirection;
@@ -674,8 +674,8 @@ protected:
float speedMax;
// Acceleration along the x and y axes.
love::Vector linearAccelerationMin;
love::Vector linearAccelerationMax;
love::Vector2 linearAccelerationMin;
love::Vector2 linearAccelerationMax;
// Acceleration towards the emitter's center
float radialAccelerationMin;
@@ -702,7 +702,7 @@ protected:
float spinVariation;
// Offsets
love::Vector offset;
love::Vector2 offset;
// Is the ParticleSystem using a default offset?
bool defaultOffset;
+38 -38
View File
@@ -35,11 +35,11 @@ namespace graphics
void Polyline::render(const float *coords, size_t count, size_t size_hint, float halfwidth, float pixel_size, bool draw_overdraw)
{
static std::vector<Vector> anchors;
static std::vector<Vector2> anchors;
anchors.clear();
anchors.reserve(size_hint);
static std::vector<Vector> normals;
static std::vector<Vector2> normals;
normals.clear();
normals.reserve(size_hint);
@@ -49,25 +49,25 @@ void Polyline::render(const float *coords, size_t count, size_t size_hint, float
// compute sleeve
bool is_looping = (coords[0] == coords[count - 2]) && (coords[1] == coords[count - 1]);
Vector s;
Vector2 s;
if (!is_looping) // virtual starting point at second point mirrored on first point
s = Vector(coords[2] - coords[0], coords[3] - coords[1]);
s = Vector2(coords[2] - coords[0], coords[3] - coords[1]);
else // virtual starting point at last vertex
s = Vector(coords[0] - coords[count - 4], coords[1] - coords[count - 3]);
s = Vector2(coords[0] - coords[count - 4], coords[1] - coords[count - 3]);
float len_s = s.getLength();
Vector ns = s.getNormal(halfwidth / len_s);
Vector2 ns = s.getNormal(halfwidth / len_s);
Vector q, r(coords[0], coords[1]);
Vector2 q, r(coords[0], coords[1]);
for (size_t i = 0; i + 3 < count; i += 2)
{
q = r;
r = Vector(coords[i + 2], coords[i + 3]);
r = Vector2(coords[i + 2], coords[i + 3]);
renderEdge(anchors, normals, s, len_s, ns, q, r, halfwidth);
}
q = r;
r = is_looping ? Vector(coords[2], coords[3]) : r + s;
r = is_looping ? Vector2(coords[2], coords[3]) : r + s;
renderEdge(anchors, normals, s, len_s, ns, q, r, halfwidth);
vertex_count = normals.size();
@@ -87,7 +87,7 @@ void Polyline::render(const float *coords, size_t count, size_t size_hint, float
}
// Use a single linear array for both the regular and overdraw vertices.
vertices = new Vector[vertex_count + extra_vertices + overdraw_vertex_count];
vertices = new Vector2[vertex_count + extra_vertices + overdraw_vertex_count];
for (size_t i = 0; i < vertex_count; ++i)
vertices[i] = anchors[i] + normals[i];
@@ -107,9 +107,9 @@ void Polyline::render(const float *coords, size_t count, size_t size_hint, float
}
}
void NoneJoinPolyline::renderEdge(std::vector<Vector> &anchors, std::vector<Vector> &normals,
Vector &s, float &len_s, Vector &ns,
const Vector &q, const Vector &r, float hw)
void NoneJoinPolyline::renderEdge(std::vector<Vector2> &anchors, std::vector<Vector2> &normals,
Vector2 &s, float &len_s, Vector2 &ns,
const Vector2 &q, const Vector2 &r, float hw)
{
// ns1------ns2
// | |
@@ -170,19 +170,19 @@ void NoneJoinPolyline::renderEdge(std::vector<Vector> &anchors, std::vector<Vect
*
* the intersection points can be efficiently calculated using Cramer's rule.
*/
void MiterJoinPolyline::renderEdge(std::vector<Vector> &anchors, std::vector<Vector> &normals,
Vector &s, float &len_s, Vector &ns,
const Vector &q, const Vector &r, float hw)
void MiterJoinPolyline::renderEdge(std::vector<Vector2> &anchors, std::vector<Vector2> &normals,
Vector2 &s, float &len_s, Vector2 &ns,
const Vector2 &q, const Vector2 &r, float hw)
{
Vector t = (r - q);
Vector2 t = (r - q);
float len_t = t.getLength();
Vector nt = t.getNormal(hw / len_t);
Vector2 nt = t.getNormal(hw / len_t);
anchors.push_back(q);
anchors.push_back(q);
float det = s ^ t;
if (fabs(det) / (len_s * len_t) < LINES_PARALLEL_EPS && s * t > 0)
float det = Vector2::cross(s, t);
if (fabs(det) / (len_s * len_t) < LINES_PARALLEL_EPS && Vector2::dot(s, t) > 0)
{
// lines parallel, compute as u1 = q + ns * w/2, u2 = q - ns * w/2
normals.push_back(ns);
@@ -191,8 +191,8 @@ void MiterJoinPolyline::renderEdge(std::vector<Vector> &anchors, std::vector<Vec
else
{
// cramers rule
float lambda = ((nt - ns) ^ t) / det;
Vector d = ns + s * lambda;
float lambda = Vector2::cross((nt - ns), t) / det;
Vector2 d = ns + s * lambda;
normals.push_back(d);
normals.push_back(-d);
}
@@ -219,18 +219,18 @@ void MiterJoinPolyline::renderEdge(std::vector<Vector> &anchors, std::vector<Vec
*
* uh1 = q + ns * w/2, uh2 = q + nt * w/2
*/
void BevelJoinPolyline::renderEdge(std::vector<Vector> &anchors, std::vector<Vector> &normals,
Vector &s, float &len_s, Vector &ns,
const Vector &q, const Vector &r, float hw)
void BevelJoinPolyline::renderEdge(std::vector<Vector2> &anchors, std::vector<Vector2> &normals,
Vector2 &s, float &len_s, Vector2 &ns,
const Vector2 &q, const Vector2 &r, float hw)
{
Vector t = (r - q);
Vector2 t = (r - q);
float len_t = t.getLength();
float det = s ^ t;
if (fabs(det) / (len_s * len_t) < LINES_PARALLEL_EPS && s * t > 0)
float det = Vector2::cross(s, t);
if (fabs(det) / (len_s * len_t) < LINES_PARALLEL_EPS && Vector2::dot(s, t) > 0)
{
// lines parallel, compute as u1 = q + ns * w/2, u2 = q - ns * w/2
Vector n = t.getNormal(hw / len_t);
Vector2 n = t.getNormal(hw / len_t);
anchors.push_back(q);
anchors.push_back(q);
normals.push_back(n);
@@ -241,9 +241,9 @@ void BevelJoinPolyline::renderEdge(std::vector<Vector> &anchors, std::vector<Vec
}
// cramers rule
Vector nt= t.getNormal(hw / len_t);
float lambda = ((nt - ns) ^ t) / det;
Vector d = ns + s * lambda;
Vector2 nt= t.getNormal(hw / len_t);
float lambda = Vector2::cross((nt - ns), t) / det;
Vector2 d = ns + s * lambda;
anchors.push_back(q);
anchors.push_back(q);
@@ -273,7 +273,7 @@ void Polyline::calc_overdraw_vertex_count(bool is_looping)
overdraw_vertex_count = 2 * vertex_count + (is_looping ? 0 : 2);
}
void Polyline::render_overdraw(const std::vector<Vector> &normals, float pixel_size, bool is_looping)
void Polyline::render_overdraw(const std::vector<Vector2> &normals, float pixel_size, bool is_looping)
{
// upper segment
for (size_t i = 0; i + 1 < vertex_count; i += 2)
@@ -299,7 +299,7 @@ void Polyline::render_overdraw(const std::vector<Vector> &normals, float pixel_s
if (!is_looping)
{
// left edge
Vector spacer = (overdraw[1] - overdraw[3]);
Vector2 spacer = (overdraw[1] - overdraw[3]);
spacer.normalize(pixel_size);
overdraw[1] += spacer;
overdraw[overdraw_vertex_count - 3] += spacer;
@@ -322,7 +322,7 @@ void NoneJoinPolyline::calc_overdraw_vertex_count(bool /*is_looping*/)
overdraw_vertex_count = 4 * (vertex_count-2); // less than ideal
}
void NoneJoinPolyline::render_overdraw(const std::vector<Vector> &/*normals*/, float pixel_size, bool /*is_looping*/)
void NoneJoinPolyline::render_overdraw(const std::vector<Vector2> &/*normals*/, float pixel_size, bool /*is_looping*/)
{
for (size_t i = 2; i + 3 < vertex_count; i += 4)
{
@@ -330,8 +330,8 @@ void NoneJoinPolyline::render_overdraw(const std::vector<Vector> &/*normals*/, f
// | / | <- main quad line
// v1-v3
Vector s = vertices[i+0] - vertices[i+2];
Vector t = vertices[i+0] - vertices[i+1];
Vector2 s = vertices[i+0] - vertices[i+2];
Vector2 t = vertices[i+0] - vertices[i+1];
s.normalize(pixel_size);
t.normalize(pixel_size);
@@ -380,7 +380,7 @@ void Polyline::draw(love::graphics::Graphics *gfx)
Graphics::StreamVertexData data = gfx->requestStreamDraw(req);
const Matrix4 &t = gfx->getTransform();
t.transform((Vector *) data.stream[0], vertices, total_vertex_count);
t.transformXY((Vector2 *) data.stream[0], vertices, total_vertex_count);
Color curcolor = toColor(gfx->getColor());
Color *colordata = (Color *) data.stream[1];
+17 -17
View File
@@ -72,7 +72,7 @@ public:
protected:
virtual void calc_overdraw_vertex_count(bool is_looping);
virtual void render_overdraw(const std::vector<Vector> &normals, float pixel_size, bool is_looping);
virtual void render_overdraw(const std::vector<Vector2> &normals, float pixel_size, bool is_looping);
virtual void fill_color_array(Color constant_color, Color *colors);
/** Calculate line boundary points.
@@ -86,12 +86,12 @@ protected:
* @param[in] r Next point on the line.
* @param[in] hw Half line width (see Polyline.render()).
*/
virtual void renderEdge(std::vector<Vector> &anchors, std::vector<Vector> &normals,
Vector &s, float &len_s, Vector &ns,
const Vector &q, const Vector &r, float hw) = 0;
virtual void renderEdge(std::vector<Vector2> &anchors, std::vector<Vector2> &normals,
Vector2 &s, float &len_s, Vector2 &ns,
const Vector2 &q, const Vector2 &r, float hw) = 0;
Vector *vertices;
Vector *overdraw;
Vector2 *vertices;
Vector2 *overdraw;
size_t vertex_count;
size_t overdraw_vertex_count;
vertex::TriangleIndexMode triangle_mode;
@@ -124,7 +124,7 @@ public:
// get rasterized. These vertices are in between the core line vertices
// and the overdraw vertices in the combined vertex array, so they still
// get "rendered" since we draw everything with one draw call.
memset(&this->vertices[vertex_count - 4], 0, sizeof(love::Vector) * 4);
memset(&this->vertices[vertex_count - 4], 0, sizeof(love::Vector2) * 4);
vertex_count -= 4;
}
@@ -132,11 +132,11 @@ public:
protected:
virtual void calc_overdraw_vertex_count(bool is_looping);
virtual void render_overdraw(const std::vector<Vector> &normals, float pixel_size, bool is_looping);
virtual void render_overdraw(const std::vector<Vector2> &normals, float pixel_size, bool is_looping);
virtual void fill_color_array(Color constant_color, Color *colors);
virtual void renderEdge(std::vector<Vector> &anchors, std::vector<Vector> &normals,
Vector &s, float &len_s, Vector &ns,
const Vector &q, const Vector &r, float hw);
virtual void renderEdge(std::vector<Vector2> &anchors, std::vector<Vector2> &normals,
Vector2 &s, float &len_s, Vector2 &ns,
const Vector2 &q, const Vector2 &r, float hw);
}; // NoneJoinPolyline
@@ -156,9 +156,9 @@ public:
protected:
virtual void renderEdge(std::vector<Vector> &anchors, std::vector<Vector> &normals,
Vector &s, float &len_s, Vector &ns,
const Vector &q, const Vector &r, float hw);
virtual void renderEdge(std::vector<Vector2> &anchors, std::vector<Vector2> &normals,
Vector2 &s, float &len_s, Vector2 &ns,
const Vector2 &q, const Vector2 &r, float hw);
}; // MiterJoinPolyline
@@ -178,9 +178,9 @@ public:
protected:
virtual void renderEdge(std::vector<Vector> &anchors, std::vector<Vector> &normals,
Vector &s, float &len_s, Vector &ns,
const Vector &q, const Vector &r, float hw);
virtual void renderEdge(std::vector<Vector2> &anchors, std::vector<Vector2> &normals,
Vector2 &s, float &len_s, Vector2 &ns,
const Vector2 &q, const Vector2 &r, float hw);
}; // BevelJoinPolyline
+2 -2
View File
@@ -97,7 +97,7 @@ int SpriteBatch::add(Quad *quad, const Matrix4 &m, int index /*= -1*/)
size_t offset = (index == -1 ? next : index) * format_stride * 4;
auto verts = (XYf_STf_RGBAub *) ((uint8 *) array_buf->map() + offset);
m.transform(verts, quadverts, 4);
m.transformXY(verts, quadverts, 4);
for (int i = 0; i < 4; i++)
{
@@ -142,7 +142,7 @@ int SpriteBatch::addLayer(int layer, Quad *quad, const Matrix4 &m, int index)
size_t offset = (index == -1 ? next : index) * format_stride * 4;
auto verts = (XYf_STPf_RGBAub *) ((uint8 *) array_buf->map() + offset);
m.transform(verts, quadverts, 4);
m.transformXY(verts, quadverts, 4);
for (int i = 0; i < 4; i++)
{
+2 -2
View File
@@ -106,12 +106,12 @@ void Text::addTextData(const TextData &t)
// We only have formatted text if the align mode is valid.
if (t.align == Font::ALIGN_MAX_ENUM)
new_commands = font->generateVertices(t.codepoints, constantcolor, vertices, 0.0f, Vector(0.0f, 0.0f), &text_info);
new_commands = font->generateVertices(t.codepoints, constantcolor, vertices, 0.0f, Vector2(0.0f, 0.0f), &text_info);
else
new_commands = font->generateVerticesFormatted(t.codepoints, constantcolor, t.wrap, t.align, vertices, &text_info);
if (t.use_matrix)
t.matrix.transform(&vertices[0], &vertices[0], (int) vertices.size());
t.matrix.transformXY(&vertices[0], &vertices[0], (int) vertices.size());
size_t voffset = vert_offset;
+2 -2
View File
@@ -134,7 +134,7 @@ void Texture::draw(Graphics *gfx, Quad *q, const Matrix4 &localTransform)
const XYf_STf *quadverts = q->getVertices();
Matrix4 t(gfx->getTransform(), localTransform);
t.transform(verts, quadverts, 4);
t.transformXY(verts, quadverts, 4);
for (int i = 0; i < 4; i++)
{
@@ -176,7 +176,7 @@ void Texture::drawLayer(Graphics *gfx, int layer, Quad *q, const Matrix4 &m)
const XYf_STf *quadverts = q->getVertices();
Matrix4 t(gfx->getTransform(), m);
t.transform(verts, quadverts, 4);
t.transformXY(verts, quadverts, 4);
for (int i = 0; i < 4; i++)
{
+1 -1
View File
@@ -131,7 +131,7 @@ void Video::draw(Graphics *gfx, const Matrix4 &m)
Vertex *verts = (Vertex *) data.stream[0];
Matrix4 t(gfx->getTransform(), m);
t.transform(verts, vertices, 4);
t.transformXY(verts, vertices, 4);
Color c = toColor(gfx->getColor());
+2 -2
View File
@@ -2587,7 +2587,7 @@ int w_replaceTransform(lua_State *L)
int w_transformPoint(lua_State *L)
{
Vector p;
Vector2 p;
p.x = (float) luaL_checknumber(L, 1);
p.y = (float) luaL_checknumber(L, 2);
p = instance()->transformPoint(p);
@@ -2598,7 +2598,7 @@ int w_transformPoint(lua_State *L)
int w_inverseTransformPoint(lua_State *L)
{
Vector p;
Vector2 p;
p.x = (float) luaL_checknumber(L, 1);
p.y = (float) luaL_checknumber(L, 2);
p = instance()->inverseTransformPoint(p);
+8 -8
View File
@@ -177,9 +177,9 @@ int w_ParticleSystem_setPosition(lua_State *L)
int w_ParticleSystem_getPosition(lua_State *L)
{
ParticleSystem *t = luax_checkparticlesystem(L, 1);
love::Vector pos = t->getPosition();
lua_pushnumber(L, pos.getX());
lua_pushnumber(L, pos.getY());
love::Vector2 pos = t->getPosition();
lua_pushnumber(L, pos.x);
lua_pushnumber(L, pos.y);
return 2;
}
@@ -224,7 +224,7 @@ int w_ParticleSystem_getAreaSpread(lua_State *L)
ParticleSystem::AreaSpreadDistribution distribution = t-> getAreaSpreadDistribution();
const char *str;
ParticleSystem::getConstant(distribution, str);
const love::Vector &p = t->getAreaSpreadParameters();
const love::Vector2 &p = t->getAreaSpreadParameters();
lua_pushstring(L, str);
lua_pushnumber(L, p.x);
@@ -326,7 +326,7 @@ int w_ParticleSystem_setLinearAcceleration(lua_State *L)
int w_ParticleSystem_getLinearAcceleration(lua_State *L)
{
ParticleSystem *t = luax_checkparticlesystem(L, 1);
love::Vector min, max;
love::Vector2 min, max;
t->getLinearAcceleration(min, max);
lua_pushnumber(L, min.x);
lua_pushnumber(L, min.y);
@@ -510,9 +510,9 @@ int w_ParticleSystem_setOffset(lua_State *L)
int w_ParticleSystem_getOffset(lua_State *L)
{
ParticleSystem *t = luax_checkparticlesystem(L, 1);
love::Vector offset = t->getOffset();
lua_pushnumber(L, offset.getX());
lua_pushnumber(L, offset.getY());
love::Vector2 offset = t->getOffset();
lua_pushnumber(L, offset.x);
lua_pushnumber(L, offset.y);
return 2;
}