Commit Graph

20 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 fdba60214c Fix Collider/Shape/Joint UserData leak;
refs are cumbersome because they require storing an int and they require
manual cleanup when the object is destroyed.

Instead, we'll go with a pure Lua solution using a table in the
registry.  The table has weak keys containing the LÖVR object, and the
values are the userdata.  This doesn't require any manual cleanup,
reduces the size of objects by 8 bytes, and is about 25% faster.
2024-04-01 16:03:42 -07:00
bjorn 2d7b636a90 Change more asserts to checks; 2024-03-11 00:58:21 -07:00
Josip Miskovic f16956b07d Fix getter for distance joint anchors 2023-09-13 22:06:51 +02: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
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 65b0f95ca9 Add lovrUnreachable macro; 2022-04-27 00:05:14 -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 b7527c3584 More people use COUNTOF; 2022-03-22 17:56:26 -07:00
bjorn 2da18d419b mv util src; 2022-03-22 00:13:38 -07:00
bjorn e63099ba6a Flatten api.h; 2021-03-15 18:54:27 -06:00
bjorn 3bc2c00b79 api doesn't include util; 2020-12-25 12:50:26 -07:00
bjorn 51f470cf85 Easier enums; 2020-09-27 17:13:00 -07:00
bjorn ec257b179f Support Lua 5.2, 5.3, 5.4; 2020-08-19 13:12:57 -06: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
Josip Miskovic 2d6f7802f1 Joints API accepts both vec3 and number coords 2020-05-10 01:12:45 +03:00
bjorn 18dcb07b98 Convert stuff over to use new enum system; 2020-02-16 18:31:02 -08: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_joints.c (Browse further)