bjorn 5 years ago
parent
commit
502c9567bb

+ 408 - 7
api/init.lua

@@ -17364,18 +17364,419 @@ return {
         },
         },
         {
         {
           name = "Vec4",
           name = "Vec4",
-          summary = "A 4D vector.",
-          description = "A vector object that holds four numbers.",
+          summary = "A 2D vector.",
+          description = "A vector object that holds two numbers.",
           key = "Vec4",
           key = "Vec4",
           module = "lovr.math",
           module = "lovr.math",
-          methods = {},
+          methods = {
+            {
+              name = "add",
+              summary = "Add a vector or a number to the vector.",
+              description = "Adds a vector or a number to the vector.",
+              key = "Vec4:add",
+              module = "lovr.math",
+              related = {
+                "Vec4:sub",
+                "Vec4:mul",
+                "Vec4:div"
+              },
+              variants = {
+                {
+                  arguments = {
+                    {
+                      name = "u",
+                      type = "Vec4",
+                      description = "The other vector."
+                    }
+                  },
+                  returns = {
+                    {
+                      name = "v",
+                      type = "Vec4",
+                      description = "The original vector."
+                    }
+                  }
+                },
+                {
+                  arguments = {
+                    {
+                      name = "x",
+                      type = "number",
+                      description = "A number to add to each component."
+                    }
+                  },
+                  returns = {
+                    {
+                      name = "v",
+                      type = "Vec4",
+                      description = "The original vector."
+                    }
+                  }
+                }
+              }
+            },
+            {
+              name = "distance",
+              summary = "Get the distance to another vector.",
+              description = "Returns the distance to another vector.",
+              key = "Vec4:distance",
+              module = "lovr.math",
+              related = {
+                "Vec4:length"
+              },
+              variants = {
+                {
+                  arguments = {
+                    {
+                      name = "u",
+                      type = "Vec4",
+                      description = "The vector to measure the distance to."
+                    }
+                  },
+                  returns = {
+                    {
+                      name = "distance",
+                      type = "number",
+                      description = "The distance to `u`."
+                    }
+                  }
+                }
+              }
+            },
+            {
+              name = "div",
+              summary = "Divides the vector by a vector or a number.",
+              description = "Divides the vector by a vector or a number.",
+              key = "Vec4:div",
+              module = "lovr.math",
+              related = {
+                "Vec4:add",
+                "Vec4:sub",
+                "Vec4:mul"
+              },
+              variants = {
+                {
+                  arguments = {
+                    {
+                      name = "u",
+                      type = "Vec4",
+                      description = "The other vector to divide the components by."
+                    }
+                  },
+                  returns = {
+                    {
+                      name = "v",
+                      type = "Vec4",
+                      description = "The original vector."
+                    }
+                  }
+                },
+                {
+                  arguments = {
+                    {
+                      name = "x",
+                      type = "number",
+                      description = "The number to divide each component by."
+                    }
+                  },
+                  returns = {
+                    {
+                      name = "v",
+                      type = "Vec4",
+                      description = "The original vector."
+                    }
+                  }
+                }
+              }
+            },
+            {
+              name = "dot",
+              summary = "Get the dot product with another vector.",
+              description = "Returns the dot product between this vector and another one.",
+              key = "Vec4:dot",
+              module = "lovr.math",
+              notes = "This is computed as:\n\n    dot = v.x * u.x + v.y * u.y + v.z * u.z + v.w * u.w\n\nThe vectors are not normalized before computing the dot product.",
+              variants = {
+                {
+                  arguments = {
+                    {
+                      name = "u",
+                      type = "Vec4",
+                      description = "The vector to compute the dot product with."
+                    }
+                  },
+                  returns = {
+                    {
+                      name = "dot",
+                      type = "number",
+                      description = "The dot product between `v` and `u`."
+                    }
+                  }
+                }
+              }
+            },
+            {
+              name = "length",
+              summary = "Get the length of the vector.",
+              description = "Returns the length of the vector.",
+              key = "Vec4:length",
+              module = "lovr.math",
+              related = {
+                "Vec4:normalize",
+                "Vec4:distance"
+              },
+              variants = {
+                {
+                  arguments = {},
+                  returns = {
+                    {
+                      name = "length",
+                      type = "number",
+                      description = "The length of the vector."
+                    }
+                  }
+                }
+              },
+              notes = "The length is equivalent to this:\n\n    math.sqrt(v.x * v.x + v.y * v.y * v.z + v.z + v.w * v.w)"
+            },
+            {
+              name = "lerp",
+              summary = "Moves this vector some amount towards another one.",
+              description = "Performs a linear interpolation between this vector and another one, which can be used to smoothly animate between two vectors, based on a parameter value.  A parameter value of `0` will leave the vector unchanged, a parameter value of `1` will set the vector to be equal to the input vector, and a value of `.5` will set the components to be halfway between the two vectors.",
+              key = "Vec4:lerp",
+              module = "lovr.math",
+              related = {
+                "Quat:slerp"
+              },
+              variants = {
+                {
+                  arguments = {
+                    {
+                      name = "u",
+                      type = "Vec4",
+                      description = "The vector to lerp towards."
+                    },
+                    {
+                      name = "t",
+                      type = "number",
+                      description = "The lerping parameter."
+                    }
+                  },
+                  returns = {
+                    {
+                      name = "v",
+                      type = "Vec4",
+                      description = "The original vector, containing the new lerped values."
+                    }
+                  }
+                }
+              }
+            },
+            {
+              name = "mul",
+              summary = "Multiply the vector by a vector or a number.",
+              description = "Multiplies the vector by a vector or a number.",
+              key = "Vec4:mul",
+              module = "lovr.math",
+              related = {
+                "Vec4:add",
+                "Vec4:sub",
+                "Vec4:div"
+              },
+              variants = {
+                {
+                  arguments = {
+                    {
+                      name = "u",
+                      type = "Vec4",
+                      description = "The other vector to multiply the components by."
+                    }
+                  },
+                  returns = {
+                    {
+                      name = "v",
+                      type = "Vec4",
+                      description = "The original vector."
+                    }
+                  }
+                },
+                {
+                  arguments = {
+                    {
+                      name = "x",
+                      type = "number",
+                      description = "The number to multiply each component by."
+                    }
+                  },
+                  returns = {
+                    {
+                      name = "v",
+                      type = "Vec4",
+                      description = "The original vector."
+                    }
+                  }
+                }
+              }
+            },
+            {
+              name = "normalize",
+              summary = "Normalize the length of the vector to 1.",
+              description = "Adjusts the values in the vector so that its direction stays the same but its length becomes 1.",
+              key = "Vec4:normalize",
+              module = "lovr.math",
+              related = {
+                "Vec4:length"
+              },
+              variants = {
+                {
+                  arguments = {},
+                  returns = {
+                    {
+                      name = "v",
+                      type = "Vec4",
+                      description = "The original vector."
+                    }
+                  }
+                }
+              }
+            },
+            {
+              name = "set",
+              summary = "Set the components of the vector.",
+              description = "Sets the components of the vector, either from numbers or an existing vector.",
+              key = "Vec4:set",
+              module = "lovr.math",
+              related = {
+                "Vec4:unpack"
+              },
+              variants = {
+                {
+                  arguments = {
+                    {
+                      name = "x",
+                      type = "number",
+                      description = "The new x value of the vector.",
+                      default = "0"
+                    },
+                    {
+                      name = "y",
+                      type = "number",
+                      description = "The new y value of the vector.",
+                      default = "x"
+                    }
+                  },
+                  returns = {
+                    {
+                      name = "v",
+                      type = "Vec4",
+                      description = "The input vector."
+                    }
+                  }
+                },
+                {
+                  arguments = {
+                    {
+                      name = "u",
+                      type = "Vec4",
+                      description = "The vector to copy the values from."
+                    }
+                  },
+                  returns = {
+                    {
+                      name = "v",
+                      type = "Vec4",
+                      description = "The input vector."
+                    }
+                  }
+                }
+              }
+            },
+            {
+              name = "sub",
+              summary = "Subtract a vector or a number from the vector.",
+              description = "Subtracts a vector or a number from the vector.",
+              key = "Vec4:sub",
+              module = "lovr.math",
+              related = {
+                "Vec2:add",
+                "Vec2:mul",
+                "Vec2:div"
+              },
+              variants = {
+                {
+                  arguments = {
+                    {
+                      name = "u",
+                      type = "Vec2",
+                      description = "The other vector."
+                    }
+                  },
+                  returns = {
+                    {
+                      name = "v",
+                      type = "Vec2",
+                      description = "The original vector."
+                    }
+                  }
+                },
+                {
+                  arguments = {
+                    {
+                      name = "x",
+                      type = "number",
+                      description = "A number to subtract from each component."
+                    }
+                  },
+                  returns = {
+                    {
+                      name = "v",
+                      type = "Vec2",
+                      description = "The original vector."
+                    }
+                  }
+                }
+              }
+            },
+            {
+              name = "unpack",
+              summary = "Get the components of the vector.",
+              description = "Returns the 4 components of the vector as numbers.",
+              key = "Vec4:unpack",
+              module = "lovr.math",
+              related = {
+                "Vec4:set"
+              },
+              variants = {
+                {
+                  arguments = {},
+                  returns = {
+                    {
+                      name = "x",
+                      type = "number",
+                      description = "The x value."
+                    },
+                    {
+                      name = "y",
+                      type = "number",
+                      description = "The y value."
+                    },
+                    {
+                      name = "z",
+                      type = "number",
+                      description = "The z value."
+                    }
+                  }
+                }
+              }
+            }
+          },
           constructors = {
           constructors = {
-            "lovr.math.newVec4",
-            "lovr.math.vec4"
+            "lovr.math.newVec2",
+            "lovr.math.vec2"
           },
           },
           related = {
           related = {
-            "Vec2",
-            "Vec3"
+            "Vec3",
+            "Vec4"
           }
           }
         }
         }
       }
       }

