Path: blob/master/modules/jolt_physics/joints/jolt_generic_6dof_joint_3d.h
10278 views
/**************************************************************************/1/* jolt_generic_6dof_joint_3d.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 "../jolt_physics_server_3d.h"33#include "jolt_joint_3d.h"3435#include "Jolt/Jolt.h"3637#include "Jolt/Physics/Constraints/SixDOFConstraint.h"3839class JoltGeneric6DOFJoint3D final : public JoltJoint3D {40typedef Vector3::Axis Axis;41typedef JPH::SixDOFConstraintSettings::EAxis JoltAxis;42typedef PhysicsServer3D::G6DOFJointAxisParam Param;43typedef JoltPhysicsServer3D::G6DOFJointAxisParamJolt JoltParam;44typedef PhysicsServer3D::G6DOFJointAxisFlag Flag;45typedef JoltPhysicsServer3D::G6DOFJointAxisFlagJolt JoltFlag;4647enum {48AXIS_LINEAR_X = JoltAxis::TranslationX,49AXIS_LINEAR_Y = JoltAxis::TranslationY,50AXIS_LINEAR_Z = JoltAxis::TranslationZ,51AXIS_ANGULAR_X = JoltAxis::RotationX,52AXIS_ANGULAR_Y = JoltAxis::RotationY,53AXIS_ANGULAR_Z = JoltAxis::RotationZ,54AXIS_COUNT = JoltAxis::Num,55AXES_LINEAR = AXIS_LINEAR_X,56AXES_ANGULAR = AXIS_ANGULAR_X,57};5859double limit_lower[AXIS_COUNT] = {};60double limit_upper[AXIS_COUNT] = {};6162double limit_spring_frequency[AXIS_COUNT] = {};63double limit_spring_damping[AXIS_COUNT] = {};6465double motor_speed[AXIS_COUNT] = {};66double motor_limit[AXIS_COUNT] = { FLT_MAX, FLT_MAX, FLT_MAX, FLT_MAX, FLT_MAX, FLT_MAX };6768double spring_stiffness[AXIS_COUNT] = {};69double spring_frequency[AXIS_COUNT] = {};70double spring_damping[AXIS_COUNT] = {};71double spring_equilibrium[AXIS_COUNT] = {};72double spring_limit[AXIS_COUNT] = { FLT_MAX, FLT_MAX, FLT_MAX, FLT_MAX, FLT_MAX, FLT_MAX };7374bool limit_enabled[AXIS_COUNT] = {};7576bool limit_spring_enabled[AXIS_COUNT] = {};7778bool motor_enabled[AXIS_COUNT] = {};7980bool spring_enabled[AXIS_COUNT] = {};81bool spring_use_frequency[AXIS_COUNT] = {};8283JPH::Constraint *_build_6dof(JPH::Body *p_jolt_body_a, JPH::Body *p_jolt_body_b, const Transform3D &p_shifted_ref_a, const Transform3D &p_shifted_ref_b) const;8485void _update_limit_spring_parameters(int p_axis);86void _update_motor_state(int p_axis);87void _update_motor_velocity(int p_axis);88void _update_motor_limit(int p_axis);89void _update_spring_parameters(int p_axis);90void _update_spring_equilibrium(int p_axis);9192void _limits_changed();93void _limit_spring_parameters_changed(int p_axis);94void _motor_state_changed(int p_axis);95void _motor_speed_changed(int p_axis);96void _motor_limit_changed(int p_axis);97void _spring_state_changed(int p_axis);98void _spring_parameters_changed(int p_axis);99void _spring_equilibrium_changed(int p_axis);100void _spring_limit_changed(int p_axis);101102public:103JoltGeneric6DOFJoint3D(const JoltJoint3D &p_old_joint, JoltBody3D *p_body_a, JoltBody3D *p_body_b, const Transform3D &p_local_ref_a, const Transform3D &p_local_ref_b);104105virtual PhysicsServer3D::JointType get_type() const override { return PhysicsServer3D::JOINT_TYPE_6DOF; }106107double get_param(Axis p_axis, Param p_param) const;108void set_param(Axis p_axis, Param p_param, double p_value);109110bool get_flag(Axis p_axis, Flag p_flag) const;111void set_flag(Axis p_axis, Flag p_flag, bool p_enabled);112113double get_jolt_param(Axis p_axis, JoltParam p_param) const;114void set_jolt_param(Axis p_axis, JoltParam p_param, double p_value);115116bool get_jolt_flag(Axis p_axis, JoltFlag p_flag) const;117void set_jolt_flag(Axis p_axis, JoltFlag p_flag, bool p_enabled);118119float get_applied_force() const;120float get_applied_torque() const;121122virtual void rebuild() override;123};124125126