Ver Fonte

Vec3:rotate; Vec3:transform; Vec4:transform;

bjorn há 1 ano atrás
pai
commit
5bc87dd0a9

+ 290 - 0
api/init.lua

@@ -28543,6 +28543,65 @@ return {
                 }
               }
             },
+            {
+              name = "rotate",
+              summary = "Apply a rotation to the vector.",
+              description = "Applies a rotation to the vector, using a `Quat` or an angle/axis rotation.",
+              key = "Vec3:rotate",
+              module = "lovr.math",
+              related = {
+                "Quat:mul"
+              },
+              variants = {
+                {
+                  arguments = {
+                    {
+                      name = "q",
+                      type = "Quat",
+                      description = "The quaternion to apply."
+                    }
+                  },
+                  returns = {
+                    {
+                      name = "self",
+                      type = "Vec3",
+                      description = "The modified vector."
+                    }
+                  }
+                },
+                {
+                  arguments = {
+                    {
+                      name = "angle",
+                      type = "number",
+                      description = "The number of radians to rotate."
+                    },
+                    {
+                      name = "ax",
+                      type = "number",
+                      description = "The x component of the axis to rotate around."
+                    },
+                    {
+                      name = "ay",
+                      type = "number",
+                      description = "The y component of the axis to rotate around."
+                    },
+                    {
+                      name = "az",
+                      type = "number",
+                      description = "The z component of the axis to rotate around."
+                    }
+                  },
+                  returns = {
+                    {
+                      name = "self",
+                      type = "Vec3",
+                      description = "The modified vector."
+                    }
+                  }
+                }
+              }
+            },
             {
               name = "set",
               summary = "Set the components of the vector.",
@@ -28690,6 +28749,122 @@ return {
                 }
               }
             },
+            {
+              name = "transform",
+              summary = "Apply a transform to the vector.",
+              description = "Applies a transform (translation, rotation, scale) to the vector using a `Mat4` or numbers. This is the same as multiplying the vector by a matrix.  This treats the vector as a point.",
+              key = "Vec3:transform",
+              module = "lovr.math",
+              related = {
+                "Mat4:mul",
+                "Vec4:transform",
+                "Vec3:rotate"
+              },
+              variants = {
+                {
+                  arguments = {
+                    {
+                      name = "m",
+                      type = "Mat4",
+                      description = "The matrix to apply."
+                    }
+                  },
+                  returns = {
+                    {
+                      name = "self",
+                      type = "Vec3",
+                      description = "The original vector, with transformed components."
+                    }
+                  }
+                },
+                {
+                  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 = {
+                    {
+                      name = "self",
+                      type = "Vec3",
+                      description = "The original vector, with transformed components."
+                    }
+                  }
+                },
+                {
+                  arguments = {
+                    {
+                      name = "translation",
+                      type = "Vec3",
+                      description = "The translation to apply."
+                    },
+                    {
+                      name = "scale",
+                      type = "number",
+                      description = "The scale factor.",
+                      default = "1"
+                    },
+                    {
+                      name = "rotation",
+                      type = "Quat",
+                      description = "The rotation to apply."
+                    }
+                  },
+                  returns = {
+                    {
+                      name = "self",
+                      type = "Vec3",
+                      description = "The original vector, with transformed components."
+                    }
+                  }
+                }
+              }
+            },
             {
               name = "unpack",
               summary = "Get the components of the vector.",
@@ -29415,6 +29590,121 @@ return {
                 }
               }
             },
