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

LineIntersection.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/LineIntersection.h"
00027 
00028 namespace Lamp{
00029 
00030 //------------------------------------------------------------------------------
00031 // 点
00032 //------------------------------------------------------------------------------
00033 // 点交差
00034 bool LineIntersection::intersect(
00035     const Line& line, const Vector3& point, float range){
00036     Assert(false);
00037     return false;
00038 }
00039 //------------------------------------------------------------------------------
00040 // ライン
00041 //------------------------------------------------------------------------------
00042 // ライン交差
00043 bool LineIntersection::intersect(
00044     const Line& line0, const Line& line1, float range){
00045     return (line0.getSquaredDistance(line1) <= (range * range));
00046 }
00047 //------------------------------------------------------------------------------
00048 // 指向性ボックス
00049 //------------------------------------------------------------------------------
00050 // 指向性ボックス交差
00051 bool LineIntersection::intersect(const Line& line, const OrientedBox& ob){
00052     Assert(false);
00053     return false;
00054 }
00055 //------------------------------------------------------------------------------
00056 // 平面
00057 //------------------------------------------------------------------------------
00058 // 平面交差
00059 bool LineIntersection::intersect(const Line& line, const Plane& plane){
00060     float denominator = line.getDirection().dotProduct(plane.getNormal());
00061     if(Math::abs(denominator) <= Math::epsilon){
00062         // 面に平行なレイは原点が面に接していれば交差
00063         float distance = plane.getDistance(line.getOrigin());
00064         return (Math::abs(distance) <= Math::epsilon);
00065     }
00066     // 平行でなければ交差
00067     return true;
00068 }
00069 //------------------------------------------------------------------------------
00070 // レイ
00071 //------------------------------------------------------------------------------
00072 // レイ交差
00073 bool LineIntersection::intersect(
00074     const Line& line, const Ray& ray, float range){
00075     return (line.getSquaredDistance(ray) <= (range * range));
00076 }
00077 //------------------------------------------------------------------------------
00078 // セグメント
00079 //------------------------------------------------------------------------------
00080 // セグメント交差
00081 bool LineIntersection::intersect(
00082     const Line& line, const Segment& segment, float range){
00083     return (line.getSquaredDistance(segment) <= (range * range));
00084 }
00085 //------------------------------------------------------------------------------
00086 // 球
00087 //------------------------------------------------------------------------------
00088 // 球交差
00089 bool LineIntersection::intersect(const Line& line, const Sphere& sphere){
00090     // 球中心との距離が球半径以内なら交差する
00091     float squaredDistance = line.getSquaredDistance(sphere.getCenter());
00092     float radius = sphere.getRadius();
00093     return (squaredDistance <= (radius * radius));
00094 }
00095 //------------------------------------------------------------------------------
00096 // 三角
00097 //------------------------------------------------------------------------------
00098 // 三角交差
00099 bool LineIntersection::intersect(const Line& line, const Triangle& triangle){
00100     Assert(false);
00101     return false;
00102 }
00103 //------------------------------------------------------------------------------
00104 } // End of namespace Lamp
00105 //------------------------------------------------------------------------------

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