public override PShape2D CreateShape(GameObject root)
        {
            Fix64 radius = CalculateRadius();
            Fix64 height = CalculateHeight();

            CalculatePoints(height, radius, ref v1, ref v2);

            if (v1 == Fix64Vec2.zero || v2 == Fix64Vec2.zero)
            {
                return(null);
            }
            else
            {
                Fix64     angle  = Fix64.zero;
                Fix64Vec2 center = Fix64Vec2.zero;

                if (gameObject != root)
                {
                    angle  = Fix64.DegToRad(_pTransform.localEulerAngles.z);
                    center = (Fix64Vec2)_pTransform.localPosition;
                }

                return(Parallel2D.CreateCapsule(v1, v2, radius, center, angle));
            }
        }
        protected override void UpdateShape(GameObject root)
        {
            Fix64Vec2 s = CalculateSize();

            if (s != Fix64Vec2.zero)
            {
                Fix64Vec2[] scaled = new Fix64Vec2[convexVertsCount];

                for (int i = 0; i < convexVertsCount; i++)
                {
                    scaled[i] = convexVerts[i] * s;
                }

                Fix64     angle  = Fix64.zero;
                Fix64Vec2 center = Fix64Vec2.zero;

                if (gameObject != root)
                {
                    angle  = Fix64.DegToRad(_pTransform.localEulerAngles.z);
                    center = (Fix64Vec2)_pTransform.localPosition;
                }

                Parallel2D.UpdatePolygon(_shape, _fixture, scaled, convexVertsCount, center, angle);
            }
        }
Example #3
0
 public void ReceiveFixture(PFixture2D fixture)
 {
     _fixture = fixture;
     _shape   = Parallel2D.GetShapeOfFixture(fixture);
     Parallel2D.SetLayer(fixture, gameObject.layer, false);
     Parallel2D.SetFixtureProperties(fixture, isTrigger, _friction, _bounciness);
 }
Example #4
0
        public bool LoadSavedExport(UInt32 step)
        {
            if (step > _maxStep)
            {
                return(false);
            }

            if (step < _minStep)
            {
                return(false);
            }

            int index = CalculateExportIndex(step);

            PBodyExport2D export = bodyExports[index];

            linearVelocity  = export.linearVelocity;
            angularVelocity = export.angularVelocity;
            position        = export.position;
            angle           = export.angle;

            Parallel2D.UpdateBodyTransForm(this, position, angle);
            Parallel2D.UpdateBodyVelocity(this, linearVelocity, angularVelocity);

            return(true);
        }
 public void InitIfNecessary()
 {
     if (!_initialized)
     {
         _initialized = true;
         Parallel2D.SetLoggingLevel(LoggingLevel);
         Parallel2D.bodyExportSize = bodyExportSize;
     }
 }
        //============================== Unity Events ==============================
        void Awake()
        {
            ParallelPhysicsController2D pSettings = FindObjectOfType <ParallelPhysicsController2D>();

            if (pSettings == null)
            {
                return;
            }

            pSettings.InitIfNecessary();

            parallelFixedUpdates = GetComponents <IParallelFixedUpdate>();
            parallelCollisions   = GetComponents <IParallelCollision2D>();
            parallelTriggers     = GetComponents <IParallelTrigger2D>();

            pTransform.ImportFromUnity();

            colliders = GetComponentsInChildren <ParallelCollider2D>();

            _body2D = Parallel2D.AddBody(
                (int)bodyType,
                (Fix64Vec2)pTransform.position,
                pTransform.rotation.GetZAngle(),
                linearDampling,
                angularDamping,
                fixedRotation,
                gravityScale,
                this);

            _bodyID = _body2D.BodyID;

            foreach (ParallelCollider2D collider in colliders)
            {
                collider.SetRootGameObject(gameObject);
                PShape2D shape = collider.CreateShape(gameObject);

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

                PFixture2D fixture2D = Parallel2D.AddFixture(_body2D, shape, (Fix64)1);

                collider.ReceiveFixture(fixture2D);
            }
        }
        void ConvexHull2D()
        {
            Fix64Vec2[] fixedVerts = new Fix64Vec2[vertsCount];
            for (int i = 0; i < vertsCount; i++)
            {
                fixedVerts[i] = (Fix64Vec2)verts[i];
            }

            ParallelVec2List vec2List = Parallel2D.ConvexHull2D(fixedVerts, vertsCount, limit);

            convexVerts = new Fix64Vec2[vec2List.count];
            for (int i = 0; i < vec2List.count; i++)
            {
                convexVerts[i] = vec2List.points[i];
            }

            convexVertsCount = vec2List.count;
        }
