mirror of
https://github.com/love2d/love.git
synced 2026-08-16 00:02:12 +02:00
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:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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).
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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];
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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++)
|
||||
{
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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++)
|
||||
{
|
||||
|
||||
@@ -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());
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@ namespace
|
||||
/**
|
||||
* Subdivide Bezier polygon.
|
||||
**/
|
||||
void subdivide(vector<love::Vector> &points, int k)
|
||||
void subdivide(vector<love::Vector2> &points, int k)
|
||||
{
|
||||
if (k <= 0)
|
||||
return;
|
||||
@@ -50,7 +50,7 @@ void subdivide(vector<love::Vector> &points, int k)
|
||||
//
|
||||
// the subdivided control polygon is:
|
||||
// b00, b10, b20, b30, b21, b12, b03
|
||||
vector<love::Vector> left, right;
|
||||
vector<love::Vector2> left, right;
|
||||
left.reserve(points.size());
|
||||
right.reserve(points.size());
|
||||
|
||||
@@ -85,7 +85,7 @@ namespace math
|
||||
|
||||
love::Type BezierCurve::type("BezierCurve", &Object::type);
|
||||
|
||||
BezierCurve::BezierCurve(const vector<Vector> &pts)
|
||||
BezierCurve::BezierCurve(const vector<Vector2> &pts)
|
||||
: controlPoints(pts)
|
||||
{
|
||||
}
|
||||
@@ -97,7 +97,7 @@ BezierCurve BezierCurve::getDerivative() const
|
||||
throw Exception("Cannot derive a curve of degree < 1.");
|
||||
// actually we can, it just doesn't make any sense.
|
||||
|
||||
vector<Vector> forward_differences(controlPoints.size()-1);
|
||||
vector<Vector2> forward_differences(controlPoints.size()-1);
|
||||
float degree = float(getDegree());
|
||||
for (size_t i = 0; i < forward_differences.size(); ++i)
|
||||
forward_differences[i] = (controlPoints[i+1] - controlPoints[i]) * degree;
|
||||
@@ -105,7 +105,7 @@ BezierCurve BezierCurve::getDerivative() const
|
||||
return BezierCurve(forward_differences);
|
||||
}
|
||||
|
||||
const Vector &BezierCurve::getControlPoint(int i) const
|
||||
const Vector2 &BezierCurve::getControlPoint(int i) const
|
||||
{
|
||||
if (controlPoints.size() == 0)
|
||||
throw Exception("Curve contains no control points.");
|
||||
@@ -119,7 +119,7 @@ const Vector &BezierCurve::getControlPoint(int i) const
|
||||
return controlPoints[i];
|
||||
}
|
||||
|
||||
void BezierCurve::setControlPoint(int i, const Vector &point)
|
||||
void BezierCurve::setControlPoint(int i, const Vector2 &point)
|
||||
{
|
||||
if (controlPoints.size() == 0)
|
||||
throw Exception("Curve contains no control points.");
|
||||
@@ -133,7 +133,7 @@ void BezierCurve::setControlPoint(int i, const Vector &point)
|
||||
controlPoints[i] = point;
|
||||
}
|
||||
|
||||
void BezierCurve::insertControlPoint(const Vector &point, int i)
|
||||
void BezierCurve::insertControlPoint(const Vector2 &point, int i)
|
||||
{
|
||||
if (controlPoints.size() == 0)
|
||||
i = 0;
|
||||
@@ -161,30 +161,30 @@ void BezierCurve::removeControlPoint(int i)
|
||||
controlPoints.erase(controlPoints.begin() + i);
|
||||
}
|
||||
|
||||
void BezierCurve::translate(const Vector &t)
|
||||
void BezierCurve::translate(const Vector2 &t)
|
||||
{
|
||||
for (size_t i = 0; i < controlPoints.size(); ++i)
|
||||
controlPoints[i] += t;
|
||||
}
|
||||
|
||||
void BezierCurve::rotate(double phi, const Vector ¢er)
|
||||
void BezierCurve::rotate(double phi, const Vector2 ¢er)
|
||||
{
|
||||
float c = cos(phi), s = sin(phi);
|
||||
for (size_t i = 0; i < controlPoints.size(); ++i)
|
||||
{
|
||||
Vector v = controlPoints[i] - center;
|
||||
Vector2 v = controlPoints[i] - center;
|
||||
controlPoints[i].x = c * v.x - s * v.y + center.x;
|
||||
controlPoints[i].y = s * v.x + c * v.y + center.y;
|
||||
}
|
||||
}
|
||||
|
||||
void BezierCurve::scale(double s, const Vector ¢er)
|
||||
void BezierCurve::scale(double s, const Vector2 ¢er)
|
||||
{
|
||||
for (size_t i = 0; i < controlPoints.size(); ++i)
|
||||
controlPoints[i] = (controlPoints[i] - center) * s + center;
|
||||
}
|
||||
|
||||
Vector BezierCurve::evaluate(double t) const
|
||||
Vector2 BezierCurve::evaluate(double t) const
|
||||
{
|
||||
if (t < 0 || t > 1)
|
||||
throw Exception("Invalid evaluation parameter: must be between 0 and 1");
|
||||
@@ -192,7 +192,7 @@ Vector BezierCurve::evaluate(double t) const
|
||||
throw Exception("Invalid Bezier curve: Not enough control points.");
|
||||
|
||||
// de casteljau
|
||||
vector<Vector> points(controlPoints);
|
||||
vector<Vector2> points(controlPoints);
|
||||
for (size_t step = 1; step < controlPoints.size(); ++step)
|
||||
for (size_t i = 0; i < controlPoints.size() - step; ++i)
|
||||
points[i] = points[i] * (1-t) + points[i+1] * t;
|
||||
@@ -209,8 +209,8 @@ BezierCurve* BezierCurve::getSegment(double t1, double t2) const
|
||||
|
||||
// First, sudivide the curve at t2, then subdivide the "left"
|
||||
// sub-curve at t1/t2. The "right" curve is the segment.
|
||||
vector<Vector> points(controlPoints);
|
||||
vector<Vector> left, right;
|
||||
vector<Vector2> points(controlPoints);
|
||||
vector<Vector2> left, right;
|
||||
left.reserve(points.size());
|
||||
right.reserve(points.size());
|
||||
|
||||
@@ -238,20 +238,20 @@ BezierCurve* BezierCurve::getSegment(double t1, double t2) const
|
||||
return new BezierCurve(right);
|
||||
}
|
||||
|
||||
vector<Vector> BezierCurve::render(int accuracy) const
|
||||
vector<Vector2> BezierCurve::render(int accuracy) const
|
||||
{
|
||||
if (controlPoints.size() < 2)
|
||||
throw Exception("Invalid Bezier curve: Not enough control points.");
|
||||
vector<Vector> vertices(controlPoints);
|
||||
vector<Vector2> vertices(controlPoints);
|
||||
subdivide(vertices, accuracy);
|
||||
return vertices;
|
||||
}
|
||||
|
||||
vector<Vector> BezierCurve::renderSegment(double start, double end, int accuracy) const
|
||||
vector<Vector2> BezierCurve::renderSegment(double start, double end, int accuracy) const
|
||||
{
|
||||
if (controlPoints.size() < 2)
|
||||
throw Exception("Invalid Bezier curve: Not enough control points.");
|
||||
vector<Vector> vertices(controlPoints);
|
||||
vector<Vector2> vertices(controlPoints);
|
||||
subdivide(vertices, accuracy);
|
||||
if (start == end)
|
||||
{
|
||||
@@ -261,13 +261,13 @@ vector<Vector> BezierCurve::renderSegment(double start, double end, int accuracy
|
||||
{
|
||||
size_t start_idx = size_t(start * vertices.size());
|
||||
size_t end_idx = size_t(end * vertices.size() + 0.5);
|
||||
return std::vector<Vector>(vertices.begin() + start_idx, vertices.begin() + end_idx);
|
||||
return std::vector<Vector2>(vertices.begin() + start_idx, vertices.begin() + end_idx);
|
||||
}
|
||||
else if (end > start)
|
||||
{
|
||||
size_t start_idx = size_t(end * vertices.size() + 0.5);
|
||||
size_t end_idx = size_t(start * vertices.size());
|
||||
return std::vector<Vector>(vertices.begin() + start_idx, vertices.begin() + end_idx);
|
||||
return std::vector<Vector2>(vertices.begin() + start_idx, vertices.begin() + end_idx);
|
||||
}
|
||||
return vertices;
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ public:
|
||||
/**
|
||||
* @param controlPoints Control polygon of the curve.
|
||||
**/
|
||||
BezierCurve(const std::vector<Vector> &controlPoints);
|
||||
BezierCurve(const std::vector<Vector2> &controlPoints);
|
||||
|
||||
/**
|
||||
* @returns Degree of the curve
|
||||
@@ -58,14 +58,14 @@ public:
|
||||
/**
|
||||
* @returns i'th control point.
|
||||
**/
|
||||
const Vector &getControlPoint(int i) const;
|
||||
const Vector2 &getControlPoint(int i) const;
|
||||
|
||||
/**
|
||||
* Sets the i'th control point.
|
||||
* @param i Control point to change.
|
||||
* @param point New control point.
|
||||
**/
|
||||
void setControlPoint(int i, const Vector &point);
|
||||
void setControlPoint(int i, const Vector2 &point);
|
||||
|
||||
/**
|
||||
* Insert a new control point before the i'th control point.
|
||||
@@ -73,7 +73,7 @@ public:
|
||||
* @param point Control point to insert.
|
||||
* @param pos Position to insert.
|
||||
**/
|
||||
void insertControlPoint(const Vector &point, int pos = -1);
|
||||
void insertControlPoint(const Vector2 &point, int pos = -1);
|
||||
|
||||
/**
|
||||
* Remove the i'th control point from the curve.
|
||||
@@ -93,27 +93,27 @@ public:
|
||||
* Move the curve.
|
||||
* @param t Translation vector.
|
||||
*/
|
||||
void translate(const Vector &t);
|
||||
void translate(const Vector2 &t);
|
||||
|
||||
/**
|
||||
* Rotate the curve.
|
||||
* @param phi Rotation angle (radians).
|
||||
* @param center Rotation center.
|
||||
*/
|
||||
void rotate(double phi, const Vector ¢er);
|
||||
void rotate(double phi, const Vector2 ¢er);
|
||||
|
||||
/**
|
||||
* Scale the curve.
|
||||
* @param phi Scale factor.
|
||||
* @param center Scale center.
|
||||
*/
|
||||
void scale(double phi, const Vector ¢er);
|
||||
void scale(double phi, const Vector2 ¢er);
|
||||
|
||||
/**
|
||||
* Evaluates the curve at time t.
|
||||
* @param t Curve parameter, must satisfy 0 <= t <= 1.
|
||||
**/
|
||||
Vector evaluate(double t) const;
|
||||
Vector2 evaluate(double t) const;
|
||||
|
||||
/**
|
||||
* Get curve segment starting at t1 and ending at t2.
|
||||
@@ -129,7 +129,7 @@ public:
|
||||
* @param accuracy The 'fineness' of the curve.
|
||||
* @returns A polygon chain that approximates the bezier curve.
|
||||
**/
|
||||
std::vector<Vector> render(int accuracy = 4) const;
|
||||
std::vector<Vector2> render(int accuracy = 4) const;
|
||||
|
||||
/**
|
||||
* Renders a segment of the curve by subdivision.
|
||||
@@ -138,10 +138,10 @@ public:
|
||||
* @param accuracy The 'fineness' of the curve.
|
||||
* @returns A polygon chain that approximates the segment along the curve
|
||||
**/
|
||||
std::vector<Vector> renderSegment(double start, double end, int accuracy = 4) const;
|
||||
std::vector<Vector2> renderSegment(double start, double end, int accuracy = 4) const;
|
||||
|
||||
private:
|
||||
std::vector<Vector> controlPoints;
|
||||
std::vector<Vector2> controlPoints;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@
|
||||
#include <iostream>
|
||||
|
||||
using std::list;
|
||||
using love::Vector;
|
||||
using love::Vector2;
|
||||
|
||||
namespace
|
||||
{
|
||||
@@ -117,14 +117,14 @@ love::uint8 *hexToBytes(const char *src, size_t srclen, size_t &dstlen)
|
||||
}
|
||||
|
||||
// check if an angle is oriented counter clockwise
|
||||
inline bool is_oriented_ccw(const Vector &a, const Vector &b, const Vector &c)
|
||||
inline bool is_oriented_ccw(const Vector2 &a, const Vector2 &b, const Vector2 &c)
|
||||
{
|
||||
// return det(b-a, c-a) >= 0
|
||||
return ((b.x - a.x) * (c.y - a.y) - (b.y - a.y) * (c.x - a.x)) >= 0;
|
||||
}
|
||||
|
||||
// check if a and b are on the same side of the line c->d
|
||||
bool on_same_side(const Vector &a, const Vector &b, const Vector &c, const Vector &d)
|
||||
bool on_same_side(const Vector2 &a, const Vector2 &b, const Vector2 &c, const Vector2 &d)
|
||||
{
|
||||
float px = d.x - c.x, py = d.y - c.y;
|
||||
// return det(p, a-c) * det(p, b-c) >= 0
|
||||
@@ -134,15 +134,15 @@ bool on_same_side(const Vector &a, const Vector &b, const Vector &c, const Vecto
|
||||
}
|
||||
|
||||
// checks is p is contained in the triangle abc
|
||||
inline bool point_in_triangle(const Vector &p, const Vector &a, const Vector &b, const Vector &c)
|
||||
inline bool point_in_triangle(const Vector2 &p, const Vector2 &a, const Vector2 &b, const Vector2 &c)
|
||||
{
|
||||
return on_same_side(p,a, b,c) && on_same_side(p,b, a,c) && on_same_side(p,c, a,b);
|
||||
}
|
||||
|
||||
// checks if any vertex in `vertices' is in the triangle abc.
|
||||
bool any_point_in_triangle(const std::list<const Vector *> &vertices, const Vector &a, const Vector &b, const Vector &c)
|
||||
bool any_point_in_triangle(const std::list<const Vector2 *> &vertices, const Vector2 &a, const Vector2 &b, const Vector2 &c)
|
||||
{
|
||||
for (const Vector *p : vertices)
|
||||
for (const Vector2 *p : vertices)
|
||||
{
|
||||
if ((p != &a) && (p != &b) && (p != &c) && point_in_triangle(*p, a,b,c)) // oh god...
|
||||
return true;
|
||||
@@ -151,7 +151,7 @@ bool any_point_in_triangle(const std::list<const Vector *> &vertices, const Vect
|
||||
return false;
|
||||
}
|
||||
|
||||
inline bool is_ear(const Vector &a, const Vector &b, const Vector &c, const std::list<const Vector *> &vertices)
|
||||
inline bool is_ear(const Vector2 &a, const Vector2 &b, const Vector2 &c, const std::list<const Vector2 *> &vertices)
|
||||
{
|
||||
return is_oriented_ccw(a,b,c) && !any_point_in_triangle(vertices, a,b,c);
|
||||
}
|
||||
@@ -163,7 +163,7 @@ namespace love
|
||||
namespace math
|
||||
{
|
||||
|
||||
std::vector<Triangle> triangulate(const std::vector<love::Vector> &polygon)
|
||||
std::vector<Triangle> triangulate(const std::vector<love::Vector2> &polygon)
|
||||
{
|
||||
if (polygon.size() < 3)
|
||||
throw love::Exception("Not a polygon");
|
||||
@@ -176,7 +176,7 @@ std::vector<Triangle> triangulate(const std::vector<love::Vector> &polygon)
|
||||
size_t idx_lm = 0;
|
||||
for (size_t i = 0; i < polygon.size(); ++i)
|
||||
{
|
||||
const love::Vector &lm = polygon[idx_lm], &p = polygon[i];
|
||||
const love::Vector2 &lm = polygon[idx_lm], &p = polygon[i];
|
||||
if (p.x < lm.x || (p.x == lm.x && p.y < lm.y))
|
||||
idx_lm = i;
|
||||
next_idx[i] = i+1;
|
||||
@@ -190,7 +190,7 @@ std::vector<Triangle> triangulate(const std::vector<love::Vector> &polygon)
|
||||
next_idx.swap(prev_idx);
|
||||
|
||||
// collect list of concave polygons
|
||||
std::list<const love::Vector *> concave_vertices;
|
||||
std::list<const love::Vector2 *> concave_vertices;
|
||||
for (size_t i = 0; i < polygon.size(); ++i)
|
||||
{
|
||||
if (!is_oriented_ccw(polygon[prev_idx[i]], polygon[i], polygon[next_idx[i]]))
|
||||
@@ -205,7 +205,7 @@ std::vector<Triangle> triangulate(const std::vector<love::Vector> &polygon)
|
||||
{
|
||||
next = next_idx[current];
|
||||
prev = prev_idx[current];
|
||||
const Vector &a = polygon[prev], &b = polygon[current], &c = polygon[next];
|
||||
const Vector2 &a = polygon[prev], &b = polygon[current], &c = polygon[next];
|
||||
if (is_ear(a,b,c, concave_vertices))
|
||||
{
|
||||
triangles.push_back(Triangle(a,b,c));
|
||||
@@ -228,7 +228,7 @@ std::vector<Triangle> triangulate(const std::vector<love::Vector> &polygon)
|
||||
return triangles;
|
||||
}
|
||||
|
||||
bool isConvex(const std::vector<love::Vector> &polygon)
|
||||
bool isConvex(const std::vector<love::Vector2> &polygon)
|
||||
{
|
||||
if (polygon.size() < 3)
|
||||
return false;
|
||||
@@ -237,9 +237,9 @@ bool isConvex(const std::vector<love::Vector> &polygon)
|
||||
// turning direction can be determined using the cross-product of
|
||||
// the forward difference vectors
|
||||
size_t i = polygon.size() - 2, j = polygon.size() - 1, k = 0;
|
||||
Vector p(polygon[j].x - polygon[i].x, polygon[j].y - polygon[i].y);
|
||||
Vector q(polygon[k].x - polygon[j].x, polygon[k].y - polygon[j].y);
|
||||
float winding = p ^ q;
|
||||
Vector2 p(polygon[j].x - polygon[i].x, polygon[j].y - polygon[i].y);
|
||||
Vector2 q(polygon[k].x - polygon[j].x, polygon[k].y - polygon[j].y);
|
||||
float winding = Vector2::cross(p, q);
|
||||
|
||||
while (k+1 < polygon.size())
|
||||
{
|
||||
@@ -249,7 +249,7 @@ bool isConvex(const std::vector<love::Vector> &polygon)
|
||||
q.x = polygon[k].x - polygon[j].x;
|
||||
q.y = polygon[k].y - polygon[j].y;
|
||||
|
||||
if ((p^q) * winding < 0)
|
||||
if (Vector2::cross(p, q) * winding < 0)
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@@ -370,7 +370,7 @@ RandomGenerator *Math::newRandomGenerator()
|
||||
return new RandomGenerator();
|
||||
}
|
||||
|
||||
BezierCurve *Math::newBezierCurve(const std::vector<Vector> &points)
|
||||
BezierCurve *Math::newBezierCurve(const std::vector<Vector2> &points)
|
||||
{
|
||||
return new BezierCurve(points);
|
||||
}
|
||||
|
||||
@@ -49,10 +49,10 @@ class Transform;
|
||||
|
||||
struct Triangle
|
||||
{
|
||||
Triangle(const Vector &x, const Vector &y, const Vector &z)
|
||||
Triangle(const Vector2 &x, const Vector2 &y, const Vector2 &z)
|
||||
: a(x), b(y), c(z)
|
||||
{}
|
||||
Vector a, b, c;
|
||||
Vector2 a, b, c;
|
||||
};
|
||||
|
||||
enum EncodeFormat
|
||||
@@ -68,7 +68,7 @@ enum EncodeFormat
|
||||
* @param polygon Polygon to triangulate. Must not intersect itself.
|
||||
* @return List of triangles the polygon is composed of.
|
||||
**/
|
||||
std::vector<Triangle> triangulate(const std::vector<love::Vector> &polygon);
|
||||
std::vector<Triangle> triangulate(const std::vector<love::Vector2> &polygon);
|
||||
|
||||
/**
|
||||
* Checks whether a polygon is convex.
|
||||
@@ -76,7 +76,7 @@ std::vector<Triangle> triangulate(const std::vector<love::Vector> &polygon);
|
||||
* @param polygon Polygon to test.
|
||||
* @return True if the polygon is convex, false otherwise.
|
||||
**/
|
||||
bool isConvex(const std::vector<love::Vector> &polygon);
|
||||
bool isConvex(const std::vector<love::Vector2> &polygon);
|
||||
|
||||
/**
|
||||
* Converts a value from the sRGB (gamma) colorspace to linear RGB.
|
||||
@@ -175,7 +175,7 @@ public:
|
||||
/**
|
||||
* Creates a new bezier curve.
|
||||
**/
|
||||
BezierCurve *newBezierCurve(const std::vector<Vector> &points);
|
||||
BezierCurve *newBezierCurve(const std::vector<Vector2> &points);
|
||||
|
||||
Transform *newTransform();
|
||||
Transform *newTransform(float x, float y, float a, float sx, float sy, float ox, float oy, float kx, float ky);
|
||||
|
||||
@@ -104,17 +104,17 @@ void Transform::setTransformation(float x, float y, float a, float sx, float sy,
|
||||
inverseDirty = true;
|
||||
}
|
||||
|
||||
love::Vector Transform::transformPoint(love::Vector p) const
|
||||
love::Vector2 Transform::transformPoint(love::Vector2 p) const
|
||||
{
|
||||
love::Vector result;
|
||||
matrix.transform(&result, &p, 1);
|
||||
love::Vector2 result;
|
||||
matrix.transformXY(&result, &p, 1);
|
||||
return result;
|
||||
}
|
||||
|
||||
love::Vector Transform::inverseTransformPoint(love::Vector p)
|
||||
love::Vector2 Transform::inverseTransformPoint(love::Vector2 p)
|
||||
{
|
||||
love::Vector result;
|
||||
getInverseMatrix().transform(&result, &p, 1);
|
||||
love::Vector2 result;
|
||||
getInverseMatrix().transformXY(&result, &p, 1);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@@ -55,8 +55,8 @@ public:
|
||||
void reset();
|
||||
void setTransformation(float x, float y, float a, float sx, float sy, float ox, float oy, float kx, float ky);
|
||||
|
||||
love::Vector transformPoint(love::Vector p) const;
|
||||
love::Vector inverseTransformPoint(love::Vector p);
|
||||
love::Vector2 transformPoint(love::Vector2 p) const;
|
||||
love::Vector2 inverseTransformPoint(love::Vector2 p);
|
||||
|
||||
const Matrix4 &getMatrix() const;
|
||||
void setMatrix(const Matrix4 &m);
|
||||
|
||||
@@ -58,7 +58,7 @@ int w_BezierCurve_getControlPoint(lua_State *L)
|
||||
idx--;
|
||||
|
||||
luax_catchexcept(L, [&]() {
|
||||
Vector v = curve->getControlPoint(idx);
|
||||
Vector2 v = curve->getControlPoint(idx);
|
||||
lua_pushnumber(L, v.x);
|
||||
lua_pushnumber(L, v.y);
|
||||
});
|
||||
@@ -76,7 +76,7 @@ int w_BezierCurve_setControlPoint(lua_State *L)
|
||||
if (idx > 0) // 1-indexing
|
||||
idx--;
|
||||
|
||||
luax_catchexcept(L, [&](){ curve->setControlPoint(idx, Vector(vx,vy)); });
|
||||
luax_catchexcept(L, [&](){ curve->setControlPoint(idx, Vector2(vx,vy)); });
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -90,7 +90,7 @@ int w_BezierCurve_insertControlPoint(lua_State *L)
|
||||
if (idx > 0) // 1-indexing
|
||||
idx--;
|
||||
|
||||
luax_catchexcept(L, [&](){ curve->insertControlPoint(Vector(vx,vy), idx); });
|
||||
luax_catchexcept(L, [&](){ curve->insertControlPoint(Vector2(vx,vy), idx); });
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -118,7 +118,7 @@ int w_BezierCurve_translate(lua_State *L)
|
||||
BezierCurve *curve = luax_checkbeziercurve(L, 1);
|
||||
float dx = (float) luaL_checknumber(L, 2);
|
||||
float dy = (float) luaL_checknumber(L, 3);
|
||||
curve->translate(Vector(dx,dy));
|
||||
curve->translate(Vector2(dx,dy));
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -128,7 +128,7 @@ int w_BezierCurve_rotate(lua_State *L)
|
||||
double phi = luaL_checknumber(L, 2);
|
||||
float ox = (float) luaL_optnumber(L, 3, 0);
|
||||
float oy = (float) luaL_optnumber(L, 4, 0);
|
||||
curve->rotate(phi, Vector(ox,oy));
|
||||
curve->rotate(phi, Vector2(ox,oy));
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -138,7 +138,7 @@ int w_BezierCurve_scale(lua_State *L)
|
||||
double s = luaL_checknumber(L, 2);
|
||||
float ox = (float) luaL_optnumber(L, 3, 0);
|
||||
float oy = (float) luaL_optnumber(L, 4, 0);
|
||||
curve->scale(s, Vector(ox,oy));
|
||||
curve->scale(s, Vector2(ox,oy));
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -148,7 +148,7 @@ int w_BezierCurve_evaluate(lua_State *L)
|
||||
double t = luaL_checknumber(L, 2);
|
||||
|
||||
luax_catchexcept(L, [&]() {
|
||||
Vector v = curve->evaluate(t);
|
||||
Vector2 v = curve->evaluate(t);
|
||||
lua_pushnumber(L, v.x);
|
||||
lua_pushnumber(L, v.y);
|
||||
});
|
||||
@@ -176,7 +176,7 @@ int w_BezierCurve_render(lua_State *L)
|
||||
BezierCurve *curve = luax_checkbeziercurve(L, 1);
|
||||
int accuracy = (int) luaL_optnumber(L, 2, 5);
|
||||
|
||||
std::vector<Vector> points;
|
||||
std::vector<Vector2> points;
|
||||
luax_catchexcept(L, [&](){ points = curve->render(accuracy); });
|
||||
|
||||
lua_createtable(L, (int) points.size() * 2, 0);
|
||||
@@ -198,7 +198,7 @@ int w_BezierCurve_renderSegment(lua_State *L)
|
||||
double end = luaL_checknumber(L, 3);
|
||||
int accuracy = (int) luaL_optnumber(L, 4, 5);
|
||||
|
||||
std::vector<Vector> points;
|
||||
std::vector<Vector2> points;
|
||||
luax_catchexcept(L, [&](){ points = curve->renderSegment(start, end, accuracy); });
|
||||
|
||||
lua_createtable(L, (int) points.size() * 2, 0);
|
||||
|
||||
@@ -83,7 +83,7 @@ int w_newRandomGenerator(lua_State *L)
|
||||
|
||||
int w_newBezierCurve(lua_State *L)
|
||||
{
|
||||
std::vector<Vector> points;
|
||||
std::vector<Vector2> points;
|
||||
if (lua_istable(L, 1))
|
||||
{
|
||||
int top = (int) luax_objlen(L, 1);
|
||||
@@ -93,7 +93,7 @@ int w_newBezierCurve(lua_State *L)
|
||||
lua_rawgeti(L, 1, i);
|
||||
lua_rawgeti(L, 1, i+1);
|
||||
|
||||
Vector v;
|
||||
Vector2 v;
|
||||
v.x = (float) luaL_checknumber(L, -2);
|
||||
v.y = (float) luaL_checknumber(L, -1);
|
||||
points.push_back(v);
|
||||
@@ -107,7 +107,7 @@ int w_newBezierCurve(lua_State *L)
|
||||
points.reserve(top / 2);
|
||||
for (int i = 1; i <= top; i += 2)
|
||||
{
|
||||
Vector v;
|
||||
Vector2 v;
|
||||
v.x = (float) luaL_checknumber(L, i);
|
||||
v.y = (float) luaL_checknumber(L, i+1);
|
||||
points.push_back(v);
|
||||
@@ -147,7 +147,7 @@ int w_newTransform(lua_State *L)
|
||||
|
||||
int w_triangulate(lua_State *L)
|
||||
{
|
||||
std::vector<love::Vector> vertices;
|
||||
std::vector<love::Vector2> vertices;
|
||||
if (lua_istable(L, 1))
|
||||
{
|
||||
int top = (int) luax_objlen(L, 1);
|
||||
@@ -157,7 +157,7 @@ int w_triangulate(lua_State *L)
|
||||
lua_rawgeti(L, 1, i);
|
||||
lua_rawgeti(L, 1, i+1);
|
||||
|
||||
Vector v;
|
||||
Vector2 v;
|
||||
v.x = (float) luaL_checknumber(L, -2);
|
||||
v.y = (float) luaL_checknumber(L, -1);
|
||||
vertices.push_back(v);
|
||||
@@ -171,7 +171,7 @@ int w_triangulate(lua_State *L)
|
||||
vertices.reserve(top / 2);
|
||||
for (int i = 1; i <= top; i += 2)
|
||||
{
|
||||
Vector v;
|
||||
Vector2 v;
|
||||
v.x = (float) luaL_checknumber(L, i);
|
||||
v.y = (float) luaL_checknumber(L, i+1);
|
||||
vertices.push_back(v);
|
||||
@@ -217,7 +217,7 @@ int w_triangulate(lua_State *L)
|
||||
|
||||
int w_isConvex(lua_State *L)
|
||||
{
|
||||
std::vector<love::Vector> vertices;
|
||||
std::vector<love::Vector2> vertices;
|
||||
if (lua_istable(L, 1))
|
||||
{
|
||||
int top = (int) luax_objlen(L, 1);
|
||||
@@ -227,7 +227,7 @@ int w_isConvex(lua_State *L)
|
||||
lua_rawgeti(L, 1, i);
|
||||
lua_rawgeti(L, 1, i+1);
|
||||
|
||||
love::Vector v;
|
||||
love::Vector2 v;
|
||||
v.x = (float) luaL_checknumber(L, -2);
|
||||
v.y = (float) luaL_checknumber(L, -1);
|
||||
vertices.push_back(v);
|
||||
@@ -241,7 +241,7 @@ int w_isConvex(lua_State *L)
|
||||
vertices.reserve(top / 2);
|
||||
for (int i = 1; i <= top; i += 2)
|
||||
{
|
||||
love::Vector v;
|
||||
love::Vector2 v;
|
||||
v.x = (float) luaL_checknumber(L, i);
|
||||
v.y = (float) luaL_checknumber(L, i+1);
|
||||
vertices.push_back(v);
|
||||
|
||||
@@ -255,7 +255,7 @@ int w_Transform_getMatrix(lua_State *L)
|
||||
int w_Transform_transformPoint(lua_State *L)
|
||||
{
|
||||
Transform *t = luax_checktransform(L, 1);
|
||||
love::Vector p;
|
||||
love::Vector2 p;
|
||||
p.x = (float) luaL_checknumber(L, 2);
|
||||
p.y = (float) luaL_checknumber(L, 3);
|
||||
p = t->transformPoint(p);
|
||||
@@ -267,7 +267,7 @@ int w_Transform_transformPoint(lua_State *L)
|
||||
int w_Transform_inverseTransformPoint(lua_State *L)
|
||||
{
|
||||
Transform *t = luax_checktransform(L, 1);
|
||||
love::Vector p;
|
||||
love::Vector2 p;
|
||||
p.x = (float) luaL_checknumber(L, 2);
|
||||
p.y = (float) luaL_checknumber(L, 3);
|
||||
p = t->inverseTransformPoint(p);
|
||||
|
||||
Reference in New Issue
Block a user