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-10-01 16:24:52 +08:00
|
|
|
https://axmolengine.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.
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifndef __PHYSICS_3D_CONSTRAINT_H__
|
|
|
|
#define __PHYSICS_3D_CONSTRAINT_H__
|
|
|
|
|
|
|
|
#include "math/CCMath.h"
|
|
|
|
#include "base/CCRef.h"
|
|
|
|
#include "base/ccConfig.h"
|
|
|
|
|
2022-07-15 19:17:01 +08:00
|
|
|
#if AX_USE_3D_PHYSICS
|
2015-05-08 15:49:33 +08:00
|
|
|
|
2022-07-15 19:17:01 +08:00
|
|
|
# if (AX_ENABLE_BULLET_INTEGRATION)
|
2015-05-08 15:49:33 +08:00
|
|
|
|
|
|
|
class btTypedConstraint;
|
|
|
|
|
2022-07-11 17:50:21 +08:00
|
|
|
NS_AX_BEGIN
|
2015-05-08 15:49:33 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @addtogroup _3d
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
|
|
|
class Physics3DRigidBody;
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
/** @brief Physics3DConstraint: Constraint affects the movement of physics object, it usually connect one or two physics
|
|
|
|
* object. There are some types of physics constraints. */
|
2022-07-15 19:17:01 +08:00
|
|
|
class AX_DLL Physics3DConstraint : public Ref
|
2015-05-08 15:49:33 +08:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
enum class ConstraintType
|
|
|
|
{
|
|
|
|
UNKNOWN,
|
|
|
|
POINT_TO_POINT,
|
|
|
|
HINGE,
|
|
|
|
SLIDER,
|
|
|
|
CONE_TWIST,
|
|
|
|
SIX_DOF,
|
|
|
|
};
|
|
|
|
/**
|
|
|
|
* get the impulse that break the constraint
|
|
|
|
*/
|
|
|
|
float getBreakingImpulse() const;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-05-08 15:49:33 +08:00
|
|
|
/**
|
|
|
|
* set the impulse that break the constraint
|
|
|
|
*/
|
|
|
|
void setBreakingImpulse(float impulse);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-05-08 15:49:33 +08:00
|
|
|
/**
|
|
|
|
* is it enabled
|
|
|
|
*/
|
|
|
|
bool isEnabled() const;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-05-08 15:49:33 +08:00
|
|
|
/**
|
|
|
|
* set enable or not
|
|
|
|
*/
|
|
|
|
void setEnabled(bool enabled);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-05-08 15:49:33 +08:00
|
|
|
/**
|
|
|
|
* get rigid body a
|
|
|
|
*/
|
|
|
|
Physics3DRigidBody* getBodyA() const { return _bodyA; }
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-05-08 15:49:33 +08:00
|
|
|
/**
|
|
|
|
* get rigid body b
|
|
|
|
*/
|
|
|
|
Physics3DRigidBody* getBodyB() const { return _bodyB; }
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-05-08 15:49:33 +08:00
|
|
|
/**
|
|
|
|
* get constraint type
|
|
|
|
*/
|
|
|
|
ConstraintType getConstraintType() const { return _type; }
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-05-08 15:49:33 +08:00
|
|
|
/**
|
|
|
|
* get user data
|
|
|
|
*/
|
|
|
|
void setUserData(void* userData) { _userData = userData; }
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-05-08 15:49:33 +08:00
|
|
|
/**
|
|
|
|
* get user data
|
|
|
|
*/
|
|
|
|
void* getUserData() const { return _userData; }
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-05-08 15:49:33 +08:00
|
|
|
/**
|
|
|
|
* get override number of solver iterations
|
|
|
|
*/
|
2015-05-12 16:13:14 +08:00
|
|
|
int getOverrideNumSolverIterations() const;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-05-12 16:13:14 +08:00
|
|
|
/**
|
2021-12-25 10:04:45 +08:00
|
|
|
* override the number of constraint solver iterations used to solve this constraint, -1 will use the default number
|
|
|
|
* of iterations, as specified in SolverInfo.m_numIterations
|
2015-05-12 16:13:14 +08:00
|
|
|
*/
|
2016-06-29 10:04:11 +08:00
|
|
|
void setOverrideNumSolverIterations(int overrideNumIterations);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2022-07-15 19:17:01 +08:00
|
|
|
# if (AX_ENABLE_BULLET_INTEGRATION)
|
2015-05-08 15:49:33 +08:00
|
|
|
btTypedConstraint* getbtContraint() { return _constraint; }
|
2021-12-25 10:04:45 +08:00
|
|
|
# endif
|
|
|
|
|
2015-05-08 15:49:33 +08:00
|
|
|
protected:
|
|
|
|
Physics3DConstraint();
|
|
|
|
virtual ~Physics3DConstraint();
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-05-08 15:49:33 +08:00
|
|
|
btTypedConstraint* _constraint;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-05-08 15:49:33 +08:00
|
|
|
Physics3DRigidBody* _bodyA;
|
|
|
|
Physics3DRigidBody* _bodyB;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
|
|
ConstraintType _type;
|
|
|
|
void* _userData;
|
2015-05-08 15:49:33 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Point to point constraint limits the translation so that the local pivot points of 2 rigidbodies match in worldspace.
|
|
|
|
*/
|
2022-07-15 19:17:01 +08:00
|
|
|
class AX_DLL Physics3DPointToPointConstraint : public Physics3DConstraint
|
2015-05-08 15:49:33 +08:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* create point to point constraint, limits the translation of local pivot point of rigid body A
|
|
|
|
* @param rbA The rigid body going to be fixed
|
|
|
|
* @param pivotPointInA local pivot point in A's local space
|
|
|
|
* @return created constraint
|
|
|
|
*/
|
2022-08-08 18:02:17 +08:00
|
|
|
static Physics3DPointToPointConstraint* create(Physics3DRigidBody* rbA, const ax::Vec3& pivotPointInA);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-05-08 15:49:33 +08:00
|
|
|
/**
|
|
|
|
* create point to point constraint, make the local pivot points of 2 rigid bodies match in worldspace.
|
|
|
|
* @param rbA The rigid body A going to be fixed
|
|
|
|
* @param rbB The rigid body B going to be fixed
|
|
|
|
* @param pivotPointInA local pivot point in A's local space
|
|
|
|
* @param pivotPointInB local pivot point in B's local space
|
|
|
|
* @return created constraint
|
|
|
|
*/
|
2021-12-25 10:04:45 +08:00
|
|
|
static Physics3DPointToPointConstraint* create(Physics3DRigidBody* rbA,
|
|
|
|
Physics3DRigidBody* rbB,
|
2022-08-08 18:02:17 +08:00
|
|
|
const ax::Vec3& pivotPointInA,
|
|
|
|
const ax::Vec3& pivotPointInB);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-05-08 15:49:33 +08:00
|
|
|
/**
|
|
|
|
* set pivot point in A's local space
|
|
|
|
*/
|
2022-08-08 18:02:17 +08:00
|
|
|
void setPivotPointInA(const ax::Vec3& pivotA);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-05-08 15:49:33 +08:00
|
|
|
/**
|
|
|
|
* set pivot point in B's local space
|
|
|
|
*/
|
2022-08-08 18:02:17 +08:00
|
|
|
void setPivotPointInB(const ax::Vec3& pivotB);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-05-08 15:49:33 +08:00
|
|
|
/**
|
|
|
|
* get pivot point in A's local space
|
|
|
|
*/
|
2022-08-08 18:02:17 +08:00
|
|
|
ax::Vec3 getPivotPointInA() const;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-05-08 15:49:33 +08:00
|
|
|
/**
|
|
|
|
* get pivot point in B's local space
|
|
|
|
*/
|
2022-08-08 18:02:17 +08:00
|
|
|
ax::Vec3 getPivotPointInB() const;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2022-03-18 21:46:07 +08:00
|
|
|
Physics3DPointToPointConstraint();
|
2015-05-08 15:49:33 +08:00
|
|
|
virtual ~Physics3DPointToPointConstraint();
|
2022-08-08 18:02:17 +08:00
|
|
|
bool init(Physics3DRigidBody* rbA, const ax::Vec3& pivotPointInA);
|
2021-12-25 10:04:45 +08:00
|
|
|
bool init(Physics3DRigidBody* rbA,
|
|
|
|
Physics3DRigidBody* rbB,
|
2022-08-08 18:02:17 +08:00
|
|
|
const ax::Vec3& pivotPointInA,
|
|
|
|
const ax::Vec3& pivotPointInB);
|
2015-05-08 15:49:33 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2021-12-25 10:04:45 +08:00
|
|
|
* Hinge constraint restricts two additional angular degrees of freedom, so the body can only rotate around one axis,
|
|
|
|
* the hinge axis. This can be useful to represent doors or wheels rotating around one axis. hinge constraint between
|
|
|
|
* two rigidbodies each with a pivotpoint that describes the axis location in local space
|
2015-05-08 15:49:33 +08:00
|
|
|
*/
|
2022-07-15 19:17:01 +08:00
|
|
|
class AX_DLL Physics3DHingeConstraint : public Physics3DConstraint
|
2015-05-08 15:49:33 +08:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* create hinge constraint
|
|
|
|
* @param rbA rigid body A
|
|
|
|
* @param rbAFrame rigid body A's frame
|
|
|
|
* @param useReferenceFrameA use frame A as reference
|
|
|
|
*/
|
2021-12-25 10:04:45 +08:00
|
|
|
static Physics3DHingeConstraint* create(Physics3DRigidBody* rbA,
|
2022-08-08 18:02:17 +08:00
|
|
|
const ax::Mat4& rbAFrame,
|
2021-12-25 10:04:45 +08:00
|
|
|
bool useReferenceFrameA = false);
|
|
|
|
|
2015-05-08 15:49:33 +08:00
|
|
|
/**
|
|
|
|
* create hinge constraint
|
|
|
|
* @param rbA rigid body A
|
|
|
|
* @param pivotInA pivot in rigid body A's local space
|
|
|
|
* @param axisInA axis in rigid body A's local space
|
|
|
|
* @param useReferenceFrameA use frame A as reference
|
|
|
|
*/
|
2021-12-25 10:04:45 +08:00
|
|
|
static Physics3DHingeConstraint* create(Physics3DRigidBody* rbA,
|
2022-08-08 18:02:17 +08:00
|
|
|
const ax::Vec3& pivotInA,
|
|
|
|
const ax::Vec3& axisInA,
|
2021-12-25 10:04:45 +08:00
|
|
|
bool useReferenceFrameA = false);
|
2015-05-08 15:49:33 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* create hinge constraint
|
|
|
|
* @param rbA rigid body A
|
|
|
|
* @param rbB rigid body B
|
|
|
|
* @param pivotInA pivot point in A's local space
|
|
|
|
* @param pivotInB pivot point in B's local space
|
|
|
|
* @param axisInA axis in A's local space
|
|
|
|
* @param axisInB axis in B's local space
|
|
|
|
* @param useReferenceFrameA use frame A as reference
|
|
|
|
*/
|
2021-12-25 10:04:45 +08:00
|
|
|
static Physics3DHingeConstraint* create(Physics3DRigidBody* rbA,
|
|
|
|
Physics3DRigidBody* rbB,
|
2022-08-08 18:02:17 +08:00
|
|
|
const ax::Vec3& pivotInA,
|
|
|
|
const ax::Vec3& pivotInB,
|
|
|
|
ax::Vec3& axisInA,
|
|
|
|
ax::Vec3& axisInB,
|
2021-12-25 10:04:45 +08:00
|
|
|
bool useReferenceFrameA = false);
|
|
|
|
|
2015-05-08 15:49:33 +08:00
|
|
|
/**
|
|
|
|
* create hinge constraint
|
|
|
|
* @param rbA rigid body A
|
|
|
|
* @param rbB rigid body B
|
|
|
|
* @param rbAFrame rigid body A's frame
|
|
|
|
* @param rbBFrame rigid body B's frame
|
|
|
|
* @param useReferenceFrameA use frame A as reference
|
|
|
|
*/
|
2021-12-25 10:04:45 +08:00
|
|
|
static Physics3DHingeConstraint* create(Physics3DRigidBody* rbA,
|
|
|
|
Physics3DRigidBody* rbB,
|
2022-08-08 18:02:17 +08:00
|
|
|
const ax::Mat4& rbAFrame,
|
|
|
|
const ax::Mat4& rbBFrame,
|
2021-12-25 10:04:45 +08:00
|
|
|
bool useReferenceFrameA = false);
|
|
|
|
|
2015-05-08 15:49:33 +08:00
|
|
|
/**
|
|
|
|
* get rigid body A's frame offset
|
|
|
|
*/
|
2022-08-08 18:02:17 +08:00
|
|
|
ax::Mat4 getFrameOffsetA() const;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-05-08 15:49:33 +08:00
|
|
|
/**
|
|
|
|
* get rigid body B's frame offset
|
|
|
|
*/
|
2022-08-08 18:02:17 +08:00
|
|
|
ax::Mat4 getFrameOffsetB() const;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-05-08 15:49:33 +08:00
|
|
|
/**
|
|
|
|
* set frames for rigid body A and B
|
|
|
|
*/
|
2022-08-08 18:02:17 +08:00
|
|
|
void setFrames(const ax::Mat4& frameA, const ax::Mat4& frameB);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-05-08 15:49:33 +08:00
|
|
|
/**
|
|
|
|
* set angular only
|
|
|
|
*/
|
2015-05-12 16:13:14 +08:00
|
|
|
void setAngularOnly(bool angularOnly);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-05-08 15:49:33 +08:00
|
|
|
/** enable angular motor */
|
2015-05-12 16:13:14 +08:00
|
|
|
void enableAngularMotor(bool enableMotor, float targetVelocity, float maxMotorImpulse);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-05-12 16:13:14 +08:00
|
|
|
// extra motor API, including ability to set a target rotation (as opposed to angular velocity)
|
|
|
|
// note: setMotorTarget sets angular velocity under the hood, so you must call it every tick to
|
|
|
|
// maintain a given angular target.
|
|
|
|
void enableMotor(bool enableMotor);
|
2015-05-08 15:49:33 +08:00
|
|
|
/** set max motor impulse */
|
2015-05-12 16:13:14 +08:00
|
|
|
void setMaxMotorImpulse(float maxMotorImpulse);
|
2015-05-08 15:49:33 +08:00
|
|
|
/**
|
|
|
|
* set motor target
|
|
|
|
*/
|
2022-08-08 18:02:17 +08:00
|
|
|
void setMotorTarget(const ax::Quaternion& qAinB, float dt);
|
2015-05-08 15:49:33 +08:00
|
|
|
/** set motor target */
|
2015-05-12 16:13:14 +08:00
|
|
|
void setMotorTarget(float targetAngle, float dt);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-05-08 15:49:33 +08:00
|
|
|
/** set limit */
|
2021-12-25 10:04:45 +08:00
|
|
|
void setLimit(float low,
|
|
|
|
float high,
|
|
|
|
float _softness = 0.9f,
|
|
|
|
float _biasFactor = 0.3f,
|
|
|
|
float _relaxationFactor = 1.0f);
|
2015-05-08 15:49:33 +08:00
|
|
|
/**set axis*/
|
2022-08-08 18:02:17 +08:00
|
|
|
void setAxis(const ax::Vec3& axisInA);
|
2015-05-08 15:49:33 +08:00
|
|
|
/**get lower limit*/
|
2015-05-12 16:13:14 +08:00
|
|
|
float getLowerLimit() const;
|
2015-05-08 15:49:33 +08:00
|
|
|
/**get upper limit*/
|
2015-05-12 16:13:14 +08:00
|
|
|
float getUpperLimit() const;
|
2015-05-08 15:49:33 +08:00
|
|
|
/**get hinge angle*/
|
2015-05-12 16:13:14 +08:00
|
|
|
float getHingeAngle() const;
|
2015-05-08 15:49:33 +08:00
|
|
|
/**get hinge angle*/
|
2022-08-08 18:02:17 +08:00
|
|
|
float getHingeAngle(const ax::Mat4& transA, const ax::Mat4& transB);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-05-08 15:49:33 +08:00
|
|
|
/**get A's frame */
|
2022-08-08 18:02:17 +08:00
|
|
|
ax::Mat4 getAFrame() const;
|
2015-05-08 15:49:33 +08:00
|
|
|
/**get B's frame*/
|
2022-08-08 18:02:17 +08:00
|
|
|
ax::Mat4 getBFrame() const;
|
2015-05-08 15:49:33 +08:00
|
|
|
/**get angular only*/
|
2015-05-12 16:13:14 +08:00
|
|
|
bool getAngularOnly() const;
|
2015-05-08 15:49:33 +08:00
|
|
|
/**get enable angular motor*/
|
2015-05-12 16:13:14 +08:00
|
|
|
bool getEnableAngularMotor() const;
|
2015-09-22 16:08:23 +08:00
|
|
|
/**get motor target velocity*/
|
2015-05-12 16:13:14 +08:00
|
|
|
float getMotorTargetVelosity() const;
|
2015-05-08 15:49:33 +08:00
|
|
|
/**get max motor impulse*/
|
2015-05-12 16:13:14 +08:00
|
|
|
float getMaxMotorImpulse() const;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-05-12 16:13:14 +08:00
|
|
|
/** access for UseFrameOffset*/
|
|
|
|
bool getUseFrameOffset() const;
|
2015-05-08 15:49:33 +08:00
|
|
|
/**set use frame offset*/
|
2015-05-12 16:13:14 +08:00
|
|
|
void setUseFrameOffset(bool frameOffsetOnOff);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2022-03-18 21:46:07 +08:00
|
|
|
Physics3DHingeConstraint() { _type = ConstraintType::HINGE; }
|
2021-12-25 10:04:45 +08:00
|
|
|
virtual ~Physics3DHingeConstraint() {}
|
2015-05-08 15:49:33 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* It allows the body to rotate around x axis and translate along this axis.
|
|
|
|
* softness, restitution and damping for different cases
|
|
|
|
* DirLin - moving inside linear limits
|
|
|
|
* LimLin - hitting linear limit
|
|
|
|
* DirAng - moving inside angular limits
|
|
|
|
* LimAng - hitting angular limit
|
|
|
|
* OrthoLin, OrthoAng - against constraint axis
|
|
|
|
*/
|
2022-07-15 19:17:01 +08:00
|
|
|
class AX_DLL Physics3DSliderConstraint : public Physics3DConstraint
|
2015-05-08 15:49:33 +08:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* create slider constraint
|
|
|
|
* @param rbA rigid body A
|
|
|
|
* @param rbB rigid body B
|
|
|
|
* @param frameInA frame in A's local space
|
|
|
|
* @param frameInB frame in B's local space
|
|
|
|
* @param useLinearReferenceFrameA use fixed frame A for linear limits
|
|
|
|
*/
|
2021-12-25 10:04:45 +08:00
|
|
|
static Physics3DSliderConstraint* create(Physics3DRigidBody* rbA,
|
|
|
|
Physics3DRigidBody* rbB,
|
2022-08-08 18:02:17 +08:00
|
|
|
const ax::Mat4& frameInA,
|
|
|
|
const ax::Mat4& frameInB,
|
2021-12-25 10:04:45 +08:00
|
|
|
bool useLinearReferenceFrameA);
|
|
|
|
|
2015-05-08 15:49:33 +08:00
|
|
|
/**get A's frame offset*/
|
2022-08-08 18:02:17 +08:00
|
|
|
ax::Mat4 getFrameOffsetA() const;
|
2015-05-08 15:49:33 +08:00
|
|
|
/**get B's frame offset*/
|
2022-08-08 18:02:17 +08:00
|
|
|
ax::Mat4 getFrameOffsetB() const;
|
2015-05-08 15:49:33 +08:00
|
|
|
/**get lower linear limit*/
|
2015-05-12 16:13:14 +08:00
|
|
|
float getLowerLinLimit() const;
|
2015-05-08 15:49:33 +08:00
|
|
|
/**set lower linear limit*/
|
|
|
|
void setLowerLinLimit(float lowerLimit);
|
|
|
|
/**get upper linear limit*/
|
2015-05-12 16:13:14 +08:00
|
|
|
float getUpperLinLimit() const;
|
2015-05-08 15:49:33 +08:00
|
|
|
/**set upper linear limit*/
|
|
|
|
void setUpperLinLimit(float upperLimit);
|
|
|
|
/**get lower angular limit*/
|
2015-05-12 16:13:14 +08:00
|
|
|
float getLowerAngLimit() const;
|
2015-09-22 16:08:23 +08:00
|
|
|
/**set lower angular limit*/
|
2015-05-08 15:49:33 +08:00
|
|
|
void setLowerAngLimit(float lowerLimit);
|
2015-09-22 16:08:23 +08:00
|
|
|
/**get upper angular limit*/
|
2015-05-12 16:13:14 +08:00
|
|
|
float getUpperAngLimit() const;
|
2015-09-22 16:08:23 +08:00
|
|
|
/**set upper angular limit*/
|
2015-05-08 15:49:33 +08:00
|
|
|
void setUpperAngLimit(float upperLimit);
|
2015-09-22 16:08:23 +08:00
|
|
|
/**use A's frame as linear reference*/
|
2015-05-12 16:13:14 +08:00
|
|
|
bool getUseLinearReferenceFrameA() const;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-05-12 16:13:14 +08:00
|
|
|
float getSoftnessDirLin() const;
|
|
|
|
float getRestitutionDirLin() const;
|
|
|
|
float getDampingDirLin() const;
|
|
|
|
float getSoftnessDirAng() const;
|
|
|
|
float getRestitutionDirAng() const;
|
|
|
|
float getDampingDirAng() const;
|
|
|
|
float getSoftnessLimLin() const;
|
|
|
|
float getRestitutionLimLin() const;
|
|
|
|
float getDampingLimLin() const;
|
|
|
|
float getSoftnessLimAng() const;
|
|
|
|
float getRestitutionLimAng() const;
|
|
|
|
float getDampingLimAng() const;
|
|
|
|
float getSoftnessOrthoLin() const;
|
|
|
|
float getRestitutionOrthoLin() const;
|
|
|
|
float getDampingOrthoLin() const;
|
|
|
|
float getSoftnessOrthoAng() const;
|
|
|
|
float getRestitutionOrthoAng() const;
|
|
|
|
float getDampingOrthoAng() const;
|
2015-05-08 15:49:33 +08:00
|
|
|
void setSoftnessDirLin(float softnessDirLin);
|
|
|
|
void setRestitutionDirLin(float restitutionDirLin);
|
|
|
|
void setDampingDirLin(float dampingDirLin);
|
|
|
|
void setSoftnessDirAng(float softnessDirAng);
|
|
|
|
void setRestitutionDirAng(float restitutionDirAng);
|
|
|
|
void setDampingDirAng(float dampingDirAng);
|
|
|
|
void setSoftnessLimLin(float softnessLimLin);
|
|
|
|
void setRestitutionLimLin(float restitutionLimLin);
|
|
|
|
void setDampingLimLin(float dampingLimLin);
|
|
|
|
void setSoftnessLimAng(float softnessLimAng);
|
|
|
|
void setRestitutionLimAng(float restitutionLimAng);
|
|
|
|
void setDampingLimAng(float dampingLimAng);
|
|
|
|
void setSoftnessOrthoLin(float softnessOrthoLin);
|
|
|
|
void setRestitutionOrthoLin(float restitutionOrthoLin);
|
|
|
|
void setDampingOrthoLin(float dampingOrthoLin);
|
|
|
|
void setSoftnessOrthoAng(float softnessOrthoAng);
|
|
|
|
void setRestitutionOrthoAng(float restitutionOrthoAng);
|
|
|
|
void setDampingOrthoAng(float dampingOrthoAng);
|
|
|
|
void setPoweredLinMotor(bool onOff);
|
2015-05-12 16:13:14 +08:00
|
|
|
bool getPoweredLinMotor() const;
|
2015-05-08 15:49:33 +08:00
|
|
|
void setTargetLinMotorVelocity(float targetLinMotorVelocity);
|
2015-05-12 16:13:14 +08:00
|
|
|
float getTargetLinMotorVelocity() const;
|
2015-05-08 15:49:33 +08:00
|
|
|
void setMaxLinMotorForce(float maxLinMotorForce);
|
2015-05-12 16:13:14 +08:00
|
|
|
float getMaxLinMotorForce() const;
|
2015-05-08 15:49:33 +08:00
|
|
|
void setPoweredAngMotor(bool onOff);
|
2015-05-12 16:13:14 +08:00
|
|
|
bool getPoweredAngMotor() const;
|
2015-05-08 15:49:33 +08:00
|
|
|
void setTargetAngMotorVelocity(float targetAngMotorVelocity);
|
2015-05-12 16:13:14 +08:00
|
|
|
float getTargetAngMotorVelocity() const;
|
2015-05-08 15:49:33 +08:00
|
|
|
void setMaxAngMotorForce(float maxAngMotorForce);
|
2015-05-12 16:13:14 +08:00
|
|
|
float getMaxAngMotorForce() const;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-05-08 15:49:33 +08:00
|
|
|
float getLinearPos() const;
|
|
|
|
float getAngularPos() const;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-05-12 16:13:14 +08:00
|
|
|
/** access for UseFrameOffset*/
|
|
|
|
bool getUseFrameOffset() const;
|
2015-05-08 15:49:33 +08:00
|
|
|
/**set use frame offset*/
|
|
|
|
void setUseFrameOffset(bool frameOffsetOnOff);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-05-08 15:49:33 +08:00
|
|
|
/**set frames for rigid body A and B*/
|
2022-08-08 18:02:17 +08:00
|
|
|
void setFrames(const ax::Mat4& frameA, const ax::Mat4& frameB);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2022-03-18 21:46:07 +08:00
|
|
|
Physics3DSliderConstraint() { _type = ConstraintType::SLIDER; }
|
2021-12-25 10:04:45 +08:00
|
|
|
virtual ~Physics3DSliderConstraint() {}
|
2015-05-08 15:49:33 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* It is a special point to point constraint that adds cone and twist axis limits. The x-axis serves as twist axis.
|
|
|
|
*/
|
2022-07-15 19:17:01 +08:00
|
|
|
class AX_DLL Physics3DConeTwistConstraint : public Physics3DConstraint
|
2015-05-08 15:49:33 +08:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
2021-12-25 10:04:45 +08:00
|
|
|
* create cone twist constraint
|
2015-05-08 15:49:33 +08:00
|
|
|
* rbA rigid body A
|
|
|
|
* frameA A's local frame
|
|
|
|
*/
|
2022-08-08 18:02:17 +08:00
|
|
|
static Physics3DConeTwistConstraint* create(Physics3DRigidBody* rbA, const ax::Mat4& frameA);
|
2015-05-08 15:49:33 +08:00
|
|
|
/**
|
|
|
|
* create cone twist constraint
|
|
|
|
* rbA rigid body A
|
|
|
|
* rbB rigid body B
|
|
|
|
* frameA rigid body A's local frame
|
|
|
|
* frameB rigid body B's local frame
|
|
|
|
*/
|
2021-12-25 10:04:45 +08:00
|
|
|
static Physics3DConeTwistConstraint* create(Physics3DRigidBody* rbA,
|
|
|
|
Physics3DRigidBody* rbB,
|
2022-08-08 18:02:17 +08:00
|
|
|
const ax::Mat4& frameA,
|
|
|
|
const ax::Mat4& frameB);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-05-08 15:49:33 +08:00
|
|
|
/**
|
|
|
|
* set limits
|
|
|
|
* @param swingSpan1 swing span1
|
|
|
|
* @param swingSpan2 swing span2
|
|
|
|
* @param twistSpan twist span
|
2021-12-25 10:04:45 +08:00
|
|
|
* @param softness 0->1, recommend ~0.8->1. Describes % of limits where movement is free. Beyond this softness %,
|
|
|
|
* the limit is gradually enforced until the "hard" (1.0) limit is reached.
|
|
|
|
* @param biasFactor 0->1?, recommend 0.3 +/-0.3 or so. Strength with which constraint resists zeroth order
|
|
|
|
* (angular, not angular velocity) limit violation.
|
|
|
|
* @param relaxationFactor 0->1, recommend to stay near 1. the lower the value, the less the constraint will fight
|
|
|
|
* velocities which violate the angular limits.
|
|
|
|
*/
|
|
|
|
void setLimit(float swingSpan1,
|
|
|
|
float swingSpan2,
|
|
|
|
float twistSpan,
|
|
|
|
float softness = 1.f,
|
|
|
|
float biasFactor = 0.3f,
|
|
|
|
float relaxationFactor = 1.0f);
|
|
|
|
|
2015-05-08 15:49:33 +08:00
|
|
|
/**get A's frame*/
|
2022-08-08 18:02:17 +08:00
|
|
|
ax::Mat4 getAFrame() const;
|
2015-05-08 15:49:33 +08:00
|
|
|
/**get B's frame*/
|
2022-08-08 18:02:17 +08:00
|
|
|
ax::Mat4 getBFrame() const;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-05-08 15:49:33 +08:00
|
|
|
/**get swing span1*/
|
2015-05-12 16:13:14 +08:00
|
|
|
float getSwingSpan1() const;
|
2015-05-08 15:49:33 +08:00
|
|
|
/**get swing span2*/
|
2015-05-12 16:13:14 +08:00
|
|
|
float getSwingSpan2() const;
|
2015-05-08 15:49:33 +08:00
|
|
|
/**get twist span*/
|
2015-05-12 16:13:14 +08:00
|
|
|
float getTwistSpan() const;
|
2015-05-08 15:49:33 +08:00
|
|
|
/**get twist angle*/
|
2015-05-12 16:13:14 +08:00
|
|
|
float getTwistAngle() const;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-05-08 15:49:33 +08:00
|
|
|
/**set damping*/
|
2015-05-12 16:13:14 +08:00
|
|
|
void setDamping(float damping);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-05-08 15:49:33 +08:00
|
|
|
/**enable motor*/
|
2015-05-12 16:13:14 +08:00
|
|
|
void enableMotor(bool b);
|
2015-05-08 15:49:33 +08:00
|
|
|
/**set max motor impulse*/
|
2015-05-12 16:13:14 +08:00
|
|
|
void setMaxMotorImpulse(float maxMotorImpulse);
|
2015-05-08 15:49:33 +08:00
|
|
|
/**set max motor impulse normalize*/
|
2015-05-12 16:13:14 +08:00
|
|
|
void setMaxMotorImpulseNormalized(float maxMotorImpulse);
|
2015-05-08 15:49:33 +08:00
|
|
|
/**get fix thresh*/
|
2015-05-12 16:13:14 +08:00
|
|
|
float getFixThresh() const;
|
2015-05-08 15:49:33 +08:00
|
|
|
/**set fix thresh*/
|
2015-05-12 16:13:14 +08:00
|
|
|
void setFixThresh(float fixThresh);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-05-08 15:49:33 +08:00
|
|
|
/**
|
|
|
|
* setMotorTarget
|
2021-12-25 10:04:45 +08:00
|
|
|
* @param q the desired rotation of bodyA wrt bodyB. Note: if q violates the joint limits, the internal target is
|
|
|
|
* clamped to avoid conflicting impulses (very bad for stability), also don't forget to enableMotor()
|
2015-05-08 15:49:33 +08:00
|
|
|
*/
|
2021-12-25 10:04:45 +08:00
|
|
|
void setMotorTarget(const btQuaternion& q);
|
|
|
|
|
2015-05-12 16:13:14 +08:00
|
|
|
/** setMotorTarget, q is the desired rotation of frameA wrt frameB in constraint space*/
|
2021-12-25 10:04:45 +08:00
|
|
|
void setMotorTargetInConstraintSpace(const btQuaternion& q);
|
|
|
|
|
2015-05-08 15:49:33 +08:00
|
|
|
/**get point for angle*/
|
2022-08-08 18:02:17 +08:00
|
|
|
ax::Vec3 GetPointForAngle(float fAngleInRadians, float fLength) const;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-05-08 15:49:33 +08:00
|
|
|
/**set A and B's frame*/
|
2022-08-08 18:02:17 +08:00
|
|
|
virtual void setFrames(const ax::Mat4& frameA, const ax::Mat4& frameB);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-05-08 15:49:33 +08:00
|
|
|
/**get A's frame offset*/
|
2022-08-08 18:02:17 +08:00
|
|
|
ax::Mat4 getFrameOffsetA() const;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-05-08 15:49:33 +08:00
|
|
|
/**get B's frame offset*/
|
2022-08-08 18:02:17 +08:00
|
|
|
ax::Mat4 getFrameOffsetB() const;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2022-03-18 21:46:07 +08:00
|
|
|
Physics3DConeTwistConstraint() { _type = ConstraintType::CONE_TWIST; }
|
2021-12-25 10:04:45 +08:00
|
|
|
virtual ~Physics3DConeTwistConstraint() {}
|
2015-05-08 15:49:33 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2021-12-25 10:04:45 +08:00
|
|
|
* This generic constraint can emulate a variety of standard constraints, by configuring each of the 6 degrees of
|
|
|
|
* freedom (dof). The first 3 dof axis are linear axis, which represent translation of rigidbodies, and the latter 3 dof
|
|
|
|
* axis represent the angular motion. Each axis can be either locked, free or limited. All axis are locked by default.
|
2015-05-08 15:49:33 +08:00
|
|
|
* For each axis:
|
|
|
|
* Lowerlimit == Upperlimit -> axis is locked.
|
|
|
|
* Lowerlimit > Upperlimit -> axis is free
|
|
|
|
* Lowerlimit < Upperlimit -> axis it limited in that range
|
|
|
|
*/
|
2022-07-15 19:17:01 +08:00
|
|
|
class AX_DLL Physics3D6DofConstraint : public Physics3DConstraint
|
2015-05-08 15:49:33 +08:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* create 6 dof constraint
|
|
|
|
* @param rbA rigid body A
|
|
|
|
* @param rbB rigid body B
|
|
|
|
* @param frameInA frame in A's local space
|
|
|
|
* @param frameInB frame in B's local space
|
|
|
|
* @param useLinearReferenceFrameA use fixed frame A for linear limits
|
|
|
|
*/
|
2021-12-25 10:04:45 +08:00
|
|
|
static Physics3D6DofConstraint* create(Physics3DRigidBody* rbA,
|
|
|
|
Physics3DRigidBody* rbB,
|
2022-08-08 18:02:17 +08:00
|
|
|
const ax::Mat4& frameInA,
|
|
|
|
const ax::Mat4& frameInB,
|
2021-12-25 10:04:45 +08:00
|
|
|
bool useLinearReferenceFrameA);
|
|
|
|
|
2015-05-08 15:49:33 +08:00
|
|
|
/**
|
|
|
|
* create 6 dof constraint
|
|
|
|
* @param rbB rigid body B
|
|
|
|
* @param frameInB frame in B's local space
|
|
|
|
* @param useLinearReferenceFrameB use fixed frame B for linear limits
|
|
|
|
*/
|
2021-12-25 10:04:45 +08:00
|
|
|
static Physics3D6DofConstraint* create(Physics3DRigidBody* rbB,
|
2022-08-08 18:02:17 +08:00
|
|
|
const ax::Mat4& frameInB,
|
2021-12-25 10:04:45 +08:00
|
|
|
bool useLinearReferenceFrameB);
|
|
|
|
|
2015-05-08 15:49:33 +08:00
|
|
|
/**set linear lower limit*/
|
2022-08-08 18:02:17 +08:00
|
|
|
void setLinearLowerLimit(const ax::Vec3& linearLower);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-05-08 15:49:33 +08:00
|
|
|
/**get linear lower limit*/
|
2022-08-08 18:02:17 +08:00
|
|
|
ax::Vec3 getLinearLowerLimit() const;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-05-08 15:49:33 +08:00
|
|
|
/**set linear upper limit*/
|
2022-08-08 18:02:17 +08:00
|
|
|
void setLinearUpperLimit(const ax::Vec3& linearUpper);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-05-08 15:49:33 +08:00
|
|
|
/**get linear upper limit*/
|
2022-08-08 18:02:17 +08:00
|
|
|
ax::Vec3 getLinearUpperLimit() const;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-05-08 15:49:33 +08:00
|
|
|
/**set angular lower limit*/
|
2022-08-08 18:02:17 +08:00
|
|
|
void setAngularLowerLimit(const ax::Vec3& angularLower);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-05-08 15:49:33 +08:00
|
|
|
/**get angular lower limit*/
|
2022-08-08 18:02:17 +08:00
|
|
|
ax::Vec3 getAngularLowerLimit() const;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-05-08 15:49:33 +08:00
|
|
|
/**set angular upper limit*/
|
2022-08-08 18:02:17 +08:00
|
|
|
void setAngularUpperLimit(const ax::Vec3& angularUpper);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-05-08 15:49:33 +08:00
|
|
|
/**get angular upper limit*/
|
2022-08-08 18:02:17 +08:00
|
|
|
ax::Vec3 getAngularUpperLimit() const;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
|
|
/**
|
2015-05-08 15:49:33 +08:00
|
|
|
* is limited?
|
|
|
|
* @param limitIndex first 3 are linear, next 3 are angular
|
|
|
|
*/
|
2015-05-12 16:13:14 +08:00
|
|
|
bool isLimited(int limitIndex) const;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-05-12 16:13:14 +08:00
|
|
|
/** access for UseFrameOffset*/
|
|
|
|
bool getUseFrameOffset() const;
|
2015-05-08 15:49:33 +08:00
|
|
|
/**set use frame offset*/
|
2015-05-12 16:13:14 +08:00
|
|
|
void setUseFrameOffset(bool frameOffsetOnOff) const;
|
2015-05-08 15:49:33 +08:00
|
|
|
|
2022-03-18 21:46:07 +08:00
|
|
|
Physics3D6DofConstraint() { _type = ConstraintType::SIX_DOF; }
|
2021-12-25 10:04:45 +08:00
|
|
|
virtual ~Physics3D6DofConstraint() {}
|
2015-05-08 15:49:33 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
// end of 3d group
|
|
|
|
/// @}
|
|
|
|
|
2022-07-11 17:50:21 +08:00
|
|
|
NS_AX_END
|
2015-05-08 15:49:33 +08:00
|
|
|
|
2022-07-15 19:17:01 +08:00
|
|
|
# endif // AX_ENABLE_BULLET_INTEGRATION
|
2015-05-08 15:49:33 +08:00
|
|
|
|
2022-07-15 19:17:01 +08:00
|
|
|
#endif // AX_USE_3D_PHYSICS
|
2015-05-08 15:49:33 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
#endif // __PHYSICS_3D_CONSTRAINT_H__
|