Functions parameters reorganize: Axis and Angle
sin(), cos() functions cached and replaced by float c99 versions sinf(), cos()
This commit is contained in:
parent
65ecde1e75
commit
df5c64d0be
5 changed files with 38 additions and 35 deletions
12
src/models.c
12
src/models.c
|
@ -1149,14 +1149,14 @@ void DrawModel(Model model, Vector3 position, float scale, Color tint)
|
||||||
Vector3 vScale = { scale, scale, scale };
|
Vector3 vScale = { scale, scale, scale };
|
||||||
Vector3 rotationAxis = { 0.0f, 0.0f, 0.0f };
|
Vector3 rotationAxis = { 0.0f, 0.0f, 0.0f };
|
||||||
|
|
||||||
DrawModelEx(model, position, 0.0f, rotationAxis, vScale, tint);
|
DrawModelEx(model, position, rotationAxis, 0.0f, vScale, tint);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Draw a model with extended parameters
|
// Draw a model with extended parameters
|
||||||
void DrawModelEx(Model model, Vector3 position, float rotationAngle, Vector3 rotationAxis, Vector3 scale, Color tint)
|
void DrawModelEx(Model model, Vector3 position, Vector3 rotationAxis, float rotationAngle, Vector3 scale, Color tint)
|
||||||
{
|
{
|
||||||
// NOTE: Rotation must be provided in degrees, it's converted to radians inside rlglDrawModel()
|
// NOTE: Rotation must be provided in degrees, it's converted to radians inside rlglDrawModel()
|
||||||
rlglDrawModel(model, position, rotationAngle, rotationAxis, scale, tint, false);
|
rlglDrawModel(model, position, rotationAxis, rotationAngle, scale, tint, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Draw a model wires (with texture if set)
|
// Draw a model wires (with texture if set)
|
||||||
|
@ -1165,14 +1165,14 @@ void DrawModelWires(Model model, Vector3 position, float scale, Color color)
|
||||||
Vector3 vScale = { scale, scale, scale };
|
Vector3 vScale = { scale, scale, scale };
|
||||||
Vector3 rotationAxis = { 0.0f, 0.0f, 0.0f };
|
Vector3 rotationAxis = { 0.0f, 0.0f, 0.0f };
|
||||||
|
|
||||||
rlglDrawModel(model, position, 0.0f, rotationAxis, vScale, color, true);
|
rlglDrawModel(model, position, rotationAxis, 0.0f, vScale, color, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Draw a model wires (with texture if set) with extended parameters
|
// Draw a model wires (with texture if set) with extended parameters
|
||||||
void DrawModelWiresEx(Model model, Vector3 position, float rotationAngle, Vector3 rotationAxis, Vector3 scale, Color tint)
|
void DrawModelWiresEx(Model model, Vector3 position, Vector3 rotationAxis, float rotationAngle, Vector3 scale, Color tint)
|
||||||
{
|
{
|
||||||
// NOTE: Rotation must be provided in degrees, it's converted to radians inside rlglDrawModel()
|
// NOTE: Rotation must be provided in degrees, it's converted to radians inside rlglDrawModel()
|
||||||
rlglDrawModel(model, position, rotationAngle, rotationAxis, scale, tint, true);
|
rlglDrawModel(model, position, rotationAxis, rotationAngle, scale, tint, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Draw a billboard
|
// Draw a billboard
|
||||||
|
|
|
@ -764,9 +764,9 @@ void UnloadModel(Model model);
|
||||||
void SetModelTexture(Model *model, Texture2D texture); // Link a texture to a model
|
void SetModelTexture(Model *model, Texture2D texture); // Link a texture to a model
|
||||||
|
|
||||||
void DrawModel(Model model, Vector3 position, float scale, Color tint); // Draw a model (with texture if set)
|
void DrawModel(Model model, Vector3 position, float scale, Color tint); // Draw a model (with texture if set)
|
||||||
void DrawModelEx(Model model, Vector3 position, float rotationAngle, Vector3 rotationAxis, Vector3 scale, Color tint); // Draw a model with extended parameters
|
void DrawModelEx(Model model, Vector3 position, Vector3 rotationAxis, float rotationAngle, Vector3 scale, Color tint); // Draw a model with extended parameters
|
||||||
void DrawModelWires(Model model, Vector3 position, float scale, Color color); // Draw a model wires (with texture if set)
|
void DrawModelWires(Model model, Vector3 position, float scale, Color color); // Draw a model wires (with texture if set)
|
||||||
void DrawModelWiresEx(Model model, Vector3 position, float rotationAngle, Vector3 rotationAxis, Vector3 scale, Color tint); // Draw a model wires (with texture if set) with extended parameters
|
void DrawModelWiresEx(Model model, Vector3 position, Vector3 rotationAxis, float rotationAngle, Vector3 scale, Color tint); // Draw a model wires (with texture if set) with extended parameters
|
||||||
void DrawBoundingBox(BoundingBox box); // Draw bounding box (wires)
|
void DrawBoundingBox(BoundingBox box); // Draw bounding box (wires)
|
||||||
|
|
||||||
void DrawBillboard(Camera camera, Texture2D texture, Vector3 center, float size, Color tint); // Draw a billboard texture
|
void DrawBillboard(Camera camera, Texture2D texture, Vector3 center, float size, Color tint); // Draw a billboard texture
|
||||||
|
|
|
@ -141,7 +141,7 @@ RMDEF Matrix MatrixIdentity(void); // Returns identit
|
||||||
RMDEF Matrix MatrixAdd(Matrix left, Matrix right); // Add two matrices
|
RMDEF Matrix MatrixAdd(Matrix left, Matrix right); // Add two matrices
|
||||||
RMDEF Matrix MatrixSubstract(Matrix left, Matrix right); // Substract two matrices (left - right)
|
RMDEF Matrix MatrixSubstract(Matrix left, Matrix right); // Substract two matrices (left - right)
|
||||||
RMDEF Matrix MatrixTranslate(float x, float y, float z); // Returns translation matrix
|
RMDEF Matrix MatrixTranslate(float x, float y, float z); // Returns translation matrix
|
||||||
RMDEF Matrix MatrixRotate(float angle, Vector3 axis); // Returns rotation matrix for an angle around an specified axis (angle in radians)
|
RMDEF Matrix MatrixRotate(Vector3 axis, float angle); // Returns rotation matrix for an angle around an specified axis (angle in radians)
|
||||||
RMDEF Matrix MatrixRotateX(float angle); // Returns x-rotation matrix (angle in radians)
|
RMDEF Matrix MatrixRotateX(float angle); // Returns x-rotation matrix (angle in radians)
|
||||||
RMDEF Matrix MatrixRotateY(float angle); // Returns y-rotation matrix (angle in radians)
|
RMDEF Matrix MatrixRotateY(float angle); // Returns y-rotation matrix (angle in radians)
|
||||||
RMDEF Matrix MatrixRotateZ(float angle); // Returns z-rotation matrix (angle in radians)
|
RMDEF Matrix MatrixRotateZ(float angle); // Returns z-rotation matrix (angle in radians)
|
||||||
|
@ -162,8 +162,8 @@ RMDEF Quaternion QuaternionMultiply(Quaternion q1, Quaternion q2); // Calcula
|
||||||
RMDEF Quaternion QuaternionSlerp(Quaternion q1, Quaternion q2, float slerp); // Calculates spherical linear interpolation between two quaternions
|
RMDEF Quaternion QuaternionSlerp(Quaternion q1, Quaternion q2, float slerp); // Calculates spherical linear interpolation between two quaternions
|
||||||
RMDEF Quaternion QuaternionFromMatrix(Matrix matrix); // Returns a quaternion for a given rotation matrix
|
RMDEF Quaternion QuaternionFromMatrix(Matrix matrix); // Returns a quaternion for a given rotation matrix
|
||||||
RMDEF Matrix QuaternionToMatrix(Quaternion q); // Returns a matrix for a given quaternion
|
RMDEF Matrix QuaternionToMatrix(Quaternion q); // Returns a matrix for a given quaternion
|
||||||
RMDEF Quaternion QuaternionFromAxisAngle(float angle, Vector3 axis); // Returns rotation quaternion for an angle and axis
|
RMDEF Quaternion QuaternionFromAxisAngle(Vector3 axis, float angle); // Returns rotation quaternion for an angle and axis
|
||||||
RMDEF void QuaternionToAxisAngle(Quaternion q, float *outAngle, Vector3 *outAxis); // Returns the rotation angle and axis for a given quaternion
|
RMDEF void QuaternionToAxisAngle(Quaternion q, Vector3 *outAxis, float *outAngle); // Returns the rotation angle and axis for a given quaternion
|
||||||
RMDEF void QuaternionTransform(Quaternion *q, Matrix mat); // Transform a quaternion given a transformation matrix
|
RMDEF void QuaternionTransform(Quaternion *q, Matrix mat); // Transform a quaternion given a transformation matrix
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
@ -587,7 +587,7 @@ RMDEF Matrix MatrixTranslate(float x, float y, float z)
|
||||||
|
|
||||||
// Create rotation matrix from axis and angle
|
// Create rotation matrix from axis and angle
|
||||||
// NOTE: Angle should be provided in radians
|
// NOTE: Angle should be provided in radians
|
||||||
RMDEF Matrix MatrixRotate(float angle, Vector3 axis)
|
RMDEF Matrix MatrixRotate(Vector3 axis, float angle)
|
||||||
{
|
{
|
||||||
Matrix result;
|
Matrix result;
|
||||||
|
|
||||||
|
@ -605,9 +605,9 @@ RMDEF Matrix MatrixRotate(float angle, Vector3 axis)
|
||||||
z *= length;
|
z *= length;
|
||||||
}
|
}
|
||||||
|
|
||||||
float s = sinf(angle);
|
float sinres = sinf(angle);
|
||||||
float c = cosf(angle);
|
float cosres = cosf(angle);
|
||||||
float t = 1.0f - c;
|
float t = 1.0f - cosres;
|
||||||
|
|
||||||
// Cache some matrix values (speed optimization)
|
// Cache some matrix values (speed optimization)
|
||||||
float a00 = mat.m0, a01 = mat.m1, a02 = mat.m2, a03 = mat.m3;
|
float a00 = mat.m0, a01 = mat.m1, a02 = mat.m2, a03 = mat.m3;
|
||||||
|
@ -615,9 +615,9 @@ RMDEF Matrix MatrixRotate(float angle, Vector3 axis)
|
||||||
float a20 = mat.m8, a21 = mat.m9, a22 = mat.m10, a23 = mat.m11;
|
float a20 = mat.m8, a21 = mat.m9, a22 = mat.m10, a23 = mat.m11;
|
||||||
|
|
||||||
// Construct the elements of the rotation matrix
|
// Construct the elements of the rotation matrix
|
||||||
float b00 = x*x*t + c, b01 = y*x*t + z*s, b02 = z*x*t - y*s;
|
float b00 = x*x*t + cosres, b01 = y*x*t + z*sinres, b02 = z*x*t - y*sinres;
|
||||||
float b10 = x*y*t - z*s, b11 = y*y*t + c, b12 = z*y*t + x*s;
|
float b10 = x*y*t - z*sinres, b11 = y*y*t + cosres, b12 = z*y*t + x*sinres;
|
||||||
float b20 = x*z*t + y*s, b21 = y*z*t - x*s, b22 = z*z*t + c;
|
float b20 = x*z*t + y*sinres, b21 = y*z*t - x*sinres, b22 = z*z*t + cosres;
|
||||||
|
|
||||||
// Perform rotation-specific matrix multiplication
|
// Perform rotation-specific matrix multiplication
|
||||||
result.m0 = a00*b00 + a10*b01 + a20*b02;
|
result.m0 = a00*b00 + a10*b01 + a20*b02;
|
||||||
|
@ -688,8 +688,8 @@ RMDEF Matrix MatrixRotateX(float angle)
|
||||||
{
|
{
|
||||||
Matrix result = MatrixIdentity();
|
Matrix result = MatrixIdentity();
|
||||||
|
|
||||||
float cosres = (float)cos(angle);
|
float cosres = cosf(angle);
|
||||||
float sinres = (float)sin(angle);
|
float sinres = sinf(angle);
|
||||||
|
|
||||||
result.m5 = cosres;
|
result.m5 = cosres;
|
||||||
result.m6 = -sinres;
|
result.m6 = -sinres;
|
||||||
|
@ -720,8 +720,8 @@ RMDEF Matrix MatrixRotateZ(float angle)
|
||||||
{
|
{
|
||||||
Matrix result = MatrixIdentity();
|
Matrix result = MatrixIdentity();
|
||||||
|
|
||||||
float cosres = (float)cos(angle);
|
float cosres = cosf(angle);
|
||||||
float sinres = (float)sin(angle);
|
float sinres = sinf(angle);
|
||||||
|
|
||||||
result.m0 = cosres;
|
result.m0 = cosres;
|
||||||
result.m1 = -sinres;
|
result.m1 = -sinres;
|
||||||
|
@ -946,8 +946,8 @@ RMDEF Quaternion QuaternionSlerp(Quaternion q1, Quaternion q2, float amount)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
float ratioA = sin((1 - amount)*halfTheta)/sinHalfTheta;
|
float ratioA = sinf((1 - amount)*halfTheta)/sinHalfTheta;
|
||||||
float ratioB = sin(amount*halfTheta)/sinHalfTheta;
|
float ratioB = sinf(amount*halfTheta)/sinHalfTheta;
|
||||||
|
|
||||||
result.x = (q1.x*ratioA + q2.x*ratioB);
|
result.x = (q1.x*ratioA + q2.x*ratioB);
|
||||||
result.y = (q1.y*ratioA + q2.y*ratioB);
|
result.y = (q1.y*ratioA + q2.y*ratioB);
|
||||||
|
@ -1060,7 +1060,7 @@ RMDEF Matrix QuaternionToMatrix(Quaternion q)
|
||||||
|
|
||||||
// Returns rotation quaternion for an angle and axis
|
// Returns rotation quaternion for an angle and axis
|
||||||
// NOTE: angle must be provided in radians
|
// NOTE: angle must be provided in radians
|
||||||
RMDEF Quaternion QuaternionFromAxisAngle(float angle, Vector3 axis)
|
RMDEF Quaternion QuaternionFromAxisAngle(Vector3 axis, float angle)
|
||||||
{
|
{
|
||||||
Quaternion result = { 0.0f, 0.0f, 0.0f, 1.0f };
|
Quaternion result = { 0.0f, 0.0f, 0.0f, 1.0f };
|
||||||
|
|
||||||
|
@ -1070,10 +1070,13 @@ RMDEF Quaternion QuaternionFromAxisAngle(float angle, Vector3 axis)
|
||||||
|
|
||||||
VectorNormalize(&axis);
|
VectorNormalize(&axis);
|
||||||
|
|
||||||
result.x = axis.x*(float)sin(angle);
|
float sinres = sinf(angle);
|
||||||
result.y = axis.y*(float)sin(angle);
|
float cosres = cosf(angle);
|
||||||
result.z = axis.z*(float)sin(angle);
|
|
||||||
result.w = (float)cos(angle);
|
result.x = axis.x*sinres;
|
||||||
|
result.y = axis.y*sinres;
|
||||||
|
result.z = axis.z*sinres;
|
||||||
|
result.w = cosres;
|
||||||
|
|
||||||
QuaternionNormalize(&result);
|
QuaternionNormalize(&result);
|
||||||
|
|
||||||
|
@ -1081,7 +1084,7 @@ RMDEF Quaternion QuaternionFromAxisAngle(float angle, Vector3 axis)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns the rotation angle and axis for a given quaternion
|
// Returns the rotation angle and axis for a given quaternion
|
||||||
RMDEF void QuaternionToAxisAngle(Quaternion q, float *outAngle, Vector3 *outAxis)
|
RMDEF void QuaternionToAxisAngle(Quaternion q, Vector3 *outAxis, float *outAngle)
|
||||||
{
|
{
|
||||||
if (fabs(q.w) > 1.0f) QuaternionNormalize(&q);
|
if (fabs(q.w) > 1.0f) QuaternionNormalize(&q);
|
||||||
|
|
||||||
|
|
|
@ -411,7 +411,7 @@ void rlRotatef(float angleDeg, float x, float y, float z)
|
||||||
|
|
||||||
Vector3 axis = (Vector3){ x, y, z };
|
Vector3 axis = (Vector3){ x, y, z };
|
||||||
VectorNormalize(&axis);
|
VectorNormalize(&axis);
|
||||||
matRotation = MatrixRotate(angleDeg*DEG2RAD, axis);
|
matRotation = MatrixRotate(axis, angleDeg*DEG2RAD);
|
||||||
|
|
||||||
MatrixTranspose(&matRotation);
|
MatrixTranspose(&matRotation);
|
||||||
|
|
||||||
|
@ -1406,13 +1406,13 @@ void rlglDrawPostpro(void)
|
||||||
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
|
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
|
||||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||||
|
|
||||||
rlglDrawModel(postproQuad, (Vector3){0,0,0}, 0.0f, (Vector3){0,0,0}, (Vector3){1.0f, 1.0f, 1.0f}, (Color){ 255, 255, 255, 255 }, false);
|
rlglDrawModel(postproQuad, (Vector3){0,0,0}, (Vector3){0,0,0}, 0.0f, (Vector3){1.0f, 1.0f, 1.0f}, (Color){ 255, 255, 255, 255 }, false);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
// Draw a 3d model
|
// Draw a 3d model
|
||||||
// NOTE: Model transform can come within model struct
|
// NOTE: Model transform can come within model struct
|
||||||
void rlglDrawModel(Model model, Vector3 position, float rotationAngle, Vector3 rotationAxis, Vector3 scale, Color color, bool wires)
|
void rlglDrawModel(Model model, Vector3 position, Vector3 rotationAxis, float rotationAngle, Vector3 scale, Color color, bool wires)
|
||||||
{
|
{
|
||||||
#if defined (GRAPHICS_API_OPENGL_11) || defined(GRAPHICS_API_OPENGL_33)
|
#if defined (GRAPHICS_API_OPENGL_11) || defined(GRAPHICS_API_OPENGL_33)
|
||||||
// NOTE: glPolygonMode() not available on OpenGL ES
|
// NOTE: glPolygonMode() not available on OpenGL ES
|
||||||
|
@ -1461,7 +1461,7 @@ void rlglDrawModel(Model model, Vector3 position, float rotationAngle, Vector3 r
|
||||||
|
|
||||||
// Calculate transformation matrix from function parameters
|
// Calculate transformation matrix from function parameters
|
||||||
// Get transform matrix (rotation -> scale -> translation)
|
// Get transform matrix (rotation -> scale -> translation)
|
||||||
Matrix matRotation = MatrixRotate(rotationAngle*DEG2RAD, rotationAxis);
|
Matrix matRotation = MatrixRotate(rotationAxis, rotationAngle*DEG2RAD);
|
||||||
Matrix matScale = MatrixScale(scale.x, scale.y, scale.z);
|
Matrix matScale = MatrixScale(scale.x, scale.y, scale.z);
|
||||||
Matrix matTranslation = MatrixTranslate(position.x, position.y, position.z);
|
Matrix matTranslation = MatrixTranslate(position.x, position.y, position.z);
|
||||||
Matrix matTransform = MatrixMultiply(MatrixMultiply(matRotation, matScale), matTranslation);
|
Matrix matTransform = MatrixMultiply(MatrixMultiply(matRotation, matScale), matTranslation);
|
||||||
|
|
|
@ -262,7 +262,7 @@ void rlglInitPostpro(void); // Initialize postprocessing sys
|
||||||
void rlglDrawPostpro(void); // Draw with postprocessing shader
|
void rlglDrawPostpro(void); // Draw with postprocessing shader
|
||||||
|
|
||||||
Model rlglLoadModel(Mesh mesh); // Upload vertex data into GPU and provided VAO/VBO ids
|
Model rlglLoadModel(Mesh mesh); // Upload vertex data into GPU and provided VAO/VBO ids
|
||||||
void rlglDrawModel(Model model, Vector3 position, float rotationAngle, Vector3 rotationAxis, Vector3 scale, Color color, bool wires);
|
void rlglDrawModel(Model model, Vector3 position, Vector3 rotationAxis, float rotationAngle, Vector3 scale, Color color, bool wires);
|
||||||
|
|
||||||
Vector3 rlglUnproject(Vector3 source, Matrix proj, Matrix view); // Get world coordinates from screen coordinates
|
Vector3 rlglUnproject(Vector3 source, Matrix proj, Matrix view); // Get world coordinates from screen coordinates
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue