Commit Graph

57 Commits

Author SHA1 Message Date
bjorn 060e72c525 Rename CompoundShape 'shape' to 'child';
Maybe slightly less ambiguous/confusing?
2024-04-07 13:47:52 -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 b589cec975 Collider:getShape takes optional child index;
For convenience when you're trying to dig a leaf shape out of a CompoundShape.

It's ignored if the collider's shape is not a CompoundShape.
2024-04-07 13:47:52 -07:00
bjorn 8bdab9f2d4 Shape:getAABB; 2024-04-07 13:47:52 -07:00
bjorn 5751068728 Move Shape:is/setSensor and Shape:is/setEnabled to Collider; 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 ff0f39fc7b rm unused shape prototypes; 2024-04-07 13:47:52 -07:00
bjorn 930e713079 Add Collider:get/setShapeOffset; 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 10f965d69e rm Shape setters;
Jolt doesn't support this and requires you to recreate the shape.  Since
the shape -> collider relationship is 1:N, we can't really create a new
shape because we'd have to figure out which colliders/compoundshapes to
assign it to, which isn't feasible.
2024-04-07 13:47:52 -07:00
bjorn b3e9e55b8a CompoundShape API; 2024-04-07 13:47:52 -07:00
bjorn 6f0b6391df Start CompoundShape; 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 38a68dc4e5 TerrainShape image must be square; 2024-04-06 00:12:50 -07:00
bjorn 5e521b7698 Collider:applyLinear/AngularImpulse; 2024-04-05 19:16:39 -07:00
bjorn fb6b402034 Add Collider:is/setContinuous; 2024-04-05 19:05:25 -07:00
bjorn e9fe088521 Add Collider:get/setGravityScale; Deprecate Collider:get/setGravityIgnored; 2024-04-05 14:22:02 -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 d756cc2b1d Add variant of newWorld that takes an options table; 2024-04-05 13:25:32 -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
xiejiangzhi 45a6333afb Slow movement for sim, fix bug of tag, add max number of tag to 32
Holding ctrl to slowly movement for Sim
Check null for findTag
Increment max number of tags to 32
Fix newWorld error if tags > MAX_TAGS
2024-01-21 13:50:59 +08: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 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 9bf2def86d Rename box shape dimensions to be more clear; 2023-07-10 23:11:14 -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
bjorn a511064987 Collider:isDestroyed; 2023-06-22 15:48:23 -07: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 57a215a0aa Minor MeshShape cleanup;
- Fix memory leak
- Minor error message improvements
2021-02-19 17:28:04 -07:00
bjorn 023067ec27 util.h no longer uses atomics; 2021-02-11 16:37:55 -07:00
bjorn 6d92d54079 Try having arr_t in util; 2021-02-08 18:25:05 -07:00
bjorn 3ded60948f rm core/ref; rm lovrAlloc; util does refcounting; 2021-02-08 17:26:44 -07:00
Josip Miskovic 75591fde42 Support for trimesh shape colliders 2020-09-24 20:58:28 +02: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
bjorn 6539bc1bd2 Make physics orientation getters more consistent; 2020-05-10 02:08:36 -06:00
Josip Miskovic e2d1b33eed Shapes API accepts both vec3 and number coords 2020-05-10 01:12:45 +03:00
bjorn eea73792a6 Minor formatting; 2020-04-30 14:15:36 -06: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
Josip Miskovic a4b0d004a1 Fix collider setOrientation() and setPose()
The conversion from angle,ax,ay,az to quaternion is already done in
physics module.
2020-04-28 20:15:09 +03:00
Bjorn 539e25897b
Merge pull request #157 from bjornbytes/shape-sensor
Shape:isSensor; Shape:setSensor;
2019-11-20 18:35:24 -08:00
bjorn a7e24ab28e Joint:isEnabled; Joint:setEnabled; 2019-11-11 16:39:02 -08:00