bjorn 7 gadi atpakaļ
vecāks
revīzija
5f5de2ee6b
34 mainītis faili ar 1804 papildinājumiem un 84 dzēšanām
  1. 992 55
      api/init.lua
  2. 6 0
      api/lovr/callbacks/conf.lua
  3. 2 2
      api/lovr/callbacks/draw.lua
  4. 57 2
      api/lovr/graphics/Buffer/draw.lua
  5. 18 0
      api/lovr/graphics/Buffer/getVertexFormat.lua
  6. 12 0
      api/lovr/graphics/Font/getLineHeight.lua
  7. 8 0
      api/lovr/graphics/Font/init.lua
  8. 15 0
      api/lovr/graphics/Font/setLineHeight.lua
  9. 28 22
      api/lovr/graphics/Model/draw.lua
  10. 12 0
      api/lovr/graphics/cube.lua
  11. 16 0
      api/lovr/graphics/getFont.lua
  12. 38 0
      api/lovr/graphics/newFont.lua
  13. 6 0
      api/lovr/graphics/newModel.lua
  14. 78 0
      api/lovr/graphics/print.lua
  15. 2 1
      api/lovr/graphics/rotate.lua
  16. 2 1
      api/lovr/graphics/scale.lua
  17. 16 0
      api/lovr/graphics/setFont.lua
  18. 74 0
      api/lovr/graphics/transform.lua
  19. 2 1
      api/lovr/graphics/translate.lua
  20. 16 0
      api/lovr/headset/HeadsetEye.lua
  21. 32 0
      api/lovr/headset/getEyePosition.lua
  22. 21 0
      api/lovr/math/Transform/apply.lua
  23. 12 0
      api/lovr/math/Transform/clone.lua
  24. 8 0
      api/lovr/math/Transform/init.lua
  25. 18 0
      api/lovr/math/Transform/inverse.lua
  26. 41 0
      api/lovr/math/Transform/inverseTransformPoint.lua
  27. 18 0
      api/lovr/math/Transform/origin.lua
  28. 33 0
      api/lovr/math/Transform/rotate.lua
  29. 30 0
      api/lovr/math/Transform/scale.lua
  30. 56 0
      api/lovr/math/Transform/setTransformation.lua
  31. 41 0
      api/lovr/math/Transform/transformPoint.lua
  32. 28 0
      api/lovr/math/Transform/translate.lua
  33. 8 0
      api/lovr/math/init.lua
  34. 58 0
      api/lovr/math/newTransform.lua

+ 992 - 55
api/init.lua

@@ -50,6 +50,11 @@ return {
                       type = "boolean",
                       description = "Whether the headset module should be enabled."
                     },
+                    {
+                      name = "math",
+                      type = "boolean",
+                      description = "Whether the math module should be enabled."
+                    },
                     {
                       name = "timer",
                       type = "boolean",
@@ -69,7 +74,7 @@ return {
       examples = {
         {
           description = "A noop conf.lua that sets all configuration settings to their defaults:",
-          code = "function lovr.conf(t)\n  -- Set the project identity\n  t.identity = 'default'\n\n  -- Enable or disable different modules\n  t.modules.audio = true\n  t.modules.event = true\n  t.modules.graphics = true\n  t.modules.headset = true\n  t.modules.timer = true\nend"
+          code = "function lovr.conf(t)\n  -- Set the project identity\n  t.identity = 'default'\n\n  -- Enable or disable different modules\n  t.modules.audio = true\n  t.modules.event = true\n  t.modules.graphics = true\n  t.modules.headset = true\n  t.modules.math = true\n  t.modules.timer = true\nend"
         }
       },
       notes = "Disabling the `headset` module can improve startup time a lot if you aren't intending to use `lovr.headset`."
@@ -139,8 +144,8 @@ return {
           arguments = {
             {
               name = "eye",
-              type = "string",
-              description = "The eye currently being rendered to (\"left\" or \"right\")."
+              type = "HeadsetEye",
+              description = "The eye currently being rendered to."
             }
           },
           returns = {}
@@ -1926,6 +1931,36 @@ return {
                 }
               },
               returns = {}
+            },
+            {
+              arguments = {
+                {
+                  name = "mode",
+                  type = "DrawMode",
+                  description = "How to draw the cube."
+                },
+                {
+                  name = "transform",
+                  type = "Transform",
+                  description = "The cube's transform."
+                }
+              },
+              returns = {}
+            },
+            {
+              arguments = {
+                {
+                  name = "texture",
+                  type = "Texture",
+                  description = "The Texture to apply to the cube faces."
+                },
+                {
+                  name = "transform",
+                  type = "Transform",
+                  description = "The cube's transform."
+                }
+              },
+              returns = {}
             }
           }
         },
@@ -2087,6 +2122,29 @@ return {
             }
           }
         },
+        {
+          name = "getFont",
+          tag = "graphicsState",
+          summary = "Get the active font.",
+          description = "Returns the active font.",
+          key = "lovr.graphics.getFont",
+          module = "lovr.graphics",
+          related = {
+            "lovr.graphics.print"
+          },
+          variants = {
+            {
+              arguments = {},
+              returns = {
+                {
+                  name = "font",
+                  type = "Font",
+                  description = "The active font object."
+                }
+              }
+            }
+          }
+        },
         {
           name = "getHeight",
           tag = "window",
@@ -2499,6 +2557,57 @@ return {
             }
           }
         },
+        {
+          name = "newFont",
+          tag = "graphicsObjects",
+          summary = "Create a new Font.",
+          description = "Creates a new Font.  It can be used to render text with `lovr.graphics.print`.\n\nCurrently, the only supported font format is TTF.",
+          key = "lovr.graphics.newFont",
+          module = "lovr.graphics",
+          notes = "Larger font sizes will lead to sharper text at the cost of performance.",
+          variants = {
+            {
+              arguments = {
+                {
+                  name = "filename",
+                  type = "string",
+                  description = "The filename of the font file."
+                },
+                {
+                  name = "size",
+                  type = "number",
+                  description = "The size of the font, in pixels.",
+                  default = "32"
+                }
+              },
+              returns = {
+                {
+                  name = "font",
+                  type = "Font",
+                  description = "The new Font."
+                }
+              }
+            },
+            {
+              description = "Creates a new Font from the default font included with LÖVR (Cabin).",
+              arguments = {
+                {
+                  name = "size",
+                  type = "number",
+                  description = "The size of the font, in pixels.",
+                  default = "32"
+                }
+              },
+              returns = {
+                {
+                  name = "font",
+                  type = "Font",
+                  description = "The new Font."
+                }
+              }
+            }
+          }
+        },
         {
           name = "newModel",
           tag = "graphicsObjects",
@@ -2513,6 +2622,12 @@ return {
                   name = "filename",
                   type = "string",
                   description = "The filename of the model to load."
+                },
+                {
+                  name = "texture",
+                  type = "string",
+                  description = "A filename for a texture to apply to the Model, or `nil` for no texture.",
+                  default = "nil"
                 }
               },
               returns = {
@@ -2899,6 +3014,87 @@ return {
             }
           }
         },
