box2d 3.0.0
A 2D physics engine for games
 
Loading...
Searching...
No Matches
distance.h
1// SPDX-FileCopyrightText: 2023 Erin Catto
2// SPDX-License-Identifier: MIT
3
4#pragma once
5
6#include "constants.h"
7#include "types.h"
8
11{
12 b2Vec2 closest1;
13 b2Vec2 closest2;
14 float fraction1;
15 float fraction2;
16 float distanceSquared;
18
20BOX2D_API b2SegmentDistanceResult b2SegmentDistance(b2Vec2 p1, b2Vec2 q1, b2Vec2 p2, b2Vec2 q2);
21
23typedef struct b2DistanceProxy
24{
26 int32_t count;
27 float radius;
29
32typedef struct b2DistanceCache
33{
34 float metric;
35 uint16_t count;
36 uint8_t indexA[3];
37 uint8_t indexB[3];
39
40static const b2DistanceCache b2_emptyDistanceCache = B2_ZERO_INIT;
41
45typedef struct b2DistanceInput
46{
47 b2DistanceProxy proxyA;
48 b2DistanceProxy proxyB;
49 b2Transform transformA;
50 b2Transform transformB;
51 bool useRadii;
53
55typedef struct b2DistanceOutput
56{
59 float distance;
60 int32_t iterations;
62
66BOX2D_API b2DistanceOutput b2ShapeDistance(b2DistanceCache* cache, const b2DistanceInput* input);
67
70{
71 b2DistanceProxy proxyA;
72 b2DistanceProxy proxyB;
73 b2Transform transformA;
74 b2Transform transformB;
75 b2Vec2 translationB;
76 float maxFraction;
78
81BOX2D_API b2RayCastOutput b2ShapeCast(const b2ShapeCastPairInput* input);
82
84BOX2D_API b2DistanceProxy b2MakeProxy(const b2Vec2* vertices, int32_t count, float radius);
85
89typedef struct b2Sweep
90{
93
96
98 float a1, a2;
99} b2Sweep;
100
101BOX2D_API b2Transform b2GetSweepTransform(const b2Sweep* sweep, float time);
102
104typedef struct b2TOIInput
105{
106 b2DistanceProxy proxyA;
107 b2DistanceProxy proxyB;
108 b2Sweep sweepA;
109 b2Sweep sweepB;
110
111 // defines sweep interval [0, tMax]
112 float tMax;
113} b2TOIInput;
114
116typedef enum b2TOIState
117{
118 b2_toiStateUnknown,
119 b2_toiStateFailed,
120 b2_toiStateOverlapped,
121 b2_toiStateHit,
122 b2_toiStateSeparated
123} b2TOIState;
124
126typedef struct b2TOIOutput
127{
128 b2TOIState state;
129 float t;
131
136BOX2D_API b2TOIOutput b2TimeOfImpact(const b2TOIInput* input);
#define b2_maxPolygonVertices
Definition constants.h:47
Definition distance.h:33
uint8_t indexB[3]
vertices on shape B
Definition distance.h:37
uint8_t indexA[3]
vertices on shape A
Definition distance.h:36
float metric
length or area
Definition distance.h:34
Definition distance.h:46
Output for b2Distance.
Definition distance.h:56
int32_t iterations
number of GJK iterations used
Definition distance.h:60
b2Vec2 pointA
closest point on shapeA
Definition distance.h:57
b2Vec2 pointB
closest point on shapeB
Definition distance.h:58
A distance proxy is used by the GJK algorithm. It encapsulates any shape.
Definition distance.h:24
Result of computing the distance between two line segments.
Definition distance.h:11
Input parameters for b2ShapeCast.
Definition distance.h:70
Definition distance.h:90
b2Vec2 c1
center world positions
Definition distance.h:95
b2Vec2 localCenter
local center of mass position
Definition distance.h:92
float a1
world angles
Definition distance.h:98
Input parameters for b2TimeOfImpact.
Definition distance.h:105
Output parameters for b2TimeOfImpact.
Definition distance.h:127
types used by the Box2D API
#define B2_ZERO_INIT
Used for C zero initialization, such as b2Vec2 v = {0} where C++ requires b2Vec2 v = {}.
Definition types.h:32
Low level ray-cast or shape-cast output data.
Definition types.h:99
A 2D rigid transform.
Definition types.h:61
Definition types.h:47