init.lua 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. return {
  2. summary = 'A quaternion.',
  3. description = [[
  4. A `quat` is a math type that represents a 3D rotation, stored as four numbers. LÖVR functions
  5. that take rotations also accept quaternions. `quat`s are created using `lovr.math.quat` or by
  6. using a `Pool`.
  7. The four numbers stored in a `quat`, normally called `x, y, z, w`, are not very intuitive to
  8. work with. Instead, rotations in most LÖVR APIs use the angle/axis representation, which is
  9. defined by a rotation angle in radians and an axis to rotate around. Accordingly, the quat
  10. functions for getting and setting elements, `quat:unpack` and `quat:set`, don't take the normal
  11. `x, y, z, w` elements but instead take four angle/axis values. If you need to access the raw
  12. components, you can pass in `true` as the last argument to signify that you want to work with
  13. raw components.
  14. Two quaternions can be multiplied together to combine their rotations into a single new
  15. quaternion. The `quat:mul` function can be used to multiply two quaternions "in place",
  16. modifying the first quaternion. Alternatively, the `*` operator can be used to multiply them,
  17. which will create a new quaternion to store the result in.
  18. A quaternion can also be multiplied by a vector. This rotates the vector. Both `quat:mul` and
  19. the `*` operator can be used for this.
  20. A common source of bugs is to forget to normalize a quaternion. If you run into weird bugs with
  21. rotations, calling `quat:normalize` on your rotations may fix the issue!
  22. Creating huge numbers of quaternions every frame can lead to performance problems due to the
  23. sheer amount of memory allocation and garbage collection overhead. If you need lots of
  24. quaternion objects you can use `Pool`s to make things much more efficient.
  25. ]],
  26. constructors = {
  27. 'lovr.math.quat',
  28. 'Pool:quat'
  29. },
  30. related = {
  31. 'vec3',
  32. 'mat4'
  33. }
  34. }