- new: whole quaternion library enabled for Lite-C
- new: whole 3x3 rotation matrix library enabled for Lite-C
- new: some PI constants (single, double, inverted...)

quaternion library functions
Click to reveal..
// quaternion
typedef struct NxQuat {
float x, y, z, w;
} NxQuat;

//...

// constructors
NxQuat* pXquatCreate (); // uninitialized quaternion
NxQuat* pXquatCreateCopy (NxQuat*); // from another quaternion (copy)
NxQuat* pXquatCreateVec0 (NxVec3* v); // from v = x,y,z and w = 0
NxQuat* pXquatCreateVecW (NxVec3* v, float w); // from v = x,y,z and w
NxQuat* pXquatCreateAngAxis (float angle, NxVec3* axis); // from angle-axis representation
NxQuat* pXquatCreateAngle (ANGLE* a); // from euler angle
NxQuat* pXquatCreateMat (NxMat33* m); // from orientation matrix

// setters
NxQuat* pXquatSet (NxQuat*, NxQuat* other); // from other quaternion
NxQuat* pXquatSetWXYZ (NxQuat*, float w, float x, float y, float z);
NxQuat* pXquatSetArrWXYZ (NxQuat*, float* wxyz); // from array
NxQuat* pXquatSetXYZW (NxQuat*, float x, float y, float z, float w);
NxQuat* pXquatSetArrXYZW (NxQuat*, float* xyzw); // from array
NxQuat* pXquatSetX (NxQuat*, float);
NxQuat* pXquatSetY (NxQuat*, float);
NxQuat* pXquatSetZ (NxQuat*, float);
NxQuat* pXquatSetW (NxQuat*, float);

// getters
NxQuat* pXquatGetWXYZ (NxQuat*, float* wxyz); // to array
NxQuat* pXquatGetXYZW (NxQuat*, float* xyzw); // to array

// sets q to the identity rotation
NxQuat* pXquatId (NxQuat* q);

// sets q to the quaternion to [0,0,0,1]
NxQuat* pXquatZero (NxQuat* q);

// randomizes q as unit quaternion
NxQuat* pXquatRandom (NxQuat* q);

// sets the quaterion to the opposite rotation
NxQuat* pXquatInvert (NxQuat*);

// creates from angle-axis representation, euler angle, or rotation matrix
NxQuat* pXquatFromAngleAxis (NxQuat*, float angle, NxVec3* axis);
NxQuat* pXquatFromAngleAxisFast (NxQuat*, float angle, NxVec3* axis);
NxQuat* pXquatFromMat (NxQuat*, NxMat33* m);
NxQuat* pXquatFromAngle (NxQuat* q, ANGLE* a);

// fetches the angle/axis or euler angle given by the NxQuat
NxQuat* pXquatGetAngleAxis (NxQuat*, float* angle, NxVec3* axis);

// gets the angle between the quat and another quat or the identity quaternion
float pXquatGetAngleIdentity (NxQuat*);
float pXquatGetAngle (NxQuat*, NxQuat* other);

// squared 4D vector length, should be 1 for unit quaternions
float pXquatGetLengthSq (NxQuat*);

// returns the scalar product of two quaternions
float pXquatDot (NxQuat*, NxQuat*);

// maps to the closest unit quaternion
NxQuat* pXquatNormalize (NxQuat*);

// conjugates q
NxQuat* pXquatConjugate (NxQuat* q);

// multiplies a with b/v
NxQuat* pXquatMultiply (NxQuat* a, NxQuat* b);
NxQuat* pXquatMultiplyVec (NxQuat* a, NxVec3* v);

// spherical linear interpolation between a and b by t percent (0...100)
// result is stored in q: q = slerp(t, a, b)
NxQuat* pXquatSlerp (NxQuat* q, float t, NxQuat* a, NxQuat* b);

// rotates a vector
NxVec3* pXquatRotate (NxQuat*, NxVec3* v);
NxVec3* pXquatInvRotate (NxQuat*, NxVec3* v);

// transforms a vector at position p
NxQuat* pXquatTransform (NxQuat*, NxVec3* v, NxVec3* p);
NxQuat* pXquatInvTransform (NxQuat*, NxVec3* v, NxVec3* p);

// negates q
NxQuat* pXquatNegate (NxQuat* q);

// arithmethics
NxQuat* pXquatSub (NxQuat* q, NxQuat* other);
NxQuat* pXquatMul (NxQuat* q, NxQuat* other);
NxQuat* pXquatMulS (NxQuat* q, float s);
NxQuat* pXquatAdd (NxQuat* q, NxQuat* other);

// tests
BOOL pXquatIsIdentityRotation (NxQuat*);
BOOL pXquatIsFinite (NxQuat*);

rotation matrix library functions
Click to reveal..
typedef struct NxMat33 {
float m[3][3];
} NxMat33;

typedef int NxMatrixType;
#define NX_ZERO_MATRIX 0 // all zeros
#define NX_IDENTITY_MATRIX 1 // identity matrix

//...

// constructors
NxMat33* pXmatCreate ();
NxMat33* pXmatCreateType (NxMatrixType type);
NxMat33* pXmatCreateRows (NxVec3* row0, NxVec3* row1, NxVec3* row2);
NxMat33* pXmatCreateCopy (NxMat33* m);
NxMat33* pXmatCreateQuat (NxQuat* q);
NxMat33* pXmatCreateAngle (ANGLE* a);

