/// Perform a ray-hit test with the collision models. public override bool RayHit(ChVector from, ChVector to, ChCollisionModel model, ref ChRayhitResult mresult) { return(RayHit(from, to, model, ref mresult, CollisionFilterGroups.DefaultFilter, CollisionFilterGroups.AllFilter)); }
/// Removes a collision model from the collision /// engine (custom data may be deallocated). public override void Remove(ChCollisionModel model) { if (((ChModelBullet)model).GetBulletModel().GetCollisionShape() != null) { bt_collision_world.RemoveCollisionObject(((ChModelBullet)model).GetBulletModel()); } }
/// Adds a collision model to the collision /// engine (custom data may be allocated). public override void Add(ChCollisionModel model) { if (((ChModelBullet)model).GetBulletModel().GetCollisionShape() != null) { model.SyncPosition(); bt_collision_world.AddCollisionObject(((ChModelBullet)model).GetBulletModel(), (CollisionFilterGroups)((ChModelBullet)model).GetFamilyGroup(), (CollisionFilterGroups)((ChModelBullet)model).GetFamilyMask()); } }
public float[] reaction_cache; //< pointer to some persistent user cache of reactions /// Basic default constructor. public ChCollisionInfo() { modelA = null; modelB = null; vpA = new ChVector(0, 0, 0); vpB = new ChVector(0, 0, 0); vN = new ChVector(1, 0, 0); distance = 0; eff_radius = default_eff_radius; reaction_cache = null; }
/// Perform a ray-hit test with the specified collision model. public override bool RayHit(ChVector from, ChVector to, ChCollisionModel model, ref ChRayhitResult mresult, CollisionFilterGroups filter_group, CollisionFilterGroups filter_mask) { IndexedVector3 btfrom = new IndexedVector3((float)from.x, (float)from.y, (float)from.z); IndexedVector3 btto = new IndexedVector3((float)to.x, (float)to.y, (float)to.z); BulletXNA.BulletCollision.AllHitsRayResultCallback rayCallback = new AllHitsRayResultCallback(btfrom, btto); rayCallback.m_collisionFilterGroup = filter_group; rayCallback.m_collisionFilterMask = filter_mask; this.bt_collision_world.rayTest(btfrom, btto, rayCallback); // Find the closest hit result on the specified model (if any) int hit = -1; float fraction = 1; for (int i = 0; i < rayCallback.m_collisionObjects.Count; ++i) { if (rayCallback.m_collisionObjects[i].GetUserPointer() == model && rayCallback.m_hitFractions[i] < fraction) { hit = i; fraction = rayCallback.m_hitFractions[i]; } } // Ray does not hit specified model if (hit == -1) { mresult.hit = false; return(false); } // Return the closest hit on the specified model mresult.hit = true; mresult.hitModel = (ChCollisionModel)(rayCallback.m_collisionObjects[hit].GetUserPointer()); mresult.abs_hitPoint.Set(rayCallback.m_hitPointWorld[hit].X, rayCallback.m_hitPointWorld[hit].Y, rayCallback.m_hitPointWorld[hit].Z); mresult.abs_hitNormal.Set(rayCallback.m_hitNormalWorld[hit].X, rayCallback.m_hitNormalWorld[hit].Y, rayCallback.m_hitNormalWorld[hit].Z); mresult.abs_hitNormal.Normalize(); mresult.dist_factor = fraction; mresult.abs_hitPoint = mresult.abs_hitPoint - mresult.abs_hitNormal * mresult.hitModel.GetEnvelope(); return(true); }
/// Copy from other. public ChCollisionInfo(ChCollisionInfo other, bool swap = false) { if (!swap) { modelA = other.modelA; modelB = other.modelB; vpA = other.vpA; vpB = other.vpB; vN = other.vN; } else { // copy by swapping models modelA = other.modelB; modelB = other.modelA; vpA = other.vpB; vpB = other.vpA; vN = -other.vN; } distance = other.distance; eff_radius = other.eff_radius; reaction_cache = other.reaction_cache; }
public override void ReportProximities(ChProximityContainer mproximitycontainer) { mproximitycontainer.BeginAddProximities(); /* * int numManifolds = bt_collision_world->getDispatcher()->getNumManifolds(); * for (int i = 0; i < numManifolds; i++) { * btPersistentManifold* contactManifold = bt_collision_world->getDispatcher()->getManifoldByIndexInternal(i); * btCollisionObject* obA = static_cast<btCollisionObject*>(contactManifold->getBody0()); * btCollisionObject* obB = static_cast<btCollisionObject*>(contactManifold->getBody1()); * contactManifold->refreshContactPoints(obA->getWorldTransform(), obB->getWorldTransform()); * * ChCollisionModel* modelA = (ChCollisionModel*)obA->getUserPointer(); * ChCollisionModel* modelB = (ChCollisionModel*)obB->getUserPointer(); * * // Add to proximity container * mproximitycontainer->AddProximity(modelA, modelB); * } */ int numPairs = bt_collision_world.GetBroadphase().GetOverlappingPairCache().GetNumOverlappingPairs(); for (int i = 0; i < numPairs; i++) { BroadphasePair mp = bt_collision_world.GetBroadphase().GetOverlappingPairCache().GetOverlappingPairArray()[i]; CollisionObject obA = (CollisionObject)(mp.m_pProxy0.GetClientObject()); CollisionObject obB = (CollisionObject)(mp.m_pProxy1.GetClientObject()); ChCollisionModel modelA = (ChCollisionModel)obA.GetUserPointer(); ChCollisionModel modelB = (ChCollisionModel)obB.GetUserPointer(); // Add to proximity container mproximitycontainer.AddProximity(modelA, modelB); } mproximitycontainer.EndAddProximities(); }
/// Callback used to process 'near enough' pairs of collision models found by the /// broad-phase collision algorithm. /// Return false to skip narrow-phase contact generation for this pair of bodies. public abstract bool OnBroadphase(ChCollisionModel modelA, ///< 1st model ChCollisionModel modelB ///< 2nd model );
/// Removes a collision model from the collision /// engine (custom data may be deallocated). public abstract void Remove(ChCollisionModel model);
/// Adds a collision model to the collision /// engine (custom data may be allocated). public abstract void Add(ChCollisionModel model);
/// Perform a ray-hit test with the specified collision model. public abstract bool RayHit(ChVector from, ChVector to, ChCollisionModel model, ref ChRayhitResult mresult, CollisionFilterGroups filter_group, CollisionFilterGroups filter_mask);
/// Perform a ray-hit test with the collision models. public abstract bool RayHit(ChVector from, ChVector to, ChCollisionModel model, ref ChRayhitResult mresult);