Vegastrike 0.5.1 rc1  1.0
Original sources for Vegastrike Evolved
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Opcode Namespace Reference

Classes

struct  Internal
 
class  SAP_Element
 
class  SAP_Box
 
class  SAP_EndPoint
 
class  Axes
 
class  Point
 
class  HPoint
 
class  Matrix3x3
 
class  Matrix4x4
 
class  Plane
 
class  Ray
 
class  IndexedTriangle
 
class  Triangle
 
class  TriList
 
class  TriangleList
 
class  AABB
 
class  OBB
 
class  Sphere
 
class  Segment
 
class  LSS
 
class  CollisionAABB
 
class  QuantizedAABB
 
struct  VertexPointers
 
class  MeshInterface
 
struct  BuildSettings
 Simple wrapper around build-related settings [Opcode 1.3]. More...
 
class  AABBTreeBuilder
 
class  AABBTreeOfVerticesBuilder
 
class  AABBTreeOfAABBsBuilder
 
class  AABBTreeOfTrianglesBuilder
 
class  AABBTreeNode
 
class  AABBTree
 
class  AABBCollisionNode
 
class  AABBQuantizedNode
 
class  AABBNoLeafNode
 
class  AABBQuantizedNoLeafNode
 
class  AABBOptimizedTree
 
class  AABBCollisionTree
 
class  AABBNoLeafTree
 
class  AABBQuantizedTree
 
class  AABBQuantizedNoLeafTree
 
struct  OPCODECREATE
 Model creation structure. More...
 
class  BaseModel
 
class  Model
 
struct  LeafTriangles
 Leaf descriptor. More...
 
class  HybridModel
 
class  Collider
 
struct  VolumeCache
 
class  VolumeCollider
 
struct  BVTCache
 
class  AABBTreeCollider
 
class  CollisionFace
 
class  CollisionFaces
 
class  RayCollider
 
struct  SphereCache
 
class  SphereCollider
 
class  HybridSphereCollider
 
struct  OBBCache
 
class  OBBCollider
 
class  HybridOBBCollider
 
struct  AABBCache
 
class  AABBCollider
 
class  HybridAABBCollider
 
struct  LSSCache
 
class  LSSCollider
 
class  HybridLSSCollider
 
struct  PlanesCache
 
class  PlanesCollider
 
class  HybridPlanesCollider
 
class  SAP_PairData
 
class  SweepAndPrune
 

Typedefs

typedef void(* RequestCallback )(udword triangle_index, VertexPointers &triangle, void *user_data)
 
typedef void(* CullingCallback )(udword nb_primitives, udword *node_primitives, BOOL need_clipping, void *user_data)
 
typedef bool(* WalkingCallback )(const AABBTreeNode *current, udword depth, void *user_data)
 
typedef bool(* GenericWalkingCallback )(const void *current, void *user_data)
 
typedef void(* HitCallback )(const CollisionFace &hit, void *user_data)
 
typedef CullMode(* CullModeCallback )(udword triangle_index, void *user_data)
 
typedef BOOL(* PairCallback )(udword id0, udword id1, void *user_data)
 

Enumerations

enum  PointComponent {
  _X = 0, _Y = 1, _Z = 2, _W = 3,
  _FORCE_DWORD = 0x7fffffff
}
 
enum  AxisOrder {
  AXES_XYZ = (_X)|(_Y<<2)|(_Z<<4), AXES_XZY = (_X)|(_Z<<2)|(_Y<<4), AXES_YXZ = (_Y)|(_X<<2)|(_Z<<4), AXES_YZX = (_Y)|(_Z<<2)|(_X<<4),
  AXES_ZXY = (_Z)|(_X<<2)|(_Y<<4), AXES_ZYX = (_Z)|(_Y<<2)|(_X<<4), AXES_FORCE_DWORD = 0x7fffffff
}
 
enum  PartVal {
  TRI_MINUS_SPACE = 0, TRI_PLUS_SPACE = 1, TRI_INTERSECT = 2, TRI_ON_PLANE = 3,
  TRI_FORCEDWORD = 0x7fffffff
}
 
enum  AABBType { AABB_RENDER = 0, AABB_UPDATE = 1, AABB_FORCE_DWORD = 0x7fffffff }
 
enum  BSphereMethod { BS_NONE, BS_GEMS, BS_MINIBALL, BS_FORCE_DWORD = 0x7fffffff }
 
enum  SplittingRules {
  SPLIT_LARGEST_AXIS = (1<<0), SPLIT_SPLATTER_POINTS = (1<<1), SPLIT_BEST_AXIS = (1<<2), SPLIT_BALANCED = (1<<3),
  SPLIT_FIFTY = (1<<4), SPLIT_GEOM_CENTER = (1<<5), SPLIT_FORCE_DWORD = 0x7fffffff
}
 Tree splitting rules. More...
 
