clockwise option, joint is awake (#130)
- b3MeshDef gets stride and clockwise option - Added b3Joint_IsAwake - Added b3Body_TimeOfImpactMover - #116 - Smoother mover collision: #141 - Shape casts now ignore backside collision on mesh and height-field triangles, same as ray casts.
This commit is contained in:
parent
30c67b5e6d
commit
47d7f7cc7e
35 changed files with 2466 additions and 303 deletions
|
|
@ -82,6 +82,7 @@ B3_API b3TreeStats b3World_OverlapShape( b3WorldId worldId, b3Pos origin, const
|
|||
|
||||
/// Cast a ray into the world to collect shapes in the path of the ray.
|
||||
/// Your callback function controls whether you get the closest point, any point, or n-points.
|
||||
/// Ignores back-side collision on meshes and height-fields.
|
||||
/// @note The callback function may receive shapes in any order
|
||||
/// @param worldId The world to cast the ray against
|
||||
/// @param origin The start point of the ray
|
||||
|
|
@ -94,19 +95,20 @@ B3_API b3TreeStats b3World_CastRay( b3WorldId worldId, b3Pos origin, b3Vec3 tran
|
|||
b3CastResultFcn* fcn, void* context );
|
||||
|
||||
/// Cast a ray into the world to collect the closest hit. This is a convenience function. Ignores initial overlap.
|
||||
/// This is less general than b3World_CastRay() and does not allow for custom filtering.
|
||||
/// This is less general than b3World_CastRay() and does not allow for custom filtering. Ignores back-side collision
|
||||
/// on meshes and height-fields.
|
||||
B3_API b3RayResult b3World_CastRayClosest( b3WorldId worldId, b3Pos origin, b3Vec3 translation, b3QueryFilter filter );
|
||||
|
||||
/// Cast a shape through the world. Similar to a cast ray except that a shape is cast instead of a point.
|
||||
/// The proxy points are relative to the origin and the hit points come back as world positions, so the
|
||||
/// cast stays precise far from the world origin.
|
||||
/// cast stays precise far from the world origin. Ignores back-side collision on meshes and height-fields.
|
||||
/// @see b3World_CastRay
|
||||
B3_API b3TreeStats b3World_CastShape( b3WorldId worldId, b3Pos origin, const b3ShapeProxy* proxy, b3Vec3 translation,
|
||||
b3QueryFilter filter, b3CastResultFcn* fcn, void* context );
|
||||
|
||||
/// Cast a capsule mover through the world. This is a special shape cast that handles sliding along other shapes while reducing
|
||||
/// clipping. This is not a good source of information about what the mover is touching. Instead use the planes returned by
|
||||
/// b3World_CollideMover.
|
||||
/// b3World_CollideMover. Ignores back-side collision on meshes and height-fields.
|
||||
/// @param worldId World to cast the mover against
|
||||
/// @param origin World position the mover capsule is relative to
|
||||
/// @param mover Capsule mover, relative to the origin
|
||||
|
|
@ -120,6 +122,7 @@ B3_API float b3World_CastMover( b3WorldId worldId, b3Pos origin, const b3Capsule
|
|||
|
||||
/// Collide a capsule mover with the world, gathering collision planes that can be fed to b3SolvePlanes. Useful for
|
||||
/// kinematic character movement. The mover and the returned planes are relative to the origin.
|
||||
/// Ignores back-side collision on meshes and height-fields.
|
||||
B3_API void b3World_CollideMover( b3WorldId worldId, b3Pos origin, const b3Capsule* mover, b3QueryFilter filter,
|
||||
b3PlaneResultFcn* fcn, void* context );
|
||||
|
||||
|
|
@ -759,14 +762,25 @@ B3_API int b3Body_GetContactData( b3BodyId bodyId, b3ContactData* contactData, i
|
|||
/// If there are no shapes attached then the returned AABB is empty and centered on the body origin.
|
||||
B3_API b3AABB b3Body_ComputeAABB( b3BodyId bodyId );
|
||||
|
||||
/// The minimum distance from any shape to the shape centroid.
|
||||
B3_API float b3Body_GetMinExtent( b3BodyId bodyId );
|
||||
|
||||
/// The maximum extent vector from any point on the body shapes to the center of mass.
|
||||
B3_API b3Vec3 b3Body_GetMaxExtent( b3BodyId bodyId );
|
||||
|
||||
/// The maximum extent vector from any point on the body shapes to the body origin. Conservative.
|
||||
B3_API b3Vec3 b3Body_GetMaxExtentOrigin( b3BodyId bodyId );
|
||||
|
||||
/// Get the closest point on a body to a world target.
|
||||
B3_API float b3Body_GetClosestPoint( b3BodyId bodyId, b3Vec3* result, b3Vec3 target );
|
||||
|
||||
/// Cast a ray at a specific body using a specified body transform.
|
||||
/// Ignores back-side collision on meshes and height-fields.
|
||||
B3_API b3BodyCastResult b3Body_CastRay( b3BodyId bodyId, b3Pos origin, b3Vec3 translation, b3QueryFilter filter,
|
||||
float maxFraction, b3WorldTransform bodyTransform );
|
||||
|
||||
/// Cast a shape at a specific body using a specified body transform.
|
||||
/// Ignores back-side collision on meshes and height-fields.
|
||||
B3_API b3BodyCastResult b3Body_CastShape( b3BodyId bodyId, b3Pos origin, const b3ShapeProxy* proxy, b3Vec3 translation,
|
||||
b3QueryFilter filter, float maxFraction, bool canEncroach,
|
||||
b3WorldTransform bodyTransform );
|
||||
|
|
@ -776,9 +790,17 @@ B3_API bool b3Body_OverlapShape( b3BodyId bodyId, b3Pos origin, const b3ShapePro
|
|||
b3WorldTransform bodyTransform );
|
||||
|
||||
/// Collide a character mover with a specific body using a specified body transform.
|
||||
/// Only considers convex shapes on the body.
|
||||
B3_API int b3Body_CollideMover( b3BodyId bodyId, b3BodyPlaneResult* bodyPlanes, int planeCapacity, b3Pos origin,
|
||||
const b3Capsule* mover, b3QueryFilter filter, b3WorldTransform bodyTransform );
|
||||
|
||||
/// Perform a time of impact between a character mover and a body using specified sweep transforms.
|
||||
/// Initial overlap of any shape on the body is ignored. A non-overlapped shape can still be hit.
|
||||
/// Only considers convex shapes on the body.
|
||||
B3_API b3BodyTOIResult b3Body_TimeOfImpactMover( b3BodyId bodyId, b3Pos origin, const b3Capsule* mover, b3Vec3 moverTranslation,
|
||||
b3QueryFilter filter, b3WorldTransform bodyTransform1,
|
||||
b3WorldTransform bodyTransform2 );
|
||||
|
||||
/** @} */ // body
|
||||
|
||||
/**
|
||||
|
|
@ -786,7 +808,7 @@ B3_API int b3Body_CollideMover( b3BodyId bodyId, b3BodyPlaneResult* bodyPlanes,
|
|||
* Functions to create, destroy, and access.
|
||||
* Shapes bind raw geometry to bodies and hold material properties including friction and restitution.
|
||||
* You may add multiple shapes to a single body. There are no hard limits on shape count per body.
|
||||
*
|
||||
*
|
||||
* When you create a shape on a body the center of mass moves. This can lead to the body linear velocity
|
||||
* changing if the angular velocity is non-zero.
|
||||
* @{
|
||||
|
|
@ -1076,6 +1098,9 @@ B3_API void* b3Joint_GetUserData( b3JointId jointId );
|
|||
/// Wake the bodies connect to this joint
|
||||
B3_API void b3Joint_WakeBodies( b3JointId jointId );
|
||||
|
||||
/// Is the joint awake? If true then an attached body is awake.
|
||||
B3_API bool b3Joint_IsAwake( b3JointId jointId );
|
||||
|
||||
/// Get the current constraint force for this joint
|
||||
B3_API b3Vec3 b3Joint_GetConstraintForce( b3JointId jointId );
|
||||
|
||||
|
|
@ -1552,7 +1577,9 @@ B3_API void b3SphericalJoint_EnableMotor( b3JointId jointId, bool enableMotor );
|
|||
/// Is the spherical joint motor enabled?
|
||||
B3_API bool b3SphericalJoint_IsMotorEnabled( b3JointId jointId );
|
||||
|
||||
/// Set the spherical joint motor velocity in radians per second
|
||||
/// Set the spherical joint motor velocity in radians per second. This is the relative angular
|
||||
/// velocity between the two bodies in world space.
|
||||
/// motorVelocity = angularVelocityB - angularVelocityA
|
||||
B3_API void b3SphericalJoint_SetMotorVelocity( b3JointId jointId, b3Vec3 motorVelocity );
|
||||
|
||||
/// Get the spherical joint motor velocity in radians per second
|
||||
|
|
|
|||
|
|
@ -137,3 +137,10 @@ B3_API float b3GetStallThreshold( void );
|
|||
#ifndef B3_RESTITUTION_ITERATIONS
|
||||
#define B3_RESTITUTION_ITERATIONS 1
|
||||
#endif
|
||||
|
||||
/// This is the limit on how many mesh or heightfield triangles a single convex shape can collide with.
|
||||
/// Increasing this will increase stack usage, so be careful. I recommend to simplify your collision data
|
||||
/// before increasing this. For example, using render mesh for collision often leads to poor performance.
|
||||
#ifndef B3_MAX_MESH_CONTACT_TRIANGLES
|
||||
#define B3_MAX_MESH_CONTACT_TRIANGLES 256
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -276,14 +276,12 @@ B3_INLINE float b3DistanceSquared( b3Vec3 a, b3Vec3 b )
|
|||
B3_FORCE_INLINE b3Vec3 b3Normalize( b3Vec3 a )
|
||||
{
|
||||
float lengthSquared = a.x * a.x + a.y * a.y + a.z * a.z;
|
||||
|
||||
if ( lengthSquared > 1000.0f * FLT_MIN )
|
||||
{
|
||||
float s = 1.0f / sqrtf( lengthSquared );
|
||||
b3Vec3 u = { s * a.x, s * a.y, s * a.z };
|
||||
return u;
|
||||
}
|
||||
|
||||
return B3_LITERAL( b3Vec3 ){ 0.0f, 0.0f, 0.0f };
|
||||
}
|
||||
|
||||
|
|
@ -291,15 +289,17 @@ B3_FORCE_INLINE b3Vec3 b3Normalize( b3Vec3 a )
|
|||
/// if the input is very small.
|
||||
B3_INLINE b3Vec3 b3GetLengthAndNormalize( float* length, b3Vec3 a )
|
||||
{
|
||||
*length = b3Length( a );
|
||||
if ( *length < FLT_EPSILON )
|
||||
float lengthSquared = a.x * a.x + a.y * a.y + a.z * a.z;
|
||||
if ( lengthSquared > 1000.0f * FLT_MIN )
|
||||
{
|
||||
return b3Vec3_zero;
|
||||
*length = sqrtf( lengthSquared );
|
||||
float s = 1.0f / *length;
|
||||
b3Vec3 u = { s * a.x, s * a.y, s * a.z };
|
||||
return u;
|
||||
}
|
||||
|
||||
float invLength = 1.0f / *length;
|
||||
b3Vec3 n = { invLength * a.x, invLength * a.y, invLength * a.z };
|
||||
return n;
|
||||
*length = 0.0f;
|
||||
return B3_LITERAL( b3Vec3 ){ 0.0f, 0.0f, 0.0f };
|
||||
}
|
||||
|
||||
/// Get a unit vector that is perpendicular to the supplied vector.
|
||||
|
|
@ -756,9 +756,10 @@ B3_INLINE b3WorldTransform b3MakeWorldTransform( b3Transform t )
|
|||
return w;
|
||||
}
|
||||
|
||||
/// Translate a local AABB by a world origin, rounding outward so the float box always contains
|
||||
/// the double box. Far from the origin a plain conversion could clip a shape out of its own box.
|
||||
/// In float mode the origin is float and the rounding is a no-op.
|
||||
/// Translate a local AABB by a world position, rounding outward so the single precision box
|
||||
/// encloses the double precision box. Far from the origin a plain conversion could clip a
|
||||
/// shape out of its own box.
|
||||
/// In single precision mode the the rounding is a no-op.
|
||||
B3_INLINE b3AABB b3OffsetAABB( b3AABB localBox, b3Pos origin )
|
||||
{
|
||||
b3AABB out;
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@
|
|||
#include "id.h"
|
||||
#include "math_functions.h"
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#define B3_DEFAULT_CATEGORY_BITS UINT64_MAX
|
||||
|
|
@ -912,7 +913,9 @@ typedef struct b3SphericalJointDef
|
|||
/// The maximum motor torque, typically in newton-meters. Non-negative number.
|
||||
float maxMotorTorque;
|
||||
|
||||
/// The desired motor angular velocity in radians per second.
|
||||
/// The desired motor angular velocity in radians per second. This is the relative angular
|
||||
/// velocity between the two bodies in world space.
|
||||
/// motorVelocity = angularVelocityB - angularVelocityA
|
||||
b3Vec3 motorVelocity;
|
||||
} b3SphericalJointDef;
|
||||
|
||||
|
|
@ -1620,31 +1623,31 @@ typedef enum b3TOIState
|
|||
b3_toiStateSeparated
|
||||
} b3TOIState;
|
||||
|
||||
/// Time of impact output
|
||||
/// Time of impact output.
|
||||
typedef struct b3TOIOutput
|
||||
{
|
||||
/// The type of result
|
||||
/// The type of result.
|
||||
b3TOIState state;
|
||||
|
||||
/// The hit point
|
||||
/// The hit point. A shared point if overlapped.
|
||||
b3Vec3 point;
|
||||
|
||||
/// The hit normal
|
||||
/// The hit normal. Zero if overlapped.
|
||||
b3Vec3 normal;
|
||||
|
||||
/// The sweep time of the collision
|
||||
/// The sweep time of the collision. 0 if overlapped.
|
||||
float fraction;
|
||||
|
||||
/// The final distance
|
||||
/// The final distance. 0 if overlapped.
|
||||
float distance;
|
||||
|
||||
/// Number of outer iterations
|
||||
/// Number of outer iterations.
|
||||
int distanceIterations;
|
||||
|
||||
/// Total number of push back iterations
|
||||
/// Total number of push back iterations.
|
||||
int pushBackIterations;
|
||||
|
||||
/// Total number of root iterations
|
||||
/// Total number of root iterations.
|
||||
int rootIterations;
|
||||
|
||||
/// Indicates that the time of impact detected initial
|
||||
|
|
@ -1817,6 +1820,15 @@ typedef struct b3PlaneResult
|
|||
/// Closest point on the shape. May not be unique.
|
||||
b3Vec3 point;
|
||||
|
||||
/// The index of the mesh or height field triangle hit.
|
||||
int triangleIndex;
|
||||
|
||||
/// The index of the compound child shape.
|
||||
int childIndex;
|
||||
|
||||
/// The material index.
|
||||
int materialIndex;
|
||||
|
||||
} b3PlaneResult;
|
||||
|
||||
/// These are collision planes that can be fed to b3SolvePlanes. Normally
|
||||
|
|
@ -1857,6 +1869,22 @@ typedef struct b3BodyPlaneResult
|
|||
b3PlaneResult result;
|
||||
} b3BodyPlaneResult;
|
||||
|
||||
/// Body time of impact result for movers.
|
||||
typedef struct b3BodyTOIResult
|
||||
{
|
||||
/// The hit point in world space.
|
||||
b3Pos point;
|
||||
|
||||
/// The hit normal. Points from the body to the mover.
|
||||
b3Vec3 normal;
|
||||
|
||||
/// The sweep time of the collision.
|
||||
float fraction;
|
||||
|
||||
/// The hit shape.
|
||||
b3ShapeId shapeId;
|
||||
} b3BodyTOIResult;
|
||||
|
||||
/// Used to collect collision planes for character movers.
|
||||
/// Return true to continue gathering planes.
|
||||
typedef bool b3PlaneResultFcn( b3ShapeId shapeId, const b3PlaneResult* plane, int planeCount, void* context );
|
||||
|
|
@ -2068,7 +2096,10 @@ typedef struct b3MeshDef
|
|||
/// Triangle vertices.
|
||||
b3Vec3* vertices;
|
||||
|
||||
/// Triangle vertex indices. 3 for each triangle. CCW winding.
|
||||
/// Stride between vertices. Use 0 for contiguous vertices.
|
||||
size_t stride;
|
||||
|
||||
/// Triangle vertex indices. 3 for each triangle. CCW winding unless CW is indicated below.
|
||||
int32_t* indices;
|
||||
|
||||
/// Triangle material index. 1 per triangle. Indexes into b3ShapeDef::materials.
|
||||
|
|
@ -2094,6 +2125,9 @@ typedef struct b3MeshDef
|
|||
|
||||
/// Compute triangle adjacency information using shared edges
|
||||
bool identifyEdges;
|
||||
|
||||
/// Input indices have clockWise winding order.
|
||||
bool clockWiseWinding;
|
||||
} b3MeshDef;
|
||||
|
||||
/// 64-bit mesh version. Useful for validating serialized data.
|
||||
|
|
|
|||
Loading…
Reference in a new issue