00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
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
00066
00067 virtual bool isIntersected() const{
00068 return (intersections_.getCount() != 0);
00069 }
00070
00071
00072
00073
00074
00075
00076 virtual int getCount() const{ return intersections_.getCount(); }
00077
00078
00079
00080
00081
00082
00083 virtual const Intersection& get(int index) const{
00084 return intersections_.get(index);
00085 }
00086
00087
00088
00089
00090
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
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
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
00138
00139 virtual void add(const Intersection& intersection){
00140 intersections_.add(intersection);
00141 }
00142
00143
00144
00145
00146
00147 virtual void remove(int index){ intersections_.remove(index); }
00148
00149
00150
00151
00152
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 }
00174 #endif // End of INTERSECTION_RESULT_H_
00175