Browse Source

World:queryBox; World:querySphere;

bjorn 1 year ago
parent
commit
d56be00204

+ 175 - 0
api/init.lua

@@ -35568,6 +35568,177 @@ return {
                 }
                 }
               }
               }
             },
             },
+            {
+              name = "queryBox",
+              tag = "worldBasics",
+              summary = "Find all shapes that intersect a box.",
+              description = "Finds all the shapes that intersect a box and calls a function for each one.",
+              key = "World:queryBox",
+              module = "lovr.physics",
+              notes = "Currently there is no way to specify a rotated box.",
+              related = {
+                "World:querySphere",
+                "World:raycast",
+                "World:getContacts",
+                "Shape:setSensor"
+              },
+              variants = {
+                {
+                  arguments = {
+                    {
+                      name = "x",
+                      type = "number",
+                      description = "The x coordinate of the center of the box."
+                    },
+                    {
+                      name = "y",
+                      type = "number",
+                      description = "The y coordinate of the center of the box."
+                    },
+                    {
+                      name = "z",
+                      type = "number",
+                      description = "The z coordinate of the center of the box."
+                    },
+                    {
+                      name = "w",
+                      type = "number",
+                      description = "The width of the box."
+                    },
+                    {
+                      name = "h",
+                      type = "number",
+                      description = "The height of the box."
+                    },
+                    {
+                      name = "d",
+                      type = "number",
+                      description = "The depth of the box."
+                    },
+                    {
+                      name = "callback",
+                      type = "function",
+                      description = "An optional function to call when an intersection is detected.  The function will be called with a single `Shape` argument, and it may return `false` to cancel the query.",
+                      default = "nil"
+                    }
+                  },
+                  returns = {
+                    {
+                      name = "any",
+                      type = "boolean",
+                      description = "Whether there were any intersections."
+                    }
+                  }
+                },
+                {
+                  arguments = {
+                    {
+                      name = "position",
+                      type = "Vec3",
+                      description = "The position of the center of the box."
+                    },
+                    {
+                      name = "size",
+                      type = "Vec3",
+                      description = "The size of the box."
+                    },
+                    {
+                      name = "callback",
+                      type = "function",
+                      description = "An optional function to call when an intersection is detected.  The function will be called with a single `Shape` argument, and it may return `false` to cancel the query.",
+                      default = "nil"
+                    }
+                  },
+                  returns = {
+                    {
+                      name = "any",
+                      type = "boolean",
+                      description = "Whether there were any intersections."
+                    }
+                  }
+                }
+              }
+            },
+            {
+              name = "querySphere",
+              tag = "worldBasics",
+              summary = "Find all shapes that intersect a sphere.",
+              description = "Finds all the shapes that intersect a sphere and calls a function for each one.",
+              key = "World:querySphere",
+              module = "lovr.physics",
+              related = {
+                "World:queryBox",
+                "World:raycast",
+                "World:getContacts",
+                "Shape:setSensor"
+              },
+              variants = {
+                {
+                  arguments = {
+                    {
+                      name = "x",
+                      type = "number",
+                      description = "The x coordinate of the center of the sphere."
+                    },
+                    {
+                      name = "y",
+                      type = "number",
+                      description = "The y coordinate of the center of the sphere."
+                    },
+                    {
+                      name = "z",
+                      type = "number",
+                      description = "The z coordinate of the center of the sphere."
+                    },
+                    {
+                      name = "radius",
+                      type = "number",
+                      description = "The radius of the sphere."
+                    },
+                    {
+                      name = "callback",
+                      type = "function",
+                      description = "An optional function to call when an intersection is detected.  The function will be called with a single `Shape` argument, and it may return `false` to cancel the query.",
+                      default = "nil"
+                    }
+                  },
+                  returns = {
+                    {
+                      name = "any",
+                      type = "boolean",
+                      description = "Whether there were any intersections."
+                    }
+                  }
+                },
+                {
+                  arguments = {
+                    {
+                      name = "position",
+                      type = "Vec3",
+                      description = "The position of the center of the sphere."
+                    },
+                    {
+                      name = "radius",
+                      type = "number",
+                      description = "The radius of the sphere."
+                    },
+                    {
+                      name = "callback",
+                      type = "function",
+                      description = "An optional function to call when an intersection is detected.  The function will be called with a single `Shape` argument, and it may return `false` to cancel the query.",
+                      default = "nil"
+                    }
+                  },
+                  returns = {
+                    {
+                      name = "any",
+                      type = "boolean",
+                      description = "Whether there were any intersections."
+                    }
+                  }
+                }
+              }
+            },
             {
             {
               name = "raycast",
               name = "raycast",
               tag = "worldBasics",
               tag = "worldBasics",
@@ -35581,6 +35752,10 @@ return {
                 }
                 }
               },
               },
               notes = "The callback is passed the shape that was hit, the hit position (in world coordinates), and the normal vector of the hit.",
               notes = "The callback is passed the shape that was hit, the hit position (in world coordinates), and the normal vector of the hit.",