enum  ModelFlag { OPC_QUANTIZED = (1<<0), OPC_NO_LEAF = (1<<1), OPC_SINGLE_NODE = (1<<2) }
 
enum  CollisionFlag {
  OPC_FIRST_CONTACT = (1<<0), OPC_TEMPORAL_COHERENCE = (1<<1), OPC_CONTACT = (1<<2), OPC_TEMPORAL_HIT = (1<<3),
  OPC_NO_PRIMITIVE_TESTS = (1<<4), OPC_CONTACT_FOUND = OPC_FIRST_CONTACT | OPC_CONTACT, OPC_TEMPORAL_CONTACT = OPC_TEMPORAL_HIT | OPC_CONTACT, OPC_FORCE_DWORD = 0x7fffffff
}
 
enum  CullMode { CULLMODE_NONE = 0, CULLMODE_CW = 1, CULLMODE_CCW = 2 }
 

Functions

inline_ void OPComputeMinMax (Point &min, Point &max, const VertexPointers &vp)
 
bool SetupAllHits (RayCollider &collider, CollisionFaces &contacts)
 
bool SetupClosestHit (RayCollider &collider, CollisionFace &closest_contact)
 
bool SetupShadowFeeler (RayCollider &collider)
 
bool SetupInOutTest (RayCollider &collider)
 
bool Picking (CollisionFace &picked_face, const Ray &world_ray, const Model &model, const Matrix4x4 *world, float min_dist, float max_dist, const Point &view_point, CullModeCallback callback, void *user_data)
 
FUNCTION ICEMATHS_API void Normalize1 (Point &a)
 
FUNCTION ICEMATHS_API void Normalize2 (Point &a)
 
inline_ void TransformPoint4x3 (Point &dest, const Point &source, const Matrix4x4 &rot)
 Quickly rotates & translates a vector, using the 4x3 part of a 4x4 matrix. More...
 
inline_ void TransformPoint3x3 (Point &dest, const Point &source, const Matrix4x4 &rot)
 Quickly rotates a vector, using the 3x3 part of a 4x4 matrix. More...
 
void InvertPRMatrix (Matrix4x4 &dest, const Matrix4x4 &src)
 
inline_ void TransformPlane (Plane &transformed, const Plane &plane, const Matrix4x4 &transform)
 
inline_ void TransformPlane (Plane &plane, const Matrix4x4 &transform)
 
inline_ void ComputeReflexionVector (Point &reflected, const Point &incoming_dir, const Point &outward_normal)
 
inline_ void ComputeReflexionVector (Point &reflected, const Point &source, const Point &impact, const Point &normal)
 
inline_ void DecomposeVector (Point &normal_compo, Point &tangent_compo, const Point &outward_dir, const Point &outward_normal)
 
inline_ void ComputeLocalDirection (Point &local_dir, const Point &world_dir, const Matrix4x4 &world)
 
inline_ void ComputeLocalPoint (Point &local_pt, const Point &world_pt, const Matrix4x4 &world)
 
inline_ void ComputeLocalRay (Ray &local_ray, const Ray &world_ray, const Matrix4x4 &world)
 
inline_ void ComputeMinMax (const Point &p, Point &min, Point &max)
 
inline_ void ComputeAABB (AABB &aabb, const Point *list, udword nb_pts)
 
inline_ void TransformPoint (Point &dest, const Point &source, const Matrix3x3 &rot, const Point &trans)
 Quickly rotates & translates a vector. More...
 
FUNCTION OPCODE_API bool CompleteBoxPruning (udword nb, const AABB **array, Pairs &pairs, const Axes &axes)
 
FUNCTION OPCODE_API bool BipartiteBoxPruning (udword nb0, const AABB **array0, udword nb1, const AABB **array1, Pairs &pairs, const Axes &axes)
 
FUNCTION OPCODE_API bool BruteForceCompleteBoxTest (udword nb, const AABB **array, Pairs &pairs)
 
FUNCTION OPCODE_API bool BruteForceBipartiteBoxTest (udword nb0, const AABB **array0, udword nb1, const AABB **array1, Pairs &pairs)
 

Variables

const float EPSILON2 = 1.0e-20f
 

Typedef Documentation

typedef void(* Opcode::CullingCallback)(udword nb_primitives, udword *node_primitives, BOOL need_clipping, void *user_data)

Definition at line 77 of file Opcode.h.

typedef CullMode(* Opcode::CullModeCallback)(udword triangle_index, void *user_data)

Definition at line 33 of file Opcode.h.

