Skip to content

Commit

Permalink
Math: remove and replace GP_ASSERT with AX_ASSERT (axmolengine#2143)
Browse files Browse the repository at this point in the history
  • Loading branch information
smilediver authored and xfbird committed Sep 18, 2024
1 parent 02b4d92 commit 732fbf5
Show file tree
Hide file tree
Showing 12 changed files with 68 additions and 70 deletions.
2 changes: 0 additions & 2 deletions core/base/Macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,6 @@ extern bool AX_DLL ax_assert_script_compatible(const char* msg);
# define AXASSERT(cond, msg)
# endif

# define GP_ASSERT(cond) AXASSERT(cond, "")

// FIXME:: Backward compatible
# define CCAssert AXASSERT
#endif // AXASSERT
Expand Down
66 changes: 33 additions & 33 deletions core/math/Mat4.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ void Mat4::createLookAt(float eyePositionX,
float upZ,
Mat4* dst)
{
GP_ASSERT(dst);
AX_ASSERT(dst);

Vec3 eye(eyePositionX, eyePositionY, eyePositionZ);
Vec3 target(targetPositionX, targetPositionY, targetPositionZ);
Expand Down Expand Up @@ -96,8 +96,8 @@ void Mat4::createLookAt(float eyePositionX,

void Mat4::createPerspective(float fieldOfView, float aspectRatio, float zNearPlane, float zFarPlane, Mat4* dst)
{
GP_ASSERT(dst);
GP_ASSERT(zFarPlane != zNearPlane);
AX_ASSERT(dst);
AX_ASSERT(zFarPlane != zNearPlane);

float f_n = 1.0f / (zFarPlane - zNearPlane);
float theta = MATH_DEG_TO_RAD(fieldOfView) * 0.5f;
Expand All @@ -108,12 +108,12 @@ void Mat4::createPerspective(float fieldOfView, float aspectRatio, float zNearPl
return;
}
float divisor = std::tan(theta);
GP_ASSERT(divisor);
AX_ASSERT(divisor);
float factor = 1.0f / divisor;

memset(dst->m, 0, sizeof(dst->m));

GP_ASSERT(aspectRatio);
AX_ASSERT(aspectRatio);
dst->m[0] = (1.0f / aspectRatio) * factor;
dst->m[5] = factor;
dst->m[10] = (-(zFarPlane + zNearPlane)) * f_n;
Expand Down Expand Up @@ -142,10 +142,10 @@ void Mat4::createOrthographicOffCenter(float left,
float zFarPlane,
Mat4* dst)
{
GP_ASSERT(dst);
GP_ASSERT(right != left);
GP_ASSERT(top != bottom);
GP_ASSERT(zFarPlane != zNearPlane);
AX_ASSERT(dst);
AX_ASSERT(right != left);
AX_ASSERT(top != bottom);
AX_ASSERT(zFarPlane != zNearPlane);

memset(dst->m, 0, sizeof(dst->m));
dst->m[0] = 2 / (right - left);
Expand Down Expand Up @@ -237,7 +237,7 @@ void Mat4::createBillboardHelper(const Vec3& objectPosition,

void Mat4::createScale(const Vec3& scale, Mat4* dst)
{
GP_ASSERT(dst);
AX_ASSERT(dst);

dst->setIdentity();

Expand All @@ -248,7 +248,7 @@ void Mat4::createScale(const Vec3& scale, Mat4* dst)

void Mat4::createScale(float xScale, float yScale, float zScale, Mat4* dst)
{
GP_ASSERT(dst);
AX_ASSERT(dst);

dst->setIdentity();

Expand All @@ -259,7 +259,7 @@ void Mat4::createScale(float xScale, float yScale, float zScale, Mat4* dst)

void Mat4::createRotation(const Quaternion& q, Mat4* dst)
{
GP_ASSERT(dst);
AX_ASSERT(dst);

float x2 = q.x + q.x;
float y2 = q.y + q.y;
Expand Down Expand Up @@ -298,7 +298,7 @@ void Mat4::createRotation(const Quaternion& q, Mat4* dst)

void Mat4::createRotation(const Vec3& axis, float angle, Mat4* dst)
{
GP_ASSERT(dst);
AX_ASSERT(dst);

float x = axis.x;
float y = axis.y;
Expand Down Expand Up @@ -357,7 +357,7 @@ void Mat4::createRotation(const Vec3& axis, float angle, Mat4* dst)

void Mat4::createRotationX(float angle, Mat4* dst)
{
GP_ASSERT(dst);
AX_ASSERT(dst);

dst->setIdentity();

Expand All @@ -372,7 +372,7 @@ void Mat4::createRotationX(float angle, Mat4* dst)

void Mat4::createRotationY(float angle, Mat4* dst)
{
GP_ASSERT(dst);
AX_ASSERT(dst);

dst->setIdentity();

Expand All @@ -387,7 +387,7 @@ void Mat4::createRotationY(float angle, Mat4* dst)

void Mat4::createRotationZ(float angle, Mat4* dst)
{
GP_ASSERT(dst);
AX_ASSERT(dst);

dst->setIdentity();

Expand All @@ -402,7 +402,7 @@ void Mat4::createRotationZ(float angle, Mat4* dst)

void Mat4::createTranslation(const Vec3& translation, Mat4* dst)
{
GP_ASSERT(dst);
AX_ASSERT(dst);

dst->setIdentity();

Expand All @@ -413,7 +413,7 @@ void Mat4::createTranslation(const Vec3& translation, Mat4* dst)

void Mat4::createTranslation(float xTranslation, float yTranslation, float zTranslation, Mat4* dst)
{
GP_ASSERT(dst);
AX_ASSERT(dst);

dst->setIdentity();

Expand All @@ -429,7 +429,7 @@ void Mat4::add(float scalar)

void Mat4::add(float scalar, Mat4* dst)
{
GP_ASSERT(dst);
AX_ASSERT(dst);
MathUtil::addMatrix(m, scalar, dst->m);
}

Expand All @@ -440,7 +440,7 @@ void Mat4::add(const Mat4& mat)

void Mat4::add(const Mat4& m1, const Mat4& m2, Mat4* dst)
{
GP_ASSERT(dst);
AX_ASSERT(dst);
MathUtil::addMatrix(m1.m, m2.m, dst->m);
}

Expand Down Expand Up @@ -588,7 +588,7 @@ void Mat4::getTranslation(Vec3* translation) const

void Mat4::getUpVector(Vec3* dst) const
{
GP_ASSERT(dst);
AX_ASSERT(dst);

dst->x = m[4];
dst->y = m[5];
Expand All @@ -597,7 +597,7 @@ void Mat4::getUpVector(Vec3* dst) const

void Mat4::getDownVector(Vec3* dst) const
{
GP_ASSERT(dst);
AX_ASSERT(dst);

dst->x = -m[4];
dst->y = -m[5];
Expand All @@ -606,7 +606,7 @@ void Mat4::getDownVector(Vec3* dst) const

void Mat4::getLeftVector(Vec3* dst) const
{
GP_ASSERT(dst);
AX_ASSERT(dst);

dst->x = -m[0];
dst->y = -m[1];
Expand All @@ -615,7 +615,7 @@ void Mat4::getLeftVector(Vec3* dst) const

void Mat4::getRightVector(Vec3* dst) const
{
GP_ASSERT(dst);
AX_ASSERT(dst);

dst->x = m[0];
dst->y = m[1];
Expand All @@ -624,7 +624,7 @@ void Mat4::getRightVector(Vec3* dst) const

void Mat4::getForwardVector(Vec3* dst) const
{
GP_ASSERT(dst);
AX_ASSERT(dst);

dst->x = -m[8];
dst->y = -m[9];
Expand All @@ -633,7 +633,7 @@ void Mat4::getForwardVector(Vec3* dst) const

void Mat4::getBackVector(Vec3* dst) const
{
GP_ASSERT(dst);
AX_ASSERT(dst);

dst->x = m[8];
dst->y = m[9];
Expand Down Expand Up @@ -713,7 +713,7 @@ void Mat4::multiply(float scalar, Mat4* dst) const

void Mat4::multiply(const Mat4& m, float scalar, Mat4* dst)
{
GP_ASSERT(dst);
AX_ASSERT(dst);
MathUtil::multiplyMatrix(m.m, scalar, dst->m);
}

Expand All @@ -724,7 +724,7 @@ void Mat4::multiply(const Mat4& mat)

void Mat4::multiply(const Mat4& m1, const Mat4& m2, Mat4* dst)
{
GP_ASSERT(dst);
AX_ASSERT(dst);
MathUtil::multiplyMatrix(m1.m, m2.m, dst->m);
}

Expand Down Expand Up @@ -839,13 +839,13 @@ void Mat4::subtract(const Mat4& mat)

void Mat4::subtract(const Mat4& m1, const Mat4& m2, Mat4* dst)
{
GP_ASSERT(dst);
AX_ASSERT(dst);
MathUtil::subtractMatrix(m1.m, m2.m, dst->m);
}

void Mat4::transformVector(Vec3* vector) const
{
GP_ASSERT(vector);
AX_ASSERT(vector);
transformVector(vector->x, vector->y, vector->z, 0.0f, vector);
}

Expand All @@ -856,20 +856,20 @@ void Mat4::transformVector(const Vec3& vector, Vec3* dst) const

void Mat4::transformVector(float x, float y, float z, float w, Vec3* dst) const
{
GP_ASSERT(dst);
AX_ASSERT(dst);

MathUtil::transformVec4(m, x, y, z, w, reinterpret_cast<float*>(dst));
}

void Mat4::transformVector(Vec4* vector) const
{
GP_ASSERT(vector);
AX_ASSERT(vector);
transformVector(*vector, vector);
}

void Mat4::transformVector(const Vec4& vector, Vec4* dst) const
{
GP_ASSERT(dst);
AX_ASSERT(dst);
MathUtil::transformVec4(m, reinterpret_cast<const float*>(&vector), reinterpret_cast<float*>(dst));
}

Expand Down
6 changes: 3 additions & 3 deletions core/math/Mat4.h
Original file line number Diff line number Diff line change
Expand Up @@ -772,7 +772,7 @@ class AX_DLL Mat4
*/
void set(const float* mat)
{
GP_ASSERT(mat);
AX_ASSERT(mat);
memcpy(m, mat, sizeof(m));
}

Expand Down Expand Up @@ -821,7 +821,7 @@ class AX_DLL Mat4
*/
inline void transformPoint(Vec3* point) const
{
GP_ASSERT(point);
AX_ASSERT(point);
transformVector(point->x, point->y, point->z, 1.0f, point);
}

Expand All @@ -834,7 +834,7 @@ class AX_DLL Mat4
*/
inline void transformPoint(const Vec3& point, Vec3* dst) const
{
GP_ASSERT(dst);
AX_ASSERT(dst);
transformVector(point.x, point.y, point.z, 1.0f, dst);
}

Expand Down
4 changes: 2 additions & 2 deletions core/math/MathUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ NS_AX_MATH_BEGIN

void MathUtil::smooth(float* x, float target, float elapsedTime, float responseTime)
{
GP_ASSERT(x);
AX_ASSERT(x);

if (elapsedTime > 0)
{
Expand All @@ -50,7 +50,7 @@ void MathUtil::smooth(float* x, float target, float elapsedTime, float responseT

void MathUtil::smooth(float* x, float target, float elapsedTime, float riseTime, float fallTime)
{
GP_ASSERT(x);
AX_ASSERT(x);

if (elapsedTime > 0)
{
Expand Down
18 changes: 9 additions & 9 deletions core/math/Quaternion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ void Quaternion::multiply(const Quaternion& q)

void Quaternion::multiply(const Quaternion& q1, const Quaternion& q2, Quaternion* dst)
{
GP_ASSERT(dst);
AX_ASSERT(dst);

float x = q1.w * q2.x + q1.x * q2.w + q1.y * q2.z - q1.z * q2.y;
float y = q1.w * q2.y - q1.x * q2.z + q1.y * q2.w + q1.z * q2.x;
Expand Down Expand Up @@ -153,7 +153,7 @@ void Quaternion::set(const Mat4& m)

float Quaternion::toAxisAngle(Vec3* axis) const
{
GP_ASSERT(axis);
AX_ASSERT(axis);

Quaternion q(x, y, z, w);
q.normalize();
Expand All @@ -167,8 +167,8 @@ float Quaternion::toAxisAngle(Vec3* axis) const

void Quaternion::lerp(const Quaternion& q1, const Quaternion& q2, float t, Quaternion* dst)
{
GP_ASSERT(dst);
GP_ASSERT(!(t < 0.0f || t > 1.0f));
AX_ASSERT(dst);
AX_ASSERT(!(t < 0.0f || t > 1.0f));

if (t == 0.0f)
{
Expand All @@ -191,7 +191,7 @@ void Quaternion::lerp(const Quaternion& q1, const Quaternion& q2, float t, Quate

void Quaternion::slerp(const Quaternion& q1, const Quaternion& q2, float t, Quaternion* dst)
{
GP_ASSERT(dst);
AX_ASSERT(dst);
slerp(q1.x, q1.y, q1.z, q1.w, q2.x, q2.y, q2.z, q2.w, t, &dst->x, &dst->y, &dst->z, &dst->w);
}

Expand All @@ -202,7 +202,7 @@ void Quaternion::squad(const Quaternion& q1,
float t,
Quaternion* dst)
{
GP_ASSERT(!(t < 0.0f || t > 1.0f));
AX_ASSERT(!(t < 0.0f || t > 1.0f));

Quaternion dstQ(0.0f, 0.0f, 0.0f, 1.0f);
Quaternion dstS(0.0f, 0.0f, 0.0f, 1.0f);
Expand Down Expand Up @@ -230,8 +230,8 @@ void Quaternion::slerp(float q1x,
// It contains no division operations, no trig, no inverse trig
// and no sqrt. Not only does this code tolerate small constraint
// errors in the input quaternions, it actually corrects for them.
GP_ASSERT(dstx && dsty && dstz && dstw);
GP_ASSERT(!(t < 0.0f || t > 1.0f));
AX_ASSERT(dstx && dsty && dstz && dstw);
AX_ASSERT(!(t < 0.0f || t > 1.0f));

if (t == 0.0f)
{
Expand Down Expand Up @@ -325,7 +325,7 @@ void Quaternion::slerp(float q1x,

void Quaternion::slerpForSquad(const Quaternion& q1, const Quaternion& q2, float t, Quaternion* dst)
{
GP_ASSERT(dst);
AX_ASSERT(dst);

// cos(omega) = q1 * q2;
// slerp(q1, q2, t) = (q1*sin((1-t)*omega) + q2*sin(t*omega))/sin(omega);
Expand Down
4 changes: 2 additions & 2 deletions core/math/Quaternion.h
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ class AX_DLL Quaternion
*/
static void createFromAxisAngle(const Vec3& axis, float angle, Quaternion* dst)
{
GP_ASSERT(dst);
AX_ASSERT(dst);

float halfAngle = angle * 0.5f;
float sinHalfAngle = sinf(halfAngle);
Expand Down Expand Up @@ -281,7 +281,7 @@ class AX_DLL Quaternion
*/
constexpr void set(float* array)
{
GP_ASSERT(array);
AX_ASSERT(array);

x = array[0];
y = array[1];
Expand Down
Loading

0 comments on commit 732fbf5

Please sign in to comment.