2014-04-02 10:33:07 +08:00
|
|
|
#ifndef MATHUTIL_H_
|
|
|
|
#define MATHUTIL_H_
|
|
|
|
|
2014-04-02 12:09:51 +08:00
|
|
|
#include "CCMathBase.h"
|
|
|
|
|
|
|
|
NS_CC_MATH_BEGIN
|
|
|
|
|
2014-04-02 10:33:07 +08:00
|
|
|
/**
|
|
|
|
* Defines a math utility class.
|
|
|
|
*
|
|
|
|
* This is primarily used for optimized internal math operations.
|
|
|
|
*/
|
|
|
|
class MathUtil
|
|
|
|
{
|
|
|
|
friend class Matrix;
|
|
|
|
friend class Vector3;
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Updates the given scalar towards the given target using a smoothing function.
|
|
|
|
* The given response time determines the amount of smoothing (lag). A longer
|
|
|
|
* response time yields a smoother result and more lag. To force the scalar to
|
|
|
|
* follow the target closely, provide a response time that is very small relative
|
|
|
|
* to the given elapsed time.
|
|
|
|
*
|
|
|
|
* @param x the scalar to update.
|
|
|
|
* @param target target value.
|
|
|
|
* @param elapsedTime elapsed time between calls.
|
|
|
|
* @param responseTime response time (in the same units as elapsedTime).
|
|
|
|
*/
|
|
|
|
static void smooth(float* x, float target, float elapsedTime, float responseTime);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Updates the given scalar towards the given target using a smoothing function.
|
|
|
|
* The given rise and fall times determine the amount of smoothing (lag). Longer
|
|
|
|
* rise and fall times yield a smoother result and more lag. To force the scalar to
|
|
|
|
* follow the target closely, provide rise and fall times that are very small relative
|
|
|
|
* to the given elapsed time.
|
|
|
|
*
|
|
|
|
* @param x the scalar to update.
|
|
|
|
* @param target target value.
|
|
|
|
* @param elapsedTime elapsed time between calls.
|
|
|
|
* @param riseTime response time for rising slope (in the same units as elapsedTime).
|
|
|
|
* @param fallTime response time for falling slope (in the same units as elapsedTime).
|
|
|
|
*/
|
|
|
|
static void smooth(float* x, float target, float elapsedTime, float riseTime, float fallTime);
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
inline static void addMatrix(const float* m, float scalar, float* dst);
|
|
|
|
|
|
|
|
inline static void addMatrix(const float* m1, const float* m2, float* dst);
|
|
|
|
|
|
|
|
inline static void subtractMatrix(const float* m1, const float* m2, float* dst);
|
|
|
|
|
|
|
|
inline static void multiplyMatrix(const float* m, float scalar, float* dst);
|
|
|
|
|
|
|
|
inline static void multiplyMatrix(const float* m1, const float* m2, float* dst);
|
|
|
|
|
|
|
|
inline static void negateMatrix(const float* m, float* dst);
|
|
|
|
|
|
|
|
inline static void transposeMatrix(const float* m, float* dst);
|
|
|
|
|
|
|
|
inline static void transformVector4(const float* m, float x, float y, float z, float w, float* dst);
|
|
|
|
|
|
|
|
inline static void transformVector4(const float* m, const float* v, float* dst);
|
|
|
|
|
|
|
|
inline static void crossVector3(const float* v1, const float* v2, float* dst);
|
|
|
|
|
|
|
|
MathUtil();
|
|
|
|
};
|
|
|
|
|
2014-04-02 12:09:51 +08:00
|
|
|
NS_CC_MATH_END
|
2014-04-02 10:33:07 +08:00
|
|
|
|
|
|
|
#define MATRIX_SIZE ( sizeof(float) * 16)
|
|
|
|
|
|
|
|
#ifdef USE_NEON
|
|
|
|
#include "MathUtilNeon.inl"
|
|
|
|
#else
|
|
|
|
#include "MathUtil.inl"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif
|