Commit Graph

39 Commits

Author SHA1 Message Date
bjorn 15649802c8 Rework World Collider/Joint lists;
- Add World:getColliderCount
- Add World:getJointCount
- Add World:getJoints
- Add Joint:isDestroyed
- Destroy joints when either of their colliders are destroyed (Jolt
  seems to require this).
- Fix joint memory leak.
- Change joints to be stored in some crazy graph thing.
  - Reduces allocations, allows constant time insertion/removal.
2024-04-07 15:08:22 -07:00
bjorn 2ac0d6946e Move shape arg to last argument of query callbacks;
Also fix an off-by-one error.
2024-04-07 13:47:52 -07:00
bjorn 481a9dafa2 newCollider takes optional Shape as first arg; 2024-04-07 13:47:52 -07:00
bjorn f35cda7db8 lovrColliderCreate takes shape;
Jolt requires a shape, also it saves a bit of work.
2024-04-07 13:47:52 -07:00
bjorn 4f26182595 World queries return collider/shapeindex instead of Shape; 2024-04-07 13:47:52 -07:00
bjorn ce58619094 Colliders can only have 1 shape; rm shape pose; 2024-04-07 13:47:52 -07:00
bjorn 01194a80c7 Deprecate several World methods;
They still work on ODE, and Jolt makes a best-effort attempt to support
them, but they will be removed in a future version.

- Damping should be set explicitly on colliders.
- Tightness and response time will be supported via spring forces, and
  also some global settings in newWorld will affect joints too.
- Step count will be added to :update soon.  Since the correct value is
  dt-dependent in Jolt, a persistent accessor doesn't make sense.
- Sleeping allowed will be an immutable setting in newWorld soon, but
  otherwise should be changed per-collider.
2024-04-05 14:07:56 -07:00
bjorn ffc23497a9 Details; 2024-04-05 13:58:28 -07:00
bjorn 2d7b636a90 Change more asserts to checks; 2024-03-11 00:58:21 -07:00
bjorn 2c5f9d379b World:raycastAny and World:raycastClosest;
These are methods that implement some common raycast behaviors without
creating a closure.  They also take tag filters.  The tag filters could
be optimized to use tag numbers instead of string comparison, and the
default raycast method could take a tag filter, but I didn't want to
modify the C API while Jolt is in progress.
2023-10-23 16:09:07 -07:00
bjorn 0d6c9a1def World:isCollisionEnabledBetween takes nils;
They act like wildcards, just like nil tags do otherwise.
2023-08-15 18:24:19 -07:00
xiejiangzhi ee10e22402 World query: Rename should_stop to shouldStop, early stop queryCallback if no give a callback 2023-07-21 08:00:58 +08:00
xiejiangzhi a4dc1d9ffb Support early exit for world:raycast world:queryBox world:querySphere 2023-07-20 16:34:56 +08:00
bjorn 534d47904e World:queryBox/World:querySphere callback is optional;
They also return a bool indicating if any intersections occurred.
2023-07-17 13:23:57 -07:00
bjorn b268cd1776 World:queryBox; World:querySphere; 2023-07-10 23:20:01 -07:00
bjorn be795c0ebd Change vec3 back to 3 floats; Clean up maf/vectors;
The "vec3 is 4 floats" thing was consistently confusing to people.  It's
reverted everywhere except for Curve.

maf now has full sets of methods for vec2/vec3/vec4, for consistency.

Vector bindings now use luax_readvec* helper functions for the
number/vector variants, and use maf for most functionality, which cleans
things up a lot.
2023-07-10 17:51:24 -07:00
Josip Miskovic 9e06c72b37 A getter for World list of tags 2022-12-26 09:50:14 +01:00
bjorn e9776f98c6 Fix compatibility with Lua 5.2, 5.3, 5.4;
Part of this involved putting the Lua header back in api.h, since we
need to know the Lua version to define some macros properly.
2022-11-24 14:33:55 -08:00
bjorn f8f748320e Minor Shape improvements;
- Add helper functions for creating shapes to avoid duplication between
  newShape and newShapeCollider.
- Add lovr.physics.newMeshShape and lovr.physics.newTerrainShape
- Register TerrainShape so it has all the base Shape methods
- Smooth out a few TerrainShape warnings
2022-11-09 20:53:42 -08:00
Josip Miskovic 34611f2069 Add physics heightfield shape 2022-11-08 18:46:49 -08:00
Josip Miskovic 24a0751c16 Add `World:setStepIterations(num)` and its getter
Physics world's "quick step" is executed in multiple iteration steps.
The getter and setter for this value is now made available as two new
methods in the World object.

