[Opal-commits] opal/src VolumeSensor.cpp,NONE,1.1 VolumeSensor.h,NONE,1.1 VolumeSensorData.h,NONE,1.
Status: Inactive
Brought to you by:
tylerstreeter
|
From: tylerstreeter <tyl...@us...> - 2005-03-12 01:21:30
|
Update of /cvsroot/opal/opal/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17179/src Modified Files: RaycastSensor.cpp RaycastSensor.h SConscript SensorData.h Simulator.cpp Simulator.h opal.h Added Files: VolumeSensor.cpp VolumeSensor.h VolumeSensorData.h Log Message: added VolumeSensor Index: opal.h =================================================================== RCS file: /cvsroot/opal/opal/src/opal.h,v retrieving revision 1.21 retrieving revision 1.22 diff -C2 -d -r1.21 -r1.22 *** opal.h 9 Mar 2005 02:09:50 -0000 1.21 --- opal.h 12 Mar 2005 01:21:17 -0000 1.22 *************** *** 56,59 **** --- 56,61 ---- #include "RaycastSensor.h" #include "RaycastSensorData.h" + #include "VolumeSensor.h" + #include "VolumeSensorData.h" #include "EventHandler.h" #include "JointBreakEventHandler.h" Index: RaycastSensor.cpp =================================================================== RCS file: /cvsroot/opal/opal/src/RaycastSensor.cpp,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** RaycastSensor.cpp 11 Mar 2005 05:31:56 -0000 1.3 --- RaycastSensor.cpp 12 Mar 2005 01:21:16 -0000 1.4 *************** *** 43,47 **** void RaycastSensor::init(const RaycastSensorData& data) { - assert(data.solid); Sensor::init(); mData = data; --- 43,46 ---- *************** *** 55,63 **** const RaycastResult& RaycastSensor::fireRay() { ! return mSim->internal_fireRay(mData.ray, mData.ray.getLength()); } const RaycastResult& RaycastSensor::fireRay(real length) { return mSim->internal_fireRay(mData.ray, length); } --- 54,68 ---- const RaycastResult& RaycastSensor::fireRay() { ! return fireRay(mData.ray.getLength()); } const RaycastResult& RaycastSensor::fireRay(real length) { + // TODO: if mData.solid is valid, update this Sensor's ray + // relative to the Solid + + // TODO: if this is attached to a Solid, keep the ray from + // colliding with that Solid. + return mSim->internal_fireRay(mData.ray, length); } *************** *** 117,122 **** if (mData.enabled) { ! // TODO: if mData.solid is valid, update this Sensor's ray ! // relative to the Solid } } --- 122,126 ---- if (mData.enabled) { ! // Do nothing. } } Index: SensorData.h =================================================================== RCS file: /cvsroot/opal/opal/src/SensorData.h,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** SensorData.h 11 Mar 2005 05:31:56 -0000 1.5 --- SensorData.h 12 Mar 2005 01:21:16 -0000 1.6 *************** *** 36,42 **** enum SensorType { ! VELOCITY_SENSOR, ! ACCELERATION_SENSOR, ! RAYCAST_SENSOR }; --- 36,43 ---- enum SensorType { ! ACCELERATION_SENSOR, ! RAYCAST_SENSOR, ! VELOCITY_SENSOR, ! VOLUME_SENSOR }; *************** *** 49,53 **** // The initial type doesn't matter since the abstract base // class will never be instantiated. ! mType = VELOCITY_SENSOR; enabled = defaults::sensor::enabled; name = ""; --- 50,54 ---- // The initial type doesn't matter since the abstract base // class will never be instantiated. ! mType = ACCELERATION_SENSOR; enabled = defaults::sensor::enabled; name = ""; --- NEW FILE: VolumeSensor.cpp --- /************************************************************************* * * * Open Physics Abstraction Layer * * Copyright (C) 2004-2005 * * Alan Fischer ala...@gm... * * Andres Reinot an...@re... * * Tyler Streeter tyl...@gm... * * All rights reserved. * * Web: opal.sourceforge.net * * * * This library is free software; you can redistribute it and/or * * modify it under the terms of EITHER: * * (1) The GNU Lesser General Public License as published by the Free * * Software Foundation; either version 2.1 of the License, or (at * * your option) any later version. The text of the GNU Lesser * * General Public License is included with this library in the * * file license-LGPL.txt. * * (2) The BSD-style license that is included with this library in * * the file license-BSD.txt. * * * * This library is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the files * * license-LGPL.txt and license-BSD.txt for more details. * * * *************************************************************************/ #include "VolumeSensor.h" #include "Simulator.h" namespace opal { VolumeSensor::VolumeSensor(Simulator* s) { // "mData" is initialized in its own constructor. mSim = s; } VolumeSensor::~VolumeSensor() { } void VolumeSensor::init(const VolumeSensorData& data) { Sensor::init(); mData = data; } const VolumeSensorData& VolumeSensor::getData()const { return mData; } const VolumeQueryResult& VolumeSensor::queryVolume(const Solid* volume) { // TODO: if mData.solid is valid, update this Sensor's transform // relative to the Solid // TODO: if this is attached to a Solid, don't add the volume Solid // to the results. return mSim->internal_queryVolume(volume); } void VolumeSensor::setEnabled(bool e) { if (!mInitCalled) { return; } mData.enabled = e; } bool VolumeSensor::isEnabled()const { return mData.enabled; } SensorType VolumeSensor::getType()const { return mData.getType(); } void VolumeSensor::setTransform(const Matrix44r& t) { mData.transform = t; } const Matrix44r& VolumeSensor::getTransform()const { return mData.transform; } void VolumeSensor::setName(const std::string& name) { mData.name = name; } const std::string& VolumeSensor::getName()const { return mData.name; } void VolumeSensor::internal_update() { if (mData.enabled) { // Do nothing. } } bool VolumeSensor::internal_dependsOn(Solid* solid) { if (solid == mData.solid) { return true; } else { return false; } } } Index: RaycastSensor.h =================================================================== RCS file: /cvsroot/opal/opal/src/RaycastSensor.h,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** RaycastSensor.h 11 Mar 2005 05:31:56 -0000 1.3 --- RaycastSensor.h 12 Mar 2005 01:21:16 -0000 1.4 *************** *** 41,45 **** struct RaycastResult { ! RaycastResult() { solid = NULL; --- 41,45 ---- struct RaycastResult { ! OPAL_DECL RaycastResult() { solid = NULL; *************** *** 49,52 **** --- 49,72 ---- } + /// Copy constructor. + OPAL_DECL RaycastResult(const RaycastResult& result) + { + (*this) = result; + } + + OPAL_DECL ~RaycastResult() + { + } + + /// Makes a deep copy. + OPAL_DECL void OPAL_CALL operator=( + const RaycastResult& result) + { + solid = result.solid; + intersection = result.intersection; + normal = result.normal; + distance = result.distance; + } + /// The first Solid hit by the ray. This will remain NULL if no /// Solid is hit. *************** *** 75,80 **** virtual ~RaycastSensor(); ! /// Initializes the Sensor with the given data structure. Solid ! /// pointer in the data must be valid. virtual void OPAL_CALL init(const RaycastSensorData& data); --- 95,102 ---- virtual ~RaycastSensor(); ! /// Initializes the Sensor with the given data structure. If the ! /// Solid pointer in the data is valid, the Sensor's offset will ! /// be relative to the Solid's transform instead of the global ! /// origin. virtual void OPAL_CALL init(const RaycastSensorData& data); *************** *** 83,92 **** /// Fires a ray into the Sensor's environment, returning ! /// information about the first intersection encountered. virtual const RaycastResult& OPAL_CALL fireRay(); /// Fires a ray of a given length into the Sensor's environment ! /// information about the first intersection encountered. ! virtual const RaycastResult& OPAL_CALL fireRay( real length ); virtual void OPAL_CALL setEnabled(bool e); --- 105,117 ---- /// Fires a ray into the Sensor's environment, returning ! /// information about the first intersection encountered. The ! /// length of the ray used will be the length of the Sensor's ! /// ray data. virtual const RaycastResult& OPAL_CALL fireRay(); /// Fires a ray of a given length into the Sensor's environment ! /// information about the first intersection encountered. The ! /// length of the ray used will be the given length parameter. ! virtual const RaycastResult& OPAL_CALL fireRay(real length); virtual void OPAL_CALL setEnabled(bool e); --- NEW FILE: VolumeSensor.h --- /************************************************************************* * * * Open Physics Abstraction Layer * * Copyright (C) 2004-2005 * * Alan Fischer ala...@gm... * * Andres Reinot an...@re... * * Tyler Streeter tyl...@gm... * * All rights reserved. * * Web: opal.sourceforge.net * * * * This library is free software; you can redistribute it and/or * * modify it under the terms of EITHER: * * (1) The GNU Lesser General Public License as published by the Free * * Software Foundation; either version 2.1 of the License, or (at * * your option) any later version. The text of the GNU Lesser * * General Public License is included with this library in the * * file license-LGPL.txt. * * (2) The BSD-style license that is included with this library in * * the file license-BSD.txt. * * * * This library is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the files * * license-LGPL.txt and license-BSD.txt for more details. * * * *************************************************************************/ #ifndef OPAL_VOLUME_SENSOR_H #define OPAL_VOLUME_SENSOR_H #include "Defines.h" #include "Sensor.h" #include "VolumeSensorData.h" namespace opal { class Simulator; /// A data structure containing information about a specific /// volume query. struct VolumeQueryResult { OPAL_DECL VolumeQueryResult() { } /// Copy constructor. OPAL_DECL VolumeQueryResult(const VolumeQueryResult& result) { (*this) = result; } OPAL_DECL ~VolumeQueryResult() { internal_clearSolids(); } /// Makes a deep copy. OPAL_DECL void OPAL_CALL operator=( const VolumeQueryResult& result) { unsigned int i=0; for (i=0; i<result.mSolidList.size(); ++i) { mSolidList.push_back(result.mSolidList[i]); } } /// Adds a Solid pointer to the list of results. OPAL_DECL void OPAL_CALL internal_addSolid(Solid* s) { assert(s); mSolidList.push_back(s); } /// Returns the number of Solids in the results. OPAL_DECL int OPAL_CALL getNumSolids()const { return (int)(mSolidList.size()); } // This is probably not needed... //Solid* getSolid(unsigned int i)const //{ // return mSolidList.at(i); //} /// Removes all Solids from the results. OPAL_DECL void OPAL_CALL internal_clearSolids() { mSolidList.clear(); } /// Removes a specified Solid from the list of collided Solids. OPAL_DECL void OPAL_CALL internal_removeSolid(const Solid* s) { for(size_t i = 0; i<mSolidList.size(); ++i) { if(mSolidList[i] == s) { mSolidList[i] = mSolidList.back(); mSolidList.pop_back(); return; } } } private: /// A list of Solids that were found in a volume query. std::vector<Solid*> mSolidList; }; /// A Sensor that queries a scene to find which Solids are intersecting /// a specified volume. Each volume query returns a data structure /// containing a list of those Solids. This Sensor does not do a volume /// query on every time step because that would be a waste of time in /// most cases; it must be queried manually. class VolumeSensor : public Sensor { public: VolumeSensor(Simulator* s); virtual ~VolumeSensor(); /// Initializes the Sensor with the given data structure. virtual void OPAL_CALL init(const VolumeSensorData& data); /// Returns all data describing the Sensor. virtual const VolumeSensorData& OPAL_CALL getData()const; /// Queries the Sensor's environment with the given Solid's volume, /// returning a list of the Solids that collide with that Solid. virtual const VolumeQueryResult& OPAL_CALL queryVolume( const Solid* volume); virtual void OPAL_CALL setEnabled(bool e); virtual bool OPAL_CALL isEnabled()const; virtual void OPAL_CALL setTransform(const Matrix44r& t); virtual const Matrix44r& OPAL_CALL getTransform()const; virtual SensorType OPAL_CALL getType()const; virtual void OPAL_CALL setName(const std::string& name); virtual const std::string& OPAL_CALL getName()const; virtual void OPAL_CALL internal_update(); virtual bool OPAL_CALL internal_dependsOn(Solid* solid); protected: /// Stores data describing the Sensor. VolumeSensorData mData; /// Pointer to the Simulator containing this Sensor; used to fire /// rays into the Simulator. Simulator* mSim; private: }; } #endif Index: Simulator.cpp =================================================================== RCS file: /cvsroot/opal/opal/src/Simulator.cpp,v retrieving revision 1.44 retrieving revision 1.45 diff -C2 -d -r1.44 -r1.45 *** Simulator.cpp 9 Mar 2005 02:09:49 -0000 1.44 --- Simulator.cpp 12 Mar 2005 01:21:16 -0000 1.45 *************** *** 38,41 **** --- 38,42 ---- #include "SpringMotor.h" #include "RaycastSensor.h" + #include "VolumeSensor.h" namespace opal --- NEW FILE: VolumeSensorData.h --- /************************************************************************* * * * Open Physics Abstraction Layer * * Copyright (C) 2004-2005 * * Alan Fischer ala...@gm... * * Andres Reinot an...@re... * * Tyler Streeter tyl...@gm... * * All rights reserved. * * Web: opal.sourceforge.net * * * * This library is free software; you can redistribute it and/or * * modify it under the terms of EITHER: * * (1) The GNU Lesser General Public License as published by the Free * * Software Foundation; either version 2.1 of the License, or (at * * your option) any later version. The text of the GNU Lesser * * General Public License is included with this library in the * * file license-LGPL.txt. * * (2) The BSD-style license that is included with this library in * * the file license-BSD.txt. * * * * This library is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the files * * license-LGPL.txt and license-BSD.txt for more details. * * * *************************************************************************/ #ifndef OPAL_VOLUME_SENSOR_DATA_H #define OPAL_VOLUME_SENSOR_DATA_H #include "Defines.h" #include "SensorData.h" namespace opal { /// A data structure describing a VolumeSensor. class VolumeSensorData : public SensorData { public: OPAL_DECL VolumeSensorData() : SensorData() { mType = VOLUME_SENSOR; } /// Copy constructor. OPAL_DECL VolumeSensorData(const VolumeSensorData& data) { (*this) = data; } OPAL_DECL virtual ~VolumeSensorData() { } /// Makes a deep copy. OPAL_DECL virtual void OPAL_CALL operator=( const VolumeSensorData& data) { mType = data.mType; enabled = data.enabled; name = data.name; solid = data.solid; transform = data.transform; } protected: private: }; } #endif Index: SConscript =================================================================== RCS file: /cvsroot/opal/opal/src/SConscript,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** SConscript 9 Mar 2005 02:09:49 -0000 1.13 --- SConscript 12 Mar 2005 01:21:16 -0000 1.14 *************** *** 50,53 **** --- 50,55 ---- ThrusterMotorData.h Vec3r.h + VolumeSensor.h + VolumeSensorData.h """) *************** *** 71,74 **** --- 73,77 ---- SpringMotor.cpp ThrusterMotor.cpp + VolumeSensor.cpp """) Index: Simulator.h =================================================================== RCS file: /cvsroot/opal/opal/src/Simulator.h,v retrieving revision 1.84 retrieving revision 1.85 diff -C2 -d -r1.84 -r1.85 *** Simulator.h 11 Mar 2005 05:31:56 -0000 1.84 --- Simulator.h 12 Mar 2005 01:21:17 -0000 1.85 *************** *** 47,50 **** --- 47,51 ---- class BlueprintInstance; struct RaycastResult; + struct VolumeQueryResult; /// A Simulator is an environment that contains simulated objects. *************** *** 81,92 **** const Matrix44r& offset=Matrix44r(), real scale=1); - /// A convenient volume collision check function. TODO: replace - /// with a Sensor. TODO: the vector pointer here is bad because - /// memory is allocated within the DLL and deallocated on the - /// user's side; make a VolumeCollisionReport object with an - /// add function - //virtual void OPAL_CALL collide(const Solid* solid, - // std::vector<Solid*>* solids) = 0; - /// Sets the gravity used in the simulation. virtual void OPAL_CALL setGravity(const Vec3r& gravity) = 0; --- 82,85 ---- *************** *** 230,233 **** --- 223,230 ---- const Rayr& r, real length) = 0; + /// Helper function used for volume queries. + virtual const VolumeQueryResult& OPAL_CALL internal_queryVolume( + const Solid* volume) = 0; + /// Returns the Simulator's contact group flags. virtual unsigned long int OPAL_CALL |