00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #ifndef __SIM_Isect_h__
00015 #define __SIM_Isect_h__
00016
00017 #include "SIM_API.h"
00018
00019 #include "SIM_Time.h"
00020 #include <UT/UT_PriorityQueue.h>
00021 #include <GU/GU_Detail.h>
00022
00023
00024 class SIM_API SIM_Isect
00025 {
00026 public:
00027
00028
00029 struct simIsectInfo
00030 {
00031
00032 int myObjectId;
00033
00034
00035 UT_Vector3 myPosition;
00036
00037
00038
00039 enum simIsectInfoType
00040 {
00041 NONE,
00042 PRIM_EDGE_U,
00043 PRIM_UV,
00044 POINT
00045 } myType;
00046
00047 union
00048 {
00049 struct
00050 {
00051 int myPrimitiveId;
00052 int myEdgeId;
00053 fpreal myU;
00054 } myPEU;
00055 struct
00056 {
00057 int myPrimitiveId;
00058 fpreal myU;
00059 fpreal myV;
00060 } myPUV;
00061 struct
00062 {
00063 int myPointId;
00064 } myPt;
00065 };
00066
00067 simIsectInfo() { }
00068
00069
00070
00071 static simIsectInfo makeNone(int obj_id, const UT_Vector3 &position)
00072 {
00073 return simIsectInfo(obj_id, position, NONE);
00074 }
00075 static simIsectInfo makeEdgeU(int obj_id, const UT_Vector3 &position,
00076 int primId, int eid, fpreal u)
00077 {
00078 simIsectInfo result(obj_id, position,
00079 PRIM_EDGE_U);
00080 result.myPEU.myPrimitiveId = primId;
00081 result.myPEU.myEdgeId = eid;
00082 result.myPEU.myU = u;
00083 return result;
00084 }
00085 static simIsectInfo makePrimUV(int obj_id, const UT_Vector3 &position,
00086 int primid, fpreal u, fpreal v)
00087 {
00088 simIsectInfo result(obj_id, position, PRIM_UV);
00089 result.myPUV.myPrimitiveId = primid;
00090 result.myPUV.myU = u;
00091 result.myPUV.myV = v;
00092 return result;
00093 }
00094 static simIsectInfo makePoint(int obj_id, const UT_Vector3 &position,
00095 int pointid)
00096 {
00097 simIsectInfo result(obj_id, position, POINT);
00098 result.myPt.myPointId = pointid;
00099 return result;
00100 }
00101
00102
00103 private:
00104 simIsectInfo(int obj_id, const UT_Vector3 &position,
00105 simIsectInfoType type)
00106 : myObjectId(obj_id), myPosition(position),
00107 myType(type)
00108 { }
00109 };
00110
00111
00112
00113 SIM_Isect() {}
00114
00115
00116
00117 SIM_Isect(const UT_Vector3 &normal,
00118 fpreal64 depth,
00119 const SIM_Time &time,
00120 const simIsectInfo &objectInfoA,
00121 const simIsectInfo &objectInfoB)
00122 : myDepth(depth),
00123 myNormal(normal),
00124 myTime(time),
00125 myObjectInfoA(objectInfoA),
00126 myObjectInfoB(objectInfoB)
00127 { }
00128 SIM_Isect(const UT_Vector3 &position,
00129 const UT_Vector3 &normal,
00130 const SIM_Time &time,
00131 fpreal64 depth,
00132 int obj_a, int obj_b)
00133 : myDepth(depth),
00134 myNormal(normal),
00135 myTime(time),
00136 myObjectInfoA(simIsectInfo::makeNone(obj_a, position)),
00137 myObjectInfoB(simIsectInfo::makeNone(obj_b, position))
00138 { }
00139
00140 bool isFaceVertex() const
00141 {
00142 return (myObjectInfoA.myType == simIsectInfo::PRIM_UV &&
00143 myObjectInfoB.myType == simIsectInfo::POINT) ||
00144 (myObjectInfoB.myType == simIsectInfo::PRIM_UV &&
00145 myObjectInfoA.myType == simIsectInfo::POINT);
00146 }
00147 bool isEdgeEdge() const
00148 {
00149 return myObjectInfoA.myType == simIsectInfo::PRIM_EDGE_U &&
00150 myObjectInfoB.myType == simIsectInfo::PRIM_EDGE_U;
00151 }
00152
00153
00154
00155
00156
00157 fpreal64 myDepth;
00158
00159
00160 UT_Vector3 myNormal;
00161
00162
00163 SIM_Time myTime;
00164
00165
00166 simIsectInfo myObjectInfoA;
00167
00168
00169 simIsectInfo myObjectInfoB;
00170 };
00171
00172
00173 class SIM_API SIM_IsectCompare
00174 {
00175 public:
00176 bool isLess(const SIM_Isect *a, const SIM_Isect *b)
00177 { return a->myDepth > b->myDepth; }
00178 };
00179
00180 typedef UT_PriorityQueue<SIM_Isect *, SIM_IsectCompare, false>
00181 SIM_IsectPriorityQueue;
00182 typedef UT_RefArray<SIM_Isect> SIM_IsectArray;
00183
00184 #endif