////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// * Initializes a collision query : * - reset stats & contact status * - compute planes in model space * - check temporal coherence * * \param cache [in/out] a planes cache * \param planes [in] lis
| 174 | */ |
| 175 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
| 176 | BOOL PlanesCollider::InitQuery(PlanesCache& cache, const Plane* planes, udword nb_planes, const Matrix4x4* worldm) |
| 177 | { |
| 178 | // 1) Call the base method |
| 179 | VolumeCollider::InitQuery(); |
| 180 | |
| 181 | // 2) Compute planes in model space |
| 182 | if(nb_planes>mNbPlanes) |
| 183 | { |
| 184 | DELETEARRAY(mPlanes); |
| 185 | mPlanes = new Plane[nb_planes]; |
| 186 | } |
| 187 | mNbPlanes = nb_planes; |
| 188 | |
| 189 | if(worldm) |
| 190 | { |
| 191 | Matrix4x4 InvWorldM; |
| 192 | InvertPRMatrix(InvWorldM, *worldm); |
| 193 | |
| 194 | // for(udword i=0;i<nb_planes;i++) mPlanes[i] = planes[i] * InvWorldM; |
| 195 | for(udword i=0;i<nb_planes;i++) TransformPlane(mPlanes[i], planes[i], InvWorldM); |
| 196 | } |
| 197 | else CopyMemory(mPlanes, planes, nb_planes*sizeof(Plane)); |
| 198 | |
| 199 | // 3) Setup destination pointer |
| 200 | mTouchedPrimitives = &cache.TouchedPrimitives; |
| 201 | |
| 202 | // 4) Special case: 1-triangle meshes [Opcode 1.3] |
| 203 | if(mCurrentModel && mCurrentModel->HasSingleNode()) |
| 204 | { |
| 205 | if(!SkipPrimitiveTests()) |
| 206 | { |
| 207 | // We simply perform the BV-Prim overlap test each time. We assume single triangle has index 0. |
| 208 | mTouchedPrimitives->Reset(); |
| 209 | |
| 210 | // Perform overlap test between the unique triangle and the planes (and set contact status if needed) |
| 211 | udword clip_mask = (1<<mNbPlanes)-1; |
| 212 | PLANES_PRIM(udword(0), OPC_CONTACT) |
| 213 | |
| 214 | // Return immediately regardless of status |
| 215 | return TRUE; |
| 216 | } |
| 217 | } |
| 218 | |
| 219 | // 4) Check temporal coherence: |
| 220 | if(TemporalCoherenceEnabled()) |
| 221 | { |
| 222 | // Here we use temporal coherence |
| 223 | // => check results from previous frame before performing the collision query |
| 224 | if(FirstContactEnabled()) |
| 225 | { |
| 226 | // We're only interested in the first contact found => test the unique previously touched face |
| 227 | if(mTouchedPrimitives->GetNbEntries()) |
| 228 | { |
| 229 | // Get index of previously touched face = the first entry in the array |
| 230 | udword PreviouslyTouchedFace = mTouchedPrimitives->GetEntry(0); |
| 231 | |
| 232 | // Then reset the array: |
| 233 | // - if the overlap test below is successful, the index we'll get added back anyway |
nothing calls this directly
no test coverage detected