15 #include "bulletHingeConstraint.h" 16 #include "bulletRigidBodyNode.h" 18 #include "deg_2_rad.h" 20 TypeHandle BulletHingeConstraint::_type_handle;
30 const TransformState *ts_a,
33 btRigidBody *ptr_a = btRigidBody::upcast(node_a->get_object());
34 btTransform frame_a = TransformState_to_btTrans(ts_a);
36 _constraint =
new btHingeConstraint(*ptr_a, frame_a, use_frame_a);
48 const TransformState *ts_a,
49 const TransformState *ts_b,
52 btRigidBody *ptr_a = btRigidBody::upcast(node_a->get_object());
53 btTransform frame_a = TransformState_to_btTrans(ts_a);
55 btRigidBody *ptr_b = btRigidBody::upcast(node_b->get_object());
56 btTransform frame_b = TransformState_to_btTrans(ts_b);
58 _constraint =
new btHingeConstraint(*ptr_a, *ptr_b, frame_a, frame_b, use_frame_a);
75 btRigidBody *ptr_a = btRigidBody::upcast(node_a->get_object());
76 btVector3 pos_a = LVecBase3_to_btVector3(pivot_a);
77 btVector3 vec_a = LVecBase3_to_btVector3(axis_a);
79 _constraint =
new btHingeConstraint(*ptr_a, pos_a, vec_a, use_frame_a);
102 btRigidBody *ptr_a = btRigidBody::upcast(node_a->get_object());
103 btVector3 pos_a = LVecBase3_to_btVector3(pivot_a);
104 btVector3 vec_a = LVecBase3_to_btVector3(axis_a);
106 btRigidBody *ptr_b = btRigidBody::upcast(node_b->get_object());
107 btVector3 pos_b = LVecBase3_to_btVector3(pivot_b);
108 btVector3 vec_b = LVecBase3_to_btVector3(axis_b);
110 _constraint =
new btHingeConstraint(*ptr_a, *ptr_b, pos_a, pos_b, vec_a, vec_b, use_frame_a);
118 btTypedConstraint *BulletHingeConstraint::
129 void BulletHingeConstraint::
130 set_angular_only(
bool value) {
132 return _constraint->setAngularOnly(value);
140 bool BulletHingeConstraint::
141 get_angular_only()
const {
143 return _constraint->getAngularOnly();
153 set_limit(PN_stdfloat low, PN_stdfloat high, PN_stdfloat softness, PN_stdfloat bias, PN_stdfloat relaxation) {
155 low = deg_2_rad(low);
156 high = deg_2_rad(high);
158 _constraint->setLimit(low, high, softness, bias, relaxation);
172 btVector3 v = LVecBase3_to_btVector3(axis);
173 _constraint->setAxis(v);
184 return rad_2_deg(_constraint->getLowerLimit());
195 return rad_2_deg(_constraint->getUpperLimit());
207 return rad_2_deg(_constraint->getHingeAngle());
224 _constraint->enableAngularMotor(enable, target_velocity, max_impulse);
232 void BulletHingeConstraint::
233 enable_motor(
bool enable) {
235 _constraint->enableMotor(enable);
247 _constraint->setMaxMotorImpulse(max_impulse);
255 void BulletHingeConstraint::
256 set_motor_target(
const LQuaternion &quat, PN_stdfloat dt) {
258 _constraint->setMotorTarget(LQuaternion_to_btQuat(quat), dt);
266 void BulletHingeConstraint::
267 set_motor_target(PN_stdfloat target_angle, PN_stdfloat dt) {
269 _constraint->setMotorTarget(target_angle, dt);
277 void BulletHingeConstraint::
278 set_frames(
const TransformState *ts_a,
const TransformState *ts_b) {
280 btTransform frame_a = TransformState_to_btTrans(ts_a);
281 btTransform frame_b = TransformState_to_btTrans(ts_b);
283 _constraint->setFrames(frame_a, frame_b);
void set_axis(const LVector3 &axis)
Sets the hinge's rotation axis in world coordinates.
PN_stdfloat get_hinge_angle()
Returns the angle between node_a and node_b in degrees.
void enable_angular_motor(bool enable, PN_stdfloat target_velocity, PN_stdfloat max_impulse)
Applies an impulse to the constraint so that the angle changes at target_velocity where max_impulse i...
PN_stdfloat get_lower_limit() const
Returns the lower angular limit in degrees.
PN_stdfloat get_upper_limit() const
Returns the upper angular limit in degrees.
This is a three-component vector distance (as opposed to a three-component point, which represents a ...
This is a three-component point in space (as opposed to a three-component vector, which represents a ...
bool is_nan() const
Returns true if any component of the vector is not-a-number, false otherwise.
void set_max_motor_impulse(PN_stdfloat max_impulse)
Sets the maximum impulse used to achieve the velocity set in enable_angular_motor.
void set_limit(PN_stdfloat low, PN_stdfloat high, PN_stdfloat softness=0.9f, PN_stdfloat bias=0.3f, PN_stdfloat relaxation=1.0f)
Sets the lower and upper rotational limits in degrees.
This is the base quaternion class.
BulletHingeConstraint(const BulletRigidBodyNode *node_a, const LPoint3 &pivot_a, const LVector3 &axis_a, bool use_frame_a=false)
Creates a hinge constraint in the same way as the other constructor, but uses the world as second bod...
TypeHandle is the identifier used to differentiate C++ class types.