+ 35 - 0
api/lovr/math/Vec4/add.lua

@@ -0,0 +1,35 @@
+return {
+  summary = 'Add a vector or a number to the vector.',
+  description = 'Adds a vector or a number to the vector.',
+  arguments = {
+    u = {
+      type = 'Vec4',
+      description = 'The other vector.'
+    },
+    x = {
+      type = 'number',
+      description = 'A number to add to each component.'
+    }
+  },
+  returns = {
+    v = {
+      type = 'Vec4',
+      description = 'The original vector.'
+    }
+  },
+  variants = {
+    {
+      arguments = { 'u' },
+      returns = { 'v' }
+    },
+    {
+      arguments = { 'x' },
+      returns = { 'v' }
+    }
+  },
+  related = {
+    'Vec4:sub',
+    'Vec4:mul',
+    'Vec4:div'
+  }
+}

+ 21 - 0
api/lovr/math/Vec4/distance.lua

@@ -0,0 +1,21 @@
+return {
+  summary = 'Get the distance to another vector.',
+  description = 'Returns the distance to another vector.',
+  arguments = {
+    {
+      name = 'u',
+      type = 'Vec4',
+      description = 'The vector to measure the distance to.'
+    }
+  },
+  returns = {
+    {
+      name = 'distance',
+      type = 'number',
+      description = 'The distance to `u`.'
+    }
+  },
+  related = {
+    'Vec4:length'
+  }
+}

