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