[Opal-commits] opal/src AccelerationSensor.cpp,1.5,1.6 AttractorMotor.cpp,1.21,1.22 AttractorMotor.h
Status: Inactive
Brought to you by:
tylerstreeter
Update of /cvsroot/opal/opal/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4745/src Modified Files: AccelerationSensor.cpp AttractorMotor.cpp AttractorMotor.h Defines.h GearedMotor.cpp InclineSensor.cpp InclineSensor.h InclineSensorData.h Joint.h Motor.h RaycastSensor.cpp Sensor.h ServoMotor.cpp Simulator.cpp Simulator.h SpringMotor.cpp SpringMotor.h ThrusterMotor.cpp ThrusterMotor.h Vec3r.h VolumeSensor.cpp Log Message: implemented InclineSensor; added code for Ogre sample apps Index: Sensor.h =================================================================== RCS file: /cvsroot/opal/opal/src/Sensor.h,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** Sensor.h 23 Mar 2005 04:04:30 -0000 1.10 --- Sensor.h 30 Mar 2005 23:26:22 -0000 1.11 *************** *** 38,44 **** /// environment. Each Sensor maintains a transform matrix; depending /// on whether the Sensor is attached to a Solid, the transform is ! /// relative to the attached Solid or the global origin. All Sensors ! /// start out disabled and must be initialized (via init) before they ! /// can be enabled. class Sensor { --- 38,43 ---- /// environment. Each Sensor maintains a transform matrix; depending /// on whether the Sensor is attached to a Solid, the transform is ! /// relative to the attached Solid or the global origin. Most Sensors ! /// remain ineffective until they are initialized. class Sensor { *************** *** 48,53 **** virtual ~Sensor(); ! /// Sets whether the Sensor can update its measurements. If the ! /// Sensor has not yet been initialized, this will have no effect. virtual void OPAL_CALL setEnabled(bool e) = 0; --- 47,51 ---- virtual ~Sensor(); ! /// Sets whether the Sensor can update its measurements. virtual void OPAL_CALL setEnabled(bool e) = 0; Index: Vec3r.h =================================================================== RCS file: /cvsroot/opal/opal/src/Vec3r.h,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** Vec3r.h 29 Mar 2005 03:05:46 -0000 1.13 --- Vec3r.h 30 Mar 2005 23:26:23 -0000 1.14 *************** *** 295,299 **** inline bool areCollinear(const Vec3r& u, const Vec3r& v) { ! if (dot(u, v) < globals::OPAL_EPSILON) { return true; --- 295,300 ---- inline bool areCollinear(const Vec3r& u, const Vec3r& v) { ! real value = 1 - dot(u, v); ! if (fabs(value) < globals::OPAL_EPSILON) { return true; Index: Motor.h =================================================================== RCS file: /cvsroot/opal/opal/src/Motor.h,v retrieving revision 1.38 retrieving revision 1.39 diff -C2 -d -r1.38 -r1.39 *** Motor.h 23 Mar 2005 04:04:30 -0000 1.38 --- Motor.h 30 Mar 2005 23:26:22 -0000 1.39 *************** *** 43,49 **** /// attain a desired state, users should use a Motor that takes a /// desired position or velocity, automatically applying forces every ! /// time step to attain that state. All Motors start out ! /// disabled and must be initialized via init before they can be ! /// enabled. class Motor { --- 43,48 ---- /// attain a desired state, users should use a Motor that takes a /// desired position or velocity, automatically applying forces every ! /// time step to attain that state. Most Motors remain ineffective ! /// until they are initialized. class Motor { *************** *** 53,58 **** virtual ~Motor(); ! /// Sets whether the Motor has any effect. If the Motor has not ! /// yet been initialized, this will have no effect. virtual void OPAL_CALL setEnabled(bool e) = 0; --- 52,56 ---- virtual ~Motor(); ! /// Sets whether the Motor has any effect. virtual void OPAL_CALL setEnabled(bool e) = 0; Index: Simulator.h =================================================================== RCS file: /cvsroot/opal/opal/src/Simulator.h,v retrieving revision 1.91 retrieving revision 1.92 diff -C2 -d -r1.91 -r1.92 *** Simulator.h 25 Mar 2005 02:44:20 -0000 1.91 --- Simulator.h 30 Mar 2005 23:26:22 -0000 1.92 *************** *** 45,48 **** --- 45,49 ---- class ThrusterMotor; class AccelerationSensor; + class InclineSensor; class RaycastSensor; class VolumeSensor; *************** *** 222,225 **** --- 223,229 ---- virtual AccelerationSensor* OPAL_CALL createAccelerationSensor(); + /// Creates and returns a pointer to an InclineSensor. + virtual InclineSensor* OPAL_CALL createInclineSensor(); + /// Creates and returns a pointer to a RaycastSensor. virtual RaycastSensor* OPAL_CALL createRaycastSensor(); Index: InclineSensor.cpp =================================================================== RCS file: /cvsroot/opal/opal/src/InclineSensor.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** InclineSensor.cpp 29 Mar 2005 03:05:46 -0000 1.1 --- InclineSensor.cpp 30 Mar 2005 23:26:22 -0000 1.2 *************** *** 34,37 **** --- 34,39 ---- { // "mData" is initialized in its own constructor. + // "mLocalReferenceVec" is initialized in its own constructor. + // "mInitGlobalReferenceVec" is initialized in its own constructor. } *************** *** 44,47 **** --- 46,52 ---- Sensor::init(); mData = data; + + // Define the current setup as zero degrees. + setupInternalVectors(); } *************** *** 58,71 **** } ! //TODO: calc angle ! return 0; // temp } void InclineSensor::setEnabled(bool e) { ! if (!mInitCalled) ! { ! return; ! } mData.enabled = e; --- 63,108 ---- } ! // By this time setupInternalVectors should have been called, so ! // the mLocalReferenceVec and mInitGlobalReferenceVec vectors are ! // valid. ! ! // Let's call the plane orthogonal to the rotation axis the ! // "plane of rotation." The local reference vector is currently on ! // the plane of rotation. We need to get the initial global ! // reference vector projected onto the plane of rotation. ! ! Vec3r currentGlobalReferenceVec = mData.solid->getTransform() * ! mLocalReferenceVec; ! ! if (areCollinear(mInitGlobalReferenceVec, currentGlobalReferenceVec)) ! { ! // Return zero degrees if the initial global reference vector ! // is collinear with the current global reference vector. ! return 0; ! } ! ! Vec3r tempVec = cross(mData.axis, mInitGlobalReferenceVec); ! Vec3r u = cross(mData.axis, tempVec); ! ! // Now 'u' should be on the plane of rotation. We just need to ! // project the initial global reference vector onto it. ! ! Vec3r projInitGlobalReferenceVec = project(u, ! mInitGlobalReferenceVec); ! ! // Now calculate the angle between the projected global reference ! // vector and the current global reference vector. ! real angle = angleBetween(projInitGlobalReferenceVec, ! currentGlobalReferenceVec); ! ! return angle; } void InclineSensor::setEnabled(bool e) { ! //if (!mInitCalled) ! //{ ! // return; ! //} mData.enabled = e; *************** *** 79,84 **** void InclineSensor::setAxis(const Vec3r& axis) { ! //TODO: redefine angle as zero degrees mData.axis = axis; } --- 116,128 ---- void InclineSensor::setAxis(const Vec3r& axis) { ! if (!mData.solid) ! { ! return; ! } ! mData.axis = axis; + + // Redefine the current setup as zero degrees. + setupInternalVectors(); } *************** *** 93,96 **** --- 137,150 ---- } + void InclineSensor::setTransform(const Matrix44r& t) + { + mData.transform = t; + } + + const Matrix44r& InclineSensor::getTransform()const + { + return mData.transform; + } + void InclineSensor::setName(const std::string& name) { *************** *** 105,109 **** void InclineSensor::internal_update() { ! if (mData.enabled) { // Do nothing. --- 159,163 ---- void InclineSensor::internal_update() { ! if (mData.enabled && mData.solid) { // Do nothing. *************** *** 122,124 **** --- 176,207 ---- } } + + void InclineSensor::setupInternalVectors() + { + if (!mData.solid) + { + return; + } + + // We need to calculate a local reference vector that's orthogonal + // to the rotation axis. + + // This temporary vector can be anything as long as its not + // collinear with the rotation axis. + Vec3r tempVec(1, 0, 0); + + if (areCollinear(mData.axis, tempVec)) + { + // Pick a new tempVec. + tempVec.set(0, 1, 0); + } + + // Now we can get the orthogonal reference vector. + mLocalReferenceVec = cross(mData.axis, tempVec); + + // Also store a copy of this reference vector in its initial global + // representation. + mInitGlobalReferenceVec = mData.solid->getTransform() * + mLocalReferenceVec; + } } Index: SpringMotor.h =================================================================== RCS file: /cvsroot/opal/opal/src/SpringMotor.h,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** SpringMotor.h 23 Mar 2005 04:52:36 -0000 1.13 --- SpringMotor.h 30 Mar 2005 23:26:23 -0000 1.14 *************** *** 46,57 **** virtual ~SpringMotor(); ! /// Sets up the Motor to affect a Solid. Also specifies which ! /// degrees of freedom are affected by the Motor. This will ! /// enable the Motor. Calling this more than once will detach the ! /// Motor from its Solid and attach it to a new Solid. ! //virtual void OPAL_CALL init(Mode m, Solid* s); ! ! /// Initializes the Motor with the given data structure. Solid ! /// pointer in the data must be valid. virtual void OPAL_CALL init(const SpringMotorData& data); --- 46,51 ---- virtual ~SpringMotor(); ! /// Initializes the Motor with the given data structure. If the ! /// Solid pointer in the data are NULL, the Motor will do nothing. virtual void OPAL_CALL init(const SpringMotorData& data); *************** *** 70,78 **** /// Sets the spring's attach point on the Solid. This is a local ! // offset point from the Solid's position. ! virtual void OPAL_CALL setAttachOffset(const Point3r& offset); ! /// Returns the spring's attach point on the Solid. ! virtual const Point3r& OPAL_CALL getAttachOffset()const; /// Sets the desired position and orientation. --- 64,81 ---- /// Sets the spring's attach point on the Solid. This is a local ! /// offset point from the Solid's position. ! virtual void OPAL_CALL setLocalAttachOffset(const Point3r& offset); ! /// Returns the spring's attach point on the Solid. This is a local ! /// offset point from the Solid's position. ! virtual const Point3r& OPAL_CALL getLocalAttachOffset()const; ! ! /// Sets the spring's attach point on the Solid in global ! /// coordinates. ! virtual void OPAL_CALL setGlobalAttachPoint(const Point3r& p); ! ! /// Returns the spring's attach point on the Solid in global ! /// coordinates. ! virtual Point3r OPAL_CALL getGlobalAttachPoint()const; /// Sets the desired position and orientation. Index: InclineSensorData.h =================================================================== RCS file: /cvsroot/opal/opal/src/InclineSensorData.h,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** InclineSensorData.h 29 Mar 2005 03:05:46 -0000 1.1 --- InclineSensorData.h 30 Mar 2005 23:26:22 -0000 1.2 *************** *** 42,46 **** { mType = INCLINE_SENSOR; ! // "axis" is initialized in its own constructor. } --- 42,46 ---- { mType = INCLINE_SENSOR; ! axis = defaults::sensor::incline::axis; } Index: ThrusterMotor.h =================================================================== RCS file: /cvsroot/opal/opal/src/ThrusterMotor.h,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** ThrusterMotor.h 23 Mar 2005 04:04:31 -0000 1.13 --- ThrusterMotor.h 30 Mar 2005 23:26:23 -0000 1.14 *************** *** 51,57 **** //virtual void OPAL_CALL init(Solid* solid); ! /// Initializes the Motor with the given data structure. The Solid ! /// pointer in the data must be valid. The Force in this data ! /// structure will automatically be set to a "single step" Force. virtual void OPAL_CALL init(const ThrusterMotorData& data); --- 51,58 ---- //virtual void OPAL_CALL init(Solid* solid); ! /// Initializes the Motor with the given data structure. If the ! /// Solid pointer in the data are NULL, the Motor will do nothing. ! /// The Force in this data structure will automatically be set to a ! /// "single step" Force. virtual void OPAL_CALL init(const ThrusterMotorData& data); Index: InclineSensor.h =================================================================== RCS file: /cvsroot/opal/opal/src/InclineSensor.h,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** InclineSensor.h 29 Mar 2005 03:05:46 -0000 1.1 --- InclineSensor.h 30 Mar 2005 23:26:22 -0000 1.2 *************** *** 55,60 **** /// Initializes the Sensor with the given data structure. This will /// define the rotation angle as zero degrees when called. The Solid ! /// pointer should always be valid because this Sensor only works ! /// when attached to something. virtual void OPAL_CALL init(const InclineSensorData& data); --- 55,61 ---- /// Initializes the Sensor with the given data structure. This will /// define the rotation angle as zero degrees when called. The Solid ! /// pointer should be valid because this Sensor only works when ! /// attached to something. This does nothing if the Sensor's Solid ! /// pointer is NULL. virtual void OPAL_CALL init(const InclineSensorData& data); *************** *** 72,76 **** /// Sets the local rotation axis around which the angle of rotation /// will be measured. This will redefine the rotation angle as zero ! /// degrees when called. virtual void OPAL_CALL setAxis(const Vec3r& axis); --- 73,78 ---- /// Sets the local rotation axis around which the angle of rotation /// will be measured. This will redefine the rotation angle as zero ! /// degrees when called. This does nothing if the Sensor's Solid ! /// pointer is NULL. virtual void OPAL_CALL setAxis(const Vec3r& axis); *************** *** 78,81 **** --- 80,87 ---- virtual const Vec3r& OPAL_CALL getAxis(); + virtual void OPAL_CALL setTransform(const Matrix44r& t); + + virtual const Matrix44r& OPAL_CALL getTransform()const; + virtual SensorType OPAL_CALL getType()const; *************** *** 89,95 **** --- 95,111 ---- protected: + /// A helper function that sets up all internal vectors used when + /// calculating the angle of rotation. + void setupInternalVectors(); + /// Stores data describing the Sensor. InclineSensorData mData; + /// A vector used to measure the angle of rotation. + Vec3r mLocalReferenceVec; + + /// A vector used to measure the angle of rotation. + Vec3r mInitGlobalReferenceVec; + private: }; Index: AccelerationSensor.cpp =================================================================== RCS file: /cvsroot/opal/opal/src/AccelerationSensor.cpp,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** AccelerationSensor.cpp 29 Mar 2005 03:05:45 -0000 1.5 --- AccelerationSensor.cpp 30 Mar 2005 23:26:21 -0000 1.6 *************** *** 108,115 **** void AccelerationSensor::setEnabled(bool e) { ! if (!mInitCalled) ! { ! return; ! } mData.enabled = e; --- 108,115 ---- void AccelerationSensor::setEnabled(bool e) { ! //if (!mInitCalled) ! //{ ! // return; ! //} mData.enabled = e; *************** *** 148,152 **** void AccelerationSensor::internal_update() { ! if (mData.enabled) { mCurrentGlobalLinearVel = --- 148,152 ---- void AccelerationSensor::internal_update() { ! if (mData.enabled && mData.solid) { mCurrentGlobalLinearVel = Index: GearedMotor.cpp =================================================================== RCS file: /cvsroot/opal/opal/src/GearedMotor.cpp,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** GearedMotor.cpp 23 Mar 2005 04:04:30 -0000 1.11 --- GearedMotor.cpp 30 Mar 2005 23:26:22 -0000 1.12 *************** *** 84,91 **** void GearedMotor::setEnabled(bool e) { ! if (!mInitCalled) ! { ! return; ! } mData.enabled = e; --- 84,91 ---- void GearedMotor::setEnabled(bool e) { ! //if (!mInitCalled) ! //{ ! // return; ! //} mData.enabled = e; *************** *** 94,98 **** void GearedMotor::internal_update() { ! if (mData.enabled) { // Global/local direction makes no difference here since --- 94,98 ---- void GearedMotor::internal_update() { ! if (mData.enabled && mData.joint) { // Global/local direction makes no difference here since Index: AttractorMotor.h =================================================================== RCS file: /cvsroot/opal/opal/src/AttractorMotor.h,v retrieving revision 1.28 retrieving revision 1.29 diff -C2 -d -r1.28 -r1.29 *** AttractorMotor.h 23 Mar 2005 04:04:30 -0000 1.28 --- AttractorMotor.h 30 Mar 2005 23:26:22 -0000 1.29 *************** *** 48,58 **** virtual ~AttractorMotor(); ! /// Sets up the Motor to attract two Solids to each other. This will ! /// enable the Motor. Calling this more than once will detach the ! /// Motor from its Solids and attach it to new Solids. ! //virtual void OPAL_CALL init(Solid* solid0, Solid* solid1); ! ! /// Initializes the Motor with the given data structure. Solid ! /// pointers in the data must be valid. virtual void OPAL_CALL init(const AttractorMotorData& data); --- 48,53 ---- virtual ~AttractorMotor(); ! /// Initializes the Motor with the given data structure. If the ! /// Solid pointers in the data are NULL, the Motor will do nothing. virtual void OPAL_CALL init(const AttractorMotorData& data); Index: ThrusterMotor.cpp =================================================================== RCS file: /cvsroot/opal/opal/src/ThrusterMotor.cpp,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** ThrusterMotor.cpp 23 Mar 2005 04:04:31 -0000 1.11 --- ThrusterMotor.cpp 30 Mar 2005 23:26:23 -0000 1.12 *************** *** 50,54 **** void ThrusterMotor::init(const ThrusterMotorData& data) { - assert(data.solid); Motor::init(); mData = data; --- 50,53 ---- *************** *** 83,90 **** void ThrusterMotor::setEnabled(bool e) { ! if (!mInitCalled) ! { ! return; ! } mData.enabled = e; --- 82,89 ---- void ThrusterMotor::setEnabled(bool e) { ! //if (!mInitCalled) ! //{ ! // return; ! //} mData.enabled = e; *************** *** 93,97 **** void ThrusterMotor::internal_update() { ! if (mData.enabled) { mData.solid->addForce(mData.force); --- 92,96 ---- void ThrusterMotor::internal_update() { ! if (mData.enabled && mData.solid) { mData.solid->addForce(mData.force); Index: Simulator.cpp =================================================================== RCS file: /cvsroot/opal/opal/src/Simulator.cpp,v retrieving revision 1.53 retrieving revision 1.54 diff -C2 -d -r1.53 -r1.54 *** Simulator.cpp 29 Mar 2005 03:05:46 -0000 1.53 --- Simulator.cpp 30 Mar 2005 23:26:22 -0000 1.54 *************** *** 841,844 **** --- 841,851 ---- } + InclineSensor* Simulator::createInclineSensor() + { + InclineSensor* newSensor = new InclineSensor(); + addSensor(newSensor); + return newSensor; + } + RaycastSensor* Simulator::createRaycastSensor() { Index: RaycastSensor.cpp =================================================================== RCS file: /cvsroot/opal/opal/src/RaycastSensor.cpp,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** RaycastSensor.cpp 23 Mar 2005 20:24:36 -0000 1.8 --- RaycastSensor.cpp 30 Mar 2005 23:26:22 -0000 1.9 *************** *** 59,88 **** const RaycastResult& RaycastSensor::fireRay(real length) { ! Rayr ray = mData.ray; ! ! // If the Sensor is attached to a Solid, we need to transform ! // the ray relative to that Solid's transform. ! if (mData.solid) { ! ray = mData.solid->getTransform() * ray; ! } ! // Use the Sensor's transform on the ray. ! ray = mData.transform * ray; ! // If this is attached to a Solid, the Simulator raycast function ! // will automatically ignore intersections between the ray and ! // that Solid. ! return mSim->internal_fireRay(ray, length, mData.solid, ! mData.contactGroup); } void RaycastSensor::setEnabled(bool e) { ! if (!mInitCalled) ! { ! return; ! } mData.enabled = e; --- 59,96 ---- const RaycastResult& RaycastSensor::fireRay(real length) { ! if (mData.enabled) { ! Rayr ray = mData.ray; ! // If the Sensor is attached to a Solid, we need to transform ! // the ray relative to that Solid's transform. ! if (mData.solid) ! { ! ray = mData.solid->getTransform() * ray; ! } ! // Use the Sensor's transform on the ray. ! ray = mData.transform * ray; ! // If this is attached to a Solid, the Simulator raycast function ! // will automatically ignore intersections between the ray and ! // that Solid. ! ! return mSim->internal_fireRay(ray, length, mData.solid, ! mData.contactGroup); ! } ! else ! { ! static RaycastResult junkResult; ! return junkResult; ! } } void RaycastSensor::setEnabled(bool e) { ! //if (!mInitCalled) ! //{ ! // return; ! //} mData.enabled = e; *************** *** 131,135 **** void RaycastSensor::internal_update() { ! if (mData.enabled) { // Do nothing. --- 139,143 ---- void RaycastSensor::internal_update() { ! if (mData.enabled && mData.solid) { // Do nothing. Index: Defines.h =================================================================== RCS file: /cvsroot/opal/opal/src/Defines.h,v retrieving revision 1.69 retrieving revision 1.70 diff -C2 -d -r1.69 -r1.70 *** Defines.h 13 Mar 2005 23:40:53 -0000 1.69 --- Defines.h 30 Mar 2005 23:26:22 -0000 1.70 *************** *** 374,377 **** --- 374,383 ---- { const bool enabled = true; + + /// Default parameters used in InclineSensor creation. + namespace incline + { + const Vec3r axis = Vec3r(1, 0, 0); + } } Index: VolumeSensor.cpp =================================================================== RCS file: /cvsroot/opal/opal/src/VolumeSensor.cpp,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** VolumeSensor.cpp 23 Mar 2005 04:04:31 -0000 1.4 --- VolumeSensor.cpp 30 Mar 2005 23:26:23 -0000 1.5 *************** *** 54,98 **** const VolumeQueryResult& VolumeSensor::queryVolume(Solid* volume) { ! // The volume Solid's transform will be totally ignored. ! // Store the volume Solid's transform. ! Matrix44r originalVolumeTransform = volume->getTransform(); ! Matrix44r newVolumeTransform; ! // If the Sensor is attached to a Solid, we need to transform ! // the volume relative to that Solid's transform. ! if (mData.solid) ! { ! newVolumeTransform = ! mData.solid->getTransform() * newVolumeTransform; ! } ! // Use the Sensor's transform on the volume. ! newVolumeTransform = mData.transform * newVolumeTransform; ! // Set the volume's new transform we just setup. ! volume->setTransform(newVolumeTransform); ! // If this is attached to a Solid, the Simulator volume query ! // function will automatically ignore intersections between the ! // volume and that Solid. ! // Query the volume for colliding Solids. ! const VolumeQueryResult& result = ! mSim->internal_queryVolume(volume, mData.solid); ! // Restore the volume Solid's original transform. ! volume->setTransform(originalVolumeTransform); ! return result; } void VolumeSensor::setEnabled(bool e) { ! if (!mInitCalled) ! { ! return; ! } mData.enabled = e; --- 54,106 ---- const VolumeQueryResult& VolumeSensor::queryVolume(Solid* volume) { ! if (mData.enabled) ! { ! // The volume Solid's transform will be totally ignored. ! // Store the volume Solid's transform. ! Matrix44r originalVolumeTransform = volume->getTransform(); ! Matrix44r newVolumeTransform; ! // If the Sensor is attached to a Solid, we need to transform ! // the volume relative to that Solid's transform. ! if (mData.solid) ! { ! newVolumeTransform = ! mData.solid->getTransform() * newVolumeTransform; ! } ! // Use the Sensor's transform on the volume. ! newVolumeTransform = mData.transform * newVolumeTransform; ! // Set the volume's new transform we just setup. ! volume->setTransform(newVolumeTransform); ! // If this is attached to a Solid, the Simulator volume query ! // function will automatically ignore intersections between the ! // volume and that Solid. ! // Query the volume for colliding Solids. ! const VolumeQueryResult& result = ! mSim->internal_queryVolume(volume, mData.solid); ! // Restore the volume Solid's original transform. ! volume->setTransform(originalVolumeTransform); ! return result; ! } ! else ! { ! static VolumeQueryResult junkResult; ! return junkResult; ! } } void VolumeSensor::setEnabled(bool e) { ! //if (!mInitCalled) ! //{ ! // return; ! //} mData.enabled = e; *************** *** 131,135 **** void VolumeSensor::internal_update() { ! if (mData.enabled) { // Do nothing. --- 139,143 ---- void VolumeSensor::internal_update() { ! if (mData.enabled && mData.solid) { // Do nothing. Index: SpringMotor.cpp =================================================================== RCS file: /cvsroot/opal/opal/src/SpringMotor.cpp,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** SpringMotor.cpp 23 Mar 2005 04:52:36 -0000 1.11 --- SpringMotor.cpp 30 Mar 2005 23:26:23 -0000 1.12 *************** *** 43,47 **** void SpringMotor::init(const SpringMotorData& data) { - assert(data.solid); Motor::init(); mData = data; --- 43,46 ---- *************** *** 75,82 **** void SpringMotor::setEnabled(bool e) { ! if (!mInitCalled) ! { ! return; ! } mData.enabled = e; --- 74,81 ---- void SpringMotor::setEnabled(bool e) { ! //if (!mInitCalled) ! //{ ! // return; ! //} mData.enabled = e; *************** *** 87,91 **** // Note: this only applies to global position and orientation. ! if (mData.enabled) { if (LINEAR_MODE == mData.mode || --- 86,90 ---- // Note: this only applies to global position and orientation. ! if (mData.enabled && mData.solid) { if (LINEAR_MODE == mData.mode || *************** *** 170,183 **** } ! void SpringMotor::setAttachOffset(const Point3r& offset) { mData.attachOffset = offset; } ! const Point3r& SpringMotor::getAttachOffset()const { return mData.attachOffset; } void SpringMotor::setDesiredTransform(const Matrix44r& transform) { --- 169,219 ---- } ! void SpringMotor::setLocalAttachOffset(const Point3r& offset) { mData.attachOffset = offset; } ! const Point3r& SpringMotor::getLocalAttachOffset()const { return mData.attachOffset; } + void SpringMotor::setGlobalAttachPoint(const Point3r& p) + { + if (!mData.solid) + { + OPAL_LOGGER("warning") << + "opal::SpringMotor::setGlobalAttachPoint: Solid pointer is \ + invalid. Ignoring request." << std::endl; + return; + } + + // Convert the global point to an offset from the Solid's transform. + Vec3r relVec = p - mData.solid->getPosition(); + Point3r relPos(relVec[0], relVec[1], relVec[2]); + mData.attachOffset = mData.solid->getTransform() * relPos; + } + + Point3r SpringMotor::getGlobalAttachPoint()const + { + if (!mData.solid) + { + OPAL_LOGGER("warning") << + "opal::SpringMotor::getGlobalAttachPoint: Solid pointer is \ + invalid. Returning (0,0,0)." << std::endl; + return Point3r(); + } + + // The global position is a combination of the Solid's global + // transform and the spring's local offset from the Solid's + // transform. + Vec3r offset(mData.attachOffset[0], mData.attachOffset[1], + mData.attachOffset[2]); + Point3r globalPos = mData.solid->getPosition() + + mData.solid->getTransform() * offset; + + return globalPos; + } + void SpringMotor::setDesiredTransform(const Matrix44r& transform) { Index: Joint.h =================================================================== RCS file: /cvsroot/opal/opal/src/Joint.h,v retrieving revision 1.66 retrieving revision 1.67 diff -C2 -d -r1.66 -r1.67 *** Joint.h 23 Mar 2005 04:04:30 -0000 1.66 --- Joint.h 30 Mar 2005 23:26:22 -0000 1.67 *************** *** 51,56 **** /// do not use all of the anchor and axis parameters. An unused anchor /// or axis will be ignored (see the JointType description for more ! /// details). All Joints start out disabled and must be initialized ! /// via init before they can be enabled. class Joint { --- 51,55 ---- /// do not use all of the anchor and axis parameters. An unused anchor /// or axis will be ignored (see the JointType description for more ! /// details). Joints remain ineffective until they are initialized. class Joint { Index: AttractorMotor.cpp =================================================================== RCS file: /cvsroot/opal/opal/src/AttractorMotor.cpp,v retrieving revision 1.21 retrieving revision 1.22 diff -C2 -d -r1.21 -r1.22 *** AttractorMotor.cpp 23 Mar 2005 04:04:30 -0000 1.21 --- AttractorMotor.cpp 30 Mar 2005 23:26:22 -0000 1.22 *************** *** 58,69 **** void AttractorMotor::init(const AttractorMotorData& data) { - assert(data.solid0 && data.solid1); Motor::init(); mData = data; - mSolid0Mass = data.solid0->getMass(); - mSolid1Mass = data.solid1->getMass(); ! // Update this constant since the masses changed. ! mMassConstant = data.strength * mSolid0Mass * mSolid1Mass; } --- 58,72 ---- void AttractorMotor::init(const AttractorMotorData& data) { Motor::init(); mData = data; ! if (data.solid0 && data.solid1) ! { ! mSolid0Mass = data.solid0->getMass(); ! mSolid1Mass = data.solid1->getMass(); ! ! // Update this constant since the masses changed. ! mMassConstant = data.strength * mSolid0Mass * mSolid1Mass; ! } } *************** *** 95,102 **** void AttractorMotor::setEnabled(bool e) { ! if (!mInitCalled) ! { ! return; ! } mData.enabled = e; --- 98,105 ---- void AttractorMotor::setEnabled(bool e) { ! //if (!mInitCalled) ! //{ ! // return; ! //} mData.enabled = e; *************** *** 105,109 **** void AttractorMotor::internal_update() { ! if (mData.enabled) { Point3r pos1 = mData.solid0->getPosition(); --- 108,112 ---- void AttractorMotor::internal_update() { ! if (mData.enabled && mData.solid0 && mData.solid1) { Point3r pos1 = mData.solid0->getPosition(); Index: ServoMotor.cpp =================================================================== RCS file: /cvsroot/opal/opal/src/ServoMotor.cpp,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** ServoMotor.cpp 23 Mar 2005 04:04:30 -0000 1.15 --- ServoMotor.cpp 30 Mar 2005 23:26:22 -0000 1.16 *************** *** 48,69 **** } - //void ServoMotor::init(Mode m, Joint* j, int axisNum) - //{ - // if (mInitCalled) - // { - // // If the Servo is already in operation, we first need to - // // set the Joint's desired vel and max force to 0. The - // // following function call will automatically handle this - // // when set to false. - // setEnabled(false); - // } - - // Motor::init(); - // assert(axisNum >= 0 && axisNum < j->getNumAxes()); - // mJoint = j; - // mMode = m; - // mJointAxis = axisNum; - //} - void ServoMotor::init(const ServoMotorData& data) { --- 48,51 ---- *************** *** 112,119 **** void ServoMotor::setEnabled(bool e) { ! if (!mInitCalled) ! { ! return; ! } mData.enabled = e; --- 94,101 ---- void ServoMotor::setEnabled(bool e) { ! //if (!mInitCalled) ! //{ ! // return; ! //} mData.enabled = e; *************** *** 138,142 **** void ServoMotor::internal_update() { ! if (mData.enabled) { // Make sure both Solids are awake at this point. --- 120,124 ---- void ServoMotor::internal_update() { ! if (mData.enabled && mData.joint) { // Make sure both Solids are awake at this point. |