+ 35 - 0
api/lovr/math/Vec4/div.lua

@@ -0,0 +1,35 @@
+return {
+  summary = 'Divides the vector by a vector or a number.',
+  description = 'Divides the vector by a vector or a number.',
+  arguments = {
+    u = {
+      type = 'Vec4',
+      description = 'The other vector to divide the components by.'
+    },
+    x = {
+      type = 'number',
+      description = 'The number to divide each component by.'
+    }
+  },
+  returns = {
+    v = {
+      type = 'Vec4',
+      description = 'The original vector.'
+    }
+  },
+  variants = {
+    {
+      arguments = { 'u' },
+      returns = { 'v' }
+    },
+    {
+      arguments = { 'x' },
+      returns = { 'v' }
+    }
+  },
+  related = {
+    'Vec4:add',
+    'Vec4:sub',
+    'Vec4:mul'
+  }
+}

+ 25 - 0
api/lovr/math/Vec4/dot.lua

@@ -0,0 +1,25 @@
+return {
+  summary = 'Get the dot product with another vector.',
+  description = 'Returns the dot product between this vector and another one.',
+  arguments = {
+    {
+      name = 'u',
+      type = 'Vec4',
+      description = 'The vector to compute the dot product with.'
+    }
+  },
+  returns = {
+    {
+      name = 'dot',
+      type = 'number',
+      description = 'The dot product between `v` and `u`.'
+    }
+  },
+  notes = [[
+    This is computed as:
+
+        dot = v.x * u.x + v.y * u.y + v.z * u.z + v.w * u.w
+
+    The vectors are not normalized before computing the dot product.
+  ]]
+}

