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
14#include "bulletConeTwistConstraint.h"
15
16#include "bulletRigidBodyNode.h"
17#include "bulletWorld.h"
18
19#include "deg_2_rad.h"
20
21 TypeHandle 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 */
66 void 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 */
78 void 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 */
92 void 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 */
112 void BulletConeTwistConstraint::
113set_fix_threshold(PN_stdfloat threshold) {
114 LightMutexHolder holder(BulletWorld::get_global_lock());
115
116 _constraint->setFixThresh(threshold);
117}
118
119/**
120 *
121 */
122 void BulletConeTwistConstraint::
123enable_motor(bool enable) {
124 LightMutexHolder holder(BulletWorld::get_global_lock());
125
126 _constraint->enableMotor(enable);
127}
128
129/**
130 *
131 */
132 void 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 */
142 void 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 */
152 void 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 */
162 void 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 */
172 void 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}
bulletConeTwistConstraint.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
bulletRigidBodyNode.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
bulletWorld.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
BulletRigidBodyNode
Definition bulletRigidBodyNode.h:31
TransformState
Indicates a coordinate-system transform on vertices.
Definition transformState.h:54
TypeHandle
TypeHandle is the identifier used to differentiate C++ class types.
Definition typeHandle.h:81
deg_2_rad.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.