Panda3D
bulletGenericConstraint.cxx
Go to the documentation of this file.
1 /**
2  * PANDA 3D SOFTWARE
3  * Copyright (c) Carnegie Mellon University. All rights reserved.
4  *
5  * All use of this software is subject to the terms of the revised BSD
6  * license. You should have received a copy of this license along
7  * with this source code in a file named "LICENSE."
8  *
9  * @file bulletGenericConstraint.cxx
10  * @author enn0x
11  * @date 2010-03-02
12  */
13 
15 
16 #include "bulletRigidBodyNode.h"
17 #include "bulletWorld.h"
18 
19 TypeHandle BulletGenericConstraint::_type_handle;
20 
21 /**
22  *
23  */
24 BulletGenericConstraint::
25 BulletGenericConstraint(const BulletRigidBodyNode *node_a,
26  const TransformState *frame_a,
27  bool use_frame_a) {
28 
29  btRigidBody *ptr_a = btRigidBody::upcast(node_a->get_object());
30  btTransform trans_a = TransformState_to_btTrans(frame_a);
31 
32  _constraint = new btGeneric6DofConstraint(*ptr_a, trans_a, use_frame_a);
33 }
34 
35 /**
36  *
37  */
38 BulletGenericConstraint::
39 BulletGenericConstraint(const BulletRigidBodyNode *node_a,
40  const BulletRigidBodyNode *node_b,
41  const TransformState *frame_a,
42  const TransformState *frame_b,
43  bool use_frame_a) {
44 
45  btRigidBody *ptr_a = btRigidBody::upcast(node_a->get_object());
46  btTransform trans_a = TransformState_to_btTrans(frame_a);
47 
48  btRigidBody *ptr_b = btRigidBody::upcast(node_b->get_object());
49  btTransform trans_b = TransformState_to_btTrans(frame_b);
50 
51  _constraint = new btGeneric6DofConstraint(*ptr_a, *ptr_b, trans_a, trans_b, use_frame_a);
52 }
53 
54 /**
55  *
56  */
57 btTypedConstraint *BulletGenericConstraint::
58 ptr() const {
59 
60  return _constraint;
61 }
62 
63 /**
64  *
65  */
66 LVector3 BulletGenericConstraint::
67 get_axis(int axis) const {
68  LightMutexHolder holder(BulletWorld::get_global_lock());
69 
70  nassertr(axis >= 0, LVector3::zero());
71  nassertr(axis <= 3, LVector3::zero());
72 
73  _constraint->buildJacobian();
74  return btVector3_to_LVector3(_constraint->getAxis(axis));
75 }
76 
77 /**
78  *
79  */
80 PN_stdfloat BulletGenericConstraint::
81 get_pivot(int axis) const {
82  LightMutexHolder holder(BulletWorld::get_global_lock());
83 
84  nassertr(axis >= 0, 0.0f);
85  nassertr(axis <= 3, 0.0f);
86 
87  _constraint->buildJacobian();
88  return _constraint->getRelativePivotPosition(axis);
89 }
90 
91 /**
92  *
93  */
94 PN_stdfloat BulletGenericConstraint::
95 get_angle(int axis) const {
96  LightMutexHolder holder(BulletWorld::get_global_lock());
97 
98  nassertr(axis >= 0, 0.0f);
99  nassertr(axis <= 3, 0.0f);
100 
101  _constraint->buildJacobian();
102  return _constraint->getAngle(axis);
103 }
104 
105 /**
106  *
107  */
108 void BulletGenericConstraint::
109 set_linear_limit(int axis, PN_stdfloat low, PN_stdfloat high) {
110  LightMutexHolder holder(BulletWorld::get_global_lock());
111 
112  nassertv(axis >= 0);
113  nassertv(axis <= 3);
114 
115  _constraint->buildJacobian();
116  _constraint->setLimit(axis, low, high);
117 }
118 
119 /**
120  *
121  */
122 void BulletGenericConstraint::
123 set_angular_limit(int axis, PN_stdfloat low, PN_stdfloat high) {
124  LightMutexHolder holder(BulletWorld::get_global_lock());
125 
126  nassertv(axis >= 0);
127  nassertv(axis <= 3);
128 
129  low = deg_2_rad(low);
130  high = deg_2_rad(high);
131 
132  _constraint->buildJacobian();
133  _constraint->setLimit(axis + 3, low, high);
134 }
135 
136 /**
137  *
138  */
139 CPT(TransformState) BulletGenericConstraint::
140 get_frame_a() const {
141  LightMutexHolder holder(BulletWorld::get_global_lock());
142 
143  return btTrans_to_TransformState(_constraint->getFrameOffsetA());
144 }
145 
146 /**
147  *
148  */
149 CPT(TransformState) BulletGenericConstraint::
150 get_frame_b() const {
151  LightMutexHolder holder(BulletWorld::get_global_lock());
152 
153  return btTrans_to_TransformState(_constraint->getFrameOffsetB());
154 }
155 
156 /**
157  *
158  */
159 BulletRotationalLimitMotor BulletGenericConstraint::
160 get_rotational_limit_motor(int axis) {
161  LightMutexHolder holder(BulletWorld::get_global_lock());
162 
163  return BulletRotationalLimitMotor(*_constraint->getRotationalLimitMotor(axis));
164 }
165 
166 /**
167  *
168  */
169 BulletTranslationalLimitMotor BulletGenericConstraint::
170 get_translational_limit_motor() {
171  LightMutexHolder holder(BulletWorld::get_global_lock());
172 
173  return BulletTranslationalLimitMotor(*_constraint->getTranslationalLimitMotor());
174 }
175 
176 /**
177  *
178  */
179 void BulletGenericConstraint::
180 set_frames(const TransformState *ts_a, const TransformState *ts_b) {
181  LightMutexHolder holder(BulletWorld::get_global_lock());
182 
183  btTransform frame_a = TransformState_to_btTrans(ts_a);
184  btTransform frame_b = TransformState_to_btTrans(ts_b);
185 
186  _constraint->setFrames(frame_a, frame_b);
187 }
Indicates a coordinate-system transform on vertices.
Rotation Limit structure for generic joints.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
Rotation Limit structure for generic joints.
Similar to MutexHolder, but for a light mutex.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:81