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