mirror of https://github.com/axmolengine/axmol.git
Merge pull request #6524 from dabingnn/v3_refactor_inverse_conjugate_etc
V3 refactor inverse conjugate etc
This commit is contained in:
commit
b549e6b4f9
|
@ -739,8 +739,7 @@ Vector2 Director::convertToGL(const Vector2& uiPoint)
|
|||
Matrix transform;
|
||||
GLToClipTransform(&transform);
|
||||
|
||||
Matrix transformInv;
|
||||
transform.invert(&transformInv);
|
||||
Matrix transformInv = transform.getInversed();
|
||||
|
||||
// Calculate z=0 using -> transform*[0, 0, 0, 1]/w
|
||||
float zClip = transform.m[14]/transform.m[15];
|
||||
|
|
|
@ -1452,7 +1452,7 @@ AffineTransform Node::getParentToNodeAffineTransform() const
|
|||
const Matrix& Node::getParentToNodeTransform() const
|
||||
{
|
||||
if ( _inverseDirty ) {
|
||||
_transform.invert(&_inverse);
|
||||
_inverse = _transform.getInversed();
|
||||
_inverseDirty = false;
|
||||
}
|
||||
|
||||
|
@ -1489,9 +1489,7 @@ AffineTransform Node::getWorldToNodeAffineTransform() const
|
|||
|
||||
Matrix Node::getWorldToNodeTransform() const
|
||||
{
|
||||
Matrix result = getNodeToWorldTransform();
|
||||
result.invert();
|
||||
return result;
|
||||
return getNodeToWorldTransform().getInversed();
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -274,13 +274,13 @@ Matrix* kmMat4Identity(Matrix* pOut)
|
|||
|
||||
Matrix* kmMat4Inverse(Matrix* pOut, const Matrix* pM)
|
||||
{
|
||||
pM->invert(pOut);
|
||||
*pOut = pM->getInversed();
|
||||
return pOut;
|
||||
}
|
||||
|
||||
Matrix* kmMat4Transpose(Matrix* pOut, const Matrix* pIn)
|
||||
{
|
||||
pIn->transpose(pOut);
|
||||
*pOut = pIn->getTransposed();
|
||||
return pOut;
|
||||
}
|
||||
|
||||
|
|
|
@ -634,12 +634,14 @@ void Matrix::getBackVector(Vector3* dst) const
|
|||
dst->z = m[10];
|
||||
}
|
||||
|
||||
bool Matrix::invert()
|
||||
Matrix Matrix::getInversed() const
|
||||
{
|
||||
return invert(this);
|
||||
Matrix mat(*this);
|
||||
mat.inverse();
|
||||
return mat;
|
||||
}
|
||||
|
||||
bool Matrix::invert(Matrix* dst) const
|
||||
bool Matrix::inverse()
|
||||
{
|
||||
float a0 = m[0] * m[5] - m[1] * m[4];
|
||||
float a1 = m[0] * m[6] - m[2] * m[4];
|
||||
|
@ -683,7 +685,7 @@ bool Matrix::invert(Matrix* dst) const
|
|||
inverse.m[14] = -m[12] * a3 + m[13] * a1 - m[14] * a0;
|
||||
inverse.m[15] = m[8] * a3 - m[9] * a1 + m[10] * a0;
|
||||
|
||||
multiply(inverse, 1.0f / det, dst);
|
||||
multiply(inverse, 1.0f / det, this);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -724,14 +726,14 @@ void Matrix::multiply(const Matrix& m1, const Matrix& m2, Matrix* dst)
|
|||
|
||||
void Matrix::negate()
|
||||
{
|
||||
negate(this);
|
||||
MathUtil::negateMatrix(m, m);
|
||||
}
|
||||
|
||||
void Matrix::negate(Matrix* dst) const
|
||||
Matrix Matrix::getNegated() const
|
||||
{
|
||||
GP_ASSERT(dst);
|
||||
|
||||
MathUtil::negateMatrix(m, dst->m);
|
||||
Matrix mat(*this);
|
||||
mat.negate();
|
||||
return mat;
|
||||
}
|
||||
|
||||
void Matrix::rotate(const Quaternion& q)
|
||||
|
@ -946,14 +948,14 @@ void Matrix::translate(const Vector3& t, Matrix* dst) const
|
|||
|
||||
void Matrix::transpose()
|
||||
{
|
||||
transpose(this);
|
||||
MathUtil::transposeMatrix(m, m);
|
||||
}
|
||||
|
||||
void Matrix::transpose(Matrix* dst) const
|
||||
Matrix Matrix::getTransposed() const
|
||||
{
|
||||
GP_ASSERT(dst);
|
||||
|
||||
MathUtil::transposeMatrix(m, dst->m);
|
||||
Matrix mat(*this);
|
||||
mat.transpose();
|
||||
return mat;
|
||||
}
|
||||
|
||||
NS_CC_MATH_END
|
||||
|
|
|
@ -467,7 +467,7 @@ public:
|
|||
*
|
||||
* @return true if the the matrix can be inverted, false otherwise.
|
||||
*/
|
||||
bool invert();
|
||||
bool inverse();
|
||||
|
||||
/**
|
||||
* Stores the inverse of this matrix in the specified matrix.
|
||||
|
@ -476,7 +476,7 @@ public:
|
|||
*
|
||||
* @return true if the the matrix can be inverted, false otherwise.
|
||||
*/
|
||||
bool invert(Matrix* dst) const;
|
||||
Matrix getInversed() const;
|
||||
|
||||
/**
|
||||
* Determines if this matrix is equal to the identity matrix.
|
||||
|
@ -535,7 +535,7 @@ public:
|
|||
*
|
||||
* @param dst A matrix to store the result in.
|
||||
*/
|
||||
void negate(Matrix* dst) const;
|
||||
Matrix getNegated() const;
|
||||
|
||||
/**
|
||||
* Post-multiplies this matrix by the matrix corresponding to the
|
||||
|
@ -856,7 +856,7 @@ public:
|
|||
*
|
||||
* @param dst A matrix to store the result in.
|
||||
*/
|
||||
void transpose(Matrix* dst) const;
|
||||
Matrix getTransposed() const;
|
||||
|
||||
/**
|
||||
* Calculates the sum of this matrix with the given matrix.
|
||||
|
|
|
@ -81,35 +81,28 @@ void Quaternion::createFromAxisAngle(const Vector3& axis, float angle, Quaternio
|
|||
|
||||
void Quaternion::conjugate()
|
||||
{
|
||||
conjugate(this);
|
||||
x = -x;
|
||||
y = -y;
|
||||
z = -z;
|
||||
w = w;
|
||||
}
|
||||
|
||||
void Quaternion::conjugate(Quaternion* dst) const
|
||||
Quaternion Quaternion::getConjugated() const
|
||||
{
|
||||
GP_ASSERT(dst);
|
||||
|
||||
dst->x = -x;
|
||||
dst->y = -y;
|
||||
dst->z = -z;
|
||||
dst->w = w;
|
||||
Quaternion q(*this);
|
||||
q.conjugate();
|
||||
return q;
|
||||
}
|
||||
|
||||
bool Quaternion::inverse()
|
||||
{
|
||||
return inverse(this);
|
||||
}
|
||||
|
||||
bool Quaternion::inverse(Quaternion* dst) const
|
||||
{
|
||||
GP_ASSERT(dst);
|
||||
|
||||
float n = x * x + y * y + z * z + w * w;
|
||||
if (n == 1.0f)
|
||||
{
|
||||
dst->x = -x;
|
||||
dst->y = -y;
|
||||
dst->z = -z;
|
||||
dst->w = w;
|
||||
x = -x;
|
||||
y = -y;
|
||||
z = -z;
|
||||
w = w;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -119,14 +112,21 @@ bool Quaternion::inverse(Quaternion* dst) const
|
|||
return false;
|
||||
|
||||
n = 1.0f / n;
|
||||
dst->x = -x * n;
|
||||
dst->y = -y * n;
|
||||
dst->z = -z * n;
|
||||
dst->w = w * n;
|
||||
x = -x * n;
|
||||
y = -y * n;
|
||||
z = -z * n;
|
||||
w = w * n;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Quaternion Quaternion::getInversed() const
|
||||
{
|
||||
Quaternion q(*this);
|
||||
q.inverse();
|
||||
return q;
|
||||
}
|
||||
|
||||
void Quaternion::multiply(const Quaternion& q)
|
||||
{
|
||||
multiply(*this, q, this);
|
||||
|
|
|
@ -167,7 +167,7 @@ public:
|
|||
*
|
||||
* @param dst A quaternion to store the conjugate in.
|
||||
*/
|
||||
void conjugate(Quaternion* dst) const;
|
||||
Quaternion getConjugated() const;
|
||||
|
||||
/**
|
||||
* Sets this quaternion to the inverse of itself.
|
||||
|
@ -193,7 +193,7 @@ public:
|
|||
*
|
||||
* @return true if the inverse can be computed, false otherwise.
|
||||
*/
|
||||
bool inverse(Quaternion* dst) const;
|
||||
Quaternion getInversed() const;
|
||||
|
||||
/**
|
||||
* Multiplies this quaternion by the specified one and stores the result in this quaternion.
|
||||
|
|
Loading…
Reference in New Issue