Created
May 28, 2020 17:50
-
-
Save profan/7a8c3306fbd8765c192de3225c6fe81c to your computer and use it in GitHub Desktop.
raylib-d raymath ffi
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module raymath; | |
import raylib; | |
extern (C) @nogc nothrow: | |
//---------------------------------------------------------------------------------- | |
// Module Functions Definition - Vector2 math | |
//---------------------------------------------------------------------------------- | |
// Vector with components value 0.0f | |
Vector2 Vector2Zero(); | |
// Vector with components value 1.0f | |
Vector2 Vector2One(); | |
// Add two vectors (v1 + v2) | |
Vector2 Vector2Add(Vector2 v1, Vector2 v2); | |
// Add vector and float value | |
Vector2 Vector2AddValue(Vector2 v, float add); | |
// Subtract two vectors (v1 - v2) | |
Vector2 Vector2Subtract(Vector2 v1, Vector2 v2); | |
// Subtract vector by float value | |
Vector2 Vector2SubtractValue(Vector2 v, float sub); | |
// Calculate vector length | |
float Vector2Length(Vector2 v); | |
// Calculate vector square length | |
float Vector2LengthSqr(Vector2 v); | |
// Calculate two vectors dot product | |
float Vector2DotProduct(Vector2 v1, Vector2 v2); | |
// Calculate distance between two vectors | |
float Vector2Distance(Vector2 v1, Vector2 v2); | |
// Calculate angle from two vectors in X-axis | |
float Vector2Angle(Vector2 v1, Vector2 v2); | |
// Scale vector (multiply by value) | |
Vector2 Vector2Scale(Vector2 v, float scale); | |
// Multiply vector by vector | |
Vector2 Vector2Multiply(Vector2 v1, Vector2 v2); | |
// Negate vector | |
Vector2 Vector2Negate(Vector2 v); | |
// Divide vector by vector | |
Vector2 Vector2Divide(Vector2 v1, Vector2 v2); | |
// Normalize provided vector | |
Vector2 Vector2Normalize(Vector2 v); | |
// Calculate linear interpolation between two vectors | |
Vector2 Vector2Lerp(Vector2 v1, Vector2 v2, float amount); | |
// Rotate Vector by float in Degrees. | |
Vector2 Vector2Rotate(Vector2 v, float degs); | |
// Move Vector towards target | |
Vector2 Vector2MoveTowards(Vector2 v, Vector2 target, float maxDistance); | |
//---------------------------------------------------------------------------------- | |
// Module Functions Definition - Vector3 math | |
//---------------------------------------------------------------------------------- | |
// Vector with components value 0.0f | |
Vector3 Vector3Zero(); | |
// Vector with components value 1.0f | |
Vector3 Vector3One(); | |
// Add two vectors | |
Vector3 Vector3Add(Vector3 v1, Vector3 v2); | |
// Add vector and float value | |
Vector3 Vector3AddValue(Vector3 v, float add); | |
// Subtract two vectors | |
Vector3 Vector3Subtract(Vector3 v1, Vector3 v2); | |
// Subtract vector by float value | |
Vector3 Vector3SubtractValue(Vector3 v, float sub); | |
// Multiply vector by scalar | |
Vector3 Vector3Scale(Vector3 v, float scalar); | |
// Multiply vector by vector | |
Vector3 Vector3Multiply(Vector3 v1, Vector3 v2); | |
// Calculate two vectors cross product | |
Vector3 Vector3CrossProduct(Vector3 v1, Vector3 v2); | |
// Calculate one vector perpendicular vector | |
Vector3 Vector3Perpendicular(Vector3 v); | |
// Calculate vector length | |
float Vector3Length(const Vector3 v); | |
// Calculate vector square length | |
float Vector3LengthSqr(const Vector3 v); | |
// Calculate two vectors dot product | |
float Vector3DotProduct(Vector3 v1, Vector3 v2); | |
// Calculate distance between two vectors | |
float Vector3Distance(Vector3 v1, Vector3 v2); | |
// Negate provided vector (invert direction) | |
Vector3 Vector3Negate(Vector3 v); | |
// Divide vector by vector | |
Vector3 Vector3Divide(Vector3 v1, Vector3 v2); | |
// Normalize provided vector | |
Vector3 Vector3Normalize(Vector3 v); | |
// Orthonormalize provided vectors | |
// Makes vectors normalized and orthogonal to each other | |
// Gram-Schmidt function implementation | |
void Vector3OrthoNormalize(Vector3 *v1, Vector3 *v2); | |
// Transforms a Vector3 by a given Matrix | |
Vector3 Vector3Transform(Vector3 v, Matrix mat); | |
// Transform a vector by quaternion rotation | |
Vector3 Vector3RotateByQuaternion(Vector3 v, Quaternion q); | |
// Calculate linear interpolation between two vectors | |
Vector3 Vector3Lerp(Vector3 v1, Vector3 v2, float amount); | |
// Calculate reflected vector to normal | |
Vector3 Vector3Reflect(Vector3 v, Vector3 normal); | |
// Return min value for each pair of components | |
Vector3 Vector3Min(Vector3 v1, Vector3 v2); | |
// Return max value for each pair of components | |
Vector3 Vector3Max(Vector3 v1, Vector3 v2); | |
// Compute barycenter coordinates (u, v, w) for point p with respect to triangle (a, b, c) | |
// NOTE: Assumes P is on the plane of the triangle | |
Vector3 Vector3Barycenter(Vector3 p, Vector3 a, Vector3 b, Vector3 c); | |
// Returns Vector3 as float array | |
float[3] Vector3ToFloatV(Vector3 v); | |
//---------------------------------------------------------------------------------- | |
// Module Functions Definition - Matrix math | |
//---------------------------------------------------------------------------------- | |
// Compute matrix determinant | |
float MatrixDeterminant(Matrix mat); | |
// Returns the trace of the matrix (sum of the values along the diagonal) | |
float MatrixTrace(Matrix mat); | |
// Transposes provided matrix | |
Matrix MatrixTranspose(Matrix mat); | |
// Invert provided matrix | |
Matrix MatrixInvert(Matrix mat); | |
// Normalize provided matrix | |
Matrix MatrixNormalize(Matrix mat); | |
// Returns identity matrix | |
Matrix MatrixIdentity(); | |
// Add two matrices | |
Matrix MatrixAdd(Matrix left, Matrix right); | |
// Subtract two matrices (left - right) | |
Matrix MatrixSubtract(Matrix left, Matrix right); | |
// Returns translation matrix | |
Matrix MatrixTranslate(float x, float y, float z); | |
// Create rotation matrix from axis and angle | |
// NOTE: Angle should be provided in radians | |
Matrix MatrixRotate(Vector3 axis, float angle); | |
// Returns xyz-rotation matrix (angles in radians) | |
Matrix MatrixRotateXYZ(Vector3 ang); | |
// Returns x-rotation matrix (angle in radians) | |
Matrix MatrixRotateX(float angle); | |
// Returns y-rotation matrix (angle in radians) | |
Matrix MatrixRotateY(float angle); | |
// Returns z-rotation matrix (angle in radians) | |
Matrix MatrixRotateZ(float angle); | |
// Returns scaling matrix | |
Matrix MatrixScale(float x, float y, float z); | |
// Returns two matrix multiplication | |
// NOTE: When multiplying matrices... the order matters! | |
Matrix MatrixMultiply(Matrix left, Matrix right); | |
// Returns perspective projection matrix | |
Matrix MatrixFrustum(double left, double right, double bottom, double top, double near, double far); | |
// Returns perspective projection matrix | |
// NOTE: Angle should be provided in radians | |
Matrix MatrixPerspective(double fovy, double aspect, double near, double far); | |
// Returns orthographic projection matrix | |
Matrix MatrixOrtho(double left, double right, double bottom, double top, double near, double far); | |
// Returns camera look-at matrix (view matrix) | |
Matrix MatrixLookAt(Vector3 eye, Vector3 target, Vector3 up); | |
// Returns float array of matrix data | |
float[16] MatrixToFloatV(Matrix mat); | |
//---------------------------------------------------------------------------------- | |
// Module Functions Definition - Quaternion math | |
//---------------------------------------------------------------------------------- | |
// Add two quaternions | |
Quaternion QuaternionAdd(Quaternion q1, Quaternion q2); | |
// Add quaternion and float value | |
Quaternion QuaternionAddValue(Quaternion q, float add); | |
// Subtract two quaternions | |
Quaternion QuaternionSubtract(Quaternion q1, Quaternion q2); | |
// Subtract quaternion and float value | |
Quaternion QuaternionSubtractValue(Quaternion q, float sub); | |
// Returns identity quaternion | |
Quaternion QuaternionIdentity(); | |
// Computes the length of a quaternion | |
float QuaternionLength(Quaternion q); | |
// Normalize provided quaternion | |
Quaternion QuaternionNormalize(Quaternion q); | |
// Invert provided quaternion | |
Quaternion QuaternionInvert(Quaternion q); | |
// Calculate two quaternion multiplication | |
Quaternion QuaternionMultiply(Quaternion q1, Quaternion q2); | |
// Scale quaternion by float value | |
Quaternion QuaternionScale(Quaternion q, float mul); | |
// Divide two quaternions | |
Quaternion QuaternionDivide(Quaternion q1, Quaternion q2); | |
// Calculate linear interpolation between two quaternions | |
Quaternion QuaternionLerp(Quaternion q1, Quaternion q2, float amount); | |
// Calculate slerp-optimized interpolation between two quaternions | |
Quaternion QuaternionNlerp(Quaternion q1, Quaternion q2, float amount); | |
// Calculates spherical linear interpolation between two quaternions | |
Quaternion QuaternionSlerp(Quaternion q1, Quaternion q2, float amount); | |
// Calculate quaternion based on the rotation from one vector to another | |
Quaternion QuaternionFromVector3ToVector3(Vector3 from, Vector3 to); | |
// Returns a quaternion for a given rotation matrix | |
Quaternion QuaternionFromMatrix(Matrix mat); | |
// Returns a matrix for a given quaternion | |
Matrix QuaternionToMatrix(Quaternion q); | |
// Returns rotation quaternion for an angle and axis | |
// NOTE: angle must be provided in radians | |
Quaternion QuaternionFromAxisAngle(Vector3 axis, float angle); | |
// Returns the rotation angle and axis for a given quaternion | |
void QuaternionToAxisAngle(Quaternion q, Vector3 *outAxis, float *outAngle); | |
// Returns he quaternion equivalent to Euler angles | |
Quaternion QuaternionFromEuler(float roll, float pitch, float yaw); | |
// Return the Euler angles equivalent to quaternion (roll, pitch, yaw) | |
// NOTE: Angles are returned in a Vector3 struct in degrees | |
Vector3 QuaternionToEuler(Quaternion q); | |
// Transform a quaternion given a transformation matrix | |
Quaternion QuaternionTransform(Quaternion q, Matrix mat); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment