VolumeSensor.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 "VolumeSensor.h"
00029 #include "Simulator.h"
00030 
00031 namespace opal
00032 {
00033         VolumeSensor::VolumeSensor(Simulator* s)
00034         {
00035                 // "mData" is initialized in its own constructor.
00036                 mSim = s;
00037         }
00038 
00039         VolumeSensor::~VolumeSensor()
00040         {
00041         }
00042 
00043         void VolumeSensor::init(const VolumeSensorData& data)
00044         {
00045                 Sensor::init();
00046                 mData = data;
00047         }
00048 
00049         const VolumeSensorData& VolumeSensor::getData()const
00050         {
00051                 return mData;
00052         }
00053 
00054         const VolumeQueryResult& VolumeSensor::queryVolume(Solid* volume)
00055         {
00056                 if (mData.enabled)
00057                 {
00058                         // The volume Solid's transform will be totally ignored.
00059 
00060                         // Store the volume Solid's transform.
00061                         Matrix44r originalVolumeTransform = volume->getTransform();
00062 
00063                         // If the Sensor is attached to a Solid, we need to transform 
00064                         // the volume relative to the Solid's transform and the 
00065                         // Sensor's transform.
00066                         if (mData.solid)
00067                         {
00068                                 volume->setTransform(mData.solid->getTransform() * 
00069                                         mData.transform);
00070                         }
00071                         else
00072                         {
00073                                 // If the Sensor is not attached to a Solid, just use the 
00074                                 // Sensor's transform as a global transform on the volume.
00075                                 volume->setTransform(mData.transform);
00076                         }
00077 
00078                         // If this is attached to a Solid, the Simulator volume query 
00079                         // function will automatically ignore intersections between the 
00080                         // volume and that Solid.
00081 
00082                         // Query the volume for colliding Solids.
00083                         const VolumeQueryResult& result = 
00084                                 mSim->internal_queryVolume(volume, mData.solid);
00085 
00086                         // Restore the volume Solid's original transform.
00087                         volume->setTransform(originalVolumeTransform);
00088 
00089                         return result;
00090                 }
00091                 else
00092                 {
00093                         static VolumeQueryResult junkResult;
00094                         return junkResult;
00095                 }
00096         }
00097 
00098         void VolumeSensor::setEnabled(bool e)
00099         {
00100                 //if (!mInitCalled)
00101                 //{
00102                 //      return;
00103                 //}
00104 
00105                 mData.enabled = e;
00106         }
00107 
00108         bool VolumeSensor::isEnabled()const
00109         {
00110                 return mData.enabled;
00111         }
00112 
00113         SensorType VolumeSensor::getType()const
00114         {
00115                 return mData.getType();
00116         }
00117 
00118         void VolumeSensor::setTransform(const Matrix44r& t)
00119         {
00120                 mData.transform = t;
00121         }
00122 
00123         const Matrix44r& VolumeSensor::getTransform()const
00124         {
00125                 return mData.transform;
00126         }
00127 
00128         void VolumeSensor::setName(const std::string& name)
00129         {
00130                 mData.name = name;
00131         }
00132 
00133         const std::string& VolumeSensor::getName()const
00134         {
00135                 return mData.name;
00136         }
00137 
00138         void VolumeSensor::internal_update()
00139         {
00140                 if (mData.enabled && mData.solid)
00141                 {
00142                         // Do nothing.
00143                 }
00144         }
00145 
00146         bool VolumeSensor::internal_dependsOnSolid(Solid* s)
00147         {
00148                 if (s == mData.solid)
00149                 {
00150                         return true;
00151                 }
00152                 else
00153                 {
00154                         return false;
00155                 }
00156         }
00157 }

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