Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/modules/godot_physics_2d/godot_body_pair_2d.h
10277 views
1
/**************************************************************************/
2
/* godot_body_pair_2d.h */
3
/**************************************************************************/
4
/* This file is part of: */
5
/* GODOT ENGINE */
6
/* https://godotengine.org */
7
/**************************************************************************/
8
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
9
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
10
/* */
11
/* Permission is hereby granted, free of charge, to any person obtaining */
12
/* a copy of this software and associated documentation files (the */
13
/* "Software"), to deal in the Software without restriction, including */
14
/* without limitation the rights to use, copy, modify, merge, publish, */
15
/* distribute, sublicense, and/or sell copies of the Software, and to */
16
/* permit persons to whom the Software is furnished to do so, subject to */
17
/* the following conditions: */
18
/* */
19
/* The above copyright notice and this permission notice shall be */
20
/* included in all copies or substantial portions of the Software. */
21
/* */
22
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
23
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
24
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
25
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
26
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
27
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
28
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
29
/**************************************************************************/
30
31
#pragma once
32
33
#include "godot_body_2d.h"
34
#include "godot_constraint_2d.h"
35
36
class GodotBodyPair2D : public GodotConstraint2D {
37
enum {
38
MAX_CONTACTS = 2
39
};
40
union {
41
struct {
42
GodotBody2D *A;
43
GodotBody2D *B;
44
};
45
46
GodotBody2D *_arr[2] = { nullptr, nullptr };
47
};
48
49
int shape_A = 0;
50
int shape_B = 0;
51
52
bool collide_A = false;
53
bool collide_B = false;
54
55
GodotSpace2D *space = nullptr;
56
57
struct Contact {
58
Vector2 position;
59
Vector2 normal;
60
Vector2 local_A, local_B;
61
Vector2 acc_impulse; // accumulated impulse
62
real_t acc_normal_impulse = 0.0; // accumulated normal impulse (Pn)
63
real_t acc_tangent_impulse = 0.0; // accumulated tangent impulse (Pt)
64
real_t acc_bias_impulse = 0.0; // accumulated normal impulse for position bias (Pnb)
65
real_t acc_bias_impulse_center_of_mass = 0.0; // accumulated normal impulse for position bias applied to com
66
real_t mass_normal, mass_tangent = 0.0;
67
real_t bias = 0.0;
68
69
real_t depth = 0.0;
70
bool active = false;
71
bool used = false;
72
Vector2 rA, rB;
73
real_t bounce = 0.0;
74
};
75
76
Vector2 offset_B; //use local A coordinates to avoid numerical issues on collision detection
77
78
Vector2 sep_axis;
79
Contact contacts[MAX_CONTACTS];
80
int contact_count = 0;
81
bool collided = false;
82
bool check_ccd = false;
83
bool oneway_disabled = false;
84
bool report_contacts_only = false;
85
86
bool _test_ccd(real_t p_step, GodotBody2D *p_A, int p_shape_A, const Transform2D &p_xform_A, GodotBody2D *p_B, int p_shape_B, const Transform2D &p_xform_B);
87
void _validate_contacts();
88
static void _add_contact(const Vector2 &p_point_A, const Vector2 &p_point_B, void *p_self);
89
_FORCE_INLINE_ void _contact_added_callback(const Vector2 &p_point_A, const Vector2 &p_point_B);
90
91
public:
92
virtual bool setup(real_t p_step) override;
93
virtual bool pre_solve(real_t p_step) override;
94
virtual void solve(real_t p_step) override;
95
96
GodotBodyPair2D(GodotBody2D *p_A, int p_shape_A, GodotBody2D *p_B, int p_shape_B);
97
~GodotBodyPair2D();
98
};
99
100