// setters
NxMat33* pXmatSet (NxMat33* m, int row, int col, float value);
NxMat33* pXmatSetRow (NxMat33* m, int row, NxVec3* v);
NxMat33* pXmatSetRowMajor (NxMat33* m, float* v);
NxMat33* pXmatSetRowMajorStride4 (NxMat33* m, float* v);
NxMat33* pXmatSetColumn (NxMat33* m, int col, NxVec3* v);
NxMat33* pXmatSetColumnMajor (NxMat33* m, float* v);
NxMat33* pXmatSetColumnMajorStride4 (NxMat33* m, float* v);

// getters
float pXmatGet (NxMat33* m, int row, int col);
NxVec3* pXmatGetRow (NxMat33* m, int row, NxVec3* v);
NxMat33* pXmatGetRowMajor (NxMat33* m, float* v);
NxMat33* pXmatGetRowMajorStride4 (NxMat33* m, float* v);
NxVec3* pXmatGetColumn (NxMat33* m, int col, NxVec3* v);
NxMat33* pXmatGetColumnMajor (NxMat33* m, float* v);
NxMat33* pXmatGetColumnMajorStride4 (NxMat33* m, float* v);

// returns true for identity matrix
BOOL pXmatIsIdentity (NxMat33* m);

// returns true for zero matrix
BOOL pXmatIsZero (NxMat33* m);

// returns true if all elems are finite (not NAN or INF, etc.)
BOOL pXmatIsFinite (NxMat33* m);

// sets this matrix to the zero matrix
NxMat33* pXmatZero (NxMat33* m);

// sets this matrix to the identity matrix
NxMat33* pXmatId (NxMat33* m);

// m = -m
NxMat33* pXmatSetNegative (NxMat33* m);

// sets this matrix to the diagonal matrix
NxMat33* pXmatDiagonal (NxMat33* m, NxVec3* d);

// sets this matrix to the star (skew symmetric) matrix
NxMat33* pXmatStar (NxMat33* m, NxVec3* v);

NxMat33* pXmatFromQuat (NxMat33* m, NxQuat* q);
NxQuat* pXmatToQuat (NxMat33* m, NxQuat* q);

NxMat33* pXmatFromAngle (NxMat33* m, ANGLE* a);
ANGLE* pXmatToAngle (NxMat33* m, ANGLE* a);

NxMat33* pXmatAdd (NxMat33* m, NxMat33* other);
NxMat33* pXmatAddDest (NxMat33* m, NxMat33* other, NxMat33* dest);
NxMat33* pXmatSub (NxMat33* m, NxMat33* other);
NxMat33* pXmatSubDest (NxMat33* m, NxMat33* other, NxMat33* dest);
NxMat33* pXmatScale (NxMat33* m, float s); // m = m * s
NxMat33* pXmatScaleDest (NxMat33* m, float s, NxMat33* dest); // dest = m * s
NxMat33* pXmatMultiply (NxMat33* m, NxMat33* other); // m = m * other
NxMat33* pXmatMultiplyDest (NxMat33* m, NxMat33* other, NxMat33* dest); // dest = m * other
NxVec3* pXmatMultiplyVec (NxMat33* m, NxVec3* v);
NxVec3* pXmatMultiplyVecDest (NxMat33* m, NxVec3* v, NxVec3* dest);
NxMat33* pXmatMultiplyTransposeLeft (NxMat33* m, NxMat33* left, NxMat33* right); // m = transpose(left) * right
NxMat33* pXmatMultiplyTransposeRight (NxMat33* m, NxMat33* left, NxMat33* right); // m = left * transpose(right)
NxMat33* pXmatMultiplyTransposeRightVec (NxMat33* m, NxVec3* left, NxVec3* right); // m = left * transpose(right)
NxMat33* pXmatDiv (NxMat33* m, float s);

// returns determinant
float pXmatDeterminant (NxMat33* m);

// assigns inverse to dest
BOOL pXmatGetInverse (NxMat33* m, NxMat33* dest);

// m = transpose(other)
NxMat33* pXmatSetTransposed (NxMat33* m, NxMat33* other);

// m = transpose(m)
NxMat33* pXmatTranspose (NxMat33* m);

// m = m * [ d.x 0 0; 0 d.y 0; 0 0 d.z ]
NxMat33* pXmatMultiplyDiagonal (NxMat33* m, NxVec3* d);

// dest = m * [ d.x 0 0; 0 d.y 0; 0 0 d.z ]
NxMat33* pXmatMultiplyDiagonalDest (NxMat33* m, NxVec3* d, NxMat33* dest);

// m = transpose(m) * [ d.x 0 0; 0 d.y 0; 0 0 d.z ]
NxMat33* pXmatMultiplyDiagonalTranspose (NxMat33* m, NxVec3* d);

// dest = transpose(m) * [ d.x 0 0; 0 d.y 0; 0 0 d.z ]
NxMat33* pXmatMultiplyDiagonalTransposeDest (NxMat33* m, NxVec3* d, NxMat33* dest);

// rotate m around x, y or z axis
NxMat33* pXmatRotX (NxMat33* m, float angle);
NxMat33* pXmatRotY (NxMat33* m, float angle);
NxMat33* pXmatRotZ (NxMat33* m, float angle);

// returns if matrix rows and columns are normalized
BOOL pXmatIsNormalized (NxMat33* m);

// returns if matrix rows and columns are orthogonal
BOOL pXmatIsOrthogonal (NxMat33* m);

// returns if matrix is rotation matrix
BOOL pXmatIsRotation (NxMat33* m);


Download lib, dll and header here: ackphysx.20111126.dll.h.lib.rar and on SVN the whole source code as always.

Have fun,
-Christian

Last edited by HeelX; 11/27/11 13:50.