|
Tiny3D
|
#include <libdragon.h>

Go to the source code of this file.
Data Structures | |
| struct | T3DVec4FP |
| struct | __attribute__ |
| struct | T3DFrustum |
Macros | |
| #define | T3D_DEG_TO_RAD(deg) |
| #define | T3D_F32_TO_FIXED(val) |
| #define | T3D_PI 3.14159265358979f |
Typedefs | |
| typedef fm_vec3_t | T3DVec3 |
| typedef fm_vec4_t | T3DVec4 |
| typedef fm_quat_t | T3DQuat |
| typedef fm_mat4_t | T3DMat4 |
Functions | |
| static float | s1616_to_float (int16_t partI, uint16_t partF) |
| Converts a 16.16 fixed-point number to a float. | |
| static float | t3d_lerp (float a, float b, float t) |
| Interpolates between two floats by 't'. | |
| static float | t3d_lerp_angle (float a, float b, float t) |
| Interpolates between two angles (radians) by 't'. | |
| static void | t3d_vec3_add (T3DVec3 *res, const T3DVec3 *a, const T3DVec3 *b) |
| Sets 'res' to 'a + b'. | |
| static void | t3d_vec3_mul (T3DVec3 *res, const T3DVec3 *a, const T3DVec3 *b) |
| Sets 'res' to 'a + b'. | |
| static void | t3d_vec3_scale (T3DVec3 *res, const T3DVec3 *a, float s) |
| Sets 'res' to 'a * s'. | |
| static void | t3d_vec3_diff (T3DVec3 *res, const T3DVec3 *a, const T3DVec3 *b) |
| Set 'res' to 'a - b'. | |
| static float | t3d_vec3_len2 (const T3DVec3 *vec) |
| Returns the squared length of 'v'. | |
| static float | t3d_vec3_len (const T3DVec3 *vec) |
| Returns the length of 'v'. | |
| static float | t3d_vec3_distance2 (const T3DVec3 *vecA, const T3DVec3 *vecB) |
| Returns the squared distance between 'vecA' and 'vecB'. | |
| static float | t3d_vec3_distance (const T3DVec3 *vecA, const T3DVec3 *vecB) |
| Returns the distance between 'vecA' and 'vecB'. | |
| static void | t3d_vec3_norm (T3DVec3 *res) |
| Normalizes 'res', this does NOT check for a zero-length vector. | |
| static void | t3d_vec3_cross (T3DVec3 *res, const T3DVec3 *a, const T3DVec3 *b) |
| Crosses 'a' with 'b' and stores it in 'res'. | |
| static float | t3d_vec3_dot (const T3DVec3 *a, const T3DVec3 *b) |
| Returns the dot product of 'a' and 'b'. | |
| static void | t3d_vec3_lerp (T3DVec3 *res, const T3DVec3 *a, const T3DVec3 *b, float t) |
| Linearly interpolates between 'a' and 'b' by 't' and stores it in 'res'. | |
| static void | t3d_quat_identity (T3DQuat *quat) |
| static void | t3d_quat_from_euler (T3DQuat *quat, const float rotEuler[3]) |
| static void | t3d_quat_from_rotation (T3DQuat *quat, float axis[3], float angleRad) |
| static void | t3d_quat_mul (T3DQuat *res, T3DQuat *a, T3DQuat *b) |
| static void | t3d_quat_rotate_euler (T3DQuat *quat, float axis[3], float angleRad) |
| static float | t3d_quat_dot (const T3DQuat *a, const T3DQuat *b) |
| static void | t3d_quat_normalize (T3DQuat *quat) |
| void | t3d_quat_nlerp (T3DQuat *res, const T3DQuat *a, const T3DQuat *b, float t) |
| void | t3d_quat_slerp (T3DQuat *res, const T3DQuat *a, const T3DQuat *b, float t) |
| static void | t3d_mat4_identity (T3DMat4 *mat) |
| Initializes a matrix to the identity matrix. | |
| static void | t3d_mat4_scale (T3DMat4 *mat, float scaleX, float scaleY, float scaleZ) |
| static void | t3d_mat4_translate (T3DMat4 *mat, float offsetX, float offsetY, float offsetZ) |
| void | t3d_mat4_rotate (T3DMat4 *mat, const T3DVec3 *axis, float angleRad) |
| void | t3d_mat4_from_srt (T3DMat4 *mat, const float scale[3], const float quat[4], const float translate[3]) |
| void | t3d_mat4_from_srt_euler (T3DMat4 *mat, const float scale[3], const float rot[3], const float translate[3]) |
| void | t3d_mat4_rot_from_dir (T3DMat4 *mat, const T3DVec3 *dir, const T3DVec3 *up) |
| void | t3d_mat4fp_from_srt_euler (T3DMat4FP *mat, const float scale[3], const float rot[3], const float translate[3]) |
| void | t3d_mat4fp_from_srt (T3DMat4FP *mat, const float scale[3], const float rotQuat[4], const float translate[3]) |
| static void | t3d_mat4fp_set_float (T3DMat4FP *mat, uint32_t column, uint32_t row, float val) |
| Sets a value in a fixed-point matrix. | |
| static void | t3d_mat4fp_set_pos (T3DMat4FP *mat, const float pos[3]) |
| static float | t3d_mat4fp_get_float (const T3DMat4FP *mat, uint32_t y, uint32_t x) |
| Gets a value from a fixed-point matrix. | |
| static void | t3d_mat4fp_identity (T3DMat4FP *mat) |
| void | t3d_mat4_to_fixed (T3DMat4FP *matOut, const T3DMat4 *matIn) |
| void | t3d_mat4_to_fixed_3x4 (T3DMat4FP *matOut, const T3DMat4 *matIn) |
| void | t3d_mat4_perspective (T3DMat4 *mat, float fov, float aspect, float near, float far) |
| void | t3d_mat4_ortho (T3DMat4 *mat, float left, float right, float bottom, float top, float near, float far) |
| void | t3d_mat4_look_at (T3DMat4 *mat, const T3DVec3 *eye, const T3DVec3 *target, const T3DVec3 *up) |
| Creates a look-at matrix from an eye and target vector. | |
| void | t3d_mat4_to_frustum (T3DFrustum *frustum, const T3DMat4 *mat) |
| void | t3d_frustum_scale (T3DFrustum *frustum, float scale) |
| bool | t3d_frustum_vs_aabb (const T3DFrustum *frustum, const T3DVec3 *min, const T3DVec3 *max) |
| bool | t3d_frustum_vs_aabb_s16 (const T3DFrustum *frustum, const int16_t min[3], const int16_t max[3]) |
| bool | t3d_frustum_vs_sphere (const T3DFrustum *frustum, const T3DVec3 *center, const float radius) |
| static void | t3d_mat4_mul (T3DMat4 *matRes, const T3DMat4 *matA, const T3DMat4 *matB) |
| Multiplies the matrices 'matA' and 'matB' and stores it in 'matRes'. | |
| static void | t3d_mat3_mul_vec3 (T3DVec3 *vecOut, const T3DMat4 *mat, const T3DVec3 *vec) |
| static void | t3d_mat4_mul_vec3 (T3DVec4 *vecOut, const T3DMat4 *mat, const T3DVec3 *vec) |
| #define T3D_DEG_TO_RAD | ( | deg | ) |
| #define T3D_F32_TO_FIXED | ( | val | ) |
| void t3d_frustum_scale | ( | T3DFrustum * | frustum, |
| float | scale ) |
Scales a frustum by a given factor. This can be used if you need to check scaled objects without having to transform the AABBs
| frustum | frustum to scale |
| scale | scale factor (use the same as the model scale) |
| bool t3d_frustum_vs_aabb | ( | const T3DFrustum * | frustum, |
| const T3DVec3 * | min, | ||
| const T3DVec3 * | max ) |
Checks if an AABB is inside a frustum. Note that this function may choose to return false positives in favor of speed. So it should only be used where this is acceptable (e.g. culling) and not for collision detection.
| frustum | frustum |
| min | AABB min |
| max | AABB max |
| bool t3d_frustum_vs_aabb_s16 | ( | const T3DFrustum * | frustum, |
| const int16_t | min[3], | ||
| const int16_t | max[3] ) |
Checks if an s16 AABB is inside a frustum. Note that this function may choose to return false positives in favor of speed. So it should only be used where this is acceptable (e.g. culling) and not for collision detection.
| frustum | frustum |
| min | AABB min |
| max | AABB max |
| bool t3d_frustum_vs_sphere | ( | const T3DFrustum * | frustum, |
| const T3DVec3 * | center, | ||
| const float | radius ) |
Checks if a Sphere is inside a frustum. Note that this function may choose to return false positives in favor of speed. So it should only be used where this is acceptable (e.g. culling) and not for collision detection.
| frustum | frustum |
| center | Sphere center |
| radius | Sphere radius |
|
inlinestatic |
Multiplies a 3x3 matrix with a 3D vector
| vecOut | result |
| mat | matrix |
| vec | input-vector |
| void t3d_mat4_from_srt | ( | T3DMat4 * | mat, |
| const float | scale[3], | ||
| const float | quat[4], | ||
| const float | translate[3] ) |
Directly constructs a matrix from scale, rotation (quaternion) and translation For a euler version, see 't3d_mat4_from_srt_euler'.
| mat | result |
| scale | scale factors |
| rot | rotation quaternion |
| translate | offsets |
| void t3d_mat4_from_srt_euler | ( | T3DMat4 * | mat, |
| const float | scale[3], | ||
| const float | rot[3], | ||
| const float | translate[3] ) |
Directly constructs a matrix from scale, rotation (euler) and translation For a quaternion version, see 't3d_mat4_from_srt'.
| mat | |
| scale | |
| rot | |
| translate |
|
inlinestatic |
Initializes a matrix to the identity matrix.
| mat | matrix to be changed |
| void t3d_mat4_look_at | ( | T3DMat4 * | mat, |
| const T3DVec3 * | eye, | ||
| const T3DVec3 * | target, | ||
| const T3DVec3 * | up ) |
Creates a look-at matrix from an eye and target vector.
| mat | destination matrix |
| eye | camera position |
| target | camera target/focus point |
| up | camera up vector, expected to be {0,1,0} by default |
|
inlinestatic |
Multiplies a 4x4 matrix with a 3D vector. The W component of the vector is assumed to be 1.
| vecOut | result |
| mat | matrix |
| vec | input-vector |
| void t3d_mat4_ortho | ( | T3DMat4 * | mat, |
| float | left, | ||
| float | right, | ||
| float | bottom, | ||
| float | top, | ||
| float | near, | ||
| float | far ) |
Constructs an orthographic projection matrix
| mat | result |
| left | |
| right | |
| bottom | |
| top | |
| near | near plane distance |
| far | far plane distance |
| void t3d_mat4_perspective | ( | T3DMat4 * | mat, |
| float | fov, | ||
| float | aspect, | ||
| float | near, | ||
| float | far ) |
Constructs a perspective projection matrix
| mat | result |
| fov | fov in radians |
| aspect | aspect ratio |
| near | near plane distance |
| far | far plane distance |
| void t3d_mat4_rot_from_dir | ( | T3DMat4 * | mat, |
| const T3DVec3 * | dir, | ||
| const T3DVec3 * | up ) |
Constructs a matrix from a direction and up vector. This will only create a rotation matrix, the translation part will be identity.
| mat | result |
| dir | direction vector |
| up | up vector |
| void t3d_mat4_rotate | ( | T3DMat4 * | mat, |
| const T3DVec3 * | axis, | ||
| float | angleRad ) |
Rotates a matrix around an axis
| mat | result |
| axis | axis to rotate around |
| angleRad | angle in radians |
|
inlinestatic |
Scales a matrix by the given factors
| mat | result |
| scaleX | |
| scaleY | |
| scaleZ |
| void t3d_mat4_to_fixed | ( | T3DMat4FP * | matOut, |
| const T3DMat4 * | matIn ) |
Converts a float matrix to a fixed-point matrix.
| matOut | result |
| matIn | input |
| void t3d_mat4_to_fixed_3x4 | ( | T3DMat4FP * | matOut, |
| const T3DMat4 * | matIn ) |
Converts a float 4x4 matrix to a fixed-point 4x4 matrix. The last row of the matrix is assumed to be {0,0,0,1}. This should be preferred over 't3d_mat4_to_fixed' when possible as it is faster.
| matOut | result |
| matIn | input |
| void t3d_mat4_to_frustum | ( | T3DFrustum * | frustum, |
| const T3DMat4 * | mat ) |
Extracts the frustum planes from a 4x4 view/camera matrix
| frustum | result |
| mat | view/camera matrix |
|
inlinestatic |
Translates a matrix by the given offsets
| mat | result |
| offsetX | |
| offsetY | |
| offsetZ |
| void t3d_mat4fp_from_srt | ( | T3DMat4FP * | mat, |
| const float | scale[3], | ||
| const float | rotQuat[4], | ||
| const float | translate[3] ) |
Directly constructs a matrix from scale, rotation (quaternion) and translation Same as 't3d_mat4_from_srt', but instead directly writes to a fixed-point matrix.
| mat | |
| scale | |
| rot | |
| translate |
| void t3d_mat4fp_from_srt_euler | ( | T3DMat4FP * | mat, |
| const float | scale[3], | ||
| const float | rot[3], | ||
| const float | translate[3] ) |
Directly constructs a matrix from scale, rotation (euler) and translation Same as 't3d_mat4_from_srt_euler', but instead directly writes to a fixed-point matrix.
| mat | |
| scale | |
| rot | |
| translate |
|
inlinestatic |
Gets a value from a fixed-point matrix.
| mat | matrix to be read |
| y | row |
| x | column |
|
inlinestatic |
Sets a value in a fixed-point matrix.
| mat | matrix to be changed |
| column | |
| row | |
| val | value to be set as a float |
|
inlinestatic |
Sets the position of a fixed-point matrix. Note: that this will just set the values without any further checks/calculations.
| mat | matrix to be changed |
| pos | position as a float[3] |
|
inlinestatic |
Dot product of a quaternion as a vec4
| a | quaternion |
| b | quaternion |
|
inlinestatic |
Creates a quaternion from euler angles (radians)
| quat | result (in XYZW order) |
| rotEuler |
|
inlinestatic |
Creates a quaternion from a rotation (radians) around an axis
| quat | result |
| axis | rotation axis |
| angleRad | angle in radians |
|
inlinestatic |
Multiplies two quaternions and stores the result in 'res'. NOTE: if 'a' or 'b' point to the same quat. as 'res', the result will be incorrect.
| res | result |
| a | first quaternion |
| b | second quaternion |
| void t3d_quat_nlerp | ( | T3DQuat * | res, |
| const T3DQuat * | a, | ||
| const T3DQuat * | b, | ||
| float | t ) |
Interpolates between two quaternions using a normalized linear interpolation.
| res | interpolated quaternion |
| a | first quaternion |
| b | second quaternion |
| t | interpolation factor |
|
inlinestatic |
Normalizes a quaternion
| quat |
|
inlinestatic |
Rotates a quaternion around an axis
| quat | quat to modify |
| axis | rotation axis |
| angleRad | angle in radians |