Changeset 31326 in project


Ignore:
Timestamp:
09/02/14 20:03:04 (5 years ago)
Author:
acharlton
Message:

wiki/gl-math: Update to 0.5.0

File:
1 edited

Legend:

Unmodified
Added
Removed
  • wiki/eggref/4/gl-math

    r31310 r31326  
    1 
    21== gl-math
    32[[toc:]]
    4 A very small math library for gamedev that mostly provides 4x4 float matrix operations. Uses the [[https://github.com/AlexCharlton/hypermath|hypermath]] library.
     3A small math library aimed at gamedev that provides 4x4 float matrix, vector, and quaternion operations. Uses the [[https://github.com/AlexCharlton/hypermath|hypermath]] library.
    54
    65
     
    1817Additionally, gl-math is one fifth the compiled size of glm, has a more straight-forward code-base, and complete documentation.
    1918
    20 gl-math expects matrices to be f32vectors or pointers. f32vectors must be 16 elements long. The memory pointed to should likewise be an array of 16 floats. If a function accepts more than one matrix, all matrices must be of the same type.
    21 
    22 gl-math operates on matrices in a column-major fashion in correspondence with OpenGL (e.g. translation components are at indices 12, 13, and 14).
     19gl-math expects matrices, vectors, and quaternions to be f32vectors or pointers. f32vectors must be 16 elements long, 3 elements long, or 4 elements long for matrices, vectors, or quaternions, respectively. The memory pointed to should likewise be an array of 16, 3, or 4 floats . If a function accepts more than one matrix, vector, or quaternion, all must be of the same type.
     20
     21gl-math operates on matrices in a column-major fashion in correspondence with OpenGL (e.g. translation components are at indices 12, 13, and 14). Vectors are arranged as ({{(x y z)}}), and quaternions as ({{(x y z w)}}).
    2322
    2423
     
    3029<procedure> (copy-mat4 MATRIX [RESULT])</procedure>
    3130
    32 Make a copy of {{MATRIX}}. If the matrix {{RESULT}} is given, it will be modified to contain the contents of {{MATRIX}}. If {{RESULT}} is {{#t}}, {{MATRIX}} must be an f32vector and the returned value will be an f32vector located in non-garbage collected memory (the memory will still be freed when there are no more references to the matrix). If {{RESULT}} is not provided, {{MATRIX}} must be an f32vector and the returned value will be an f32vector located in normal garbage collected memory.
     31Make a copy of {{MATRIX}}. If the matrix {{RESULT}} is given, it will be modified to contain the contents of {{MATRIX}}. If {{RESULT}} is {{#t}}, {{MATRIX}} must be an f32vector and the returned value will be an f32vector located in non-garbage-collected memory (the memory will still be freed when there are no more references to the matrix). If {{RESULT}} is not provided, {{MATRIX}} must be an f32vector and the returned value will be an f32vector located in normal garbage collected memory.
    3332
    3433<procedure> (m* A B [RESULT])</procedure>
    3534
    36 Multiply matrix {{A}} by matrix {{B}}. If the matrix {{RESULT}} is given, it will be modified to contain the results of the multiplication. If {{RESULT}} is {{#t}}, {{A}} and {{B}} must be f32vectors and the returned value will be an f32vector located in non-garbage collected memory (the memory will still be freed when there are no more references to the matrix). If {{RESULT}} is not provided, {{A}} and {{B}} must be f32vectors and the returned value will be an f32vector located in normal garbage collected memory.
     35Multiply matrix {{A}} by matrix {{B}}. If the matrix {{RESULT}} is given, it will be modified to contain the results of the multiplication. If {{RESULT}} is {{#t}}, {{A}} and {{B}} must be f32vectors and the returned value will be an f32vector located in non-garbage-collected memory (the memory will still be freed when there are no more references to the matrix). If {{RESULT}} is not provided, {{A}} and {{B}} must be f32vectors and the returned value will be an f32vector located in normal garbage collected memory.
    3736
    3837<procedure> (mat4-identity [RESULT])</procedure>
    3938
    40 Return an identity matrix. If {{RESULT}} is {{#t}}, the returned value will be an f32vector located in non-garbage collected memory (the memory will still be freed when there are no more references to the matrix). If {{RESULT}} is not provided, the returned value will be an f32vector located in normal garbage collected memory.
    41 
    42 <procedure> (translation X Y Z [RESULT])</procedure>
    43 
    44 Return the translation matrix given by {{X}}, {{Y}}, and {{Z}}. If {{RESULT}} is {{#t}}, the returned value will be an f32vector located in non-garbage collected memory (the memory will still be freed when there are no more references to the matrix). If {{RESULT}} is not provided, the returned value will be an f32vector located in normal garbage collected memory.
    45 
    46 <procedure> (translate X Y Z MATRIX)</procedure>
    47 
    48 Translate {{MATRIX}} by {{X}}, {{Y}}, and {{Z}}.
    49 
    50     void hpmXRotation(float rotation, float *mat);
    51 
    52 Create the rotation matrix of {{rotation}} radians around the X-axis in the given matrix.
     39Return an identity matrix. If {{RESULT}} is {{#t}}, the returned value will be an f32vector located in non-garbage-collected memory (the memory will still be freed when there are no more references to the matrix). If {{RESULT}} is not provided, the returned value will be an f32vector located in normal garbage collected memory.
     40
     41<procedure> (translation VECTOR [RESULT])</procedure>
     42
     43Return the translation matrix given by {{VECTOR}}. If {{RESULT}} is {{#t}}, the returned value will be an f32vector located in non-garbage-collected memory (the memory will still be freed when there are no more references to the matrix). If {{RESULT}} is not provided, the returned value will be an f32vector located in normal garbage collected memory.
     44
     45<procedure> (translate VECTOR MATRIX)</procedure>
     46
     47Translate {{MATRIX}} by {{VECTOR}}.
    5348
    5449<procedure> (x-rotation ANGLE [RESULT])</procedure>
    5550
    56 Return the rotation matrix given by a rotation of {{ANGLE}} radians around the x-axis. If {{RESULT}} is {{#t}}, the returned value will be an f32vector located in non-garbage collected memory (the memory will still be freed when there are no more references to the matrix). If {{RESULT}} is not provided, the returned value will be an f32vector located in normal garbage collected memory.
     51Return the rotation matrix given by a rotation of {{ANGLE}} radians around the x-axis. If {{RESULT}} is {{#t}}, the returned value will be an f32vector located in non-garbage-collected memory (the memory will still be freed when there are no more references to the matrix). If {{RESULT}} is not provided, the returned value will be an f32vector located in normal garbage collected memory.
    5752
    5853<procedure> (rotate-x ANGLE MATRIX)</procedure>
     
    6257<procedure> (y-rotation ANGLE [RESULT])</procedure>
    6358
    64 Return the rotation matrix given by a rotation of {{ANGLE}} radians around the y-axis. If {{RESULT}} is {{#t}}, the returned value will be an f32vector located in non-garbage collected memory (the memory will still be freed when there are no more references to the matrix). If {{RESULT}} is not provided, the returned value will be an f32vector located in normal garbage collected memory.
     59Return the rotation matrix given by a rotation of {{ANGLE}} radians around the y-axis. If {{RESULT}} is {{#t}}, the returned value will be an f32vector located in non-garbage-collected memory (the memory will still be freed when there are no more references to the matrix). If {{RESULT}} is not provided, the returned value will be an f32vector located in normal garbage collected memory.
    6560
    6661<procedure> (rotate-y ANGLE MATRIX)</procedure>
     
    7065<procedure> (z-rotation ANGLE [RESULT])</procedure>
    7166
    72 Return the rotation matrix given by a rotation of {{ANGLE}} radians around the z-axis. If {{RESULT}} is {{#t}}, the returned value will be an f32vector located in non-garbage collected memory (the memory will still be freed when there are no more references to the matrix). If {{RESULT}} is not provided, the returned value will be an f32vector located in normal garbage collected memory.
     67Return the rotation matrix given by a rotation of {{ANGLE}} radians around the z-axis. If {{RESULT}} is {{#t}}, the returned value will be an f32vector located in non-garbage-collected memory (the memory will still be freed when there are no more references to the matrix). If {{RESULT}} is not provided, the returned value will be an f32vector located in normal garbage collected memory.
    7368
    7469<procedure> (rotate-z ANGLE MATRIX)</procedure>
     
    7671Rotate {{MATRIX}} around the z-axis by {{ANGLE}} radians.
    7772
    78 <procedure> (rotation X Y Z ANGLE [RESULT])</procedure>
    79 
    80 Return the rotation matrix given by a rotation of {{ANGLE}} radians around the vector {{(X, Y, Z)}}. If {{RESULT}} is {{#t}}, the returned value will be an f32vector located in non-garbage collected memory (the memory will still be freed when there are no more references to the matrix). If {{RESULT}} is not provided, the returned value will be an f32vector located in normal garbage collected memory.
    81 
    82 <procedure> (rotate X Y Z ANGLE MATRIX)</procedure>
    83 
    84 Rotate {{MATRIX}} around the vector {{(X, Y, Z)}} by {{ANGLE}} radians.
    85 
    86 <procedure> (quaternion-rotation X Y Z W [RESULT])</procedure>
    87 
    88 Return the rotation matrix given by the quaternion {{(X, Y, Z, Q)}}. If {{RESULT}} is {{#t}}, the returned value will be an f32vector located in non-garbage collected memory (the memory will still be freed when there are no more references to the matrix). If {{RESULT}} is not provided, the returned value will be an f32vector located in normal garbage collected memory.
    89 
    90 <procedure> (rotate-quaternion X Y Z W MATRIX)</procedure>
    91 
    92 Rotate {{MATRIX}} by the quaternion {{(X, Y, Z, Q)}}.
     73<procedure> (axis-angle-rotation AXIS ANGLE [RESULT])</procedure>
     74
     75Return the rotation matrix given by a rotation of {{ANGLE}} radians around the vector {{AXIS}}. If {{RESULT}} is {{#t}}, the returned value will be an f32vector located in non-garbage-collected memory (the memory will still be freed when there are no more references to the matrix). If {{RESULT}} is not provided, the returned value will be an f32vector located in normal garbage collected memory.
     76
     77<procedure> (rotate-axis-angle AXIS ANGLE MATRIX)</procedure>
     78
     79Rotate {{MATRIX}} around the vector {{AXIS}} by {{ANGLE}} radians.
     80
     81<procedure> (quaternion-rotation Q [RESULT])</procedure>
     82
     83Return the rotation matrix given by the quaternion {{Q}}. If {{RESULT}} is {{#t}}, the returned value will be an f32vector located in non-garbage-collected memory (the memory will still be freed when there are no more references to the matrix). If {{RESULT}} is not provided, the returned value will be an f32vector located in normal garbage collected memory.
     84
     85<procedure> (rotate-quaternion Q MATRIX)</procedure>
     86
     87Rotate {{MATRIX}} by the quaternion {{Q}}.
    9388
    9489<procedure> (ypr-rotation YAW PITCH ROLL [RESULT])</procedure>
    9590
    96 Return the rotation matrix given by rotating by {{ROLL}} radians followed by {{PITCH}} radians followed by {{YAW}} radians. If {{RESULT}} is {{#t}}, the returned value will be an f32vector located in non-garbage collected memory (the memory will still be freed when there are no more references to the matrix). If {{RESULT}} is not provided, the returned value will be an f32vector located in normal garbage collected memory.
     91Return the rotation matrix given by rotating by {{ROLL}} radians around the z-axis followed by {{PITCH}} radians around the x-axis followed by {{YAW}} radians around the y-axis. If {{RESULT}} is {{#t}}, the returned value will be an f32vector located in non-garbage-collected memory (the memory will still be freed when there are no more references to the matrix). If {{RESULT}} is not provided, the returned value will be an f32vector located in normal garbage collected memory.
    9792
    9893<procedure> (rotate-ypr YAW PITCH ROLL MATRIX)</procedure>
    9994
    100 Rotate {{MATRIX}} by {{ROLL}} radians followed by {{PITCH}} radians followed by {{YAW}} radians.
     95Rotate {{MATRIX}} by {{ROLL}} radians around the z-axis followed by {{PITCH}} radians around the x-axis followed by {{YAW}} radians around the y-axis.
    10196
    10297<procedure> (2d-scaling SCALE-X SCALE-Y [RESULT])</procedure>
    10398
    104 Return the matrix created by scaling the x and y axes by {{SCALE-X}} and {{SCALE-Y}}. If {{RESULT}} is {{#t}}, the returned value will be an f32vector located in non-garbage collected memory (the memory will still be freed when there are no more references to the matrix). If {{RESULT}} is not provided, the returned value will be an f32vector located in normal garbage collected memory.
     99Return the matrix created by scaling the x and y axes by {{SCALE-X}} and {{SCALE-Y}}. If {{RESULT}} is {{#t}}, the returned value will be an f32vector located in non-garbage-collected memory (the memory will still be freed when there are no more references to the matrix). If {{RESULT}} is not provided, the returned value will be an f32vector located in normal garbage collected memory.
    105100
    106101<procedure> (scale-2d SCALE-X SCALE-Y MATRIX)</procedure>
     
    110105<procedure> (3d-scaling SCALE-X SCALE-Y SCALE-Z [RESULT])</procedure>
    111106
    112 Return the matrix created by scaling the x, y and z axes by {{SCALE-X}}, {{SCALE-Y}}, and {{SCALE-Z}}. If {{RESULT}} is {{#t}}, the returned value will be an f32vector located in non-garbage collected memory (the memory will still be freed when there are no more references to the matrix). If {{RESULT}} is not provided, the returned value will be an f32vector located in normal garbage collected memory.
     107Return the matrix created by scaling the x, y and z axes by {{SCALE-X}}, {{SCALE-Y}}, and {{SCALE-Z}}. If {{RESULT}} is {{#t}}, the returned value will be an f32vector located in non-garbage-collected memory (the memory will still be freed when there are no more references to the matrix). If {{RESULT}} is not provided, the returned value will be an f32vector located in normal garbage collected memory.
    113108
    114109<procedure> (scale-3d SCALE-X SCALE-Y SCALE-Z MATRIX)</procedure>
     
    118113<procedure> (scaling SCALE [RESULT])</procedure>
    119114
    120 Return the matrix created by scaling the x, y and z axes by {{SCALE}}. If {{RESULT}} is {{#t}}, the returned value will be an f32vector located in non-garbage collected memory (the memory will still be freed when there are no more references to the matrix). If {{RESULT}} is not provided, the returned value will be an f32vector located in normal garbage collected memory.
     115Return the matrix created by scaling the x, y and z axes by {{SCALE}}. If {{RESULT}} is {{#t}}, the returned value will be an f32vector located in non-garbage-collected memory (the memory will still be freed when there are no more references to the matrix). If {{RESULT}} is not provided, the returned value will be an f32vector located in normal garbage collected memory.
    121116
    122117<procedure> (scale SCALE MATRIX)</procedure>
     
    136131Flip (mirror) {{MATRIX}} along the z-axis.
    137132
    138 <procedure> (translate-rotate-scale-2d X Y Z ANGLE SCALE [RESULT])</procedure>
    139 
    140 Efficiently create a matrix translated by {{X}}, {{Y}}, and {{Z}}, rotated around the z-axis by {{ANGLE}} radians, then scaled by {{SCALE}}. If the matrix {{RESULT}} is given, it will be modified to contain the result. If {{RESULT}} is {{#t}}, the returned value will be an f32vector located in non-garbage collected memory (the memory will still be freed when there are no more references to the matrix). If {{RESULT}} is not provided, the returned value will be an f32vector located in normal garbage collected memory.
     133<procedure> (translate-rotate-scale-2d VECTOR ANGLE SCALE [RESULT])</procedure>
     134
     135Efficiently create a matrix translated by {{VECTOR}}, rotated around the z-axis by {{ANGLE}} radians, then scaled by {{SCALE}}. If the matrix {{RESULT}} is given, it will be modified to contain the result. If {{RESULT}} is {{#t}}, the returned value will be an f32vector located in non-garbage-collected memory (the memory will still be freed when there are no more references to the matrix). If {{RESULT}} is not provided, the returned value will be an f32vector located in normal garbage collected memory.
    141136
    142137<procedure> (transpose MATRIX [RESULT])</procedure>
    143138
    144 Transpose {{MATRIX}}. If the matrix {{RESULT}} is given, it will be modified to contain the result. If {{RESULT}} is {{#t}}, {{MATRIX}} must be an f32vector and the returned value will be an f32vector located in non-garbage collected memory (the memory will still be freed when there are no more references to the matrix). If {{RESULT}} is not provided, {{MATRIX}} must be an f32vector and the returned value will be an f32vector located in normal garbage collected memory.
     139Transpose {{MATRIX}}. If the matrix {{RESULT}} is given, it will be modified to contain the result. If {{RESULT}} is {{#t}}, {{MATRIX}} must be an f32vector and the returned value will be an f32vector located in non-garbage-collected memory (the memory will still be freed when there are no more references to the matrix). If {{RESULT}} is not provided, {{MATRIX}} must be an f32vector and the returned value will be an f32vector located in normal garbage collected memory.
    145140
    146141<procedure> (inverse MATRIX [RESULT])</procedure>
    147142
    148 Invert {{MATRIX}}. If the matrix {{RESULT}} is given, it will be modified to contain the result. If {{RESULT}} is {{#t}}, {{MATRIX}} must be an f32vector and the returned value will be an f32vector located in non-garbage collected memory (the memory will still be freed when there are no more references to the matrix). If {{RESULT}} is not provided, {{MATRIX}} must be an f32vector and the returned value will be an f32vector located in normal garbage collected memory.
     143Invert {{MATRIX}}. If the matrix {{RESULT}} is given, it will be modified to contain the result. If {{RESULT}} is {{#t}}, {{MATRIX}} must be an f32vector and the returned value will be an f32vector located in non-garbage-collected memory (the memory will still be freed when there are no more references to the matrix). If {{RESULT}} is not provided, {{MATRIX}} must be an f32vector and the returned value will be an f32vector located in normal garbage collected memory.
    149144
    150145
     
    152147<procedure> (ortho WIDTH HEIGHT NEAR FAR [RESULT])</procedure>
    153148
    154 Create an orthographic projection matrix. If the matrix {{RESULT}} is given, it will be modified to contain the result. If {{RESULT}} is {{#t}}, the returned value will be an f32vector located in non-garbage collected memory (the memory will still be freed when there are no more references to the matrix). If {{RESULT}} is not provided, the returned value will be an f32vector located in normal garbage collected memory.
     149Create an orthographic projection matrix. If the matrix {{RESULT}} is given, it will be modified to contain the result. If {{RESULT}} is {{#t}}, the returned value will be an f32vector located in non-garbage-collected memory (the memory will still be freed when there are no more references to the matrix). If {{RESULT}} is not provided, the returned value will be an f32vector located in normal garbage collected memory.
    155150
    156151<procedure> (perspective WIDTH HEIGHT NEAR FAR ANGLE [RESULT])</procedure>
    157152
    158 Create an perspective projection matrix. If the matrix {{RESULT}} is given, it will be modified to contain the result. If {{RESULT}} is {{#t}}, the returned value will be an f32vector located in non-garbage collected memory (the memory will still be freed when there are no more references to the matrix). If {{RESULT}} is not provided, the returned value will be an f32vector located in normal garbage collected memory.
     153Create an perspective projection matrix. If the matrix {{RESULT}} is given, it will be modified to contain the result. If {{RESULT}} is {{#t}}, the returned value will be an f32vector located in non-garbage-collected memory (the memory will still be freed when there are no more references to the matrix). If {{RESULT}} is not provided, the returned value will be an f32vector located in normal garbage collected memory.
    159154
    160155<procedure> (frustum LEFT RIGHT BOTTOM TOP NEAR FAR [RESULT])</procedure>
    161156
    162 Create a view-frustum matrix. If the matrix {{RESULT}} is given, it will be modified to contain the result. If {{RESULT}} is {{#t}}, the returned value will be an f32vector located in non-garbage collected memory (the memory will still be freed when there are no more references to the matrix). If {{RESULT}} is not provided, the returned value will be an f32vector located in normal garbage collected memory.
     157Create a view-frustum matrix. If the matrix {{RESULT}} is given, it will be modified to contain the result. If {{RESULT}} is {{#t}}, the returned value will be an f32vector located in non-garbage-collected memory (the memory will still be freed when there are no more references to the matrix). If {{RESULT}} is not provided, the returned value will be an f32vector located in normal garbage collected memory.
    163158
    164159
    165160==== Camera functions
    166 <procedure> (look-at EYE-X EYE-Y EYE-Z X Y Z UP-X UP-Y UP-Z [RESULT])</procedure>
    167 
    168 Create a “look-at” style camera matrix. The camera is positioned at {{(EYE-X, EYE-Y, EYE-Z)}}, pointing towards {{(X, Y, Z)}}. {{(UP-X, UP-Y, UP-Z)}} defines the camera’s up vector. If the matrix {{RESULT}} is given, it will be modified to contain the result. If {{RESULT}} is {{#t}}, the returned value will be an f32vector located in non-garbage collected memory (the memory will still be freed when there are no more references to the matrix). If {{RESULT}} is not provided, the returned value will be an f32vector located in normal garbage collected memory.
     161<procedure> (look-at EYE OBJ UP [RESULT])</procedure>
     162
     163Create a “look-at” style camera matrix. The camera is positioned at point {{EYE}}, pointing towards the point {{OBJ}}. {{UP}} defines the camera’s up vector. If the matrix {{RESULT}} is given, it will be modified to contain the result. If {{RESULT}} is {{#t}}, the returned value will be an f32vector located in non-garbage-collected memory (the memory will still be freed when there are no more references to the matrix). If {{RESULT}} is not provided, the returned value will be an f32vector located in normal garbage collected memory.
    169164
    170165<procedure> (camera-inverse CAMERA [RESULT])</procedure>
    171166
    172 Invert {{CAMERA}} in an efficient fashion. This allows the camera to be constructed in an intuitive fashion by translating and rotating before inverting in order to position the scene properly. This function is far faster than the general {{inverse}} function, but the matrix {{CAMERA}} must only be a matrix representing a translation and a rotation (no scaling). If the matrix {{RESULT}} is given, it will be modified to contain the result. If {{RESULT}} is {{#t}}, {{CAMERA}} must be an f32vector and the returned value will be an f32vector located in non-garbage collected memory (the memory will still be freed when there are no more references to the matrix). If {{RESULT}} is not provided, {{CAMERA}} must be an f32vector and the returned value will be an f32vector located in normal garbage collected memory.
     167Invert {{CAMERA}} in an efficient fashion. This allows the camera to be constructed in an intuitive fashion by translating and rotating before inverting in order to position the scene properly. This function is far faster than the general {{inverse}} function, but the matrix {{CAMERA}} must only be a matrix representing a translation and a rotation (no scaling). If the matrix {{RESULT}} is given, it will be modified to contain the result. If {{RESULT}} is {{#t}}, {{CAMERA}} must be an f32vector and the returned value will be an f32vector located in non-garbage-collected memory (the memory will still be freed when there are no more references to the matrix). If {{RESULT}} is not provided, {{CAMERA}} must be an f32vector and the returned value will be an f32vector located in normal garbage collected memory.
    173168
    174169
    175170==== Vector operations
    176 <procedure> (cross-product AX AY AZ BX BY BZ)</procedure>
    177 
    178 Return the result of the cross product between the vectors {{(AX, AY, AZ)}} and {{(BX, BY, BZ)}}. The resulting vector is returned as three values.
    179 
    180 <procedure> (dot-product AX AY AZ BX BY BZ)</procedure>
    181 
    182 Return the result of the dot product between the vectors {{(AX, AY, AZ)}} and {{(BX, BY, BZ)}}.
    183 
    184 <procedure> (normalize X Y Z)</procedure>
    185 
    186 Return the normalized vector {{(X, Y, Z)}}. The resulting vector is returned as three values.
     171<procedure> (make-point X Y Z [NON-GC?])</procedure>
     172<procedure> (point-x POINT)</procedure>
     173<procedure> (point-y POINT)</procedure>
     174<procedure> (point-z POINT)</procedure>
     175<procedure> (point-x-set! POINT)</procedure>
     176<procedure> (point-y-set! POINT)</procedure>
     177<procedure> (point-z-set! POINT)</procedure>
     178
     179Vector constructor, getters, and setters. If {{NON-GC}} is {{#t}}, the point is created in a non-garbage-collected area (the memory will still be freed when there are no more references to the vector).
     180
     181<procedure> (v+ A B [RESULT])</procedure>
     182
     183Return the result of the addition of vectors {{A}} and {{B}}. If the vector {{RESULT}} is given, it will be modified to contain the result. If {{RESULT}} is {{#t}} the returned value will be an f32vector located in non-garbage-collected memory (the memory will still be freed when there are no more references to the matrix). If {{RESULT}} is not provided, the returned value will be an f32vector located in normal garbage collected memory.
     184
     185<procedure> (v- A B [RESULT])</procedure>
     186
     187Return the result of the subtraction of vector {{B}} from {{A}}. If the vector {{RESULT}} is given, it will be modified to contain the result. If {{RESULT}} is {{#t}} the returned value will be an f32vector located in non-garbage-collected memory (the memory will still be freed when there are no more references to the matrix). If {{RESULT}} is not provided, the returned value will be an f32vector located in normal garbage collected memory.
     188
     189<procedure> (v* V S [RESULT])</procedure>
     190
     191Return the result of the multiplication of vector {{A}} with scalar {{S}}. If the vector {{RESULT}} is given, it will be modified to contain the result. If {{RESULT}} is {{#t}} the returned value will be an f32vector located in non-garbage-collected memory (the memory will still be freed when there are no more references to the matrix). If {{RESULT}} is not provided, the returned value will be an f32vector located in normal garbage collected memory.
     192
     193<procedure> (cross-product A B [RESULT])</procedure>
     194
     195Return the result of the cross product between the vectors {{A}} and {{B}}. If the vector {{RESULT}} is given, it will be modified to contain the result. If {{RESULT}} is {{#t}} the returned value will be an f32vector located in non-garbage-collected memory (the memory will still be freed when there are no more references to the matrix). If {{RESULT}} is not provided, the returned value will be an f32vector located in normal garbage collected memory.
     196
     197<procedure> (dot-product A B)</procedure>
     198
     199Return the result of the dot product between the vectors {{A}} and {{B}}.
     200
     201<procedure> (vector-magnitude V)</procedure>
     202
     203Return the magnitude of vector {{V}}.
     204
     205<procedure> (normalize! V)</procedure>
     206
     207Destructively normalize the vector {{V}}.
    187208
    188209<procedure> (m*vector! MATRIX VECTOR)</procedure>
    189210
    190 Destructively multiply the 3 element f32vector {{VECTOR}} by {{MATRIX}}.
     211Destructively multiply {{VECTOR}} by {{MATRIX}}.
    191212
    192213<procedure> (m*vector-array! MATRIX VECTORS stride: [STRIDE] length: [LENGTH])</procedure>
    193214
    194215Destructively multiply the array of 3 element floats {{VECTORS}} by {{MATRIX}}. The keyword {{STRIDE}} specifies the number of elements between consecutive vectors, given in number of floats (which must be at least 3). {{VECTORS}} may be given as an f32vector or a pointer. When given as a pointer, the keyword {{LENGTH}} must be provided, specifying the number of vectors in {{VECTORS}}.
     216
     217<procedure> (lerp A B T [RESULT])</procedure>
     218
     219Linear interpolation between the points {{A}} and {{B}} with the interpolation parameter {{T}} which must be between 0 and 1. If the vector {{RESULT}} is given, it will be modified to contain the result. If {{RESULT}} is {{#t}} the returned value will be an f32vector located in non-garbage-collected memory (the memory will still be freed when there are no more references to the matrix). If {{RESULT}} is not provided, the returned value will be an f32vector located in normal garbage collected memory.
     220
     221
     222==== Quaternion operations
     223Quaternions are expected to be normalized before they are used in certain functions ({{quaternion-normalize}} may be used to do so). All the provided functions that create quaternions, create unit quaternions.
     224
     225The order of quaternion cross-multiplication is the inverse of the “standard” order, so a quaternion that has undergone a series or rotations will represent the same rotation as a marix that has gone through the same series, in the same order.
     226
     227<procedure> (make-quaternion X Y Z W [NON-GC?])</procedure>
     228<procedure> (quaternion-x POINT)</procedure>
     229<procedure> (quaternion-y POINT)</procedure>
     230<procedure> (quaternion-z POINT)</procedure>
     231<procedure> (quaternion-w POINT)</procedure>
     232<procedure> (quaternion-x-set! POINT)</procedure>
     233<procedure> (quaternion-y-set! POINT)</procedure>
     234<procedure> (quaternion-z-set! POINT)</procedure>
     235<procedure> (quaternion-w-set! POINT)</procedure>
     236
     237Quaternion constructor, getters, and setters. If {{NON-GC}} is {{#t}}, the quaternion is created in a non-garbage-collected area (the memory will still be freed when there are no more references to the quaternion).
     238
     239<procedure> (quaternion-normalize! Q)</procedure>
     240
     241Destructively normalize the quaternion {{Q}}.
     242
     243<procedure> (quaternion-inverse Q [RESULT])</procedure>
     244
     245Return the inverse of the unit quaternion {{Q}}. If the quaternion {{RESULT}} is given, it will be modified to contain the result. If {{RESULT}} is {{#t}} the returned value will be an f32vector located in non-garbage-collected memory (the memory will still be freed when there are no more references to the matrix). If {{RESULT}} is not provided, the returned value will be an f32vector located in normal garbage collected memory.
     246
     247<procedure> (quaternion-cross-product A B [RESULT])</procedure>
     248
     249Return the cross-product of the quaternions {{A}} and {{B}}. If the quaternion {{RESULT}} is given, it will be modified to contain the result. If {{RESULT}} is {{#t}} the returned value will be an f32vector located in non-garbage-collected memory (the memory will still be freed when there are no more references to the matrix). If {{RESULT}} is not provided, the returned value will be an f32vector located in normal garbage collected memory.
     250
     251<procedure> (quaternion-axis-angle-rotation AXIS ANGLE [RESULT])</procedure>
     252
     253Return the quaternion corresponding to a rotation of {{ANGLE}} radians around the vector {{AXIS}}. If the quaternion {{RESULT}} is given, it will be modified to contain the result. If {{RESULT}} is {{#t}} the returned value will be an f32vector located in non-garbage-collected memory (the memory will still be freed when there are no more references to the matrix). If {{RESULT}} is not provided, the returned value will be an f32vector located in normal garbage collected memory.
     254
     255<procedure> (quaternion-rotate-axis-angle AXIS ANGLE Q)</procedure>
     256
     257Rotate the quaternion {{Q}} by a rotation of {{ANGLE}} radians around the vector {{AXIS}}.
     258
     259<procedure> (quaternion-x-rotation ANGLE [RESULT])</procedure>
     260
     261Return the quaternion corresponding to a rotation of {{ANGLE}} radians around the x-axis. If the quaternion {{RESULT}} is given, it will be modified to contain the result. If {{RESULT}} is {{#t}} the returned value will be an f32vector located in non-garbage-collected memory (the memory will still be freed when there are no more references to the matrix). If {{RESULT}} is not provided, the returned value will be an f32vector located in normal garbage collected memory.
     262
     263<procedure> (quaternion-rotate-x ANGLE Q)</procedure>
     264
     265Rotate the quaternion {{Q}} by a rotation of {{ANGLE}} radians around the x-axis.
     266
     267<procedure> (quaternion-y-rotation ANGLE [RESULT])</procedure>
     268
     269Return the quaternion corresponding to a rotation of {{ANGLE}} radians around the y-axis. If the quaternion {{RESULT}} is given, it will be modified to contain the result. If {{RESULT}} is {{#t}} the returned value will be an f32vector located in non-garbage-collected memory (the memory will still be freed when there are no more references to the matrix). If {{RESULT}} is not provided, the returned value will be an f32vector located in normal garbage collected memory.
     270
     271<procedure> (quaternion-rotate-y ANGLE Q)</procedure>
     272
     273Rotate the quaternion {{Q}} by a rotation of {{ANGLE}} radians around the y-axis.
     274
     275<procedure> (quaternion-z-rotation ANGLE [RESULT])</procedure>
     276
     277Return the quaternion corresponding to a rotation of {{ANGLE}} radians around the z-axis. If the quaternion {{RESULT}} is given, it will be modified to contain the result. If {{RESULT}} is {{#t}} the returned value will be an f32vector located in non-garbage-collected memory (the memory will still be freed when there are no more references to the matrix). If {{RESULT}} is not provided, the returned value will be an f32vector located in normal garbage collected memory.
     278
     279<procedure> (quaternion-rotate-z ANGLE Q)</procedure>
     280
     281Rotate the quaternion {{Q}} by a rotation of {{ANGLE}} radians around the z-axis.
     282
     283<procedure> (quaternion-ypr-rotation YAW PITCH ROLL [RESULT])</procedure>
     284
     285Return the quaternion corresponding to a rotation of {{ROLL}} radians around the z-axis followed by {{PITCH}} radians around the x-axis followed by {{YAW}} radians around the y-axis. If the quaternion {{RESULT}} is given, it will be modified to contain the result. If {{RESULT}} is {{#t}} the returned value will be an f32vector located in non-garbage-collected memory (the memory will still be freed when there are no more references to the matrix). If {{RESULT}} is not provided, the returned value will be an f32vector located in normal garbage collected memory.
     286
     287<procedure> (quaternion-rotate-ypr YAW PITCH ROLL Q)</procedure>
     288
     289Rotate the quaternion {{Q}} by {{ROLL}} radians around the z-axis followed by {{PITCH}} radians around the x-axis followed by {{YAW}} radians around the y-axis.
     290
     291<procedure> (quaternion-rotate-point! Q P)</procedure>
     292
     293Destructively rotate the point {{P}} by the unit quaternion {{Q}}.
     294
     295<procedure> (slerp A B T [RESULT])</procedure>
     296
     297Spherical linear interpolation between the quaternions {{A}} and {{B}} with the interpolation parameter {{T}} which must be between 0 and 1. If the quaternion {{RESULT}} is given, it will be modified to contain the result. If {{RESULT}} is {{#t}} the returned value will be an f32vector located in non-garbage-collected memory (the memory will still be freed when there are no more references to the matrix). If {{RESULT}} is not provided, the returned value will be an f32vector located in normal garbage collected memory.
    195298
    196299
     
    203306
    204307Converts {{ANGLE}} from radians to degrees.
     308
     309<constant> pi</constant>
     310<constant> pi/2</constant>
    205311
    206312
     
    214320
    215321(define view-matrix
    216   (look-at 1 0 3
    217            0 0 0
    218            0 1 0))
     322  (look-at (make-point 1 0 3)
     323           (make-point 0 0 0)
     324           (make-point 0 1 0)))
    219325
    220326(define model-matrix (mat4-identity))
     
    226332
    227333=== Version history
     334
     335==== Version 0.5.0
     3362 September 2014
     337
     338* Many new vector and quaternion functions
     339* Functions that previously accepted vectors as individual floats, now accept them as f32vectors
     340
    228341
    229342==== Version 0.4.1
     
    281394=== Licence
    282395BSD
     396
Note: See TracChangeset for help on using the changeset viewer.