Changeset 31326 in project
 Timestamp:
 09/02/14 20:03:04 (7 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

wiki/eggref/4/glmath
r31310 r31326 1 2 1 == glmath 3 2 [[toc:]] 4 A very small math library for gamedev that mostly provides 4x4 float matrixoperations. Uses the [[https://github.com/AlexCharlton/hypermathhypermath]] library.3 A small math library aimed at gamedev that provides 4x4 float matrix, vector, and quaternion operations. Uses the [[https://github.com/AlexCharlton/hypermathhypermath]] library. 5 4 6 5 … … 18 17 Additionally, glmath is one fifth the compiled size of glm, has a more straightforward codebase, and complete documentation. 19 18 20 glmath 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 matricesmust be of the same type.21 22 glmath operates on matrices in a columnmajor fashion in correspondence with OpenGL (e.g. translation components are at indices 12, 13, and 14). 19 glmath 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 21 glmath operates on matrices in a columnmajor 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)}}). 23 22 24 23 … … 30 29 <procedure> (copymat4 MATRIX [RESULT])</procedure> 31 30 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 nongarbage 31 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 nongarbagecollected 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. 33 32 34 33 <procedure> (m* A B [RESULT])</procedure> 35 34 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 nongarbage 35 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 nongarbagecollected 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. 37 36 38 37 <procedure> (mat4identity [RESULT])</procedure> 39 38 40 Return an identity matrix. If {{RESULT}} is {{#t}}, the returned value will be an f32vector located in nongarbage 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 nongarbage 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 Xaxis in the given matrix. 39 Return an identity matrix. If {{RESULT}} is {{#t}}, the returned value will be an f32vector located in nongarbagecollected 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 43 Return the translation matrix given by {{VECTOR}}. If {{RESULT}} is {{#t}}, the returned value will be an f32vector located in nongarbagecollected 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 47 Translate {{MATRIX}} by {{VECTOR}}. 53 48 54 49 <procedure> (xrotation ANGLE [RESULT])</procedure> 55 50 56 Return the rotation matrix given by a rotation of {{ANGLE}} radians around the xaxis. If {{RESULT}} is {{#t}}, the returned value will be an f32vector located in nongarbage 51 Return the rotation matrix given by a rotation of {{ANGLE}} radians around the xaxis. If {{RESULT}} is {{#t}}, the returned value will be an f32vector located in nongarbagecollected 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. 57 52 58 53 <procedure> (rotatex ANGLE MATRIX)</procedure> … … 62 57 <procedure> (yrotation ANGLE [RESULT])</procedure> 63 58 64 Return the rotation matrix given by a rotation of {{ANGLE}} radians around the yaxis. If {{RESULT}} is {{#t}}, the returned value will be an f32vector located in nongarbage 59 Return the rotation matrix given by a rotation of {{ANGLE}} radians around the yaxis. If {{RESULT}} is {{#t}}, the returned value will be an f32vector located in nongarbagecollected 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. 65 60 66 61 <procedure> (rotatey ANGLE MATRIX)</procedure> … … 70 65 <procedure> (zrotation ANGLE [RESULT])</procedure> 71 66 72 Return the rotation matrix given by a rotation of {{ANGLE}} radians around the zaxis. If {{RESULT}} is {{#t}}, the returned value will be an f32vector located in nongarbage 67 Return the rotation matrix given by a rotation of {{ANGLE}} radians around the zaxis. If {{RESULT}} is {{#t}}, the returned value will be an f32vector located in nongarbagecollected 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. 73 68 74 69 <procedure> (rotatez ANGLE MATRIX)</procedure> … … 76 71 Rotate {{MATRIX}} around the zaxis by {{ANGLE}} radians. 77 72 78 <procedure> ( rotation X Y ZANGLE [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 nongarbagecollected 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 ZANGLE MATRIX)</procedure>83 84 Rotate {{MATRIX}} around the vector {{ (X, Y, Z)}} by {{ANGLE}} radians.85 86 <procedure> (quaternionrotation 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 nongarbagecollected 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> (rotatequaternion X Y Z WMATRIX)</procedure>91 92 Rotate {{MATRIX}} by the quaternion {{ (X, Y, Z, Q)}}.73 <procedure> (axisanglerotation AXIS ANGLE [RESULT])</procedure> 74 75 Return 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 nongarbagecollected 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> (rotateaxisangle AXIS ANGLE MATRIX)</procedure> 78 79 Rotate {{MATRIX}} around the vector {{AXIS}} by {{ANGLE}} radians. 80 81 <procedure> (quaternionrotation Q [RESULT])</procedure> 82 83 Return the rotation matrix given by the quaternion {{Q}}. If {{RESULT}} is {{#t}}, the returned value will be an f32vector located in nongarbagecollected 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> (rotatequaternion Q MATRIX)</procedure> 86 87 Rotate {{MATRIX}} by the quaternion {{Q}}. 93 88 94 89 <procedure> (yprrotation YAW PITCH ROLL [RESULT])</procedure> 95 90 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 nongarbagecollected 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.91 Return the rotation matrix given by rotating by {{ROLL}} radians around the zaxis followed by {{PITCH}} radians around the xaxis followed by {{YAW}} radians around the yaxis. If {{RESULT}} is {{#t}}, the returned value will be an f32vector located in nongarbagecollected 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. 97 92 98 93 <procedure> (rotateypr YAW PITCH ROLL MATRIX)</procedure> 99 94 100 Rotate {{MATRIX}} by {{ROLL}} radians followed by {{PITCH}} radians followed by {{YAW}} radians.95 Rotate {{MATRIX}} by {{ROLL}} radians around the zaxis followed by {{PITCH}} radians around the xaxis followed by {{YAW}} radians around the yaxis. 101 96 102 97 <procedure> (2dscaling SCALEX SCALEY [RESULT])</procedure> 103 98 104 Return the matrix created by scaling the x and y axes by {{SCALEX}} and {{SCALEY}}. If {{RESULT}} is {{#t}}, the returned value will be an f32vector located in nongarbage 99 Return the matrix created by scaling the x and y axes by {{SCALEX}} and {{SCALEY}}. If {{RESULT}} is {{#t}}, the returned value will be an f32vector located in nongarbagecollected 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. 105 100 106 101 <procedure> (scale2d SCALEX SCALEY MATRIX)</procedure> … … 110 105 <procedure> (3dscaling SCALEX SCALEY SCALEZ [RESULT])</procedure> 111 106 112 Return the matrix created by scaling the x, y and z axes by {{SCALEX}}, {{SCALEY}}, and {{SCALEZ}}. If {{RESULT}} is {{#t}}, the returned value will be an f32vector located in nongarbage 107 Return the matrix created by scaling the x, y and z axes by {{SCALEX}}, {{SCALEY}}, and {{SCALEZ}}. If {{RESULT}} is {{#t}}, the returned value will be an f32vector located in nongarbagecollected 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. 113 108 114 109 <procedure> (scale3d SCALEX SCALEY SCALEZ MATRIX)</procedure> … … 118 113 <procedure> (scaling SCALE [RESULT])</procedure> 119 114 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 nongarbage 115 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 nongarbagecollected 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. 121 116 122 117 <procedure> (scale SCALE MATRIX)</procedure> … … 136 131 Flip (mirror) {{MATRIX}} along the zaxis. 137 132 138 <procedure> (translaterotatescale2d X Y ZANGLE SCALE [RESULT])</procedure>139 140 Efficiently create a matrix translated by {{ X}}, {{Y}}, and {{Z}}, rotated around the zaxis 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 nongarbagecollected 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> (translaterotatescale2d VECTOR ANGLE SCALE [RESULT])</procedure> 134 135 Efficiently create a matrix translated by {{VECTOR}}, rotated around the zaxis 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 nongarbagecollected 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. 141 136 142 137 <procedure> (transpose MATRIX [RESULT])</procedure> 143 138 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 nongarbage 139 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 nongarbagecollected 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. 145 140 146 141 <procedure> (inverse MATRIX [RESULT])</procedure> 147 142 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 nongarbage 143 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 nongarbagecollected 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. 149 144 150 145 … … 152 147 <procedure> (ortho WIDTH HEIGHT NEAR FAR [RESULT])</procedure> 153 148 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 nongarbage 149 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 nongarbagecollected 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. 155 150 156 151 <procedure> (perspective WIDTH HEIGHT NEAR FAR ANGLE [RESULT])</procedure> 157 152 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 nongarbage 153 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 nongarbagecollected 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. 159 154 160 155 <procedure> (frustum LEFT RIGHT BOTTOM TOP NEAR FAR [RESULT])</procedure> 161 156 162 Create a viewfrustum 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 nongarbage 157 Create a viewfrustum 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 nongarbagecollected 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. 163 158 164 159 165 160 ==== Camera functions 166 <procedure> (lookat EYE X EYEY EYEZ X Y Z UPX UPY UPZ[RESULT])</procedure>167 168 Create a âlookatâ style camera matrix. The camera is positioned at {{(EYEX, EYEY, EYEZ)}}, pointing towards {{(X, Y, Z)}}. {{(UPX, UPY, UPZ)}} 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 nongarbagecollected 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> (lookat EYE OBJ UP [RESULT])</procedure> 162 163 Create a âlookatâ 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 nongarbagecollected 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. 169 164 170 165 <procedure> (camerainverse CAMERA [RESULT])</procedure> 171 166 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 nongarbage 167 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 nongarbagecollected 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. 173 168 174 169 175 170 ==== Vector operations 176 <procedure> (crossproduct 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> (dotproduct 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> (makepoint X Y Z [NONGC?])</procedure> 172 <procedure> (pointx POINT)</procedure> 173 <procedure> (pointy POINT)</procedure> 174 <procedure> (pointz POINT)</procedure> 175 <procedure> (pointxset! POINT)</procedure> 176 <procedure> (pointyset! POINT)</procedure> 177 <procedure> (pointzset! POINT)</procedure> 178 179 Vector constructor, getters, and setters. If {{NONGC}} is {{#t}}, the point is created in a nongarbagecollected 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 183 Return 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 nongarbagecollected 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 187 Return 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 nongarbagecollected 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 191 Return 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 nongarbagecollected 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> (crossproduct A B [RESULT])</procedure> 194 195 Return 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 nongarbagecollected 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> (dotproduct A B)</procedure> 198 199 Return the result of the dot product between the vectors {{A}} and {{B}}. 200 201 <procedure> (vectormagnitude V)</procedure> 202 203 Return the magnitude of vector {{V}}. 204 205 <procedure> (normalize! V)</procedure> 206 207 Destructively normalize the vector {{V}}. 187 208 188 209 <procedure> (m*vector! MATRIX VECTOR)</procedure> 189 210 190 Destructively multiply the 3 element f32vector{{VECTOR}} by {{MATRIX}}.211 Destructively multiply {{VECTOR}} by {{MATRIX}}. 191 212 192 213 <procedure> (m*vectorarray! MATRIX VECTORS stride: [STRIDE] length: [LENGTH])</procedure> 193 214 194 215 Destructively 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 219 Linear 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 nongarbagecollected 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 223 Quaternions are expected to be normalized before they are used in certain functions ({{quaternionnormalize}} may be used to do so). All the provided functions that create quaternions, create unit quaternions. 224 225 The order of quaternion crossmultiplication 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> (makequaternion X Y Z W [NONGC?])</procedure> 228 <procedure> (quaternionx POINT)</procedure> 229 <procedure> (quaterniony POINT)</procedure> 230 <procedure> (quaternionz POINT)</procedure> 231 <procedure> (quaternionw POINT)</procedure> 232 <procedure> (quaternionxset! POINT)</procedure> 233 <procedure> (quaternionyset! POINT)</procedure> 234 <procedure> (quaternionzset! POINT)</procedure> 235 <procedure> (quaternionwset! POINT)</procedure> 236 237 Quaternion constructor, getters, and setters. If {{NONGC}} is {{#t}}, the quaternion is created in a nongarbagecollected area (the memory will still be freed when there are no more references to the quaternion). 238 239 <procedure> (quaternionnormalize! Q)</procedure> 240 241 Destructively normalize the quaternion {{Q}}. 242 243 <procedure> (quaternioninverse Q [RESULT])</procedure> 244 245 Return 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 nongarbagecollected 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> (quaternioncrossproduct A B [RESULT])</procedure> 248 249 Return the crossproduct 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 nongarbagecollected 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> (quaternionaxisanglerotation AXIS ANGLE [RESULT])</procedure> 252 253 Return 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 nongarbagecollected 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> (quaternionrotateaxisangle AXIS ANGLE Q)</procedure> 256 257 Rotate the quaternion {{Q}} by a rotation of {{ANGLE}} radians around the vector {{AXIS}}. 258 259 <procedure> (quaternionxrotation ANGLE [RESULT])</procedure> 260 261 Return the quaternion corresponding to a rotation of {{ANGLE}} radians around the xaxis. 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 nongarbagecollected 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> (quaternionrotatex ANGLE Q)</procedure> 264 265 Rotate the quaternion {{Q}} by a rotation of {{ANGLE}} radians around the xaxis. 266 267 <procedure> (quaternionyrotation ANGLE [RESULT])</procedure> 268 269 Return the quaternion corresponding to a rotation of {{ANGLE}} radians around the yaxis. 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 nongarbagecollected 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> (quaternionrotatey ANGLE Q)</procedure> 272 273 Rotate the quaternion {{Q}} by a rotation of {{ANGLE}} radians around the yaxis. 274 275 <procedure> (quaternionzrotation ANGLE [RESULT])</procedure> 276 277 Return the quaternion corresponding to a rotation of {{ANGLE}} radians around the zaxis. 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 nongarbagecollected 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> (quaternionrotatez ANGLE Q)</procedure> 280 281 Rotate the quaternion {{Q}} by a rotation of {{ANGLE}} radians around the zaxis. 282 283 <procedure> (quaternionyprrotation YAW PITCH ROLL [RESULT])</procedure> 284 285 Return the quaternion corresponding to a rotation of {{ROLL}} radians around the zaxis followed by {{PITCH}} radians around the xaxis followed by {{YAW}} radians around the yaxis. 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 nongarbagecollected 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> (quaternionrotateypr YAW PITCH ROLL Q)</procedure> 288 289 Rotate the quaternion {{Q}} by {{ROLL}} radians around the zaxis followed by {{PITCH}} radians around the xaxis followed by {{YAW}} radians around the yaxis. 290 291 <procedure> (quaternionrotatepoint! Q P)</procedure> 292 293 Destructively rotate the point {{P}} by the unit quaternion {{Q}}. 294 295 <procedure> (slerp A B T [RESULT])</procedure> 296 297 Spherical 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 nongarbagecollected 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. 195 298 196 299 … … 203 306 204 307 Converts {{ANGLE}} from radians to degrees. 308 309 <constant> pi</constant> 310 <constant> pi/2</constant> 205 311 206 312 … … 214 320 215 321 (define viewmatrix 216 (lookat 1 0 3217 0 0 0218 0 1 0))322 (lookat (makepoint 1 0 3) 323 (makepoint 0 0 0) 324 (makepoint 0 1 0))) 219 325 220 326 (define modelmatrix (mat4identity)) … … 226 332 227 333 === Version history 334 335 ==== Version 0.5.0 336 2 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 228 341 229 342 ==== Version 0.4.1 … … 281 394 === Licence 282 395 BSD 396
Note: See TracChangeset
for help on using the changeset viewer.