Exemplo n.º 1
0
        public static void PrepareContacts()
        {
            for (int i = 0; i < _contactCount; i++)
            {
                PContactExport3D export = contactExports[i];

                //some
                if (export.id == 0)
                {
                    continue;
                }

                PContact3D c;

                if (contactDictionary.ContainsKey(export.id))
                {
                    c = contactDictionary[export.id];
                }
                else
                {
                    c = new PContact3D(export.id);
                    contactDictionary[export.id] = c;
                }

                c.Update(
                    contactPtrs[i],
                    export.manifoldCount,
                    export.relativeVelocity,
                    export.isTrigger
                    );

                AddAllContactWrapper(c);
            }
        }
Exemplo n.º 2
0
        static void AddAllContactWrapper(PContact3D contact)
        {
            _allContactWrapperEnd.contact = contact;

            _allContactWrapperEnd = _allContactWrapperEnd.next;

            _allContactCount++;
        }
Exemplo n.º 3
0
        static void AddExitContactWrapper(PContact3D contact)
        {
            _exitContactWrapperEnd.contact = contact;

            _exitContactWrapperEnd = _exitContactWrapperEnd.next;

            _exitContactCount++;
        }
Exemplo n.º 4
0
        public static void OnContactExitCallBack(IntPtr contactPtr, UInt32 contactID)
        {
            PContact3D c;

            if (contactDictionary.ContainsKey(contactID))
            {
                //already has this contact
                //the native contact for this body pair was created and destroyed before
                c       = contactDictionary[contactID];
                c.state = ContactState.Exit;
            }
            else
            {
                //first time
                c       = new PContact3D(contactID);
                c.state = ContactState.Enter;
                contactDictionary[contactID] = c;
            }

            AddExitContactWrapper(c);
            //Debug.Log("Exit contact");
        }
Exemplo n.º 5
0
        public static void ExcuteUserCallbacks(Fix64 timeStep)
        {
            //call contact exit callback

            PContact3DWrapper currentWrapper = _exitContactWrapperHead;

            for (int i = 0; i < _exitContactCount; i++)
            {
                PContact3D contact = currentWrapper.contact;

                PBody3D body1 = bodyDictionary[contact.Body1ID];
                PBody3D body2 = bodyDictionary[contact.Body2ID];

                if (contact.IsTrigger)
                {
                    body1.RigidBody.OnParallelTriggerExit(body2.RigidBody);
                    body2.RigidBody.OnParallelTriggerExit(body1.RigidBody);
                }
                else
                {
                    _tempCollision.SetContact(contact, body2.RigidBody);
                    body1.RigidBody.OnParallelCollisionExit(_tempCollision);

                    _tempCollision.SetContact(contact, body1.RigidBody);
                    body2.RigidBody.OnParallelCollisionExit(_tempCollision);
                }

                contact.state  = ContactState.Inactive;
                currentWrapper = currentWrapper.next;
            }

            //call contact stay callback
            currentWrapper = _allContactWrapperHead;

            for (int i = 0; i < _allContactCount; i++)
            {
                PContact3D contact = currentWrapper.contact;

                if (contact.state == ContactState.Active)
                {
                    PBody3D body1 = bodyDictionary[contact.Body1ID];
                    PBody3D body2 = bodyDictionary[contact.Body2ID];

                    if (contact.IsTrigger)
                    {
                        body1.RigidBody.OnParallelTriggerStay(body2.RigidBody);
                        body2.RigidBody.OnParallelTriggerStay(body1.RigidBody);
                    }
                    else
                    {
                        _tempCollision.SetContact(contact, body2.RigidBody);
                        body1.RigidBody.OnParallelCollisionStay(_tempCollision);

                        _tempCollision.SetContact(contact, body1.RigidBody);
                        body2.RigidBody.OnParallelCollisionStay(_tempCollision);
                    }
                }

                currentWrapper = currentWrapper.next;
            }

            //call contact enter callback
            currentWrapper = _enterContactWrapperHead;

            for (int i = 0; i < _enterContactCount; i++)
            {
                PContact3D contact = currentWrapper.contact;
                PBody3D    body1   = bodyDictionary[contact.Body1ID];
                PBody3D    body2   = bodyDictionary[contact.Body2ID];

                if (contact.IsTrigger)
                {
                    body1.RigidBody.OnParallelTriggerEnter(body2.RigidBody);
                    body2.RigidBody.OnParallelTriggerEnter(body1.RigidBody);
                }
                else
                {
                    _tempCollision.SetContact(contact, body2.RigidBody);
                    body1.RigidBody.OnParallelCollisionEnter(_tempCollision);

                    _tempCollision.SetContact(contact, body1.RigidBody);
                    body2.RigidBody.OnParallelCollisionEnter(_tempCollision);
                }

                contact.state  = ContactState.Active;
                currentWrapper = currentWrapper.next;
            }

            foreach (IParallelRigidbody3D rigidBody in rigidBodies)
            {
                rigidBody.Step(timeStep);
            }

            foreach (IParallelRigidbody3D rigidBody in rigidBodies)
            {
                rigidBody.WriteNative();
            }
        }
Exemplo n.º 6
0
 internal void SetContact(PContact3D contact, ParallelRigidbody3D rigidBody)
 {
     _contact       = contact;
     otherRigidbody = rigidBody;
 }