Panda3D
bulletSliderConstraint.cxx
1 // Filename: bulletSliderConstraint.cxx
2 // Created by: enn0x (01Mar10)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #include "bulletSliderConstraint.h"
16 #include "bulletRigidBodyNode.h"
17 
18 #include "deg_2_rad.h"
19 
20 TypeHandle BulletSliderConstraint::_type_handle;
21 
22 ////////////////////////////////////////////////////////////////////
23 // Function: BulletSliderConstraint::Constructor
24 // Access: Published
25 // Description:
26 ////////////////////////////////////////////////////////////////////
27 BulletSliderConstraint::
28 BulletSliderConstraint(const BulletRigidBodyNode *node_a,
29  const TransformState *frame_a,
30  bool use_frame_a) {
31 
32  btRigidBody *ptr_a = btRigidBody::upcast(node_a->get_object());
33  btTransform trans_a = TransformState_to_btTrans(frame_a);
34 
35  _constraint = new btSliderConstraint(*ptr_a, trans_a, use_frame_a);
36 }
37 
38 ////////////////////////////////////////////////////////////////////
39 // Function: BulletSliderConstraint::Constructor
40 // Access: Published
41 // Description:
42 ////////////////////////////////////////////////////////////////////
43 BulletSliderConstraint::
44 BulletSliderConstraint(const BulletRigidBodyNode *node_a,
45  const BulletRigidBodyNode *node_b,
46  const TransformState *frame_a,
47  const TransformState *frame_b,
48  bool use_frame_a) {
49 
50  btRigidBody *ptr_a = btRigidBody::upcast(node_a->get_object());
51  btTransform trans_a = TransformState_to_btTrans(frame_a);
52 
53  btRigidBody *ptr_b = btRigidBody::upcast(node_b->get_object());
54  btTransform trans_b = TransformState_to_btTrans(frame_b);
55 
56  _constraint = new btSliderConstraint(*ptr_a, *ptr_b, trans_a, trans_b, use_frame_a);
57 }
58 
59 ////////////////////////////////////////////////////////////////////
60 // Function: BulletSliderConstraint::ptr
61 // Access: Public
62 // Description:
63 ////////////////////////////////////////////////////////////////////
64 btTypedConstraint *BulletSliderConstraint::
65 ptr() const {
66 
67  return _constraint;
68 }
69 
70 ////////////////////////////////////////////////////////////////////
71 // Function: BulletSliderConstraint::get_lower_linear_limit
72 // Access: Published
73 // Description:
74 ////////////////////////////////////////////////////////////////////
75 PN_stdfloat BulletSliderConstraint::
76 get_lower_linear_limit() const {
77 
78  return (PN_stdfloat)_constraint->getLowerLinLimit();
79 }
80 
81 ////////////////////////////////////////////////////////////////////
82 // Function: BulletSliderConstraint::get_upper_linear_limit
83 // Access: Published
84 // Description:
85 ////////////////////////////////////////////////////////////////////
86 PN_stdfloat BulletSliderConstraint::
87 get_upper_linear_limit() const {
88 
89  return (PN_stdfloat)_constraint->getUpperLinLimit();
90 }
91 
92 ////////////////////////////////////////////////////////////////////
93 // Function: BulletSliderConstraint::get_lower_angular_limit
94 // Access: Published
95 // Description:
96 ////////////////////////////////////////////////////////////////////
97 PN_stdfloat BulletSliderConstraint::
98 get_lower_angular_limit() const {
99 
100  return rad_2_deg(_constraint->getLowerAngLimit());
101 }
102 
103 ////////////////////////////////////////////////////////////////////
104 // Function: BulletSliderConstraint::get_upper_angular_limit
105 // Access: Published
106 // Description:
107 ////////////////////////////////////////////////////////////////////
108 PN_stdfloat BulletSliderConstraint::
109 get_upper_angular_limit() const {
110 
111  return rad_2_deg(_constraint->getUpperAngLimit());
112 }
113 
114 ////////////////////////////////////////////////////////////////////
115 // Function: BulletSliderConstraint::set_lower_linear_limit
116 // Access: Published
117 // Description:
118 ////////////////////////////////////////////////////////////////////
119 void BulletSliderConstraint::
120 set_lower_linear_limit(PN_stdfloat value) {
121 
122  _constraint->setLowerLinLimit((btScalar)value);
123 }
124 
125 ////////////////////////////////////////////////////////////////////
126 // Function: BulletSliderConstraint::set_upper_linear_limit
127 // Access: Published
128 // Description:
129 ////////////////////////////////////////////////////////////////////
130 void BulletSliderConstraint::
131 set_upper_linear_limit(PN_stdfloat value) {
132 
133  _constraint->setUpperLinLimit((btScalar)value);
134 }
135 
136 ////////////////////////////////////////////////////////////////////
137 // Function: BulletSliderConstraint::set_lower_angular_limit
138 // Access: Published
139 // Description:
140 ////////////////////////////////////////////////////////////////////
141 void BulletSliderConstraint::
142 set_lower_angular_limit(PN_stdfloat value) {
143 
144  _constraint->setLowerAngLimit((btScalar)deg_2_rad(value));
145 }
146 
147 ////////////////////////////////////////////////////////////////////
148 // Function: BulletSliderConstraint::set_upper_angular_limit
149 // Access: Published
150 // Description:
151 ////////////////////////////////////////////////////////////////////
152 void BulletSliderConstraint::
153 set_upper_angular_limit(PN_stdfloat value) {
154 
155  _constraint->setUpperAngLimit((btScalar)deg_2_rad(value));
156 }
157 
158 ////////////////////////////////////////////////////////////////////
159 // Function: BulletSliderConstraint::get_linear_pos
160 // Access: Published
161 // Description:
162 ////////////////////////////////////////////////////////////////////
163 PN_stdfloat BulletSliderConstraint::
164 get_linear_pos() const {
165 
166  return (PN_stdfloat)_constraint->getLinearPos();
167 }
168 
169 ////////////////////////////////////////////////////////////////////
170 // Function: BulletSliderConstraint::get_angular_pos
171 // Access: Published
172 // Description:
173 ////////////////////////////////////////////////////////////////////
174 PN_stdfloat BulletSliderConstraint::
175 get_angular_pos() const {
176 
177  return (PN_stdfloat)_constraint->getAngularPos();
178 }
179 
180 ////////////////////////////////////////////////////////////////////
181 // Function: BulletSliderConstraint::set_powered_linear_motor
182 // Access: Published
183 // Description:
184 ////////////////////////////////////////////////////////////////////
185 void BulletSliderConstraint::
186 set_powered_linear_motor(bool on) {
187 
188  _constraint->setPoweredLinMotor(on);
189 }
190 
191 ////////////////////////////////////////////////////////////////////
192 // Function: BulletSliderConstraint::set_target_linear_motor_velocity
193 // Access: Published
194 // Description:
195 ////////////////////////////////////////////////////////////////////
196 void BulletSliderConstraint::
197 set_target_linear_motor_velocity(PN_stdfloat target_velocity) {
198 
199  _constraint->setTargetLinMotorVelocity((btScalar)target_velocity);
200 }
201 
202 ////////////////////////////////////////////////////////////////////
203 // Function: BulletSliderConstraint::set_max_linear_motor_force
204 // Access: Published
205 // Description:
206 ////////////////////////////////////////////////////////////////////
207 void BulletSliderConstraint::
208 set_max_linear_motor_force(PN_stdfloat max_force) {
209 
210  _constraint->setMaxLinMotorForce((btScalar)max_force);
211 }
212 
213 ////////////////////////////////////////////////////////////////////
214 // Function: BulletSliderConstraint::get_powered_linear_motor
215 // Access: Published
216 // Description:
217 ////////////////////////////////////////////////////////////////////
218 bool BulletSliderConstraint::
219 get_powered_linear_motor() const {
220 
221  return _constraint->getPoweredLinMotor();
222 }
223 
224 ////////////////////////////////////////////////////////////////////
225 // Function: BulletSliderConstraint::get_target_linear_motor_velocity
226 // Access: Published
227 // Description:
228 ////////////////////////////////////////////////////////////////////
229 PN_stdfloat BulletSliderConstraint::
230 get_target_linear_motor_velocity() const {
231 
232  return (PN_stdfloat)_constraint->getTargetLinMotorVelocity();
233 }
234 
235 ////////////////////////////////////////////////////////////////////
236 // Function: BulletSliderConstraint::get_max_linear_motor_force
237 // Access: Published
238 // Description:
239 ////////////////////////////////////////////////////////////////////
240 PN_stdfloat BulletSliderConstraint::
241 get_max_linear_motor_force() const {
242 
243  return (PN_stdfloat)_constraint->getMaxLinMotorForce();
244 }
245 
246 ////////////////////////////////////////////////////////////////////
247 // Function: BulletSliderConstraint::set_powered_angular_motor
248 // Access: Published
249 // Description:
250 ////////////////////////////////////////////////////////////////////
251 void BulletSliderConstraint::
252 set_powered_angular_motor(bool on) {
253 
254  _constraint->setPoweredAngMotor(on);
255 }
256 
257 ////////////////////////////////////////////////////////////////////
258 // Function: BulletSliderConstraint::set_target_angular_motor_velocity
259 // Access: Published
260 // Description:
261 ////////////////////////////////////////////////////////////////////
262 void BulletSliderConstraint::
263 set_target_angular_motor_velocity(PN_stdfloat target_velocity) {
264 
265  _constraint->setTargetAngMotorVelocity((btScalar)target_velocity);
266 }
267 
268 ////////////////////////////////////////////////////////////////////
269 // Function: BulletSliderConstraint::set_max_angular_motor_force
270 // Access: Published
271 // Description:
272 ////////////////////////////////////////////////////////////////////
273 void BulletSliderConstraint::
274 set_max_angular_motor_force(PN_stdfloat max_force) {
275 
276  _constraint->setMaxAngMotorForce((btScalar)max_force);
277 }
278 
279 ////////////////////////////////////////////////////////////////////
280 // Function: BulletSliderConstraint::get_powered_angular_motor
281 // Access: Published
282 // Description:
283 ////////////////////////////////////////////////////////////////////
284 bool BulletSliderConstraint::
285 get_powered_angular_motor() const {
286 
287  return _constraint->getPoweredAngMotor();
288 }
289 
290 ////////////////////////////////////////////////////////////////////
291 // Function: BulletSliderConstraint::get_target_angular_motor_velocity
292 // Access: Published
293 // Description:
294 ////////////////////////////////////////////////////////////////////
295 PN_stdfloat BulletSliderConstraint::
296 get_target_angular_motor_velocity() const {
297 
298  return (PN_stdfloat)_constraint->getTargetAngMotorVelocity();
299 }
300 
301 ////////////////////////////////////////////////////////////////////
302 // Function: BulletSliderConstraint::get_max_angular_motor_force
303 // Access: Published
304 // Description:
305 ////////////////////////////////////////////////////////////////////
306 PN_stdfloat BulletSliderConstraint::
307 get_max_angular_motor_force() const {
308 
309  return (PN_stdfloat)_constraint->getMaxAngMotorForce();
310 }
311 
312 ////////////////////////////////////////////////////////////////////
313 // Function: BulletSliderConstraint::set_frames
314 // Access: Published
315 // Description:
316 ////////////////////////////////////////////////////////////////////
317 void BulletSliderConstraint::
318 set_frames(const TransformState *ts_a, const TransformState *ts_b) {
319 
320  btTransform frame_a = TransformState_to_btTrans(ts_a);
321  btTransform frame_b = TransformState_to_btTrans(ts_b);
322 
323  _constraint->setFrames(frame_a, frame_b);
324 }
325 
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85