+        {
+          name = "print",
+          tag = "graphicsPrimitives",
+          summary = "Render text.",
+          description = "Draws text in 3D space using the active font.",
+          key = "lovr.graphics.print",
+          module = "lovr.graphics",
+          variants = {
+            {
+              arguments = {
+                {
+                  name = "str",
+                  type = "string",
+                  description = "The text to render."
+                },
+                {
+                  name = "x",
+                  type = "number",
+                  description = "The x coordinate of the center of the text.",
+                  default = 0
+                },
+                {
+                  name = "y",
+                  type = "number",
+                  description = "The y coordinate of the center of the text.",
+                  default = 0
+                },
+                {
+                  name = "z",
+                  type = "number",
+                  description = "The z coordinate of the center of the text.",
+                  default = 0
+                },
+                {
+                  name = "w",
+                  type = "number",
+                  description = "The maximum width of each line, in meters.  Use zero for unlimited.",
+                  default = 0
+                },
+                {
+                  name = "h",
+                  type = "number",
+                  description = "The height of each line, in meters.",
+                  default = 0.10000000000000001
+                },
+                {
+                  name = "angle",
+                  type = "number",
+                  description = "The number of radians to rotate the text around its rotation axis.",
+                  default = 0
+                },
+                {
+                  name = "ax",
+                  type = "number",
+                  description = "The x component of the axis of rotation.",
+                  default = 0
+                },
+                {
+                  name = "ay",
+                  type = "number",
+                  description = "The y component of the axis of rotation.",
+                  default = 1
+                },
+                {
+                  name = "az",
+                  type = "number",
+                  description = "The z component of the axis of rotation.",
+                  default = 0
+                }
+              },
+              returns = {}
+            }
+          },
+          related = {
+            "lovr.graphics.getFont",
+            "lovr.graphics.setFont",
+            "lovr.graphics.newFont",
+            "Font"
+          },
+          notes = "Unicode text is supported.\n\nUse `\\n` to add line breaks."
+        },
         {
           name = "push",
           tag = "graphicsTransforms",
@@ -2967,7 +3163,8 @@ return {
           },
           related = {
             "lovr.graphics.scale",
-            "lovr.graphics.translate"
+            "lovr.graphics.translate",
+            "lovr.graphics.transform"
           },
           notes = "Order matters when scaling, translating, and rotating the coordinate system."
         },
@@ -3002,7 +3199,8 @@ return {
           },
           related = {
             "lovr.graphics.rotate",
-            "lovr.graphics.translate"
+            "lovr.graphics.translate",
+            "lovr.graphics.transform"
           },
           notes = "Order matters when scaling, translating, and rotating the coordinate system."
         },
@@ -3194,6 +3392,29 @@ return {
             }
           }
         },
+        {
+          name = "setFont",
+          tag = "graphicsState",
+          summary = "Set the active font.",
+          description = "Sets the active font used to render text with `lovr.graphics.print`.",
+          key = "lovr.graphics.setFont",
+          module = "lovr.graphics",
+          related = {
+            "lovr.graphics.print"
+          },
+          variants = {
+            {
+              arguments = {
+                {
+                  name = "font",
+                  type = "Font",
+                  description = "The font to use."
+                }
+              },
+              returns = {}
+            }
+          }
+        },
         {
           name = "setLineWidth",
           tag = "graphicsState",
@@ -3378,6 +3599,85 @@ return {
           },
           notes = "Wireframe rendering is initially disabled."
         },
+        {
+          name = "transform",
+          tag = "graphicsTransforms",
+          summary = "Apply a general transform to the coordinate system.",
+          description = "Apply a transform to the coordinate system, changing its translation, rotation, and scale using a single function.  A Transform object can also be used.\n\nThe transformation will last until `lovr.draw` returns or the transformation is popped off the transformation stack.",
+          key = "lovr.graphics.transform",
+          module = "lovr.graphics",
+          related = {
+            "lovr.graphics.rotate",
+            "lovr.graphics.scale",
+            "lovr.graphics.translate"
+          },
+          variants = {
+            {
+              arguments = {
+                {
+                  name = "x",
+                  type = "number",
+                  description = "The x component of the translation.",
+                  default = 0
+                },
+                {
+                  name = "y",
+                  type = "number",
+                  description = "The y component of the translation.",
+                  default = 0
+                },
+                {
+                  name = "z",
+                  type = "number",
+                  description = "The z component of the translation.",
+                  default = 0
+                },
+                {
+                  name = "scale",
+                  type = "number",
+                  description = "The scale factor.",
+                  default = 1
+                },
+                {
+                  name = "angle",
+                  type = "number",
+                  description = "The number of radians to rotate around the rotation axis.",
+                  default = 0
+                },
+                {
+                  name = "ax",
+                  type = "number",
+                  description = "The x component of the axis of rotation.",
+                  default = 0
+                },
+                {
+                  name = "ay",
+                  type = "number",
+                  description = "The y component of the axis of rotation.",
+                  default = 1
+                },
+                {
+                  name = "az",
+                  type = "number",
+                  description = "The z component of the axis of rotation.",
+                  default = 0
+                }
+              },
+              returns = {}
+            },
+            {
+              description = "Modify the coordinate system using a Transform object.",
+              arguments = {
+                {
+                  name = "transform",
+                  type = "Transform",
+                  description = "The Transform to apply to the coordinate system."
+                }
+              },
+              returns = {}
+            }
+          }
+        },
         {
           name = "translate",
           tag = "graphicsTransforms",
@@ -3409,7 +3709,8 @@ return {
           },
           related = {
             "lovr.graphics.rotate",
-            "lovr.graphics.scale"
+            "lovr.graphics.scale",
+            "lovr.graphics.transform"
           },
           notes = "Order matters when scaling, translating, and rotating the coordinate system."
         },