+              related = {
+                "World:queryBox",
+                "World:querySphere"
+              },
               variants = {
               variants = {
                 {
                 {
                   arguments = {
                   arguments = {

+ 70 - 0
api/lovr/physics/World/queryBox.lua

@@ -0,0 +1,70 @@
+return {
+  tag = 'worldBasics',
+  summary = 'Find all shapes that intersect a box.',
+  description = 'Finds all the shapes that intersect a box and calls a function for each one.',
+  arguments = {
+    x = {
+      type = 'number',
+      description = 'The x coordinate of the center of the box.',
+    },
+    y = {
+      type = 'number',
+      description = 'The y coordinate of the center of the box.',
+    },
+    z = {
+      type = 'number',
+      description = 'The z coordinate of the center of the box.',
+    },
+    w = {
+      type = 'number',
+      description = 'The width of the box.',
+    },
+    h = {
+      type = 'number',
+      description = 'The height of the box.',
+    },
+    d = {
+      type = 'number',
+      description = 'The depth of the box.',
+    },
+    position = {
+      type = 'Vec3',
+      description = 'The position of the center of the box.'
+    },
+    size = {
+      type = 'Vec3',
+      description = 'The size of the box.'
+    },
+    callback = {
+      type = 'function',
+      default = 'nil',
+      description = [[
+        An optional function to call when an intersection is detected.  The function will be called
+        with a single `Shape` argument, and it may return `false` to cancel the query.
+      ]]
+    }
+  },
+  returns = {
+    any = {
+      type = 'boolean',
+      description = 'Whether there were any intersections.'
+    }
+  },
+  variants = {
+    {
+      arguments = { 'x', 'y', 'z', 'w', 'h', 'd', 'callback' },
+      returns = { 'any' }
+    },
+    {
+      arguments = { 'position', 'size', 'callback' },
+      returns = { 'any' }
+    }
+  },
+  notes = 'Currently there is no way to specify a rotated box.',
+  related = {
+    'World:querySphere',
+    'World:raycast',
+    'World:getContacts',
+    'Shape:setSensor'
+  }
+}

+ 57 - 0
api/lovr/physics/World/querySphere.lua

@@ -0,0 +1,57 @@
+return {
+  tag = 'worldBasics',
+  summary = 'Find all shapes that intersect a sphere.',
+  description = 'Finds all the shapes that intersect a sphere and calls a function for each one.',
+  arguments = {
+    x = {
+      type = 'number',
+      description = 'The x coordinate of the center of the sphere.',
+    },
+    y = {
+      type = 'number',
+      description = 'The y coordinate of the center of the sphere.',
+    },
+    z = {
+      type = 'number',
+      description = 'The z coordinate of the center of the sphere.',
+    },
+    radius = {
+      type = 'number',
+      description = 'The radius of the sphere.',
+    },
+    position = {
+      type = 'Vec3',
+      description = 'The position of the center of the sphere.'
+    },
+    callback = {
+      type = 'function',
+      default = 'nil',
+      description = [[
+        An optional function to call when an intersection is detected.  The function will be called
+        with a single `Shape` argument, and it may return `false` to cancel the query.
+      ]]
+    }
+  },
+  returns = {
+    any = {
+      type = 'boolean',
+      description = 'Whether there were any intersections.'
+    }
+  },
+  variants = {
+    {
+      arguments = { 'x', 'y', 'z', 'radius', 'callback' },
+      returns = { 'any' }
+    },
+    {
+      arguments = { 'position', 'radius', 'callback' },
+      returns = { 'any' }
+    }
+  },
+  related = {
+    'World:queryBox',
+    'World:raycast',
+    'World:getContacts',
+    'Shape:setSensor'
+  }
+}

+ 5 - 1
api/lovr/physics/World/raycast.lua

@@ -100,5 +100,9 @@ return {
         print('Collision detected!', shape, x, y, z, nx, ny, nz)
         print('Collision detected!', shape, x, y, z, nx, ny, nz)
       end)
       end)
     end
     end
-  ]]
+  ]],
+  related = {
+    'World:queryBox',
+    'World:querySphere'
+  }
 }
 }