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

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

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