2016-06-18 14:46:12 +02:00
|
|
|
/*************************************************************************/
|
2020-03-28 13:19:05 +01:00
|
|
|
/* slider_joint_3d_sw.cpp */
|
2016-06-18 14:46:12 +02:00
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
2017-08-27 14:16:55 +02:00
|
|
|
/* https://godotengine.org */
|
2016-06-18 14:46:12 +02:00
|
|
|
/*************************************************************************/
|
2020-01-01 11:16:22 +01:00
|
|
|
/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
|
2016-06-18 14:46:12 +02: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. */
|
|
|
|
/*************************************************************************/
|
|
|
|
|
|
|
|
/*
|
|
|
|
Adapted to Godot from the Bullet library.
|
2017-05-06 23:38:44 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
Bullet Continuous Collision Detection and Physics Library
|
|
|
|
Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
|
|
|
|
|
|
|
|
This software is provided 'as-is', without any express or implied warranty.
|
|
|
|
In no event will the authors be held liable for any damages arising from the use of this software.
|
|
|
|
Permission is granted to anyone to use this software for any purpose,
|
|
|
|
including commercial applications, and to alter it and redistribute it freely,
|
|
|
|
subject to the following restrictions:
|
|
|
|
|
|
|
|
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
|
|
|
|
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
|
|
|
|
3. This notice may not be removed or altered from any source distribution.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
Added by Roman Ponomarev (rponom@gmail.com)
|
|
|
|
April 04, 2008
|
|
|
|
|
2016-06-18 14:46:12 +02:00
|
|
|
*/
|
|
|
|
|
2020-03-27 19:21:27 +01:00
|
|
|
#include "slider_joint_3d_sw.h"
|
2014-09-15 16:33:30 +02:00
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
static _FORCE_INLINE_ real_t atan2fast(real_t y, real_t x) {
|
2014-09-15 16:33:30 +02:00
|
|
|
real_t coeff_1 = Math_PI / 4.0f;
|
|
|
|
real_t coeff_2 = 3.0f * coeff_1;
|
|
|
|
real_t abs_y = Math::abs(y);
|
|
|
|
real_t angle;
|
|
|
|
if (x >= 0.0f) {
|
|
|
|
real_t r = (x - abs_y) / (x + abs_y);
|
|
|
|
angle = coeff_1 - coeff_1 * r;
|
|
|
|
} else {
|
|
|
|
real_t r = (x + abs_y) / (abs_y - x);
|
|
|
|
angle = coeff_2 - coeff_1 * r;
|
|
|
|
}
|
|
|
|
return (y < 0.0f) ? -angle : angle;
|
|
|
|
}
|
|
|
|
|
2020-03-27 19:21:27 +01:00
|
|
|
void SliderJoint3DSW::initParams() {
|
2017-03-05 16:44:50 +01:00
|
|
|
m_lowerLinLimit = real_t(1.0);
|
|
|
|
m_upperLinLimit = real_t(-1.0);
|
|
|
|
m_lowerAngLimit = real_t(0.);
|
|
|
|
m_upperAngLimit = real_t(0.);
|
2014-09-15 16:33:30 +02:00
|
|
|
m_softnessDirLin = SLIDER_CONSTRAINT_DEF_SOFTNESS;
|
|
|
|
m_restitutionDirLin = SLIDER_CONSTRAINT_DEF_RESTITUTION;
|
|
|
|
m_dampingDirLin = real_t(0.);
|
|
|
|
m_softnessDirAng = SLIDER_CONSTRAINT_DEF_SOFTNESS;
|
|
|
|
m_restitutionDirAng = SLIDER_CONSTRAINT_DEF_RESTITUTION;
|
|
|
|
m_dampingDirAng = real_t(0.);
|
|
|
|
m_softnessOrthoLin = SLIDER_CONSTRAINT_DEF_SOFTNESS;
|
|
|
|
m_restitutionOrthoLin = SLIDER_CONSTRAINT_DEF_RESTITUTION;
|
|
|
|
m_dampingOrthoLin = SLIDER_CONSTRAINT_DEF_DAMPING;
|
|
|
|
m_softnessOrthoAng = SLIDER_CONSTRAINT_DEF_SOFTNESS;
|
|
|
|
m_restitutionOrthoAng = SLIDER_CONSTRAINT_DEF_RESTITUTION;
|
|
|
|
m_dampingOrthoAng = SLIDER_CONSTRAINT_DEF_DAMPING;
|
|
|
|
m_softnessLimLin = SLIDER_CONSTRAINT_DEF_SOFTNESS;
|
|
|
|
m_restitutionLimLin = SLIDER_CONSTRAINT_DEF_RESTITUTION;
|
|
|
|
m_dampingLimLin = SLIDER_CONSTRAINT_DEF_DAMPING;
|
|
|
|
m_softnessLimAng = SLIDER_CONSTRAINT_DEF_SOFTNESS;
|
|
|
|
m_restitutionLimAng = SLIDER_CONSTRAINT_DEF_RESTITUTION;
|
|
|
|
m_dampingLimAng = SLIDER_CONSTRAINT_DEF_DAMPING;
|
|
|
|
|
|
|
|
m_poweredLinMotor = false;
|
|
|
|
m_targetLinMotorVelocity = real_t(0.);
|
|
|
|
m_maxLinMotorForce = real_t(0.);
|
|
|
|
m_accumulatedLinMotorImpulse = real_t(0.0);
|
|
|
|
|
|
|
|
m_poweredAngMotor = false;
|
2017-03-05 16:44:50 +01:00
|
|
|
m_targetAngMotorVelocity = real_t(0.);
|
|
|
|
m_maxAngMotorForce = real_t(0.);
|
2014-09-15 16:33:30 +02:00
|
|
|
m_accumulatedAngMotorImpulse = real_t(0.0);
|
|
|
|
|
|
|
|
} // SliderJointSW::initParams()
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2020-03-27 19:21:27 +01:00
|
|
|
SliderJoint3DSW::SliderJoint3DSW(Body3DSW *rbA, Body3DSW *rbB, const Transform &frameInA, const Transform &frameInB) :
|
|
|
|
Joint3DSW(_arr, 2),
|
2017-12-06 21:36:34 +01:00
|
|
|
m_frameInA(frameInA),
|
|
|
|
m_frameInB(frameInB) {
|
2017-03-05 16:44:50 +01:00
|
|
|
A = rbA;
|
|
|
|
B = rbB;
|
2014-09-15 16:33:30 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
A->add_constraint(this, 0);
|
|
|
|
B->add_constraint(this, 1);
|
2014-09-15 16:33:30 +02:00
|
|
|
|
|
|
|
initParams();
|
|
|
|
} // SliderJointSW::SliderJointSW()
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2020-03-27 19:21:27 +01:00
|
|
|
bool SliderJoint3DSW::setup(real_t p_step) {
|
2014-09-15 16:33:30 +02:00
|
|
|
//calculate transforms
|
2017-03-05 16:44:50 +01:00
|
|
|
m_calculatedTransformA = A->get_transform() * m_frameInA;
|
|
|
|
m_calculatedTransformB = B->get_transform() * m_frameInB;
|
2014-09-15 16:33:30 +02:00
|
|
|
m_realPivotAInW = m_calculatedTransformA.origin;
|
|
|
|
m_realPivotBInW = m_calculatedTransformB.origin;
|
|
|
|
m_sliderAxis = m_calculatedTransformA.basis.get_axis(0); // along X
|
|
|
|
m_delta = m_realPivotBInW - m_realPivotAInW;
|
|
|
|
m_projPivotInW = m_realPivotAInW + m_sliderAxis.dot(m_delta) * m_sliderAxis;
|
|
|
|
m_relPosA = m_projPivotInW - A->get_transform().origin;
|
|
|
|
m_relPosB = m_realPivotBInW - B->get_transform().origin;
|
2017-03-05 16:44:50 +01:00
|
|
|
Vector3 normalWorld;
|
|
|
|
int i;
|
|
|
|
//linear part
|
|
|
|
for (i = 0; i < 3; i++) {
|
2014-09-15 16:33:30 +02:00
|
|
|
normalWorld = m_calculatedTransformA.basis.get_axis(i);
|
2020-03-27 19:21:27 +01:00
|
|
|
memnew_placement(&m_jacLin[i], JacobianEntry3DSW(
|
2017-03-05 16:44:50 +01:00
|
|
|
A->get_principal_inertia_axes().transposed(),
|
|
|
|
B->get_principal_inertia_axes().transposed(),
|
|
|
|
m_relPosA - A->get_center_of_mass(),
|
|
|
|
m_relPosB - B->get_center_of_mass(),
|
|
|
|
normalWorld,
|
|
|
|
A->get_inv_inertia(),
|
|
|
|
A->get_inv_mass(),
|
|
|
|
B->get_inv_inertia(),
|
|
|
|
B->get_inv_mass()));
|
2014-09-15 16:33:30 +02:00
|
|
|
m_jacLinDiagABInv[i] = real_t(1.) / m_jacLin[i].getDiagonal();
|
|
|
|
m_depth[i] = m_delta.dot(normalWorld);
|
2017-03-05 16:44:50 +01:00
|
|
|
}
|
2014-09-15 16:33:30 +02:00
|
|
|
testLinLimits();
|
2017-03-05 16:44:50 +01:00
|
|
|
// angular part
|
|
|
|
for (i = 0; i < 3; i++) {
|
2014-09-15 16:33:30 +02:00
|
|
|
normalWorld = m_calculatedTransformA.basis.get_axis(i);
|
2020-03-27 19:21:27 +01:00
|
|
|
memnew_placement(&m_jacAng[i], JacobianEntry3DSW(
|
2017-03-05 16:44:50 +01:00
|
|
|
normalWorld,
|
|
|
|
A->get_principal_inertia_axes().transposed(),
|
|
|
|
B->get_principal_inertia_axes().transposed(),
|
|
|
|
A->get_inv_inertia(),
|
|
|
|
B->get_inv_inertia()));
|
2014-09-15 16:33:30 +02:00
|
|
|
}
|
|
|
|
testAngLimits();
|
|
|
|
Vector3 axisA = m_calculatedTransformA.basis.get_axis(0);
|
2017-03-05 16:44:50 +01:00
|
|
|
m_kAngle = real_t(1.0) / (A->compute_angular_impulse_denominator(axisA) + B->compute_angular_impulse_denominator(axisA));
|
2014-09-15 16:33:30 +02:00
|
|
|
// clear accumulator for motors
|
|
|
|
m_accumulatedLinMotorImpulse = real_t(0.0);
|
|
|
|
m_accumulatedAngMotorImpulse = real_t(0.0);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
} // SliderJointSW::buildJacobianInt()
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2020-03-27 19:21:27 +01:00
|
|
|
void SliderJoint3DSW::solve(real_t p_step) {
|
2017-03-05 16:44:50 +01:00
|
|
|
int i;
|
|
|
|
// linear
|
|
|
|
Vector3 velA = A->get_velocity_in_local_point(m_relPosA);
|
|
|
|
Vector3 velB = B->get_velocity_in_local_point(m_relPosB);
|
|
|
|
Vector3 vel = velA - velB;
|
|
|
|
for (i = 0; i < 3; i++) {
|
|
|
|
const Vector3 &normal = m_jacLin[i].m_linearJointAxis;
|
2014-09-15 16:33:30 +02:00
|
|
|
real_t rel_vel = normal.dot(vel);
|
|
|
|
// calculate positional error
|
|
|
|
real_t depth = m_depth[i];
|
|
|
|
// get parameters
|
|
|
|
real_t softness = (i) ? m_softnessOrthoLin : (m_solveLinLim ? m_softnessLimLin : m_softnessDirLin);
|
|
|
|
real_t restitution = (i) ? m_restitutionOrthoLin : (m_solveLinLim ? m_restitutionLimLin : m_restitutionDirLin);
|
|
|
|
real_t damping = (i) ? m_dampingOrthoLin : (m_solveLinLim ? m_dampingLimLin : m_dampingDirLin);
|
|
|
|
// calcutate and apply impulse
|
|
|
|
real_t normalImpulse = softness * (restitution * depth / p_step - damping * rel_vel) * m_jacLinDiagABInv[i];
|
|
|
|
Vector3 impulse_vector = normal * normalImpulse;
|
2017-03-05 16:44:50 +01:00
|
|
|
A->apply_impulse(m_relPosA, impulse_vector);
|
|
|
|
B->apply_impulse(m_relPosB, -impulse_vector);
|
|
|
|
if (m_poweredLinMotor && (!i)) { // apply linear motor
|
|
|
|
if (m_accumulatedLinMotorImpulse < m_maxLinMotorForce) {
|
2014-09-15 16:33:30 +02:00
|
|
|
real_t desiredMotorVel = m_targetLinMotorVelocity;
|
|
|
|
real_t motor_relvel = desiredMotorVel + rel_vel;
|
|
|
|
normalImpulse = -motor_relvel * m_jacLinDiagABInv[i];
|
|
|
|
// clamp accumulated impulse
|
|
|
|
real_t new_acc = m_accumulatedLinMotorImpulse + Math::abs(normalImpulse);
|
2017-03-05 16:44:50 +01:00
|
|
|
if (new_acc > m_maxLinMotorForce) {
|
2014-09-15 16:33:30 +02:00
|
|
|
new_acc = m_maxLinMotorForce;
|
|
|
|
}
|
2017-03-05 16:44:50 +01:00
|
|
|
real_t del = new_acc - m_accumulatedLinMotorImpulse;
|
|
|
|
if (normalImpulse < real_t(0.0)) {
|
2014-09-15 16:33:30 +02:00
|
|
|
normalImpulse = -del;
|
2017-03-05 16:44:50 +01:00
|
|
|
} else {
|
2014-09-15 16:33:30 +02:00
|
|
|
normalImpulse = del;
|
|
|
|
}
|
|
|
|
m_accumulatedLinMotorImpulse = new_acc;
|
|
|
|
// apply clamped impulse
|
|
|
|
impulse_vector = normal * normalImpulse;
|
2017-03-05 16:44:50 +01:00
|
|
|
A->apply_impulse(m_relPosA, impulse_vector);
|
|
|
|
B->apply_impulse(m_relPosB, -impulse_vector);
|
2014-09-15 16:33:30 +02:00
|
|
|
}
|
|
|
|
}
|
2017-03-05 16:44:50 +01:00
|
|
|
}
|
2014-09-15 16:33:30 +02:00
|
|
|
// angular
|
|
|
|
// get axes in world space
|
2017-03-05 16:44:50 +01:00
|
|
|
Vector3 axisA = m_calculatedTransformA.basis.get_axis(0);
|
|
|
|
Vector3 axisB = m_calculatedTransformB.basis.get_axis(0);
|
2014-09-15 16:33:30 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
const Vector3 &angVelA = A->get_angular_velocity();
|
|
|
|
const Vector3 &angVelB = B->get_angular_velocity();
|
2014-09-15 16:33:30 +02:00
|
|
|
|
|
|
|
Vector3 angVelAroundAxisA = axisA * axisA.dot(angVelA);
|
|
|
|
Vector3 angVelAroundAxisB = axisB * axisB.dot(angVelB);
|
|
|
|
|
|
|
|
Vector3 angAorthog = angVelA - angVelAroundAxisA;
|
|
|
|
Vector3 angBorthog = angVelB - angVelAroundAxisB;
|
2017-03-05 16:44:50 +01:00
|
|
|
Vector3 velrelOrthog = angAorthog - angBorthog;
|
2014-09-15 16:33:30 +02:00
|
|
|
//solve orthogonal angular velocity correction
|
|
|
|
real_t len = velrelOrthog.length();
|
2017-03-05 16:44:50 +01:00
|
|
|
if (len > real_t(0.00001)) {
|
2014-09-15 16:33:30 +02:00
|
|
|
Vector3 normal = velrelOrthog.normalized();
|
|
|
|
real_t denom = A->compute_angular_impulse_denominator(normal) + B->compute_angular_impulse_denominator(normal);
|
2017-03-05 16:44:50 +01:00
|
|
|
velrelOrthog *= (real_t(1.) / denom) * m_dampingOrthoAng * m_softnessOrthoAng;
|
2014-09-15 16:33:30 +02:00
|
|
|
}
|
|
|
|
//solve angular positional correction
|
2017-03-05 16:44:50 +01:00
|
|
|
Vector3 angularError = axisA.cross(axisB) * (real_t(1.) / p_step);
|
2014-09-15 16:33:30 +02:00
|
|
|
real_t len2 = angularError.length();
|
2017-03-05 16:44:50 +01:00
|
|
|
if (len2 > real_t(0.00001)) {
|
2014-09-15 16:33:30 +02:00
|
|
|
Vector3 normal2 = angularError.normalized();
|
|
|
|
real_t denom2 = A->compute_angular_impulse_denominator(normal2) + B->compute_angular_impulse_denominator(normal2);
|
2017-03-05 16:44:50 +01:00
|
|
|
angularError *= (real_t(1.) / denom2) * m_restitutionOrthoAng * m_softnessOrthoAng;
|
2014-09-15 16:33:30 +02:00
|
|
|
}
|
|
|
|
// apply impulse
|
2017-03-05 16:44:50 +01:00
|
|
|
A->apply_torque_impulse(-velrelOrthog + angularError);
|
|
|
|
B->apply_torque_impulse(velrelOrthog - angularError);
|
2014-09-15 16:33:30 +02:00
|
|
|
real_t impulseMag;
|
|
|
|
//solve angular limits
|
2017-03-05 16:44:50 +01:00
|
|
|
if (m_solveAngLim) {
|
2014-09-15 16:33:30 +02:00
|
|
|
impulseMag = (angVelB - angVelA).dot(axisA) * m_dampingLimAng + m_angDepth * m_restitutionLimAng / p_step;
|
|
|
|
impulseMag *= m_kAngle * m_softnessLimAng;
|
2017-03-05 16:44:50 +01:00
|
|
|
} else {
|
2014-09-15 16:33:30 +02:00
|
|
|
impulseMag = (angVelB - angVelA).dot(axisA) * m_dampingDirAng + m_angDepth * m_restitutionDirAng / p_step;
|
|
|
|
impulseMag *= m_kAngle * m_softnessDirAng;
|
|
|
|
}
|
|
|
|
Vector3 impulse = axisA * impulseMag;
|
|
|
|
A->apply_torque_impulse(impulse);
|
|
|
|
B->apply_torque_impulse(-impulse);
|
|
|
|
//apply angular motor
|
2017-03-05 16:44:50 +01:00
|
|
|
if (m_poweredAngMotor) {
|
|
|
|
if (m_accumulatedAngMotorImpulse < m_maxAngMotorForce) {
|
2014-09-15 16:33:30 +02:00
|
|
|
Vector3 velrel = angVelAroundAxisA - angVelAroundAxisB;
|
|
|
|
real_t projRelVel = velrel.dot(axisA);
|
|
|
|
|
|
|
|
real_t desiredMotorVel = m_targetAngMotorVelocity;
|
|
|
|
real_t motor_relvel = desiredMotorVel - projRelVel;
|
|
|
|
|
|
|
|
real_t angImpulse = m_kAngle * motor_relvel;
|
|
|
|
// clamp accumulated impulse
|
|
|
|
real_t new_acc = m_accumulatedAngMotorImpulse + Math::abs(angImpulse);
|
2017-03-05 16:44:50 +01:00
|
|
|
if (new_acc > m_maxAngMotorForce) {
|
2014-09-15 16:33:30 +02:00
|
|
|
new_acc = m_maxAngMotorForce;
|
|
|
|
}
|
2017-03-05 16:44:50 +01:00
|
|
|
real_t del = new_acc - m_accumulatedAngMotorImpulse;
|
|
|
|
if (angImpulse < real_t(0.0)) {
|
2014-09-15 16:33:30 +02:00
|
|
|
angImpulse = -del;
|
2017-03-05 16:44:50 +01:00
|
|
|
} else {
|
2014-09-15 16:33:30 +02:00
|
|
|
angImpulse = del;
|
|
|
|
}
|
|
|
|
m_accumulatedAngMotorImpulse = new_acc;
|
|
|
|
// apply clamped impulse
|
|
|
|
Vector3 motorImp = angImpulse * axisA;
|
|
|
|
A->apply_torque_impulse(motorImp);
|
|
|
|
B->apply_torque_impulse(-motorImp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} // SliderJointSW::solveConstraint()
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2020-05-14 11:11:27 +02:00
|
|
|
void SliderJoint3DSW::calculateTransforms() {
|
2017-03-05 16:44:50 +01:00
|
|
|
m_calculatedTransformA = A->get_transform() * m_frameInA;
|
2014-09-15 16:33:30 +02:00
|
|
|
m_calculatedTransformB = B->get_transform() * m_frameInB;
|
|
|
|
m_realPivotAInW = m_calculatedTransformA.origin;
|
|
|
|
m_realPivotBInW = m_calculatedTransformB.origin;
|
|
|
|
m_sliderAxis = m_calculatedTransformA.basis.get_axis(0); // along X
|
|
|
|
m_delta = m_realPivotBInW - m_realPivotAInW;
|
|
|
|
m_projPivotInW = m_realPivotAInW + m_sliderAxis.dot(m_delta) * m_sliderAxis;
|
2017-03-05 16:44:50 +01:00
|
|
|
Vector3 normalWorld;
|
|
|
|
int i;
|
|
|
|
//linear part
|
|
|
|
for (i = 0; i < 3; i++) {
|
2014-09-15 16:33:30 +02:00
|
|
|
normalWorld = m_calculatedTransformA.basis.get_axis(i);
|
|
|
|
m_depth[i] = m_delta.dot(normalWorld);
|
2017-03-05 16:44:50 +01:00
|
|
|
}
|
2014-09-15 16:33:30 +02:00
|
|
|
} // SliderJointSW::calculateTransforms()
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2020-05-14 11:11:27 +02:00
|
|
|
void SliderJoint3DSW::testLinLimits() {
|
2014-09-15 16:33:30 +02:00
|
|
|
m_solveLinLim = false;
|
|
|
|
m_linPos = m_depth[0];
|
2017-03-05 16:44:50 +01:00
|
|
|
if (m_lowerLinLimit <= m_upperLinLimit) {
|
|
|
|
if (m_depth[0] > m_upperLinLimit) {
|
2014-09-15 16:33:30 +02:00
|
|
|
m_depth[0] -= m_upperLinLimit;
|
|
|
|
m_solveLinLim = true;
|
2017-03-05 16:44:50 +01:00
|
|
|
} else if (m_depth[0] < m_lowerLinLimit) {
|
2014-09-15 16:33:30 +02:00
|
|
|
m_depth[0] -= m_lowerLinLimit;
|
|
|
|
m_solveLinLim = true;
|
2017-03-05 16:44:50 +01:00
|
|
|
} else {
|
2014-09-15 16:33:30 +02:00
|
|
|
m_depth[0] = real_t(0.);
|
|
|
|
}
|
2017-03-05 16:44:50 +01:00
|
|
|
} else {
|
2014-09-15 16:33:30 +02:00
|
|
|
m_depth[0] = real_t(0.);
|
|
|
|
}
|
|
|
|
} // SliderJointSW::testLinLimits()
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2020-05-14 11:11:27 +02:00
|
|
|
void SliderJoint3DSW::testAngLimits() {
|
2014-09-15 16:33:30 +02:00
|
|
|
m_angDepth = real_t(0.);
|
|
|
|
m_solveAngLim = false;
|
2017-03-05 16:44:50 +01:00
|
|
|
if (m_lowerAngLimit <= m_upperAngLimit) {
|
2014-09-15 16:33:30 +02:00
|
|
|
const Vector3 axisA0 = m_calculatedTransformA.basis.get_axis(1);
|
|
|
|
const Vector3 axisA1 = m_calculatedTransformA.basis.get_axis(2);
|
|
|
|
const Vector3 axisB0 = m_calculatedTransformB.basis.get_axis(1);
|
|
|
|
real_t rot = atan2fast(axisB0.dot(axisA1), axisB0.dot(axisA0));
|
2017-03-05 16:44:50 +01:00
|
|
|
if (rot < m_lowerAngLimit) {
|
2014-09-15 16:33:30 +02:00
|
|
|
m_angDepth = rot - m_lowerAngLimit;
|
|
|
|
m_solveAngLim = true;
|
2017-03-05 16:44:50 +01:00
|
|
|
} else if (rot > m_upperAngLimit) {
|
2014-09-15 16:33:30 +02:00
|
|
|
m_angDepth = rot - m_upperAngLimit;
|
|
|
|
m_solveAngLim = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} // SliderJointSW::testAngLimits()
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2020-05-14 11:11:27 +02:00
|
|
|
Vector3 SliderJoint3DSW::getAncorInA() {
|
2014-09-15 16:33:30 +02:00
|
|
|
Vector3 ancorInA;
|
|
|
|
ancorInA = m_realPivotAInW + (m_lowerLinLimit + m_upperLinLimit) * real_t(0.5) * m_sliderAxis;
|
2017-03-05 16:44:50 +01:00
|
|
|
ancorInA = A->get_transform().inverse().xform(ancorInA);
|
2014-09-15 16:33:30 +02:00
|
|
|
return ancorInA;
|
|
|
|
} // SliderJointSW::getAncorInA()
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2020-05-14 11:11:27 +02:00
|
|
|
Vector3 SliderJoint3DSW::getAncorInB() {
|
2014-09-15 16:33:30 +02:00
|
|
|
Vector3 ancorInB;
|
|
|
|
ancorInB = m_frameInB.origin;
|
|
|
|
return ancorInB;
|
|
|
|
} // SliderJointSW::getAncorInB();
|
|
|
|
|
2020-03-27 19:21:27 +01:00
|
|
|
void SliderJoint3DSW::set_param(PhysicsServer3D::SliderJointParam p_param, real_t p_value) {
|
2017-03-05 16:44:50 +01:00
|
|
|
switch (p_param) {
|
2020-05-10 13:00:47 +02:00
|
|
|
case PhysicsServer3D::SLIDER_JOINT_LINEAR_LIMIT_UPPER:
|
|
|
|
m_upperLinLimit = p_value;
|
|
|
|
break;
|
|
|
|
case PhysicsServer3D::SLIDER_JOINT_LINEAR_LIMIT_LOWER:
|
|
|
|
m_lowerLinLimit = p_value;
|
|
|
|
break;
|
|
|
|
case PhysicsServer3D::SLIDER_JOINT_LINEAR_LIMIT_SOFTNESS:
|
|
|
|
m_softnessLimLin = p_value;
|
|
|
|
break;
|
|
|
|
case PhysicsServer3D::SLIDER_JOINT_LINEAR_LIMIT_RESTITUTION:
|
|
|
|
m_restitutionLimLin = p_value;
|
|
|
|
break;
|
|
|
|
case PhysicsServer3D::SLIDER_JOINT_LINEAR_LIMIT_DAMPING:
|
|
|
|
m_dampingLimLin = p_value;
|
|
|
|
break;
|
|
|
|
case PhysicsServer3D::SLIDER_JOINT_LINEAR_MOTION_SOFTNESS:
|
|
|
|
m_softnessDirLin = p_value;
|
|
|
|
break;
|
|
|
|
case PhysicsServer3D::SLIDER_JOINT_LINEAR_MOTION_RESTITUTION:
|
|
|
|
m_restitutionDirLin = p_value;
|
|
|
|
break;
|
|
|
|
case PhysicsServer3D::SLIDER_JOINT_LINEAR_MOTION_DAMPING:
|
|
|
|
m_dampingDirLin = p_value;
|
|
|
|
break;
|
|
|
|
case PhysicsServer3D::SLIDER_JOINT_LINEAR_ORTHOGONAL_SOFTNESS:
|
|
|
|
m_softnessOrthoLin = p_value;
|
|
|
|
break;
|
|
|
|
case PhysicsServer3D::SLIDER_JOINT_LINEAR_ORTHOGONAL_RESTITUTION:
|
|
|
|
m_restitutionOrthoLin = p_value;
|
|
|
|
break;
|
|
|
|
case PhysicsServer3D::SLIDER_JOINT_LINEAR_ORTHOGONAL_DAMPING:
|
|
|
|
m_dampingOrthoLin = p_value;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PhysicsServer3D::SLIDER_JOINT_ANGULAR_LIMIT_UPPER:
|
|
|
|
m_upperAngLimit = p_value;
|
|
|
|
break;
|
|
|
|
case PhysicsServer3D::SLIDER_JOINT_ANGULAR_LIMIT_LOWER:
|
|
|
|
m_lowerAngLimit = p_value;
|
|
|
|
break;
|
|
|
|
case PhysicsServer3D::SLIDER_JOINT_ANGULAR_LIMIT_SOFTNESS:
|
|
|
|
m_softnessLimAng = p_value;
|
|
|
|
break;
|
|
|
|
case PhysicsServer3D::SLIDER_JOINT_ANGULAR_LIMIT_RESTITUTION:
|
|
|
|
m_restitutionLimAng = p_value;
|
|
|
|
break;
|
|
|
|
case PhysicsServer3D::SLIDER_JOINT_ANGULAR_LIMIT_DAMPING:
|
|
|
|
m_dampingLimAng = p_value;
|
|
|
|
break;
|
|
|
|
case PhysicsServer3D::SLIDER_JOINT_ANGULAR_MOTION_SOFTNESS:
|
|
|
|
m_softnessDirAng = p_value;
|
|
|
|
break;
|
|
|
|
case PhysicsServer3D::SLIDER_JOINT_ANGULAR_MOTION_RESTITUTION:
|
|
|
|
m_restitutionDirAng = p_value;
|
|
|
|
break;
|
|
|
|
case PhysicsServer3D::SLIDER_JOINT_ANGULAR_MOTION_DAMPING:
|
|
|
|
m_dampingDirAng = p_value;
|
|
|
|
break;
|
|
|
|
case PhysicsServer3D::SLIDER_JOINT_ANGULAR_ORTHOGONAL_SOFTNESS:
|
|
|
|
m_softnessOrthoAng = p_value;
|
|
|
|
break;
|
|
|
|
case PhysicsServer3D::SLIDER_JOINT_ANGULAR_ORTHOGONAL_RESTITUTION:
|
|
|
|
m_restitutionOrthoAng = p_value;
|
|
|
|
break;
|
|
|
|
case PhysicsServer3D::SLIDER_JOINT_ANGULAR_ORTHOGONAL_DAMPING:
|
|
|
|
m_dampingOrthoAng = p_value;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PhysicsServer3D::SLIDER_JOINT_MAX:
|
|
|
|
break; // Can't happen, but silences warning
|
2014-09-15 16:33:30 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-27 19:21:27 +01:00
|
|
|
real_t SliderJoint3DSW::get_param(PhysicsServer3D::SliderJointParam p_param) const {
|
2017-03-05 16:44:50 +01:00
|
|
|
switch (p_param) {
|
2020-05-10 13:00:47 +02:00
|
|
|
case PhysicsServer3D::SLIDER_JOINT_LINEAR_LIMIT_UPPER:
|
|
|
|
return m_upperLinLimit;
|
|
|
|
case PhysicsServer3D::SLIDER_JOINT_LINEAR_LIMIT_LOWER:
|
|
|
|
return m_lowerLinLimit;
|
|
|
|
case PhysicsServer3D::SLIDER_JOINT_LINEAR_LIMIT_SOFTNESS:
|
|
|
|
return m_softnessLimLin;
|
|
|
|
case PhysicsServer3D::SLIDER_JOINT_LINEAR_LIMIT_RESTITUTION:
|
|
|
|
return m_restitutionLimLin;
|
|
|
|
case PhysicsServer3D::SLIDER_JOINT_LINEAR_LIMIT_DAMPING:
|
|
|
|
return m_dampingLimLin;
|
|
|
|
case PhysicsServer3D::SLIDER_JOINT_LINEAR_MOTION_SOFTNESS:
|
|
|
|
return m_softnessDirLin;
|
|
|
|
case PhysicsServer3D::SLIDER_JOINT_LINEAR_MOTION_RESTITUTION:
|
|
|
|
return m_restitutionDirLin;
|
|
|
|
case PhysicsServer3D::SLIDER_JOINT_LINEAR_MOTION_DAMPING:
|
|
|
|
return m_dampingDirLin;
|
|
|
|
case PhysicsServer3D::SLIDER_JOINT_LINEAR_ORTHOGONAL_SOFTNESS:
|
|
|
|
return m_softnessOrthoLin;
|
|
|
|
case PhysicsServer3D::SLIDER_JOINT_LINEAR_ORTHOGONAL_RESTITUTION:
|
|
|
|
return m_restitutionOrthoLin;
|
|
|
|
case PhysicsServer3D::SLIDER_JOINT_LINEAR_ORTHOGONAL_DAMPING:
|
|
|
|
return m_dampingOrthoLin;
|
|
|
|
|
|
|
|
case PhysicsServer3D::SLIDER_JOINT_ANGULAR_LIMIT_UPPER:
|
|
|
|
return m_upperAngLimit;
|
|
|
|
case PhysicsServer3D::SLIDER_JOINT_ANGULAR_LIMIT_LOWER:
|
|
|
|
return m_lowerAngLimit;
|
|
|
|
case PhysicsServer3D::SLIDER_JOINT_ANGULAR_LIMIT_SOFTNESS:
|
|
|
|
return m_softnessLimAng;
|
|
|
|
case PhysicsServer3D::SLIDER_JOINT_ANGULAR_LIMIT_RESTITUTION:
|
|
|
|
return m_restitutionLimAng;
|
|
|
|
case PhysicsServer3D::SLIDER_JOINT_ANGULAR_LIMIT_DAMPING:
|
|
|
|
return m_dampingLimAng;
|
|
|
|
case PhysicsServer3D::SLIDER_JOINT_ANGULAR_MOTION_SOFTNESS:
|
|
|
|
return m_softnessDirAng;
|
|
|
|
case PhysicsServer3D::SLIDER_JOINT_ANGULAR_MOTION_RESTITUTION:
|
|
|
|
return m_restitutionDirAng;
|
|
|
|
case PhysicsServer3D::SLIDER_JOINT_ANGULAR_MOTION_DAMPING:
|
|
|
|
return m_dampingDirAng;
|
|
|
|
case PhysicsServer3D::SLIDER_JOINT_ANGULAR_ORTHOGONAL_SOFTNESS:
|
|
|
|
return m_softnessOrthoAng;
|
|
|
|
case PhysicsServer3D::SLIDER_JOINT_ANGULAR_ORTHOGONAL_RESTITUTION:
|
|
|
|
return m_restitutionOrthoAng;
|
|
|
|
case PhysicsServer3D::SLIDER_JOINT_ANGULAR_ORTHOGONAL_DAMPING:
|
|
|
|
return m_dampingOrthoAng;
|
|
|
|
|
|
|
|
case PhysicsServer3D::SLIDER_JOINT_MAX:
|
|
|
|
break; // Can't happen, but silences warning
|
2014-09-15 16:33:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|