Panda3D
Loading...
Searching...
No Matches
bulletConeTwistConstraint.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 bulletConeTwistConstraint.cxx
10 * @author enn0x
11 * @date 2010-03-01
12 */
13
15
16#include "bulletRigidBodyNode.h"
17#include "bulletWorld.h"
18
19#include "deg_2_rad.h"
20
21TypeHandle BulletConeTwistConstraint::_type_handle;
22
23/**
24 *
25 */
26BulletConeTwistConstraint::
27BulletConeTwistConstraint(const BulletRigidBodyNode *node_a,
28 const TransformState *frame_a) {
29
30 btRigidBody *ptr_a = btRigidBody::upcast(node_a->get_object());
31 btTransform trans_a = TransformState_to_btTrans(frame_a);
32
33 _constraint = new btConeTwistConstraint(*ptr_a, trans_a);
34}
35
36/**
37 *
38 */
39BulletConeTwistConstraint::
40BulletConeTwistConstraint(const BulletRigidBodyNode *node_a,
41 const BulletRigidBodyNode *node_b,
42 const TransformState *frame_a,
43 const TransformState *frame_b) {
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 btConeTwistConstraint(*ptr_a, *ptr_b, trans_a, trans_b);
52}
53
54/**
55 *
56 */
57btTypedConstraint *BulletConeTwistConstraint::
58ptr() const {
59
60 return _constraint;
61}
62
63/**
64 *
65 */
66void BulletConeTwistConstraint::
67set_limit(int index, PN_stdfloat value) {
68 LightMutexHolder holder(BulletWorld::get_global_lock());
69
70 value = deg_2_rad(value);
71
72 _constraint->setLimit(index, value);
73}
74
75/**
76 *
77 */
78void BulletConeTwistConstraint::
79set_limit(PN_stdfloat swing1, PN_stdfloat swing2, PN_stdfloat twist, PN_stdfloat softness, PN_stdfloat bias, PN_stdfloat relaxation) {
80 LightMutexHolder holder(BulletWorld::get_global_lock());
81
82 swing1 = deg_2_rad(swing1);
83 swing2 = deg_2_rad(swing2);
84 twist = deg_2_rad(twist);
85
86 _constraint->setLimit(swing1, swing2, twist, softness, bias, relaxation);
87}
88
89/**
90 *
91 */
92void BulletConeTwistConstraint::
93set_damping(PN_stdfloat damping) {
94 LightMutexHolder holder(BulletWorld::get_global_lock());
95
96 _constraint->setDamping(damping);
97}
98
99/**
100 *
101 */
102PN_stdfloat BulletConeTwistConstraint::
103get_fix_threshold() const {
104 LightMutexHolder holder(BulletWorld::get_global_lock());
105
106 return _constraint->getFixThresh();
107}
108
109/**
110 *
111 */
112void BulletConeTwistConstraint::
113set_fix_threshold(PN_stdfloat threshold) {
114 LightMutexHolder holder(BulletWorld::get_global_lock());
115
116 _constraint->setFixThresh(threshold);
117}
118
119/**
120 *
121 */
122void BulletConeTwistConstraint::
123enable_motor(bool enable) {
124 LightMutexHolder holder(BulletWorld::get_global_lock());
125
126 _constraint->enableMotor(enable);
127}
128
129/**
130 *
131 */
132void BulletConeTwistConstraint::
133set_max_motor_impulse(PN_stdfloat max_impulse) {
134 LightMutexHolder holder(BulletWorld::get_global_lock());
135
136 _constraint->setMaxMotorImpulse(max_impulse);
137}
138
139/**
140 *
141 */
142void BulletConeTwistConstraint::
143set_max_motor_impulse_normalized(PN_stdfloat max_impulse) {
144 LightMutexHolder holder(BulletWorld::get_global_lock());
145
146 _constraint->setMaxMotorImpulseNormalized(max_impulse);
147}
148
149/**
150 *
151 */
152void BulletConeTwistConstraint::
153set_motor_target(const LQuaternion &quat) {
154 LightMutexHolder holder(BulletWorld::get_global_lock());
155
156 _constraint->setMotorTarget(LQuaternion_to_btQuat(quat));
157}
158
159/**
160 *
161 */
162void BulletConeTwistConstraint::
163set_motor_target_in_constraint_space(const LQuaternion &quat) {
164 LightMutexHolder holder(BulletWorld::get_global_lock());
165
166 _constraint->setMotorTargetInConstraintSpace(LQuaternion_to_btQuat(quat));
167}
168
169/**
170 *
171 */
172void BulletConeTwistConstraint::
173set_frames(const TransformState *ts_a, const TransformState *ts_b) {
174 LightMutexHolder holder(BulletWorld::get_global_lock());
175
176 btTransform frame_a = TransformState_to_btTrans(ts_a);
177 btTransform frame_b = TransformState_to_btTrans(ts_b);
178
179 _constraint->setFrames(frame_a, frame_b);
180}
181
182/**
183 *
184 */
185CPT(TransformState) BulletConeTwistConstraint::
186get_frame_a() const {
187 LightMutexHolder holder(BulletWorld::get_global_lock());
188
189 return btTrans_to_TransformState(_constraint->getAFrame());
190}
191
192/**
193 *
194 */
195CPT(TransformState) BulletConeTwistConstraint::
196get_frame_b() const {
197 LightMutexHolder holder(BulletWorld::get_global_lock());
198
199 return btTrans_to_TransformState(_constraint->getBFrame());
200}
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
Similar to MutexHolder, but for a light mutex.
Indicates a coordinate-system transform on vertices.
TypeHandle is the identifier used to differentiate C++ class types.
Definition typeHandle.h:81
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.