From ac697ddb0f226671e3e40a7c12986d35230287b2 Mon Sep 17 00:00:00 2001 From: Alex Szpakowski Date: Tue, 16 May 2017 22:07:01 -0300 Subject: [PATCH] =?UTF-8?q?Clean=20up=20love=E2=80=99s=20internal=20Vector?= =?UTF-8?q?=20code=20a=20bit,=20and=20rename=20it=20to=20Vector2=20so=20it?= =?UTF-8?q?=E2=80=99s=20more=20obvious=20what=20it=20is.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --HG-- branch : minor --- src/common/Matrix.h | 50 ++- src/common/Vector.h | 364 +++++++++++-------- src/modules/graphics/Font.cpp | 6 +- src/modules/graphics/Font.h | 2 +- src/modules/graphics/Graphics.cpp | 18 +- src/modules/graphics/Graphics.h | 4 +- src/modules/graphics/ParticleSystem.cpp | 90 ++--- src/modules/graphics/ParticleSystem.h | 28 +- src/modules/graphics/Polyline.cpp | 76 ++-- src/modules/graphics/Polyline.h | 34 +- src/modules/graphics/SpriteBatch.cpp | 4 +- src/modules/graphics/Text.cpp | 4 +- src/modules/graphics/Texture.cpp | 4 +- src/modules/graphics/Video.cpp | 2 +- src/modules/graphics/wrap_Graphics.cpp | 4 +- src/modules/graphics/wrap_ParticleSystem.cpp | 16 +- src/modules/math/BezierCurve.cpp | 42 +-- src/modules/math/BezierCurve.h | 22 +- src/modules/math/MathModule.cpp | 34 +- src/modules/math/MathModule.h | 10 +- src/modules/math/Transform.cpp | 12 +- src/modules/math/Transform.h | 4 +- src/modules/math/wrap_BezierCurve.cpp | 18 +- src/modules/math/wrap_Math.cpp | 18 +- src/modules/math/wrap_Transform.cpp | 4 +- 25 files changed, 486 insertions(+), 384 deletions(-) diff --git a/src/common/Matrix.h b/src/common/Matrix.h index 07af79018..1a82fc021 100644 --- a/src/common/Matrix.h +++ b/src/common/Matrix.h @@ -185,19 +185,22 @@ public: void shear(float kx, float ky); /** - * Transforms an array of vertices by this Matrix. The sources and - * destination arrays may be the same. - * - * @param dst Storage for the transformed vertices. - * @param src The source vertices. - * @param size The number of vertices. + * Transforms an array of 2-component vertices by this Matrix. The source + * and destination arrays may be the same. **/ template - void transform(Vdst *dst, const Vsrc *src, int size) const; + void transformXY(Vdst *dst, const Vsrc *src, int size) const; + + /** + * Transforms an array of 3-component vertices by this Matrix. The source + * and destination arrays may be the same. + **/ + template + void transformXYZ(Vdst *dst, const Vsrc *src, int size) const; /** * Gets whether this matrix is an affine 2D transform (if the only non- - * identity elements are the upper-left 4x4 and 2 translation values in the + * identity elements are the upper-left 2x2 and 2 translation values in the * 4th column). **/ bool isAffine2DTransform() const; @@ -281,7 +284,7 @@ public: * Transforms an array of vertices by this matrix. **/ template - void transform(Vdst *dst, const Vsrc *src, int size) const; + void transformXY(Vdst *dst, const Vsrc *src, int size) const; private: @@ -304,7 +307,7 @@ private: // | e3 e7 e11 e15 | template -void Matrix4::transform(Vdst *dst, const Vsrc *src, int size) const +void Matrix4::transformXY(Vdst *dst, const Vsrc *src, int size) const { for (int i = 0; i < size; i++) { @@ -317,6 +320,31 @@ void Matrix4::transform(Vdst *dst, const Vsrc *src, int size) const } } +// | x | +// | y | +// | z | +// | 1 | +// | e0 e4 e8 e12 | +// | e1 e5 e9 e13 | +// | e2 e6 e10 e14 | +// | e3 e7 e11 e15 | + +template +void Matrix4::transformXYZ(Vdst *dst, const Vsrc *src, int size) const +{ + for (int i = 0; i < size; i++) + { + // Store in temp variables in case src = dst + float x = (e[0]*src[i].x) + (e[4]*src[i].y) + (e[ 8]*src[i].z) + (e[12]); + float y = (e[1]*src[i].x) + (e[5]*src[i].y) + (e[ 9]*src[i].z) + (e[13]); + float z = (e[2]*src[i].x) + (e[6]*src[i].y) + (e[10]*src[i].z) + (e[14]); + + dst[i].x = x; + dst[i].y = y; + dst[i].z = z; + } +} + // | x | // | y | // | 1 | @@ -324,7 +352,7 @@ void Matrix4::transform(Vdst *dst, const Vsrc *src, int size) const // | e1 e4 e7 | // | e2 e5 e8 | template -void Matrix3::transform(Vdst *dst, const Vsrc *src, int size) const +void Matrix3::transformXY(Vdst *dst, const Vsrc *src, int size) const { for (int i = 0; i < size; i++) { diff --git a/src/common/Vector.h b/src/common/Vector.h index cd85bcf9a..5a94860f5 100644 --- a/src/common/Vector.h +++ b/src/common/Vector.h @@ -24,45 +24,26 @@ // STD #include -// LOVE -#include "Matrix.h" - namespace love { -/** - * 2D Vector class. - * - * @author Anders Ruud - * @date 2006-05-13 - **/ -class Vector +struct Vector2 { -public: - - // The components. float x, y; - /** - * Creates a new (1,1) Vector. - **/ - Vector(); + Vector2() + : x(0.0f), y(0.0f) + {} - /** - * Creates a new Vector. - * @param x The x position/dimension. - * @param y The y position/dimension. - **/ - Vector(float x, float y); + Vector2(float x, float y) + : x(x), y(y) + {} /** * Gets the length of the Vector. - * @return The length of the Vector. - * - * This method requires sqrtf() and should be used - * carefully. **/ float getLength() const; + float getLengthSquare() const; /** * Normalizes the Vector. @@ -76,7 +57,7 @@ public: * To get the true (normalized) normal, use v.getNormal(1.0f / v.getLength()) * @return A normal to the Vector. **/ - Vector getNormal() const; + Vector2 getNormal() const; /** * Gets a vector perpendicular to the Vector. @@ -84,132 +65,177 @@ public: * @param scale factor to apply. * @return A normal to the Vector. **/ - Vector getNormal(float scale) const; + Vector2 getNormal(float scale) const; - float cross(const Vector &v) const; + static inline float dot(const Vector2 &a, const Vector2 &b); + static inline float cross(const Vector2 &a, const Vector2 &b); /** * Adds a Vector to this Vector. - * @param v The Vector we want to add to this Vector. - * @return The resulting Vector. **/ - Vector operator + (const Vector &v) const; + Vector2 operator + (const Vector2 &v) const; /** - * Substracts a Vector to this Vector. - * @param v The Vector we want to subtract to this Vector. - * @return The resulting Vector. + * Substracts a Vector from this Vector. **/ - Vector operator - (const Vector &v) const; + Vector2 operator - (const Vector2 &v) const; /** - * Resizes a Vector by a scalar. - * @param s The scalar with which to resize the Vector. - * @return The resulting Vector. + * Component-wise multiplies the Vector by a scalar. **/ - Vector operator * (float s) const; + Vector2 operator * (float s) const; /** - * Resizes a Vector by a scalar. - * @param s The scalar with which to resize the Vector. - * @return The resulting Vector. + * Component-wise divides the Vector by a scalar. **/ - Vector operator / (float s) const; + Vector2 operator / (float s) const; /** - * Reverses the Vector. - * @return The reversed Vector. + * Component-wise negates the Vector. **/ - Vector operator - () const; + Vector2 operator - () const; /** * Adds a Vector to this Vector, and also saves changes in the first Vector. - * @param v The Vector we want to add to this Vector. **/ - void operator += (const Vector &v); + void operator += (const Vector2 &v); /** * Subtracts a Vector to this Vector, and also saves changes in the first Vector. - * @param v The Vector we want to subtract to this Vector. **/ - void operator -= (const Vector &v); + void operator -= (const Vector2 &v); /** * Resizes the Vector, and also saves changes in the first Vector. - * @param s The scalar by which we want to resize the Vector. **/ void operator *= (float s); /** * Resizes the Vector, and also saves changes in the first Vector. - * @param s The scalar by which we want to resize the Vector. **/ void operator /= (float s); - /** - * Calculates the dot product of two Vectors. - * @return The dot product of the two Vectors. - **/ - float operator * (const Vector &v) const; + bool operator == (const Vector2 &v) const; + bool operator != (const Vector2 &v) const; + +}; // Vector2 + + +struct Vector3 +{ + float x, y, z; + + Vector3() + : x(0.0f), y(0.0f), z(0.0f) + {} + + Vector3(float x, float y, float z) + : x(x), y(y), z(z) + {} + + Vector3(const Vector2 &v) + : x(v.x), y(v.y), z(0.0f) + {} /** - * Calculates the cross product of two Vectors. - * @return The cross product of the two Vectors. + * Gets the length of the Vector. **/ - float operator ^ (const Vector &v) const; - - bool operator == (const Vector &v) const; - - bool operator < (const Vector &v) const; - /** - * Gets the x value of the Vector. - * @return The x value of the Vector. - **/ - float getX() const; + float getLength() const; + float getLengthSquare() const; /** - * Gets the x value of the Vector. - * @return The x value of the Vector. + * Normalizes the Vector. + * @param length Desired length of the vector. + * @return The old length of the Vector. **/ - float getY() const; + float normalize(float length = 1.0); + + static inline float dot(const Vector3 &a, const Vector3 &b); + static inline Vector3 cross(const Vector3 &a, const Vector3 &b); /** - * Sets the x value of the Vector. - * @param x The x value of the Vector. + * Adds a Vector to this Vector. **/ - void setX(float x); + Vector3 operator + (const Vector3 &v) const; /** - * Sets the x value of the Vector. - * @param y The x value of the Vector. + * Substracts a Vector from this Vector. **/ - void setY(float y); + Vector3 operator - (const Vector3 &v) const; -}; + /** + * Component-wise multiplies the Vector by a scalar. + **/ + Vector3 operator * (float s) const; -inline float Vector::getLength() const + /** + * Component-wise divides the Vector by a scalar. + **/ + Vector3 operator / (float s) const; + + /** + * Component-wise negates the Vector. + **/ + Vector3 operator - () const; + + /** + * Adds a Vector to this Vector, and also saves changes in the first Vector. + **/ + void operator += (const Vector3 &v); + + /** + * Subtracts a Vector to this Vector, and also saves changes in the first Vector. + **/ + void operator -= (const Vector3 &v); + + /** + * Resizes the Vector, and also saves changes in the first Vector. + **/ + void operator *= (float s); + + /** + * Resizes the Vector, and also saves changes in the first Vector. + **/ + void operator /= (float s); + + bool operator == (const Vector3 &v) const; + bool operator != (const Vector3 &v) const; + +}; // Vector3 + + +inline float Vector2::getLength() const { return sqrtf(x*x + y*y); } -inline Vector Vector::getNormal() const +inline float Vector2::getLengthSquare() const { - return Vector(-y, x); + return x*x + y*y; } -inline Vector Vector::getNormal(float scale) const +inline Vector2 Vector2::getNormal() const { - return Vector(-y * scale, x * scale); + return Vector2(-y, x); } -inline float Vector::cross(const Vector &v) const +inline Vector2 Vector2::getNormal(float scale) const { - return x * v.getY() - y * v.getX(); + return Vector2(-y * scale, x * scale); } -inline float Vector::normalize(float length) +inline float Vector2::dot(const Vector2 &a, const Vector2 &b) { + return a.x * b.x + a.y * b.y; +} +inline float Vector2::cross(const Vector2 &a, const Vector2 &b) +{ + return a.x * b.y - a.y * b.x; +} + +inline float Vector2::normalize(float length) +{ float length_current = getLength(); if (length_current > 0) @@ -218,113 +244,161 @@ inline float Vector::normalize(float length) return length_current; } -/** - * Inline methods must have body in header. - **/ - -inline Vector::Vector() - : x(0.0f) - , y(0.0f) +inline Vector2 Vector2::operator + (const Vector2 &v) const { + return Vector2(x + v.x, y + v.y); } -inline Vector::Vector(float x, float y) - : x(x) - , y(y) +inline Vector2 Vector2::operator - (const Vector2 &v) const { + return Vector2(x - v.x, y - v.y); } -inline Vector Vector::operator + (const Vector &v) const +inline Vector2 Vector2::operator * (float s) const { - return Vector(x + v.x, y + v.y); + return Vector2(x*s, y*s); } -inline Vector Vector::operator - (const Vector &v) const +inline Vector2 Vector2::operator / (float s) const { - return Vector(x - v.getX(), y - v.getY()); + float invs = 1.0f / s; + return Vector2(x*invs, y*invs); } -inline Vector Vector::operator * (float s) const +inline Vector2 Vector2::operator - () const { - return Vector(x*s, y*s); + return Vector2(-x, -y); } -inline Vector Vector::operator / (float s) const +inline void Vector2::operator += (const Vector2 &v) { - return Vector(x/s, y/s); + x += v.x; + y += v.y; } -inline Vector Vector::operator - () const +inline void Vector2::operator -= (const Vector2 &v) { - return Vector(-x, -y); + x -= v.x; + y -= v.y; } -inline void Vector::operator += (const Vector &v) -{ - x += v.getX(); - y += v.getY(); -} - -inline void Vector::operator -= (const Vector &v) -{ - x -= v.getX(); - y -= v.getY(); -} - -inline void Vector::operator *= (float s) +inline void Vector2::operator *= (float s) { x *= s; y *= s; } -inline void Vector::operator /= (float s) +inline void Vector2::operator /= (float s) { - x /= s; - y /= s; + float invs = 1.0f / s; + x *= invs; + y *= invs; } -inline float Vector::operator * (const Vector &v) const +inline bool Vector2::operator == (const Vector2 &v) const { - return x * v.getX() + y * v.getY(); + return x == v.x && y == v.y; } -inline float Vector::operator ^ (const Vector &v) const +inline bool Vector2::operator != (const Vector2 &v) const { - return cross(v); + return x != v.x || y != v.y; } -inline bool Vector::operator == (const Vector &v) const + +inline float Vector3::getLength() const { - return getLength() == v.getLength(); + return sqrtf(x*x + y*y + z*z); } -inline bool Vector::operator < (const Vector &v) const +inline float Vector3::getLengthSquare() const { - return getLength() < v.getLength(); + return x*x + y*y + z*z; } -/** - * Accessor methods - **/ - -inline float Vector::getX() const +inline float Vector3::dot(const Vector3 &a, const Vector3 &b) { - return x; + return a.x * b.x + a.y * b.y + a.z * b.z; } -inline float Vector::getY() const +inline Vector3 Vector3::cross(const Vector3 &a, const Vector3 &b) { - return y; + return Vector3(a.y*b.z - a.z*b.y, a.z*b.x - a.x*b.z, a.x*b.y - a.y*b.x); } -inline void Vector::setX(float x) +inline float Vector3::normalize(float length) { - this->x = x; + float length_current = getLength(); + + if (length_current > 0) + (*this) *= length / length_current; + + return length_current; } -inline void Vector::setY(float y) +inline Vector3 Vector3::operator + (const Vector3 &v) const { - this->y = y; + return Vector3(x + v.x, y + v.y, z + v.z); +} + +inline Vector3 Vector3::operator - (const Vector3 &v) const +{ + return Vector3(x - v.x, y - v.y, z - v.z); +} + +inline Vector3 Vector3::operator * (float s) const +{ + return Vector3(x*s, y*s, z*s); +} + +inline Vector3 Vector3::operator / (float s) const +{ + float invs = 1.0f / s; + return Vector3(x*invs, y*invs, z*invs); +} + +inline Vector3 Vector3::operator - () const +{ + return Vector3(-x, -y, -z); +} + +inline void Vector3::operator += (const Vector3 &v) +{ + x += v.x; + y += v.y; + z += v.z; +} + +inline void Vector3::operator -= (const Vector3 &v) +{ + x -= v.x; + y -= v.y; + z -= v.z; +} + +inline void Vector3::operator *= (float s) +{ + x *= s; + y *= s; + z *= s; +} + +inline void Vector3::operator /= (float s) +{ + float invs = 1.0f / s; + x *= invs; + y *= invs; + z *= invs; +} + +inline bool Vector3::operator == (const Vector3 &v) const +{ + return x == v.x && y == v.y && z == v.z; +} + +inline bool Vector3::operator != (const Vector3 &v) const +{ + return x != v.x || y != v.y || z != v.z; } } //love diff --git a/src/modules/graphics/Font.cpp b/src/modules/graphics/Font.cpp index 0268d21d6..2b0bf2a39 100644 --- a/src/modules/graphics/Font.cpp +++ b/src/modules/graphics/Font.cpp @@ -373,7 +373,7 @@ float Font::getHeight() const return (float) floorf(height / pixelDensity + 0.5f); } -std::vector Font::generateVertices(const ColoredCodepoints &codepoints, const Colorf &constantcolor, std::vector &vertices, float extra_spacing, Vector offset, TextInfo *info) +std::vector Font::generateVertices(const ColoredCodepoints &codepoints, const Colorf &constantcolor, std::vector &vertices, float extra_spacing, Vector2 offset, TextInfo *info) { // Spacing counter and newline handling. float dx = offset.x; @@ -534,7 +534,7 @@ std::vector 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 generateVertices(const ColoredCodepoints &codepoints, const Colorf &constantColor, std::vector &vertices, - float extra_spacing = 0.0f, Vector offset = {}, TextInfo *info = nullptr); + float extra_spacing = 0.0f, Vector2 offset = {}, TextInfo *info = nullptr); std::vector generateVerticesFormatted(const ColoredCodepoints &text, const Colorf &constantColor, float wrap, AlignMode align, std::vector &vertices, TextInfo *info = nullptr); diff --git a/src/modules/graphics/Graphics.cpp b/src/modules/graphics/Graphics.cpp index 30337f113..6393b44dc 100644 --- a/src/modules/graphics/Graphics.cpp +++ b/src/modules/graphics/Graphics.cpp @@ -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; } diff --git a/src/modules/graphics/Graphics.h b/src/modules/graphics/Graphics.h index 51f7ebe7b..195bb7dfc 100644 --- a/src/modules/graphics/Graphics.h +++ b/src/modules/graphics/Graphics.h @@ -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); diff --git a/src/modules/graphics/ParticleSystem.cpp b/src/modules/graphics/ParticleSystem.cpp index 2e1070fa7..9c69133ad 100644 --- a/src/modules/graphics/ParticleSystem.cpp +++ b/src/modules/graphics/ParticleSystem.cpp @@ -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). diff --git a/src/modules/graphics/ParticleSystem.h b/src/modules/graphics/ParticleSystem.h index 67db4353a..a60edf1fe 100644 --- a/src/modules/graphics/ParticleSystem.h +++ b/src/modules/graphics/ParticleSystem.h @@ -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; diff --git a/src/modules/graphics/Polyline.cpp b/src/modules/graphics/Polyline.cpp index 031f4276e..c87d2ce77 100644 --- a/src/modules/graphics/Polyline.cpp +++ b/src/modules/graphics/Polyline.cpp @@ -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 anchors; + static std::vector anchors; anchors.clear(); anchors.reserve(size_hint); - static std::vector normals; + static std::vector 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 &anchors, std::vector &normals, - Vector &s, float &len_s, Vector &ns, - const Vector &q, const Vector &r, float hw) +void NoneJoinPolyline::renderEdge(std::vector &anchors, std::vector &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 &anchors, std::vector &anchors, std::vector &normals, - Vector &s, float &len_s, Vector &ns, - const Vector &q, const Vector &r, float hw) +void MiterJoinPolyline::renderEdge(std::vector &anchors, std::vector &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 &anchors, std::vector &anchors, std::vector &anchors, std::vector &normals, - Vector &s, float &len_s, Vector &ns, - const Vector &q, const Vector &r, float hw) +void BevelJoinPolyline::renderEdge(std::vector &anchors, std::vector &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 &anchors, std::vector &normals, float pixel_size, bool is_looping) +void Polyline::render_overdraw(const std::vector &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 &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 &/*normals*/, float pixel_size, bool /*is_looping*/) +void NoneJoinPolyline::render_overdraw(const std::vector &/*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 &/*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]; diff --git a/src/modules/graphics/Polyline.h b/src/modules/graphics/Polyline.h index a9031b511..9bdc2ab6a 100644 --- a/src/modules/graphics/Polyline.h +++ b/src/modules/graphics/Polyline.h @@ -72,7 +72,7 @@ public: protected: virtual void calc_overdraw_vertex_count(bool is_looping); - virtual void render_overdraw(const std::vector &normals, float pixel_size, bool is_looping); + virtual void render_overdraw(const std::vector &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 &anchors, std::vector &normals, - Vector &s, float &len_s, Vector &ns, - const Vector &q, const Vector &r, float hw) = 0; + virtual void renderEdge(std::vector &anchors, std::vector &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 &normals, float pixel_size, bool is_looping); + virtual void render_overdraw(const std::vector &normals, float pixel_size, bool is_looping); virtual void fill_color_array(Color constant_color, Color *colors); - virtual void renderEdge(std::vector &anchors, std::vector &normals, - Vector &s, float &len_s, Vector &ns, - const Vector &q, const Vector &r, float hw); + virtual void renderEdge(std::vector &anchors, std::vector &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 &anchors, std::vector &normals, - Vector &s, float &len_s, Vector &ns, - const Vector &q, const Vector &r, float hw); + virtual void renderEdge(std::vector &anchors, std::vector &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 &anchors, std::vector &normals, - Vector &s, float &len_s, Vector &ns, - const Vector &q, const Vector &r, float hw); + virtual void renderEdge(std::vector &anchors, std::vector &normals, + Vector2 &s, float &len_s, Vector2 &ns, + const Vector2 &q, const Vector2 &r, float hw); }; // BevelJoinPolyline diff --git a/src/modules/graphics/SpriteBatch.cpp b/src/modules/graphics/SpriteBatch.cpp index 5eeab5f18..302f63013 100644 --- a/src/modules/graphics/SpriteBatch.cpp +++ b/src/modules/graphics/SpriteBatch.cpp @@ -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++) { diff --git a/src/modules/graphics/Text.cpp b/src/modules/graphics/Text.cpp index 8f47eb9ad..ee9228054 100644 --- a/src/modules/graphics/Text.cpp +++ b/src/modules/graphics/Text.cpp @@ -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; diff --git a/src/modules/graphics/Texture.cpp b/src/modules/graphics/Texture.cpp index c1d1b91eb..d35e98b5d 100644 --- a/src/modules/graphics/Texture.cpp +++ b/src/modules/graphics/Texture.cpp @@ -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++) { diff --git a/src/modules/graphics/Video.cpp b/src/modules/graphics/Video.cpp index 7766f1766..bece39873 100644 --- a/src/modules/graphics/Video.cpp +++ b/src/modules/graphics/Video.cpp @@ -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()); diff --git a/src/modules/graphics/wrap_Graphics.cpp b/src/modules/graphics/wrap_Graphics.cpp index f88cb02ee..7937f72c4 100644 --- a/src/modules/graphics/wrap_Graphics.cpp +++ b/src/modules/graphics/wrap_Graphics.cpp @@ -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); diff --git a/src/modules/graphics/wrap_ParticleSystem.cpp b/src/modules/graphics/wrap_ParticleSystem.cpp index 676133956..4958063c3 100644 --- a/src/modules/graphics/wrap_ParticleSystem.cpp +++ b/src/modules/graphics/wrap_ParticleSystem.cpp @@ -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; } diff --git a/src/modules/math/BezierCurve.cpp b/src/modules/math/BezierCurve.cpp index eb4172c77..6faeb5d08 100644 --- a/src/modules/math/BezierCurve.cpp +++ b/src/modules/math/BezierCurve.cpp @@ -33,7 +33,7 @@ namespace /** * Subdivide Bezier polygon. **/ -void subdivide(vector &points, int k) +void subdivide(vector &points, int k) { if (k <= 0) return; @@ -50,7 +50,7 @@ void subdivide(vector &points, int k) // // the subdivided control polygon is: // b00, b10, b20, b30, b21, b12, b03 - vector left, right; + vector 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 &pts) +BezierCurve::BezierCurve(const vector &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 forward_differences(controlPoints.size()-1); + vector 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 points(controlPoints); + vector 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 points(controlPoints); - vector left, right; + vector points(controlPoints); + vector 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 BezierCurve::render(int accuracy) const +vector BezierCurve::render(int accuracy) const { if (controlPoints.size() < 2) throw Exception("Invalid Bezier curve: Not enough control points."); - vector vertices(controlPoints); + vector vertices(controlPoints); subdivide(vertices, accuracy); return vertices; } -vector BezierCurve::renderSegment(double start, double end, int accuracy) const +vector BezierCurve::renderSegment(double start, double end, int accuracy) const { if (controlPoints.size() < 2) throw Exception("Invalid Bezier curve: Not enough control points."); - vector vertices(controlPoints); + vector vertices(controlPoints); subdivide(vertices, accuracy); if (start == end) { @@ -261,13 +261,13 @@ 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(vertices.begin() + start_idx, vertices.begin() + end_idx); + return std::vector(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(vertices.begin() + start_idx, vertices.begin() + end_idx); + return std::vector(vertices.begin() + start_idx, vertices.begin() + end_idx); } return vertices; } diff --git a/src/modules/math/BezierCurve.h b/src/modules/math/BezierCurve.h index e7f0723a3..ceb5145b2 100644 --- a/src/modules/math/BezierCurve.h +++ b/src/modules/math/BezierCurve.h @@ -40,7 +40,7 @@ public: /** * @param controlPoints Control polygon of the curve. **/ - BezierCurve(const std::vector &controlPoints); + BezierCurve(const std::vector &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 render(int accuracy = 4) const; + std::vector 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 renderSegment(double start, double end, int accuracy = 4) const; + std::vector renderSegment(double start, double end, int accuracy = 4) const; private: - std::vector controlPoints; + std::vector controlPoints; }; } diff --git a/src/modules/math/MathModule.cpp b/src/modules/math/MathModule.cpp index ae517eed2..b153d4452 100644 --- a/src/modules/math/MathModule.cpp +++ b/src/modules/math/MathModule.cpp @@ -33,7 +33,7 @@ #include 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 &vertices, const Vector &a, const Vector &b, const Vector &c) +bool any_point_in_triangle(const std::list &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 &vertices, const Vect return false; } -inline bool is_ear(const Vector &a, const Vector &b, const Vector &c, const std::list &vertices) +inline bool is_ear(const Vector2 &a, const Vector2 &b, const Vector2 &c, const std::list &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 triangulate(const std::vector &polygon) +std::vector triangulate(const std::vector &polygon) { if (polygon.size() < 3) throw love::Exception("Not a polygon"); @@ -176,7 +176,7 @@ std::vector triangulate(const std::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 triangulate(const std::vector &polygon) next_idx.swap(prev_idx); // collect list of concave polygons - std::list concave_vertices; + std::list 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 triangulate(const std::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 triangulate(const std::vector &polygon) return triangles; } -bool isConvex(const std::vector &polygon) +bool isConvex(const std::vector &polygon) { if (polygon.size() < 3) return false; @@ -237,9 +237,9 @@ bool isConvex(const std::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 &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 &points) +BezierCurve *Math::newBezierCurve(const std::vector &points) { return new BezierCurve(points); } diff --git a/src/modules/math/MathModule.h b/src/modules/math/MathModule.h index dfa2f0e77..3983715de 100644 --- a/src/modules/math/MathModule.h +++ b/src/modules/math/MathModule.h @@ -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 triangulate(const std::vector &polygon); +std::vector triangulate(const std::vector &polygon); /** * Checks whether a polygon is convex. @@ -76,7 +76,7 @@ std::vector triangulate(const std::vector &polygon); * @param polygon Polygon to test. * @return True if the polygon is convex, false otherwise. **/ -bool isConvex(const std::vector &polygon); +bool isConvex(const std::vector &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 &points); + BezierCurve *newBezierCurve(const std::vector &points); Transform *newTransform(); Transform *newTransform(float x, float y, float a, float sx, float sy, float ox, float oy, float kx, float ky); diff --git a/src/modules/math/Transform.cpp b/src/modules/math/Transform.cpp index 162bea5a7..e8e43ed32 100644 --- a/src/modules/math/Transform.cpp +++ b/src/modules/math/Transform.cpp @@ -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; } diff --git a/src/modules/math/Transform.h b/src/modules/math/Transform.h index e084133ef..391bb4cbe 100644 --- a/src/modules/math/Transform.h +++ b/src/modules/math/Transform.h @@ -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); diff --git a/src/modules/math/wrap_BezierCurve.cpp b/src/modules/math/wrap_BezierCurve.cpp index 98cb34dca..56953fb48 100644 --- a/src/modules/math/wrap_BezierCurve.cpp +++ b/src/modules/math/wrap_BezierCurve.cpp @@ -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 points; + std::vector 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 points; + std::vector points; luax_catchexcept(L, [&](){ points = curve->renderSegment(start, end, accuracy); }); lua_createtable(L, (int) points.size() * 2, 0); diff --git a/src/modules/math/wrap_Math.cpp b/src/modules/math/wrap_Math.cpp index efbf1017b..5e7b8d337 100644 --- a/src/modules/math/wrap_Math.cpp +++ b/src/modules/math/wrap_Math.cpp @@ -83,7 +83,7 @@ int w_newRandomGenerator(lua_State *L) int w_newBezierCurve(lua_State *L) { - std::vector points; + std::vector 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 vertices; + std::vector 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 vertices; + std::vector 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); diff --git a/src/modules/math/wrap_Transform.cpp b/src/modules/math/wrap_Transform.cpp index aea09f781..8b73fe4f1 100644 --- a/src/modules/math/wrap_Transform.cpp +++ b/src/modules/math/wrap_Transform.cpp @@ -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);