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

IntersectionResult.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 INTERSECTION_RESULT_H_
00026 #define INTERSECTION_RESULT_H_
00027 
00028 #include <Core/Container/ArrayList.h>
00029 #include <Geometry/System/Intersection.h>
00030 
00031 namespace Lamp{
00032 
00033 //------------------------------------------------------------------------------
00034 /**
00035  * 交差結果
00036  */
00037 class IntersectionResult{
00038 public:
00039     /**
00040      * コンストラクタ
00041      */
00042     IntersectionResult(){}
00043 
00044     /**
00045      * デストラクタ
00046      */
00047     virtual ~IntersectionResult(){}
00048 
00049     //--------------------------------------------------------------------------
00050     /**
00051      * クリア
00052      */
00053     virtual void clear(){ intersections_.clear(); }
00054 
00055     /**
00056      * 反転
00057      */
00058     virtual void reverse(){
00059         int count = getCount();
00060         for(int i = 0; i < count; i++){ intersections_.get(i).reverse(); }
00061     }
00062 
00063     /**
00064      * 交差しているか
00065      * @return 交差していればtrue
00066      */
00067     virtual bool isIntersected() const{
00068         return (intersections_.getCount() != 0);
00069     }
00070 
00071     //--------------------------------------------------------------------------
00072     /**
00073      * 交差数の取得
00074      * @return 交差数
00075      */
00076     virtual int getCount() const{ return intersections_.getCount(); }
00077 
00078     /**
00079      * 交差の取得
00080      * @param index インデックス
00081      * @return 交差
00082      */
00083     virtual const Intersection& get(int index) const{
00084         return intersections_.get(index);
00085     }
00086 
00087     //--------------------------------------------------------------------------
00088     /**
00089      * 交差位置の平均取得
00090      * @return 交差位置の平均
00091      */
00092     virtual Vector3 getAveragePosition() const{
00093         Assert(isIntersected());
00094         Vector3 result(Vector3::zero);
00095         int count = getCount();
00096         for(int i = 0; i < count; i++){ result += get(i).getPosition(); }
00097         result *= 1.f / count;
00098         return result;
00099     }
00100 
00101     /**
00102      * 反射の平均取得
00103      * @return 反射の平均
00104      */
00105     virtual Vector3 getAverageRefrection() const{
00106         Vector3 result(Vector3::zero);
00107         if(!isIntersected()){ return result; }
00108         int count = getCount();
00109         for(int i = 0; i < count; i++){ result += get(i).getRefrection(); }
00110         result *= 1.f / count;
00111         return result;
00112     }
00113 
00114     /**
00115      * 最大の反射取得
00116      * @return 最大の反射
00117      */
00118     virtual Vector3 getMaxRefrection() const{
00119         if(!isIntersected()){ return Vector3::zero; }
00120         Vector3 result(get(0).getRefrection());
00121         float maxSquaredLength = result.getSquaredLength();
00122         int count = getCount();
00123         for(int i = 1; i < count; i++){
00124             const Vector3& refrection = get(i).getRefrection();
00125             float squaredLength = refrection.getSquaredLength();
00126             if(squaredLength > maxSquaredLength){
00127                 result = refrection;
00128                 maxSquaredLength = squaredLength;
00129             }
00130         }
00131         return result;
00132     }
00133 
00134     //--------------------------------------------------------------------------
00135     /**
00136      * 交差の追加
00137      * @param intersection 交差
00138      */
00139     virtual void add(const Intersection& intersection){
00140         intersections_.add(intersection);
00141     }
00142 
00143     /**
00144      * 交差の削除
00145      * @param index インデックス
00146      */
00147     virtual void remove(int index){ intersections_.remove(index); }
00148 
00149     /**
00150      * 交差の削除
00151      * @param intersection 交差
00152      * @return 削除したインデックス。-1なら該当する要素無し。
00153      */
00154     virtual int remove(const Intersection& intersection){
00155         return intersections_.removeByValue(intersection);
00156     }
00157 
00158 private:
00159     //--------------------------------------------------------------------------
00160     // コピーコンストラクタの隠蔽
00161     IntersectionResult(const IntersectionResult& copy);
00162 
00163     // 代入コピーの隠蔽
00164     void operator =(const IntersectionResult& copy);
00165 
00166     //--------------------------------------------------------------------------
00167     // 交差配列
00168     ArrayList<Intersection> intersections_;
00169 
00170 };
00171 
00172 //------------------------------------------------------------------------------
00173 } // End of namespace Lamp
00174 #endif // End of INTERSECTION_RESULT_H_
00175 //------------------------------------------------------------------------------

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