Example #8
0
        protected override void UpdateShape(GameObject root)
        {
            Fix64Vec2 s = CalculateSize();

            if (s != Fix64Vec2.zero)
            {
                Fix64     angle  = Fix64.zero;
                Fix64Vec2 center = Fix64Vec2.zero;

                if (gameObject != root)
                {
                    angle  = Fix64.DegToRad(_pTransform.localEulerAngles.z);
                    center = (Fix64Vec2)_pTransform.localPosition;
                }

                Parallel2D.UpdateBox(_shape, _fixture, s.x, s.y, center, angle);
            }
        }
        protected override void UpdateShape(GameObject root)
        {
            Fix64 r = CalculateRadius();

            if (r <= Fix64.zero)
            {
                Debug.LogError("Invalid Size");
            }
            else
            {
                Fix64Vec2 center = Fix64Vec2.zero;

                if (gameObject != root)
                {
                    center = (Fix64Vec2)_pTransform.localPosition;
                }

                Parallel2D.UpdateCircle(_shape, _fixture, r, center);
            }
        }
        protected override void UpdateShape(GameObject root)
        {
            Fix64 radius = CalculateRadius();
            Fix64 height = CalculateHeight();

            CalculatePoints(height, radius, ref v1, ref v2);

            if (v1 != Fix64Vec2.zero && v2 != Fix64Vec2.zero)
            {
                Fix64     angle  = Fix64.zero;
                Fix64Vec2 center = Fix64Vec2.zero;

                if (gameObject != root)
                {
                    angle  = Fix64.DegToRad(_pTransform.localEulerAngles.z);
                    center = (Fix64Vec2)_pTransform.localPosition;
                }

                Parallel2D.UpdateCapsule(_shape, _fixture, v1, v2, radius, center, angle);
            }
        }
        public override PShape2D CreateShape(GameObject root)
        {
            Fix64 r = CalculateRadius();

            if (r <= Fix64.zero)
            {
                Debug.LogError("Invalid Size");
                return(null);
            }
            else
            {
                Fix64Vec2 center = Fix64Vec2.zero;

                if (gameObject != root)
                {
                    center = (Fix64Vec2)_pTransform.localPosition;
                }

                return(Parallel2D.CreateCircle(r, center));
            }
        }
Example #12
0
        public override PShape2D CreateShape(GameObject root)
        {
            Fix64Vec2 s = CalculateSize();

            if (s != Fix64Vec2.zero)
            {
                Fix64     angle  = Fix64.zero;
                Fix64Vec2 center = Fix64Vec2.zero;

                if (gameObject != root)
                {
                    angle  = Fix64.DegToRad(_pTransform.localEulerAngles.z);
                    center = (Fix64Vec2)_pTransform.localPosition;
                }

                return(Parallel2D.CreateBox(s.x, s.y, center, angle));
            }
            else
            {
                return(null);
            }
        }
