コード例 #1
0
        public void AddToWorldForPathFinding()
        {
            if (_bodyType != BodyType.Static)
            {
                return;
            }

            ParallelCollider3D[] colliders = GetComponentsInChildren <ParallelCollider3D>();
            PBody3D body = Parallel3D.AddBody(
                (int)bodyType,
                pTransform.position,
                pTransform.rotation,
                linearDamping,
                angularDamping,
                gravityScale,
                fixedRotationX,
                fixedRotationY,
                fixedRotationZ,
                this);

            foreach (ParallelCollider3D collider in colliders)
            {
                PShape3D shape = collider.CreateShape(gameObject);

                if (shape == null)
                {
                    Debug.LogError("Failed to create collider shape");
                    continue;
                }

                Parallel3D.AddFixture(body, shape, (Fix64)1);
            }
        }
コード例 #2
0
        public static void UpdateMassData(PBody3D body, Fix64 mass, Fix64Vec3 centerOfMass)
        {
            if (!initialized)
            {
                Initialize();
            }

            NativeParallel3D.UpdateMassData(body.IntPointer, mass, centerOfMass);
        }
コード例 #3
0
        public static bool IsAwake(PBody3D body)
        {
            if (!initialized)
            {
                Initialize();
            }

            return(NativeParallel3D.IsAwake(body.IntPointer));
        }
コード例 #4
0
        public static void SetAwakeForRollback(PBody3D body, bool awake, Fix64 sleepTime)
        {
            if (!initialized)
            {
                Initialize();
            }

            NativeParallel3D.SetAwakeForRollback(body.IntPointer, awake, sleepTime);
        }
コード例 #5
0
        public static void SetAwake(PBody3D body, bool awake)
        {
            if (!initialized)
            {
                Initialize();
            }

            NativeParallel3D.SetAwake(body.IntPointer, awake);
        }
コード例 #6
0
        public static void ApplyTorque(PBody3D body, Fix64Vec3 torque)
        {
            if (!initialized)
            {
                Initialize();
            }

            NativeParallel3D.ApplyTorque(body.IntPointer, torque);
        }
コード例 #7
0
        public static void ApplyAngularImpulse(PBody3D body, Fix64Vec3 impulse)
        {
            if (!initialized)
            {
                Initialize();
            }

            NativeParallel3D.ApplyAngularImpulse(body.IntPointer, impulse);
        }
コード例 #8
0
        public static void UpdateMass(PBody3D body, Fix64 mass)
        {
            if (!initialized)
            {
                Initialize();
            }

            NativeParallel3D.UpdateMass(body.IntPointer, mass);
        }
コード例 #9
0
        public static void ApplyForceToCenter(PBody3D body, Fix64Vec3 force)
        {
            if (!initialized)
            {
                Initialize();
            }

            NativeParallel3D.ApplyForceToCenter(body.IntPointer, force);
        }
コード例 #10
0
        public static void UpdateBodyVelocity(PBody3D body, Fix64Vec3 linearVelocity, Fix64Vec3 angularVelocity)
        {
            if (!initialized)
            {
                Initialize();
            }

            NativeParallel3D.UpdateBodyVelocity(body.IntPointer, linearVelocity, angularVelocity);
        }
コード例 #11
0
        public static void UpdateBodyTransformForRollback(PBody3D body, Fix64Vec3 pos, Fix64Quat rot, Fix64Quat rot0)
        {
            if (!initialized)
            {
                Initialize();
            }

            NativeParallel3D.UpdateBodyTransformForRollback(body.IntPointer, pos, rot, rot0);
        }
コード例 #12
0
        //3D fixture
        public static PFixture3D AddFixture(PBody3D body, PShape3D shape, Fix64 density)
        {
            if (!initialized)
            {
                Initialize();
            }

            IntPtr m_NativeObject = NativeParallel3D.AddFixtureToBody(body.IntPointer, shape.IntPointer, density);

            return(new PFixture3D(m_NativeObject));
        }
コード例 #13
0
        public static void ReadNativeBody(PBody3D body)
        {
            if (!initialized)
            {
                Initialize();
            }

            NativeParallel3D.GetTransform(body.IntPointer, ref body.position, ref body.orientation, ref body.orientation0);
            NativeParallel3D.GetVelocity(body.IntPointer, ref body.linearVelocity, ref body.angularVelocity);
            body.awake = NativeParallel3D.IsAwake(body.IntPointer);
            NativeParallel3D.GetSleepTime(body.IntPointer, ref body.sleepTime);
        }