This is allows user to balance between the less accurate but quick
simulations, and more stable behavior of physics.

Something similar was already possible, by reducing the delta time and
running the sim multiple times per frame. However, any force user applies
to collider is zeroed after each step. User would thus have to keep track
of applied forces, and re-apply them inside the physics iteration loop.

By default ODE uses 20 iterations in quick step.
2022-04-27 11:39:08 -07:00
bjorn 42e618fa00 World:getContacts; 2022-03-30 22:32:20 -07:00
bjorn 8fcdfd2bb4 Minor physics cleanup; 2022-03-30 22:05:10 -07:00
bjorn 6c9531564e Make physics structs private; 2022-03-25 12:40:29 -07:00
bjorn 2da18d419b mv util src; 2022-03-22 00:13:38 -07:00
bjorn 61ef2747ee World:newMeshCollider uses luax_readmesh;
This is a breaking API change -- instead of a table of tables, a flat
table of coordinates must be used.
2021-03-25 12:29:11 -06:00
bjorn e63099ba6a Flatten api.h; 2021-03-15 18:54:27 -06:00
bjorn 57a215a0aa Minor MeshShape cleanup;
- Fix memory leak
- Minor error message improvements
2021-02-19 17:28:04 -07:00
bjorn bc4cde1653 Adjust lovrRelease signature; 2021-02-08 17:52:26 -07:00
bjorn 3ded60948f rm core/ref; rm lovrAlloc; util does refcounting; 2021-02-08 17:26:44 -07:00
bjorn 3bc2c00b79 api doesn't include util; 2020-12-25 12:50:26 -07:00
Josip Miskovic b4d391f45f Change default damping threshold to zero
Zero as default makes more sense. Colliders can come to full stop which
allows them to go to sleep for CPU optimization. Also in zero gravity
colliders crawling through air with 0.01 velocity are infuriating.
2020-11-12 18:28:59 +01:00
Josip Miskovic 75591fde42 Support for trimesh shape colliders 2020-09-24 20:58:28 +02:00
Josip Miskovic 5d18933411 Limit simulation parameters to positive values 2020-06-03 20:13:13 +03:00
Josip Miskovic 139808cab0 Get/set World and Joint simulation parameters
Tightness parameter is amount of force is exerted on collider to resolve
collisions and enforce joint operation. Low values make joints loose,
high values make it tight and can cause collider to overshot the joint
target. With tightness set to 0 the joint loses its function. Going
above 1 puts even more energy into joint oscillations. Tightness
parameter is called ERP in ODE manual.

The responseTime affects the time constant of physics simulation, both
for collisions and for joint inertia. Low responseTime values make
simulation tight and fast, higher values make it sluggish. For
collisions it affects how fast penetration is resolved, with higher
values resulting in spongy objects with more surface penetration and
slower collision resolving. For joints the responseTime is similar to
inertia, with higher responseTime values resulting in slow oscillations.
The oscillation frequency is also affected by collider mass, so
responseTime can be used to tweak the joint to get desired frequency
with specific collider mass. Values higher than 1 are often desirable,
especially for very light objects. Unlike tightness, responseTime is
tweaked in orders of magnitude with useful values (depending on mass)
being between 10^-8 and 10^8.

Both parameters can be applied to World for simulation-wide usage, or
specified per-joint in case of distance and ball joints. Other joints
don't allow customizing these parameters, and will use World settings
instead..
2020-06-03 19:03:38 +03:00
bjorn dab0be7055 World:getColliders; 2020-05-11 12:05:30 -06:00
Josip Miskovic 2463737722 Physics world accepts both vec3 and number coords
When creating colliders, setting gravity or casting rays on world,
arguments accept either coordinate numbers as before, or vec3 objects.
For functions that receive more than one set of coordinates, any
combination of coordinates and vectors is accepted.
2020-05-07 19:01:30 +03:00
Josip Miskovic 097d39628a Initialize inertia information for new colliders
Inertia matrix has to be calculated with algorithm specific for each
shape. Without calculated matrix the physics behaves very floaty and
slowed down.
2020-04-29 23:05:11 +03:00
bjorn c9b1f257bf api: try new file naming convention; Tupfile: cleanup;
I assume full responsibility for any catastrophes this causes.
2019-12-31 19:31:44 -08:00
Renamed from src/api/l_world.c (Browse further)