Example #13
0
        void UpdateRigidbodyTransform()
        {
            if (_rigidbody2D == null)
            {
                _rigidbody2D = GetComponent <ParallelRigidbody2D>();
            }

            if (_rigidbody3D == null)
            {
                _rigidbody3D = GetComponent <ParallelRigidbody3D>();
            }

            if (_rigidbody2D != null)
            {
                Parallel2D.UpdateBodyTransForm(_rigidbody2D._body2D, (Fix64Vec2)_localPosition, Fix64.DegToRad(_internalLocalEularAngles.z));
            }

            if (_rigidbody3D != null)
            {
                Parallel3D.UpdateBodyTransForm(_rigidbody3D._body3D, _localPosition, _internalLocalRotation);
            }
        }
        public override PShape2D CreateShape(GameObject root)
        {
            Fix64Vec2 s = CalculateSize();

            if (s != Fix64Vec2.zero)
            {
                Fix64     angle  = Fix64.zero;
                Fix64Vec2 center = Fix64Vec2.zero;

                if (gameObject != root)
                {
                    angle  = Fix64.DegToRad(_pTransform.localEulerAngles.z);
                    center = (Fix64Vec2)_pTransform.localPosition;
                }

                if (s == Fix64Vec2.one)
                {
                    return(Parallel2D.CreatePolygon(convexVerts, convexVertsCount, center, angle));
                }
                else
                {
                    Fix64Vec2[] scaled = new Fix64Vec2[convexVertsCount];

                    for (int i = 0; i < convexVertsCount; i++)
                    {
                        scaled[i] = convexVerts[i] * s;
                    }

                    return(Parallel2D.CreatePolygon(scaled, convexVertsCount, center, angle));
                }
            }
            else
            {
                return(null);
            }
        }
 public void PrepareExternalContactData()
 {
     Parallel2D.PrepareExternalContactData();
 }
 public void Step()
 {
     Parallel2D.Step(fixedUpdateTime64, velocityIteration, positionIteration);
 }
 private void OnDestroy()
 {
     Parallel2D.CleanUp();
 }
Example #18
0
 /// Apply a torque. This affects the angular velocity
 /// without affecting the linear velocity of the center of mass.
 /// z-axis (out of the screen)
 public void ApplyTorque(Fix64 torque)
 {
     Parallel2D.ApplyTorque(_body2D, torque);
 }
Example #19
0
 /// Apply an angular impulse. This immediately modifies the angular velocity
 public void ApplyAngularImpulse(Fix64 impulse)
 {
     Parallel2D.ApplyAngularImpulse(_body2D, impulse);
 }
Example #20
0
 //Apply an impulse to the center of mass. This immediately modifies the velocity.
 public void ApplyLinearImpulse(Fix64Vec2 impluse)
 {
     Parallel2D.ApplyLinearImpulseToCenter(_body2D, impluse);
 }
Example #21
0
 /// Apply an impulse at a point. This immediately modifies the velocity.
 /// It also modifies the angular velocity if the point of application
 /// is not at the center of mass.
 public void ApplyLinearImpluse(Fix64Vec2 impluse, Fix64Vec2 worldPoint)
 {
     Parallel2D.ApplyLinearImpulse(_body2D, worldPoint, impluse);
 }
Example #22
0
 //============================== Force and Torque ==============================
 //Apply a force to the center of mass
 public void ApplyForce(Fix64Vec2 force)
 {
     Parallel2D.ApplyForceToCenter(_body2D, force);
 }
Example #23
0
 //Apply a force at a world point
 public void ApplyForce(Fix64Vec2 force, Fix64Vec2 worldPoint)
 {
     Parallel2D.ApplyForce(_body2D, worldPoint, force);
 }
 public void ExportEngineState(PInternalState2D state)
 {
     Parallel2D.ExportEngineInternalState(state);
 }
 public void ApplyEngineState(PInternalState2D state)
 {
     Parallel2D.AppleEngineInternalState(state);
 }
 public void ExcuteUserCallbacks()
 {
     Parallel2D.ExcuteUserCallbacks(fixedUpdateTime64);
 }
 public void ExcuteUserFixedUpdate()
 {
     Parallel2D.ExcuteUserFixedUpdate(fixedUpdateTime64);
 }
 public void UpdateContacts()
 {
     Parallel2D.UpdateContacts();
 }
Example #29
0
 public int GetContactPoints(ref PContactPoints2D contactPoints2D)
 {
     Parallel2D.GetContactDetail(_contact.IntPointer, ref contactPoints2D);
     return(contactPoints2D.contactPointCount);
 }
Example #30
0
 public void ReadNative()
 {
     Parallel2D.ReadNativeBody(this);
     RigidBody.OnTransformUpdated();
 }