00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include "config_ode.h"
00016 #include "odeJoint.h"
00017
00018 TypeHandle OdeJoint::_type_handle;
00019
00020 OdeJoint::
00021 OdeJoint() :
00022 _id(0) {
00023 ostream &out = odejoint_cat.debug();
00024 out << get_type() << "(" << _id << ")\n";
00025 }
00026
00027 OdeJoint::
00028 OdeJoint(dJointID id) :
00029 _id(id) {
00030 ostream &out = odejoint_cat.debug();
00031 out << get_type() << "(" << _id << ")\n";
00032 }
00033
00034 OdeJoint::
00035 ~OdeJoint() {
00036 }
00037
00038 void OdeJoint::
00039 destroy() {
00040 nassertv(_id);
00041 dJointDestroy(_id);
00042 }
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052 void OdeJoint::
00053 attach_bodies(const OdeBody &body1, const OdeBody &body2) {
00054 nassertv(_id);
00055 nassertv(body1.get_id() != 0 && body2.get_id() != 0);
00056 dJointAttach(_id, body1.get_id(), body2.get_id());
00057 }
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068 void OdeJoint::
00069 attach_body(const OdeBody &body, int index) {
00070 nassertv(_id);
00071 nassertv(body.get_id() != 0);
00072 nassertv(index == 0 || index == 1);
00073 if (index == 0) {
00074 dJointAttach(_id, body.get_id(), 0);
00075 } else {
00076 dJointAttach(_id, 0, body.get_id());
00077 }
00078 }
00079
00080 void OdeJoint::
00081 detach() {
00082 nassertv(_id);
00083 dJointAttach(_id, 0, 0);
00084 }
00085
00086 OdeBody OdeJoint::
00087 get_body(int index) const {
00088 nassertr(_id, OdeBody(0));
00089 nassertr(index == 0 || index == 1, OdeBody(0));
00090 return OdeBody(dJointGetBody(_id, index));
00091 }
00092
00093 void OdeJoint::
00094 write(ostream &out, unsigned int indent) const {
00095 out.width(indent); out << "" << get_type() \
00096 << "(id = " << _id \
00097 << ", body1 = ";
00098 OdeBody body = get_body(0);
00099 if (body.get_id() != 0) {
00100 body.write(out);
00101 }
00102 else {
00103 out << "0";
00104 }
00105 out << ", body2 = ";
00106 body = get_body(1);
00107 if (body.get_id() != 0) {
00108 body.write(out);
00109 }
00110 else {
00111 out << "0";
00112 }
00113 out << ")";
00114
00115 }
00116
00117 OdeJoint::
00118 operator bool () const {
00119 return (_id != NULL);
00120 }
00121
00122 OdeBallJoint OdeJoint::
00123 convert_to_ball() const {
00124 nassertr(_id != 0, OdeBallJoint(0));
00125 nassertr(get_joint_type() == JT_ball, OdeBallJoint(0));
00126 return OdeBallJoint(_id);
00127 }
00128
00129 OdeHingeJoint OdeJoint::
00130 convert_to_hinge() const {
00131 nassertr(_id != 0, OdeHingeJoint(0));
00132 nassertr(get_joint_type() == JT_hinge, OdeHingeJoint(0));
00133 return OdeHingeJoint(_id);
00134 }
00135
00136 OdeSliderJoint OdeJoint::
00137 convert_to_slider() const {
00138 nassertr(_id != 0, OdeSliderJoint(0));
00139 nassertr(get_joint_type() == JT_slider, OdeSliderJoint(0));
00140 return OdeSliderJoint(_id);
00141 }
00142
00143 OdeContactJoint OdeJoint::
00144 convert_to_contact() const {
00145 nassertr(_id != 0, OdeContactJoint(0));
00146 nassertr(get_joint_type() == JT_contact, OdeContactJoint(0));
00147 return OdeContactJoint(_id);
00148 }
00149
00150 OdeUniversalJoint OdeJoint::
00151 convert_to_universal() const {
00152 nassertr(_id != 0, OdeUniversalJoint(0));
00153 nassertr(get_joint_type() == JT_universal, OdeUniversalJoint(0));
00154 return OdeUniversalJoint(_id);
00155 }
00156
00157 OdeHinge2Joint OdeJoint::
00158 convert_to_hinge2() const {
00159 nassertr(_id != 0, OdeHinge2Joint(0));
00160 nassertr(get_joint_type() == JT_hinge2, OdeHinge2Joint(0));
00161 return OdeHinge2Joint(_id);
00162 }
00163
00164 OdeFixedJoint OdeJoint::
00165 convert_to_fixed() const {
00166 nassertr(_id != 0, OdeFixedJoint(0));
00167 nassertr(get_joint_type() == JT_fixed, OdeFixedJoint(0));
00168 return OdeFixedJoint(_id);
00169 }
00170
00171 OdeNullJoint OdeJoint::
00172 convert_to_null() const {
00173 nassertr(_id != 0, OdeNullJoint(0));
00174 nassertr(get_joint_type() == JT_null, OdeNullJoint(0));
00175 return OdeNullJoint(_id);
00176 }
00177
00178 OdeAMotorJoint OdeJoint::
00179 convert_to_a_motor() const {
00180 nassertr(_id != 0, OdeAMotorJoint(0));
00181 nassertr(get_joint_type() == JT_a_motor, OdeAMotorJoint(0));
00182 return OdeAMotorJoint(_id);
00183 }
00184
00185 OdeLMotorJoint OdeJoint::
00186 convert_to_l_motor() const {
00187 nassertr(_id != 0, OdeLMotorJoint(0));
00188 nassertr(get_joint_type() == JT_l_motor, OdeLMotorJoint(0));
00189 return OdeLMotorJoint(_id);
00190 }
00191
00192 OdePlane2dJoint OdeJoint::
00193 convert_to_plane2d() const {
00194 nassertr(_id != 0, OdePlane2dJoint(0));
00195 nassertr(get_joint_type() == JT_plane2d, OdePlane2dJoint(0));
00196 return OdePlane2dJoint(_id);
00197 }
00198