addition to raylib to create matrix from 3 euler angles (#938)
This commit is contained in:
parent
e6e48675cc
commit
6f2f09947f
@ -92,6 +92,7 @@ int main(void)
|
|||||||
while (pitchOffset < -180) pitchOffset += 360;
|
while (pitchOffset < -180) pitchOffset += 360;
|
||||||
pitchOffset *= 10;
|
pitchOffset *= 10;
|
||||||
|
|
||||||
|
/* matrix transform done with multiplication to combine rotations
|
||||||
Matrix transform = MatrixIdentity();
|
Matrix transform = MatrixIdentity();
|
||||||
|
|
||||||
transform = MatrixMultiply(transform, MatrixRotateZ(DEG2RAD*roll));
|
transform = MatrixMultiply(transform, MatrixRotateZ(DEG2RAD*roll));
|
||||||
@ -99,8 +100,11 @@ int main(void)
|
|||||||
transform = MatrixMultiply(transform, MatrixRotateY(DEG2RAD*yaw));
|
transform = MatrixMultiply(transform, MatrixRotateY(DEG2RAD*yaw));
|
||||||
|
|
||||||
model.transform = transform;
|
model.transform = transform;
|
||||||
//----------------------------------------------------------------------------------
|
*/
|
||||||
|
// matrix created from multiple axes at once
|
||||||
|
model.transform = MatrixRotateXYZ((Vector3){DEG2RAD*pitch,DEG2RAD*yaw,DEG2RAD*roll});
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
// Draw
|
// Draw
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
BeginDrawing();
|
BeginDrawing();
|
||||||
|
@ -56,7 +56,7 @@
|
|||||||
#if defined(RAYMATH_IMPLEMENTATION)
|
#if defined(RAYMATH_IMPLEMENTATION)
|
||||||
#if defined(_WIN32) && defined(BUILD_LIBTYPE_SHARED)
|
#if defined(_WIN32) && defined(BUILD_LIBTYPE_SHARED)
|
||||||
#define RMDEF __declspec(dllexport) extern inline // We are building raylib as a Win32 shared library (.dll).
|
#define RMDEF __declspec(dllexport) extern inline // We are building raylib as a Win32 shared library (.dll).
|
||||||
#elif defined(_WIN32) && defined(USE_LIBTYPE_SHARED)
|
#elif defined(_WIN32) && defined(USE_LIBTYPE_SHARED)
|
||||||
#define RMDEF __declspec(dllimport) // We are using raylib as a Win32 shared library (.dll)
|
#define RMDEF __declspec(dllimport) // We are using raylib as a Win32 shared library (.dll)
|
||||||
#else
|
#else
|
||||||
#define RMDEF extern inline // Provide external definition
|
#define RMDEF extern inline // Provide external definition
|
||||||
@ -113,7 +113,7 @@
|
|||||||
float y;
|
float y;
|
||||||
float z;
|
float z;
|
||||||
} Vector3;
|
} Vector3;
|
||||||
|
|
||||||
// Quaternion type
|
// Quaternion type
|
||||||
typedef struct Quaternion {
|
typedef struct Quaternion {
|
||||||
float x;
|
float x;
|
||||||
@ -794,6 +794,33 @@ RMDEF Matrix MatrixRotate(Vector3 axis, float angle)
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Returns xyz-rotation matrix (angles in radians)
|
||||||
|
RMDEF Matrix MatrixRotateXYZ(Vector3 ang)
|
||||||
|
{
|
||||||
|
Matrix result = MatrixIdentity();
|
||||||
|
|
||||||
|
float cosz = cosf(-ang.z);
|
||||||
|
float sinz = sinf(-ang.z);
|
||||||
|
float cosy = cosf(-ang.y);
|
||||||
|
float siny = sinf(-ang.y);
|
||||||
|
float cosx = cosf(-ang.x);
|
||||||
|
float sinx = sinf(-ang.x);
|
||||||
|
|
||||||
|
result.m0 = cosz * cosy;
|
||||||
|
result.m4 = (cosz * siny * sinx) - (sinz * cosx);
|
||||||
|
result.m8 = (cosz * siny * cosx) + (sinz * sinx);
|
||||||
|
|
||||||
|
result.m1 = sinz * cosy;
|
||||||
|
result.m5 = (sinz * siny * sinx) + (cosz * cosx);
|
||||||
|
result.m9 = (sinz * siny * cosx) - (cosz * sinx);
|
||||||
|
|
||||||
|
result.m2 = -siny;
|
||||||
|
result.m6 = cosy * sinx;
|
||||||
|
result.m10= cosy * cosx;
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
// Returns x-rotation matrix (angle in radians)
|
// Returns x-rotation matrix (angle in radians)
|
||||||
RMDEF Matrix MatrixRotateX(float angle)
|
RMDEF Matrix MatrixRotateX(float angle)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user