MCPcopy Create free account
hub / github.com/TorqueGameEngines/Torque3D / InitQuery

Method InitQuery

Engine/lib/opcode/OPC_AABBCollider.cpp:155–249  ·  view source on GitHub ↗

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// * Initializes a collision query : * - reset stats & contact status * - check temporal coherence * * \param cache [in/out] a box cache * \param box [in] AABB in world space * \return TRUE if we

Source from the content-addressed store, hash-verified

153 */
154///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
155BOOL AABBCollider::InitQuery(AABBCache& cache, const CollisionAABB& box)
156{
157 // 1) Call the base method
158 VolumeCollider::InitQuery();
159
160 // 2) Keep track of the query box
161 mBox = box;
162
163 // 3) Setup destination pointer
164 mTouchedPrimitives = &cache.TouchedPrimitives;
165
166 // 4) Special case: 1-triangle meshes [Opcode 1.3]
167 if(mCurrentModel && mCurrentModel->HasSingleNode())
168 {
169 if(!SkipPrimitiveTests())
170 {
171 // We simply perform the BV-Prim overlap test each time. We assume single triangle has index 0.
172 mTouchedPrimitives->Reset();
173
174 // Perform overlap test between the unique triangle and the box (and set contact status if needed)
175 AABB_PRIM(udword(0), OPC_CONTACT)
176
177 // Return immediately regardless of status
178 return TRUE;
179 }
180 }
181
182 // 5) Check temporal coherence :
183 if(TemporalCoherenceEnabled())
184 {
185 // Here we use temporal coherence
186 // => check results from previous frame before performing the collision query
187 if(FirstContactEnabled())
188 {
189 // We're only interested in the first contact found => test the unique previously touched face
190 if(mTouchedPrimitives->GetNbEntries())
191 {
192 // Get index of previously touched face = the first entry in the array
193 udword PreviouslyTouchedFace = mTouchedPrimitives->GetEntry(0);
194
195 // Then reset the array:
196 // - if the overlap test below is successful, the index we'll get added back anyway
197 // - if it isn't, then the array should be reset anyway for the normal query
198 mTouchedPrimitives->Reset();
199
200 // Perform overlap test between the cached triangle and the box (and set contact status if needed)
201 AABB_PRIM(PreviouslyTouchedFace, OPC_TEMPORAL_CONTACT)
202
203 // Return immediately if possible
204 if(GetContactStatus()) return TRUE;
205 }
206 // else no face has been touched during previous query
207 // => we'll have to perform a normal query
208 }
209 else
210 {
211 // We're interested in all contacts =>test the new real box N(ew) against the previous fat box P(revious):
212 if(IsCacheValid(cache) && mBox.IsInside(cache.FatBox))

Callers

nothing calls this directly

Calls 9

SkipPrimitiveTestsFunction · 0.85
TemporalCoherenceEnabledFunction · 0.85
FirstContactEnabledFunction · 0.85
GetContactStatusFunction · 0.85
IsCacheValidFunction · 0.85
GetEntryMethod · 0.80
InitQueryFunction · 0.70
ResetMethod · 0.45
IsInsideMethod · 0.45

Tested by

no test coverage detected