worldsim/src/phyjoint.cpp

00001 /********************************************************************************
00002  *  WorldSim -- library for robot simulations                                   *
00003  *  Copyright (C) 2008-2011 Gianluca Massera <emmegian@yahoo.it>                *
00004  *                                                                              *
00005  *  This program is free software; you can redistribute it and/or modify        *
00006  *  it under the terms of the GNU General Public License as published by        *
00007  *  the Free Software Foundation; either version 2 of the License, or           *
00008  *  (at your option) any later version.                                         *
00009  *                                                                              *
00010  *  This program is distributed in the hope that it will be useful,             *
00011  *  but WITHOUT ANY WARRANTY; without even the implied warranty of              *
00012  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               *
00013  *  GNU General Public License for more details.                                *
00014  *                                                                              *
00015  *  You should have received a copy of the GNU General Public License           *
00016  *  along with this program; if not, write to the Free Software                 *
00017  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA  *
00018  ********************************************************************************/
00019 
00020 #include "phyjoint.h"
00021 #include "private/phyjointprivate.h"
00022 #include "private/phyobjectprivate.h"
00023 #include "private/worldprivate.h"
00024 
00025 #ifdef FARSA_DEBUG
00026     #include <QDebug>
00027 #endif
00028 
00029 namespace farsa {
00030 PhyJoint::PhyJoint( PhyObject* parent, PhyObject* child ) :
00031     dofsv(),
00032     dofv(0)
00033 {
00034     priv = new PhyJointPrivate();
00035     this->parentv = parent;
00036     if ( parentv == 0 ) {
00037         parentpriv = 0;
00038         priv->parent = 0;
00039     } else {
00040         parentpriv = parentv->priv;
00041         priv->parent = parentpriv->body;
00042     }
00043     this->childv = child;
00044     childpriv = child->priv;
00045     priv->child = childpriv->body;
00046     this->worldv = childv->world();
00047     worldpriv = worldv->priv;
00048     enabled = true;
00049     worldv->pushJoint( this );
00050 }
00051 
00052 PhyJoint::~PhyJoint() {
00053     worldv->popJoint( this );
00054 #ifdef WORLDSIM_USE_NEWTON
00055     NewtonDestroyJoint( worldpriv->world, priv->joint);
00056 #endif
00057     delete priv;
00058     foreach( PhyDOF* dof, dofsv ) {
00059         delete dof;
00060     }
00061 }
00062 
00063 void PhyJoint::enable( bool b ) {
00064 //  if ( enabled == b ) return;
00065     enabled = b;
00066 // #ifdef WORLDSIM_USE_NEWTON
00067 // What do these callbacks do?!?!?!?!?!?
00068 //  if ( b ) {
00069 //      NewtonUserJointSetFeedbackCollectorCallback( priv->joint, PhyJointPrivate::userBilateralHandler );
00070 //  } else {
00071 //      NewtonUserJointSetFeedbackCollectorCallback( priv->joint, 0 );
00072 //  }
00073 // #endif
00074 }
00075 
00076 } // end namespace farsa