typedef bool(* Opcode::GenericWalkingCallback)(const void *current, void *user_data)

Definition at line 132 of file Opcode.h.

typedef void(* Opcode::HitCallback)(const CollisionFace &hit, void *user_data)

User-callback, called by OPCODE to record a hit.

Parameters
hit[in] current hit
user_data[in] user-defined data from SetCallback()

Definition at line 61 of file Opcode.h.

typedef BOOL(* Opcode::PairCallback)(udword id0, udword id1, void *user_data)

User-callback, called by OPCODE for each colliding pairs.

Parameters
id0[in] id of colliding object
id1[in] id of colliding object
user_data[in] user-defined data
Returns
TRUE to continue enumeration

Definition at line 33 of file Opcode.h.

typedef void(* Opcode::RequestCallback)(udword triangle_index, VertexPointers &triangle, void *user_data)

User-callback, called by OPCODE to request vertices from the app.

Parameters
triangle_index[in] face index for which the system is requesting the vertices
triangle[out] triangle's vertices (must be provided by the user)
user_data[in] user-defined data from SetCallback()

Definition at line 51 of file Opcode.h.

typedef bool(* Opcode::WalkingCallback)(const AABBTreeNode *current, udword depth, void *user_data)

User-callback, called for each node by the walking code.

Parameters
current[in] current node
depth[in] current node's depth
user_data[in] user-defined data
Returns
true to recurse through children, else false to bypass them

Definition at line 107 of file Opcode.h.

Enumeration Type Documentation

Enumerator
AABB_RENDER 

AABB used for rendering. Not visible == not rendered.

AABB_UPDATE 

AABB used for dynamic updates. Not visible == not updated.

AABB_FORCE_DWORD 

Definition at line 40 of file Opcode.h.

Enumerator
AXES_XYZ 
AXES_XZY 
AXES_YXZ 
AXES_YZX 
AXES_ZXY 
AXES_ZYX 
AXES_FORCE_DWORD 

Definition at line 26 of file Opcode.h.

