Main Page | Class Hierarchy | Class List | File List | Class Members

Linear.h

00001 /**************************************************************************\ 00002 * 00003 * FILE: Linear.h 00004 * 00005 * This source file is part of DIME. 00006 * Copyright (C) 1998-1999 by Systems In Motion. All rights reserved. 00007 * 00008 * This library is free software; you can redistribute it and/or modify it 00009 * under the terms of the GNU General Public License, version 2, as 00010 * published by the Free Software Foundation. 00011 * 00012 * This library is distributed in the hope that it will be useful, but 00013 * WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00015 * General Public License (the accompanying file named COPYING) for more 00016 * details. 00017 * 00018 ************************************************************************** 00019 * 00020 * If you need DIME for a non-GPL project, contact Systems In Motion 00021 * to acquire a Professional Edition License: 00022 * 00023 * Systems In Motion http://www.sim.no/ 00024 * Prof. Brochs gate 6 sales@sim.no 00025 * N-7030 Trondheim Voice: +47 22114160 00026 * NORWAY Fax: +47 67172912 00027 * 00028 \**************************************************************************/ 00029 00030 #ifndef DIME_LINEAR_H 00031 #define DIME_LINEAR_H 00032 00033 #include <dime/Basic.h> 00034 #include <stdio.h> 00035 #include <stdlib.h> 00036 #include <math.h> 00037 00038 class DIME_DLL_API dimeVec2f 00039 { 00040 public: 00041 dimeVec2f() {} 00042 dimeVec2f(const dimeVec2f &vec) {x = vec.x; y = vec.y;} 00043 dimeVec2f(dxfdouble _x, dxfdouble _y) {x = _x; y = _y;} 00044 void setValue(const dxfdouble _x, const dxfdouble _y) {x = _x; y = _y;} 00045 00046 //dxfdouble operator [] (const int i) const 00047 //{ return (i==0?x:y); } 00048 // dxfdouble & operator [] (const int i) 00049 //{ return(i==0?x:y);} 00050 void print() const { printf("Coord2: (%.3f, %.3f)\n", x,y);} 00051 void print(const char *s) {printf("%s: (%.3f, %.3f)\n", s,x,y);} 00052 dxfdouble x,y; 00053 00054 }; // class dimeVec2f 00055 00056 class DIME_DLL_API dimeVec3f 00057 { 00058 public: 00059 dxfdouble x, y, z; 00060 00061 dimeVec3f(void) {}; 00062 dimeVec3f(const dxfdouble X, const dxfdouble Y, const dxfdouble Z) 00063 { x=X; y=Y; z=Z; }; 00064 dimeVec3f(const dxfdouble *xyz) 00065 { x = xyz[0]; y = xyz[1]; z = xyz[2]; } 00066 dimeVec3f (const dimeVec3f& v) 00067 { x=v.x; y=v.y; z=v.z; }; 00068 dimeVec3f cross(const dimeVec3f &v) const 00069 { return dimeVec3f(y*v.z-z*v.y, z*v.x-x*v.z, x*v.y-y*v.x); } 00070 dxfdouble dot(const dimeVec3f &v) const 00071 { return x*v.x+y*v.y+z*v.z; } 00072 00073 bool equals(const dimeVec3f &v) 00074 { return (x == v.x && y == v.y && z == v.z); } 00075 bool equals(const dimeVec3f &v, dxfdouble tol) 00076 { return (fabs(x-v.x) <= tol && fabs(y-v.y) <= tol && fabs(z-v.z) <= tol); } 00077 00078 operator dxfdouble *() { return &x; } 00079 const dxfdouble *getValue() const { return &x; } 00080 void getValue(dxfdouble &_x, dxfdouble &_y, dxfdouble &_z) const 00081 { _x = x; _y = y; _z = z;} 00082 dxfdouble length() const 00083 { return (dxfdouble) sqrt(x*x+y*y+z*z); } 00084 dxfdouble sqrLength(void) const 00085 { return x*x+y*y+z*z; } 00086 void negate(void) 00087 { x = -x; y = -y; z = -z; } 00088 void setValue(const dxfdouble *v) 00089 { x = v[0]; y = v[1]; z = v[2]; } 00090 void setValue(const dxfdouble X, const dxfdouble Y, const dxfdouble Z) 00091 { x=X; y=Y; z=Z; } 00092 00093 dxfdouble operator [] (const int i) const 00094 { return( (i==0)?x:((i==1)?y:z) ); }; 00095 dxfdouble & operator [] (const int i) 00096 { return( (i==0)?x:((i==1)?y:z) ); }; 00097 00098 dimeVec3f &operator *= (const dxfdouble s) 00099 { x*=s; y*=s; z*=s; return *this; } 00100 dimeVec3f &operator /= (const dxfdouble s) 00101 { x/=s; y/=s; z/=s; return *this; } 00102 dimeVec3f &operator += (const dimeVec3f &v) 00103 { x+=v.x; y+=v.y; z+=v.z; return *this; } 00104 dimeVec3f &operator -= (const dimeVec3f &v) 00105 { x-=v.x; y-=v.y; z-=v.z; return *this;} 00106 dimeVec3f operator -() const 00107 { return dimeVec3f(-x, -y, -z); } 00108 friend dimeVec3f operator *(const dimeVec3f &v, dxfdouble s) 00109 { return dimeVec3f(v.x*s, v.y*s, v.z*s); } 00110 friend dimeVec3f operator *(dxfdouble s, const dimeVec3f &v) 00111 { return dimeVec3f(v.x*s, v.y*s, v.z*s); } 00112 friend dimeVec3f operator / (const dimeVec3f &v, dxfdouble s) 00113 { return dimeVec3f(v.x/s, v.y/s, v.z/s); } 00114 friend dimeVec3f operator + (const dimeVec3f &v1, const dimeVec3f &v2) 00115 { return dimeVec3f(v1.x+v2.x, v1.y+v2.y, v1.z+v2.z); } 00116 friend dimeVec3f operator - (const dimeVec3f &v1, const dimeVec3f &v2) 00117 { return dimeVec3f(v1.x-v2.x, v1.y-v2.y, v1.z-v2.z); } 00118 00119 friend bool operator ==(const dimeVec3f &v1, const dimeVec3f &v2) 00120 { return (v1.x == v2.x && v1.y == v2.y && v1.z == v2.z); } 00121 friend bool operator !=(const dimeVec3f &v1, const dimeVec3f &v2) 00122 { return (v1.x != v2.x || v1.y != v2.y || v1.z != v2.z); } 00123 00124 dimeVec3f& operator = (const dimeVec3f &v) // extra 00125 { x=v.x; y=v.y; z=v.z; return *this; } 00126 00127 void multMatrix(dxfdouble *matrix) // extra 00128 { 00129 dxfdouble tx, ty, tz; 00130 tx = ty = tz = 0.0f; 00131 tx = matrix[0]*x+matrix[1]*y+matrix[2]*z; 00132 ty = matrix[4]*x+matrix[5]*y+matrix[6]*z; 00133 tz = matrix[8]*x+matrix[9]*y+matrix[10]*z; 00134 x = tx, y = ty, z = tz; 00135 } 00136 00137 void print() const // extra 00138 { printf("dimeVec3f: (%.3f, %.3f, %.3f)\n",x, y, z); } 00139 void print(const char *s) const 00140 { printf("%s: (%.3f, %.3f, %.3f)\n",s, x, y, z); } 00141 00142 00143 dimeVec3f multComponents(const dimeVec3f &v) const 00144 { return dimeVec3f(x*v.x, y*v.y, z*v.z); } 00145 00146 dxfdouble angle(const dimeVec3f &v2); 00147 void normalize(); 00148 00149 }; // class dimeVec3f 00150 00151 class DIME_DLL_API dimeMatrix 00152 { 00153 public: 00154 dimeMatrix() {} 00155 dimeMatrix(const dimeMatrix &matrix); 00156 // Constructor given all 16 elements in row-major order 00157 dimeMatrix(dxfdouble a11, dxfdouble a12, dxfdouble a13, dxfdouble a14, 00158 dxfdouble a21, dxfdouble a22, dxfdouble a23, dxfdouble a24, 00159 dxfdouble a31, dxfdouble a32, dxfdouble a33, dxfdouble a34, 00160 dxfdouble a41, dxfdouble a42, dxfdouble a43, dxfdouble a44); 00161 void transpose(); 00162 void makeIdentity(); 00163 bool isIdentity() const; 00164 void setTransform(const dimeVec3f &translation, 00165 const dimeVec3f &scalefactor, 00166 const dimeVec3f &rotAngles); 00167 dimeMatrix &multRight(const dimeMatrix &m); // this = this * m 00168 dimeMatrix &multLeft(const dimeMatrix &m); // this = m * this 00169 00170 // Sets matrix to rotate by given rotation 00171 void setRotate(const dimeVec3f &rot); 00172 00173 void setRotate(const dimeVec3f &x, const dimeVec3f &y, const dimeVec3f &z); 00174 00175 // sets matrix to rotate around given vector 00176 void setRotation(const dimeVec3f &u, const dxfdouble angle); 00177 00178 // Sets matrix to scale by given uniform factor 00179 void setScale(const dxfdouble s); 00180 00181 // Sets matrix to scale by given vector 00182 void setScale(const dimeVec3f &s); 00183 00184 // Sets matrix to translate by given vector 00185 void setTranslate(const dimeVec3f &t); 00186 00187 // Multiplies matrix by given column vector, giving vector result 00188 void multMatrixVec(const dimeVec3f &src, dimeVec3f &dst) const; 00189 00190 // transforms vector 00191 void multMatrixVec(dimeVec3f &vec) const; 00192 00193 // Multiplies given row vector by matrix, giving vector result 00194 //void multVecMatrix(const dimeVec3f &src, dimeVec3f &dst) const; 00195 00196 // Cast: returns pointer to storage of first element 00197 operator dxfdouble *() { return &matrix[0][0]; } 00198 00199 // Make it look like a usual matrix (so you can do m[3][2]) 00200 dxfdouble *operator [](int i) { return &matrix[i][0]; } 00201 const dxfdouble * operator [](int i) const { return &matrix[i][0];} 00202 00203 dimeMatrix &operator =(const dimeMatrix &m); 00204 00205 // Performs right multiplication with another matrix 00206 dimeMatrix &operator *=(const dimeMatrix &m) { return multRight(m); } 00207 00208 00209 static dimeMatrix identity(); 00210 bool inverse(); 00211 bool inverse2(); 00212 dxfdouble determinant(const int i=-2, const int j=-1); 00213 00214 void operator *=(const dxfdouble val); 00215 00216 private: 00217 dxfdouble matrix[4][4]; 00218 00219 }; // class dimeMatrix 00220 00221 #endif // ! DIME_LINEAR_H 00222

Copyright © 1998-1999, Systems In Motion <sales@sim.no>. All rights reserved.
System documentation was generated using doxygen.