HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SIM_Isect.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  */
7 
8 #ifndef __SIM_Isect_h__
9 #define __SIM_Isect_h__
10 
11 #include "SIM_API.h"
12 
13 #include "SIM_Time.h"
14 #include <UT/UT_PriorityQueue.h>
15 #include <GU/GU_Detail.h>
16 
17 /// This class defines various types of collisions.
19 {
20 public:
21  /// Information about one half of the collision (wrt one of the two
22  /// entities involved)
23  struct simIsectInfo
24  {
25  /// ID of object involved in the collision
27 
28  /// World-space position of deepest point of intersection
30 
31  /// The following is a discriminating union describing an alternate
32  /// representation of the deepest point of intersection
34  {
39  } myType;
40 
41  union
42  {
43  struct
44  {
46  int myEdgeId;
48  } myPEU;
49  struct
50  {
51  int myPrimitiveId;
52  fpreal myU;
54  } myPUV;
55  struct
56  {
57  int myPointId;
58  } myPt;
59  };
60 
62 
63  /// Named constructors
64  // @{
65  static simIsectInfo makeNone(int obj_id, const UT_Vector3 &position)
66  {
67  return simIsectInfo(obj_id, position, NONE);
68  }
69  static simIsectInfo makeEdgeU(int obj_id, const UT_Vector3 &position,
70  int primId, int eid, fpreal u)
71  {
72  simIsectInfo result(obj_id, position,
73  PRIM_EDGE_U);
74  result.myPEU.myPrimitiveId = primId;
75  result.myPEU.myEdgeId = eid;
76  result.myPEU.myU = u;
77  return result;
78  }
79  static simIsectInfo makePrimUV(int obj_id, const UT_Vector3 &position,
80  int primid, fpreal u, fpreal v)
81  {
82  simIsectInfo result(obj_id, position, PRIM_UV);
83  result.myPUV.myPrimitiveId = primid;
84  result.myPUV.myU = u;
85  result.myPUV.myV = v;
86  return result;
87  }
88  static simIsectInfo makePoint(int obj_id, const UT_Vector3 &position,
89  int pointid)
90  {
91  simIsectInfo result(obj_id, position, POINT);
92  result.myPt.myPointId = pointid;
93  return result;
94  }
95  // @}
96 
97  private:
98  simIsectInfo(int obj_id, const UT_Vector3 &position,
99  simIsectInfoType type)
100  : myObjectId(obj_id), myPosition(position),
101  myType(type)
102  { }
103  };
104 
105 
106 
108  // Default copy constructor is fine.
109  // SIM_Isect(const SIM_Isect &);
110 
111  SIM_Isect(const UT_Vector3 &normal,
112  fpreal64 depth,
113  const SIM_Time &time,
114  const simIsectInfo &objectInfoA,
115  const simIsectInfo &objectInfoB)
116  : myDepth(depth),
117  myNormal(normal),
118  myTime(time),
119  myObjectInfoA(objectInfoA),
120  myObjectInfoB(objectInfoB)
121  { }
123  const UT_Vector3 &normal,
124  const SIM_Time &time,
125  fpreal64 depth,
126  int obj_a, int obj_b)
127  : myDepth(depth),
128  myNormal(normal),
129  myTime(time),
130  myObjectInfoA(simIsectInfo::makeNone(obj_a, position)),
131  myObjectInfoB(simIsectInfo::makeNone(obj_b, position))
132  { }
133 
134  bool isFaceVertex() const
135  {
136  return (myObjectInfoA.myType == simIsectInfo::PRIM_UV &&
137  myObjectInfoB.myType == simIsectInfo::POINT) ||
138  (myObjectInfoB.myType == simIsectInfo::PRIM_UV &&
139  myObjectInfoA.myType == simIsectInfo::POINT);
140  }
141  bool isEdgeEdge() const
142  {
143  return myObjectInfoA.myType == simIsectInfo::PRIM_EDGE_U &&
144  myObjectInfoB.myType == simIsectInfo::PRIM_EDGE_U;
145  }
146 
147 
148  /// Depth of the intersection. The value is expected to be negative.
149  // TODO: why? That's bizarre.
150  // TODO: rename to a "signed distance" to intersection point.
152 
153  /// Direction object A needs to move to resolve the intersection
155 
156  /// Time of intersection.
158 
159  /// Information about the point of intersection on object A
161 
162  /// Information about the point of intersection on object B
164 };
165 
166 /// This class provides standard PriorityQueue Comparison for SIM_Isect Class
168 {
169 public:
170  bool operator()(const SIM_Isect *a, const SIM_Isect *b) const
171  { return a->myDepth > b->myDepth; }
172 };
173 
177 
178 #endif
bool isFaceVertex() const
Definition: SIM_Isect.h:134
This class defines various types of collisions.
Definition: SIM_Isect.h:18
UT_Vector3 myNormal
Direction object A needs to move to resolve the intersection.
Definition: SIM_Isect.h:154
struct SIM_Isect::simIsectInfo::@611::@615 myPt
SIM_Isect(const UT_Vector3 &normal, fpreal64 depth, const SIM_Time &time, const simIsectInfo &objectInfoA, const simIsectInfo &objectInfoB)
Definition: SIM_Isect.h:111
GT_API const UT_StringHolder time
const GLdouble * v
Definition: glcorearb.h:837
This class provides standard PriorityQueue Comparison for SIM_Isect Class.
Definition: SIM_Isect.h:167
bool isEdgeEdge() const
Definition: SIM_Isect.h:141
static simIsectInfo makeEdgeU(int obj_id, const UT_Vector3 &position, int primId, int eid, fpreal u)
Named constructors.
Definition: SIM_Isect.h:69
GLboolean GLboolean GLboolean GLboolean a
Definition: glcorearb.h:1222
**But if you need a result
Definition: thread.h:613
UT_Vector3 myPosition
World-space position of deepest point of intersection.
Definition: SIM_Isect.h:29
SIM_Isect(const UT_Vector3 &position, const UT_Vector3 &normal, const SIM_Time &time, fpreal64 depth, int obj_a, int obj_b)
Definition: SIM_Isect.h:122
double fpreal64
Definition: SYS_Types.h:201
UT_PriorityQueue< SIM_Isect *, SIM_IsectCompare, false > SIM_IsectPriorityQueue
Definition: SIM_Isect.h:175
simIsectInfo myObjectInfoB
Information about the point of intersection on object B.
Definition: SIM_Isect.h:163
struct SIM_Isect::simIsectInfo::@611::@613 myPEU
static simIsectInfo makePrimUV(int obj_id, const UT_Vector3 &position, int primid, fpreal u, fpreal v)
Named constructors.
Definition: SIM_Isect.h:79
int myObjectId
ID of object involved in the collision.
Definition: SIM_Isect.h:26
GLboolean GLboolean GLboolean b
Definition: glcorearb.h:1222
GLint GLint GLsizei GLsizei GLsizei depth
Definition: glcorearb.h:476
SIM_Time myTime
Time of intersection.
Definition: SIM_Isect.h:157
struct SIM_Isect::simIsectInfo::@611::@614 myPUV
UT_Array< SIM_Isect > SIM_IsectArray
Definition: SIM_Isect.h:176
static simIsectInfo makePoint(int obj_id, const UT_Vector3 &position, int pointid)
Named constructors.
Definition: SIM_Isect.h:88
fpreal64 fpreal
Definition: SYS_Types.h:277
SIM_API const UT_StringHolder position
#define SIM_API
Definition: SIM_API.h:12
static simIsectInfo makeNone(int obj_id, const UT_Vector3 &position)
Named constructors.
Definition: SIM_Isect.h:65
fpreal64 myDepth
Depth of the intersection. The value is expected to be negative.
Definition: SIM_Isect.h:151
type
Definition: core.h:1059
bool operator()(const SIM_Isect *a, const SIM_Isect *b) const
Definition: SIM_Isect.h:170
simIsectInfo myObjectInfoA
Information about the point of intersection on object A.
Definition: SIM_Isect.h:160