2014-02-10 09:10:30 +08:00
|
|
|
/*************************************************************************/
|
|
|
|
/* joints_2d_sw.h */
|
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
2017-08-27 20:16:55 +08:00
|
|
|
/* https://godotengine.org */
|
2014-02-10 09:10:30 +08:00
|
|
|
/*************************************************************************/
|
2020-01-01 18:16:22 +08:00
|
|
|
/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
|
2014-02-10 09:10:30 +08:00
|
|
|
/* */
|
|
|
|
/* Permission is hereby granted, free of charge, to any person obtaining */
|
|
|
|
/* a copy of this software and associated documentation files (the */
|
|
|
|
/* "Software"), to deal in the Software without restriction, including */
|
|
|
|
/* without limitation the rights to use, copy, modify, merge, publish, */
|
|
|
|
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
|
|
|
/* permit persons to whom the Software is furnished to do so, subject to */
|
|
|
|
/* the following conditions: */
|
|
|
|
/* */
|
|
|
|
/* The above copyright notice and this permission notice shall be */
|
|
|
|
/* included in all copies or substantial portions of the Software. */
|
|
|
|
/* */
|
|
|
|
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
|
|
|
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
|
|
|
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
|
|
|
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
|
|
|
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
|
|
|
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
|
|
|
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
|
|
|
/*************************************************************************/
|
2018-01-05 07:50:27 +08:00
|
|
|
|
2014-02-10 09:10:30 +08:00
|
|
|
#ifndef JOINTS_2D_SW_H
|
|
|
|
#define JOINTS_2D_SW_H
|
|
|
|
|
|
|
|
#include "body_2d_sw.h"
|
2017-03-05 23:44:50 +08:00
|
|
|
#include "constraint_2d_sw.h"
|
2014-02-10 09:10:30 +08:00
|
|
|
|
|
|
|
class Joint2DSW : public Constraint2DSW {
|
|
|
|
real_t max_force;
|
|
|
|
real_t bias;
|
|
|
|
real_t max_bias;
|
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
public:
|
|
|
|
_FORCE_INLINE_ void set_max_force(real_t p_force) { max_force = p_force; }
|
2014-02-10 09:10:30 +08:00
|
|
|
_FORCE_INLINE_ real_t get_max_force() const { return max_force; }
|
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
_FORCE_INLINE_ void set_bias(real_t p_bias) { bias = p_bias; }
|
2014-02-10 09:10:30 +08:00
|
|
|
_FORCE_INLINE_ real_t get_bias() const { return bias; }
|
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
_FORCE_INLINE_ void set_max_bias(real_t p_bias) { max_bias = p_bias; }
|
2014-02-10 09:10:30 +08:00
|
|
|
_FORCE_INLINE_ real_t get_max_bias() const { return max_bias; }
|
|
|
|
|
2020-03-28 02:21:27 +08:00
|
|
|
virtual PhysicsServer2D::JointType get_type() const = 0;
|
2020-04-02 07:20:12 +08:00
|
|
|
Joint2DSW(Body2DSW **p_body_ptr = nullptr, int p_body_count = 0) :
|
2017-12-07 04:36:34 +08:00
|
|
|
Constraint2DSW(p_body_ptr, p_body_count) {
|
2017-03-05 23:44:50 +08:00
|
|
|
bias = 0;
|
|
|
|
max_force = max_bias = 3.40282e+38;
|
|
|
|
};
|
2014-02-10 09:10:30 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
class PinJoint2DSW : public Joint2DSW {
|
|
|
|
union {
|
|
|
|
struct {
|
|
|
|
Body2DSW *A;
|
|
|
|
Body2DSW *B;
|
|
|
|
};
|
|
|
|
|
|
|
|
Body2DSW *_arr[2];
|
|
|
|
};
|
|
|
|
|
2017-01-11 11:52:51 +08:00
|
|
|
Transform2D M;
|
2017-03-05 23:44:50 +08:00
|
|
|
Vector2 rA, rB;
|
2014-02-10 09:10:30 +08:00
|
|
|
Vector2 anchor_A;
|
|
|
|
Vector2 anchor_B;
|
|
|
|
Vector2 bias;
|
|
|
|
Vector2 P;
|
|
|
|
real_t softness;
|
|
|
|
|
|
|
|
public:
|
2020-03-28 02:21:27 +08:00
|
|
|
virtual PhysicsServer2D::JointType get_type() const { return PhysicsServer2D::JOINT_PIN; }
|
2014-02-10 09:10:30 +08:00
|
|
|
|
2017-02-14 07:25:05 +08:00
|
|
|
virtual bool setup(real_t p_step);
|
|
|
|
virtual void solve(real_t p_step);
|
2014-02-10 09:10:30 +08:00
|
|
|
|
2020-03-28 02:21:27 +08:00
|
|
|
void set_param(PhysicsServer2D::PinJointParam p_param, real_t p_value);
|
|
|
|
real_t get_param(PhysicsServer2D::PinJointParam p_param) const;
|
2014-02-10 09:10:30 +08:00
|
|
|
|
2020-04-02 07:20:12 +08:00
|
|
|
PinJoint2DSW(const Vector2 &p_pos, Body2DSW *p_body_a, Body2DSW *p_body_b = nullptr);
|
2014-02-10 09:10:30 +08:00
|
|
|
~PinJoint2DSW();
|
|
|
|
};
|
|
|
|
|
|
|
|
class GrooveJoint2DSW : public Joint2DSW {
|
|
|
|
union {
|
|
|
|
struct {
|
|
|
|
Body2DSW *A;
|
|
|
|
Body2DSW *B;
|
|
|
|
};
|
|
|
|
|
|
|
|
Body2DSW *_arr[2];
|
|
|
|
};
|
|
|
|
|
|
|
|
Vector2 A_groove_1;
|
|
|
|
Vector2 A_groove_2;
|
|
|
|
Vector2 A_groove_normal;
|
|
|
|
Vector2 B_anchor;
|
|
|
|
Vector2 jn_acc;
|
|
|
|
Vector2 gbias;
|
|
|
|
real_t jn_max;
|
|
|
|
real_t clamp;
|
|
|
|
Vector2 xf_normal;
|
2017-03-05 23:44:50 +08:00
|
|
|
Vector2 rA, rB;
|
|
|
|
Vector2 k1, k2;
|
2014-02-10 09:10:30 +08:00
|
|
|
|
|
|
|
bool correct;
|
|
|
|
|
|
|
|
public:
|
2020-03-28 02:21:27 +08:00
|
|
|
virtual PhysicsServer2D::JointType get_type() const { return PhysicsServer2D::JOINT_GROOVE; }
|
2014-02-10 09:10:30 +08:00
|
|
|
|
2017-02-14 07:25:05 +08:00
|
|
|
virtual bool setup(real_t p_step);
|
|
|
|
virtual void solve(real_t p_step);
|
2014-02-10 09:10:30 +08:00
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
GrooveJoint2DSW(const Vector2 &p_a_groove1, const Vector2 &p_a_groove2, const Vector2 &p_b_anchor, Body2DSW *p_body_a, Body2DSW *p_body_b);
|
2014-02-10 09:10:30 +08:00
|
|
|
~GrooveJoint2DSW();
|
|
|
|
};
|
|
|
|
|
|
|
|
class DampedSpringJoint2DSW : public Joint2DSW {
|
|
|
|
union {
|
|
|
|
struct {
|
|
|
|
Body2DSW *A;
|
|
|
|
Body2DSW *B;
|
|
|
|
};
|
|
|
|
|
|
|
|
Body2DSW *_arr[2];
|
|
|
|
};
|
|
|
|
|
|
|
|
Vector2 anchor_A;
|
|
|
|
Vector2 anchor_B;
|
|
|
|
|
|
|
|
real_t rest_length;
|
|
|
|
real_t damping;
|
|
|
|
real_t stiffness;
|
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
Vector2 rA, rB;
|
2014-02-10 09:10:30 +08:00
|
|
|
Vector2 n;
|
|
|
|
real_t n_mass;
|
|
|
|
real_t target_vrn;
|
|
|
|
real_t v_coef;
|
|
|
|
|
|
|
|
public:
|
2020-03-28 02:21:27 +08:00
|
|
|
virtual PhysicsServer2D::JointType get_type() const { return PhysicsServer2D::JOINT_DAMPED_SPRING; }
|
2014-02-10 09:10:30 +08:00
|
|
|
|
2017-02-14 07:25:05 +08:00
|
|
|
virtual bool setup(real_t p_step);
|
|
|
|
virtual void solve(real_t p_step);
|
2014-02-10 09:10:30 +08:00
|
|
|
|
2020-06-05 00:53:29 +08:00
|
|
|
void set_param(PhysicsServer2D::DampedSpringParam p_param, real_t p_value);
|
|
|
|
real_t get_param(PhysicsServer2D::DampedSpringParam p_param) const;
|
2014-02-10 09:10:30 +08:00
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
DampedSpringJoint2DSW(const Vector2 &p_anchor_a, const Vector2 &p_anchor_b, Body2DSW *p_body_a, Body2DSW *p_body_b);
|
2014-02-10 09:10:30 +08:00
|
|
|
~DampedSpringJoint2DSW();
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // JOINTS_2D_SW_H
|