From: <mk...@us...> - 2003-08-07 17:37:22
|
Update of /cvsroot/csp/APPLICATIONS/SimData/Include/SimData In directory sc8-pr-cvs1:/tmp/cvs-serv29535 Modified Files: Quat.h Random.h osg.h Log Message: Index: Quat.h =================================================================== RCS file: /cvsroot/csp/APPLICATIONS/SimData/Include/SimData/Quat.h,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** Quat.h 6 Aug 2003 07:52:41 -0000 1.2 --- Quat.h 7 Aug 2003 17:37:19 -0000 1.3 *************** *** 49,54 **** ! /** ! * A quaternion class. It can be used to represent an orientation in 3D space. */ class SIMDATA_EXPORT Quat: public BaseType --- 49,59 ---- ! /** ! * class Quaternion ! * ! * Quaternions are four dimensional objects that form a compact ! * representation for rotations. Many thorough treatments of ! * quaternions and their use in simulations can be readily found ! * on the web. */ class SIMDATA_EXPORT Quat: public BaseType *************** *** 57,77 **** public: static const Quat IDENTITY; static const Quat ZERO; ! // BaseType interface virtual void pack(Packer&) const; virtual void unpack(UnPacker&); virtual void parseXML(const char* cdata); /** ! * String representation. */ std::string asString() const; inline Quat(): _x(0.0), _y(0.0), _z(0.0), _w(0.0) {} inline Quat(double x, double y, double z, double w): _x(x), _y(y), _z(z), _w(w) {} inline Quat(double angle, const Vector3& axis) { makeRotate(angle, axis); } inline Quat(const Matrix3 &m) { set(m); } inline Quat(double angle1, const Vector3& axis1, double angle2, const Vector3& axis2, --- 62,131 ---- public: + /// The identity Quat = (0,0,0,1) static const Quat IDENTITY; + /// The zero Quat = (0,0,0,0) static const Quat ZERO; ! /** ! * Serialize to a data archive. ! */ virtual void pack(Packer&) const; + + /** + * Deserialize from a data archive. + */ virtual void unpack(UnPacker&); + + /** + * Internal method used by the XML parser. + * + * The format for Quats is "X Y Z W" + */ virtual void parseXML(const char* cdata); /** ! * Standard representation string. */ std::string asString() const; + /** + * Construct a new quaternion. + * + * Initialize to (0,0,0,0) + */ inline Quat(): _x(0.0), _y(0.0), _z(0.0), _w(0.0) {} + + /** + * Construct a new quaternion. + * + * Specifiy the four real-valued components. + */ inline Quat(double x, double y, double z, double w): _x(x), _y(y), _z(z), _w(w) {} + + /** + * Construct a new quaternion representing a rotation. + * + * @param angle the rotation angle (right-handed) in radians. + * @param axis the rotation axis. + */ inline Quat(double angle, const Vector3& axis) { makeRotate(angle, axis); } + + /** + * Construct a new quaternion representing a rotation. + * + * @param m a matrix specifying the rotation. + */ inline Quat(const Matrix3 &m) { set(m); } + + /** + * Construct a new quaternion representing a product of three rotations. + * + * @param angle1 the first rotation angle (right-handed) in radians. + * @param axis1 the first rotation axis. + * @param angle2 the second rotation angle (right-handed) in radians. + * @param axis2 the second rotation axis. + * @param angle3 the third rotation angle (right-handed) in radians. + * @param axis3 the third rotation axis. + */ inline Quat(double angle1, const Vector3& axis1, double angle2, const Vector3& axis2, *************** *** 81,88 **** --- 135,148 ---- } + /** + * Return the 3-vector component of the quaternion (x,y,z) + */ inline const Vector3 asVector3() const { return Vector3(_x, _y, _z); } + /** + * Set the components. + */ inline void set(double x, double y, double z, double w) { _x = x; _y = y; _z = z; _w = w; *************** *** 90,93 **** --- 150,156 ---- #ifndef SWIG + /** + * Access a component by index (0,1,2,3 = x,y,z,w) + */ inline double& operator [] (int i) { switch (i) { *************** *** 100,103 **** --- 163,170 ---- } } + + /** + * Get a component value by index (0,1,2,3 = x,y,z,w) + */ inline double operator [] (int i) const { switch (i) { *************** *** 111,126 **** } inline double& x() { return _x; } inline double& y() { return _y; } inline double& z() { return _z; } inline double& w() { return _w; } inline double x() const { return _x; } inline double y() const { return _y; } inline double z() const { return _z; } inline double w() const { return _w; } #endif // SWIG ! /** return true if the Quat represents a zero rotation, and therefore can be ignored in computations.*/ bool zeroRotation() const { return _x==0.0 && _y==0.0 && _z==0.0 && _w==1.0; --- 178,205 ---- } + /// X component accessor inline double& x() { return _x; } + /// Y component accessor inline double& y() { return _y; } + /// Z component accessor inline double& z() { return _z; } + /// W component accessor inline double& w() { return _w; } + /// X component const accessor inline double x() const { return _x; } + /// Y component const accessor inline double y() const { return _y; } + /// Z component const accessor inline double z() const { return _z; } + /// W component const accessor inline double w() const { return _w; } #endif // SWIG ! /** ! * Test if the quaternion is zero. ! * ! * Zero rotations can generally be ignored in computations. ! */ bool zeroRotation() const { return _x==0.0 && _y==0.0 && _z==0.0 && _w==1.0; *************** *** 139,143 **** } ! /// Binary multiply --- adjusted relative to osg inline const Quat operator*(const Quat& rhs) const { return Quat(rhs._w*_x + rhs._x*_w - rhs._y*_z + rhs._z*_y, --- 218,222 ---- } ! /// Binary multiply --- adjusted relative to osg for active transformations! inline const Quat operator*(const Quat& rhs) const { return Quat(rhs._w*_x + rhs._x*_w - rhs._y*_z + rhs._z*_y, *************** *** 147,151 **** } ! /// Unary multiply --- adjusted relative to osg inline Quat& operator*=(const Quat& rhs) { double x = rhs._w*_x + rhs._x*_w - rhs._y*_z + rhs._z*_y; --- 226,230 ---- } ! /// Unary multiply --- adjusted relative to osg for active transformations! inline Quat& operator*=(const Quat& rhs) { double x = rhs._w*_x + rhs._x*_w - rhs._y*_z + rhs._z*_y; *************** *** 211,224 **** } ! /// Length of the quaternion = vec . vec double length2() const { return (_x*_x + _y*_y + _z*_z + _w*_w); } ! /// Conjugate ! inline Quat conj () const { return Quat(-_x, -_y, -_z, _w); } inline Quat operator ~() const { return Quat(-_x, -_y, -_z, _w); --- 290,304 ---- } ! /// Squared length of the quaternion = vec . vec double length2() const { return (_x*_x + _y*_y + _z*_z + _w*_w); } ! /// Get conjugate ! inline Quat conj() const { return Quat(-_x, -_y, -_z, _w); } + /// Get conjugate inline Quat operator ~() const { return Quat(-_x, -_y, -_z, _w); *************** *** 230,249 **** } void makeRotate(double angle, double x, double y, double z); void makeRotate(double angle, const Vector3& vec); void makeRotate(double angle1, const Vector3& axis1, double angle2, const Vector3& axis2, double angle3, const Vector3& axis3); ! /** Make a rotation Quat which will rotate vec1 to vec2. ! Generally take a dot product to get the angle between these ! and then use a cross product to get the rotation axis ! Watch out for the two special cases of when the vectors ! are co-incident or opposite in direction.*/ void makeRotate(const Vector3& vec1, const Vector3& vec2); void makeRotate(double roll, double pitch, double yaw); --- 310,358 ---- } + /** + * Set this Quat to represent a rotation about an axis. + * + * @param the angle of rotation (right-handed) in radians. + * @param x the x component of the rotation axis. + * @param y the y component of the rotation axis. + * @param z the z component of the rotation axis. + */ void makeRotate(double angle, double x, double y, double z); + /** + * Set this Quat to represent a rotation about an axis. + * + * @param the angle of rotation (right-handed) in radians. + * @param vec the rotation axis. + */ void makeRotate(double angle, const Vector3& vec); + /** + * Set this Quat to represent a product of three rotations. + * + * @param angle1 the first rotation angle (right-handed) in radians. + * @param axis1 the first rotation axis. + * @param angle2 the second rotation angle (right-handed) in radians. + * @param axis2 the second rotation axis. + * @param angle3 the third rotation angle (right-handed) in radians. + * @param axis3 the third rotation axis. + */ void makeRotate(double angle1, const Vector3& axis1, double angle2, const Vector3& axis2, double angle3, const Vector3& axis3); ! /** ! * Set this Quat to represent a rotation that transforms vec1 to vec2. ! */ void makeRotate(const Vector3& vec1, const Vector3& vec2); + /** + * Set this Quat to represent a rotation defined by Euler angles. + * + * @param roll The x-axis rotation angle (right-handed) in radians. + * @param pitch The y-axis rotation angle (right-handed) in radians. + * @param yaw The z-axis rotation angle (right-handed) in radians. + */ void makeRotate(double roll, double pitch, double yaw); Index: Random.h =================================================================== RCS file: /cvsroot/csp/APPLICATIONS/SimData/Include/SimData/Random.h,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** Random.h 6 Aug 2003 08:56:54 -0000 1.9 --- Random.h 7 Aug 2003 17:37:20 -0000 1.10 *************** *** 91,95 **** * The period of this generator is 2^{19937} - 1. */ ! class MT19937 { static const int N = 624; /* Period parameters */ static const int M = 397; --- 91,95 ---- * The period of this generator is 2^{19937} - 1. */ ! class SIMDATA_EXPORT MT19937 { static const int N = 624; /* Period parameters */ static const int M = 397; *************** *** 274,278 **** * */ ! class Taus2 { // state unsigned long int _s1, _s2, _s3; --- 274,278 ---- * */ ! class SIMDATA_EXPORT Taus2 { // state unsigned long int _s1, _s2, _s3; *************** *** 385,389 **** * Abstract interface for random number generators and random distributions. */ ! class RandomInterface { protected: struct _State: Referenced { }; --- 385,389 ---- * Abstract interface for random number generators and random distributions. */ ! class SIMDATA_EXPORT RandomInterface { protected: struct _State: Referenced { }; *************** *** 402,406 **** * Abstract interface for random number generators. */ ! class RandomNumberGeneratorInterface: public RandomInterface { public: virtual double unit()=0; --- 402,406 ---- * Abstract interface for random number generators. */ ! class SIMDATA_EXPORT RandomNumberGeneratorInterface: public RandomInterface { public: virtual double unit()=0; *************** *** 420,424 **** */ template <class RNG> ! class RandomNumberGenerator: public RandomNumberGeneratorInterface { struct RNGState: _State { typename RNG::State _state; --- 420,424 ---- */ template <class RNG> ! class SIMDATA_EXPORT RandomNumberGenerator: public RandomNumberGeneratorInterface { struct RNGState: _State { typename RNG::State _state; *************** *** 554,558 **** namespace rd { // random distributions ! class Gauss { rng::Taus2 _gen; double _mean, _sigma; --- 554,558 ---- namespace rd { // random distributions ! class SIMDATA_EXPORT Gauss { rng::Taus2 _gen; double _mean, _sigma; *************** *** 641,645 **** * Abstract interface for random distributions. */ ! class RandomDistributionInterface: public RandomInterface { public: virtual double sample()=0; --- 641,645 ---- * Abstract interface for random distributions. */ ! class SIMDATA_EXPORT RandomDistributionInterface: public RandomInterface { public: virtual double sample()=0; *************** *** 654,658 **** */ template <class RD> ! class RandomDistribution: public RandomDistributionInterface { struct RDState: _State { typename RD::State _state; --- 654,658 ---- */ template <class RD> ! class SIMDATA_EXPORT RandomDistribution: public RandomDistributionInterface { struct RDState: _State { typename RD::State _state; *************** *** 740,744 **** * Global random number generator. */ ! SIMDATA_EXPORT extern random::Taus2 g_Random; --- 740,744 ---- * Global random number generator. */ ! extern SIMDATA_EXPORT random::Taus2 g_Random; Index: osg.h =================================================================== RCS file: /cvsroot/csp/APPLICATIONS/SimData/Include/SimData/osg.h,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** osg.h 6 Aug 2003 06:36:25 -0000 1.3 --- osg.h 7 Aug 2003 17:37:20 -0000 1.4 *************** *** 50,64 **** } inline osg::Matrix toOSG(Matrix3 const &m) { ! return osg::Matrix(m(0, 0), m(0, 1), m(0, 2), 0.0, ! m(1, 0), m(1, 1), m(1, 2), 0.0, ! m(2, 0), m(2, 1), m(2, 2), 0.0, 0.0, 0.0, 0.0, 1.0); } inline Matrix3 fromOSG(osg::Matrix const &m) { ! return Matrix3(m(0, 0), m(0, 1), m(0, 2), ! m(1, 0), m(1, 1), m(1, 2), ! m(2, 0), m(2, 1), m(2, 2)); } --- 50,66 ---- } + // transpose: osg matrix convension is v * M inline osg::Matrix toOSG(Matrix3 const &m) { ! return osg::Matrix(m(0, 0), m(1, 0), m(2, 0), 0.0, ! m(0, 1), m(1, 1), m(2, 1), 0.0, ! m(0, 2), m(1, 2), m(2, 2), 0.0, 0.0, 0.0, 0.0, 1.0); } + // transpose: osg matrix convension is v * M inline Matrix3 fromOSG(osg::Matrix const &m) { ! return Matrix3(m(0, 0), m(1, 0), m(2, 0), ! m(0, 1), m(1, 1), m(2, 1), ! m(0, 2), m(1, 2), m(2, 2)); } |