Panda3D
Loading...
Searching...
No Matches
odeJoint.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 odeJoint.cxx
10 * @author joswilso
11 * @date 2006-12-27
12 */
13
14#include "config_ode.h"
15#include "odeJoint.h"
16#include "odeBallJoint.h"
17#include "odeHingeJoint.h"
18#include "odeHinge2Joint.h"
19#include "odeSliderJoint.h"
20#include "odeContactJoint.h"
21#include "odeUniversalJoint.h"
22#include "odeFixedJoint.h"
23#include "odeNullJoint.h"
24#include "odePlane2dJoint.h"
25#include "odeAMotorJoint.h"
26#include "odeLMotorJoint.h"
27#include "odeBody.h"
28
29TypeHandle OdeJoint::_type_handle;
30
31OdeJoint::
32OdeJoint() :
33 _id(nullptr) {
34 if (odejoint_cat.is_debug()) {
35 std::ostream &out = odejoint_cat.debug();
36 out << get_type() << "(" << _id << ")\n";
37 }
38}
39
40OdeJoint::
41OdeJoint(dJointID id) :
42 _id(id) {
43 if (odejoint_cat.is_debug()) {
44 std::ostream &out = odejoint_cat.debug();
45 out << get_type() << "(" << _id << ")\n";
46 }
47}
48
49OdeJoint::
50~OdeJoint() {
51}
52
53void OdeJoint::
54destroy() {
55 nassertv(_id);
56 dJointDestroy(_id);
57}
58
59/**
60 * Attaches two OdeBody objects to this joint. Order is important. Consider
61 * using the OdeJoint::attach extension function if you're using the Python
62 * interface.
63 */
65attach_bodies(const OdeBody &body1, const OdeBody &body2) {
66 nassertv(_id);
67 nassertv(body1.get_id() != nullptr || body2.get_id() != nullptr);
68 dJointAttach(_id, body1.get_id(), body2.get_id());
69}
70
71/**
72 * Attaches a single OdeBody to this joint at the specified index (0 or 1).
73 * The other index will be set to the environment (null). Consider using the
74 * OdeJoint::attach extension function if you're using the Python interface.
75 */
77attach_body(const OdeBody &body, int index) {
78 nassertv(_id);
79 nassertv(body.get_id() != nullptr);
80 nassertv(index == 0 || index == 1);
81 if (index == 0) {
82 dJointAttach(_id, body.get_id(), nullptr);
83 } else {
84 dJointAttach(_id, nullptr, body.get_id());
85 }
86}
87
88void OdeJoint::
89detach() {
90 nassertv(_id);
91 dJointAttach(_id, nullptr, nullptr);
92}
93
94OdeBody OdeJoint::
95get_body(int index) const {
96 nassertr(_id, OdeBody(nullptr));
97 nassertr(index == 0 || index == 1, OdeBody(nullptr));
98 return OdeBody(dJointGetBody(_id, index));
99}
100
101void OdeJoint::
102write(std::ostream &out, unsigned int indent) const {
103 out.width(indent); out << "" << get_type() \
104 << "(id = " << _id \
105 << ", body1 = ";
106 OdeBody body = get_body(0);
107 if (body.get_id() != nullptr) {
108 body.write(out);
109 }
110 else {
111 out << "0";
112 }
113 out << ", body2 = ";
114 body = get_body(1);
115 if (body.get_id() != nullptr) {
116 body.write(out);
117 }
118 else {
119 out << "0";
120 }
121 out << ")";
122
123}
124
125OdeJoint::
126operator bool () const {
127 return (_id != nullptr);
128}
129
130OdeBallJoint OdeJoint::
131convert_to_ball() const {
132 nassertr(_id != nullptr, OdeBallJoint(nullptr));
133 nassertr(get_joint_type() == JT_ball, OdeBallJoint(nullptr));
134 return OdeBallJoint(_id);
135}
136
137OdeHingeJoint OdeJoint::
138convert_to_hinge() const {
139 nassertr(_id != nullptr, OdeHingeJoint(nullptr));
140 nassertr(get_joint_type() == JT_hinge, OdeHingeJoint(nullptr));
141 return OdeHingeJoint(_id);
142}
143
144OdeSliderJoint OdeJoint::
145convert_to_slider() const {
146 nassertr(_id != nullptr, OdeSliderJoint(nullptr));
147 nassertr(get_joint_type() == JT_slider, OdeSliderJoint(nullptr));
148 return OdeSliderJoint(_id);
149}
150
151OdeContactJoint OdeJoint::
152convert_to_contact() const {
153 nassertr(_id != nullptr, OdeContactJoint(nullptr));
154 nassertr(get_joint_type() == JT_contact, OdeContactJoint(nullptr));
155 return OdeContactJoint(_id);
156}
157
158OdeUniversalJoint OdeJoint::
159convert_to_universal() const {
160 nassertr(_id != nullptr, OdeUniversalJoint(nullptr));
161 nassertr(get_joint_type() == JT_universal, OdeUniversalJoint(nullptr));
162 return OdeUniversalJoint(_id);
163}
164
165OdeHinge2Joint OdeJoint::
166convert_to_hinge2() const {
167 nassertr(_id != nullptr, OdeHinge2Joint(nullptr));
168 nassertr(get_joint_type() == JT_hinge2, OdeHinge2Joint(nullptr));
169 return OdeHinge2Joint(_id);
170}
171
172OdeFixedJoint OdeJoint::
173convert_to_fixed() const {
174 nassertr(_id != nullptr, OdeFixedJoint(nullptr));
175 nassertr(get_joint_type() == JT_fixed, OdeFixedJoint(nullptr));
176 return OdeFixedJoint(_id);
177}
178
179OdeNullJoint OdeJoint::
180convert_to_null() const {
181 nassertr(_id != nullptr, OdeNullJoint(nullptr));
182 nassertr(get_joint_type() == JT_null, OdeNullJoint(nullptr));
183 return OdeNullJoint(_id);
184}
185
186OdeAMotorJoint OdeJoint::
187convert_to_a_motor() const {
188 nassertr(_id != nullptr, OdeAMotorJoint(nullptr));
189 nassertr(get_joint_type() == JT_a_motor, OdeAMotorJoint(nullptr));
190 return OdeAMotorJoint(_id);
191}
192
193OdeLMotorJoint OdeJoint::
194convert_to_l_motor() const {
195 nassertr(_id != nullptr, OdeLMotorJoint(nullptr));
196 nassertr(get_joint_type() == JT_l_motor, OdeLMotorJoint(nullptr));
197 return OdeLMotorJoint(_id);
198}
199
200OdePlane2dJoint OdeJoint::
201convert_to_plane2d() const {
202 nassertr(_id != nullptr, OdePlane2dJoint(nullptr));
203 nassertr(get_joint_type() == JT_plane2d, OdePlane2dJoint(nullptr));
204 return OdePlane2dJoint(_id);
205}
dBodyID get_id() const
Returns the underlying dBodyID.
Definition odeBody.I:28
void attach_body(const OdeBody &body, int index)
Attaches a single OdeBody to this joint at the specified index (0 or 1).
Definition odeJoint.cxx:77
void attach_bodies(const OdeBody &body1, const OdeBody &body2)
Attaches two OdeBody objects to this joint.
Definition odeJoint.cxx:65
TypeHandle is the identifier used to differentiate C++ class types.
Definition typeHandle.h:81
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
std::ostream & indent(std::ostream &out, int indent_level)
A handy function for doing text formatting.
Definition indent.cxx:20
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.