Main Page | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Namespace Members | Compound Members | File Members

OrientedBox.h

Go to the documentation of this file.
00001 //------------------------------------------------------------------------------
00002 // Lamp : Open source game middleware
00003 // Copyright (C) 2004  Junpei Ohtani ( Email : junpee@users.sourceforge.jp )
00004 //
00005 // This library is free software; you can redistribute it and/or
00006 // modify it under the terms of the GNU Lesser General Public
00007 // License as published by the Free Software Foundation; either
00008 // version 2.1 of the License, or (at your option) any later version.
00009 //
00010 // This library is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013 // Lesser General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU Lesser General Public
00016 // License along with this library; if not, write to the Free Software
00017 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018 //------------------------------------------------------------------------------
00019 
00020 /** @file
00021  * 指向性ボックスヘッダ
00022  * @author Junpee
00023  */
00024 
00025 #ifndef ORIENTED_BOX_H_
00026 #define ORIENTED_BOX_H_
00027 
00028 #include <Core/Primitive/Vector3.h>
00029 #include <Core/Primitive/Matrix33.h>
00030 #include <Core/Primitive/Matrix34.h>
00031 #include <Core/Primitive/Matrix44.h>
00032 
00033 namespace Lamp{
00034 
00035 class AxisAlignedBox;
00036 class Capsule;
00037 class Cone;
00038 class Line;
00039 class Plane;
00040 class Ray;
00041 class Segment;
00042 class Sphere;
00043 class Triangle;
00044 
00045 //------------------------------------------------------------------------------
00046 /**
00047  * 指向性ボックス
00048  *
00049  * このクラスは継承しないで下さい。
00050  */
00051 class OrientedBox{
00052 public:
00053     //--------------------------------------------------------------------------
00054     // 定数
00055     //--------------------------------------------------------------------------
00056     /// ゼロボックス
00057     static const OrientedBox zero;
00058 
00059     /// 単位ボックス
00060     static const OrientedBox unit;
00061 
00062     //--------------------------------------------------------------------------
00063     // コンストラクタ
00064     //--------------------------------------------------------------------------
00065     /**
00066      * コンストラクタ
00067      *
00068      * このコンストラクタは初期値の設定を行わないため値は不定です。
00069      */
00070     inline OrientedBox(){}
00071 
00072     /**
00073      * コンストラクタ
00074      * @param rotationMatrix 回転行列の初期値
00075      * @param center 中心の初期値
00076      * @param extent 大きさの初期値
00077      */
00078     inline OrientedBox(const Matrix33& rotationMatrix,
00079         const Vector3& center, const Vector3& extent) :
00080         rotationMatrix_(rotationMatrix), center_(center), extent_(extent){
00081         Assert((extent_.x >= 0.f) && (extent_.y >= 0.f) && (extent_.z >= 0.f));
00082     }
00083 
00084     /**
00085      * コンストラクタ
00086      * @param rotation00 回転行列のm00初期値
00087      * @param rotation01 回転行列のm01初期値
00088      * @param rotation02 回転行列のm02初期値
00089      * @param rotation10 回転行列のm10初期値
00090      * @param rotation11 回転行列のm11初期値
00091      * @param rotation12 回転行列のm12初期値
00092      * @param rotation20 回転行列のm20初期値
00093      * @param rotation21 回転行列のm21初期値
00094      * @param rotation22 回転行列のm22初期値
00095      * @param centerX 中心Xの初期値
00096      * @param centerY 中心Yの初期値
00097      * @param centerZ 中心Zの初期値
00098      * @param extentX 大きさXの初期値
00099      * @param extentY 大きさYの初期値
00100      * @param extentZ 大きさZの初期値
00101      */
00102     inline OrientedBox(
00103         float rotation00, float rotation01, float rotation02,
00104         float rotation10, float rotation11, float rotation12,
00105         float rotation20, float rotation21, float rotation22,
00106         float centerX, float centerY, float centerZ,
00107         float extentX, float extentY, float extentZ) :
00108         rotationMatrix_(rotation00, rotation01, rotation02,
00109             rotation10, rotation11, rotation12,
00110             rotation20, rotation21, rotation22),
00111         center_(centerX, centerY, centerZ),
00112         extent_(extentX, extentY, extentZ){
00113         Assert((extent_.x >= 0.f) && (extent_.y >= 0.f) && (extent_.z >= 0.f));
00114     }
00115 
00116     /**
00117      * コンストラクタ
00118      * @param source 初期値配列
00119      */
00120     inline explicit OrientedBox(const float* const source) :
00121         rotationMatrix_(source[0], source[1], source[2],
00122             source[3], source[4], source[5],
00123             source[6], source[7], source[8]),
00124         center_(source[9], source[10], source[11]),
00125         extent_(source[12], source[13], source[14]){
00126         Assert((extent_.x >= 0.f) && (extent_.y >= 0.f) && (extent_.z >= 0.f));
00127     }
00128 
00129     //--------------------------------------------------------------------------
00130     // 値の設定
00131     //--------------------------------------------------------------------------
00132     /**
00133      * 値の設定
00134      * @param rotationMatrix 設定する回転行列
00135      * @param center 設定する中心
00136      * @param extent 設定する大きさ
00137      */
00138     inline void set(const Matrix33& rotationMatrix,
00139         const Vector3& center, const Vector3& extent){
00140         rotationMatrix_ = rotationMatrix;
00141         center_ = center;
00142         extent_ = extent;
00143         Assert((extent_.x >= 0.f) && (extent_.y >= 0.f) && (extent_.z >= 0.f));
00144     }
00145 
00146     /**
00147      * 値の設定
00148      * @param rotation00 設定する回転行列のm00
00149      * @param rotation01 設定する回転行列のm01
00150      * @param rotation02 設定する回転行列のm02
00151      * @param rotation10 設定する回転行列のm10
00152      * @param rotation11 設定する回転行列のm11
00153      * @param rotation12 設定する回転行列のm12
00154      * @param rotation20 設定する回転行列のm20
00155      * @param rotation21 設定する回転行列のm21
00156      * @param rotation22 設定する回転行列のm22
00157      * @param centerX 設定する中心X
00158      * @param centerY 設定する中心Y
00159      * @param centerZ 設定する中心Z
00160      * @param extentX 設定する大きさX
00161      * @param extentY 設定する大きさY
00162      * @param extentZ 設定する大きさZ
00163      */
00164     inline void set(
00165         float rotation00, float rotation01, float rotation02,
00166         float rotation10, float rotation11, float rotation12,
00167         float rotation20, float rotation21, float rotation22,
00168         float centerX, float centerY, float centerZ,
00169         float extentX, float extentY, float extentZ){
00170         rotationMatrix_.set(rotation00, rotation01, rotation02,
00171             rotation10, rotation11, rotation12,
00172             rotation20, rotation21, rotation22);
00173         center_.set(centerX, centerY, centerZ);
00174         extent_.set(extentX, extentY, extentZ);
00175         Assert((extent_.x >= 0.f) && (extent_.y >= 0.f) && (extent_.z >= 0.f));
00176     }
00177 
00178     /**
00179      * 値の設定
00180      * @param source 設定値配列
00181      */
00182     inline void set(const float* const source){
00183         rotationMatrix_.set(source[0], source[1], source[2],
00184             source[3], source[4], source[5],
00185             source[6], source[7], source[8]);
00186         center_.set(source[9], source[10], source[11]);
00187         extent_.set(source[12], source[13], source[14]);
00188         Assert((extent_.x >= 0.f) && (extent_.y >= 0.f) && (extent_.z >= 0.f));
00189     }
00190 
00191     //--------------------------------------------------------------------------
00192     /**
00193      * 回転行列の設定
00194      * @param rotationMatrix 回転行列
00195      */
00196     inline void setRotationMatrix(const Matrix33& rotationMatrix){
00197         rotationMatrix_ = rotationMatrix;
00198     }
00199 
00200     /**
00201      * XYZ回転の設定
00202      * @param rotationXYZ XYZ回転
00203      */
00204     inline void setRotationXYZ(const Vector3 rotationXYZ){
00205         rotationMatrix_.setRotationXYZ(rotationXYZ);
00206     }
00207 
00208     /**
00209      * 四元数回転の設定
00210      * @param rotationQuaternion 四元数回転
00211      */
00212     inline void setRotationQuaternion(const Quaternion& rotationQuaternion){
00213         rotationMatrix_.setRotationQuaternion(rotationQuaternion);
00214     }
00215 
00216     //--------------------------------------------------------------------------
00217     /**
00218      * 中心の設定
00219      * @param center 中心
00220      */
00221     inline void setCenter(const Vector3& center){ center_ = center; }
00222 
00223     //--------------------------------------------------------------------------
00224     /**
00225      * 大きさの設定
00226      * @param extent 大きさ
00227      */
00228     inline void setExtent(const Vector3& extent){
00229         extent_ = extent;
00230         Assert((extent_.x >= 0.f) && (extent_.y >= 0.f) && (extent_.z >= 0.f));
00231     }
00232 
00233     //--------------------------------------------------------------------------
00234     // 値の取得
00235     //--------------------------------------------------------------------------
00236     /**
00237      * 回転行列の取得
00238      * @return 回転行列
00239      */
00240     inline const Matrix33& getRotationMatrix() const{ return rotationMatrix_; }
00241 
00242     /**
00243      * 中心の取得
00244      * @return 中心
00245      */
00246     inline const Vector3& getCenter() const{ return center_; }
00247 
00248     /**
00249      * 大きさの取得
00250      * @return 大きさ
00251      */
00252     inline const Vector3& getExtent() const{ return extent_; }
00253 
00254     /**
00255      * サイズの取得
00256      * @return サイズ
00257      */
00258     inline Vector3 getSize() const{ return (extent_ * 2.f); }
00259 
00260     //--------------------------------------------------------------------------
00261     /**
00262      * 軸の取得
00263      * @param index 軸インデックス
00264      * @return 軸ベクトル
00265      */
00266     inline Vector3 getAxis(int index) const{
00267         Assert((index >= 0) && (index < 3));
00268         return Vector3(rotationMatrix_.m[index][0],
00269             rotationMatrix_.m[index][1], rotationMatrix_.m[index][2]);
00270     }
00271 
00272     /**
00273      * X軸の取得
00274      * @return X軸ベクトル
00275      */
00276     inline Vector3 getAxisX() const{
00277         return Vector3(
00278             rotationMatrix_.m00, rotationMatrix_.m01, rotationMatrix_.m02);
00279     }
00280 
00281     /**
00282      * Y軸の取得
00283      * @return Y軸ベクトル
00284      */
00285     inline Vector3 getAxisY() const{
00286         return Vector3(
00287             rotationMatrix_.m10, rotationMatrix_.m11, rotationMatrix_.m12);
00288     }
00289 
00290     /**
00291      * Z軸の取得
00292      * @return X軸ベクトル
00293      */
00294     inline Vector3 getAxisZ() const{
00295         return Vector3(
00296             rotationMatrix_.m20, rotationMatrix_.m21, rotationMatrix_.m22);
00297     }
00298 
00299     //--------------------------------------------------------------------------
00300     /**
00301      * 大きさを適用した軸の取得
00302      * @param index 軸インデックス
00303      * @return 大きさを適用した軸ベクトル
00304      */
00305     inline Vector3 getExtendedAxis(int index) const{
00306         Assert((index >= 0) && (index < 3));
00307         float extent = extent_.array[index];
00308         return Vector3(rotationMatrix_.m[index][0] * extent,
00309             rotationMatrix_.m[index][1] * extent,
00310             rotationMatrix_.m[index][2] * extent);
00311     }
00312 
00313     /**
00314      * 大きさを適用したX軸の取得
00315      * @return 大きさを適用したX軸ベクトル
00316      */
00317     inline Vector3 getExtendedAxisX() const{
00318         return Vector3(rotationMatrix_.m00 * extent_.x,
00319             rotationMatrix_.m01 * extent_.x, rotationMatrix_.m02 * extent_.x);
00320     }
00321 
00322     /**
00323      * 大きさを適用したY軸の取得
00324      * @return 大きさを適用したY軸ベクトル
00325      */
00326     inline Vector3 getExtendedAxisY() const{
00327         return Vector3(rotationMatrix_.m10 * extent_.y,
00328             rotationMatrix_.m11 * extent_.y, rotationMatrix_.m12 * extent_.y);
00329     }
00330 
00331     /**
00332      * 大きさを適用したZ軸の取得
00333      * @return 大きさを適用したX軸ベクトル
00334      */
00335     inline Vector3 getExtendedAxisZ() const{
00336         return Vector3(rotationMatrix_.m20 * extent_.z,
00337             rotationMatrix_.m21 * extent_.z, rotationMatrix_.m22 * extent_.z);
00338     }
00339 
00340     //--------------------------------------------------------------------------
00341     /**
00342      * 実効直径の取得
00343      * @param direction 実効直径を測る方向
00344      * @return 実効直径
00345      */
00346     inline float getEffectiveDiameter(const Vector3& direction) const{
00347         return (Math::abs(direction.dotProduct(getExtendedAxisX())) +
00348             Math::abs(direction.dotProduct(getExtendedAxisY())) +
00349             Math::abs(direction.dotProduct(getExtendedAxisZ())));
00350     }
00351 
00352     /**
00353      * 実効半径の取得
00354      * @param direction 実効直径を測る方向
00355      * @return 実効半径
00356      */
00357     inline float getEffectiveRadius(const Vector3& direction) const{
00358         return getEffectiveDiameter(direction) * 0.5f;
00359     }
00360 
00361     //--------------------------------------------------------------------------
00362     /**
00363      * コーナーの取得
00364      *
00365      * 以下の図のインデックスに沿ってコーナーを取得します。
00366      * 0が中心で4が大きさです。
00367      * <pre>
00368      *     y+
00369      *     |
00370      *     1----2
00371      *    /|   /|
00372      *   5-+--4 |
00373      *   | 0--+-3-- x+
00374      *   |/   |/
00375      *   6----7
00376      *  /
00377      * z+
00378      * </pre>
00379      * @param index インデックス
00380      * @return コーナー
00381      */
00382     inline Vector3 getCorner(int index) const{
00383         Assert((index >= 0) && (index < 8));
00384         Vector3 axisX = getExtendedAxisX();
00385         Vector3 axisY = getExtendedAxisY();
00386         Vector3 axisZ = getExtendedAxisZ();
00387         if(index == 0){
00388             return center_ - axisX - axisY - axisZ;
00389         }else if(index == 1){
00390             return center_ - axisX + axisY - axisZ;
00391         }else if(index == 2){
00392             return center_ + axisX + axisY - axisZ;
00393         }else if(index == 3){
00394             return center_ + axisX - axisY - axisZ;
00395         }else if(index == 4){
00396             return center_ + axisX + axisY + axisZ;
00397         }else if(index == 5){
00398             return center_ - axisX + axisY + axisZ;
00399         }else if(index == 6){
00400             return center_ - axisX - axisY + axisZ;
00401         }else if(index == 7){
00402             return center_ + axisX - axisY + axisZ;
00403         }
00404         ErrorOut("OrientedBox::getCorner() Out of index");
00405         return center_;
00406     }
00407 
00408     /**
00409      * コーナー配列の取得
00410      *
00411      * 以下の図のインデックスに沿ってコーナーを取得します。
00412      * 0が中心で4が大きさです。
00413      * <pre>
00414      *     y+
00415      *     |
00416      *     1----2
00417      *    /|   /|
00418      *   5-+--4 |
00419      *   | 0--+-3-- x+
00420      *   |/   |/
00421      *   6----7
00422      *  /
00423      * z+
00424      * </pre>
00425      * @param corner [out] コーナー配列
00426      */
00427     inline void getCornerArray(Vector3 corner[8]) const{
00428         const Matrix33& matrix = rotationMatrix_;
00429         Vector3 axisX = getExtendedAxisX();
00430         Vector3 axisY = getExtendedAxisY();
00431         Vector3 axisZ = getExtendedAxisZ();
00432         corner[0] = center_ - axisX - axisY - axisZ;
00433         corner[1] = center_ - axisX + axisY - axisZ;
00434         corner[2] = center_ + axisX + axisY - axisZ;
00435         corner[3] = center_ + axisX - axisY - axisZ;
00436         corner[4] = center_ + axisX + axisY + axisZ;
00437         corner[5] = center_ - axisX + axisY + axisZ;
00438         corner[6] = center_ - axisX - axisY + axisZ;
00439         corner[7] = center_ + axisX - axisY + axisZ;
00440     }
00441 
00442     //--------------------------------------------------------------------------
00443     // ボックス演算
00444     //--------------------------------------------------------------------------
00445     /**
00446      * ゼロボックスかどうか
00447      * @return ゼロボックスならtrueを返す
00448      */
00449     inline bool isZero() const{
00450         return extent_.epsilonEquals(Vector3::zero, Math::epsilon);
00451     }
00452 
00453     /**
00454      * 単位ボックスかどうか
00455      * @return 単位ボックスならtrueを返す
00456      */
00457     inline bool isUnit() const{
00458         return extent_.epsilonEquals(Vector3(0.5f, 0.5f, 0.5f), Math::epsilon);
00459     }
00460 
00461     //--------------------------------------------------------------------------
00462     // トランスフォーム
00463     //--------------------------------------------------------------------------
00464     /**
00465      * トランスフォーム
00466      * @param matrix 乗算する行列
00467      * @return 変換後の指向性ボックス
00468      */
00469     inline OrientedBox transform(const Matrix33& matrix) const{
00470         OrientedBox result;
00471         result.rotationMatrix_ = matrix * rotationMatrix_;
00472         result.center_ = matrix * center_;
00473         result.extent_ = extent_;
00474         return result;
00475     }
00476 
00477     /**
00478      * トランスフォーム
00479      * @param matrix 乗算する行列
00480      * @return 変換後の指向性ボックス
00481      */
00482     inline OrientedBox transform(const Matrix34& matrix) const{
00483         OrientedBox result;
00484         Matrix33 matrix33;
00485         matrix33.set(matrix);
00486         result.rotationMatrix_ = matrix33 * rotationMatrix_;
00487         result.center_ = matrix * center_;
00488         result.extent_ = extent_;
00489         return result;
00490     }
00491 
00492     /**
00493      * トランスフォーム
00494      * @param matrix 乗算する行列
00495      * @return 変換後の指向性ボックス
00496      */
00497     inline OrientedBox transform(const Matrix44& matrix) const{
00498         OrientedBox result;
00499         Matrix33 matrix33;
00500         matrix33.set(matrix);
00501         result.rotationMatrix_ = matrix33 * rotationMatrix_;
00502         result.center_ = matrix * center_;
00503         result.extent_ = extent_;
00504         return result;
00505     }
00506 
00507     //--------------------------------------------------------------------------
00508     /**
00509      * スケール有りトランスフォーム
00510      * @param matrix 乗算する行列
00511      * @return 変換後の軸沿いボックス
00512      */
00513     AxisAlignedBox scaledTransform(const Matrix33& matrix) const;
00514 
00515     /**
00516      * スケール有りトランスフォーム
00517      * @param matrix 乗算する行列
00518      * @return 変換後の軸沿いボックス
00519      */
00520     AxisAlignedBox scaledTransform(const Matrix34& matrix) const;
00521 
00522     /**
00523      * スケール有りトランスフォーム
00524      * @param matrix 乗算する行列
00525      * @return 変換後の軸沿いボックス
00526      */
00527     AxisAlignedBox scaledTransform(const Matrix44& matrix) const;
00528 
00529     //--------------------------------------------------------------------------
00530     // 距離
00531     //--------------------------------------------------------------------------
00532     /**
00533      * 点距離
00534      * @param point 距離判定する点
00535      * @return 距離
00536      */
00537     float getDistance(const Vector3& point) const{
00538         return Math::sqrt(getSquaredDistance(point));
00539     }
00540 
00541     /**
00542      * 点距離の二乗
00543      * @param point 距離判定する点
00544      * @return 距離の二乗
00545      */
00546     float getSquaredDistance(const Vector3& point) const;
00547 
00548     //--------------------------------------------------------------------------
00549     /**
00550      * 軸沿いボックス距離
00551      * @param axisAlignedBox 距離判定する軸沿いボックス
00552      * @return 距離
00553      */
00554     float getDistance(const AxisAlignedBox& axisAlignedBox) const{
00555         return Math::sqrt(getSquaredDistance(axisAlignedBox));
00556     }
00557 
00558     /**
00559      * 軸沿いボックス距離の二乗
00560      * @param axisAlignedBox 距離判定する軸沿いボックス
00561      * @return 距離の二乗
00562      */
00563     float getSquaredDistance(const AxisAlignedBox& axisAlignedBox) const;
00564 
00565     //--------------------------------------------------------------------------
00566     /**
00567      * カプセル距離
00568      * @param capsule 距離判定するカプセル
00569      * @return 距離
00570      */
00571     float getDistance(const Capsule& capsule) const{
00572         return Math::sqrt(getSquaredDistance(capsule));
00573     }
00574 
00575     /**
00576      * カプセル距離の二乗
00577      * @param capsule 距離判定するカプセル
00578      * @return 距離の二乗
00579      */
00580     float getSquaredDistance(const Capsule& capsule) const;
00581 
00582     //--------------------------------------------------------------------------
00583     /**
00584      * コーン距離
00585      * @param cone 距離判定するコーン
00586      * @return 距離
00587      */
00588     float getDistance(const Cone& cone) const{
00589         return Math::sqrt(getSquaredDistance(cone));
00590     }
00591 
00592     /**
00593      * コーン距離の二乗
00594      * @param cone 距離判定するコーン
00595      * @return 距離の二乗
00596      */
00597     float getSquaredDistance(const Cone& cone) const;
00598 
00599     //--------------------------------------------------------------------------
00600     /**
00601      * ライン距離
00602      * @param line 距離判定するライン
00603      * @return 距離
00604      */
00605     float getDistance(const Line& line) const{
00606         return Math::sqrt(getSquaredDistance(line));
00607     }
00608 
00609     /**
00610      * ライン距離の二乗
00611      * @param line 距離判定するライン
00612      * @return 距離の二乗
00613      */
00614     float getSquaredDistance(const Line& line) const;
00615 
00616     //--------------------------------------------------------------------------
00617     /**
00618      * 指向性ボックス距離
00619      * @param orientedBox 距離判定する指向性ボックス
00620      * @return 距離
00621      */
00622     float getDistance(const OrientedBox& orientedBox) const{
00623         return Math::sqrt(getSquaredDistance(orientedBox));
00624     }
00625 
00626     /**
00627      * 指向性ボックス距離の二乗
00628      * @param orientedBox 距離判定する指向性ボックス
00629      * @return 距離の二乗
00630      */
00631     float getSquaredDistance(const OrientedBox& orientedBox) const;
00632 
00633     //--------------------------------------------------------------------------
00634     /**
00635      * 平面距離
00636      * @param plane 距離判定する平面
00637      * @return 距離
00638      */
00639     float getDistance(const Plane& plane) const;
00640 
00641     /**
00642      * 平面距離の二乗
00643      * @param plane 距離判定する平面
00644      * @return 距離の二乗
00645      */
00646     float getSquaredDistance(const Plane& plane) const{
00647         float distance = getDistance(plane);
00648         return (distance * distance);
00649     }
00650 
00651     //--------------------------------------------------------------------------
00652     /**
00653      * レイ距離
00654      * @param ray 距離判定するレイ
00655      * @return 距離
00656      */
00657     float getDistance(const Ray& ray) const{
00658         return Math::sqrt(getSquaredDistance(ray));
00659     }
00660 
00661     /**
00662      * レイ距離の二乗
00663      * @param ray 距離判定するレイ
00664      * @return 距離の二乗
00665      */
00666     float getSquaredDistance(const Ray& ray) const;
00667 
00668     //--------------------------------------------------------------------------
00669     /**
00670      * セグメント距離
00671      * @param segment 距離判定するセグメント
00672      * @return 距離
00673      */
00674     float getDistance(const Segment& segment) const{
00675         return Math::sqrt(getSquaredDistance(segment));
00676     }
00677 
00678     /**
00679      * セグメント距離の二乗
00680      * @param segment 距離判定するセグメント
00681      * @return 距離の二乗
00682      */
00683     float getSquaredDistance(const Segment& segment) const;
00684 
00685     //--------------------------------------------------------------------------
00686     /**
00687      * 球距離
00688      * @param sphere 距離判定する球
00689      * @return 距離
00690      */
00691     float getDistance(const Sphere& sphere) const{
00692         return Math::sqrt(getSquaredDistance(sphere));
00693     }
00694 
00695     /**
00696      * 球距離の二乗
00697      * @param sphere 距離判定する球
00698      * @return 距離の二乗
00699      */
00700     float getSquaredDistance(const Sphere& sphere) const;
00701 
00702     //--------------------------------------------------------------------------
00703     /**
00704      * 三角距離
00705      * @param triangle 距離判定する三角
00706      * @return 距離
00707      */
00708     float getDistance(const Triangle& triangle) const{
00709         return Math::sqrt(getSquaredDistance(triangle));
00710     }
00711 
00712     /**
00713      * 三角距離の二乗
00714      * @param triangle 距離判定する三角
00715      * @return 距離の二乗
00716      */
00717     float getSquaredDistance(const Triangle& triangle) const;
00718 
00719     //--------------------------------------------------------------------------
00720     // 交差
00721     //--------------------------------------------------------------------------
00722     /**
00723      * 点交差
00724      * @param point 交差判定する点
00725      * @return 交差していればtrue
00726      */
00727     bool intersect(const Vector3& point) const;
00728 
00729     //--------------------------------------------------------------------------
00730     /**
00731      * 軸沿いボックス交差
00732      * @param axisAlignedBox 交差判定する軸沿いボックス
00733      * @return 交差していればtrue
00734      */
00735     bool intersect(const AxisAlignedBox& axisAlignedBox) const;
00736 
00737     //--------------------------------------------------------------------------
00738     /**
00739      * カプセル交差
00740      * @param capsule 交差判定するカプセル
00741      * @return 交差していればtrue
00742      */
00743     bool intersect(const Capsule& capsule) const;
00744 
00745     //--------------------------------------------------------------------------
00746     /**
00747      * コーン交差
00748      * @param cone 交差判定するコーン
00749      * @return 交差していればtrue
00750      */
00751     bool intersect(const Cone& cone) const;
00752 
00753     //--------------------------------------------------------------------------
00754     /**
00755      * ライン交差
00756      * @param line 交差判定するライン
00757      * @return 交差していればtrue
00758      */
00759     bool intersect(const Line& line) const;
00760 
00761     //--------------------------------------------------------------------------
00762     /**
00763      * 指向性ボックス交差
00764      * @param orientedBox 交差判定する指向性ボックス
00765      * @return 交差していればtrue
00766      */
00767     bool intersect(const OrientedBox& orientedBox) const;
00768 
00769     //--------------------------------------------------------------------------
00770     /**
00771      * 平面交差
00772      * @param plane 交差判定する平面
00773      * @return 交差していればtrue
00774      */
00775     bool intersect(const Plane& plane) const;
00776 
00777     //--------------------------------------------------------------------------
00778     /**
00779      * レイ交差
00780      * @param ray 交差判定するレイ
00781      * @return 交差していればtrue
00782      */
00783     bool intersect(const Ray& ray) const;
00784 
00785     //--------------------------------------------------------------------------
00786     /**
00787      * セグメント交差
00788      * @param segment 交差判定するセグメント
00789      * @return 交差していればtrue
00790      */
00791     bool intersect(const Segment& segment) const;
00792 
00793     //--------------------------------------------------------------------------
00794     /**
00795      * 球交差
00796      * @param sphere 交差判定する球
00797      * @return 交差していればtrue
00798      */
00799     bool intersect(const Sphere& sphere) const;
00800 
00801     //--------------------------------------------------------------------------
00802     /**
00803      * 三角交差
00804      * @param triangle 交差判定する三角
00805      * @return 交差していればtrue
00806      */
00807     bool intersect(const Triangle& triangle) const;
00808 
00809     //--------------------------------------------------------------------------
00810     // 論理演算
00811     //--------------------------------------------------------------------------
00812     /**
00813      * 指向性ボックスが同じかどうか
00814      * @param target 比較する指向性ボックス
00815      * @return 同じ値であればtrueを返す
00816      */
00817     inline bool operator ==(const OrientedBox& target) const{
00818         return ((rotationMatrix_ == target.rotationMatrix_) &&
00819             (center_ == target.center_) && (extent_ == target.extent_));
00820     }
00821 
00822     /**
00823      * 指向性ボックスが同じかどうか
00824      * @param target 比較する指向性ボックス
00825      * @param epsilon 誤差
00826      * @return 誤差の範囲内で同じ値であればtrueを返す
00827      */
00828     inline bool epsilonEquals(
00829         const OrientedBox& target, float epsilon) const{
00830         Assert(epsilon >= 0.f);
00831         return (
00832             rotationMatrix_.epsilonEquals(target.rotationMatrix_, epsilon) &&
00833             center_.epsilonEquals(target.center_, epsilon) &&
00834             extent_.epsilonEquals(target.extent_, epsilon));
00835     }
00836 
00837     /**
00838      * 指向性ボックスが同じでないかどうか
00839      * @param target 比較する指向性ボックス
00840      * @return 同じでない値であればtrueを返す
00841      */
00842     inline bool operator !=(const OrientedBox& target) const{
00843         return ((rotationMatrix_ != target.rotationMatrix_) ||
00844             (center_ != target.center_) || (extent_ != target.extent_));
00845     }
00846 
00847     /**
00848      * 指向性ボックスが同じでないかどうか
00849      * @param target 比較する指向性ボックス
00850      * @param epsilon 誤差
00851      * @return 誤差の範囲内で同じでない値であればtrueを返す
00852      */
00853     inline bool notEpsilonEquals(
00854         const OrientedBox& target, float epsilon) const{
00855         Assert(epsilon >= 0.f);
00856         return (
00857             rotationMatrix_.notEpsilonEquals(target.rotationMatrix_, epsilon) ||
00858             center_.notEpsilonEquals(target.center_, epsilon) ||
00859             extent_.notEpsilonEquals(target.extent_, epsilon));
00860     }
00861 
00862     //--------------------------------------------------------------------------
00863     // その他
00864     //--------------------------------------------------------------------------
00865     /**
00866      * 文字列化
00867      * @return 指向性ボックスの文字列表記
00868      */
00869     inline String toString() const{
00870         String returnString;
00871         returnString.format("{ { ( %.8f, %.8f, %.8f ) "
00872             "( %.8f, %.8f, %.8f ) ( %.8f, %.8f, %.8f ) } "
00873             "( %.8f, %.8f, %.8f ) ( %.8f, %.8f, %.8f ) }",
00874             rotationMatrix_.m00, rotationMatrix_.m01, rotationMatrix_.m02,
00875             rotationMatrix_.m10, rotationMatrix_.m11, rotationMatrix_.m12,
00876             rotationMatrix_.m20, rotationMatrix_.m21, rotationMatrix_.m22,
00877             center_.x, center_.y, center_.z, extent_.x, extent_.y, extent_.z);
00878         return returnString;
00879     }
00880 
00881 private:
00882     //--------------------------------------------------------------------------
00883     // メンバ変数
00884     //--------------------------------------------------------------------------
00885     // 回転行列
00886     Matrix33 rotationMatrix_;
00887     // 中心
00888     Vector3 center_;
00889     // 大きさ
00890     Vector3 extent_;
00891 
00892 };
00893 
00894 //------------------------------------------------------------------------------
00895 } // End of namespace Lamp
00896 #endif // End of ORIENTED_BOX_H_
00897 //------------------------------------------------------------------------------

Generated on Wed Mar 16 10:29:33 2005 for Lamp by doxygen 1.3.2