Panda3D
 All Classes Functions Variables Enumerations
bulletConeTwistConstraint.cxx
1 // Filename: bulletConeTwistConstraint.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 "bulletConeTwistConstraint.h"
16 #include "bulletRigidBodyNode.h"
17 
18 #include "deg_2_rad.h"
19 
20 TypeHandle BulletConeTwistConstraint::_type_handle;
21 
22 ////////////////////////////////////////////////////////////////////
23 // Function: BulletConeTwistConstraint::Constructor
24 // Access: Published
25 // Description:
26 ////////////////////////////////////////////////////////////////////
27 BulletConeTwistConstraint::
28 BulletConeTwistConstraint(const BulletRigidBodyNode *node_a,
29  const TransformState *frame_a) {
30 
31  btRigidBody *ptr_a = btRigidBody::upcast(node_a->get_object());
32  btTransform trans_a = TransformState_to_btTrans(frame_a);
33 
34  _constraint = new btConeTwistConstraint(*ptr_a, trans_a);
35 }
36 
37 ////////////////////////////////////////////////////////////////////
38 // Function: BulletConeTwistConstraint::Constructor
39 // Access: Published
40 // Description:
41 ////////////////////////////////////////////////////////////////////
42 BulletConeTwistConstraint::
43 BulletConeTwistConstraint(const BulletRigidBodyNode *node_a,
44  const BulletRigidBodyNode *node_b,
45  const TransformState *frame_a,
46  const TransformState *frame_b) {
47 
48  btRigidBody *ptr_a = btRigidBody::upcast(node_a->get_object());
49  btTransform trans_a = TransformState_to_btTrans(frame_a);
50 
51  btRigidBody *ptr_b = btRigidBody::upcast(node_b->get_object());
52  btTransform trans_b = TransformState_to_btTrans(frame_b);
53 
54  _constraint = new btConeTwistConstraint(*ptr_a, *ptr_b, trans_a, trans_b);
55 }
56 
57 ////////////////////////////////////////////////////////////////////
58 // Function: BulletConeTwistConstraint::ptr
59 // Access: Public
60 // Description:
61 ////////////////////////////////////////////////////////////////////
62 btTypedConstraint *BulletConeTwistConstraint::
63 ptr() const {
64 
65  return _constraint;
66 }
67 
68 ////////////////////////////////////////////////////////////////////
69 // Function: BulletConeTwistConstraint::set_limit
70 // Access: Published
71 // Description:
72 ////////////////////////////////////////////////////////////////////
73 void BulletConeTwistConstraint::
74 set_limit(int index, PN_stdfloat value) {
75 
76  value = deg_2_rad(value);
77 
78  _constraint->setLimit(index, value);
79 }
80 
81 ////////////////////////////////////////////////////////////////////
82 // Function: BulletConeTwistConstraint::set_limit
83 // Access: Published
84 // Description:
85 ////////////////////////////////////////////////////////////////////
86 void BulletConeTwistConstraint::
87 set_limit(PN_stdfloat swing1, PN_stdfloat swing2, PN_stdfloat twist, PN_stdfloat softness, PN_stdfloat bias, PN_stdfloat relaxation) {
88 
89  swing1 = deg_2_rad(swing1);
90  swing2 = deg_2_rad(swing2);
91  twist = deg_2_rad(twist);
92 
93  _constraint->setLimit(swing1, swing2, twist, softness, bias, relaxation);
94 }
95 
96 ////////////////////////////////////////////////////////////////////
97 // Function: BulletConeTwistConstraint::set_damping
98 // Access: Published
99 // Description:
100 ////////////////////////////////////////////////////////////////////
101 void BulletConeTwistConstraint::
102 set_damping(PN_stdfloat damping) {
103 
104  _constraint->setDamping(damping);
105 }
106 
107 ////////////////////////////////////////////////////////////////////
108 // Function: BulletConeTwistConstraint::get_fix_threshold
109 // Access: Published
110 // Description:
111 ////////////////////////////////////////////////////////////////////
112 PN_stdfloat BulletConeTwistConstraint::
113 get_fix_threshold() const {
114 
115  return _constraint->getFixThresh();
116 }
117 
118 ////////////////////////////////////////////////////////////////////
119 // Function: BulletConeTwistConstraint::set_fix_threshold
120 // Access: Published
121 // Description:
122 ////////////////////////////////////////////////////////////////////
123 void BulletConeTwistConstraint::
124 set_fix_threshold(PN_stdfloat threshold) {
125 
126  _constraint->setFixThresh(threshold);
127 }
128 
129 ////////////////////////////////////////////////////////////////////
130 // Function: BulletConeTwistConstraint::enable_motor
131 // Access: Published
132 // Description:
133 ////////////////////////////////////////////////////////////////////
134 void BulletConeTwistConstraint::
135 enable_motor(bool enable) {
136 
137  _constraint->enableMotor(enable);
138 }
139 
140 ////////////////////////////////////////////////////////////////////
141 // Function: BulletConeTwistConstraint::set_max_motor_impulse
142 // Access: Published
143 // Description:
144 ////////////////////////////////////////////////////////////////////
145 void BulletConeTwistConstraint::
146 set_max_motor_impulse(PN_stdfloat max_impulse) {
147 
148  _constraint->setMaxMotorImpulse(max_impulse);
149 }
150 
151 ////////////////////////////////////////////////////////////////////
152 // Function: BulletConeTwistConstraint::set_max_motor_impulse_normalized
153 // Access: Published
154 // Description:
155 ////////////////////////////////////////////////////////////////////
156 void BulletConeTwistConstraint::
157 set_max_motor_impulse_normalized(PN_stdfloat max_impulse) {
158 
159  _constraint->setMaxMotorImpulseNormalized(max_impulse);
160 }
161 
162 ////////////////////////////////////////////////////////////////////
163 // Function: BulletConeTwistConstraint::set_motor_target
164 // Access: Published
165 // Description:
166 ////////////////////////////////////////////////////////////////////
167 void BulletConeTwistConstraint::
168 set_motor_target(const LQuaternion &quat) {
169 
170  _constraint->setMotorTarget(LQuaternion_to_btQuat(quat));
171 }
172 
173 ////////////////////////////////////////////////////////////////////
174 // Function: BulletConeTwistConstraint::set_motor_target_in_constraint_space
175 // Access: Published
176 // Description:
177 ////////////////////////////////////////////////////////////////////
178 void BulletConeTwistConstraint::
179 set_motor_target_in_constraint_space(const LQuaternion &quat) {
180 
181  _constraint->setMotorTargetInConstraintSpace(LQuaternion_to_btQuat(quat));
182 }
183 
184 ////////////////////////////////////////////////////////////////////
185 // Function: BulletConeTwistConstraint::set_frames
186 // Access: Published
187 // Description:
188 ////////////////////////////////////////////////////////////////////
189 void BulletConeTwistConstraint::
190 set_frames(const TransformState *ts_a, const TransformState *ts_b) {
191 
192  btTransform frame_a = TransformState_to_btTrans(ts_a);
193  btTransform frame_b = TransformState_to_btTrans(ts_b);
194 
195  _constraint->setFrames(frame_a, frame_b);
196 }
197 
This is the base quaternion class.
Definition: lquaternion.h:96
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85