-
-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
27 changed files
with
2,882 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
#pragma once | ||
|
||
#include "common/Object.hpp" | ||
#include "common/Vector.hpp" | ||
|
||
#include <vector> | ||
|
||
namespace love | ||
{ | ||
class BezierCurve : public Object | ||
{ | ||
public: | ||
static Type type; | ||
|
||
BezierCurve(const std::vector<Vector2>& controlPoints); | ||
|
||
size_t getDegree() const | ||
{ | ||
return this->controlPoints.size() - 1; | ||
} | ||
|
||
BezierCurve getDerivative() const; | ||
|
||
const Vector2& getControlPoint(int i) const; | ||
|
||
void setControlPoint(int i, const Vector2& point); | ||
|
||
void insertControlPoint(const Vector2& point, int pos = -1); | ||
|
||
void removeControlPoint(int i); | ||
|
||
size_t getControlPointCount() const | ||
{ | ||
return this->controlPoints.size(); | ||
} | ||
|
||
void translate(const Vector2& offset); | ||
|
||
void rotate(double phi, const Vector2& center); | ||
|
||
void scale(double scale, const Vector2& center); | ||
|
||
Vector2 evaluate(double time) const; | ||
|
||
BezierCurve* getSegment(double start, double end) const; | ||
|
||
std::vector<Vector2> render(int accuracy = 4) const; | ||
|
||
std::vector<Vector2> renderSegment(double start, double end, int accuracy = 4) const; | ||
|
||
private: | ||
std::vector<Vector2> controlPoints; | ||
}; | ||
} // namespace love |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
#pragma once | ||
|
||
#include "modules/math/RandomGenerator.hpp" | ||
|
||
#include "common/Module.hpp" | ||
#include "common/StrongRef.hpp" | ||
#include "common/Vector.hpp" | ||
#include "common/int.hpp" | ||
#include "common/math.hpp" | ||
|
||
#include "noise1234.h" | ||
#include "simplexnoise1234.h" | ||
|
||
#include <vector> | ||
|
||
namespace love | ||
{ | ||
class BezierCurve; | ||
class Transform; | ||
|
||
struct Triangle | ||
{ | ||
Triangle(const Vector2& x, const Vector2& y, const Vector2& z) : a(x), b(y), c(z) | ||
{} | ||
|
||
Vector2 a, b, c; | ||
}; | ||
|
||
std::vector<Triangle> triangulate(const std::vector<love::Vector2>& polygon); | ||
|
||
bool isConvex(const std::vector<Vector2>& polygon); | ||
|
||
float gammaToLinear(float c); | ||
|
||
float linearToGamma(float c); | ||
|
||
static inline double simplexNoise1(double x) | ||
{ | ||
return SimplexNoise1234::noise(x) * 0.5 + 0.5; | ||
} | ||
|
||
static inline double simplexNoise2(double x, double y) | ||
{ | ||
return SimplexNoise1234::noise(x, y) * 0.5 + 0.5; | ||
} | ||
|
||
static inline double simplexNoise3(double x, double y, double z) | ||
{ | ||
return SimplexNoise1234::noise(x, y, z) * 0.5 + 0.5; | ||
} | ||
|
||
static inline double simplexNoise4(double x, double y, double z, double w) | ||
{ | ||
return SimplexNoise1234::noise(x, y, z, w) * 0.5 + 0.5; | ||
} | ||
|
||
static inline double perlinNoise1(double x) | ||
{ | ||
return Noise1234::noise(x) * 0.5 + 0.5; | ||
} | ||
|
||
static inline double perlinNoise2(double x, double y) | ||
{ | ||
return Noise1234::noise(x, y) * 0.5 + 0.5; | ||
} | ||
|
||
static inline double perlinNoise3(double x, double y, double z) | ||
{ | ||
return Noise1234::noise(x, y, z) * 0.5 + 0.5; | ||
} | ||
|
||
static inline double perlinNoise4(double x, double y, double z, double w) | ||
{ | ||
return Noise1234::noise(x, y, z, w) * 0.5 + 0.5; | ||
} | ||
|
||
class Math : public Module | ||
{ | ||
public: | ||
Math(); | ||
|
||
virtual ~Math(); | ||
|
||
RandomGenerator* getRandomGenerator() | ||
{ | ||
return this->random.get(); | ||
} | ||
|
||
RandomGenerator* newRandomGenerator() const; | ||
|
||
BezierCurve* newBezierCurve(const std::vector<Vector2>& points) const; | ||
|
||
Transform* newTransform() const; | ||
|
||
Transform* newTransform(float x, float y, float angle, float sx, float sy, float ox, float oy, | ||
float kx, float ky) const; | ||
|
||
private: | ||
StrongRef<RandomGenerator> random; | ||
}; | ||
} // namespace love |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
#pragma once | ||
|
||
#include "common/Exception.hpp" | ||
#include "common/Object.hpp" | ||
#include "common/int.hpp" | ||
#include "common/math.hpp" | ||
|
||
#include <limits> | ||
#include <string> | ||
|
||
namespace love | ||
{ | ||
class RandomGenerator : public Object | ||
{ | ||
public: | ||
static Type type; | ||
|
||
union Seed | ||
{ | ||
uint64_t b64; | ||
struct | ||
{ | ||
#if defined(LOVE_BIG_ENDIAN) | ||
uint32_t high; | ||
uint32_t low; | ||
#else | ||
uint32_t low; | ||
uint32_t high; | ||
#endif | ||
} b32; | ||
}; | ||
|
||
RandomGenerator(); | ||
|
||
virtual ~RandomGenerator() | ||
{} | ||
|
||
uint64_t rand(); | ||
|
||
inline double random() | ||
{ | ||
uint64_t value = rand(); | ||
|
||
union | ||
{ | ||
uint64_t i; | ||
double d; | ||
} u; | ||
|
||
u.i = ((0x3FFULL) << 52) | (value >> 12); | ||
return u.d - 1.0; | ||
} | ||
|
||
inline double random(double max) | ||
{ | ||
return random() * max; | ||
} | ||
|
||
inline double random(double min, double max) | ||
{ | ||
return random() * (max - min) + min; | ||
} | ||
|
||
double randomNormal(double stddev); | ||
|
||
void setSeed(Seed seed); | ||
|
||
Seed getSeed() const; | ||
|
||
void setState(const std::string& state); | ||
|
||
std::string getState() const; | ||
|
||
private: | ||
static constexpr auto DEFAULT_LOW = 0xCBBF7A44; | ||
static constexpr auto DEFAULT_HIGH = 0x0139408D; | ||
|
||
static constexpr auto MULTIPLIER = 2685821657736338717ULL; | ||
|
||
Seed seed; | ||
Seed state; | ||
double lastRandomNormal; | ||
}; | ||
} // namespace love |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
#pragma once | ||
|
||
#include "common/Map.hpp" | ||
#include "common/Matrix.hpp" | ||
#include "common/Object.hpp" | ||
#include "common/Vector.hpp" | ||
|
||
namespace love | ||
{ | ||
class Transform : public Object | ||
{ | ||
public: | ||
enum MatrixLayout | ||
{ | ||
MATRIX_ROW_MAJOR, | ||
MATRIX_COLUMN_MAJOR, | ||
MATRIX_MAX_ENUM | ||
}; | ||
|
||
static Type type; | ||
|
||
Transform(); | ||
|
||
Transform(const Matrix4& m); | ||
|
||
Transform(float x, float y, float a, float sx, float sy, float ox, float oy, float kx, float ky); | ||
|
||
virtual ~Transform(); | ||
|
||
Transform* clone(); | ||
|
||
Transform* inverse(); | ||
|
||
void apply(Transform* other); | ||
|
||
void translate(float x, float y); | ||
|
||
void rotate(float angle); | ||
|
||
void scale(float x, float y); | ||
|
||
void shear(float x, float y); | ||
|
||
void reset(); | ||
|
||
void setTransformation(float x, float y, float a, float sx, float sy, float ox, float oy, float kx, | ||
float ky); | ||
|
||
Vector2 transformPoint(Vector2 point) const; | ||
|
||
Vector2 inverseTransformPoint(Vector2 point); | ||
|
||
const Matrix4& getMatrix() const; | ||
|
||
void setMatrix(const Matrix4& m); | ||
|
||
// clang-format off | ||
STRINGMAP_DECLARE(MatrixLayouts, MatrixLayout, | ||
{ "row", MATRIX_ROW_MAJOR }, | ||
{ "column", MATRIX_COLUMN_MAJOR } | ||
); | ||
// clang-format on | ||
|
||
private: | ||
inline const Matrix4& getInverseMatrix() | ||
{ | ||
if (this->inverseDirty) | ||
{ | ||
this->inverseMatrix = matrix.inverse(); | ||
this->inverseDirty = false; | ||
} | ||
|
||
return this->inverseMatrix; | ||
} | ||
|
||
Matrix4 matrix; | ||
bool inverseDirty; | ||
Matrix4 inverseMatrix; | ||
}; | ||
} // namespace love |
Oops, something went wrong.