[Opal-commits] opal/src AccelerationSensor.cpp,1.2,1.3 AccelerationSensor.h,1.2,1.3 Blueprint.cpp,1.
Status: Inactive
Brought to you by:
tylerstreeter
|
From: tylerstreeter <tyl...@us...> - 2005-03-23 07:54:43
|
Update of /cvsroot/opal/opal/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29501/src Modified Files: AccelerationSensor.cpp AccelerationSensor.h Blueprint.cpp BlueprintManager.cpp BlueprintManager.h SConscript SensorData.h Simulator.cpp Simulator.h Solid.cpp Solid.h opal.h Removed Files: VelocitySensor.cpp VelocitySensor.h VelocitySensorData.h Log Message: finished AccelerationSensor; remove VelocitySensor because the existing Solid velocity functions render it useless Index: Blueprint.cpp =================================================================== RCS file: /cvsroot/opal/opal/src/Blueprint.cpp,v retrieving revision 1.18 retrieving revision 1.19 diff -C2 -d -r1.18 -r1.19 *** Blueprint.cpp 13 Mar 2005 23:07:09 -0000 1.18 --- Blueprint.cpp 23 Mar 2005 07:54:33 -0000 1.19 *************** *** 36,39 **** --- 36,40 ---- #include "ThrusterMotorData.h" #include "SensorData.h" + #include "AccelerationSensorData.h" #include "RaycastSensorData.h" #include "VolumeSensorData.h" *************** *** 348,358 **** switch(data->getType()) { ! //case ACCELERATION_SENSOR: ! //{ ! // newData = ! // new AccelerationSensorData( ! // *((AccelerationSensorData*)data)); ! // break; ! //} case RAYCAST_SENSOR: { --- 349,359 ---- switch(data->getType()) { ! case ACCELERATION_SENSOR: ! { ! newData = ! new AccelerationSensorData( ! *((AccelerationSensorData*)data)); ! break; ! } case RAYCAST_SENSOR: { *************** *** 361,369 **** break; } - //case VELOCITY_SENSOR: - //{ - // newData = - // new VelocitySensorData(*((VelocitySensorData*)data)); - //} case VOLUME_SENSOR: { --- 362,365 ---- Index: AccelerationSensor.h =================================================================== RCS file: /cvsroot/opal/opal/src/AccelerationSensor.h,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** AccelerationSensor.h 23 Mar 2005 04:04:30 -0000 1.2 --- AccelerationSensor.h 23 Mar 2005 07:54:33 -0000 1.3 *************** *** 35,38 **** --- 35,40 ---- namespace opal { + class Simulator; + /// A Sensor that monitors the linear and angular acceleration of a /// Solid. Using its transform, it can be set to a desired offset from *************** *** 42,46 **** { public: ! AccelerationSensor(); virtual ~AccelerationSensor(); --- 44,48 ---- { public: ! AccelerationSensor(Simulator* s); virtual ~AccelerationSensor(); *************** *** 55,69 **** virtual const AccelerationSensorData& OPAL_CALL getData()const; ! /// Returns the Sensor's global linear acceleration. ! virtual real OPAL_CALL getGlobalLinearAccel()const; ! /// Returns the Sensor's global angular acceleration. ! virtual real OPAL_CALL getGlobalAngularAccel()const; ! /// Returns the Sensor's local linear acceleration. ! virtual real OPAL_CALL getLocalLinearAccel()const; ! /// Returns the Sensor's local angular acceleration. ! virtual real OPAL_CALL getLocalAngularAccel()const; virtual void OPAL_CALL setEnabled(bool e); --- 57,75 ---- virtual const AccelerationSensorData& OPAL_CALL getData()const; ! /// Returns the Sensor's global linear acceleration. If the Sensor ! /// is not attached to a Solid, this returns (0, 0, 0). ! virtual Vec3r OPAL_CALL getGlobalLinearAccel()const; ! /// Returns the Sensor's global angular acceleration. If the Sensor ! /// is not attached to a Solid, this returns (0, 0, 0). ! virtual Vec3r OPAL_CALL getGlobalAngularAccel()const; ! /// Returns the Sensor's local linear acceleration. If the Sensor ! /// is not attached to a Solid, this returns (0, 0, 0). ! virtual Vec3r OPAL_CALL getLocalLinearAccel()const; ! /// Returns the Sensor's local angular acceleration. If the Sensor ! /// is not attached to a Solid, this returns (0, 0, 0). ! virtual Vec3r OPAL_CALL getLocalAngularAccel()const; virtual void OPAL_CALL setEnabled(bool e); *************** *** 89,92 **** --- 95,130 ---- AccelerationSensorData mData; + /// Pointer to the Simulator containing this Sensor. This is used + /// to get an accurate dt value on every update. + Simulator* mSim; + + /// Stored copy of the current global linear acceleration. + Vec3r mGlobalLinearAccel; + + /// Stored copy of the current global angular acceleration. + Vec3r mGlobalAngularAccel; + + /// Stored copy of the current local linear acceleration. + Vec3r mLocalLinearAccel; + + /// Stored copy of the current local angular acceleration. + Vec3r mLocalAngularAccel; + + /// Stored copy of the previous step's velocity data; used for + /// acceleration calculations. + Vec3r mPrevGlobalLinearVel; + + /// Stored copy of the previous step's velocity data; used for + /// acceleration calculations. + Vec3r mPrevGlobalAngularVel; + + /// Stored copy of the previous step's velocity data; used for + /// acceleration calculations. + Vec3r mPrevLocalLinearVel; + + /// Stored copy of the previous step's velocity data; used for + /// acceleration calculations. + Vec3r mPrevLocalAngularVel; + private: }; Index: opal.h =================================================================== RCS file: /cvsroot/opal/opal/src/opal.h,v retrieving revision 1.24 retrieving revision 1.25 diff -C2 -d -r1.24 -r1.25 *** opal.h 21 Mar 2005 04:29:05 -0000 1.24 --- opal.h 23 Mar 2005 07:54:34 -0000 1.25 *************** *** 58,63 **** #include "RaycastSensor.h" #include "RaycastSensorData.h" - #include "VelocitySensor.h" - #include "VelocitySensorData.h" #include "VolumeSensor.h" #include "VolumeSensorData.h" --- 58,61 ---- Index: SensorData.h =================================================================== RCS file: /cvsroot/opal/opal/src/SensorData.h,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** SensorData.h 13 Mar 2005 23:07:10 -0000 1.7 --- SensorData.h 23 Mar 2005 07:54:34 -0000 1.8 *************** *** 86,90 **** std::string internal_solidName; ! /// If the Sensor is attached to a Solid, this matrix is the global /// offset from that Solid's transform. Otherwise, it is just the /// Sensor's global transform. --- 86,90 ---- std::string internal_solidName; ! /// If the Sensor is attached to a Solid, this transform is the global /// offset from that Solid's transform. Otherwise, it is just the /// Sensor's global transform. Index: Solid.cpp =================================================================== RCS file: /cvsroot/opal/opal/src/Solid.cpp,v retrieving revision 1.29 retrieving revision 1.30 diff -C2 -d -r1.29 -r1.30 *** Solid.cpp 21 Mar 2005 17:52:22 -0000 1.29 --- Solid.cpp 23 Mar 2005 07:54:34 -0000 1.30 *************** *** 67,92 **** } - //void Solid::internal_updateAcceleration(real dt) - //{ - // Vec3r currentGlobalLinearVel = getGlobalLinearVel(); - // Vec3r currentGlobalAngularVel = getGlobalAngularVel(); - // mGlobalLinearAccel = (currentGlobalLinearVel - - // mPrevGlobalLinearVel) / dt; - // mGlobalAngularAccel = (currentGlobalAngularVel - - // mPrevGlobalAngularVel) / dt; - // mPrevGlobalLinearVel = currentGlobalLinearVel; - // mPrevGlobalAngularVel = currentGlobalAngularVel; - //} - - //Vec3r Solid::getGlobalLinearAccel()const - //{ - // return mGlobalLinearAccel; - //} - - //Vec3r Solid::getGlobalAngularAccel()const - //{ - // return mGlobalAngularAccel; - //} - bool Solid::isStatic()const { --- 67,70 ---- --- VelocitySensor.cpp DELETED --- Index: Simulator.cpp =================================================================== RCS file: /cvsroot/opal/opal/src/Simulator.cpp,v retrieving revision 1.50 retrieving revision 1.51 diff -C2 -d -r1.50 -r1.51 *** Simulator.cpp 23 Mar 2005 04:04:30 -0000 1.50 --- Simulator.cpp 23 Mar 2005 07:54:34 -0000 1.51 *************** *** 38,42 **** #include "SpringMotor.h" #include "RaycastSensor.h" - #include "VelocitySensor.h" #include "AccelerationSensor.h" #include "VolumeSensor.h" --- 38,41 ---- *************** *** 555,570 **** switch(sensorData->getType()) { ! //case ACCELERATION_SENSOR: ! //{ ! // // Make a local copy of the Sensor's data. ! // AccelerationSensorData data = ! // *(AccelerationSensorData*)sensorData; ! // data.solid = solidPtr; ! // data.transform = transform; ! // s = createAccelerationSensor(); ! // ((AccelerationSensor*)s)->init(data); ! // break; ! //} case RAYCAST_SENSOR: { --- 554,569 ---- switch(sensorData->getType()) { ! case ACCELERATION_SENSOR: ! { ! // Make a local copy of the Sensor's data. ! AccelerationSensorData data = ! *(AccelerationSensorData*)sensorData; ! data.solid = solidPtr; ! data.transform = transform; ! s = createAccelerationSensor(); ! ((AccelerationSensor*)s)->init(data); ! break; ! } case RAYCAST_SENSOR: { *************** *** 578,592 **** break; } - //case VELOCITY_SENSOR: - //{ - // // Make a local copy of the Sensor's data. - // VelocitySensorData data = *(VelocitySensorData*)sensorData; - // data.solid = solidPtr; - // data.transform = transform; - - // s = createVelocitySensor(); - // ((VelocitySensor*)s)->init(data); - // break; - //} case VOLUME_SENSOR: { --- 577,580 ---- *************** *** 826,829 **** --- 814,824 ---- } + AccelerationSensor* Simulator::createAccelerationSensor() + { + AccelerationSensor* newSensor = new AccelerationSensor(this); + addSensor(newSensor); + return newSensor; + } + RaycastSensor* Simulator::createRaycastSensor() { Index: Simulator.h =================================================================== RCS file: /cvsroot/opal/opal/src/Simulator.h,v retrieving revision 1.88 retrieving revision 1.89 diff -C2 -d -r1.88 -r1.89 *** Simulator.h 21 Mar 2005 04:29:05 -0000 1.88 --- Simulator.h 23 Mar 2005 07:54:34 -0000 1.89 *************** *** 44,47 **** --- 44,48 ---- class SpringMotor; class ThrusterMotor; + class AccelerationSensor; class RaycastSensor; class VolumeSensor; *************** *** 213,216 **** --- 214,220 ---- // SENSORS + /// Creates and returns a pointer to an AccelerationSensor. + virtual AccelerationSensor* OPAL_CALL createAccelerationSensor(); + /// Creates and returns a pointer to a RaycastSensor. virtual RaycastSensor* OPAL_CALL createRaycastSensor(); --- VelocitySensor.h DELETED --- Index: BlueprintManager.cpp =================================================================== RCS file: /cvsroot/opal/opal/src/BlueprintManager.cpp,v retrieving revision 1.34 retrieving revision 1.35 diff -C2 -d -r1.34 -r1.35 *** BlueprintManager.cpp 23 Mar 2005 04:52:26 -0000 1.34 --- BlueprintManager.cpp 23 Mar 2005 07:54:33 -0000 1.35 *************** *** 38,41 **** --- 38,42 ---- #include "SpringMotorData.h" #include "SensorData.h" + #include "AccelerationSensorData.h" #include "RaycastSensorData.h" #include "VolumeSensorData.h" *************** *** 1212,1228 **** // Load data for the specific type of Sensor. ! //if ("acceleration" == type) ! //{ ! // data = loadAccelerationSensor(nodePtr, bp, filename); ! //} ! //else if ("raycast" == type) ! if ("raycast" == type) { data = loadRaycastSensor(nodePtr, bp, filename); } - //else if ("velocity" == type) - //{ - // data = loadVelocitySensor(nodePtr, bp, filename); - //} else if ("volume" == type) { --- 1213,1224 ---- // Load data for the specific type of Sensor. ! if ("acceleration" == type) ! { ! data = loadAccelerationSensor(nodePtr, bp, filename); ! } ! else if ("raycast" == type) { data = loadRaycastSensor(nodePtr, bp, filename); } else if ("volume" == type) { *************** *** 1295,1298 **** --- 1291,1308 ---- } + AccelerationSensorData* BlueprintManager::loadAccelerationSensor( + const TiXmlNode* nodePtr, const Blueprint& bp, + const std::string& filename) + { + // This data structure automatically gets initialized to + // default values in its constructor. + AccelerationSensorData* data = new AccelerationSensorData(); + + #ifdef OPAL_USE_XML + // Nothing special to load for AccelerationSensors. + #endif + return data; + } + RaycastSensorData* BlueprintManager::loadRaycastSensor( const TiXmlNode* nodePtr, const Blueprint& bp, Index: Solid.h =================================================================== RCS file: /cvsroot/opal/opal/src/Solid.h,v retrieving revision 1.84 retrieving revision 1.85 diff -C2 -d -r1.84 -r1.85 *** Solid.h 21 Mar 2005 04:29:05 -0000 1.84 --- Solid.h 23 Mar 2005 07:54:34 -0000 1.85 *************** *** 157,160 **** --- 157,165 ---- virtual Vec3r OPAL_CALL getLocalLinearVel()const = 0; + /// Given an offset point relative to the Solid's local origin, + /// returns the linear velocity of the point in local coordinates. + virtual Vec3r OPAL_CALL getLocalLinearVelAtLocalPos( + const Point3r& p)const = 0; + /// Sets the Solid's angular velocity in local coordinates. virtual void OPAL_CALL setLocalAngularVel(const Vec3r& vel) = 0; *************** *** 169,172 **** --- 174,182 ---- virtual Vec3r OPAL_CALL getGlobalLinearVel()const = 0; + /// Given an offset point relative to the Solid's local origin, + /// returns the linear velocity of the point in global coordinates. + virtual Vec3r OPAL_CALL getGlobalLinearVelAtLocalPos( + const Point3r& p)const = 0; + /// Sets the Solid's angular velocity in global coordinates. virtual void OPAL_CALL setGlobalAngularVel(const Vec3r& vel) = 0; *************** *** 206,211 **** virtual void OPAL_CALL internal_updateEngineTransform() = 0; - //virtual void OPAL_CALL internal_updateAcceleration(real dt); - /// Loops over the Solid's list of Forces and applies them. virtual void OPAL_CALL internal_applyForces(real stepSize); --- 216,219 ---- --- VelocitySensorData.h DELETED --- Index: BlueprintManager.h =================================================================== RCS file: /cvsroot/opal/opal/src/BlueprintManager.h,v retrieving revision 1.18 retrieving revision 1.19 diff -C2 -d -r1.18 -r1.19 *** BlueprintManager.h 13 Mar 2005 23:07:10 -0000 1.18 --- BlueprintManager.h 23 Mar 2005 07:54:34 -0000 1.19 *************** *** 42,45 **** --- 42,46 ---- class SpringMotorData; class ThrusterMotorData; + class AccelerationSensorData; class RaycastSensorData; class VolumeSensorData; *************** *** 131,134 **** --- 132,143 ---- const Blueprint& bp, const std::string& filename); + /// Helper function for parsing AccelerationSensor XML elements. + /// Allocates and returns a pointer to a new + /// AccelerationSensorData object. Returns NULL if the element + /// could not be loaded. + AccelerationSensorData* loadAccelerationSensor( + const TiXmlNode* nodePtr, const Blueprint& bp, + const std::string& filename); + /// Helper function for parsing RaycastSensor XML elements. /// Allocates and returns a pointer to a new RaycastSensorData Index: AccelerationSensor.cpp =================================================================== RCS file: /cvsroot/opal/opal/src/AccelerationSensor.cpp,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** AccelerationSensor.cpp 23 Mar 2005 04:04:30 -0000 1.2 --- AccelerationSensor.cpp 23 Mar 2005 07:54:33 -0000 1.3 *************** *** 31,37 **** namespace opal { ! AccelerationSensor::AccelerationSensor() { // "mData" is initialized in its own constructor. } --- 31,48 ---- namespace opal { ! AccelerationSensor::AccelerationSensor(Simulator* s) { // "mData" is initialized in its own constructor. + mSim = s; + + // "mGlobalLinearAccel" is initialized in its own constructor. + // "mGlobalAngularAccel" is initialized in its own constructor. + // "mLocalLinearAccel" is initialized in its own constructor. + // "mLocalAngularAccel" is initialized in its own constructor. + + // "mPrevGlobalLinearVel" is initialized in its own constructor. + // "mPrevGlobalAngularVel" is initialized in its own constructor. + // "mPrevLocalLinearVel" is initialized in its own constructor. + // "mPrevLocalAngularVel" is initialized in its own constructor. } *************** *** 51,112 **** } ! real AccelerationSensor::getGlobalLinearAccel()const { if (!mData.solid) { ! return 0; } ! // TODO: use the Sensor's transform to find its actual position ! // in global coordinates. ! ! // TODO: get the acceleration of the Solid at the Sensor's position. ! ! return 0; // temporary } ! real AccelerationSensor::getGlobalAngularAccel()const { if (!mData.solid) { ! return 0; } ! // TODO: use the Sensor's transform to find its actual position ! // in global coordinates. ! ! // TODO: get the acceleration of the Solid at the Sensor's position. ! ! return 0; // temporary } ! real AccelerationSensor::getLocalLinearAccel()const { if (!mData.solid) { ! return 0; } ! // TODO: use the Sensor's transform to find its actual position ! // relative to the Solid. ! ! // TODO: get the acceleration of the Solid at the Sensor's position. ! ! return 0; // temporary } ! real AccelerationSensor::getLocalAngularAccel()const { if (!mData.solid) { ! return 0; } ! // TODO: use the Sensor's transform to find its actual position ! // relative to the Solid. ! ! // TODO: get the acceleration of the Solid at the Sensor's position. ! ! return 0; // temporary } --- 62,103 ---- } ! Vec3r AccelerationSensor::getGlobalLinearAccel()const { if (!mData.solid) { ! return Vec3r(); } ! return mGlobalLinearAccel; } ! Vec3r AccelerationSensor::getGlobalAngularAccel()const { if (!mData.solid) { ! return Vec3r(); } ! return mGlobalAngularAccel; } ! Vec3r AccelerationSensor::getLocalLinearAccel()const { if (!mData.solid) { ! return Vec3r(); } ! return mLocalLinearAccel; } ! Vec3r AccelerationSensor::getLocalAngularAccel()const { if (!mData.solid) { ! return Vec3r(); } ! return mLocalAngularAccel; } *************** *** 155,159 **** if (mData.enabled) { ! // TODO: update acceleration calculations } } --- 146,175 ---- if (mData.enabled) { ! real dt = mSim->getStepSize(); ! ! Vec3r currentGlobalLinearVel = ! mData.solid->getGlobalLinearVelAtLocalPos( ! mData.transform.getPosition()); ! Vec3r currentGlobalAngularVel = ! mData.solid->getGlobalAngularVel(); ! Vec3r currentLocalLinearVel = ! mData.solid->getLocalLinearVelAtLocalPos( ! mData.transform.getPosition()); ! Vec3r currentLocalAngularVel = ! mData.solid->getLocalAngularVel(); ! ! mGlobalLinearAccel = (currentGlobalLinearVel - ! mPrevGlobalLinearVel) / dt; ! mGlobalAngularAccel = (currentGlobalAngularVel - ! mPrevGlobalAngularVel) / dt; ! mLocalLinearAccel = (currentLocalLinearVel - ! mPrevLocalLinearVel) / dt; ! mLocalAngularAccel = (currentLocalAngularVel - ! mPrevLocalAngularVel) / dt; ! ! mPrevGlobalLinearVel = currentGlobalLinearVel; ! mPrevGlobalAngularVel = currentGlobalAngularVel; ! mPrevLocalLinearVel = currentLocalLinearVel; ! mPrevLocalAngularVel = currentLocalAngularVel; } } Index: SConscript =================================================================== RCS file: /cvsroot/opal/opal/src/SConscript,v retrieving revision 1.17 retrieving revision 1.18 diff -C2 -d -r1.17 -r1.18 *** SConscript 21 Mar 2005 04:29:05 -0000 1.17 --- SConscript 23 Mar 2005 07:54:34 -0000 1.18 *************** *** 52,57 **** ThrusterMotorData.h Vec3r.h - VelocitySensor.h - VelocitySensorData.h VolumeSensor.h VolumeSensorData.h --- 52,55 ---- *************** *** 78,82 **** SpringMotor.cpp ThrusterMotor.cpp - VelocitySensor.cpp VolumeSensor.cpp """) --- 76,79 ---- |