AccelerationSensor.cpp

Go to the documentation of this file.
00001 /*************************************************************************
00002  *                                                                       *
00003  * Open Physics Abstraction Layer                                        *
00004  * Copyright (C) 2004-2005                                               *
00005  * Alan Fischer  alan.fischer@gmail.com                                  *
00006  * Andres Reinot  andres@reinot.com                                      *
00007  * Tyler Streeter  tylerstreeter@gmail.com                               *
00008  * All rights reserved.                                                  *
00009  * Web: opal.sourceforge.net                                             *
00010  *                                                                       *
00011  * This library is free software; you can redistribute it and/or         *
00012  * modify it under the terms of EITHER:                                  *
00013  *   (1) The GNU Lesser General Public License as published by the Free  *
00014  *       Software Foundation; either version 2.1 of the License, or (at  *
00015  *       your option) any later version. The text of the GNU Lesser      *
00016  *       General Public License is included with this library in the     *
00017  *       file license-LGPL.txt.                                          *
00018  *   (2) The BSD-style license that is included with this library in     *
00019  *       the file license-BSD.txt.                                       *
00020  *                                                                       *
00021  * This library is distributed in the hope that it will be useful,       *
00022  * but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00023  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the files    *
00024  * license-LGPL.txt and license-BSD.txt for more details.                *
00025  *                                                                       *
00026  *************************************************************************/
00027 
00028 #include "AccelerationSensor.h"
00029 #include "Simulator.h"
00030 
00031 namespace opal
00032 {
00033         AccelerationSensor::AccelerationSensor(Simulator* s)
00034         {
00035                 // "mData" is initialized in its own constructor.
00036                 mSim = s;
00037 
00038                 // "mCurrentGlobalLinearVel" is initialized in its own constructor.
00039                 // "mCurrentGlobalAngularVel" is initialized in its own constructor.
00040                 // "mCurrentLocalLinearVel" is initialized in its own constructor.
00041                 // "mCurrentLocalAngularVel" is initialized in its own constructor.
00042 
00043                 // "mPrevGlobalLinearVel" is initialized in its own constructor.
00044                 // "mPrevGlobalAngularVel" is initialized in its own constructor.
00045                 // "mPrevLocalLinearVel" is initialized in its own constructor.
00046                 // "mPrevLocalAngularVel" is initialized in its own constructor.
00047         }
00048 
00049         AccelerationSensor::~AccelerationSensor()
00050         {
00051         }
00052 
00053         void AccelerationSensor::init(const AccelerationSensorData& data)
00054         {
00055                 Sensor::init();
00056                 mData = data;
00057         }
00058 
00059         const AccelerationSensorData& AccelerationSensor::getData()const
00060         {
00061                 return mData;
00062         }
00063 
00064         Vec3r AccelerationSensor::getGlobalLinearAccel()const
00065         {
00066                 if (!mData.enabled || !mData.solid)
00067                 {
00068                         return Vec3r();
00069                 }
00070 
00071                 return (mCurrentGlobalLinearVel - mPrevGlobalLinearVel) / 
00072                         mSim->getStepSize();
00073         }
00074 
00075         Vec3r AccelerationSensor::getGlobalAngularAccel()const
00076         {
00077                 if (!mData.enabled || !mData.solid)
00078                 {
00079                         return Vec3r();
00080                 }
00081 
00082                 return (mCurrentGlobalAngularVel - mPrevGlobalAngularVel) / 
00083                         mSim->getStepSize();
00084         }
00085 
00086         Vec3r AccelerationSensor::getLocalLinearAccel()const
00087         {
00088                 if (!mData.enabled || !mData.solid)
00089                 {
00090                         return Vec3r();
00091                 }
00092 
00093                 return (mCurrentLocalLinearVel - mPrevLocalLinearVel) / 
00094                         mSim->getStepSize();
00095         }
00096 
00097         Vec3r AccelerationSensor::getLocalAngularAccel()const
00098         {
00099                 if (!mData.enabled || !mData.solid)
00100                 {
00101                         return Vec3r();
00102                 }
00103 
00104                 return (mCurrentLocalAngularVel - mPrevLocalAngularVel) / 
00105                         mSim->getStepSize();
00106         }
00107 
00108         void AccelerationSensor::setEnabled(bool e)
00109         {
00110                 //if (!mInitCalled)
00111                 //{
00112                 //      return;
00113                 //}
00114 
00115                 mData.enabled = e;
00116         }
00117 
00118         bool AccelerationSensor::isEnabled()const
00119         {
00120                 return mData.enabled;
00121         }
00122 
00123         SensorType AccelerationSensor::getType()const
00124         {
00125                 return mData.getType();
00126         }
00127 
00128         void AccelerationSensor::setTransform(const Matrix44r& t)
00129         {
00130                 mData.transform = t;
00131         }
00132 
00133         const Matrix44r& AccelerationSensor::getTransform()const
00134         {
00135                 return mData.transform;
00136         }
00137 
00138         void AccelerationSensor::setName(const std::string& name)
00139         {
00140                 mData.name = name;
00141         }
00142 
00143         const std::string& AccelerationSensor::getName()const
00144         {
00145                 return mData.name;
00146         }
00147 
00148         void AccelerationSensor::internal_update()
00149         {
00150                 if (mData.enabled && mData.solid)
00151                 {
00152                         mPrevGlobalLinearVel = mCurrentGlobalLinearVel;
00153                         mPrevGlobalAngularVel = mCurrentGlobalAngularVel;
00154                         mPrevLocalLinearVel = mCurrentLocalLinearVel;
00155                         mPrevLocalAngularVel = mCurrentLocalAngularVel;
00156 
00157                         mCurrentGlobalLinearVel = 
00158                                 mData.solid->getGlobalLinearVel();
00159                         mCurrentGlobalAngularVel = 
00160                                 mData.solid->getGlobalAngularVel();
00161                         mCurrentLocalLinearVel = 
00162                                 mData.solid->getLocalLinearVel();
00163                         mCurrentLocalAngularVel = 
00164                                 mData.solid->getLocalAngularVel();
00165                 }
00166         }
00167 
00168         bool AccelerationSensor::internal_dependsOnSolid(Solid* s)
00169         {
00170                 if (s == mData.solid)
00171                 {
00172                         return true;
00173                 }
00174                 else
00175                 {
00176                         return false;
00177                 }
00178         }
00179 }

Generated on Tue May 16 17:49:50 2006 for OPAL by  doxygen 1.4.6-NO