1 #ifndef JUGIMAP_COMMON_H
2 #define JUGIMAP_COMMON_H
36 inline void Set(
T _x,
T _y){
x = _x;
y = _y;}
46 inline bool Equals(
const Vec2<T> &v,
float epsilon = 0.00001f)
const {
return(
x==v.
x &&
y==v.
y); }
163 return fabs(x - v.x)<epsilon && fabs(y - v.y)<epsilon ;
198 inline bool Equals(
const Rect<T> &r,
float epsilon = 0.00001f)
const {
return(min==r.
min && max==r.
max); }
209 T x0 = std::min<T>( min.
x, r.
min.x );
210 T y0 = std::min<T>( min.
y, r.
min.y );
211 T x1 = std::max<T>( max.
x, r.
max.x );
212 T y1 = std::max<T>( max.
y, r.
max.y );
219 T x0 = std::min<T>( min.
x, v.
x );
220 T y0 = std::min<T>( min.
y, v.
y );
221 T x1 = std::max<T>( max.
x, v.
x );
222 T y1 = std::max<T>( max.
y, v.
y );
253 return min.Equals(r.min, epsilon) && max.Equals(r.max, epsilon);
277 AffineMat3(T ix, T iy, T jx, T jy, T tx, T ty){ i.
x=ix; i.
y=iy; j.
x=jx; j.
y=jy; t.
x=tx; t.
y=ty; }
283 float idet = 1.0/(i.
x*j.
y-i.
y*j.
x);
285 j.
y*idet , -i.
y*idet,
286 -j.
x*idet , i.
x*idet,
287 (j.
x*t.
y-j.
y*t.
x)*idet , (i.
y*t.
x-i.
x*t.
y)*idet );
300 i.
x*m.
i.x + j.
x*m.
i.y , i.
y*m.
i.x + j.
y*m.
i.y ,
301 i.
x*m.
j.x + j.
x*m.
j.y , i.
y*m.
j.x + j.
y*m.
j.y ,
302 i.
x*m.
t.x + j.
x*m.
t.y + t.
x , i.
y*m.
t.x + j.
y*m.
t.y + t.
y );
323 i.
x*ix + j.
x*iy , i.
y*ix + j.
y*iy ,
324 i.
x*jx + j.
x*jy , i.
y*jx + j.
y*jy ,
325 i.
x*tx + j.
x*ty + t.
x , i.
y*tx + j.
y*ty + t.
y );
332 return Transform( 1,0,0,1,tx,ty );
340 inline AffineMat3<T> Rotate(
double rz)
const {
return Transform( std::cos( rz ),-std::sin( rz ), std::sin( rz ), std::cos( rz ),0,0 );}
374 r.
t.x=-(right+left)/w;
375 r.
t.y=-(top+bottom)/h;
401 static bool Exists(
const std::vector<Parameter> ¶meters,
const std::string &name,
const std::string &value=
"");
404 static std::string GetValue(
const std::vector<Parameter> ¶meters,
const std::string &name,
const std::string &defaultValue=
"");
407 static int GetIntValue(
const std::vector<Parameter> ¶meters,
const std::string &name,
int defaultValue=0);
410 static float GetFloatValue(
const std::vector<Parameter> ¶meters,
const std::string &name,
float defaultValue=0.0);
413 static Parameter Parse(
const std::string &s);
440 float GetValue(
float p);
442 Kind kind = Kind::LINEAR;
474 void Init(
float _valueStart,
float _valueEnd,
float _durationS,
Easing::Kind _easingKind);
488 bool IsIdle() {
return state==stateIDLE || state == stateNEVER_INITIALIZED; }
527 float valueStart = 0.0;
528 float valueEnd = 0.0;
534 int state = stateNEVER_INITIALIZED;
535 static const int stateNEVER_INITIALIZED = -1;
536 static const int stateIDLE = 0;
537 static const int statePLAYING = 1;
538 static const int statePAUSED = 3;
541 Mode mode = Mode::NORMAL;
542 bool reverse =
false;
545 int msTimeStored = 0;
561 virtual std::string GetInfo(){
return ""; }
AffineMat3< T > Translate(T tx, T ty) const
Returns a matrix formed by translating this matrix by the given vector coordinates tx and ty.
Definition: jmCommon.h:330
AffineMat3< float > AffineMat3f
AffineMat3 struct in float precision.
Definition: jmCommon.h:381
The CustomObject class is the base class for custom objects.
Definition: jmCommon.h:555
bool Contains(const Vec2< T > &v) const
Returns true if the given vector point v is inside this rectangle; otherwise returns false.
Definition: jmCommon.h:239
bool Intersects(const Rect< T > &r) const
Returns true if the given rectangle r is intersects this rectangle; otherwise returns false.
Definition: jmCommon.h:245
Vec2< T > operator-(T s) const
Returns a vector object formed by subtracting the given s from this vector.
Definition: jmCommon.h:137
Vec2< T > & operator/=(T s)
Divides this vector with the given s and return a reference to this vector.
Definition: jmCommon.h:120
Rectangle.
Definition: jmCommon.h:174
Vec2< T > Normalize() const
Returns a vector object formed by normalizing this vector.
Definition: jmCommon.h:152
AffineMat3< T > Scale(T sx, T sy) const
Returns a matrix formed by scaling this matrix by the given vector components sx and sy.
Definition: jmCommon.h:343
std::string name
The name of this parameter.
Definition: jmCommon.h:394
AffineMat3(T ix, T iy, T jx, T jy, T tx, T ty)
Constructs a matrix from the given row vector components ix, iy, jx, jy, tx and ty.
Definition: jmCommon.h:277
std::string value
The value of this parameter.
Definition: jmCommon.h:395
bool operator==(const Vec2< T > &v) const
Returns true if this vector is equal to given vector v; otherwise returns false.
Definition: jmCommon.h:39
Vec2()
Constructs a vector with coordinates (0,0).
Definition: jmCommon.h:30
double Distance2(const Vec2< T > &v) const
Returns the square distance from the given vector v.
Definition: jmCommon.h:149
Mode
The tween mode.
Definition: jmCommon.h:457
Rect()
Constructs an empty 'null' rectangle.
Definition: jmCommon.h:182
Vec2< int > Vec2i
Vec2 struct in integer precision.
Definition: jmCommon.h:166
double Distance(const Vec2< T > &v) const
Return the distance from the given vector v.
Definition: jmCommon.h:146
bool IsIdle()
Returns true if this tween is not running; otherwise return false.
Definition: jmCommon.h:488
float GetEndValue()
Returns the end value of this tween;.
Definition: jmCommon.h:520
AffineMat3< T > Rotate(double rz) const
Returns a matrix formed by rotating this matrix by the given angle rz; the angle is in radians.
Definition: jmCommon.h:340
Vec2< T > & operator*=(T s)
Multiplies this vector with the given s and return a reference to this vector.
Definition: jmCommon.h:112
T Dot(const Vec2< T > &v) const
Returns the dot product of this vector and the given vector v.
Definition: jmCommon.h:155
Vec2< T > j
The second row of the matrix.
Definition: jmCommon.h:267
bool IsValid()
Returns true if the maximum coordinate is bigger or equal to the minimum coordinate; otherwise return...
Definition: jmCommon.h:236
Vec2< T > & operator-=(const Vec2< T > &v)
Subtracts the given vector v from this vector and return a reference to this vector.
Definition: jmCommon.h:72
Vec2< T > & operator-=(T s)
Subtracts the given s from this vector and return a reference to this vector.
Definition: jmCommon.h:104
Vec2< T > operator*(const Vec2< T > &v) const
Returns a vector object formed by multiplying this vector with the given vector v.
Definition: jmCommon.h:52
Vec2< T > operator*(const Vec2< T > &v) const
Returns a matrix formed by multiplying this matrix with the given vector v.
Definition: jmCommon.h:291
Rect(const Vec2< T > &_min, const Vec2< T > &_max)
Constructs a rectangle from the given minimum and maximum vectors .
Definition: jmCommon.h:188
Rect< T > Expand(const Vec2< T > &v) const
Returns a rectangle formed by expanding this rectangle by the given vector v.
Definition: jmCommon.h:217
AffineMat3(const Vec2< T > &_i, const Vec2< T > &_j, const Vec2< T > &_t)
Constructs a matrix from the given row vectors **_i**, **_j** and **_t**.
Definition: jmCommon.h:274
Vec2< T > t
The third row of the matrix.
Definition: jmCommon.h:268
Vec2< T > max
The maximum coordinate (the right-bottom corner when y coordinate points downward).
Definition: jmCommon.h:178
Vec2< T > & operator*=(const Vec2< T > &v)
Multiplyes this vector with the given vector v and return a reference to this vector.
Definition: jmCommon.h:80
The Parameter struct defines a pair name : value.
Definition: jmCommon.h:392
T x
The x coordinate.
Definition: jmCommon.h:25
Vec2< T > & operator/=(const Vec2< T > &v)
Divides this vector with the given vector v and return a reference to this vector.
Definition: jmCommon.h:88
The Tween class defines transition between two values over time.
Definition: jmCommon.h:451
AffineMat3< T > Invert() const
Returns a matrix formed by inverting this matrix.
Definition: jmCommon.h:281
Vec2< T > i
The first row of the matrix.
Definition: jmCommon.h:266
Vec2< T > operator-() const
Return a vector object formed by changing the sign of this vector components.
Definition: jmCommon.h:49
void SetTag(int _tag)
Set the tag of this custom object.
Definition: jmCommon.h:565
float GetStartValue()
Returns the starting value of this tween;.
Definition: jmCommon.h:516
AffineMat3< T > Scale(const Vec2< T > &sv) const
Returns a matrix formed by scaling this matrix by the given vector sv.
Definition: jmCommon.h:346
AffineMat3()
Constructs an identity matrix.
Definition: jmCommon.h:271
Rect< int > Recti
Rect struct in integer precision.
Definition: jmCommon.h:256
bool operator==(const Rect< T > &r) const
Returns true if this rectangle is equal to the given rectangle r; otherwise returns false.
Definition: jmCommon.h:191
bool Equals(const Rect< T > &r, float epsilon=0.00001f) const
Definition: jmCommon.h:198
void SetEasingKind(Easing::Kind _kind)
Set the easing kind of this tween.
Definition: jmCommon.h:508
Vec2< T > min
The minimum coordinate (the left-top corner when y coordinate points downward).
Definition: jmCommon.h:177
static AffineMat3< T > Translation(const Vec2< T > &tv)
Creates a matrix representing a translation by the given vector tv.
Definition: jmCommon.h:352
static AffineMat3< T > Translation(T tx, T ty)
Creates a matrix representing a translation by the given vector coordinates tx and ty.
Definition: jmCommon.h:349
bool operator!=(const Vec2< T > &v) const
Returns true if this vector is not equal to given vector v; otherwise returns false.
Definition: jmCommon.h:42
Vec2< T > operator*(double s) const
Returns a vector object formed by multiplying this vector with the given s.
Definition: jmCommon.h:128
static AffineMat3< T > Scaling(T sx, T sy)
Creates a matrix representing a scaling by the given vector components sx and sy.
Definition: jmCommon.h:358
void SetMode(Mode _mode)
Set the mode of this tween.
Definition: jmCommon.h:512
bool Equals(const Vec2< T > &v, float epsilon=0.00001f) const
Returns true if the given vectors v is equal to this vector; otherwise returns false....
Definition: jmCommon.h:46
T y
The y coordinate.
Definition: jmCommon.h:26
void Set(T _x, T _y)
Sets the coordinates of this vector to the given **_x** and **_y**.
Definition: jmCommon.h:36
Rect< float > Rectf
Rect struct in float precision.
Definition: jmCommon.h:257
T GetHeight() const
Returns the height of this rectangle.
Definition: jmCommon.h:204
Vec2< float > Vec2f
Vec2 struct in float precision.
Definition: jmCommon.h:167
double GetLength() const
Returns the length of this vector.
Definition: jmCommon.h:140
static AffineMat3< T > Scaling(const Vec2< T > &sv)
Creates a matrix representing a scaling by the given vector sv.
Definition: jmCommon.h:361
Vec2< T > & operator+=(T s)
Adds the given s to this vector and return a reference to this vector.
Definition: jmCommon.h:96
Kind
The kind of Easing.
Definition: jmCommon.h:429
bool Contains(const Rect< T > &r) const
Returns true if the given rectangle r is inside this rectangle; otherwise returns false.
Definition: jmCommon.h:242
Vec2< T > operator+(T s) const
Returns a vector object formed by adding the given s to this vector.
Definition: jmCommon.h:134
Rect< T > Unite(const Rect< T > &r) const
Returns a rectangle formed by uniting this rectangle with the given rectangle r.
Definition: jmCommon.h:207
AffineMat3< T > Translate(const Vec2< T > &tv) const
Returns a matrix formed by translating this matrix by the given vector tv.
Definition: jmCommon.h:337
Vec2(T _x, T _y)
Constructs a vector with the given coordinates **_x** and **_y**.
Definition: jmCommon.h:33
Vec2< T > & operator+=(const Vec2< T > &v)
Adds the given vector v to this vector and return a reference to this vector.
Definition: jmCommon.h:64
T GetWidth() const
Returns the width of this rectangle.
Definition: jmCommon.h:201
Vec2< T > GetSize() const
Returns a vector storing the size of this rectangle; the width is stored in x and the height is store...
Definition: jmCommon.h:227
AffineMat3< T > operator*(const AffineMat3< T > &m) const
Returns a matrix formed by multiplying this matrix with the given matrix m.
Definition: jmCommon.h:297
bool IsEmpty()
Returns true if the minimum and maximum coordinates are equal; otherwise returns false.
Definition: jmCommon.h:233
Vec2< T > Transform(const Vec2< T > &v) const
Returns a vector formed by multiplying the given vector v with this matrix.
Definition: jmCommon.h:306
Rect(T xMin, T yMin, T xMax, T yMax)
Constructs a rectangle from the given minimum and maximum coordinates.
Definition: jmCommon.h:185
Vec2< T > operator/(const Vec2< T > &v) const
Returns a vector object formed by dividing this vector with the given vector v.
Definition: jmCommon.h:55
Matrix representation of the affine transformation.
Definition: jmCommon.h:263
int GetTag()
Returns the tag of this custom object.
Definition: jmCommon.h:568
static AffineMat3< T > Ortho(T left, T right, T bottom, T top)
Creates a matrix representing an orthographic projection.
Definition: jmCommon.h:365
Vec2< T > operator+(const Vec2< T > &v) const
Returns a vector object formed as the sum of the given s to this vector.
Definition: jmCommon.h:58
Vec2< T > GetCenter() const
Returns a vector storing the center point of this rectangle.
Definition: jmCommon.h:230
2d vector.
Definition: jmCommon.h:23
Vec2< T > Transform(T x, T y) const
Returns a vector formed by multiplying the given coordinate x,y with this matrix.
Definition: jmCommon.h:313
Vec2< T > operator-(const Vec2< T > &v) const
Returns a vector object formed by subtracting the given v from this vector.
Definition: jmCommon.h:61
double GetLength2() const
Returns the square length of this vector.
Definition: jmCommon.h:143
Vec2< T > operator/(double s) const
Returns a vector object formed by dividing this vector with the given s.
Definition: jmCommon.h:131
bool operator!=(const Rect< T > &r) const
Returns true if this rectangle is not equal to the given rectangle r; otherwise returns false.
Definition: jmCommon.h:194
AffineMat3< T > Transform(float ix, float iy, float jx, float jy, float tx, float ty) const
Returns a matrix formed by multiplying this matrix with the given matrix components ix,...
Definition: jmCommon.h:320
The Easing struct defines interpolation methods used for obtaining values between a start value and a...
Definition: jmCommon.h:424
static AffineMat3< T > Rotation(double rz)
Creates a matrix representing a rotation by the given angle rz; the angle is in radians.
Definition: jmCommon.h:355