Ejemplo n.º 1
0
 /// 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;
 }
Ejemplo n.º 2
0
 /// Callback used to process collision pairs found by the narrow-phase collision step.
 /// Return true to generate a contact for this pair of overlapping bodies.
 public abstract bool OnNarrowphase(ChCollisionInfo contactinfo);
Ejemplo n.º 3
0
            public override void ReportContacts(ChContactContainer mcontactcontainer)
            {
                // This should remove all old contacts (or at least rewind the index)
                mcontactcontainer.BeginAddContact();

                // NOTE: Bullet does not provide information on radius of curvature at a contact point.
                // As such, for all Bullet-identified contacts, the default value will be used (SMC only).
                ChCollisionInfo icontact = new ChCollisionInfo();

                int numManifolds = bt_collision_world.GetDispatcher().GetNumManifolds();

                for (int i = 0; i < numManifolds; i++)
                {
                    PersistentManifold contactManifold = bt_collision_world.GetDispatcher().GetManifoldByIndexInternal(i);
                    CollisionObject    obA             = (CollisionObject)(contactManifold.GetBody0());
                    CollisionObject    obB             = (CollisionObject)(contactManifold.GetBody1());

                    if (obA != null && obA != null) // Alan
                    {
                        contactManifold.RefreshContactPoints(ref obA.GetWorldTransform(), ref obB.GetWorldTransform());

                        icontact.modelA = (ChCollisionModel)obA.GetUserPointer();
                        icontact.modelB = (ChCollisionModel)obB.GetUserPointer();

                        double envelopeA = icontact.modelA.GetEnvelope();
                        double envelopeB = icontact.modelB.GetEnvelope();

                        double marginA = icontact.modelA.GetSafeMargin();
                        double marginB = icontact.modelB.GetSafeMargin();

                        // Execute custom broadphase callback, if any
                        bool do_narrow_contactgeneration = true;
                        if (this.broad_callback != null)
                        {
                            do_narrow_contactgeneration = this.broad_callback.OnBroadphase(icontact.modelA, icontact.modelB);
                        }

                        if (do_narrow_contactgeneration)
                        {
                            int numContacts = contactManifold.GetNumContacts();
                            //GetLog() << "numContacts=" << numContacts << "\n";
                            for (int j = 0; j < numContacts; j++)
                            {
                                // Debug.Log("contacts " + numContacts);
                                ManifoldPoint pt = contactManifold.GetContactPoint(j);

                                // Discard "too far" constraints (the Bullet engine also has its threshold)
                                if (pt.GetDistance() < marginA + marginB)
                                {
                                    IndexedVector3 ptA = pt.GetPositionWorldOnA();
                                    IndexedVector3 ptB = pt.GetPositionWorldOnB();

                                    icontact.vpA.Set(ptA.X, ptA.Y, ptA.Z);
                                    icontact.vpB.Set(ptB.X, ptB.Y, ptB.Z);

                                    icontact.vN.Set(-pt.GetNormalWorldOnB().X, -pt.GetNormalWorldOnB().Y,
                                                    -pt.GetNormalWorldOnB().Z);
                                    icontact.vN.Normalize();

                                    double ptdist = pt.GetDistance();

                                    icontact.vpA      = icontact.vpA - icontact.vN * envelopeA;
                                    icontact.vpB      = icontact.vpB + icontact.vN * envelopeB;
                                    icontact.distance = ptdist + envelopeA + envelopeB;

                                    icontact.reaction_cache = pt.reactions_cache;// reactions_cache;

                                    // Execute some user custom callback, if any
                                    bool add_contact = true;
                                    if (this.narrow_callback != null)
                                    {
                                        add_contact = this.narrow_callback.OnNarrowphase(icontact);
                                    }

                                    // Add to contact container
                                    if (add_contact)
                                    {
                                        mcontactcontainer.AddContact(icontact);
                                    }
                                }
                            }
                        }
                    }

                    // you can un-comment out this line, and then all points are removed
                    // contactManifold->clearManifold();
                }
                mcontactcontainer.EndAddContact();
            }