39  {
Enumerator
BS_NONE 
BS_GEMS 
BS_MINIBALL 
BS_FORCE_DWORD 

Definition at line 16 of file Opcode.h.

39  {
Enumerator
OPC_FIRST_CONTACT 

Report all contacts (false) or only first one (true)

OPC_TEMPORAL_COHERENCE 

Use temporal coherence or not.

OPC_CONTACT 

Final contact status after a collision query.

OPC_TEMPORAL_HIT 

There has been an early exit due to temporal coherence.

OPC_NO_PRIMITIVE_TESTS 

Keep or discard primitive-bv tests in leaf nodes (volume-mesh queries)

OPC_CONTACT_FOUND 
OPC_TEMPORAL_CONTACT 
OPC_FORCE_DWORD 

Definition at line 24 of file Opcode.h.

39  {
Enumerator
CULLMODE_NONE 
CULLMODE_CW 
CULLMODE_CCW 

Definition at line 26 of file Opcode.h.

39  {
Enumerator
OPC_QUANTIZED 

Compressed/uncompressed tree.

OPC_NO_LEAF 

Leaf/NoLeaf tree.

OPC_SINGLE_NODE 

Special case for 1-node models.

Definition at line 44 of file Opcode.h.

Enumerator
TRI_MINUS_SPACE 

Triangle is in the negative space.

TRI_PLUS_SPACE 

Triangle is in the positive space.

TRI_INTERSECT 

Triangle intersects plane.

TRI_ON_PLANE 

Triangle and plane are coplanar.

TRI_FORCEDWORD 

Definition at line 20 of file Opcode.h.

39  {
Enumerator
_X 
_Y 
_Z 
_W 
_FORCE_DWORD 

Definition at line 16 of file Opcode.h.

39  {

Tree splitting rules.

Enumerator
SPLIT_LARGEST_AXIS 

Split along the largest axis.

SPLIT_SPLATTER_POINTS 

Splatter primitive centers (QuickCD-style)

SPLIT_BEST_AXIS 

Try largest axis, then second, then last.

SPLIT_BALANCED 

Try to keep a well-balanced tree.

SPLIT_FIFTY 

Arbitrary 50-50 split.

SPLIT_GEOM_CENTER 

Split at geometric center (else split in the middle)

SPLIT_FORCE_DWORD 

Definition at line 25 of file Opcode.h.

39  {

Function Documentation

bool Opcode::BipartiteBoxPruning ( udword  nb0,
const AABB **  array0,
udword  nb1,
const AABB **  array1,
Pairs pairs,
const Axes axes 
)

Bipartite box pruning. Returns a list of overlapping pairs of boxes, each box of the pair belongs to a different set.

Parameters
nb0[in] number of boxes in the first set
array0[in] array of boxes for the first set
nb1[in] number of boxes in the second set
array1[in] array of boxes for the second set
pairs[out] array of overlapping pairs
axes[in] projection order (0,2,1 is often best)
Returns
true if success.

Definition at line 95 of file OPC_BoxPruning.cpp.

96 {
97  // Checkings
98  if(!nb0 || !array0 || !nb1 || !array1) return false;
99 
100  // Catch axes
101  udword Axis0 = axes.mAxis0;
102  udword Axis1 = axes.mAxis1;
103  udword Axis2 = axes.mAxis2;
104 
105  // Allocate some temporary data
106  float* MinPosList0 = new float[nb0];
107  float* MinPosList1 = new float[nb1];
108 
109  udword i;
110  // 1) Build main lists using the primary axis
111  for(i=0;i<nb0;i++) MinPosList0[i] = array0[i]->GetMin(Axis0);
112  for(i=0;i<nb1;i++) MinPosList1[i] = array1[i]->GetMin(Axis0);
113 
114  // 2) Sort the lists
117  const udword* Sorted0 = RS0->Sort(MinPosList0, nb0).GetRanks();
118  const udword* Sorted1 = RS1->Sort(MinPosList1, nb1).GetRanks();
119 
120  // 3) Prune the lists
121  udword Index0, Index1;
122 
123  const udword* const LastSorted0 = &Sorted0[nb0];
124  const udword* const LastSorted1 = &Sorted1[nb1];
125  const udword* RunningAddress0 = Sorted0;
126  const udword* RunningAddress1 = Sorted1;
127 
128  while(RunningAddress1<LastSorted1 && Sorted0<LastSorted0)
129  {
130  Index0 = *Sorted0++;
131 
132  while(RunningAddress1<LastSorted1 && MinPosList1[*RunningAddress1]<MinPosList0[Index0]) RunningAddress1++;
133 
134  const udword* RunningAddress2_1 = RunningAddress1;
135 
136  while(RunningAddress2_1<LastSorted1 && MinPosList1[Index1 = *RunningAddress2_1++]<=array0[Index0]->GetMax(Axis0))
137  {
138  if(array0[Index0]->Intersect(*array1[Index1], Axis1))
139  {
140  if(array0[Index0]->Intersect(*array1[Index1], Axis2))
141  {
142  pairs.AddPair(Index0, Index1);
143  }
144  }
145  }
146  }
147 
149 
150  while(RunningAddress0<LastSorted0 && Sorted1<LastSorted1)
151  {
152  Index0 = *Sorted1++;
153 
154  while(RunningAddress0<LastSorted0 && MinPosList0[*RunningAddress0]<=MinPosList1[Index0]) RunningAddress0++;
155 
156  const udword* RunningAddress2_0 = RunningAddress0;
157 
158  while(RunningAddress2_0<LastSorted0 && MinPosList0[Index1 = *RunningAddress2_0++]<=array1[Index0]->GetMax(Axis0))
159  {
160  if(array0[Index1]->Intersect(*array1[Index0], Axis1))
161  {
162  if(array0[Index1]->Intersect(*array1[Index0], Axis2))
163  {
164  pairs.AddPair(Index1, Index0);
165  }
166  }
167 
168  }
169  }
170 
171  DELETEARRAY(MinPosList1);
172  DELETEARRAY(MinPosList0);
173 
174  return true;
175 }
bool Opcode::BruteForceBipartiteBoxTest ( udword  nb0,
const AABB **  array0,
udword  nb1,
const AABB **  array1,
Pairs pairs 
)

Brute-force bipartite box pruning. Returns a list of overlapping pairs of boxes, each box of the pair belongs to a different set.

Parameters
nb0[in] number of boxes in the first set
array0[in] array of boxes for the first set
nb1[in] number of boxes in the second set
array1[in] array of boxes for the second set
pairs[out] array of overlapping pairs
Returns
true if success.

Definition at line 330 of file OPC_BoxPruning.cpp.

331 {
332  // Checkings
333  if(!nb0 || !array0 || !nb1 || !array1) return false;
334 
335  // Brute-force nb0*nb1 overlap tests
336  for(udword i=0;i<nb0;i++)
337  {
338  for(udword j=0;j<nb1;j++)
339  {
340  if(array0[i]->Intersect(*array1[j])) pairs.AddPair(i, j);
341  }
342  }
343  return true;
344 }
bool Opcode::BruteForceCompleteBoxTest ( udword  nb,
const AABB **  array,
Pairs pairs 
)

Complete box pruning. Returns a list of overlapping pairs of boxes, each box of the pair belongs to the same set.

Parameters
nb[in] number of boxes
array[in] array of boxes
pairs[out] array of overlapping pairs
Returns
true if success.

Definition at line 355 of file OPC_BoxPruning.cpp.

356 {
357  // Checkings
358  if(!nb || !array) return false;
359 
360  // Brute-force n(n-1)/2 overlap tests
361  for(udword i=0;i<nb;i++)
362  {
363  for(udword j=i+1;j<nb;j++)
364  {
365  if(array[i]->Intersect(*array[j])) pairs.AddPair(i, j);
366  }
367  }
368  return true;
369 }
bool Opcode::CompleteBoxPruning ( udword  nb,
const AABB **  array,
Pairs pairs,
const Axes axes 
)

Complete box pruning. Returns a list of overlapping pairs of boxes, each box of the pair belongs to the same set.

Parameters
nb[in] number of boxes
array[in] array of boxes
pairs[out] array of overlapping pairs
axes[in] projection order (0,2,1 is often best)
Returns
true if success.

Definition at line 190 of file OPC_BoxPruning.cpp.

Referenced by Opcode::SweepAndPrune::Init().

191 {
192  // Checkings
193  if(!nb || !array) return false;
194 
195  // Catch axes
196  udword Axis0 = axes.mAxis0;
197  udword Axis1 = axes.mAxis1;
198  udword Axis2 = axes.mAxis2;
199 
200 #ifdef ORIGINAL_VERSION
201  // Allocate some temporary data
202 // float* PosList = new float[nb];
203  float* PosList = new float[nb+1];
204 
205  // 1) Build main list using the primary axis
206  for(udword i=0;i<nb;i++) PosList[i] = array[i]->GetMin(Axis0);
207 PosList[nb++] = MAX_FLOAT;
208 
209  // 2) Sort the list
211  const udword* Sorted = RS->Sort(PosList, nb).GetRanks();
212 
213  // 3) Prune the list
214  const udword* const LastSorted = &Sorted[nb];
215  const udword* RunningAddress = Sorted;
216  udword Index0, Index1;
217  while(RunningAddress<LastSorted && Sorted<LastSorted)
218  {
219  Index0 = *Sorted++;
220 
221 // while(RunningAddress<LastSorted && PosList[*RunningAddress++]<PosList[Index0]);
222  while(PosList[*RunningAddress++]<PosList[Index0]);
223 
224  if(RunningAddress<LastSorted)
225  {
226  const udword* RunningAddress2 = RunningAddress;
227 
228 // while(RunningAddress2<LastSorted && PosList[Index1 = *RunningAddress2++]<=array[Index0]->GetMax(Axis0))
229  while(PosList[Index1 = *RunningAddress2++]<=array[Index0]->GetMax(Axis0))
230  {
231 // if(Index0!=Index1)
232 // {
233  if(array[Index0]->Intersect(*array[Index1], Axis1))
234  {
235  if(array[Index0]->Intersect(*array[Index1], Axis2))
236  {
237  pairs.AddPair(Index0, Index1);
238  }
239  }
240 // }
241  }
242  }
243  }
244 
245  DELETEARRAY(PosList);
246 #endif
247 
248 #ifdef JOAKIM
249  // Allocate some temporary data
250 // float* PosList = new float[nb];
251  float* MinList = new float[nb+1];
252 
253  // 1) Build main list using the primary axis
254  for(udword i=0;i<nb;i++) MinList[i] = array[i]->GetMin(Axis0);
255  MinList[nb] = MAX_FLOAT;
256 
257  // 2) Sort the list
259  udword* Sorted = RS->Sort(MinList, nb+1).GetRanks();
260 
261  // 3) Prune the list
262 // const udword* const LastSorted = &Sorted[nb];
263 // const udword* const LastSorted = &Sorted[nb-1];
264  const udword* RunningAddress = Sorted;
265  udword Index0, Index1;
266 
267 // while(RunningAddress<LastSorted && Sorted<LastSorted)
268 // while(RunningAddress<LastSorted)
269  while(RunningAddress<&Sorted[nb])
270 // while(Sorted<LastSorted)
271  {
272 // Index0 = *Sorted++;
273  Index0 = *RunningAddress++;
274 
275 // while(RunningAddress<LastSorted && PosList[*RunningAddress++]<PosList[Index0]);
276 // while(PosList[*RunningAddress++]<PosList[Index0]);
277 //RunningAddress = Sorted;
278 // if(RunningAddress<LastSorted)
279  {
280  const udword* RunningAddress2 = RunningAddress;
281 
282 // while(RunningAddress2<LastSorted && PosList[Index1 = *RunningAddress2++]<=array[Index0]->GetMax(Axis0))
283 
284 // float CurrentMin = array[Index0]->GetMin(Axis0);
285  float CurrentMax = array[Index0]->GetMax(Axis0);
286 
287  while(MinList[Index1 = *RunningAddress2] <= CurrentMax)
288 // while(PosList[Index1 = *RunningAddress] <= CurrentMax)
289  {
290 // if(Index0!=Index1)
291 // {
292  if(array[Index0]->Intersect(*array[Index1], Axis1))
293  {
294  if(array[Index0]->Intersect(*array[Index1], Axis2))
295  {
296  pairs.AddPair(Index0, Index1);
297  }
298  }
299 // }
300 
301  RunningAddress2++;
302 // RunningAddress++;
303  }
304  }
305  }
306 
307  DELETEARRAY(MinList);
308 #endif
309 
310  return true;
311 }
inline_ void Opcode::ComputeAABB ( AABB aabb,
const Point list,
udword  nb_pts 
)

Definition at line 491 of file Opcode.h.

inline_ void Opcode::ComputeLocalDirection ( Point local_dir,
const Point world_dir,
const Matrix4x4 world 
)

Transforms a direction vector from world space to local space

Parameters
local_dir[out] direction vector in local space
world_dir[in] direction vector in world space
world[in] world transform

Definition at line 60 of file Opcode.h.

inline_ void Opcode::ComputeLocalPoint ( Point local_pt,
const Point world_pt,
const Matrix4x4 world 
)

Transforms a position vector from world space to local space

Parameters
local_pt[out] position vector in local space
world_pt[in] position vector in world space
world[in] world transform

Definition at line 76 of file Opcode.h.

inline_ void Opcode::ComputeLocalRay ( Ray local_ray,
const Ray world_ray,
const Matrix4x4 world 
)

Transforms a ray from world space to local space

Parameters
local_ray[out] ray in local space
world_ray[in] ray in world space
world[in] world transform

Definition at line 92 of file Opcode.h.

inline_ void Opcode::ComputeMinMax ( const Point p,
Point min,
Point max 
)

Definition at line 479 of file Opcode.h.

inline_ void Opcode::ComputeReflexionVector ( Point reflected,
const Point incoming_dir,
const Point outward_normal 
)

Definition at line 35 of file Opcode.h.

39  {
inline_ void Opcode::ComputeReflexionVector ( Point reflected,
const Point source,
const Point impact,
const Point normal 
)

Definition at line 40 of file Opcode.h.

inline_ void Opcode::DecomposeVector ( Point normal_compo,
Point tangent_compo,
const Point outward_dir,
const Point outward_normal 
)

Definition at line 46 of file Opcode.h.

void Opcode::InvertPRMatrix ( Matrix4x4 dest,
const Matrix4x4 src 
)

Definition at line 56 of file IceMatrix4x4.cpp.

References Opcode::Matrix4x4::m.

Referenced by Picking().

57 {
58  dest.m[0][0] = src.m[0][0];
59  dest.m[1][0] = src.m[0][1];
60  dest.m[2][0] = src.m[0][2];
61  dest.m[3][0] = -(src.m[3][0]*src.m[0][0] + src.m[3][1]*src.m[0][1] + src.m[3][2]*src.m[0][2]);
62 
63  dest.m[0][1] = src.m[1][0];
64  dest.m[1][1] = src.m[1][1];
65  dest.m[2][1] = src.m[1][2];
66  dest.m[3][1] = -(src.m[3][0]*src.m[1][0] + src.m[3][1]*src.m[1][1] + src.m[3][2]*src.m[1][2]);
67 
68  dest.m[0][2] = src.m[2][0];
69  dest.m[1][2] = src.m[2][1];
70  dest.m[2][2] = src.m[2][2];
71  dest.m[3][2] = -(src.m[3][0]*src.m[2][0] + src.m[3][1]*src.m[2][1] + src.m[3][2]*src.m[2][2]);
72 
73  dest.m[0][3] = 0.0f;
74  dest.m[1][3] = 0.0f;
75  dest.m[2][3] = 0.0f;
76  dest.m[3][3] = 1.0f;
77 }
FUNCTION ICEMATHS_API void Opcode::Normalize1 ( Point a)
FUNCTION ICEMATHS_API void Opcode::Normalize2 ( Point a)
inline_ void Opcode::OPComputeMinMax ( Point min,
Point max,
const VertexPointers vp 
)

Definition at line 314 of file OPC_HybridModel.cpp.

References Opcode::Point::Max(), Opcode::Point::Min(), Opcode::VertexPointers::Vertex, Opcode::Point::x, Opcode::Point::y, and Opcode::Point::z.

315 {
316  // Compute triangle's AABB = a leaf box
317 #ifdef OPC_USE_FCOMI // a 15% speedup on my machine, not much
318  min.x = FCMin3(vp.Vertex[0]->x, vp.Vertex[1]->x, vp.Vertex[2]->x);
319  max.x = FCMax3(vp.Vertex[0]->x, vp.Vertex[1]->x, vp.Vertex[2]->x);
320 
321  min.y = FCMin3(vp.Vertex[0]->y, vp.Vertex[1]->y, vp.Vertex[2]->y);
322  max.y = FCMax3(vp.Vertex[0]->y, vp.Vertex[1]->y, vp.Vertex[2]->y);
323 
324  min.z = FCMin3(vp.Vertex[0]->z, vp.Vertex[1]->z, vp.Vertex[2]->z);
325  max.z = FCMax3(vp.Vertex[0]->z, vp.Vertex[1]->z, vp.Vertex[2]->z);
326 #else
327  min = *vp.Vertex[0];
328  max = *vp.Vertex[0];
329  min.Min(*vp.Vertex[1]);
330  max.Max(*vp.Vertex[1]);
331  min.Min(*vp.Vertex[2]);
332  max.Max(*vp.Vertex[2]);
333 #endif
334 }
OPCODE_API bool Opcode::Picking ( CollisionFace picked_face,
const Ray world_ray,
const Model model,
const Matrix4x4 world,
float  min_dist,
float  max_dist,
const Point view_point,
CullModeCallback  callback,
void *  user_data 
)

Definition at line 87 of file OPC_Picking.cpp.

References Opcode::VertexPointers::BackfaceCulling(), Opcode::RayCollider::Collide(), CULLMODE_CCW, CULLMODE_CW, CULLMODE_NONE, Opcode::BaseModel::GetMeshInterface(), INVALID_ID, InvertPRMatrix(), MAX_FLOAT, Opcode::CollisionFace::mDistance, Opcode::CollisionFace::mFaceID, Opcode::CollisionFace::mU, Opcode::CollisionFace::mV, Opcode::RayCollider::SetCulling(), Opcode::Collider::SetFirstContact(), Opcode::RayCollider::SetHitCallback(), Opcode::RayCollider::SetMaxDist(), Opcode::Collider::SetTemporalCoherence(), and Opcode::RayCollider::SetUserData().

91 {
92  struct Local
93  {
94  struct CullData
95  {
96  CollisionFace* Closest;
97  float MinLimit;
98  CullModeCallback Callback;
99  void* UserData;
100  Point ViewPoint;
101  const MeshInterface* IMesh;
102  };
103 
104  // Called for each stabbed face
105  static void RenderCullingCallback(const CollisionFace& hit, void* user_data)
106  {
107  CullData* Data = (CullData*)user_data;
108 
109  // Discard face if we already have a closer hit
110  if(hit.mDistance>=Data->Closest->mDistance) return;
111 
112  // Discard face if hit point is smaller than min limit. This mainly happens when the face is in front
113  // of the near clip plane (or straddles it). If we keep the face nonetheless, the user can select an
114  // object that he may not even be able to see, which is very annoying.
115  if(hit.mDistance<=Data->MinLimit) return;
116 
117  // This is the index of currently stabbed triangle.
118  udword StabbedFaceIndex = hit.mFaceID;
119 
120  // We may keep it or not, depending on backface culling
121  bool KeepIt = true;
122 
123  // Catch *render* cull mode for this face
124  CullMode CM = (Data->Callback)(StabbedFaceIndex, Data->UserData);
125 
126  if(CM!=CULLMODE_NONE) // Don't even compute culling for double-sided triangles
127  {
128  // Compute backface culling for current face
129 
130  VertexPointers VP;
131  Data->IMesh->GetTriangle(VP, StabbedFaceIndex);
132  if(VP.BackfaceCulling(Data->ViewPoint))
133  {
134  if(CM==CULLMODE_CW) KeepIt = false;
135  }
136  else
137  {
138  if(CM==CULLMODE_CCW) KeepIt = false;
139  }
140  }
141 
142  if(KeepIt) *Data->Closest = hit;
143  }
144  };
145 
146  RayCollider RC;
147  RC.SetMaxDist(max_dist);
148  RC.SetTemporalCoherence(false);
149  RC.SetCulling(false); // We need all faces since some of them can be double-sided
150  RC.SetFirstContact(false);
151  RC.SetHitCallback(Local::RenderCullingCallback);
152 
153  picked_face.mFaceID = INVALID_ID;
154  picked_face.mDistance = MAX_FLOAT;
155  picked_face.mU = 0.0f;
156  picked_face.mV = 0.0f;
157 
158  Local::CullData Data;
159  Data.Closest = &picked_face;
160  Data.MinLimit = min_dist;
161  Data.Callback = callback;
162  Data.UserData = user_data;
163  Data.ViewPoint = view_point;
164  Data.IMesh = model.GetMeshInterface();
165 
166  if(world)
167  {
168  // Get matrices
169  Matrix4x4 InvWorld;
170  InvertPRMatrix(InvWorld, *world);
171 
172  // Compute camera position in mesh space
173  Data.ViewPoint *= InvWorld;
174  }
175 
176  RC.SetUserData(&Data);
177  if(RC.Collide(world_ray, model, world))
178  {
179  return picked_face.mFaceID!=INVALID_ID;
180  }
181  return false;
182 }
OPCODE_API bool Opcode::SetupAllHits ( RayCollider collider,
CollisionFaces contacts 
)

Definition at line 37 of file OPC_Picking.cpp.

References Opcode::CollisionFaces::AddFace(), Opcode::Collider::SetFirstContact(), Opcode::RayCollider::SetHitCallback(), and Opcode::RayCollider::SetUserData().

38 {
39  struct Local
40  {
41  static void AllContacts(const CollisionFace& hit, void* user_data)
42  {
43  CollisionFaces* CF = (CollisionFaces*)user_data;
44  CF->AddFace(hit);
45  }
46  };
47 
48  collider.SetFirstContact(false);
49  collider.SetHitCallback(Local::AllContacts);
50  collider.SetUserData(&contacts);
51  return true;
52 }
OPCODE_API bool Opcode::SetupClosestHit ( RayCollider collider,
CollisionFace closest_contact 
)

Definition at line 54 of file OPC_Picking.cpp.

References MAX_FLOAT, Opcode::CollisionFace::mDistance, Opcode::Collider::SetFirstContact(), Opcode::RayCollider::SetHitCallback(), and Opcode::RayCollider::SetUserData().

55 {
56  struct Local
57  {
58  static void ClosestContact(const CollisionFace& hit, void* user_data)
59  {
60  CollisionFace* CF = (CollisionFace*)user_data;
61  if(hit.mDistance<CF->mDistance) *CF = hit;
62  }
63  };
64 
65  collider.SetFirstContact(false);
66  collider.SetHitCallback(Local::ClosestContact);
67  collider.SetUserData(&closest_contact);
68  closest_contact.mDistance = MAX_FLOAT;
69  return true;
70 }
OPCODE_API bool Opcode::SetupInOutTest ( RayCollider collider)

Definition at line 79 of file OPC_Picking.cpp.

References null, Opcode::Collider::SetFirstContact(), and Opcode::RayCollider::SetHitCallback().

80 {
81  collider.SetFirstContact(false);
82  collider.SetHitCallback(null);
83  // Results with collider.GetNbIntersections()
84  return true;
85 }
OPCODE_API bool Opcode::SetupShadowFeeler ( RayCollider collider)

Definition at line 72 of file OPC_Picking.cpp.

References null, Opcode::Collider::SetFirstContact(), and Opcode::RayCollider::SetHitCallback().

73 {
74  collider.SetFirstContact(true);
75  collider.SetHitCallback(null);
76  return true;
77 }
inline_ void Opcode::TransformPlane ( Plane transformed,
const Plane plane,
const Matrix4x4 transform 
)

Transforms a plane by a 4x4 matrix. Same as Plane * Matrix4x4 operator, but faster.

Parameters
transformed[out] transformed plane
plane[in] source plane
transform[in] transform matrix
Warning
the plane normal must be unit-length

Definition at line 88 of file Opcode.h.

inline_ void Opcode::TransformPlane ( Plane plane,
const Matrix4x4 transform 
)

Transforms a plane by a 4x4 matrix. Same as Plane * Matrix4x4 operator, but faster.

Parameters
plane[in/out] source plane (transformed on return)
transform[in] transform matrix
Warning
the plane normal must be unit-length

Definition at line 105 of file Opcode.h.

inline_ void Opcode::TransformPoint ( Point dest,
const Point source,
const Matrix3x3 rot,
const Point trans 
)

Quickly rotates & translates a vector.

Definition at line 95 of file Opcode.h.

inline_ void Opcode::TransformPoint3x3 ( Point dest,
const Point source,
const Matrix4x4 rot 
)

Quickly rotates a vector, using the 3x3 part of a 4x4 matrix.

Definition at line 446 of file Opcode.h.

inline_ void Opcode::TransformPoint4x3 ( Point dest,
const Point source,
const Matrix4x4 rot 
)

Quickly rotates & translates a vector, using the 4x3 part of a 4x4 matrix.

Definition at line 438 of file Opcode.h.

Variable Documentation

const float Opcode::EPSILON2 = 1.0e-20f

Definition at line 24 of file Opcode.h.