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

Method InitQuery

Engine/lib/opcode/OPC_SphereCollider.cpp:165–272  ·  view source on GitHub ↗

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// * Initializes a collision query : * - reset stats & contact status * - setup matrices * - check temporal coherence * * \param cache [in/out] a sphere cache * \param sphere [in] sphere in local sp

Source from the content-addressed store, hash-verified

163 */
164///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
165BOOL SphereCollider::InitQuery(SphereCache& cache, const Sphere& sphere, const Matrix4x4* worlds, const Matrix4x4* worldm)
166{
167 // 1) Call the base method
168 VolumeCollider::InitQuery();
169
170 // 2) Compute sphere in model space:
171 // - Precompute R^2
172 mRadius2 = sphere.mRadius * sphere.mRadius;
173 // - Compute center position
174 mCenter = sphere.mCenter;
175 // -> to world space
176 if(worlds) mCenter *= *worlds;
177 // -> to model space
178 if(worldm)
179 {
180 // Invert model matrix
181 Matrix4x4 InvWorldM;
182 InvertPRMatrix(InvWorldM, *worldm);
183
184 mCenter *= InvWorldM;
185 }
186
187 // 3) Setup destination pointer
188 mTouchedPrimitives = &cache.TouchedPrimitives;
189
190 // 4) Special case: 1-triangle meshes [Opcode 1.3]
191 if(mCurrentModel && mCurrentModel->HasSingleNode())
192 {
193 if(!SkipPrimitiveTests())
194 {
195 // We simply perform the BV-Prim overlap test each time. We assume single triangle has index 0.
196 mTouchedPrimitives->Reset();
197
198 // Perform overlap test between the unique triangle and the sphere (and set contact status if needed)
199 SPHERE_PRIM(udword(0), OPC_CONTACT)
200
201 // Return immediately regardless of status
202 return TRUE;
203 }
204 }
205
206 // 5) Check temporal coherence :
207 if(TemporalCoherenceEnabled())
208 {
209 // Here we use temporal coherence
210 // => check results from previous frame before performing the collision query
211 if(FirstContactEnabled())
212 {
213 // We're only interested in the first contact found => test the unique previously touched face
214 if(mTouchedPrimitives->GetNbEntries())
215 {
216 // Get index of previously touched face = the first entry in the array
217 udword PreviouslyTouchedFace = mTouchedPrimitives->GetEntry(0);
218
219 // Then reset the array:
220 // - if the overlap test below is successful, the index we'll get added back anyway
221 // - if it isn't, then the array should be reset anyway for the normal query
222 mTouchedPrimitives->Reset();

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
SquareDistanceMethod · 0.45

Tested by

no test coverage detected