[Opal-commits] opal/src InclineSensor.cpp,NONE,1.1 InclineSensor.h,NONE,1.1 InclineSensorData.h,NONE
Status: Inactive
Brought to you by:
tylerstreeter
|
From: tylerstreeter <tyl...@us...> - 2005-03-29 03:06:00
|
Update of /cvsroot/opal/opal/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28949/src Modified Files: AccelerationSensor.cpp AccelerationSensor.h Blueprint.cpp BlueprintManager.cpp Matrix44r.h OpalMath.h RaycastSensorData.h SConscript SensorData.h Simulator.cpp Solid.cpp Vec3r.h opal.h Added Files: InclineSensor.cpp InclineSensor.h InclineSensorData.h Log Message: added some Vec3r functions; added InclineSensor Index: AccelerationSensor.h =================================================================== RCS file: /cvsroot/opal/opal/src/AccelerationSensor.h,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** AccelerationSensor.h 23 Mar 2005 20:24:33 -0000 1.4 --- AccelerationSensor.h 29 Mar 2005 03:05:46 -0000 1.5 *************** *** 48,55 **** virtual ~AccelerationSensor(); ! /// 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 AccelerationSensorData& data); --- 48,54 ---- virtual ~AccelerationSensor(); ! /// Initializes the Sensor with the given data structure. The Solid ! /// pointer should always be valid because this Sensor only works ! /// when attached to something. virtual void OPAL_CALL init(const AccelerationSensorData& data); Index: AccelerationSensor.cpp =================================================================== RCS file: /cvsroot/opal/opal/src/AccelerationSensor.cpp,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** AccelerationSensor.cpp 23 Mar 2005 20:24:32 -0000 1.4 --- AccelerationSensor.cpp 29 Mar 2005 03:05:45 -0000 1.5 *************** *** 64,68 **** Vec3r AccelerationSensor::getGlobalLinearAccel()const { ! if (!mData.solid) { return Vec3r(); --- 64,68 ---- Vec3r AccelerationSensor::getGlobalLinearAccel()const { ! if (!mData.enabled || !mData.solid) { return Vec3r(); *************** *** 75,79 **** Vec3r AccelerationSensor::getGlobalAngularAccel()const { ! if (!mData.solid) { return Vec3r(); --- 75,79 ---- Vec3r AccelerationSensor::getGlobalAngularAccel()const { ! if (!mData.enabled || !mData.solid) { return Vec3r(); *************** *** 86,90 **** Vec3r AccelerationSensor::getLocalLinearAccel()const { ! if (!mData.solid) { return Vec3r(); --- 86,90 ---- Vec3r AccelerationSensor::getLocalLinearAccel()const { ! if (!mData.enabled || !mData.solid) { return Vec3r(); *************** *** 97,101 **** Vec3r AccelerationSensor::getLocalAngularAccel()const { ! if (!mData.solid) { return Vec3r(); --- 97,101 ---- Vec3r AccelerationSensor::getLocalAngularAccel()const { ! if (!mData.enabled || !mData.solid) { return Vec3r(); Index: opal.h =================================================================== RCS file: /cvsroot/opal/opal/src/opal.h,v retrieving revision 1.25 retrieving revision 1.26 diff -C2 -d -r1.25 -r1.26 *** opal.h 23 Mar 2005 07:54:34 -0000 1.25 --- opal.h 29 Mar 2005 03:05:46 -0000 1.26 *************** *** 56,59 **** --- 56,61 ---- #include "AccelerationSensor.h" #include "AccelerationSensorData.h" + #include "InclineSensor.h" + #include "InclineSensorData.h" #include "RaycastSensor.h" #include "RaycastSensorData.h" Index: SensorData.h =================================================================== RCS file: /cvsroot/opal/opal/src/SensorData.h,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** SensorData.h 28 Mar 2005 22:33:07 -0000 1.10 --- SensorData.h 29 Mar 2005 03:05:46 -0000 1.11 *************** *** 37,42 **** { ACCELERATION_SENSOR, RAYCAST_SENSOR, - VELOCITY_SENSOR, VOLUME_SENSOR }; --- 37,42 ---- { ACCELERATION_SENSOR, + INCLINE_SENSOR, RAYCAST_SENSOR, VOLUME_SENSOR }; Index: Blueprint.cpp =================================================================== RCS file: /cvsroot/opal/opal/src/Blueprint.cpp,v retrieving revision 1.20 retrieving revision 1.21 diff -C2 -d -r1.20 -r1.21 *** Blueprint.cpp 28 Mar 2005 22:33:07 -0000 1.20 --- Blueprint.cpp 29 Mar 2005 03:05:46 -0000 1.21 *************** *** 37,40 **** --- 37,41 ---- #include "SensorData.h" #include "AccelerationSensorData.h" + #include "InclineSensorData.h" #include "RaycastSensorData.h" #include "VolumeSensorData.h" Index: Vec3r.h =================================================================== RCS file: /cvsroot/opal/opal/src/Vec3r.h,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** Vec3r.h 7 Feb 2005 02:08:22 -0000 1.12 --- Vec3r.h 29 Mar 2005 03:05:46 -0000 1.13 *************** *** 43,52 **** inline real dot(const Vec3r & u, const Vec3r & v); inline Vec3r cross(const Vec3r & u, const Vec3r& v); ! inline Vec3r project(const Vec3r& from, const Vec3r& onto); inline real angleBetween(const Vec3r& u, const Vec3r& v); ! // u and v are already normalized inline real angleBetweenPreNorm(const Vec3r& u, const Vec3r& v); class Vec3r { --- 43,65 ---- inline real dot(const Vec3r & u, const Vec3r & v); inline Vec3r cross(const Vec3r & u, const Vec3r& v); ! ! /// Returns the projection of 'v' onto 'u'. ! inline Vec3r project(const Vec3r& u, const Vec3r& v); ! ! /// Given that the vector 'u' is already a unit vector, returns the ! /// projection of v onto u. ! inline Vec3r projectPreNorm(const Vec3r& u, const Vec3r& v); ! ! /// Returns a positive angle between 0 and 180 degrees. inline real angleBetween(const Vec3r& u, const Vec3r& v); ! /// Given that the vectors 'u' and 'v' are already normalized, returns ! /// a positive angle between 0 and 180 degrees. inline real angleBetweenPreNorm(const Vec3r& u, const Vec3r& v); + /// Returns true if the two vectors are roughly collinear (within some + /// epsilon). + inline bool areCollinear(const Vec3r& u, const Vec3r& v); + class Vec3r { *************** *** 241,247 **** } ! inline Vec3r project(const Vec3r& from, const Vec3r& onto) { ! return (dot(onto, from) / dot(onto, onto)) * onto; } --- 254,267 ---- } ! inline Vec3r project(const Vec3r& u, const Vec3r& v) { ! Vec3r u2 = u; ! u2.normalize(); ! return projectPreNorm(u2, v); ! } ! ! inline Vec3r projectPreNorm(const Vec3r& u, const Vec3r& v) ! { ! return dot(u, v) * u; } *************** *** 255,265 **** } - // returns a positive angle between 0 and 180 inline real angleBetweenPreNorm(const Vec3r& u, const Vec3r& v) { real val = dot(u, v); ! // clamp to avoid rounding errors; acos will puke with values outside ! // this range if (val < -1) { --- 275,284 ---- } inline real angleBetweenPreNorm(const Vec3r& u, const Vec3r& v) { real val = dot(u, v); ! // Clamp to avoid rounding errors; acos will puke with values outside ! // this range. if (val < -1) { *************** *** 273,276 **** --- 292,307 ---- return radToDeg(acos(val)); } + + inline bool areCollinear(const Vec3r& u, const Vec3r& v) + { + if (dot(u, v) < globals::OPAL_EPSILON) + { + return true; + } + else + { + return false; + } + } } Index: RaycastSensorData.h =================================================================== RCS file: /cvsroot/opal/opal/src/RaycastSensorData.h,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** RaycastSensorData.h 28 Mar 2005 22:33:07 -0000 1.6 --- RaycastSensorData.h 29 Mar 2005 03:05:46 -0000 1.7 *************** *** 68,71 **** --- 68,72 ---- transform = data.transform; ray = data.ray; + contactGroup = data.contactGroup; } Index: SConscript =================================================================== RCS file: /cvsroot/opal/opal/src/SConscript,v retrieving revision 1.18 retrieving revision 1.19 diff -C2 -d -r1.18 -r1.19 *** SConscript 23 Mar 2005 07:54:34 -0000 1.18 --- SConscript 29 Mar 2005 03:05:46 -0000 1.19 *************** *** 18,21 **** --- 18,23 ---- GearedMotor.h GearedMotorData.h + InclineSensor.h + InclineSensorData.h Joint.h JointBreakEventHandler.h *************** *** 65,68 **** --- 67,71 ---- CollisionEventHandler.cpp GearedMotor.cpp + InclineSensor.cpp Joint.cpp Logger.cpp --- NEW FILE: InclineSensor.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_INCLINE_SENSOR_H #define OPAL_INCLINE_SENSOR_H #include "Defines.h" #include "Sensor.h" #include "InclineSensorData.h" namespace opal { class Simulator; /// A Sensor that measures a Solid's "tilt." This is similar to a real /// inclinometer that monitors how an object is oriented with respect /// to gravity. This Sensor takes a rotation axis (defined relative to /// the attached Solid's transform) and returns an angle describing how /// far the Solid has rotated around that axis. The rotation of the /// Solid is defined as zero degrees when the Sensor is initialized or /// when the rotation axis is redefined. This Sensor does /// nothing if it is not attached to a Solid (i.e. its returned values /// are always zero). class InclineSensor : public Sensor { public: InclineSensor(); virtual ~InclineSensor(); /// 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); /// Returns all data describing the Sensor. virtual const InclineSensorData& OPAL_CALL getData()const; /// Returns the angle of rotation about the local rotation axis /// relative to the initial angle of rotation. virtual real OPAL_CALL getAngle(); virtual void OPAL_CALL setEnabled(bool e); virtual bool OPAL_CALL isEnabled()const; /// 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); /// Returns the local rotation axis. virtual const Vec3r& OPAL_CALL getAxis(); 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_dependsOnSolid(Solid* s); protected: /// Stores data describing the Sensor. InclineSensorData mData; private: }; } #endif --- NEW FILE: InclineSensor.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 "InclineSensor.h" #include "Simulator.h" namespace opal { InclineSensor::InclineSensor() { // "mData" is initialized in its own constructor. } InclineSensor::~InclineSensor() { } void InclineSensor::init(const InclineSensorData& data) { Sensor::init(); mData = data; } const InclineSensorData& InclineSensor::getData()const { return mData; } real InclineSensor::getAngle() { if (!mData.enabled || !mData.solid) { return 0; } //TODO: calc angle return 0; // temp } void InclineSensor::setEnabled(bool e) { if (!mInitCalled) { return; } mData.enabled = e; } bool InclineSensor::isEnabled()const { return mData.enabled; } void InclineSensor::setAxis(const Vec3r& axis) { //TODO: redefine angle as zero degrees mData.axis = axis; } const Vec3r& InclineSensor::getAxis() { return mData.axis; } SensorType InclineSensor::getType()const { return mData.getType(); } void InclineSensor::setName(const std::string& name) { mData.name = name; } const std::string& InclineSensor::getName()const { return mData.name; } void InclineSensor::internal_update() { if (mData.enabled) { // Do nothing. } } bool InclineSensor::internal_dependsOnSolid(Solid* s) { if (s == mData.solid) { return true; } else { return false; } } } Index: Solid.cpp =================================================================== RCS file: /cvsroot/opal/opal/src/Solid.cpp,v retrieving revision 1.30 retrieving revision 1.31 diff -C2 -d -r1.30 -r1.31 *** Solid.cpp 23 Mar 2005 07:54:34 -0000 1.30 --- Solid.cpp 29 Mar 2005 03:05:46 -0000 1.31 *************** *** 175,179 **** { if (mData.enabled && !mData.isStatic && ! f.vec.lengthSquared() > 0.0000001f ) { mForceList.push_back(f); --- 175,179 ---- { if (mData.enabled && !mData.isStatic && ! f.vec.lengthSquared() > globals::OPAL_EPSILON ) { mForceList.push_back(f); Index: BlueprintManager.cpp =================================================================== RCS file: /cvsroot/opal/opal/src/BlueprintManager.cpp,v retrieving revision 1.38 retrieving revision 1.39 diff -C2 -d -r1.38 -r1.39 *** BlueprintManager.cpp 28 Mar 2005 22:33:07 -0000 1.38 --- BlueprintManager.cpp 29 Mar 2005 03:05:46 -0000 1.39 *************** *** 39,42 **** --- 39,43 ---- #include "SensorData.h" #include "AccelerationSensorData.h" + #include "InclineSensorData.h" #include "RaycastSensorData.h" #include "VolumeSensorData.h" Index: OpalMath.h =================================================================== RCS file: /cvsroot/opal/opal/src/OpalMath.h,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** OpalMath.h 7 Feb 2005 02:08:22 -0000 1.8 --- OpalMath.h 29 Mar 2005 03:05:46 -0000 1.9 *************** *** 37,43 **** namespace globals { ! const real OPAL_PI=(real)3.14159265358979323846; ! const real OPAL_HALF_PI=(real)1.57079632679489661923; ! const real OPAL_ONE_THIRD=(real)0.33333333333333333333; } --- 37,44 ---- namespace globals { ! const real OPAL_PI = (real)3.14159265358979323846; ! const real OPAL_HALF_PI = (real)1.57079632679489661923; ! const real OPAL_ONE_THIRD = (real)0.33333333333333333333; ! const real OPAL_EPSILON = (real)0.000001; } --- NEW FILE: InclineSensorData.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_INCLINE_SENSOR_DATA_H #define OPAL_INCLINE_SENSOR_DATA_H #include "Defines.h" #include "SensorData.h" namespace opal { /// A data structure describing an InclineSensor. class InclineSensorData : public SensorData { public: OPAL_DECL InclineSensorData() : SensorData() { mType = INCLINE_SENSOR; // "axis" is initialized in its own constructor. } /// Copy constructor. OPAL_DECL InclineSensorData(const InclineSensorData& data) { (*this) = data; } OPAL_DECL virtual ~InclineSensorData() { } /// Makes a deep copy. OPAL_DECL virtual void OPAL_CALL operator=( const InclineSensorData& data) { mType = data.mType; enabled = data.enabled; name = data.name; solid = data.solid; internal_solidIndex = data.internal_solidIndex; solidBlueprintRefName = data.solidBlueprintRefName; transform = data.transform; axis = data.axis; } /// The local rotation axis around which the angle of rotation will /// be measured. Vec3r axis; protected: private: }; } #endif Index: Simulator.cpp =================================================================== RCS file: /cvsroot/opal/opal/src/Simulator.cpp,v retrieving revision 1.52 retrieving revision 1.53 diff -C2 -d -r1.52 -r1.53 *** Simulator.cpp 25 Mar 2005 02:44:19 -0000 1.52 --- Simulator.cpp 29 Mar 2005 03:05:46 -0000 1.53 *************** *** 37,42 **** #include "AttractorMotor.h" #include "SpringMotor.h" - #include "RaycastSensor.h" #include "AccelerationSensor.h" #include "VolumeSensor.h" #include "PostStepEventHandler.h" --- 37,43 ---- #include "AttractorMotor.h" #include "SpringMotor.h" #include "AccelerationSensor.h" + #include "InclineSensor.h" + #include "RaycastSensor.h" #include "VolumeSensor.h" #include "PostStepEventHandler.h" Index: Matrix44r.h =================================================================== RCS file: /cvsroot/opal/opal/src/Matrix44r.h,v retrieving revision 1.29 retrieving revision 1.30 diff -C2 -d -r1.29 -r1.30 *** Matrix44r.h 14 Mar 2005 01:20:52 -0000 1.29 --- Matrix44r.h 29 Mar 2005 03:05:46 -0000 1.30 *************** *** 267,271 **** real trace = (*this)(0,0) + (*this)(1,1) + (*this)(2,2) + 1.0f; ! if(trace > 0.00000001) { real s = 0.5f / sqrt(trace); --- 267,271 ---- real trace = (*this)(0,0) + (*this)(1,1) + (*this)(2,2) + 1.0f; ! if(trace > globals::OPAL_EPSILON) { real s = 0.5f / sqrt(trace); *************** *** 514,518 **** fastInverse for affine transforms" << std::endl; real det = src.determinant(); ! if(abs(det < 0.000001)) return false; dest = ((real)1.0 / det) * src; return true; --- 514,518 ---- fastInverse for affine transforms" << std::endl; real det = src.determinant(); ! if(abs(det < globals::OPAL_EPSILON)) return false; dest = ((real)1.0 / det) * src; return true; *************** *** 523,527 **** inline void fastInverse(Matrix44r & result, const Matrix44r & source) { - static const real eps = (real)0.00000001; // source: stolen straight from GMTL // in case &dest is == &source... :( --- 523,526 ---- *************** *** 544,550 **** // TODO: write opal::abs. ! if(fabs(l0) > eps) l0 = 1.0f / l0; ! if(fabs(l1) > eps) l1 = 1.0f / l1; ! if(fabs(l2) > eps) l2 = 1.0f / l2; // apply the inverse scale to the 3x3 --- 543,549 ---- // TODO: write opal::abs. ! if(fabs(l0) > globals::OPAL_EPSILON) l0 = 1.0f / l0; ! if(fabs(l1) > globals::OPAL_EPSILON) l1 = 1.0f / l1; ! if(fabs(l2) > globals::OPAL_EPSILON) l2 = 1.0f / l2; // apply the inverse scale to the 3x3 *************** *** 571,575 **** // invert scale. ! const real tw = (fabs(src(3, 3)) > eps) ? 1.0f / src(3, 3) : 0.0f; // handle uniform scale in Nx4 matrices --- 570,575 ---- // invert scale. ! const real tw = (fabs(src(3, 3)) > globals::OPAL_EPSILON) ! ? 1.0f / src(3, 3) : 0.0f; // handle uniform scale in Nx4 matrices |