worldsim/src/physphere.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 "physphere.h"
00021 #include "private/phyobjectprivate.h"
00022 #include "private/worldprivate.h"
00023 
00024 namespace farsa {
00025 
00026 PhySphere::PhySphere( real radius, World* w, QString name, const wMatrix& tm )
00027     : PhyObject( w, name, tm, false ) {
00028     radiusv = radius;
00029     w->pushObject( this );
00030     createPrivateObject();
00031     changedMatrix();
00032 }
00033 
00034 PhySphere::~PhySphere() {
00035 #ifdef WORLDSIM_USE_NEWTON
00036     /* nothing to do */
00037 #endif
00038 }
00039 
00040 void PhySphere::createPrivateObject() {
00041 #ifdef WORLDSIM_USE_NEWTON
00042     NewtonCollision* c = NewtonCreateSphere( worldpriv->world, radiusv, radiusv, radiusv, 1, 0 );
00043     wMatrix initialTransformationMatrix = wMatrix::identity(); // The transformation matrix is set in other places
00044     priv->body = NewtonCreateBody( worldpriv->world, c, &initialTransformationMatrix[0][0] );
00045     priv->collision = NewtonBodyGetCollision( priv->body );
00046     //NewtonReleaseCollision( worldpriv->world, c );
00047     NewtonBodySetAutoSleep( priv->body, 0 );
00048     setMass( 1 );
00049     NewtonBodySetUserData( priv->body, this );
00050     NewtonBodySetLinearDamping( priv->body, 0.0 );
00051     wVector zero = wVector(0,0,0,0);
00052     NewtonBodySetAngularDamping( priv->body, &zero[0] );
00053     NewtonBodySetAutoSleep( priv->body, 0 );
00054     NewtonBodySetFreezeState( priv->body, 0 );
00055     // Sets the signal-wrappers callback
00056     NewtonBodySetTransformCallback( priv->body, (PhyObjectPrivate::setTransformHandler) );
00057     NewtonBodySetForceAndTorqueCallback( priv->body, (PhyObjectPrivate::applyForceAndTorqueHandler) );
00058 #endif
00059 }
00060 
00061 } // end namespace farsa