+ 6 - 6
api/lovr/math/Vec4/init.lua

@@ -1,12 +1,12 @@
 return {
 return {
-  summary = 'A 4D vector.',
-  description = 'A vector object that holds four numbers.',
+  summary = 'A 2D vector.',
+  description = 'A vector object that holds two numbers.',
   constructors = {
   constructors = {
-    'lovr.math.newVec4',
-    'lovr.math.vec4'
+    'lovr.math.newVec2',
+    'lovr.math.vec2'
   },
   },
   related = {
   related = {
-    'Vec2',
-    'Vec3'
+    'Vec3',
+    'Vec4'
   }
   }
 }
 }

+ 21 - 0
api/lovr/math/Vec4/length.lua

@@ -0,0 +1,21 @@
+return {
+  summary = 'Get the length of the vector.',
+  description = 'Returns the length of the vector.',
+  arguments = {},
+  returns = {
+    {
+      name = 'length',
+      type = 'number',
+      description = 'The length of the vector.'
+    }
+  },
+  notes = [[
+    The length is equivalent to this:
+
+        math.sqrt(v.x * v.x + v.y * v.y * v.z + v.z + v.w * v.w)
+  ]],
+  related = {
+    'Vec4:normalize',
+    'Vec4:distance'
+  }
+}

+ 31 - 0
api/lovr/math/Vec4/lerp.lua

@@ -0,0 +1,31 @@
+return {
+  summary = 'Moves this vector some amount towards another one.',
+  description = [[
+    Performs a linear interpolation between this vector and another one, which can be used to
+    smoothly animate between two vectors, based on a parameter value.  A parameter value of `0` will
+    leave the vector unchanged, a parameter value of `1` will set the vector to be equal to the
+    input vector, and a value of `.5` will set the components to be halfway between the two vectors.
+  ]],
+  arguments = {
+    {
+      name = 'u',
+      type = 'Vec4',
+      description = 'The vector to lerp towards.'
+    },
+    {
+      name = 't',
+      type = 'number',
+      description = 'The lerping parameter.'
+    }
+  },
+  returns = {
+    {
+      name = 'v',
+      type = 'Vec4',
+      description = 'The original vector, containing the new lerped values.'
+    }
+  },
+  related = {
+    'Quat:slerp'
+  }
+}