@@ -3500,56 +3801,115 @@ return {
               module = "lovr.graphics",
               variants = {
                 {
-                  arguments = {},
-                  returns = {}
-                }
-              }
-            },
-            {
-              name = "getDrawMode",
-              summary = "Get the draw mode of the Buffer.",
-              description = "Get the draw mode of the Buffer, which controls how the vertices are connected together.",
-              key = "Buffer:getDrawMode",
-              module = "lovr.graphics",
-              variants = {
-                {
-                  arguments = {},
-                  returns = {
+                  arguments = {
                     {
-                      name = "mode",
-                      type = "BufferDrawMode",
-                      description = "The draw mode of the buffer."
-                    }
-                  }
-                }
-              }
-            },
-            {
-              name = "getDrawRange",
-              summary = "Get the draw range of the Buffer.",
-              description = "Retrieve the current draw range for the buffer.  The draw range is a subset of the vertices of the buffer that will be drawn.",
-              key = "Buffer:getDrawRange",
-              module = "lovr.graphics",
-              variants = {
-                {
-                  arguments = {},
-                  returns = {
+                      name = "x",
+                      type = "number",
+                      description = "The x coordinate to draw the Buffer at.",
+                      default = "0"
+                    },
                     {
-                      name = "start",
+                      name = "y",
                       type = "number",
-                      description = "The index of the first vertex that will be drawn, or `nil` if no draw range is set."
+                      description = "The y coordinate to draw the Buffer at.",
+                      default = "0"
                     },
                     {
-                      name = "count",
+                      name = "z",
                       type = "number",
-                      description = "The number of vertices that will be drawn, or `nil` if no draw range is set."
-                    }
-                  }
-                }
-              }
-            },
-            {
-              name = "getTexture",
+                      description = "The z coordinate to draw the Buffer at.",
+                      default = "0"
+                    },
+                    {
+                      name = "scale",
+                      type = "number",
+                      description = "The scale to draw the Buffer at.",
+                      default = "1"
+                    },
+                    {
+                      name = "angle",
+                      type = "number",
+                      description = "The angle to rotate the Buffer around its axis of rotation.",
+                      default = "0"
+                    },
+                    {
+                      name = "ax",
+                      type = "number",
+                      description = "The x component of the axis of rotation.",
+                      default = "0"
+                    },
+                    {
+                      name = "ay",
+                      type = "number",
+                      description = "The y component of the axis of rotation.",
+                      default = "1"
+                    },
+                    {
+                      name = "az",
+                      type = "number",
+                      description = "The z component of the axis of rotation.",
+                      default = "0"
+                    }
+                  },
+                  returns = {}
+                },
+                {
+                  arguments = {
+                    {
+                      name = "transform",
+                      type = "Transform",
+                      description = "The transform to apply before drawing."
+                    }
+                  },
+                  returns = {}
+                }
+              }
+            },
+            {
+              name = "getDrawMode",
+              summary = "Get the draw mode of the Buffer.",
+              description = "Get the draw mode of the Buffer, which controls how the vertices are connected together.",
+              key = "Buffer:getDrawMode",
+              module = "lovr.graphics",
+              variants = {
+                {
+                  arguments = {},
+                  returns = {
+                    {
+                      name = "mode",
+                      type = "BufferDrawMode",
+                      description = "The draw mode of the buffer."
+                    }
+                  }
+                }
+              }
+            },
+            {
+              name = "getDrawRange",
+              summary = "Get the draw range of the Buffer.",
+              description = "Retrieve the current draw range for the buffer.  The draw range is a subset of the vertices of the buffer that will be drawn.",
+              key = "Buffer:getDrawRange",
+              module = "lovr.graphics",
+              variants = {
+                {
+                  arguments = {},
+                  returns = {
+                    {
+                      name = "start",
+                      type = "number",
+                      description = "The index of the first vertex that will be drawn, or `nil` if no draw range is set."
+                    },
+                    {
+                      name = "count",
+                      type = "number",
+                      description = "The number of vertices that will be drawn, or `nil` if no draw range is set."
+                    }
+                  }
+                }
+              }
+            },
+            {
+              name = "getTexture",
               summary = "Get the Texture applied to the Buffer.",
               description = "Get the Texture applied to the Buffer.",
               key = "Buffer:getTexture",
@@ -3643,6 +4003,25 @@ return {
                 }
               }
             },
+            {
+              name = "getVertexFormat",
+              summary = "Get the vertex format of the Buffer.",
+              description = "Get the format table of the Buffer's vertices.  The format table describes the set of data that each vertex contains.",
+              key = "Buffer:getVertexFormat",
+              module = "lovr.graphics",
+              variants = {
+                {
+                  arguments = {},
+                  returns = {
+                    {
+                      name = "format",
+                      type = "table",
+                      description = "The table of vertex attributes.  Each attribute is a table containing the name of the attribute, the data type, and the number of components."
+                    }
+                  }
+                }
+              }
+            },
             {
               name = "getVertexMap",
               summary = "Get the current vertex map of the Buffer.",
@@ -3847,6 +4226,56 @@ return {
             }
           }
         },
+        {
+          name = "Font",
+          summary = "A loaded font used to render text.",
+          description = "A Font is an object created from a TTF file.  It can be used to render text with `lovr.graphics.print`.",
+          key = "Font",
+          module = "lovr.graphics",
+          methods = {
+            {
+              name = "getLineHeight",
+              summary = "Get the line height of the Font.",
+              description = "Returns the current line height of the Font.  The default is 1.0.",
+              key = "Font:getLineHeight",
+              module = "lovr.graphics",
+              variants = {
+                {
+                  arguments = {},
+                  returns = {
+                    {
+                      name = "lineHeight",
+                      type = "number",
+                      description = "The line height."
+                    }
+                  }
+                }
+              }
+            },
+            {
+              name = "setLineHeight",
+              summary = "Set the line height of the Font.",
+              description = "Sets the line height of the Font, which controls how far lines apart lines are vertically separated.  This value is a ratio and the default is 1.0.",
+              key = "Font:setLineHeight",
+              module = "lovr.graphics",
+              variants = {
+                {
+                  arguments = {
+                    {
+                      name = "lineHeight",
+                      type = "number",
+                      description = "The new line height."
+                    }
+                  },
+                  returns = {}
+                }
+              }
+            }
+          },
+          constructors = {
+            "lovr.graphics.newFont"
+          }
+        },
         {
           name = "Model",
           summary = "An asset imported from a 3D model file.",
@@ -3875,31 +4304,31 @@ return {
                     {
                       name = "x",
                       type = "number",
-                      description = "The x coordinate to draw the model at.",
+                      description = "The x coordinate to draw the Model at.",
                       default = "0"
                     },
                     {
                       name = "y",
                       type = "number",
-                      description = "The y coordinate to draw the model at.",
+                      description = "The y coordinate to draw the Model at.",
                       default = "0"
                     },
                     {
                       name = "z",
                       type = "number",
-                      description = "The z coordinate to draw the model at.",
+                      description = "The z coordinate to draw the Model at.",
                       default = "0"
                     },
                     {
                       name = "scale",
                       type = "number",
-                      description = "The scale to draw the model at.",
+                      description = "The scale to draw the Model at.",
                       default = "1"
                     },
                     {
                       name = "angle",
                       type = "number",
-                      description = "The angle to rotate the model around its axis of rotation.",
+                      description = "The angle to rotate the Model around its axis of rotation.",
                       default = "0"
                     },
                     {
@@ -3922,6 +4351,16 @@ return {
                     }
                   },
                   returns = {}
+                },
+                {
+                  arguments = {
+                    {
+                      name = "transform",
+                      type = "Transform",
+                      description = "The transform to apply before drawing."
+                    }
+                  },
+                  returns = {}
                 }
               }
             },
@@ -4330,6 +4769,23 @@ return {
               description = "The button on the touchpad."
             }
           }
+        },
+        {
+          name = "HeadsetEye",
+          summary = "The two different eyes.",
+          description = "Represents either the left eye or the right eye.",
+          key = "HeadsetEye",
+          module = "headset",
+          values = {
+            {
+              name = "left",
+              description = "The left eye."
+            },
+            {
+              name = "right",
+              description = "The right eye."
+            }
+          }
         }
       },
       functions = {
@@ -4613,6 +5069,45 @@ return {
             }
           }
         },
+        {
+          name = "getEyePosition",
+          tag = "headset",
+          summary = "Get the position of an eye.",
+          description = "Returns the current position of one of the eyes in 3D space.",
+          key = "lovr.headset.getEyePosition",
+          module = "lovr.headset",
+          related = {
+            "lovr.headset.getPosition"
+          },
+          variants = {
+            {
+              arguments = {
+                {
+                  name = "eye",
+                  type = "HeadsetEye",
+                  description = "The eye to get the position of."
+                }
+              },
+              returns = {
+                {
+                  name = "x",
+                  type = "number",
+                  description = "The x position of the eye."
+                },
+                {
+                  name = "y",
+                  type = "number",
+                  description = "The y position of the eye."
+                },
+                {
+                  name = "z",
+                  type = "number",
+                  description = "The z position of the eye."
+                }
+              }
+            }
+          }
+        },
         {
           name = "getOrientation",
           tag = "headset",
@@ -5067,6 +5562,448 @@ return {
         }
       }
     },
