MCPcopy Create free account
hub / github.com/bulletphysics/bullet3 / cast

Method cast

examples/Heightfield/HeightfieldExample.cpp:982–1037  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

980 };
981
982 void cast(btCollisionWorld* cw, bool multiThreading = false)
983 {
984 BT_PROFILE("cast");
985
986#ifdef USE_BT_CLOCK
987 frame_timer.reset();
988#endif //USE_BT_CLOCK
989
990#ifdef BATCH_RAYCASTER
991 if (!gBatchRaycaster)
992 return;
993
994 gBatchRaycaster->clearRays();
995 for (int i = 0; i < NUMRAYS; i++)
996 {
997 gBatchRaycaster->addRay(source[i], dest[i]);
998 }
999 gBatchRaycaster->performBatchRaycast();
1000 for (int i = 0; i < gBatchRaycaster->getNumRays(); i++)
1001 {
1002 const SpuRaycastTaskWorkUnitOut& out = (*gBatchRaycaster)[i];
1003 hit[i].setInterpolate3(source[i], dest[i], out.hitFraction);
1004 normal[i] = out.hitNormal;
1005 normal[i].normalize();
1006 }
1007#else
1008#if USE_PARALLEL_RAYCASTS
1009 if (multiThreading)
1010 {
1011 CastRaysLoopBody rayLooper(cw, this);
1012 int grainSize = 20; // number of raycasts per task
1013 btParallelFor(0, NUMRAYS2, grainSize, rayLooper);
1014 }
1015 else
1016#endif // USE_PARALLEL_RAYCASTS
1017 {
1018 // single threaded
1019 castRays(cw, 0, NUMRAYS2);
1020 }
1021#ifdef USE_BT_CLOCK
1022 ms += frame_timer.getTimeMilliseconds();
1023#endif //USE_BT_CLOCK
1024 frame_counter++;
1025 if (frame_counter > 50)
1026 {
1027 min_ms = ms < min_ms ? ms : min_ms;
1028 max_ms = ms > max_ms ? ms : max_ms;
1029 sum_ms += ms;
1030 sum_ms_samples++;
1031 btScalar mean_ms = (btScalar)sum_ms / (btScalar)sum_ms_samples;
1032 printf("%d rays in %d ms %d %d %f\n", NUMRAYS2 * frame_counter, ms, min_ms, max_ms, mean_ms);
1033 ms = 0;
1034 frame_counter = 0;
1035 }
1036#endif
1037 }
1038
1039 void draw()

Callers 1

castRaysMethod · 0.45

Calls 4

btParallelForFunction · 0.85
resetMethod · 0.45
normalizeMethod · 0.45
getTimeMillisecondsMethod · 0.45

Tested by

no test coverage detected