llcoordframe.h

Go to the documentation of this file.
00001 
00032 #ifndef LL_COORDFRAME_H
00033 #define LL_COORDFRAME_H
00034 
00035 #include "v3math.h"
00036 #include "v4math.h"
00037 #include "llerror.h"
00038 
00039 // XXX : The constructors of the LLCoordFrame class assume that all vectors
00040 //               and quaternion being passed as arguments are normalized, and all matrix 
00041 //               arguments are unitary.  VERY BAD things will happen if these assumptions fail.
00042 //               Also, segfault hazzards exist in methods that accept F32* arguments.
00043 
00044 
00045 class LLCoordFrame 
00046 {
00047 public:
00048         LLCoordFrame();                                                                                 // Inits at zero with identity rotation
00049         explicit LLCoordFrame(const LLVector3 &origin);                 // Sets origin, and inits rotation = Identity
00050         LLCoordFrame(const LLVector3 &x_axis, 
00051                                  const LLVector3 &y_axis, 
00052                                  const LLVector3 &z_axis);                                      // Sets coordinate axes and inits origin at zero
00053         LLCoordFrame(const LLVector3 &origin, 
00054                                  const LLVector3 &x_axis, 
00055                                  const LLVector3 &y_axis, 
00056                                  const LLVector3 &z_axis);                                      // Sets the origin and coordinate axes
00057         LLCoordFrame(const LLVector3 &origin, 
00058                                  const LLMatrix3 &rotation);                            // Sets axes to 3x3 matrix
00059         LLCoordFrame(const LLVector3 &origin, 
00060                                  const LLVector3 &direction);                           // Sets origin and calls lookDir(direction)
00061         explicit LLCoordFrame(const LLQuaternion &q);                   // Sets axes using q and inits mOrigin to zero 
00062         LLCoordFrame(const LLVector3 &origin, 
00063                                  const LLQuaternion &q);                                        // Uses quaternion to init axes
00064         explicit LLCoordFrame(const LLMatrix4 &mat);                    // Extracts frame from a 4x4 matrix
00065         // The folowing two constructors are dangerous due to implicit casting and have been disabled - SJB
00066         //LLCoordFrame(const F32 *origin, const F32 *rotation); // Assumes "origin" is 1x3 and "rotation" is 1x9 array
00067         //LLCoordFrame(const F32 *origin_and_rotation);                 // Assumes "origin_and_rotation" is 1x12 array
00068 
00069         BOOL isFinite() { return mOrigin.isFinite() && mXAxis.isFinite() && mYAxis.isFinite() && mZAxis.isFinite(); }
00070 
00071         void reset();
00072         void resetAxes();
00073 
00074         void setOrigin(F32 x, F32 y, F32 z);                                    // Set mOrigin
00075         void setOrigin(const LLVector3 &origin);
00076         void setOrigin(const F32 *origin);
00077         void setOrigin(const LLCoordFrame &frame);
00078 
00079         inline void setOriginX(F32 x) { mOrigin.mV[VX] = x; }
00080         inline void setOriginY(F32 y) { mOrigin.mV[VY] = y; }
00081         inline void setOriginZ(F32 z) { mOrigin.mV[VZ] = z; }
00082 
00083         void setAxes(const LLVector3 &x_axis,                                   // Set axes
00084                                  const LLVector3 &y_axis, 
00085                                  const LLVector3 &z_axis);
00086         void setAxes(const LLMatrix3 &rotation_matrix);
00087         void setAxes(const LLQuaternion &q);
00088         void setAxes(const F32 *rotation_matrix);
00089         void setAxes(const LLCoordFrame &frame);
00090 
00091         void translate(F32 x, F32 y, F32 z);                                    // Move mOrgin
00092         void translate(const LLVector3 &v);
00093         void translate(const F32 *origin);
00094 
00095         void rotate(F32 angle, F32 x, F32 y, F32 z);                    // Move axes
00096         void rotate(F32 angle, const LLVector3 &rotation_axis);
00097         void rotate(const LLQuaternion &q);
00098         void rotate(const LLMatrix3 &m);
00099 
00100         void orthonormalize();  // Makes sure axes are unitary and orthogonal.
00101 
00102         // These methods allow rotations in the LLCoordFrame's frame
00103         void roll(F32 angle);           // RH rotation about mXAxis, radians
00104         void pitch(F32 angle);          // RH rotation about mYAxis, radians
00105         void yaw(F32 angle);            // RH rotation about mZAxis, radians
00106 
00107         inline const LLVector3 &getOrigin() const { return mOrigin; }
00108 
00109         inline const LLVector3 &getXAxis() const  { return mXAxis; }
00110         inline const LLVector3 &getYAxis() const  { return mYAxis; }
00111         inline const LLVector3 &getZAxis() const  { return mZAxis; }
00112 
00113         inline const LLVector3 &getAtAxis() const   { return mXAxis; }
00114         inline const LLVector3 &getLeftAxis() const { return mYAxis; }
00115         inline const LLVector3 &getUpAxis() const   { return mZAxis; }
00116         
00117         // These return representations of the rotation or orientation of the LLFrame
00118         // it its absolute frame.  That is, these rotations acting on the X-axis {1,0,0}
00119         // will produce the mXAxis.
00120         //              LLMatrix3 getMatrix3() const;                           // Returns axes in 3x3 matrix 
00121         LLQuaternion getQuaternion() const;                     // Returns axes in quaternion form
00122 
00123         // Same as above, except it also includes the translation of the LLFrame
00124         //              LLMatrix4 getMatrix4() const;                           // Returns position and axes in 4x4 matrix
00125 
00126         // Returns matrix which expresses point in local frame in the parent frame
00127         void getMatrixToParent(LLMatrix4 &mat) const;
00128         // Returns matrix which expresses point in parent frame in the local frame
00129         void getMatrixToLocal(LLMatrix4 &mat) const; // Returns matrix which expresses point in parent frame in the local frame
00130 
00131         void getRotMatrixToParent(LLMatrix4 &mat) const;
00132 
00133         // Copies mOrigin, then the three axes to buffer, returns number of bytes copied.
00134         size_t writeOrientation(char *buffer) const;
00135                 
00136         // Copies mOrigin, then the three axes from buffer, returns the number of bytes copied.
00137         // Assumes the data in buffer is correct.
00138         size_t readOrientation(const char *buffer);
00139 
00140         LLVector3 rotateToLocal(const LLVector3 &v) const;              // Returns v' rotated to local
00141         LLVector4 rotateToLocal(const LLVector4 &v) const;              // Returns v' rotated to local
00142         LLVector3 rotateToAbsolute(const LLVector3 &v) const;   // Returns v' rotated to absolute
00143         LLVector4 rotateToAbsolute(const LLVector4 &v) const;   // Returns v' rotated to absolute
00144 
00145         LLVector3 transformToLocal(const LLVector3 &v) const;           // Returns v' in local coord
00146         LLVector4 transformToLocal(const LLVector4 &v) const;           // Returns v' in local coord
00147         LLVector3 transformToAbsolute(const LLVector3 &v) const;        // Returns v' in absolute coord
00148         LLVector4 transformToAbsolute(const LLVector4 &v) const;        // Returns v' in absolute coord
00149 
00150         // Write coord frame orientation into provided array in OpenGL matrix format.
00151         void getOpenGLTranslation(F32 *ogl_matrix) const;
00152         void getOpenGLRotation(F32 *ogl_matrix) const;
00153         void getOpenGLTransform(F32 *ogl_matrix) const;
00154 
00155         // lookDir orients to (xuv, presumed normalized) and does not affect origin
00156         void lookDir(const LLVector3 &xuv, const LLVector3 &up);
00157         void lookDir(const LLVector3 &xuv); // up = 0,0,1
00158         // lookAt orients to (point_of_interest - origin) and sets origin
00159         void lookAt(const LLVector3 &origin, const LLVector3 &point_of_interest, const LLVector3 &up);
00160         void lookAt(const LLVector3 &origin, const LLVector3 &point_of_interest); // up = 0,0,1
00161 
00162         // deprecated
00163         void setOriginAndLookAt(const LLVector3 &origin, const LLVector3 &up, const LLVector3 &point_of_interest)
00164         {
00165                 lookAt(origin, point_of_interest, up);
00166         }
00167         
00168         friend std::ostream& operator<<(std::ostream &s, const LLCoordFrame &C);
00169 
00170         // These vectors are in absolute frame
00171         LLVector3 mOrigin;
00172         LLVector3 mXAxis;
00173         LLVector3 mYAxis;
00174         LLVector3 mZAxis;
00175 };
00176 
00177 
00178 #endif
00179 

Generated on Thu Jul 1 06:08:23 2010 for Second Life Viewer by  doxygen 1.4.7