first commit
This commit is contained in:
78
include/platform/math/nmath.h
Normal file
78
include/platform/math/nmath.h
Normal file
@ -0,0 +1,78 @@
|
||||
/* -----------------------------------------------------------------------------
|
||||
GSFramework
|
||||
Copyright 2001-2013 Emmanuel Julien. All Rights Reserved.
|
||||
----------------------------------------------------------------------------- */
|
||||
|
||||
|
||||
#ifndef __NMATH__
|
||||
#define __NMATH__
|
||||
|
||||
|
||||
#include "unit/nunit.h"
|
||||
|
||||
|
||||
/*
|
||||
@short Math namespace.
|
||||
@author Emmanuel Julien (ejulien@gsworks.fr)
|
||||
*/
|
||||
namespace GS {
|
||||
namespace Math {
|
||||
|
||||
static const float Pi = 3.1415926535f;
|
||||
|
||||
/// Euler angles rotation order.
|
||||
enum rOrder
|
||||
{
|
||||
rOrder_ZYX = 0,
|
||||
rOrder_YZX,
|
||||
rOrder_ZXY,
|
||||
rOrder_XZY,
|
||||
rOrder_YXZ,
|
||||
rOrder_XYZ,
|
||||
rOrder_XY,
|
||||
|
||||
rOrder_Default = rOrder_YXZ // Y then X then Z.
|
||||
};
|
||||
|
||||
enum Axis
|
||||
{
|
||||
AxisX, // Do not modify X, Y and Z order.
|
||||
AxisY,
|
||||
AxisZ,
|
||||
AxisNone
|
||||
};
|
||||
|
||||
void Init();
|
||||
|
||||
/// Return the reverse rotation order from a given input order.
|
||||
rOrder ReverserRotationOrder(rOrder r);
|
||||
|
||||
float Sqrt(float v);
|
||||
|
||||
float TestEqual(float a, float b, float e = 0.000001f);
|
||||
bool EqualZero(float v, float e = 0.000001f);
|
||||
|
||||
float Pow(float v, float exp);
|
||||
|
||||
float Ceil(float);
|
||||
float Floor(float);
|
||||
float Mod(float);
|
||||
|
||||
float RangeAdjust(float v, float old_min, float old_max, float new_min, float new_max);
|
||||
|
||||
float Quantize(float v, float q);
|
||||
|
||||
float Sin(float);
|
||||
float ASin(float);
|
||||
float Cos(float);
|
||||
float ACos(float);
|
||||
float Tan(float);
|
||||
float ATan(float);
|
||||
|
||||
bool IsFinite(float);
|
||||
|
||||
} // Math
|
||||
} // GS
|
||||
|
||||
|
||||
#endif // __NMATH__
|
||||
49
include/platform/math/nrange.h
Normal file
49
include/platform/math/nrange.h
Normal file
@ -0,0 +1,49 @@
|
||||
/* -----------------------------------------------------------------------------
|
||||
GSFramework
|
||||
Copyright 2001-2013 Emmanuel Julien. All Rights Reserved.
|
||||
----------------------------------------------------------------------------- */
|
||||
|
||||
|
||||
#ifndef __NRANGE__
|
||||
#define __NRANGE__
|
||||
|
||||
|
||||
#include "math/nrange.h"
|
||||
|
||||
|
||||
namespace GS {
|
||||
|
||||
/*!
|
||||
@short Range.
|
||||
@author Emmanuel Julien (ejulien@gsworks.fr)
|
||||
*/
|
||||
template <class T> struct Range
|
||||
{
|
||||
T start, end;
|
||||
|
||||
T valueRange() const { return end - start; }
|
||||
bool inRange(const T &v) const { return (start < end) ? ((v >= start) && (v < end)) : ((v >= end) && (v < start)); }
|
||||
void sort() { if (start > end) { T t = start; start = end; end = t; } }
|
||||
|
||||
static Range Intersection(const Range <T> &a, const Range <T> &b)
|
||||
{
|
||||
if ((a.end < b.start) || (a.start > b.end))
|
||||
return Range <T> ();
|
||||
return Range(a.start > b.start ? a.start : b.start, a.end < b.end ? a.end : b.end);
|
||||
}
|
||||
static Range Union(const Range &a, const Range &b)
|
||||
{ return Range(a.start < b.start ? a.start : b.start, a.end > b.end ? a.end : b.end); }
|
||||
|
||||
void Set(const T &s, const T &e) { start = s; end = e; }
|
||||
|
||||
template <class N> Range <N> convert() const
|
||||
{ return Range <N> (N(start), N(end)); }
|
||||
|
||||
Range(const T &s, const T &e) : start(s), end(e) {}
|
||||
Range() : start(0), end(0) {}
|
||||
};
|
||||
|
||||
} // GS
|
||||
|
||||
|
||||
#endif // __NRANGE__
|
||||
Reference in New Issue
Block a user