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

CapsuleIntersection.cpp

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 #include "LampBasic.h"
00026 #include "Geometry/Intersection/CapsuleIntersection.h"
00027 
00028 #include "Geometry/Primitive/Capsule.h"
00029 
00030 namespace Lamp{
00031 
00032 //------------------------------------------------------------------------------
00033 // 点
00034 //------------------------------------------------------------------------------
00035 // 点交差
00036 bool CapsuleIntersection::intersect(
00037     const Capsule& capsule, const Vector3& point){
00038     // セグメントと点との距離から求める
00039     const Vector3& direction = capsule.getDirection();
00040     float radius = capsule.getRadius();
00041     Vector3 distance = point - capsule.getOrigin();
00042     float t = distance.dotProduct(direction);
00043     // tが-だったら投影しない
00044     if(t > 0.f){
00045         float squaredLength = direction.getSquaredLength();
00046         if(t >= squaredLength){
00047             // tが方向を超えていた場合はターゲット位置からの距離
00048             // t = 1.f;
00049             distance -= direction;
00050         }else{
00051             t /= squaredLength;
00052             distance -= t * direction;
00053         }
00054     }
00055     // 接触点はorigin + direction * t + distance
00056     // 途中で接触点を求めていったほうがいい。distance使いまわしてる
00057     return distance.getSquaredLength() <= (radius * radius);
00058 }
00059 //------------------------------------------------------------------------------
00060 // カプセル
00061 //------------------------------------------------------------------------------
00062 // カプセル交差
00063 bool CapsuleIntersection::intersect(
00064     const Capsule& capsule0, const Capsule& capsule1){
00065     Assert(false);
00066     return false;
00067 }
00068 //------------------------------------------------------------------------------
00069 // コーン
00070 //------------------------------------------------------------------------------
00071 // コーン交差
00072 bool CapsuleIntersection::intersect(const Capsule& capsule, const Cone& cone){
00073     Assert(false);
00074     return false;
00075 }
00076 //------------------------------------------------------------------------------
00077 // ライン
00078 //------------------------------------------------------------------------------
00079 // ライン交差
00080 bool CapsuleIntersection::intersect(const Capsule& capsule, const Line& line){
00081     Assert(false);
00082     return false;
00083 }
00084 //------------------------------------------------------------------------------
00085 // 指向性ボックス
00086 //------------------------------------------------------------------------------
00087 // 指向性ボックス交差
00088 bool CapsuleIntersection::intersect(
00089     const Capsule& capsule, const OrientedBox& ob){
00090     Assert(false);
00091     return false;
00092 }
00093 //------------------------------------------------------------------------------
00094 // 平面
00095 //------------------------------------------------------------------------------
00096 // 平面交差
00097 bool CapsuleIntersection::intersect(const Capsule& capsule, const Plane& plane){
00098     Assert(false);
00099     return false;
00100 }
00101 //------------------------------------------------------------------------------
00102 // レイ
00103 //------------------------------------------------------------------------------
00104 // レイ交差
00105 bool CapsuleIntersection::intersect(const Capsule& capsule, const Ray& ray){
00106     Assert(false);
00107     return false;
00108 }
00109 //------------------------------------------------------------------------------
00110 // セグメント
00111 //------------------------------------------------------------------------------
00112 // セグメント交差
00113 bool CapsuleIntersection::intersect(
00114     const Capsule& capsule, const Segment& segment){
00115     Assert(false);
00116     return false;
00117 }
00118 //------------------------------------------------------------------------------
00119 // 球
00120 //------------------------------------------------------------------------------
00121 // 球交差
00122 bool CapsuleIntersection::intersect(
00123     const Capsule& capsule, const Sphere& sphere){
00124     Assert(false);
00125     return false;
00126 }
00127 //------------------------------------------------------------------------------
00128 // 三角
00129 //------------------------------------------------------------------------------
00130 // 三角交差
00131 bool CapsuleIntersection::intersect(
00132     const Capsule& capsule, const Triangle& triangle){
00133     Assert(false);
00134     return false;
00135 }
00136 //------------------------------------------------------------------------------
00137 } // End of namespace Lamp
00138 //------------------------------------------------------------------------------

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