+            {
+              name = "transform",
+              summary = "Apply a transform to the vector.",
+              description = "Applies a transform (translation, rotation, scale) to the vector using a `Mat4` or numbers. This is the same as multiplying the vector by a matrix.",
+              key = "Vec4:transform",
+              module = "lovr.math",
+              related = {
+                "Mat4:mul",
+                "Vec3:transform"
+              },
+              variants = {
+                {
+                  arguments = {
+                    {
+                      name = "m",
+                      type = "Mat4",
+                      description = "The matrix to apply."
+                    }
+                  },
+                  returns = {
+                    {
+                      name = "self",
+                      type = "Vec4",
+                      description = "The original vector, with transformed components."
+                    }
+                  }
+                },
+                {
+                  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 = {
+                    {
+                      name = "self",
+                      type = "Vec4",
+                      description = "The original vector, with transformed components."
+                    }
+                  }
+                },
+                {
+                  arguments = {
+                    {
+                      name = "translation",
+                      type = "Vec3",
+                      description = "The translation to apply."
+                    },
+                    {
+                      name = "scale",
+                      type = "number",
+                      description = "The scale factor.",
+                      default = "1"
+                    },
+                    {
+                      name = "rotation",
+                      type = "Quat",
+                      description = "The rotation to apply."
+                    }
+                  },
+                  returns = {
+                    {
+                      name = "self",
+                      type = "Vec4",
+                      description = "The original vector, with transformed components."
+                    }
+                  }
+                }
+              }
+            },
             {
               name = "unpack",
               summary = "Get the components of the vector.",

+ 45 - 0
api/lovr/math/Vec3/rotate.lua

@@ -0,0 +1,45 @@
+return {
+  summary = 'Apply a rotation to the vector.',
+  description = 'Applies a rotation to the vector, using a `Quat` or an angle/axis rotation.',
+  arguments = {
+    q = {
+      type = 'Quat',
+      description = 'The quaternion to apply.'
+    },
+    angle = {
+      type = 'number',
+      description = 'The number of radians to rotate.'
+    },
+    ax = {
+      type = 'number',
+      description = 'The x component of the axis to rotate around.'
+    },
+    ay = {
+      type = 'number',
+      description = 'The y component of the axis to rotate around.'
+    },
+    az = {
+      type = 'number',
+      description = 'The z component of the axis to rotate around.'
+    }
+  },
+  returns = {
+    self = {
+      type = 'Vec3',
+      description = 'The modified vector.'
+    }
+  },
+  variants = {
+    {
+      arguments = { 'q' },
+      returns = { 'self' }
+    },
+    {
+      arguments = { 'angle', 'ax', 'ay', 'az' },
+      returns = { 'self' }
+    }
+  },
+  related = {
+    'Quat:mul'
+  }
+}

+ 90 - 0
api/lovr/math/Vec3/transform.lua

@@ -0,0 +1,90 @@
+return {
+  summary = 'Apply a transform to the vector.',
+  description = [[
+    Applies a transform (translation, rotation, scale) to the vector using a `Mat4` or numbers.
+    This is the same as multiplying the vector by a matrix.  This treats the vector as a point.
+  ]],
+  arguments = {
+    m = {
+      type = 'Mat4',
+      description = 'The matrix to apply.'
+    },
+    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.'
+    },
+    translation = {
+      type = 'Vec3',
+      description = 'The translation to apply.'
+    },
+    position = {
+      type = 'Vec3',
+      description = 'The scale to apply.'
+    },
+    rotation = {
+      type = 'Quat',
+      description = 'The rotation to apply.'
+    },
+  },
+  returns = {
+    self = {
+      type = 'Vec3',
+      description = 'The original vector, with transformed components.'
+    }
+  },
+  variants = {
+    {
+      arguments = { 'm' },
+      returns = { 'self' }
+    },
+    {
+      arguments = { 'x', 'y', 'z', 'scale', 'angle', 'ax', 'ay', 'az' },
+      returns = { 'self' }
+    },
+    {
+      arguments = { 'translation', 'scale', 'rotation' },
+      returns = { 'self' }
+    }
+  },
+  related = {
+    'Mat4:mul',
+    'Vec4:transform',
+    'Vec3:rotate'
+  }
+}

+ 89 - 0
api/lovr/math/Vec4/transform.lua

@@ -0,0 +1,89 @@
+return {
+  summary = 'Apply a transform to the vector.',
+  description = [[
+    Applies a transform (translation, rotation, scale) to the vector using a `Mat4` or numbers. This
+    is the same as multiplying the vector by a matrix.
+  ]],
+  arguments = {
+    m = {
+      type = 'Mat4',
+      description = 'The matrix to apply.'
+    },
+    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.'
+    },
+    translation = {
+      type = 'Vec3',
+      description = 'The translation to apply.'
+    },
+    position = {
+      type = 'Vec3',
+      description = 'The scale to apply.'
+    },
+    rotation = {
+      type = 'Quat',
+      description = 'The rotation to apply.'
+    },
+  },
+  returns = {
+    self = {
+      type = 'Vec4',
+      description = 'The original vector, with transformed components.'
+    }
+  },
+  variants = {
+    {
+      arguments = { 'm' },
+      returns = { 'self' }
+    },
+    {
+      arguments = { 'x', 'y', 'z', 'scale', 'angle', 'ax', 'ay', 'az' },
+      returns = { 'self' }
+    },
+    {
+      arguments = { 'translation', 'scale', 'rotation' },
+      returns = { 'self' }
+    }
+  },
+  related = {
+    'Mat4:mul',
+    'Vec3:transform'
+  }
+}