public void cast(CollisionWorld cw) { #if USE_BT_CLOCK frame_timer.reset(); #endif //USE_BT_CLOCK #if BATCH_RAYCASTER if (gBatchRaycaster == null) { return; } gBatchRaycaster.clearRays(); for (int i = 0; i < NUMRAYS_IN_BAR; i++) { gBatchRaycaster.addRay(source[i], dest[i]); } gBatchRaycaster.performBatchRaycast(); for (int i = 0; i < gBatchRaycaster.getNumRays(); i++) { const SpuRaycastTaskWorkUnitOut& outResult = (*gBatchRaycaster)[i]; hit[i].setInterpolate3(source[i], dest[i], outResult.hitFraction); normal[i] = outResult.hitNormal; normal[i] = normal[i].Normalize(); } #else for (int i = 0; i < NUMRAYS_IN_BAR; i++) { ClosestRayResultCallback cb = new ClosestRayResultCallback(source[i], dest[i]); cw.RayTest(ref source[i], ref dest[i], cb); if (cb.HasHit()) { hit[i] = cb.m_hitPointWorld; normal[i] = cb.m_hitNormalWorld; normal[i] = IndexedVector3.Normalize(normal[i]); } else { hit[i] = dest[i]; normal[i] = new IndexedVector3(1.0f, 0.0f, 0.0f); } } #if USE_BT_CLOCK ms += frame_timer.getTimeMilliseconds(); #endif //USE_BT_CLOCK frame_counter++; if (frame_counter > 50) { min_ms = ms < min_ms ? ms : min_ms; max_ms = ms > max_ms ? ms : max_ms; sum_ms += ms; sum_ms_samples++; float mean_ms = (float)sum_ms / (float)sum_ms_samples; //printf("%d rays in %d ms %d %d %f\n", NUMRAYS_IN_BAR * frame_counter, ms, min_ms, max_ms, mean_ms); ms = 0; frame_counter = 0; } #endif }
public virtual Object CastRay(ref IndexedVector3 from, ref IndexedVector3 to, ref VehicleRaycasterResult result) { // RayResultCallback& resultCallback; ClosestRayResultCallback rayCallback = new ClosestRayResultCallback(ref from, ref to); m_dynamicsWorld.RayTest(ref from, ref to, rayCallback); if (rayCallback.HasHit()) { RigidBody body = RigidBody.Upcast(rayCallback.m_collisionObject); if (body != null && body.HasContactResponse()) { result.m_hitPointInWorld = rayCallback.m_hitPointWorld; result.m_hitNormalInWorld = rayCallback.m_hitNormalWorld; result.m_hitNormalInWorld.Normalize(); result.m_distFraction = rayCallback.m_closestHitFraction; return(body); } } else { int ibreak = 0; ClosestRayResultCallback rayCallback2 = new ClosestRayResultCallback(ref from, ref to); m_dynamicsWorld.RayTest(ref from, ref to, rayCallback2); } rayCallback.Cleanup(); return(null); }
public bool RayCastSingle(Vector3 from, Vector3 to, int filterMask, int filterGroup, ref Vector3 contactPoint, ref Vector3 contactNormal) { bool hasHit = false; ClosestRayResultCallback callback = new ClosestRayResultCallback(from, to); callback.m_collisionFilterGroup = (CollisionFilterGroups)filterGroup; callback.m_collisionFilterMask = (CollisionFilterGroups)filterMask; hasHit = callback.HasHit(); if (hasHit) { contactPoint = callback.m_hitPointWorld; contactNormal = callback.m_hitPointWorld; } return(hasHit); }