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 #ifndef OPAL_RAYCAST_SENSOR_H 00029 #define OPAL_RAYCAST_SENSOR_H 00030 00031 // project headers 00032 #include "Defines.h" 00033 #include "Sensor.h" 00034 #include "RaycastSensorData.h" 00035 00036 namespace opal 00037 { 00038 class Simulator; 00039 00042 struct RaycastResult 00043 { 00044 OPAL_DECL RaycastResult() 00045 { 00046 solid = NULL; 00047 // "intersection" is initialized in its own constructor. 00048 // "normal" is initialized in its own constructor. 00049 distance = 0; 00050 } 00051 00053 OPAL_DECL RaycastResult( const RaycastResult& result ) 00054 { 00055 ( *this ) = result; 00056 } 00057 00058 OPAL_DECL ~RaycastResult() 00059 {} 00060 00062 OPAL_DECL void OPAL_CALL operator=( 00063 const RaycastResult& result ) 00064 { 00065 solid = result.solid; 00066 intersection = result.intersection; 00067 normal = result.normal; 00068 distance = result.distance; 00069 } 00070 00073 Solid* solid; 00074 00076 Point3r intersection; 00077 00079 Vec3r normal; 00080 00083 real distance; 00084 }; 00085 00087 bool operator<( const RaycastResult & l, const RaycastResult & r ); 00088 00093 class RaycastSensor : public Sensor 00094 { 00095 public: 00097 RaycastSensor( Simulator* s ); 00098 00100 virtual ~RaycastSensor(); 00101 00106 virtual void OPAL_CALL init( const RaycastSensorData & data ); 00107 00109 virtual const RaycastSensorData & OPAL_CALL getData() const; 00110 00114 virtual const RaycastResult & OPAL_CALL fireRay(); 00115 00117 00122 virtual const std::vector<RaycastResult> & OPAL_CALL firePiercingRay(); 00123 00125 00130 virtual const RaycastResult& OPAL_CALL fireRay( real length ); 00131 00133 00138 virtual const std::vector<RaycastResult> & OPAL_CALL firePiercingRay( real length ); 00139 00140 virtual void OPAL_CALL setEnabled( bool e ); 00141 00142 virtual bool OPAL_CALL isEnabled() const; 00143 00145 virtual void OPAL_CALL setRay( const Rayr& r ); 00146 00148 virtual const Rayr& OPAL_CALL getRay() const; 00149 00150 virtual void OPAL_CALL setTransform( const Matrix44r& t ); 00151 00152 virtual const Matrix44r& OPAL_CALL getTransform() const; 00153 00154 virtual SensorType OPAL_CALL getType() const; 00155 00156 virtual void OPAL_CALL setName( const std::string& name ); 00157 00158 virtual const std::string& OPAL_CALL getName() const; 00159 00160 virtual void OPAL_CALL internal_update(); 00161 00162 virtual bool OPAL_CALL internal_dependsOnSolid( Solid* s ); 00163 00164 protected: 00166 RaycastSensorData mData; 00167 00170 Simulator* mSim; 00171 00172 private: 00173 }; 00174 } 00175 00176 #endif