HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SIM_SweptCollision.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  * (In contrast, static collision detection techniques only test
7  * for penetrations and proximities at a fixed point in time, which allows
8  * points to tunnel through polygons undetected.)
9  *
10  * This swept-collision code is used by DOPS, but it does not depend
11  * on DOPS. For example, it does not know about SIM_Geometry or SIM_Object.
12  * Therefore, it should be easy to re-use this code in another place,
13  * for example POPs.
14  */
15 
16 #ifndef __SIM_SweptCollision_h__
17 #define __SIM_SweptCollision_h__
18 
19 #include "SIM_API.h"
20 #include "SIM_SweptCollisionData.h"
21 #include <UT/UT_Vector3.h>
22 #include <GA/GA_PageHandle.h>
23 #include <GA/GA_Handle.h>
24 #include <GA/GA_Range.h>
25 #include <vector>
26 
27 class SIM_Object;
28 class SIM_Impacts;
29 class GU_Detail;
30 
32 {
33 public:
35  SIM_Impacts*const impacts_a,
36  const int impact_flags_a,
37  const GU_Detail*const gdp_a,
38 
39  const std::vector<SIM_Impacts*>* impacts_b,
40  const int impact_flags_b,
41  const std::vector<const SIM_Object*>& undated_objects_b,
42  const SIM_TriangleConnectivity& triangles_b
43  );
44 
45  // Apply opposite and equal impulses to A and B,
46  // where A is a point and B is a position on a triangle.
47  // pof_a is a valid point offset for 'gdp_a'
48  // b is a valid index of a triangle of 'triangles_b'
49  void addPointTriangleImpulsePair(
50  const GA_Offset pof_a,
51  const UT_Vector3D& ra,
52 
53  const exint b,
54  const fpreal64 barys_b[3],
55 
56  const UT_Vector3D& impulse_direction,
57  const fpreal64 impulse_magnitude,
58  const fpreal64 t
59  );
60 
61 private:
62  SIM_Impacts*const impacts_a_;
63  const int impact_flags_a_;
64  const GU_Detail*const gdp_a_;
65 
66  const std::vector<SIM_Impacts*>* impacts_b_;
67  const int impact_flags_b_;
68  const std::vector<const SIM_Object*>& undated_objects_b_;
69  const SIM_TriangleConnectivity& triangles_b_;
70 
71  // Disallow
75 };
76 
77 // The function SIMdetectAndResolveCollisions can be used
78 // for one-way collision detection and collision resolution.
79 // Only the positions of a are modified to avoid collisions.
80 //
81 // Given linear trajectories of a set of points a, and a set
82 // of triangles b between times t_start and t_end,
83 // find modified positions for a such that the trajectories
84 // of a and b are collision free between t_start and t_end.
85 // "Collision free" means that the points of a don't
86 // intersect any of the triangles of b during a linear sweep
87 // from t_start to t_end.
88 // In addition, find a "projected" end velocity that
89 // makes the time-derivatives of the contact distances
90 // non-negative (as much as possible).
91 //
92 // Thickness is a diameter, not radius measure, so matches
93 // the behaviour of pscale.
94 //
95 // The optional "impact_acculumator" receives all the impacts
96 // that were applied to make A's point trajectories collision free.
97 // NOTE: this is fragile, this depends on the impulses being
98 // applied in exactly the right way. This is an architectural problem.
99 // In some uses cases, the end positions can't be changed directly here.
100 //
101 extern bool SIM_API
103  SIM_SweptCollisionImpactAccumulator*const impact_acculumator,
104 
105  // A Topology
106  GA_Range range_a,
107  GA_RWPageHandleV3 &position_points_a_resolved_end,
108  GA_RWPageHandleV3 &velocity_points_a_resolved_end,
109  GA_ROPageHandleF &thickness_points_a,
110  GA_ROPageHandleF &mass_points_a,
111  GA_ROPageHandleF &bounce_points_a,
112  GA_ROPageHandleF &friction_points_a,
113  GA_ROPageHandleF &bounceforward_points_a,
114  GA_RWPageHandleV3 &position_points_a_start,
115  bool pscaleisradius,
116 
117  // B Topology
118  const SIM_TriangleConnectivity& triangles_b,
119  const std::vector<fpreal32>& thickness_points_b,
120  const std::vector<fpreal32>& bounce_points_b,
121  const std::vector<fpreal32>& friction_points_b,
122  const std::vector<fpreal32>& bounceforward_points_b,
123  const SIM_PositionPoints& position_points_b_start,
124  const SIM_PositionPoints& position_points_b_end,
125  const SIM_VelocityPoints& velocity_points_b_end,
126 
127  // Timing
128  const fpreal64 t_start,
129  const fpreal64 t_end
130 );
131 
132 extern bool SIM_API
134  // A Topology
135  GA_Range range_a,
136  GA_RWPageHandleV3 &position_points_a_resolved_end,
137  GA_ROPageHandleF &thickness_points_a,
138  GA_RWPageHandleV3 &position_points_a_start,
139  bool pscaleisradius,
140 
141  // B Topology
142  const SIM_TriangleConnectivity& triangles_b,
143  const std::vector<fpreal32>& thickness_points_b,
144  const SIM_PositionPoints& position_points_b_start,
145  const SIM_PositionPoints& position_points_b_end,
146 
147  // Timing
148  const fpreal64 t_start,
149  const fpreal64 t_end,
150 
151  // Results
152  GA_RWHandleI &hitnum_a,
153  GA_RWHandleV3 &hitpos_a,
154  GA_RWHandleV3 &hitnml_a,
155  GA_RWHandleF &hittime_a,
156  GA_RWHandleS &hitpath_a,
157  GA_RWHandleI &hitprim_a,
158  GA_RWHandleV3 &hituv_a,
159  GA_RWHandleV3 &hitvel_a
160 );
161 
162 #endif
Read-Write string handle.
Definition: GA_Handle.h:833
A range of elements in an index-map.
Definition: GA_Range.h:42
bool SIM_API SIMdetectAndResolveCollisions(SIM_SweptCollisionImpactAccumulator *const impact_acculumator, GA_Range range_a, GA_RWPageHandleV3 &position_points_a_resolved_end, GA_RWPageHandleV3 &velocity_points_a_resolved_end, GA_ROPageHandleF &thickness_points_a, GA_ROPageHandleF &mass_points_a, GA_ROPageHandleF &bounce_points_a, GA_ROPageHandleF &friction_points_a, GA_ROPageHandleF &bounceforward_points_a, GA_RWPageHandleV3 &position_points_a_start, bool pscaleisradius, const SIM_TriangleConnectivity &triangles_b, const std::vector< fpreal32 > &thickness_points_b, const std::vector< fpreal32 > &bounce_points_b, const std::vector< fpreal32 > &friction_points_b, const std::vector< fpreal32 > &bounceforward_points_b, const SIM_PositionPoints &position_points_b_start, const SIM_PositionPoints &position_points_b_end, const SIM_VelocityPoints &velocity_points_b_end, const fpreal64 t_start, const fpreal64 t_end)
GA_Size GA_Offset
Definition: GA_Types.h:617
int64 exint
Definition: SYS_Types.h:116
double fpreal64
Definition: SYS_Types.h:192
GLboolean GLboolean GLboolean b
Definition: glcorearb.h:1221
#define SIM_API
Definition: SIM_API.h:10
std::vector< SIM_PositionPoint > SIM_PositionPoints
std::vector< SIM_VelocityPoint > SIM_VelocityPoints
bool SIM_API SIMdetectCollisions(GA_Range range_a, GA_RWPageHandleV3 &position_points_a_resolved_end, GA_ROPageHandleF &thickness_points_a, GA_RWPageHandleV3 &position_points_a_start, bool pscaleisradius, const SIM_TriangleConnectivity &triangles_b, const std::vector< fpreal32 > &thickness_points_b, const SIM_PositionPoints &position_points_b_start, const SIM_PositionPoints &position_points_b_end, const fpreal64 t_start, const fpreal64 t_end, GA_RWHandleI &hitnum_a, GA_RWHandleV3 &hitpos_a, GA_RWHandleV3 &hitnml_a, GA_RWHandleF &hittime_a, GA_RWHandleS &hitpath_a, GA_RWHandleI &hitprim_a, GA_RWHandleV3 &hituv_a, GA_RWHandleV3 &hitvel_a)