コード例 #14
0
        public static Fix64Vec3 GetPointVelocity(PBody3D body, Fix64Vec3 point)
        {
            if (!initialized)
            {
                Initialize();
            }

            Fix64Vec3 result = Fix64Vec3.zero;

            NativeParallel3D.GetPointVelocity(body.IntPointer, point, ref result);

            return(result);
        }
コード例 #15
0
        public static void DestoryBody(PBody3D body, IParallelRigidbody3D rigidBody3D)
        {
            if (!initialized)
            {
                Initialize();
            }

            if (rigidBodies.Contains(rigidBody3D))
            {
                rigidBodies.Remove(rigidBody3D);
            }

            if (bodyDictionary.ContainsKey(body.BodyID))
            {
                bodyDictionary.Remove(body.BodyID);
            }

            NativeParallel3D.DestroyBody(internalWorld.IntPointer, body.IntPointer);
        }
コード例 #16
0
        //3D body
        public static PBody3D AddBody(
            int bodyType,
            Fix64Vec3 position,
            Fix64Quat orientation,
            Fix64Vec3 linearDamping,
            Fix64Vec3 angularDamping,
            Fix64Vec3 gravityScale,
            bool fixedRotationX,
            bool fixedRotationY,
            bool fixedRotationZ,
            IParallelRigidbody3D rigidBody)
        {
            if (!initialized)
            {
                Initialize();
            }

            UInt16 bodyID = 0;

            IntPtr m_NativeObject = NativeParallel3D.CreateBody(
                internalWorld.IntPointer,
                bodyType,
                position,
                orientation,
                linearDamping,
                angularDamping,
                gravityScale,
                fixedRotationX,
                fixedRotationY,
                fixedRotationZ,
                ref bodyID);

            PBody3D body = new PBody3D(m_NativeObject, bodyID, rigidBody as ParallelRigidbody3D, bodyExportSize);

            rigidBodies.Add(rigidBody);
            bodyDictionary[bodyID] = body;

            ReadNativeBody(body);

            return(body);
        }
コード例 #17
0
        public static void UpdateBodyProperties(PBody3D body,
                                                int bodyType,
                                                Fix64Vec3 linearDamping,
                                                Fix64Vec3 angularDamping,
                                                Fix64Vec3 gravityScale,
                                                bool fixedRotationX,
                                                bool fixedRotationY,
                                                bool fixedRotationZ)
        {
            if (!initialized)
            {
                Initialize();
            }

            NativeParallel3D.UpdateBodyProperties(
                body.IntPointer,
                bodyType,
                linearDamping,
                angularDamping,
                gravityScale,
                fixedRotationX,
                fixedRotationY,
                fixedRotationZ);
        }
コード例 #18
0
        //============================== Unity Events ==============================
        void Awake()
        {
            ParallelPhysicsController3D pSettings = FindObjectOfType <ParallelPhysicsController3D>();

            if (pSettings == null)
            {
                return;
            }

            pSettings.InitIfNecessary();

            parallelFixedUpdates = GetComponents <IParallelFixedUpdate>();
            parallelCollisions   = GetComponents <IParallelCollision3D>();
            parallelTriggers     = GetComponents <IParallelTrigger3D>();

            pTransform.ImportFromUnity();

            colliders = GetComponentsInChildren <ParallelCollider3D>();

            _body3D = Parallel3D.AddBody(
                (int)bodyType,
                pTransform.position,
                pTransform.rotation,
                linearDamping,
                angularDamping,
                gravityScale,
                fixedRotationX,
                fixedRotationY,
                fixedRotationZ,
                this);

            _bodyID = _body3D.BodyID;

            foreach (ParallelCollider3D collider in colliders)
            {
                PShape3D shape = collider.CreateShape(gameObject);

                if (shape == null)
                {
                    Debug.LogError("Failed to create collider shape");
                    continue;
                }

                PFixture3D fixture = Parallel3D.AddFixture(_body3D, shape, (Fix64)1);

                collider.ReceiveFixture(fixture);
            }

            if (_overideMassData)
            {
                //Parallel3D.UpdateMassData(_body3D, _mass, _centerOfMass);
                if (_centerOfMass != null)
                {
                    Fix64Vec3 com = _centerOfMass;
                    //Debug.Log(com);
                    Parallel3D.UpdateMassData(_body3D, _mass, com);
                }
                else
                {
                    Parallel3D.UpdateMass(_body3D, _mass);
                }
            }
        }
コード例 #19
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();
            }
        }