| 336 | } |
| 337 | |
| 338 | Point3F TSShapeInstance::support(const Point3F & v, S32 dl) |
| 339 | { |
| 340 | // if dl==-1, nothing to do |
| 341 | AssertFatal(dl != -1, "Error, should never try to collide with a non-existant detail level!"); |
| 342 | AssertFatal(dl>=0 && dl<mShape->details.size(),"TSShapeInstance::support"); |
| 343 | |
| 344 | // get subshape and object detail |
| 345 | const TSDetail * detail = &mShape->details[dl]; |
| 346 | S32 ss = detail->subShapeNum; |
| 347 | S32 od = detail->objectDetailNum; |
| 348 | |
| 349 | S32 start = mShape->subShapeFirstObject[ss]; |
| 350 | S32 end = mShape->subShapeNumObjects[ss] + start; |
| 351 | |
| 352 | F32 currMaxDP = -1e9f; |
| 353 | Point3F currSupport = Point3F(0, 0, 0); |
| 354 | const MatrixF * previousMat = NULL; |
| 355 | MatrixF mat; |
| 356 | if (start<end) |
| 357 | { |
| 358 | Point3F va; |
| 359 | |
| 360 | // set up for first object's node |
| 361 | previousMat = &mMeshObjects[start].getTransform(); |
| 362 | mat = *previousMat; |
| 363 | mat.inverse(); |
| 364 | |
| 365 | // run through objects and collide |
| 366 | for (S32 i=start; i<end; i++) |
| 367 | { |
| 368 | MeshObjectInstance * mesh = &mMeshObjects[i]; |
| 369 | |
| 370 | if (od >= mesh->object->numMeshes) |
| 371 | continue; |
| 372 | |
| 373 | TSMesh* physMesh = mesh->getMesh(od); |
| 374 | if (physMesh && !mesh->forceHidden && mesh->visible > 0.01f) |
| 375 | { |
| 376 | // collide... |
| 377 | if (&mesh->getTransform() != previousMat) |
| 378 | { |
| 379 | // different node from before, set up for this node |
| 380 | previousMat = &mesh->getTransform(); |
| 381 | mat = *previousMat; |
| 382 | mat.inverse(); |
| 383 | } |
| 384 | mat.mulV(v, &va); |
| 385 | physMesh->support(mesh->frame, va, &currMaxDP, &currSupport); |
| 386 | } |
| 387 | } |
| 388 | } |
| 389 | |
| 390 | if (currMaxDP != -1e9f) |
| 391 | { |
| 392 | previousMat->mulP(currSupport); |
| 393 | return currSupport; |
| 394 | } |
| 395 | else |