2015-05-08 15:49:33 +08:00
|
|
|
/****************************************************************************
|
2018-01-29 16:25:32 +08:00
|
|
|
Copyright (c) 2015-2016 Chukong Technologies Inc.
|
|
|
|
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2022-07-09 01:23:11 +08:00
|
|
|
https://axis-project.github.io/
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-05-08 15:49:33 +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:
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-05-08 15:49:33 +08:00
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
all copies or substantial portions of the Software.
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-05-08 15:49:33 +08:00
|
|
|
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.
|
|
|
|
****************************************************************************/
|
|
|
|
|
2016-03-20 21:53:44 +08:00
|
|
|
#include "physics3d/CCPhysics3D.h"
|
2015-05-08 15:49:33 +08:00
|
|
|
|
|
|
|
#if CC_USE_3D_PHYSICS
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
# if (CC_ENABLE_BULLET_INTEGRATION)
|
2015-05-08 15:49:33 +08:00
|
|
|
|
2022-07-11 17:50:21 +08:00
|
|
|
NS_AX_BEGIN
|
2015-05-08 15:49:33 +08:00
|
|
|
|
|
|
|
Physics3DConstraint::Physics3DConstraint()
|
2021-12-25 10:04:45 +08:00
|
|
|
: _constraint(nullptr)
|
|
|
|
, _bodyA(nullptr)
|
|
|
|
, _bodyB(nullptr)
|
|
|
|
, _type(Physics3DConstraint::ConstraintType::UNKNOWN)
|
|
|
|
, _userData(nullptr)
|
|
|
|
{}
|
2015-05-08 15:49:33 +08:00
|
|
|
|
|
|
|
Physics3DConstraint::~Physics3DConstraint()
|
|
|
|
{
|
|
|
|
CC_SAFE_RELEASE(_bodyA);
|
|
|
|
CC_SAFE_RELEASE(_bodyB);
|
|
|
|
CC_SAFE_DELETE(_constraint);
|
|
|
|
}
|
|
|
|
|
|
|
|
float Physics3DConstraint::getBreakingImpulse() const
|
|
|
|
{
|
|
|
|
return _constraint->getBreakingImpulseThreshold();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Physics3DConstraint::setBreakingImpulse(float impulse)
|
|
|
|
{
|
|
|
|
_constraint->setBreakingImpulseThreshold(impulse);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Physics3DConstraint::isEnabled() const
|
|
|
|
{
|
|
|
|
return _constraint->isEnabled();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Physics3DConstraint::setEnabled(bool enabled)
|
|
|
|
{
|
|
|
|
return _constraint->setEnabled(enabled);
|
|
|
|
}
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
int Physics3DConstraint::getOverrideNumSolverIterations() const
|
2015-05-08 15:49:33 +08:00
|
|
|
{
|
|
|
|
return _constraint->getOverrideNumSolverIterations();
|
|
|
|
}
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
/// override the number of constraint solver iterations used to solve this constraint
|
2015-05-08 15:49:33 +08:00
|
|
|
///-1 will use the default number of iterations, as specified in SolverInfo.m_numIterations
|
2016-06-29 10:04:11 +08:00
|
|
|
void Physics3DConstraint::setOverrideNumSolverIterations(int overrideNumIterations)
|
2015-05-08 15:49:33 +08:00
|
|
|
{
|
2016-06-29 10:04:11 +08:00
|
|
|
_constraint->setOverrideNumSolverIterations(overrideNumIterations);
|
2015-05-08 15:49:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
2021-12-25 10:04:45 +08:00
|
|
|
Physics3DPointToPointConstraint* Physics3DPointToPointConstraint::create(Physics3DRigidBody* rbA,
|
2022-07-11 17:50:21 +08:00
|
|
|
const axis::Vec3& pivotPointInA)
|
2015-05-08 15:49:33 +08:00
|
|
|
{
|
2021-12-08 00:11:53 +08:00
|
|
|
auto ret = new Physics3DPointToPointConstraint();
|
|
|
|
if (ret->init(rbA, pivotPointInA))
|
2015-05-08 15:49:33 +08:00
|
|
|
{
|
|
|
|
ret->autorelease();
|
|
|
|
return ret;
|
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-05-08 15:49:33 +08:00
|
|
|
CC_SAFE_DELETE(ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
Physics3DPointToPointConstraint* Physics3DPointToPointConstraint::create(Physics3DRigidBody* rbA,
|
|
|
|
Physics3DRigidBody* rbB,
|
2022-07-11 17:50:21 +08:00
|
|
|
const axis::Vec3& pivotPointInA,
|
|
|
|
const axis::Vec3& pivotPointInB)
|
2015-05-08 15:49:33 +08:00
|
|
|
{
|
2021-12-08 00:11:53 +08:00
|
|
|
auto ret = new Physics3DPointToPointConstraint();
|
|
|
|
if (ret->init(rbA, rbB, pivotPointInA, pivotPointInB))
|
2015-05-08 15:49:33 +08:00
|
|
|
{
|
|
|
|
ret->autorelease();
|
|
|
|
return ret;
|
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-05-08 15:49:33 +08:00
|
|
|
CC_SAFE_DELETE(ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2022-07-11 17:50:21 +08:00
|
|
|
bool Physics3DPointToPointConstraint::init(Physics3DRigidBody* rbA, const axis::Vec3& pivotPointInA)
|
2015-05-08 15:49:33 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-05-08 15:49:33 +08:00
|
|
|
_constraint = new btPoint2PointConstraint(*rbA->getRigidBody(), convertVec3TobtVector3(pivotPointInA));
|
2021-12-25 10:04:45 +08:00
|
|
|
_bodyA = rbA;
|
2015-05-08 15:49:33 +08:00
|
|
|
_bodyA->retain();
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-05-08 15:49:33 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
bool Physics3DPointToPointConstraint::init(Physics3DRigidBody* rbA,
|
|
|
|
Physics3DRigidBody* rbB,
|
2022-07-11 17:50:21 +08:00
|
|
|
const axis::Vec3& pivotPointInA,
|
|
|
|
const axis::Vec3& pivotPointInB)
|
2015-05-08 15:49:33 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
_constraint =
|
|
|
|
new btPoint2PointConstraint(*rbA->getRigidBody(), *rbB->getRigidBody(), convertVec3TobtVector3(pivotPointInA),
|
|
|
|
convertVec3TobtVector3(pivotPointInB));
|
2015-05-08 15:49:33 +08:00
|
|
|
_bodyA = rbA;
|
|
|
|
_bodyB = rbB;
|
|
|
|
_bodyA->retain();
|
|
|
|
_bodyB->retain();
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-05-08 15:49:33 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2022-07-11 17:50:21 +08:00
|
|
|
void Physics3DPointToPointConstraint::setPivotPointInA(const axis::Vec3& pivotA)
|
2015-05-08 15:49:33 +08:00
|
|
|
{
|
|
|
|
auto point = convertVec3TobtVector3(pivotA);
|
|
|
|
static_cast<btPoint2PointConstraint*>(_constraint)->setPivotA(point);
|
|
|
|
}
|
|
|
|
|
2022-07-11 17:50:21 +08:00
|
|
|
void Physics3DPointToPointConstraint::setPivotPointInB(const axis::Vec3& pivotB)
|
2015-05-08 15:49:33 +08:00
|
|
|
{
|
|
|
|
auto point = convertVec3TobtVector3(pivotB);
|
|
|
|
static_cast<btPoint2PointConstraint*>(_constraint)->setPivotB(point);
|
|
|
|
}
|
|
|
|
|
2022-07-11 17:50:21 +08:00
|
|
|
axis::Vec3 Physics3DPointToPointConstraint::getPivotPointInA() const
|
2015-05-08 15:49:33 +08:00
|
|
|
{
|
|
|
|
const auto& point = static_cast<btPoint2PointConstraint*>(_constraint)->getPivotInA();
|
|
|
|
return convertbtVector3ToVec3(point);
|
|
|
|
}
|
|
|
|
|
2022-07-11 17:50:21 +08:00
|
|
|
axis::Vec3 Physics3DPointToPointConstraint::getPivotPointInB() const
|
2015-05-08 15:49:33 +08:00
|
|
|
{
|
|
|
|
const auto& point = static_cast<btPoint2PointConstraint*>(_constraint)->getPivotInB();
|
|
|
|
return convertbtVector3ToVec3(point);
|
|
|
|
}
|
|
|
|
|
|
|
|
Physics3DPointToPointConstraint::Physics3DPointToPointConstraint()
|
|
|
|
{
|
|
|
|
_type = Physics3DConstraint::ConstraintType::POINT_TO_POINT;
|
|
|
|
}
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
Physics3DPointToPointConstraint::~Physics3DPointToPointConstraint() {}
|
2015-05-08 15:49:33 +08:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
2021-12-25 10:04:45 +08:00
|
|
|
Physics3DHingeConstraint* Physics3DHingeConstraint::create(Physics3DRigidBody* rbA,
|
2022-07-11 17:50:21 +08:00
|
|
|
const axis::Mat4& rbAFrame,
|
2021-12-25 10:04:45 +08:00
|
|
|
bool useReferenceFrameA)
|
2015-05-08 15:49:33 +08:00
|
|
|
{
|
2021-12-08 00:11:53 +08:00
|
|
|
auto ret = new Physics3DHingeConstraint();
|
2021-12-25 10:04:45 +08:00
|
|
|
ret->_constraint =
|
|
|
|
new btHingeConstraint(*rbA->getRigidBody(), convertMat4TobtTransform(rbAFrame), useReferenceFrameA);
|
2015-05-08 15:49:33 +08:00
|
|
|
ret->_bodyA = rbA;
|
|
|
|
rbA->retain();
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-05-08 15:49:33 +08:00
|
|
|
ret->autorelease();
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
Physics3DHingeConstraint* Physics3DHingeConstraint::create(Physics3DRigidBody* rbA,
|
2022-07-11 17:50:21 +08:00
|
|
|
const axis::Vec3& pivotInA,
|
|
|
|
const axis::Vec3& axisInA,
|
2021-12-25 10:04:45 +08:00
|
|
|
bool useReferenceFrameA)
|
2015-05-08 15:49:33 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
auto ret = new Physics3DHingeConstraint();
|
|
|
|
ret->_constraint = new btHingeConstraint(*rbA->getRigidBody(), convertVec3TobtVector3(pivotInA),
|
|
|
|
convertVec3TobtVector3(axisInA), useReferenceFrameA);
|
|
|
|
ret->_bodyA = rbA;
|
2015-05-08 15:49:33 +08:00
|
|
|
rbA->retain();
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-05-08 15:49:33 +08:00
|
|
|
ret->autorelease();
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
Physics3DHingeConstraint* Physics3DHingeConstraint::create(Physics3DRigidBody* rbA,
|
|
|
|
Physics3DRigidBody* rbB,
|
2022-07-11 17:50:21 +08:00
|
|
|
const axis::Vec3& pivotInA,
|
|
|
|
const axis::Vec3& pivotInB,
|
|
|
|
axis::Vec3& axisInA,
|
|
|
|
axis::Vec3& axisInB,
|
2021-12-25 10:04:45 +08:00
|
|
|
bool useReferenceFrameA)
|
2015-05-08 15:49:33 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
auto ret = new Physics3DHingeConstraint();
|
|
|
|
ret->_constraint = new btHingeConstraint(
|
|
|
|
*rbA->getRigidBody(), *rbB->getRigidBody(), convertVec3TobtVector3(pivotInA), convertVec3TobtVector3(pivotInB),
|
|
|
|
convertVec3TobtVector3(axisInA), convertVec3TobtVector3(axisInB), useReferenceFrameA);
|
2015-05-08 15:49:33 +08:00
|
|
|
ret->_bodyA = rbA;
|
|
|
|
rbA->retain();
|
|
|
|
ret->_bodyB = rbB;
|
|
|
|
rbB->retain();
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-05-08 15:49:33 +08:00
|
|
|
ret->autorelease();
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
Physics3DHingeConstraint* Physics3DHingeConstraint::create(Physics3DRigidBody* rbA,
|
|
|
|
Physics3DRigidBody* rbB,
|
2022-07-11 17:50:21 +08:00
|
|
|
const axis::Mat4& rbAFrame,
|
|
|
|
const axis::Mat4& rbBFrame,
|
2021-12-25 10:04:45 +08:00
|
|
|
bool useReferenceFrameA)
|
2015-05-08 15:49:33 +08:00
|
|
|
{
|
2021-12-08 00:11:53 +08:00
|
|
|
auto ret = new Physics3DHingeConstraint();
|
2021-12-25 10:04:45 +08:00
|
|
|
ret->_constraint =
|
|
|
|
new btHingeConstraint(*rbA->getRigidBody(), *rbB->getRigidBody(), convertMat4TobtTransform(rbAFrame),
|
|
|
|
convertMat4TobtTransform(rbBFrame), useReferenceFrameA);
|
2015-05-08 15:49:33 +08:00
|
|
|
ret->_bodyA = rbA;
|
|
|
|
rbA->retain();
|
|
|
|
ret->_bodyB = rbB;
|
|
|
|
rbB->retain();
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-05-08 15:49:33 +08:00
|
|
|
ret->autorelease();
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2022-07-11 17:50:21 +08:00
|
|
|
axis::Mat4 Physics3DHingeConstraint::getFrameOffsetA() const
|
2015-05-08 15:49:33 +08:00
|
|
|
{
|
|
|
|
const auto& transform = static_cast<btHingeConstraint*>(_constraint)->getFrameOffsetA();
|
|
|
|
return convertbtTransformToMat4(transform);
|
|
|
|
}
|
|
|
|
|
2022-07-11 17:50:21 +08:00
|
|
|
axis::Mat4 Physics3DHingeConstraint::getFrameOffsetB() const
|
2015-05-08 15:49:33 +08:00
|
|
|
{
|
|
|
|
const auto& transform = static_cast<btHingeConstraint*>(_constraint)->getFrameOffsetB();
|
|
|
|
return convertbtTransformToMat4(transform);
|
|
|
|
}
|
|
|
|
|
2022-07-11 17:50:21 +08:00
|
|
|
void Physics3DHingeConstraint::setFrames(const axis::Mat4& frameA, const axis::Mat4& frameB)
|
2015-05-08 15:49:33 +08:00
|
|
|
{
|
|
|
|
auto transformA = convertMat4TobtTransform(frameA);
|
|
|
|
auto transformB = convertMat4TobtTransform(frameB);
|
|
|
|
static_cast<btHingeConstraint*>(_constraint)->setFrames(transformA, transformB);
|
|
|
|
}
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
void Physics3DHingeConstraint::setAngularOnly(bool angularOnly)
|
2015-05-08 15:49:33 +08:00
|
|
|
{
|
|
|
|
static_cast<btHingeConstraint*>(_constraint)->setAngularOnly(angularOnly);
|
|
|
|
}
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
void Physics3DHingeConstraint::enableAngularMotor(bool enableMotor, float targetVelocity, float maxMotorImpulse)
|
2015-05-08 15:49:33 +08:00
|
|
|
{
|
|
|
|
static_cast<btHingeConstraint*>(_constraint)->enableAngularMotor(enableMotor, targetVelocity, maxMotorImpulse);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Physics3DHingeConstraint::enableMotor(bool enableMotor)
|
|
|
|
{
|
|
|
|
static_cast<btHingeConstraint*>(_constraint)->enableMotor(enableMotor);
|
|
|
|
}
|
|
|
|
void Physics3DHingeConstraint::setMaxMotorImpulse(float maxMotorImpulse)
|
|
|
|
{
|
|
|
|
static_cast<btHingeConstraint*>(_constraint)->setMaxMotorImpulse(maxMotorImpulse);
|
|
|
|
}
|
2022-07-11 17:50:21 +08:00
|
|
|
void Physics3DHingeConstraint::setMotorTarget(const axis::Quaternion& qAinB, float dt)
|
2015-05-08 15:49:33 +08:00
|
|
|
{
|
|
|
|
static_cast<btHingeConstraint*>(_constraint)->setMotorTarget(convertQuatTobtQuat(qAinB), dt);
|
|
|
|
}
|
|
|
|
void Physics3DHingeConstraint::setMotorTarget(float targetAngle, float dt)
|
|
|
|
{
|
|
|
|
static_cast<btHingeConstraint*>(_constraint)->setMotorTarget(targetAngle, dt);
|
|
|
|
}
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
void Physics3DHingeConstraint::setLimit(float low, float high, float softness, float biasFactor, float relaxationFactor)
|
2015-05-08 15:49:33 +08:00
|
|
|
{
|
|
|
|
static_cast<btHingeConstraint*>(_constraint)->setLimit(low, high, softness, biasFactor, relaxationFactor);
|
|
|
|
}
|
|
|
|
|
2022-07-11 17:50:21 +08:00
|
|
|
void Physics3DHingeConstraint::setAxis(const axis::Vec3& axisInA)
|
2015-05-08 15:49:33 +08:00
|
|
|
{
|
|
|
|
auto axis = convertVec3TobtVector3(axisInA);
|
|
|
|
static_cast<btHingeConstraint*>(_constraint)->setAxis(axis);
|
|
|
|
}
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
float Physics3DHingeConstraint::getLowerLimit() const
|
2015-05-08 15:49:33 +08:00
|
|
|
{
|
|
|
|
return static_cast<btHingeConstraint*>(_constraint)->getLowerLimit();
|
|
|
|
}
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
float Physics3DHingeConstraint::getUpperLimit() const
|
2015-05-08 15:49:33 +08:00
|
|
|
{
|
|
|
|
return static_cast<btHingeConstraint*>(_constraint)->getUpperLimit();
|
|
|
|
}
|
|
|
|
|
2015-05-12 16:13:14 +08:00
|
|
|
float Physics3DHingeConstraint::getHingeAngle() const
|
2015-05-08 15:49:33 +08:00
|
|
|
{
|
|
|
|
return static_cast<btHingeConstraint*>(_constraint)->getHingeAngle();
|
|
|
|
}
|
|
|
|
|
2022-07-11 17:50:21 +08:00
|
|
|
float Physics3DHingeConstraint::getHingeAngle(const axis::Mat4& transA, const axis::Mat4& transB)
|
2015-05-08 15:49:33 +08:00
|
|
|
{
|
|
|
|
auto btTransA = convertMat4TobtTransform(transA);
|
|
|
|
auto btTransB = convertMat4TobtTransform(transB);
|
|
|
|
return static_cast<btHingeConstraint*>(_constraint)->getHingeAngle(btTransA, btTransB);
|
|
|
|
}
|
|
|
|
|
2022-07-11 17:50:21 +08:00
|
|
|
axis::Mat4 Physics3DHingeConstraint::getAFrame() const
|
2015-05-08 15:49:33 +08:00
|
|
|
{
|
|
|
|
const auto& trans = static_cast<btHingeConstraint*>(_constraint)->getAFrame();
|
|
|
|
return convertbtTransformToMat4(trans);
|
|
|
|
}
|
2022-07-11 17:50:21 +08:00
|
|
|
axis::Mat4 Physics3DHingeConstraint::getBFrame() const
|
2015-05-08 15:49:33 +08:00
|
|
|
{
|
|
|
|
const auto& trans = static_cast<btHingeConstraint*>(_constraint)->getBFrame();
|
|
|
|
return convertbtTransformToMat4(trans);
|
|
|
|
}
|
|
|
|
|
2015-05-12 16:13:14 +08:00
|
|
|
bool Physics3DHingeConstraint::getAngularOnly() const
|
2015-05-08 15:49:33 +08:00
|
|
|
{
|
|
|
|
return static_cast<btHingeConstraint*>(_constraint)->getAngularOnly();
|
|
|
|
}
|
2015-05-12 16:13:14 +08:00
|
|
|
bool Physics3DHingeConstraint::getEnableAngularMotor() const
|
2015-05-08 15:49:33 +08:00
|
|
|
{
|
|
|
|
return static_cast<btHingeConstraint*>(_constraint)->getEnableAngularMotor();
|
|
|
|
}
|
2015-05-12 16:13:14 +08:00
|
|
|
float Physics3DHingeConstraint::getMotorTargetVelosity() const
|
2015-05-08 15:49:33 +08:00
|
|
|
{
|
2020-11-15 00:48:53 +08:00
|
|
|
return static_cast<btHingeConstraint*>(_constraint)->getMotorTargetVelocity();
|
2015-05-08 15:49:33 +08:00
|
|
|
}
|
2015-05-12 16:13:14 +08:00
|
|
|
float Physics3DHingeConstraint::getMaxMotorImpulse() const
|
2015-05-08 15:49:33 +08:00
|
|
|
{
|
|
|
|
return static_cast<btHingeConstraint*>(_constraint)->getMaxMotorImpulse();
|
|
|
|
}
|
|
|
|
|
2015-05-12 16:13:14 +08:00
|
|
|
bool Physics3DHingeConstraint::getUseFrameOffset() const
|
2015-05-08 15:49:33 +08:00
|
|
|
{
|
|
|
|
return static_cast<btHingeConstraint*>(_constraint)->getUseFrameOffset();
|
|
|
|
}
|
|
|
|
void Physics3DHingeConstraint::setUseFrameOffset(bool frameOffsetOnOff)
|
|
|
|
{
|
|
|
|
static_cast<btHingeConstraint*>(_constraint)->setUseFrameOffset(frameOffsetOnOff);
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
2021-12-25 10:04:45 +08:00
|
|
|
Physics3DSliderConstraint* Physics3DSliderConstraint::create(Physics3DRigidBody* rbA,
|
|
|
|
Physics3DRigidBody* rbB,
|
2022-07-11 17:50:21 +08:00
|
|
|
const axis::Mat4& frameInA,
|
|
|
|
const axis::Mat4& frameInB,
|
2021-12-25 10:04:45 +08:00
|
|
|
bool useLinearReferenceFrameA)
|
2015-05-08 15:49:33 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
auto ret = new Physics3DSliderConstraint();
|
2015-05-08 15:49:33 +08:00
|
|
|
ret->_bodyA = rbA;
|
|
|
|
ret->_bodyB = rbB;
|
|
|
|
rbA->retain();
|
|
|
|
rbB->retain();
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
|
|
auto transformA = convertMat4TobtTransform(frameInA);
|
|
|
|
auto transformB = convertMat4TobtTransform(frameInB);
|
|
|
|
ret->_constraint = new btSliderConstraint(*rbA->getRigidBody(), *rbB->getRigidBody(), transformA, transformB,
|
|
|
|
useLinearReferenceFrameA);
|
2015-05-08 15:49:33 +08:00
|
|
|
ret->autorelease();
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2022-07-11 17:50:21 +08:00
|
|
|
axis::Mat4 Physics3DSliderConstraint::getFrameOffsetA() const
|
2015-05-08 15:49:33 +08:00
|
|
|
{
|
|
|
|
const auto& frameOff = static_cast<btSliderConstraint*>(_constraint)->getFrameOffsetA();
|
|
|
|
return convertbtTransformToMat4(frameOff);
|
|
|
|
}
|
2022-07-11 17:50:21 +08:00
|
|
|
axis::Mat4 Physics3DSliderConstraint::getFrameOffsetB() const
|
2015-05-08 15:49:33 +08:00
|
|
|
{
|
|
|
|
const auto& frameOff = static_cast<btSliderConstraint*>(_constraint)->getFrameOffsetB();
|
|
|
|
return convertbtTransformToMat4(frameOff);
|
|
|
|
}
|
2015-05-12 16:13:14 +08:00
|
|
|
float Physics3DSliderConstraint::getLowerLinLimit() const
|
2015-05-08 15:49:33 +08:00
|
|
|
{
|
|
|
|
return static_cast<btSliderConstraint*>(_constraint)->getLowerLinLimit();
|
|
|
|
}
|
|
|
|
void Physics3DSliderConstraint::setLowerLinLimit(float lowerLimit)
|
|
|
|
{
|
|
|
|
static_cast<btSliderConstraint*>(_constraint)->setLowerLinLimit(lowerLimit);
|
|
|
|
}
|
2015-05-12 16:13:14 +08:00
|
|
|
float Physics3DSliderConstraint::getUpperLinLimit() const
|
2015-05-08 15:49:33 +08:00
|
|
|
{
|
|
|
|
return static_cast<btSliderConstraint*>(_constraint)->getUpperLinLimit();
|
|
|
|
}
|
|
|
|
void Physics3DSliderConstraint::setUpperLinLimit(float upperLimit)
|
|
|
|
{
|
|
|
|
static_cast<btSliderConstraint*>(_constraint)->setUpperLinLimit(upperLimit);
|
|
|
|
}
|
2015-05-12 16:13:14 +08:00
|
|
|
float Physics3DSliderConstraint::getLowerAngLimit() const
|
2015-05-08 15:49:33 +08:00
|
|
|
{
|
|
|
|
return static_cast<btSliderConstraint*>(_constraint)->getLowerAngLimit();
|
|
|
|
}
|
|
|
|
void Physics3DSliderConstraint::setLowerAngLimit(float lowerLimit)
|
|
|
|
{
|
|
|
|
static_cast<btSliderConstraint*>(_constraint)->setLowerAngLimit(lowerLimit);
|
|
|
|
}
|
2015-05-12 16:13:14 +08:00
|
|
|
float Physics3DSliderConstraint::getUpperAngLimit() const
|
2015-05-08 15:49:33 +08:00
|
|
|
{
|
|
|
|
return static_cast<btSliderConstraint*>(_constraint)->getUpperAngLimit();
|
|
|
|
}
|
|
|
|
void Physics3DSliderConstraint::setUpperAngLimit(float upperLimit)
|
|
|
|
{
|
|
|
|
static_cast<btSliderConstraint*>(_constraint)->setUpperAngLimit(upperLimit);
|
|
|
|
}
|
2015-05-12 16:13:14 +08:00
|
|
|
bool Physics3DSliderConstraint::getUseLinearReferenceFrameA() const
|
2015-05-08 15:49:33 +08:00
|
|
|
{
|
|
|
|
return static_cast<btSliderConstraint*>(_constraint)->getUseLinearReferenceFrameA();
|
|
|
|
}
|
2015-05-12 16:13:14 +08:00
|
|
|
float Physics3DSliderConstraint::getSoftnessDirLin() const
|
2015-05-08 15:49:33 +08:00
|
|
|
{
|
|
|
|
return static_cast<btSliderConstraint*>(_constraint)->getSoftnessDirLin();
|
|
|
|
}
|
2015-05-12 16:13:14 +08:00
|
|
|
float Physics3DSliderConstraint::getRestitutionDirLin() const
|
2015-05-08 15:49:33 +08:00
|
|
|
{
|
|
|
|
return static_cast<btSliderConstraint*>(_constraint)->getRestitutionDirLin();
|
|
|
|
}
|
2015-05-12 16:13:14 +08:00
|
|
|
float Physics3DSliderConstraint::getDampingDirLin() const
|
2015-05-08 15:49:33 +08:00
|
|
|
{
|
|
|
|
return static_cast<btSliderConstraint*>(_constraint)->getDampingDirLin();
|
|
|
|
}
|
2015-05-12 16:13:14 +08:00
|
|
|
float Physics3DSliderConstraint::getSoftnessDirAng() const
|
2015-05-08 15:49:33 +08:00
|
|
|
{
|
|
|
|
return static_cast<btSliderConstraint*>(_constraint)->getSoftnessDirAng();
|
|
|
|
}
|
2015-05-12 16:13:14 +08:00
|
|
|
float Physics3DSliderConstraint::getRestitutionDirAng() const
|
2015-05-08 15:49:33 +08:00
|
|
|
{
|
|
|
|
return static_cast<btSliderConstraint*>(_constraint)->getRestitutionDirAng();
|
|
|
|
}
|
2015-05-12 16:13:14 +08:00
|
|
|
float Physics3DSliderConstraint::getDampingDirAng() const
|
2015-05-08 15:49:33 +08:00
|
|
|
{
|
|
|
|
return static_cast<btSliderConstraint*>(_constraint)->getDampingDirAng();
|
|
|
|
}
|
2015-05-12 16:13:14 +08:00
|
|
|
float Physics3DSliderConstraint::getSoftnessLimLin() const
|
2015-05-08 15:49:33 +08:00
|
|
|
{
|
|
|
|
return static_cast<btSliderConstraint*>(_constraint)->getSoftnessLimLin();
|
|
|
|
}
|
2015-05-12 16:13:14 +08:00
|
|
|
float Physics3DSliderConstraint::getRestitutionLimLin() const
|
2015-05-08 15:49:33 +08:00
|
|
|
{
|
|
|
|
return static_cast<btSliderConstraint*>(_constraint)->getRestitutionLimLin();
|
|
|
|
}
|
2015-05-12 16:13:14 +08:00
|
|
|
float Physics3DSliderConstraint::getDampingLimLin() const
|
2015-05-08 15:49:33 +08:00
|
|
|
{
|
|
|
|
return static_cast<btSliderConstraint*>(_constraint)->getDampingLimAng();
|
|
|
|
}
|
2015-05-12 16:13:14 +08:00
|
|
|
float Physics3DSliderConstraint::getSoftnessLimAng() const
|
2015-05-08 15:49:33 +08:00
|
|
|
{
|
|
|
|
return static_cast<btSliderConstraint*>(_constraint)->getSoftnessLimAng();
|
|
|
|
}
|
2015-05-12 16:13:14 +08:00
|
|
|
float Physics3DSliderConstraint::getRestitutionLimAng() const
|
2015-05-08 15:49:33 +08:00
|
|
|
{
|
|
|
|
return static_cast<btSliderConstraint*>(_constraint)->getRestitutionLimAng();
|
|
|
|
}
|
2015-05-12 16:13:14 +08:00
|
|
|
float Physics3DSliderConstraint::getDampingLimAng() const
|
2015-05-08 15:49:33 +08:00
|
|
|
{
|
|
|
|
return static_cast<btSliderConstraint*>(_constraint)->getDampingLimAng();
|
|
|
|
}
|
2015-05-12 16:13:14 +08:00
|
|
|
float Physics3DSliderConstraint::getSoftnessOrthoLin() const
|
2015-05-08 15:49:33 +08:00
|
|
|
{
|
|
|
|
return static_cast<btSliderConstraint*>(_constraint)->getSoftnessOrthoLin();
|
|
|
|
}
|
2015-05-12 16:13:14 +08:00
|
|
|
float Physics3DSliderConstraint::getRestitutionOrthoLin() const
|
2015-05-08 15:49:33 +08:00
|
|
|
{
|
|
|
|
return static_cast<btSliderConstraint*>(_constraint)->getRestitutionOrthoAng();
|
|
|
|
}
|
2015-05-12 16:13:14 +08:00
|
|
|
float Physics3DSliderConstraint::getDampingOrthoLin() const
|
2015-05-08 15:49:33 +08:00
|
|
|
{
|
|
|
|
return static_cast<btSliderConstraint*>(_constraint)->getDampingOrthoLin();
|
|
|
|
}
|
2015-05-12 16:13:14 +08:00
|
|
|
float Physics3DSliderConstraint::getSoftnessOrthoAng() const
|
2015-05-08 15:49:33 +08:00
|
|
|
{
|
|
|
|
return static_cast<btSliderConstraint*>(_constraint)->getSoftnessOrthoAng();
|
|
|
|
}
|
2015-05-12 16:13:14 +08:00
|
|
|
float Physics3DSliderConstraint::getRestitutionOrthoAng() const
|
2015-05-08 15:49:33 +08:00
|
|
|
{
|
|
|
|
return static_cast<btSliderConstraint*>(_constraint)->getRestitutionOrthoAng();
|
|
|
|
}
|
2015-05-12 16:13:14 +08:00
|
|
|
float Physics3DSliderConstraint::getDampingOrthoAng() const
|
2015-05-08 15:49:33 +08:00
|
|
|
{
|
|
|
|
return static_cast<btSliderConstraint*>(_constraint)->getDampingOrthoAng();
|
|
|
|
}
|
|
|
|
void Physics3DSliderConstraint::setSoftnessDirLin(float softnessDirLin)
|
|
|
|
{
|
|
|
|
static_cast<btSliderConstraint*>(_constraint)->setSoftnessDirLin(softnessDirLin);
|
|
|
|
}
|
|
|
|
void Physics3DSliderConstraint::setRestitutionDirLin(float restitutionDirLin)
|
|
|
|
{
|
|
|
|
static_cast<btSliderConstraint*>(_constraint)->setRestitutionDirLin(restitutionDirLin);
|
|
|
|
}
|
|
|
|
void Physics3DSliderConstraint::setDampingDirLin(float dampingDirLin)
|
|
|
|
{
|
|
|
|
static_cast<btSliderConstraint*>(_constraint)->setDampingDirLin(dampingDirLin);
|
|
|
|
}
|
|
|
|
void Physics3DSliderConstraint::setSoftnessDirAng(float softnessDirAng)
|
|
|
|
{
|
|
|
|
static_cast<btSliderConstraint*>(_constraint)->setSoftnessDirAng(softnessDirAng);
|
|
|
|
}
|
|
|
|
void Physics3DSliderConstraint::setRestitutionDirAng(float restitutionDirAng)
|
|
|
|
{
|
|
|
|
static_cast<btSliderConstraint*>(_constraint)->setRestitutionDirAng(restitutionDirAng);
|
|
|
|
}
|
|
|
|
void Physics3DSliderConstraint::setDampingDirAng(float dampingDirAng)
|
|
|
|
{
|
|
|
|
static_cast<btSliderConstraint*>(_constraint)->setDampingDirAng(dampingDirAng);
|
|
|
|
}
|
|
|
|
void Physics3DSliderConstraint::setSoftnessLimLin(float softnessLimLin)
|
|
|
|
{
|
|
|
|
static_cast<btSliderConstraint*>(_constraint)->setSoftnessLimLin(softnessLimLin);
|
|
|
|
}
|
|
|
|
void Physics3DSliderConstraint::setRestitutionLimLin(float restitutionLimLin)
|
|
|
|
{
|
|
|
|
static_cast<btSliderConstraint*>(_constraint)->setRestitutionDirLin(restitutionLimLin);
|
|
|
|
}
|
|
|
|
void Physics3DSliderConstraint::setDampingLimLin(float dampingLimLin)
|
|
|
|
{
|
|
|
|
static_cast<btSliderConstraint*>(_constraint)->setDampingLimLin(dampingLimLin);
|
|
|
|
}
|
|
|
|
void Physics3DSliderConstraint::setSoftnessLimAng(float softnessLimAng)
|
|
|
|
{
|
|
|
|
static_cast<btSliderConstraint*>(_constraint)->setSoftnessLimAng(softnessLimAng);
|
|
|
|
}
|
|
|
|
void Physics3DSliderConstraint::setRestitutionLimAng(float restitutionLimAng)
|
|
|
|
{
|
|
|
|
static_cast<btSliderConstraint*>(_constraint)->setRestitutionLimAng(restitutionLimAng);
|
|
|
|
}
|
|
|
|
void Physics3DSliderConstraint::setDampingLimAng(float dampingLimAng)
|
|
|
|
{
|
|
|
|
static_cast<btSliderConstraint*>(_constraint)->setDampingLimAng(dampingLimAng);
|
|
|
|
}
|
|
|
|
void Physics3DSliderConstraint::setSoftnessOrthoLin(float softnessOrthoLin)
|
|
|
|
{
|
|
|
|
static_cast<btSliderConstraint*>(_constraint)->setSoftnessOrthoLin(softnessOrthoLin);
|
|
|
|
}
|
|
|
|
void Physics3DSliderConstraint::setRestitutionOrthoLin(float restitutionOrthoLin)
|
|
|
|
{
|
|
|
|
static_cast<btSliderConstraint*>(_constraint)->setRestitutionOrthoLin(restitutionOrthoLin);
|
|
|
|
}
|
|
|
|
void Physics3DSliderConstraint::setDampingOrthoLin(float dampingOrthoLin)
|
|
|
|
{
|
|
|
|
static_cast<btSliderConstraint*>(_constraint)->setDampingLimLin(dampingOrthoLin);
|
|
|
|
}
|
|
|
|
void Physics3DSliderConstraint::setSoftnessOrthoAng(float softnessOrthoAng)
|
|
|
|
{
|
|
|
|
static_cast<btSliderConstraint*>(_constraint)->setSoftnessOrthoAng(softnessOrthoAng);
|
|
|
|
}
|
|
|
|
void Physics3DSliderConstraint::setRestitutionOrthoAng(float restitutionOrthoAng)
|
|
|
|
{
|
|
|
|
static_cast<btSliderConstraint*>(_constraint)->setRestitutionOrthoAng(restitutionOrthoAng);
|
|
|
|
}
|
|
|
|
void Physics3DSliderConstraint::setDampingOrthoAng(float dampingOrthoAng)
|
|
|
|
{
|
|
|
|
static_cast<btSliderConstraint*>(_constraint)->setDampingOrthoAng(dampingOrthoAng);
|
|
|
|
}
|
|
|
|
void Physics3DSliderConstraint::setPoweredLinMotor(bool onOff)
|
|
|
|
{
|
|
|
|
static_cast<btSliderConstraint*>(_constraint)->setPoweredLinMotor(onOff);
|
|
|
|
}
|
2015-05-12 16:13:14 +08:00
|
|
|
bool Physics3DSliderConstraint::getPoweredLinMotor() const
|
2015-05-08 15:49:33 +08:00
|
|
|
{
|
|
|
|
return static_cast<btSliderConstraint*>(_constraint)->getPoweredLinMotor();
|
|
|
|
}
|
|
|
|
void Physics3DSliderConstraint::setTargetLinMotorVelocity(float targetLinMotorVelocity)
|
|
|
|
{
|
|
|
|
static_cast<btSliderConstraint*>(_constraint)->setTargetLinMotorVelocity(targetLinMotorVelocity);
|
|
|
|
}
|
2015-05-12 16:13:14 +08:00
|
|
|
float Physics3DSliderConstraint::getTargetLinMotorVelocity() const
|
2015-05-08 15:49:33 +08:00
|
|
|
{
|
|
|
|
return static_cast<btSliderConstraint*>(_constraint)->getTargetLinMotorVelocity();
|
|
|
|
}
|
|
|
|
void Physics3DSliderConstraint::setMaxLinMotorForce(float maxLinMotorForce)
|
|
|
|
{
|
|
|
|
static_cast<btSliderConstraint*>(_constraint)->setMaxLinMotorForce(maxLinMotorForce);
|
|
|
|
}
|
2015-05-12 16:13:14 +08:00
|
|
|
float Physics3DSliderConstraint::getMaxLinMotorForce() const
|
2015-05-08 15:49:33 +08:00
|
|
|
{
|
|
|
|
return static_cast<btSliderConstraint*>(_constraint)->getMaxLinMotorForce();
|
|
|
|
}
|
|
|
|
void Physics3DSliderConstraint::setPoweredAngMotor(bool onOff)
|
|
|
|
{
|
|
|
|
static_cast<btSliderConstraint*>(_constraint)->setPoweredAngMotor(onOff);
|
|
|
|
}
|
2015-05-12 16:13:14 +08:00
|
|
|
bool Physics3DSliderConstraint::getPoweredAngMotor() const
|
2015-05-08 15:49:33 +08:00
|
|
|
{
|
|
|
|
return static_cast<btSliderConstraint*>(_constraint)->getPoweredAngMotor();
|
|
|
|
}
|
|
|
|
void Physics3DSliderConstraint::setTargetAngMotorVelocity(float targetAngMotorVelocity)
|
|
|
|
{
|
|
|
|
return static_cast<btSliderConstraint*>(_constraint)->setTargetAngMotorVelocity(targetAngMotorVelocity);
|
|
|
|
}
|
2015-05-12 16:13:14 +08:00
|
|
|
float Physics3DSliderConstraint::getTargetAngMotorVelocity() const
|
2015-05-08 15:49:33 +08:00
|
|
|
{
|
|
|
|
return static_cast<btSliderConstraint*>(_constraint)->getTargetAngMotorVelocity();
|
|
|
|
}
|
|
|
|
void Physics3DSliderConstraint::setMaxAngMotorForce(float maxAngMotorForce)
|
|
|
|
{
|
|
|
|
return static_cast<btSliderConstraint*>(_constraint)->setMaxAngMotorForce(maxAngMotorForce);
|
|
|
|
}
|
2015-05-12 16:13:14 +08:00
|
|
|
float Physics3DSliderConstraint::getMaxAngMotorForce() const
|
2015-05-08 15:49:33 +08:00
|
|
|
{
|
|
|
|
return static_cast<btSliderConstraint*>(_constraint)->getMaxAngMotorForce();
|
|
|
|
}
|
|
|
|
|
|
|
|
float Physics3DSliderConstraint::getLinearPos() const
|
|
|
|
{
|
|
|
|
return static_cast<btSliderConstraint*>(_constraint)->getLinearPos();
|
|
|
|
}
|
|
|
|
float Physics3DSliderConstraint::getAngularPos() const
|
|
|
|
{
|
|
|
|
return static_cast<btSliderConstraint*>(_constraint)->getAngularPos();
|
|
|
|
}
|
|
|
|
|
|
|
|
// access for UseFrameOffset
|
2015-05-12 16:13:14 +08:00
|
|
|
bool Physics3DSliderConstraint::getUseFrameOffset() const
|
2015-05-08 15:49:33 +08:00
|
|
|
{
|
|
|
|
return static_cast<btSliderConstraint*>(_constraint)->getUseFrameOffset();
|
|
|
|
}
|
|
|
|
void Physics3DSliderConstraint::setUseFrameOffset(bool frameOffsetOnOff)
|
|
|
|
{
|
|
|
|
static_cast<btSliderConstraint*>(_constraint)->setUseFrameOffset(frameOffsetOnOff);
|
|
|
|
}
|
|
|
|
|
2022-07-11 17:50:21 +08:00
|
|
|
void Physics3DSliderConstraint::setFrames(const axis::Mat4& frameA, const axis::Mat4& frameB)
|
2015-05-08 15:49:33 +08:00
|
|
|
{
|
|
|
|
auto btFrameA = convertMat4TobtTransform(frameA);
|
|
|
|
auto btFrameB = convertMat4TobtTransform(frameB);
|
|
|
|
static_cast<btSliderConstraint*>(_constraint)->setFrames(btFrameA, btFrameB);
|
|
|
|
}
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2022-07-11 17:50:21 +08:00
|
|
|
Physics3DConeTwistConstraint* Physics3DConeTwistConstraint::create(Physics3DRigidBody* rbA, const axis::Mat4& frameA)
|
2015-05-08 15:49:33 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
auto ret = new Physics3DConeTwistConstraint();
|
2015-05-08 15:49:33 +08:00
|
|
|
ret->_bodyA = rbA;
|
|
|
|
rbA->retain();
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
|
|
auto btFrame = convertMat4TobtTransform(frameA);
|
2015-05-08 15:49:33 +08:00
|
|
|
ret->_constraint = new btConeTwistConstraint(*rbA->getRigidBody(), btFrame);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-05-08 15:49:33 +08:00
|
|
|
ret->autorelease();
|
|
|
|
return ret;
|
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
Physics3DConeTwistConstraint* Physics3DConeTwistConstraint::create(Physics3DRigidBody* rbA,
|
|
|
|
Physics3DRigidBody* rbB,
|
2022-07-11 17:50:21 +08:00
|
|
|
const axis::Mat4& frameA,
|
|
|
|
const axis::Mat4& frameB)
|
2015-05-08 15:49:33 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
auto ret = new Physics3DConeTwistConstraint();
|
2015-05-08 15:49:33 +08:00
|
|
|
ret->_bodyA = rbA;
|
|
|
|
ret->_bodyB = rbB;
|
|
|
|
rbA->retain();
|
|
|
|
rbB->retain();
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-05-08 15:49:33 +08:00
|
|
|
auto btFrameA = convertMat4TobtTransform(frameA);
|
|
|
|
auto btFrameB = convertMat4TobtTransform(frameB);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-05-08 15:49:33 +08:00
|
|
|
ret->_constraint = new btConeTwistConstraint(*rbA->getRigidBody(), *rbB->getRigidBody(), btFrameA, btFrameB);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-05-08 15:49:33 +08:00
|
|
|
ret->autorelease();
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
void Physics3DConeTwistConstraint::setLimit(float swingSpan1,
|
|
|
|
float swingSpan2,
|
|
|
|
float twistSpan,
|
|
|
|
float softness,
|
|
|
|
float biasFactor,
|
|
|
|
float relaxationFactor)
|
2015-05-08 15:49:33 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
static_cast<btConeTwistConstraint*>(_constraint)
|
|
|
|
->setLimit(swingSpan1, swingSpan2, twistSpan, softness, biasFactor, relaxationFactor);
|
2015-05-08 15:49:33 +08:00
|
|
|
}
|
|
|
|
|
2022-07-11 17:50:21 +08:00
|
|
|
axis::Mat4 Physics3DConeTwistConstraint::getAFrame() const
|
2015-05-08 15:49:33 +08:00
|
|
|
{
|
|
|
|
const auto& frame = static_cast<btConeTwistConstraint*>(_constraint)->getAFrame();
|
|
|
|
return convertbtTransformToMat4(frame);
|
|
|
|
}
|
2022-07-11 17:50:21 +08:00
|
|
|
axis::Mat4 Physics3DConeTwistConstraint::getBFrame() const
|
2015-05-08 15:49:33 +08:00
|
|
|
{
|
|
|
|
const auto& frame = static_cast<btConeTwistConstraint*>(_constraint)->getBFrame();
|
|
|
|
return convertbtTransformToMat4(frame);
|
|
|
|
}
|
|
|
|
|
2015-05-12 16:13:14 +08:00
|
|
|
float Physics3DConeTwistConstraint::getSwingSpan1() const
|
2015-05-08 15:49:33 +08:00
|
|
|
{
|
|
|
|
return static_cast<btConeTwistConstraint*>(_constraint)->getSwingSpan1();
|
|
|
|
}
|
2015-05-12 16:13:14 +08:00
|
|
|
float Physics3DConeTwistConstraint::getSwingSpan2() const
|
2015-05-08 15:49:33 +08:00
|
|
|
{
|
|
|
|
return static_cast<btConeTwistConstraint*>(_constraint)->getSwingSpan2();
|
|
|
|
}
|
2015-05-12 16:13:14 +08:00
|
|
|
float Physics3DConeTwistConstraint::getTwistSpan() const
|
2015-05-08 15:49:33 +08:00
|
|
|
{
|
|
|
|
return static_cast<btConeTwistConstraint*>(_constraint)->getTwistSpan();
|
|
|
|
}
|
2015-05-12 16:13:14 +08:00
|
|
|
float Physics3DConeTwistConstraint::getTwistAngle() const
|
2015-05-08 15:49:33 +08:00
|
|
|
{
|
|
|
|
return static_cast<btConeTwistConstraint*>(_constraint)->getTwistAngle();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Physics3DConeTwistConstraint::setDamping(float damping)
|
|
|
|
{
|
|
|
|
static_cast<btConeTwistConstraint*>(_constraint)->setDamping(damping);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Physics3DConeTwistConstraint::enableMotor(bool b)
|
|
|
|
{
|
|
|
|
static_cast<btConeTwistConstraint*>(_constraint)->enableMotor(b);
|
|
|
|
}
|
|
|
|
void Physics3DConeTwistConstraint::setMaxMotorImpulse(float maxMotorImpulse)
|
|
|
|
{
|
|
|
|
static_cast<btConeTwistConstraint*>(_constraint)->setMaxMotorImpulse(maxMotorImpulse);
|
|
|
|
}
|
|
|
|
void Physics3DConeTwistConstraint::setMaxMotorImpulseNormalized(float maxMotorImpulse)
|
|
|
|
{
|
|
|
|
static_cast<btConeTwistConstraint*>(_constraint)->setMaxMotorImpulseNormalized(maxMotorImpulse);
|
|
|
|
}
|
|
|
|
|
2015-05-12 16:13:14 +08:00
|
|
|
float Physics3DConeTwistConstraint::getFixThresh() const
|
2015-05-08 15:49:33 +08:00
|
|
|
{
|
|
|
|
return static_cast<btConeTwistConstraint*>(_constraint)->getFixThresh();
|
|
|
|
}
|
|
|
|
void Physics3DConeTwistConstraint::setFixThresh(float fixThresh)
|
|
|
|
{
|
|
|
|
static_cast<btConeTwistConstraint*>(_constraint)->setFixThresh(fixThresh);
|
|
|
|
}
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
void Physics3DConeTwistConstraint::setMotorTarget(const btQuaternion& q)
|
2015-05-08 15:49:33 +08:00
|
|
|
{
|
|
|
|
static_cast<btConeTwistConstraint*>(_constraint)->setMotorTarget(q);
|
|
|
|
}
|
|
|
|
|
|
|
|
// same as above, but q is the desired rotation of frameA wrt frameB in constraint space
|
2021-12-25 10:04:45 +08:00
|
|
|
void Physics3DConeTwistConstraint::setMotorTargetInConstraintSpace(const btQuaternion& q)
|
2015-05-08 15:49:33 +08:00
|
|
|
{
|
|
|
|
static_cast<btConeTwistConstraint*>(_constraint)->setMotorTargetInConstraintSpace(q);
|
|
|
|
}
|
|
|
|
|
2022-07-11 17:50:21 +08:00
|
|
|
axis::Vec3 Physics3DConeTwistConstraint::GetPointForAngle(float fAngleInRadians, float fLength) const
|
2015-05-08 15:49:33 +08:00
|
|
|
{
|
|
|
|
const auto& point = static_cast<btConeTwistConstraint*>(_constraint)->GetPointForAngle(fAngleInRadians, fLength);
|
|
|
|
return convertbtVector3ToVec3(point);
|
|
|
|
}
|
|
|
|
|
2022-07-11 17:50:21 +08:00
|
|
|
void Physics3DConeTwistConstraint::setFrames(const axis::Mat4& frameA, const axis::Mat4& frameB)
|
2015-05-08 15:49:33 +08:00
|
|
|
{
|
|
|
|
const auto& btFrameA = convertMat4TobtTransform(frameA);
|
|
|
|
const auto& btFrameB = convertMat4TobtTransform(frameB);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-05-08 15:49:33 +08:00
|
|
|
static_cast<btConeTwistConstraint*>(_constraint)->setFrames(btFrameA, btFrameB);
|
|
|
|
}
|
|
|
|
|
2022-07-11 17:50:21 +08:00
|
|
|
axis::Mat4 Physics3DConeTwistConstraint::getFrameOffsetA() const
|
2015-05-08 15:49:33 +08:00
|
|
|
{
|
|
|
|
const auto& trans = static_cast<btConeTwistConstraint*>(_constraint)->getFrameOffsetA();
|
|
|
|
return convertbtTransformToMat4(trans);
|
|
|
|
}
|
|
|
|
|
2022-07-11 17:50:21 +08:00
|
|
|
axis::Mat4 Physics3DConeTwistConstraint::getFrameOffsetB() const
|
2015-05-08 15:49:33 +08:00
|
|
|
{
|
|
|
|
const auto& trans = static_cast<btConeTwistConstraint*>(_constraint)->getFrameOffsetB();
|
|
|
|
return convertbtTransformToMat4(trans);
|
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
2021-12-25 10:04:45 +08:00
|
|
|
Physics3D6DofConstraint* Physics3D6DofConstraint::create(Physics3DRigidBody* rbB,
|
2022-07-11 17:50:21 +08:00
|
|
|
const axis::Mat4& frameInB,
|
2021-12-25 10:04:45 +08:00
|
|
|
bool useLinearReferenceFrameB)
|
2015-05-08 15:49:33 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
auto ret = new Physics3D6DofConstraint();
|
2015-05-08 15:49:33 +08:00
|
|
|
ret->_bodyB = rbB;
|
|
|
|
rbB->retain();
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
|
|
auto frameB = convertMat4TobtTransform(frameInB);
|
2015-05-08 15:49:33 +08:00
|
|
|
ret->_constraint = new btGeneric6DofConstraint(*rbB->getRigidBody(), frameB, useLinearReferenceFrameB);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-05-08 15:49:33 +08:00
|
|
|
ret->autorelease();
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
Physics3D6DofConstraint* Physics3D6DofConstraint::create(Physics3DRigidBody* rbA,
|
|
|
|
Physics3DRigidBody* rbB,
|
2022-07-11 17:50:21 +08:00
|
|
|
const axis::Mat4& frameInA,
|
|
|
|
const axis::Mat4& frameInB,
|
2021-12-25 10:04:45 +08:00
|
|
|
bool useLinearReferenceFrameA)
|
2015-05-08 15:49:33 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
auto ret = new Physics3D6DofConstraint();
|
2015-05-08 15:49:33 +08:00
|
|
|
ret->_bodyA = rbA;
|
|
|
|
ret->_bodyB = rbB;
|
|
|
|
rbA->retain();
|
|
|
|
rbB->retain();
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
|
|
auto frameA = convertMat4TobtTransform(frameInA);
|
|
|
|
auto frameB = convertMat4TobtTransform(frameInB);
|
|
|
|
ret->_constraint = new btGeneric6DofConstraint(*rbA->getRigidBody(), *rbB->getRigidBody(), frameA, frameB,
|
|
|
|
useLinearReferenceFrameA);
|
|
|
|
|
2015-05-08 15:49:33 +08:00
|
|
|
ret->autorelease();
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2022-07-11 17:50:21 +08:00
|
|
|
void Physics3D6DofConstraint::setLinearLowerLimit(const axis::Vec3& linearLower)
|
2015-05-08 15:49:33 +08:00
|
|
|
{
|
|
|
|
auto lower = convertVec3TobtVector3(linearLower);
|
|
|
|
static_cast<btGeneric6DofConstraint*>(_constraint)->setLinearLowerLimit(lower);
|
|
|
|
}
|
|
|
|
|
2022-07-11 17:50:21 +08:00
|
|
|
axis::Vec3 Physics3D6DofConstraint::getLinearLowerLimit() const
|
2015-05-08 15:49:33 +08:00
|
|
|
{
|
|
|
|
btVector3 lower;
|
|
|
|
static_cast<btGeneric6DofConstraint*>(_constraint)->getLinearLowerLimit(lower);
|
|
|
|
return convertbtVector3ToVec3(lower);
|
|
|
|
}
|
|
|
|
|
2022-07-11 17:50:21 +08:00
|
|
|
void Physics3D6DofConstraint::setLinearUpperLimit(const axis::Vec3& linearUpper)
|
2015-05-08 15:49:33 +08:00
|
|
|
{
|
|
|
|
auto upper = convertVec3TobtVector3(linearUpper);
|
|
|
|
static_cast<btGeneric6DofConstraint*>(_constraint)->setLinearUpperLimit(upper);
|
|
|
|
}
|
|
|
|
|
2022-07-11 17:50:21 +08:00
|
|
|
axis::Vec3 Physics3D6DofConstraint::getLinearUpperLimit() const
|
2015-05-08 15:49:33 +08:00
|
|
|
{
|
|
|
|
btVector3 upper;
|
|
|
|
static_cast<btGeneric6DofConstraint*>(_constraint)->getLinearUpperLimit(upper);
|
|
|
|
return convertbtVector3ToVec3(upper);
|
|
|
|
}
|
|
|
|
|
2022-07-11 17:50:21 +08:00
|
|
|
void Physics3D6DofConstraint::setAngularLowerLimit(const axis::Vec3& angularLower)
|
2015-05-08 15:49:33 +08:00
|
|
|
{
|
|
|
|
auto lower = convertVec3TobtVector3(angularLower);
|
|
|
|
static_cast<btGeneric6DofConstraint*>(_constraint)->setAngularLowerLimit(lower);
|
|
|
|
}
|
|
|
|
|
2022-07-11 17:50:21 +08:00
|
|
|
axis::Vec3 Physics3D6DofConstraint::getAngularLowerLimit() const
|
2015-05-08 15:49:33 +08:00
|
|
|
{
|
|
|
|
btVector3 lower;
|
|
|
|
static_cast<btGeneric6DofConstraint*>(_constraint)->getAngularLowerLimit(lower);
|
|
|
|
return convertbtVector3ToVec3(lower);
|
|
|
|
}
|
|
|
|
|
2022-07-11 17:50:21 +08:00
|
|
|
void Physics3D6DofConstraint::setAngularUpperLimit(const axis::Vec3& angularUpper)
|
2015-05-08 15:49:33 +08:00
|
|
|
{
|
|
|
|
auto upper = convertVec3TobtVector3(angularUpper);
|
|
|
|
static_cast<btGeneric6DofConstraint*>(_constraint)->setAngularUpperLimit(upper);
|
|
|
|
}
|
|
|
|
|
2022-07-11 17:50:21 +08:00
|
|
|
axis::Vec3 Physics3D6DofConstraint::getAngularUpperLimit() const
|
2015-05-08 15:49:33 +08:00
|
|
|
{
|
|
|
|
btVector3 upper;
|
|
|
|
static_cast<btGeneric6DofConstraint*>(_constraint)->getAngularUpperLimit(upper);
|
|
|
|
return convertbtVector3ToVec3(upper);
|
|
|
|
}
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
bool Physics3D6DofConstraint::isLimited(int limitIndex) const
|
2015-05-08 15:49:33 +08:00
|
|
|
{
|
|
|
|
return static_cast<btGeneric6DofConstraint*>(_constraint)->isLimited(limitIndex);
|
|
|
|
}
|
|
|
|
|
2015-05-12 16:13:14 +08:00
|
|
|
bool Physics3D6DofConstraint::getUseFrameOffset() const
|
2015-05-08 15:49:33 +08:00
|
|
|
{
|
|
|
|
return static_cast<btGeneric6DofConstraint*>(_constraint)->getUseFrameOffset();
|
|
|
|
}
|
2015-05-12 16:13:14 +08:00
|
|
|
void Physics3D6DofConstraint::setUseFrameOffset(bool frameOffsetOnOff) const
|
2015-05-08 15:49:33 +08:00
|
|
|
{
|
|
|
|
static_cast<btGeneric6DofConstraint*>(_constraint)->setUseFrameOffset(frameOffsetOnOff);
|
|
|
|
}
|
|
|
|
|
2022-07-11 17:50:21 +08:00
|
|
|
NS_AX_END
|
2015-05-08 15:49:33 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
# endif // CC_ENABLE_BULLET_INTEGRATION
|
2015-05-08 15:49:33 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
#endif // CC_USE_3D_PHYSICS
|