Browse Source

Add missing math functions;

bjorn 6 years ago
parent
commit
de0124e116
4 changed files with 1143 additions and 647 deletions
  1. 942 647
      api/init.lua
  2. 61 0
      api/lovr/math/mat4.lua
  3. 93 0
      api/lovr/math/quat.lua
  4. 47 0
      api/lovr/math/vec3.lua

File diff suppressed because it is too large
+ 942 - 647
api/init.lua


+ 61 - 0
api/lovr/math/mat4.lua

@@ -0,0 +1,61 @@
+return {
+  summary = 'Create a new `mat4`.',
+  description = 'Creates a new `mat4`.',
+  arguments = {
+    n = {
+      type = 'mat4',
+      description = 'An existing matrix to copy the values from.'
+    },
+    position = {
+      type = 'vec3',
+      default = '0, 0, 0',
+      description = 'The translation of the matrix.'
+    },
+    scale = {
+      type = 'vec3',
+      default = '1, 1, 1',
+      description = 'The scale of the matrix.'
+    },
+    rotation = {
+      type = 'quat',
+      default = '0, 0, 0, 0',
+      description = 'The rotation of the matrix.'
+    },
+    ['...'] = {
+      type = 'number',
+      description = '16 numbers to use as the raw values of the matrix (column-major).'
+    }
+  },
+  returns = {
+    m = {
+      type = 'mat4',
+      description = 'The new matrix.'
+    }
+  },
+  variants = {
+    {
+      description = 'Sets the matrix to the identity matrix.',
+      arguments = {},
+      returns = { 'm' }
+    },
+    {
+      description = 'Copies values from an existing matrix.',
+      arguments = { 'n' },
+      returns = { 'm' }
+    },
+    {
+      arguments = { 'position', 'scale', 'rotation' },
+      returns = { 'm' }
+    },
+    {
+      arguments = { '...' },
+      returns = { 'm' }
+    }
+  },
+  notes = 'This function takes the same arguments as `mat4:set`.',
+  related = {
+    'Pool:mat4',
+    'lovr.math.vec3',
+    'lovr.math.quat'
+  }
+}

+ 93 - 0
api/lovr/math/quat.lua

@@ -0,0 +1,93 @@
+return {
+  summary = 'Create a new `quat`.',
+  description = [[
+    Creates a new `quat`.  Have a look at `quat:set` for more information about how all these
+    variants can be used.
+  ]],
+  arguments = {
+    angle = {
+      default = '0',
+      description = 'The angle to use for the rotation, in radians.'
+    },
+    ax = {
+      type = 'number',
+      default = '0',
+      description = 'The x component of the axis of rotation.'
+    },
+    ay = {
+      type = 'number',
+      default = '0',
+      description = 'The y component of the axis of rotation.'
+    },
+    az = {
+      type = 'number',
+      default = '0',
+      description = 'The z component of the axis of rotation.'
+    },
+    axis = {
+      type = 'vec3',
+      description = 'The axis of rotation (does not need to be normalized).'
+    },
+    raw = {
+      type = 'boolean',
+      default = 'false',
+      description = 'Whether the components should be interpreted as raw `(x, y, z, w)` components.'
+    },
+    v = {
+      type = 'vec3',
+      description = 'A normalized direction vector.'
+    },
+    u = {
+      type = 'vec3',
+      description = 'Another normalized direction vector.'
+    },
+    r = {
+      type = 'quat',
+      description = 'An existing quaternion to copy the values from.'
+    },
+    m = {
+      type = 'mat4',
+      description = 'A matrix to use the rotation from.'
+    }
+  },
+  returns = {
+    q = {
+      type = 'quat',
+      description = 'The new quaternion.'
+    }
+  },
+  variants = {
+    {
+      arguments = { 'angle', 'ax', 'ay', 'az', 'raw' },
+      returns = { 'q' }
+    },
+    {
+      arguments = { 'angle', 'axis' },
+      returns = { 'q' }
+    },
+    {
+      arguments = { 'r' },
+      returns = { 'q' }
+    },
+    {
+      description = 'Sets the values from a direction vector.',
+      arguments = { 'v' },
+      returns = { 'q' }
+    },
+    {
+      description = 'Sets the values to represent the rotation between two vectors.',
+      arguments = { 'v', 'u' },
+      returns = { 'q' }
+    },
+    {
+      arguments = { 'm' },
+      returns = { 'q' }
+    }
+  },
+  notes = 'This function takes the same arguments as `quat:set`.',
+  related = {
+    'Pool:quat',
+    'lovr.math.vec3',
+    'lovr.math.mat4'
+  }
+}

+ 47 - 0
api/lovr/math/vec3.lua

@@ -0,0 +1,47 @@
+return {
+  summary = 'Create a new `vec3`.',
+  description = 'Creates a new `vec3`.',
+  arguments = {
+    x = {
+      type = 'number',
+      default = '0',
+      description = 'The x value of the vector.'
+    },
+    y = {
+      type = 'number',
+      default = 'x',
+      description = 'The y value of the vector.'
+    },
+    z = {
+      type = 'number',
+      default = 'x',
+      description = 'The z value of the vector.'
+    },
+    u = {
+      type = 'vec3',
+      description = 'The vector to copy the values from.'
+    }
+  },
+  returns = {
+    v = {
+      type = 'vec3',
+      description = 'The new vector.'
+    }
+  },
+  variants = {
+    {
+      arguments = { 'x', 'y', 'z' },
+      returns = { 'v' }
+    },
+    {
+      arguments = { 'u' },
+      returns = { 'v' }
+    }
+  },
+  notes = 'This function takes the same arguments as `vec3:set`.',
+  related = {
+    'Pool:vec3',
+    'lovr.math.quat',
+    'lovr.math.mat4'
+  }
+}

Some files were not shown because too many files changed in this diff