Annotation of /linden_release/linden/indra/llmath/llcoordframe.h
Parent Directory
|
Revision Log
Revision 57 - (view) (download)
| 1 : | mjm | 57 | /** |
| 2 : | * @file llcoordframe.h | ||
| 3 : | * @brief LLCoordFrame class header file. | ||
| 4 : | * | ||
| 5 : | * $LicenseInfo:firstyear=2000&license=viewergpl$ | ||
| 6 : | * | ||
| 7 : | * Copyright (c) 2000-2008, Linden Research, Inc. | ||
| 8 : | * | ||
| 9 : | * Second Life Viewer Source Code | ||
| 10 : | * The source code in this file ("Source Code") is provided by Linden Lab | ||
| 11 : | * to you under the terms of the GNU General Public License, version 2.0 | ||
| 12 : | * ("GPL"), unless you have obtained a separate licensing agreement | ||
| 13 : | * ("Other License"), formally executed by you and Linden Lab. Terms of | ||
| 14 : | * the GPL can be found in doc/GPL-license.txt in this distribution, or | ||
| 15 : | * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2 | ||
| 16 : | * | ||
| 17 : | * There are special exceptions to the terms and conditions of the GPL as | ||
| 18 : | * it is applied to this Source Code. View the full text of the exception | ||
| 19 : | * in the file doc/FLOSS-exception.txt in this software distribution, or | ||
| 20 : | * online at http://secondlifegrid.net/programs/open_source/licensing/flossexception | ||
| 21 : | * | ||
| 22 : | * By copying, modifying or distributing this software, you acknowledge | ||
| 23 : | * that you have read and understood your obligations described above, | ||
| 24 : | * and agree to abide by those obligations. | ||
| 25 : | * | ||
| 26 : | * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO | ||
| 27 : | * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, | ||
| 28 : | * COMPLETENESS OR PERFORMANCE. | ||
| 29 : | * $/LicenseInfo$ | ||
| 30 : | */ | ||
| 31 : | |||
| 32 : | #ifndef LL_COORDFRAME_H | ||
| 33 : | #define LL_COORDFRAME_H | ||
| 34 : | |||
| 35 : | #include "v3math.h" | ||
| 36 : | #include "v4math.h" | ||
| 37 : | #include "llerror.h" | ||
| 38 : | |||
| 39 : | // XXX : The constructors of the LLCoordFrame class assume that all vectors | ||
| 40 : | // and quaternion being passed as arguments are normalized, and all matrix | ||
| 41 : | // arguments are unitary. VERY BAD things will happen if these assumptions fail. | ||
| 42 : | // Also, segfault hazzards exist in methods that accept F32* arguments. | ||
| 43 : | |||
| 44 : | |||
| 45 : | class LLCoordFrame | ||
| 46 : | { | ||
| 47 : | public: | ||
| 48 : | LLCoordFrame(); // Inits at zero with identity rotation | ||
| 49 : | explicit LLCoordFrame(const LLVector3 &origin); // Sets origin, and inits rotation = Identity | ||
| 50 : | LLCoordFrame(const LLVector3 &x_axis, | ||
| 51 : | const LLVector3 &y_axis, | ||
| 52 : | const LLVector3 &z_axis); // Sets coordinate axes and inits origin at zero | ||
| 53 : | LLCoordFrame(const LLVector3 &origin, | ||
| 54 : | const LLVector3 &x_axis, | ||
| 55 : | const LLVector3 &y_axis, | ||
| 56 : | const LLVector3 &z_axis); // Sets the origin and coordinate axes | ||
| 57 : | LLCoordFrame(const LLVector3 &origin, | ||
| 58 : | const LLMatrix3 &rotation); // Sets axes to 3x3 matrix | ||
| 59 : | LLCoordFrame(const LLVector3 &origin, | ||
| 60 : | const LLVector3 &direction); // Sets origin and calls lookDir(direction) | ||
| 61 : | explicit LLCoordFrame(const LLQuaternion &q); // Sets axes using q and inits mOrigin to zero | ||
| 62 : | LLCoordFrame(const LLVector3 &origin, | ||
| 63 : | const LLQuaternion &q); // Uses quaternion to init axes | ||
| 64 : | explicit LLCoordFrame(const LLMatrix4 &mat); // Extracts frame from a 4x4 matrix | ||
| 65 : | // The folowing two constructors are dangerous due to implicit casting and have been disabled - SJB | ||
| 66 : | //LLCoordFrame(const F32 *origin, const F32 *rotation); // Assumes "origin" is 1x3 and "rotation" is 1x9 array | ||
| 67 : | //LLCoordFrame(const F32 *origin_and_rotation); // Assumes "origin_and_rotation" is 1x12 array | ||
| 68 : | |||
| 69 : | BOOL isFinite() { return mOrigin.isFinite() && mXAxis.isFinite() && mYAxis.isFinite() && mZAxis.isFinite(); } | ||
| 70 : | |||
| 71 : | void reset(); | ||
| 72 : | void resetAxes(); | ||
| 73 : | |||
| 74 : | void setOrigin(F32 x, F32 y, F32 z); // Set mOrigin | ||
| 75 : | void setOrigin(const LLVector3 &origin); | ||
| 76 : | void setOrigin(const F32 *origin); | ||
| 77 : | void setOrigin(const LLCoordFrame &frame); | ||
| 78 : | |||
| 79 : | inline void setOriginX(F32 x) { mOrigin.mV[VX] = x; } | ||
| 80 : | inline void setOriginY(F32 y) { mOrigin.mV[VY] = y; } | ||
| 81 : | inline void setOriginZ(F32 z) { mOrigin.mV[VZ] = z; } | ||
| 82 : | |||
| 83 : | void setAxes(const LLVector3 &x_axis, // Set axes | ||
| 84 : | const LLVector3 &y_axis, | ||
| 85 : | const LLVector3 &z_axis); | ||
| 86 : | void setAxes(const LLMatrix3 &rotation_matrix); | ||
| 87 : | void setAxes(const LLQuaternion &q); | ||
| 88 : | void setAxes(const F32 *rotation_matrix); | ||
| 89 : | void setAxes(const LLCoordFrame &frame); | ||
| 90 : | |||
| 91 : | void translate(F32 x, F32 y, F32 z); // Move mOrgin | ||
| 92 : | void translate(const LLVector3 &v); | ||
| 93 : | void translate(const F32 *origin); | ||
| 94 : | |||
| 95 : | void rotate(F32 angle, F32 x, F32 y, F32 z); // Move axes | ||
| 96 : | void rotate(F32 angle, const LLVector3 &rotation_axis); | ||
| 97 : | void rotate(const LLQuaternion &q); | ||
| 98 : | void rotate(const LLMatrix3 &m); | ||
| 99 : | |||
| 100 : | void orthonormalize(); // Makes sure axes are unitary and orthogonal. | ||
| 101 : | |||
| 102 : | // These methods allow rotations in the LLCoordFrame's frame | ||
| 103 : | void roll(F32 angle); // RH rotation about mXAxis, radians | ||
| 104 : | void pitch(F32 angle); // RH rotation about mYAxis, radians | ||
| 105 : | void yaw(F32 angle); // RH rotation about mZAxis, radians | ||
| 106 : | |||
| 107 : | inline const LLVector3 &getOrigin() const { return mOrigin; } | ||
| 108 : | |||
| 109 : | inline const LLVector3 &getXAxis() const { return mXAxis; } | ||
| 110 : | inline const LLVector3 &getYAxis() const { return mYAxis; } | ||
| 111 : | inline const LLVector3 &getZAxis() const { return mZAxis; } | ||
| 112 : | |||
| 113 : | inline const LLVector3 &getAtAxis() const { return mXAxis; } | ||
| 114 : | inline const LLVector3 &getLeftAxis() const { return mYAxis; } | ||
| 115 : | inline const LLVector3 &getUpAxis() const { return mZAxis; } | ||
| 116 : | |||
| 117 : | // These return representations of the rotation or orientation of the LLFrame | ||
| 118 : | // it its absolute frame. That is, these rotations acting on the X-axis {1,0,0} | ||
| 119 : | // will produce the mXAxis. | ||
| 120 : | // LLMatrix3 getMatrix3() const; // Returns axes in 3x3 matrix | ||
| 121 : | LLQuaternion getQuaternion() const; // Returns axes in quaternion form | ||
| 122 : | |||
| 123 : | // Same as above, except it also includes the translation of the LLFrame | ||
| 124 : | // LLMatrix4 getMatrix4() const; // Returns position and axes in 4x4 matrix | ||
| 125 : | |||
| 126 : | // Returns matrix which expresses point in local frame in the parent frame | ||
| 127 : | void getMatrixToParent(LLMatrix4 &mat) const; | ||
| 128 : | // Returns matrix which expresses point in parent frame in the local frame | ||
| 129 : | void getMatrixToLocal(LLMatrix4 &mat) const; // Returns matrix which expresses point in parent frame in the local frame | ||
| 130 : | |||
| 131 : | void getRotMatrixToParent(LLMatrix4 &mat) const; | ||
| 132 : | |||
| 133 : | // Copies mOrigin, then the three axes to buffer, returns number of bytes copied. | ||
| 134 : | size_t writeOrientation(char *buffer) const; | ||
| 135 : | |||
| 136 : | // Copies mOrigin, then the three axes from buffer, returns the number of bytes copied. | ||
| 137 : | // Assumes the data in buffer is correct. | ||
| 138 : | size_t readOrientation(const char *buffer); | ||
| 139 : | |||
| 140 : | LLVector3 rotateToLocal(const LLVector3 &v) const; // Returns v' rotated to local | ||
| 141 : | LLVector4 rotateToLocal(const LLVector4 &v) const; // Returns v' rotated to local | ||
| 142 : | LLVector3 rotateToAbsolute(const LLVector3 &v) const; // Returns v' rotated to absolute | ||
| 143 : | LLVector4 rotateToAbsolute(const LLVector4 &v) const; // Returns v' rotated to absolute | ||
| 144 : | |||
| 145 : | LLVector3 transformToLocal(const LLVector3 &v) const; // Returns v' in local coord | ||
| 146 : | LLVector4 transformToLocal(const LLVector4 &v) const; // Returns v' in local coord | ||
| 147 : | LLVector3 transformToAbsolute(const LLVector3 &v) const; // Returns v' in absolute coord | ||
| 148 : | LLVector4 transformToAbsolute(const LLVector4 &v) const; // Returns v' in absolute coord | ||
| 149 : | |||
| 150 : | // Write coord frame orientation into provided array in OpenGL matrix format. | ||
| 151 : | void getOpenGLTranslation(F32 *ogl_matrix) const; | ||
| 152 : | void getOpenGLRotation(F32 *ogl_matrix) const; | ||
| 153 : | void getOpenGLTransform(F32 *ogl_matrix) const; | ||
| 154 : | |||
| 155 : | // lookDir orients to (xuv, presumed normalized) and does not affect origin | ||
| 156 : | void lookDir(const LLVector3 &xuv, const LLVector3 &up); | ||
| 157 : | void lookDir(const LLVector3 &xuv); // up = 0,0,1 | ||
| 158 : | // lookAt orients to (point_of_interest - origin) and sets origin | ||
| 159 : | void lookAt(const LLVector3 &origin, const LLVector3 &point_of_interest, const LLVector3 &up); | ||
| 160 : | void lookAt(const LLVector3 &origin, const LLVector3 &point_of_interest); // up = 0,0,1 | ||
| 161 : | |||
| 162 : | // deprecated | ||
| 163 : | void setOriginAndLookAt(const LLVector3 &origin, const LLVector3 &up, const LLVector3 &point_of_interest) | ||
| 164 : | { | ||
| 165 : | lookAt(origin, point_of_interest, up); | ||
| 166 : | } | ||
| 167 : | |||
| 168 : | friend std::ostream& operator<<(std::ostream &s, const LLCoordFrame &C); | ||
| 169 : | |||
| 170 : | // These vectors are in absolute frame | ||
| 171 : | LLVector3 mOrigin; | ||
| 172 : | LLVector3 mXAxis; | ||
| 173 : | LLVector3 mYAxis; | ||
| 174 : | LLVector3 mZAxis; | ||
| 175 : | }; | ||
| 176 : | |||
| 177 : | |||
| 178 : | #endif | ||
| 179 : |
| ViewVC Help | |
| Powered by ViewVC 1.0.0 |