+ 35 - 0
api/lovr/math/Vec4/mul.lua

@@ -0,0 +1,35 @@
+return {
+  summary = 'Multiply the vector by a vector or a number.',
+  description = 'Multiplies the vector by a vector or a number.',
+  arguments = {
+    u = {
+      type = 'Vec4',
+      description = 'The other vector to multiply the components by.'
+    },
+    x = {
+      type = 'number',
+      description = 'The number to multiply each component by.'
+    }
+  },
+  returns = {
+    v = {
+      type = 'Vec4',
+      description = 'The original vector.'
+    }
+  },
+  variants = {
+    {
+      arguments = { 'u' },
+      returns = { 'v' }
+    },
+    {
+      arguments = { 'x' },
+      returns = { 'v' }
+    }
+  },
+  related = {
+    'Vec4:add',
+    'Vec4:sub',
+    'Vec4:div'
+  }
+}

+ 17 - 0
api/lovr/math/Vec4/normalize.lua

@@ -0,0 +1,17 @@
+return {
+  summary = 'Normalize the length of the vector to 1.',
+  description = [[
+    Adjusts the values in the vector so that its direction stays the same but its length becomes 1.
+  ]],
+  arguments = {},
+  returns = {
+    {
+      name = 'v',
+      type = 'Vec4',
+      description = 'The original vector.'
+    }
+  },
+  related = {
+    'Vec4:length'
+  }
+}

+ 39 - 0
api/lovr/math/Vec4/set.lua

@@ -0,0 +1,39 @@
+return {
+  summary = 'Set the components of the vector.',
+  description = 'Sets the components of the vector, either from numbers or an existing vector.',
+  arguments = {
+    x = {
+      type = 'number',
+      default = '0',
+      description = 'The new x value of the vector.'
+    },
+    y = {
+      type = 'number',
+      default = 'x',
+      description = 'The new y value of the vector.'
+    },
+    u = {
+      type = 'Vec4',
+      description = 'The vector to copy the values from.'
+    }
+  },
+  returns = {
+    v = {
+      type = 'Vec4',
+      description = 'The input vector.'
+    }
+  },
+  variants = {
+    {
+      arguments = { 'x', 'y' },
+      returns = { 'v' }
+    },
+    {
+      arguments = { 'u' },
+      returns = { 'v' }
+    }
+  },
+  related = {
+    'Vec4:unpack'
+  }
+}

+ 35 - 0
api/lovr/math/Vec4/sub.lua

@@ -0,0 +1,35 @@
+return {
+  summary = 'Subtract a vector or a number from the vector.',
+  description = 'Subtracts a vector or a number from the vector.',
+  arguments = {
+    u = {
+      type = 'Vec2',
+      description = 'The other vector.'
+    },
+    x = {
+      type = 'number',
+      description = 'A number to subtract from each component.'
+    }
+  },
+  returns = {
+    v = {
+      type = 'Vec2',
+      description = 'The original vector.'
+    }
+  },
+  variants = {
+    {
+      arguments = { 'u' },
+      returns = { 'v' }
+    },
+    {
+      arguments = { 'x' },
+      returns = { 'v' }
+    }
+  },
+  related = {
+    'Vec2:add',
+    'Vec2:mul',
+    'Vec2:div'
+  }
+}

+ 25 - 0
api/lovr/math/Vec4/unpack.lua

@@ -0,0 +1,25 @@
+return {
+  summary = 'Get the components of the vector.',
+  description = 'Returns the 4 components of the vector as numbers.',
+  arguments = {},
+  returns = {
+    {
+      name = 'x',
+      type = 'number',
+      description = 'The x value.'
+    },
+    {
+      name = 'y',
+      type = 'number',
+      description = 'The y value.'
+    },
+    {
+      name = 'z',
+      type = 'number',
+      description = 'The z value.'
+    }
+  },
+  related = {
+    'Vec4:set'
+  }
+}