+    {
+      name = "math",
+      tag = "modules",
+      summary = "Contains useful math helpers.",
+      description = "The `lovr.math` module provides math helpers commonly used for 3D applications.  Currently, only `Transform` objects are exposed.",
+      key = "lovr.math",
+      functions = {
+        {
+          name = "newTransform",
+          summary = "Create a new Transform.",
+          description = "A transform is a 4x4, column major matrix that can be used to represent the 3D transform of an object.  Most graphics primitives accept a Transform instead of the usual coordinate arguments. Transforms provide a convenient way to represent translation, rotation, and scale in a single object.",
+          key = "lovr.math.newTransform",
+          module = "lovr.math",
+          variants = {
+            {
+              arguments = {
+                {
+                  name = "x",
+                  type = "number",
+                  description = "The x position of the Transform."
+                },
+                {
+                  name = "y",
+                  type = "number",
+                  description = "The x position of the Transform."
+                },
+                {
+                  name = "z",
+                  type = "number",
+                  description = "The x position of the Transform."
+                },
+                {
+                  name = "scale",
+                  type = "number",
+                  description = "The scale of the Transform."
+                },
+                {
+                  name = "angle",
+                  type = "number",
+                  description = "The number of radians the Transform is rotated around its axis of rotation."
+                },
+                {
+                  name = "ax",
+                  type = "number",
+                  description = "The x component of the axis of rotation."
+                },
+                {
+                  name = "ay",
+                  type = "number",
+                  description = "The y component of the axis of rotation."
+                },
+                {
+                  name = "az",
+                  type = "number",
+                  description = "The z component of the axis of rotation."
+                }
+              },
+              returns = {
+                {
+                  name = "transform",
+                  type = "Transform",
+                  description = "The new Transform."
+                }
+              }
+            }
+          }
+        }
+      },
+      enums = {},
+      objects = {
+        {
+          name = "Transform",
+          summary = "A 3D transform.",
+          description = "A Transform represents a translation, rotation, and scale in 3D space.  They're commonly used to describe how entities are arranged in a scene or how a camera is positioned.",
+          key = "Transform",
+          module = "lovr.math",
+          methods = {
+            {
+              name = "apply",
+              summary = "Combine two Transforms.",
+              description = "Applies a Transform onto this Transform.",
+              key = "Transform:apply",
+              module = "lovr.math",
+              variants = {
+                {
+                  arguments = {
+                    {
+                      name = "other",
+                      type = "Transform",
+                      description = "Combine two Transforms together.  Order matters, so applying Transforms in different orders will yield different results."
+                    }
+                  },
+                  returns = {
+                    {
+                      name = "transform",
+                      type = "Transform",
+                      description = "The original Transform."
+                    }
+                  }
+                }
+              }
+            },
+            {
+              name = "clone",
+              summary = "Clone the Transform.",
+              description = "Returns a copy of the Transform.",
+              key = "Transform:clone",
+              module = "lovr.math",
+              variants = {
+                {
+                  arguments = {},
+                  returns = {
+                    {
+                      name = "copy",
+                      type = "Transform",
+                      description = "The copy of the original."
+                    }
+                  }
+                }
+              }
+            },
+            {
+              name = "inverse",
+              summary = "Get the inverse of the Transform.",
+              description = "Returns a new Transform representing the inverse of the original.  The inverse \"cancels out\" the effects of the original, so applying one onto the other will result in the origin.",
+              key = "Transform:inverse",
+              module = "lovr.math",
+              related = {
+                "Transform:inverseTransformPoint"
+              },
+              variants = {
+                {
+                  arguments = {},
+                  returns = {
+                    {
+                      name = "inverse",
+                      type = "Transform",
+                      description = "The inverse transform."
+                    }
+                  }
+                }
+              }
+            },
+            {
+              name = "inverseTransformPoint",
+              summary = "Apply the inverse of the Transform to a point.",
+              description = "Applies the inverse of the Transform to a point, returning the transformed point.",
+              key = "Transform:inverseTransformPoint",
+              module = "lovr.math",
+              related = {
+                "Transform:transformPoint"
+              },
+              variants = {
+                {
+                  arguments = {
+                    {
+                      name = "x",
+                      type = "number",
+                      description = "The x coordinate of the point."
+                    },
+                    {
+                      name = "y",
+                      type = "number",
+                      description = "The y coordinate of the point."
+                    },
+                    {
+                      name = "z",
+                      type = "number",
+                      description = "The z coordinate of the point."
+                    }
+                  },
+                  returns = {
+                    {
+                      name = "x2",
+                      type = "number",
+                      description = "The x coordinate of the transformed point."
+                    },
+                    {
+                      name = "y2",
+                      type = "number",
+                      description = "The y coordinate of the transformed point."
+                    },
+                    {
+                      name = "z2",
+                      type = "number",
+                      description = "The z coordinate of the transformed point."
+                    }
+                  }
+                }
+              }
+            },
+            {
+              name = "origin",
+              summary = "Reset the Transform.",
+              description = "Resets the Transform to the origin.",
+              key = "Transform:origin",
+              module = "lovr.math",
+              variants = {
+                {
+                  arguments = {},
+                  returns = {
+                    {
+                      name = "transform",
+                      type = "Transform",
+                      description = "The original Transform."
+                    }
+                  }
+                }
+              },
+              examples = {
+                {
+                  code = "transform = lovr.math.newTransform(3, 4, 5)\nprint(transform:transformPoint(1, 2, 2)) -- Prints 4, 6, 7\ntransform:origin()\nprint(transform:transformPoint(1, 2, 3)) -- Prints 1, 2, 3"
+                }
+              }
+            },
+            {
+              name = "rotate",
+              summary = "Rotate the Transform.",
+              description = "Rotates the Transform using an angle/axis rotation.",
+              key = "Transform:rotate",
+              module = "lovr.math",
+              variants = {
+                {
+                  arguments = {
+                    {
+                      name = "angle",
+                      type = "number",
+                      description = "The number of radians to rotate around the axis of rotation."
+                    },
+                    {
+                      name = "ax",
+                      type = "number",
+                      description = "The x component of the axis of rotation."
+                    },
+                    {
+                      name = "ay",
+                      type = "number",
+                      description = "The y component of the axis of rotation."
+                    },
+                    {
+                      name = "az",
+                      type = "number",
+                      description = "The z component of the axis of rotation."
+                    }
+                  },
+                  returns = {
+                    {
+                      name = "transform",
+                      type = "Transform",
+                      description = "The original Transform."
+                    }
+                  }
+                }
+              }
+            },
+            {
+              name = "scale",
+              summary = "Scale the Transform.",
+              description = "Scales the Transform.",
+              key = "Transform:scale",
+              module = "lovr.math",
+              variants = {
+                {
+                  arguments = {
+                    {
+                      name = "x",
+                      type = "number",
+                      description = "The scale factor for the x axis."
+                    },
+                    {
+                      name = "y",
+                      type = "number",
+                      description = "The scale factor for the y axis.",
+                      default = "x"
+                    },
+                    {
+                      name = "z",
+                      type = "number",
+                      description = "The scale factor for the z axis.",
+                      default = "x"
+                    }
+                  },
+                  returns = {
+                    {
+                      name = "transform",
+                      type = "Transform",
+                      description = "The original Transform."
+                    }
+                  }
+                }
+              }
+            },
+            {
+              name = "setTransformation",
+              summary = "Set the position, rotation, and scale of the Transform.",
+              description = "Sets the translation, rotation, and scale of the Transform.  This will override the current values in the Transform.",
+              key = "Transform:setTransformation",
+              module = "lovr.math",
+              variants = {
+                {
+                  arguments = {
+                    {
+                      name = "x",
+                      type = "number",
+                      description = "The x position of the Transform."
+                    },
+                    {
+                      name = "y",
+                      type = "number",
+                      description = "The x position of the Transform."
+                    },
+                    {
+                      name = "z",
+                      type = "number",
+                      description = "The x position of the Transform."
+                    },
+                    {
+                      name = "scale",
+                      type = "number",
+                      description = "The scale of the Transform."
+                    },
+                    {
+                      name = "angle",
+                      type = "number",
+                      description = "The number of radians the Transform is rotated around its axis of rotation."
+                    },
+                    {
+                      name = "ax",
+                      type = "number",
+                      description = "The x component of the axis of rotation."
+                    },
+                    {
+                      name = "ay",
+                      type = "number",
+                      description = "The y component of the axis of rotation."
+                    },
+                    {
+                      name = "az",
+                      type = "number",
+                      description = "The z component of the axis of rotation."
+                    }
+                  },
+                  returns = {
+                    {
+                      name = "transform",
+                      type = "Transform",
+                      description = "The original Transform."
+                    }
+                  }
+                }
+              }
+            },
+            {
+              name = "transformPoint",
+              summary = "Apply the Transform to a point.",
+              description = "Applies the Transform to a point, returning the new position.",
+              key = "Transform:transformPoint",
+              module = "lovr.math",
+              related = {
+                "Transform:inverseTransformPoint"
+              },
+              variants = {
+                {
+                  arguments = {
+                    {
+                      name = "x",
+                      type = "number",
+                      description = "The x coordinate of the point."
+                    },
+                    {
+                      name = "y",
+                      type = "number",
+                      description = "The y coordinate of the point."
+                    },
+                    {
+                      name = "z",
+                      type = "number",
+                      description = "The z coordinate of the point."
+                    }
+                  },
+                  returns = {
+                    {
+                      name = "x2",
+                      type = "number",
+                      description = "The x coordinate of the transformed point."
+                    },
+                    {
+                      name = "y2",
+                      type = "number",
+                      description = "The y coordinate of the transformed point."
+                    },
+                    {
+                      name = "z2",
+                      type = "number",
+                      description = "The z coordinate of the transformed point."
+                    }
+                  }
+                }
+              }
+            },
+            {
+              name = "translate",
+              summary = "Translate the Transform.",
+              description = "Translates the Transform.",
+              key = "Transform:translate",
+              module = "lovr.math",
+              variants = {
+                {
+                  arguments = {
+                    {
+                      name = "x",
+                      type = "number",
+                      description = "The x component of the translation."
+                    },
+                    {
+                      name = "y",
+                      type = "number",
+                      description = "The y component of the translation."
+                    },
+                    {
+                      name = "z",
+                      type = "number",
+                      description = "The z component of the translation."
+                    }
+                  },
+                  returns = {
+                    {
+                      name = "transform",
+                      type = "Transform",
+                      description = "The original Transform."
+                    }
+                  }
+                }
+              }
+            }
+          },
+          constructors = {
+            "lovr.math.newTransform"
+          }
+        }
+      }
+    },
     {
       name = "timer",
       tag = "modules",

+ 6 - 0
api/lovr/callbacks/conf.lua

@@ -47,6 +47,11 @@ return {
               type = 'boolean',
               description = 'Whether the headset module should be enabled.'
             },
+            {
+              name = 'math',
+              type = 'boolean',
+              description = 'Whether the math module should be enabled.'
+            },
             {
               name = 'timer',
               type = 'boolean',
@@ -74,6 +79,7 @@ return {
           t.modules.event = true
           t.modules.graphics = true
           t.modules.headset = true
+          t.modules.math = true
           t.modules.timer = true
         end
     ]]

+ 2 - 2
api/lovr/callbacks/draw.lua

@@ -9,8 +9,8 @@ return {
   arguments = {
     {
       name = 'eye',
-      type = 'string',
-      description = 'The eye currently being rendered to ("left" or "right").'
+      type = 'HeadsetEye',
+      description = 'The eye currently being rendered to.'
     }
   },
   returns = {},

+ 57 - 2
api/lovr/graphics/Buffer/draw.lua

@@ -1,6 +1,61 @@
 return {
   summary = 'Draw the Buffer.',
   description = 'Draws the contents of the Buffer.',
-  arguments = {},
-  returns = {}
+  arguments = {
+    x = {
+      type = 'number',
+      default = '0',
+      description = 'The x coordinate to draw the Buffer at.'
+    },
+    y = {
+      type = 'number',
+      default = '0',
+      description = 'The y coordinate to draw the Buffer at.'
+    },
+    z = {
+      type = 'number',
+      default = '0',
+      description = 'The z coordinate to draw the Buffer at.'
+    },
+    scale = {
+      type = 'number',
+      default = '1',
+      description = 'The scale to draw the Buffer at.'
+    },
+    angle = {
+      type = 'number',
+      default = '0',
+      description = 'The angle to rotate the Buffer around its axis of rotation.'
+    },
+    ax = {
+      type = 'number',
+      default = '0',
+      description = 'The x component of the axis of rotation.'
+    },
+    ay = {
+      type = 'number',
+      default = '1',
+      description = 'The y component of the axis of rotation.'
+    },
+    az = {
+      type = 'number',
+      default = '0',
+      description = 'The z component of the axis of rotation.'
+    },
+    transform = {
+      type = 'Transform',
+      description = 'The transform to apply before drawing.'
+    }
+  },
+  returns = {},
+  variants = {
+    {
+      arguments = { 'x', 'y', 'z', 'scale', 'angle', 'ax', 'ay', 'az' },
+      returns = {}
+    },
+    {
+      arguments = { 'transform' },
+      returns = {}
+    }
+  }
 }

+ 18 - 0
api/lovr/graphics/Buffer/getVertexFormat.lua

@@ -0,0 +1,18 @@
+return {
+  summary = 'Get the vertex format of the Buffer.',
+  description = [[
+    Get the format table of the Buffer's vertices.  The format table describes the set of data that
+    each vertex contains.
+  ]],
+  arguments = {},
+  returns = {
+    {
+      name = 'format',
+      type = 'table',
+      description = [[
+        The table of vertex attributes.  Each attribute is a table containing the name of the
+        attribute, the data type, and the number of components.
+      ]]
+    }
+  }
+}

+ 12 - 0
api/lovr/graphics/Font/getLineHeight.lua

@@ -0,0 +1,12 @@
+return {
+  summary = 'Get the line height of the Font.',
+  description = 'Returns the current line height of the Font.  The default is 1.0.',
+  arguments = {},
+  returns = {
+    {
+      name = 'lineHeight',
+      type = 'number',
+      description = 'The line height.'
+    }
+  }
+}

+ 8 - 0
api/lovr/graphics/Font/init.lua

@@ -0,0 +1,8 @@
+return {
+  summary = 'A loaded font used to render text.',
+  description = [[
+    A Font is an object created from a TTF file.  It can be used to render text with
+    `lovr.graphics.print`.
+  ]],
+  constructor = 'lovr.graphics.newFont'
+}

+ 15 - 0
api/lovr/graphics/Font/setLineHeight.lua

@@ -0,0 +1,15 @@
+return {
+  summary = 'Set the line height of the Font.',
+  description = [[
+    Sets the line height of the Font, which controls how far lines apart lines are vertically
+    separated.  This value is a ratio and the default is 1.0.
+  ]],
+  arguments = {
+    {
+      name = 'lineHeight',
+      type = 'number',
+      description = 'The new line height.'
+    }
+  },
+  returns = {}
+}

+ 28 - 22
api/lovr/graphics/Model/draw.lua

@@ -2,54 +2,60 @@ return {
   summary = 'Draw the Model.',
   description = 'Draw the Model.',
   arguments = {
-    {
-      name = 'x',
+    x = {
       type = 'number',
       default = '0',
-      description = 'The x coordinate to draw the model at.'
+      description = 'The x coordinate to draw the Model at.'
     },
-    {
-      name = 'y',
+    y = {
       type = 'number',
       default = '0',
-      description = 'The y coordinate to draw the model at.'
+      description = 'The y coordinate to draw the Model at.'
     },
-    {
-      name = 'z',
+    z = {
       type = 'number',
       default = '0',
-      description = 'The z coordinate to draw the model at.'
+      description = 'The z coordinate to draw the Model at.'
     },
-    {
-      name = 'scale',
+    scale = {
       type = 'number',
       default = '1',
-      description = 'The scale to draw the model at.'
+      description = 'The scale to draw the Model at.'
     },
-    {
-      name = 'angle',
+    angle = {
       type = 'number',
       default = '0',
-      description = 'The angle to rotate the model around its axis of rotation.'
+      description = 'The angle to rotate the Model around its axis of rotation.'
     },
-    {
-      name = 'ax',
+    ax = {
       type = 'number',
       default = '0',
       description = 'The x component of the axis of rotation.'
     },
-    {
-      name = 'ay',
+    ay = {
       type = 'number',
       default = '1',
       description = 'The y component of the axis of rotation.'
     },
-    {
-      name = 'az',
+    az = {
       type = 'number',
       default = '0',
       description = 'The z component of the axis of rotation.'
+    },
+    transform = {
+      type = 'Transform',
+      description = 'The transform to apply before drawing.'
     }
   },
-  returns = {}
+  returns = {},
+  variants = {
+    {
+      arguments = { 'x', 'y', 'z', 'scale', 'angle', 'ax', 'ay', 'az' },
+      returns = {}
+    },
+    {
+      arguments = { 'transform' },
+      returns = {}
+    }
+  }
 }

+ 12 - 0
api/lovr/graphics/cube.lua

@@ -11,6 +11,10 @@ return {
       type = 'DrawMode',
       description = 'How to draw the cube.'
     },
+    transform = {
+      type = 'Transform',
+      description = 'The cube\'s transform.'
+    },
     x = {
       type = 'number',
       default = '0',
@@ -61,6 +65,14 @@ return {
     {
       arguments = { 'texture', 'x', 'y', 'z', 'size', 'angle', 'ax', 'ay', 'az' },
       returns = {}
+    },
+    {
+      arguments = { 'mode', 'transform' },
+      returns = {}
+    },
+    {
+      arguments = { 'texture', 'transform' },
+      returns = {}
     }
   }
 }

+ 16 - 0
api/lovr/graphics/getFont.lua

@@ -0,0 +1,16 @@
+return {
+  tag = 'graphicsState',
+  summary = 'Get the active font.',
+  description = 'Returns the active font.',
+  arguments = {},
+  returns = {
+    {
+      name = 'font',
+      type = 'Font',
+      description = 'The active font object.'
+    }
+  },
+  related = {
+    'lovr.graphics.print'
+  }
+}

+ 38 - 0
api/lovr/graphics/newFont.lua

@@ -0,0 +1,38 @@
+return {
+  tag = 'graphicsObjects',
+  summary = 'Create a new Font.',
+  description = [[
+    Creates a new Font.  It can be used to render text with `lovr.graphics.print`.
+
+    Currently, the only supported font format is TTF.
+  ]],
+  arguments = {
+    filename = {
+      type = 'string',
+      description = 'The filename of the font file.'
+    },
+    size = {
+      type = 'number',
+      default = '32',
+      description = 'The size of the font, in pixels.'
+    }
+  },
+  returns = {
+    font = {
+      type = 'Font',
+      description = 'The new Font.'
+    }
+  },
+  variants = {
+    {
+      arguments = { 'filename', 'size' },
+      returns = { 'font' }
+    },
+    {
+      description = 'Creates a new Font from the default font included with LÖVR (Cabin).',
+      arguments = { 'size' },
+      returns = { 'font' }
+    }
+  },
+  notes = 'Larger font sizes will lead to sharper text at the cost of performance.'
+}

+ 6 - 0
api/lovr/graphics/newModel.lua

@@ -13,6 +13,12 @@ return {
       name = 'filename',
       type = 'string',
       description = 'The filename of the model to load.'
+    },
+    {
+      name = 'texture',
+      type = 'string',
+      default = 'nil',
+      description = 'A filename for a texture to apply to the Model, or `nil` for no texture.'
     }
   },
   returns = {

+ 78 - 0
api/lovr/graphics/print.lua

@@ -0,0 +1,78 @@
+return {
+  tag = 'graphicsPrimitives',
+  summary = 'Render text.',
+  description = 'Draws text in 3D space using the active font.',
+  arguments = {
+    {
+      name = 'str',
+      type = 'string',
+      description = 'The text to render.'
+    },
+    {
+      name = 'x',
+      type = 'number',
+      default = 0,
+      description = 'The x coordinate of the center of the text.'
+    },
+    {
+      name = 'y',
+      type = 'number',
+      default = 0,
+      description = 'The y coordinate of the center of the text.'
+    },
+    {
+      name = 'z',
+      type = 'number',
+      default = 0,
+      description = 'The z coordinate of the center of the text.'
+    },
+    {
+      name = 'w',
+      type = 'number',
+      default = 0,
+      description = 'The maximum width of each line, in meters.  Use zero for unlimited.'
+    },
+    {
+      name = 'h',
+      type = 'number',
+      default = .1,
+      description = 'The height of each line, in meters.'
+    },
+    {
+      name = 'angle',
+      type = 'number',
+      default = 0,
+      description = 'The number of radians to rotate the text around its rotation axis.'
+    },
+    {
+      name = 'ax',
+      type = 'number',
+      default = 0,
+      description = 'The x component of the axis of rotation.'
+    },
+    {
+      name = 'ay',
+      type = 'number',
+      default = 1,
+      description = 'The y component of the axis of rotation.'
+    },
+    {
+      name = 'az',
+      type = 'number',
+      default = 0,
+      description = 'The z component of the axis of rotation.'
+    }
+  },
+  returns = {},
+  notes = [[
+    Unicode text is supported.
+
+    Use `\n` to add line breaks.
+  ]],
+  related = {
+    'lovr.graphics.getFont',
+    'lovr.graphics.setFont',
+    'lovr.graphics.newFont',
+    'Font'
+  }
+}

+ 2 - 1
api/lovr/graphics/rotate.lua

@@ -33,6 +33,7 @@ return {
   notes = 'Order matters when scaling, translating, and rotating the coordinate system.',
   related = {
     'lovr.graphics.scale',
-    'lovr.graphics.translate'
+    'lovr.graphics.translate',
+    'lovr.graphics.transform'
   }
 }

+ 2 - 1
api/lovr/graphics/scale.lua

@@ -29,6 +29,7 @@ return {
   notes = 'Order matters when scaling, translating, and rotating the coordinate system.',
   related = {
     'lovr.graphics.rotate',
-    'lovr.graphics.translate'
+    'lovr.graphics.translate',
+    'lovr.graphics.transform'
   }
 }

+ 16 - 0
api/lovr/graphics/setFont.lua

@@ -0,0 +1,16 @@
+return {
+  tag = 'graphicsState',
+  summary = 'Set the active font.',
+  description = 'Sets the active font used to render text with `lovr.graphics.print`.',
+  arguments = {
+    {
+      name = 'font',
+      type = 'Font',
+      description = 'The font to use.'
+    }
+  },
+  returns = {},
+  related = {
+    'lovr.graphics.print'
+  }
+}

+ 74 - 0
api/lovr/graphics/transform.lua

@@ -0,0 +1,74 @@
+return {
+  tag = 'graphicsTransforms',
+  summary = 'Apply a general transform to the coordinate system.',
+  description = [[
+    Apply a transform to the coordinate system, changing its translation, rotation, and scale using
+    a single function.  A Transform object can also be used.
+
+    The transformation will last until `lovr.draw` returns or the transformation is popped off the
+    transformation stack.
+  ]],
+  arguments = {
+    transform = {
+      type = 'Transform',
+      description = 'The Transform to apply to the coordinate system.'
+    },
+    x = {
+      type = 'number',
+      default = 0,
+      description = 'The x component of the translation.'
+    },
+    y = {
+      type = 'number',
+      default = 0,
+      description = 'The y component of the translation.'
+    },
+    z = {
+      type = 'number',
+      default = 0,
+      description = 'The z component of the translation.'
+    },
+    scale = {
+      type = 'number',
+      default = 1,
+      description = 'The scale factor.'
+    },
+    angle = {
+      type = 'number',
+      default = 0,
+      description = 'The number of radians to rotate around the rotation axis.'
+    },
+    ax = {
+      type = 'number',
+      default = 0,
+      description = 'The x component of the axis of rotation.'
+    },
+    ay = {
+      type = 'number',
+      default = 1,
+      description = 'The y component of the axis of rotation.'
+    },
+    az = {
+      type = 'number',
+      default = 0,
+      description = 'The z component of the axis of rotation.'
+    }
+  },
+  returns = {},
+  variants = {
+    {
+      arguments = { 'x', 'y', 'z', 'scale', 'angle', 'ax', 'ay', 'az' },
+      returns = {}
+    },
+    {
+      description = 'Modify the coordinate system using a Transform object.',
+      arguments = { 'transform' },
+      returns = {}
+    }
+  },
+  related = {
+    'lovr.graphics.rotate',
+    'lovr.graphics.scale',
+    'lovr.graphics.translate'
+  }
+}

+ 2 - 1
api/lovr/graphics/translate.lua

@@ -29,6 +29,7 @@ return {
   notes = 'Order matters when scaling, translating, and rotating the coordinate system.',
   related = {
     'lovr.graphics.rotate',
-    'lovr.graphics.scale'
+    'lovr.graphics.scale',
+    'lovr.graphics.transform'
   }
 }

+ 16 - 0
api/lovr/headset/HeadsetEye.lua

@@ -0,0 +1,16 @@
+return {
+  summary = 'The two different eyes.',
+  description = [[
+    Represents either the left eye or the right eye.
+  ]],
+  values = {
+    {
+      name = 'left',
+      description = 'The left eye.'
+    },
+    {
+      name = 'right',
+      description = 'The right eye.'
+    }
+  }
+}

+ 32 - 0
api/lovr/headset/getEyePosition.lua

@@ -0,0 +1,32 @@
+return {
+  tag = 'headset',
+  summary = 'Get the position of an eye.',
+  description = 'Returns the current position of one of the eyes in 3D space.',
+  arguments = {
+    {
+      name = 'eye',
+      type = 'HeadsetEye',
+      description = 'The eye to get the position of.'
+    }
+  },
+  returns = {
+    {
+      name = 'x',
+      type = 'number',
+      description = 'The x position of the eye.'
+    },
+    {
+      name = 'y',
+      type = 'number',
+      description = 'The y position of the eye.'
+    },
+    {
+      name = 'z',
+      type = 'number',
+      description = 'The z position of the eye.'
+    }
+  },
+  related = {
+    'lovr.headset.getPosition'
+  }
+}

+ 21 - 0
api/lovr/math/Transform/apply.lua

@@ -0,0 +1,21 @@
+return {
+  summary = 'Combine two Transforms.',
+  description = 'Applies a Transform onto this Transform.',
+  arguments = {
+    {
+      name = 'other',
+      type = 'Transform',
+      description = [[
+        Combine two Transforms together.  Order matters, so applying Transforms in different orders
+        will yield different results.
+      ]]
+    }
+  },
+  returns = {
+    {
+      name = 'transform',
+      type = 'Transform',
+      description = 'The original Transform.'
+    }
+  }
+}

+ 12 - 0
api/lovr/math/Transform/clone.lua

@@ -0,0 +1,12 @@
+return {
+  summary = 'Clone the Transform.',
+  description = 'Returns a copy of the Transform.',
+  arguments = {},
+  returns = {
+    {
+      name = 'copy',
+      type = 'Transform',
+      description = 'The copy of the original.'
+    }
+  }
+}

+ 8 - 0
api/lovr/math/Transform/init.lua

@@ -0,0 +1,8 @@
+return {
+  summary = 'A 3D transform.',
+  description = [[
+    A Transform represents a translation, rotation, and scale in 3D space.  They're commonly used to
+    describe how entities are arranged in a scene or how a camera is positioned.
+  ]],
+  constructor = 'lovr.math.newTransform'
+}

+ 18 - 0
api/lovr/math/Transform/inverse.lua

@@ -0,0 +1,18 @@
+return {
+  summary = 'Get the inverse of the Transform.',
+  description = [[
+    Returns a new Transform representing the inverse of the original.  The inverse "cancels out" the
+    effects of the original, so applying one onto the other will result in the origin.
+  ]],
+  arguments = {},
+  returns = {
+    {
+      name = 'inverse',
+      type = 'Transform',
+      description = 'The inverse transform.'
+    }
+  },
+  related = {
+    'Transform:inverseTransformPoint'
+  }
+}

+ 41 - 0
api/lovr/math/Transform/inverseTransformPoint.lua

@@ -0,0 +1,41 @@
+return {
+  summary = 'Apply the inverse of the Transform to a point.',
+  description = 'Applies the inverse of the Transform to a point, returning the transformed point.',
+  arguments = {
+    {
+      name = 'x',
+      type = 'number',
+      description = 'The x coordinate of the point.'
+    },
+    {
+      name = 'y',
+      type = 'number',
+      description = 'The y coordinate of the point.'
+    },
+    {
+      name = 'z',
+      type = 'number',
+      description = 'The z coordinate of the point.'
+    }
+  },
+  returns = {
+    {
+      name = 'x2',
+      type = 'number',
+      description = 'The x coordinate of the transformed point.'
+    },
+    {
+      name = 'y2',
+      type = 'number',
+      description = 'The y coordinate of the transformed point.'
+    },
+    {
+      name = 'z2',
+      type = 'number',
+      description = 'The z coordinate of the transformed point.'
+    }
+  },
+  related = {
+    'Transform:transformPoint'
+  }
+}

+ 18 - 0
api/lovr/math/Transform/origin.lua

@@ -0,0 +1,18 @@
+return {
+  summary = 'Reset the Transform.',
+  description = 'Resets the Transform to the origin.',
+  arguments = {},
+  returns = {
+    {
+      name = 'transform',
+      type = 'Transform',
+      description = 'The original Transform.'
+    }
+  },
+  example = [[
+    transform = lovr.math.newTransform(3, 4, 5)
+    print(transform:transformPoint(1, 2, 2)) -- Prints 4, 6, 7
+    transform:origin()
+    print(transform:transformPoint(1, 2, 3)) -- Prints 1, 2, 3
+  ]]
+}

+ 33 - 0
api/lovr/math/Transform/rotate.lua

@@ -0,0 +1,33 @@
+return {
+  summary = 'Rotate the Transform.',
+  description = 'Rotates the Transform using an angle/axis rotation.',
+  arguments = {
+    {
+      name = 'angle',
+      type = 'number',
+      description = 'The number of radians to rotate around the axis of rotation.'
+    },
+    {
+      name = 'ax',
+      type = 'number',
+      description = 'The x component of the axis of rotation.'
+    },
+    {
+      name = 'ay',
+      type = 'number',
+      description = 'The y component of the axis of rotation.'
+    },
+    {
+      name = 'az',
+      type = 'number',
+      description = 'The z component of the axis of rotation.'
+    }
+  },
+  returns = {
+    {
+      name = 'transform',
+      type = 'Transform',
+      description = 'The original Transform.'
+    }
+  }
+}

+ 30 - 0
api/lovr/math/Transform/scale.lua

@@ -0,0 +1,30 @@
+return {
+  summary = 'Scale the Transform.',
+  description = 'Scales the Transform.',
+  arguments = {
+    {
+      name = 'x',
+      type = 'number',
+      description = 'The scale factor for the x axis.'
+    },
+    {
+      name = 'y',
+      type = 'number',
+      default = 'x',
+      description = 'The scale factor for the y axis.'
+    },
+    {
+      name = 'z',
+      type = 'number',
+      default = 'x',
+      description = 'The scale factor for the z axis.'
+    }
+  },
+  returns = {
+    {
+      name = 'transform',
+      type = 'Transform',
+      description = 'The original Transform.'
+    }
+  }
+}

+ 56 - 0
api/lovr/math/Transform/setTransformation.lua

@@ -0,0 +1,56 @@
+return {
+  summary = 'Set the position, rotation, and scale of the Transform.',
+  description = [[
+    Sets the translation, rotation, and scale of the Transform.  This will override the current
+    values in the Transform.
+  ]],
+  arguments = {
+    {
+      name = 'x',
+      type = 'number',
+      description = 'The x position of the Transform.'
+    },
+    {
+      name = 'y',
+      type = 'number',
+      description = 'The x position of the Transform.'
+    },
+    {
+      name = 'z',
+      type = 'number',
+      description = 'The x position of the Transform.'
+    },
+    {
+      name = 'scale',
+      type = 'number',
+      description = 'The scale of the Transform.'
+    },
+    {
+      name = 'angle',
+      type = 'number',
+      description = 'The number of radians the Transform is rotated around its axis of rotation.'
+    },
+    {
+      name = 'ax',
+      type = 'number',
+      description = 'The x component of the axis of rotation.'
+    },
+    {
+      name = 'ay',
+      type = 'number',
+      description = 'The y component of the axis of rotation.'
+    },
+    {
+      name = 'az',
+      type = 'number',
+      description = 'The z component of the axis of rotation.'
+    }
+  },
+  returns = {
+    {
+      name = 'transform',
+      type = 'Transform',
+      description = 'The original Transform.'
+    }
+  }
+}

+ 41 - 0
api/lovr/math/Transform/transformPoint.lua

@@ -0,0 +1,41 @@
+return {
+  summary = 'Apply the Transform to a point.',
+  description = 'Applies the Transform to a point, returning the new position.',
+  arguments = {
+    {
+      name = 'x',
+      type = 'number',
+      description = 'The x coordinate of the point.'
+    },
+    {
+      name = 'y',
+      type = 'number',
+      description = 'The y coordinate of the point.'
+    },
+    {
+      name = 'z',
+      type = 'number',
+      description = 'The z coordinate of the point.'
+    }
+  },
+  returns = {
+    {
+      name = 'x2',
+      type = 'number',
+      description = 'The x coordinate of the transformed point.'
+    },
+    {
+      name = 'y2',
+      type = 'number',
+      description = 'The y coordinate of the transformed point.'
+    },
+    {
+      name = 'z2',
+      type = 'number',
+      description = 'The z coordinate of the transformed point.'
+    }
+  },
+  related = {
+    'Transform:inverseTransformPoint'
+  }
+}

+ 28 - 0
api/lovr/math/Transform/translate.lua

@@ -0,0 +1,28 @@
+return {
+  summary = 'Translate the Transform.',
+  description = 'Translates the Transform.',
+  arguments = {
+    {
+      name = 'x',
+      type = 'number',
+      description = 'The x component of the translation.'
+    },
+    {
+      name = 'y',
+      type = 'number',
+      description = 'The y component of the translation.'
+    },
+    {
+      name = 'z',
+      type = 'number',
+      description = 'The z component of the translation.'
+    }
+  },
+  returns = {
+    {
+      name = 'transform',
+      type = 'Transform',
+      description = 'The original Transform.'
+    }
+  }
+}

+ 8 - 0
api/lovr/math/init.lua

@@ -0,0 +1,8 @@
+return {
+  tag = 'modules',
+  summary = 'Contains useful math helpers.',
+  description = [[
+    The `lovr.math` module provides math helpers commonly used for 3D applications.  Currently, only
+    `Transform` objects are exposed.
+  ]]
+}

+ 58 - 0
api/lovr/math/newTransform.lua

@@ -0,0 +1,58 @@
+return {
+  summary = 'Create a new Transform.',
+  description = [[
+    A transform is a 4x4, column major matrix that can be used to represent the 3D transform of an
+    object.  Most graphics primitives accept a Transform instead of the usual coordinate arguments.
+    Transforms provide a convenient way to represent translation, rotation, and scale in a single
+    object.
+  ]],
+  arguments = {
+    {
+      name = 'x',
+      type = 'number',
+      description = 'The x position of the Transform.'
+    },
+    {
+      name = 'y',
+      type = 'number',
+      description = 'The x position of the Transform.'
+    },
+    {
+      name = 'z',
+      type = 'number',
+      description = 'The x position of the Transform.'
+    },
+    {
+      name = 'scale',
+      type = 'number',
+      description = 'The scale of the Transform.'
+    },
+    {
+      name = 'angle',
+      type = 'number',
+      description = 'The number of radians the Transform is rotated around its axis of rotation.'
+    },
+    {
+      name = 'ax',
+      type = 'number',
+      description = 'The x component of the axis of rotation.'
+    },
+    {
+      name = 'ay',
+      type = 'number',
+      description = 'The y component of the axis of rotation.'
+    },
+    {
+      name = 'az',
+      type = 'number',
+      description = 'The z component of the axis of rotation.'
+    }
+  },
+  returns = {
+    {
+      name = 'transform',
+      type = 'Transform',
+      description = 'The new Transform.'
+    }
+  }
+}