Exemple #1
0
        internal XForm _xf; // the body origin transform

        #endregion Fields

        #region Constructors

        internal Body(BodyDef bd, World world)
        {
            _flags = 0;

            if (bd.isBullet)
            {
                _flags |= BodyFlags.Bullet;
            }
            if (bd.fixedRotation)
            {
                _flags |= BodyFlags.FixedRotation;
            }
            if (bd.allowSleep)
            {
                _flags |= BodyFlags.AllowSleep;
            }
            if (bd.isSleeping)
            {
                _flags |= BodyFlags.Sleep;
            }

            _world = world;

            _xf.Position = bd.position;
            _xf.R.Set(bd.angle);

            _sweep.localCenter = bd.massData.center;
            _sweep.t0 = 1.0f;
            _sweep.a0 = _sweep.a = bd.angle;
            _sweep.c0 = _sweep.c = MathUtils.Multiply(ref _xf, _sweep.localCenter);

            _jointList = null;
            _contactList = null;
            _prev = null;
            _next = null;

            _linearVelocity = bd.linearVelocity;
            _angularVelocity = bd.angularVelocity;

            _linearDamping = bd.linearDamping;
            _angularDamping = bd.angularDamping;

            _force = new Vector2(0.0f, 0.0f);
            _torque = 0.0f;

            _linearVelocity = Vector2.Zero;
            _angularVelocity = 0.0f;

            _sleepTime = 0.0f;

            _invMass = 0.0f;
            _I = 0.0f;
            _invI = 0.0f;

            _mass = bd.massData.mass;

            if (_mass > 0.0f)
            {
                _invMass = 1.0f / _mass;
            }

            _I = bd.massData.i;

            if (_I > 0.0f && (_flags & BodyFlags.FixedRotation) == 0)
            {
                _invI = 1.0f / _I;
            }

            if (_invMass == 0.0f && _invI == 0.0f)
            {
                _type = BodyType.Static;
            }
            else
            {
                _type = BodyType.Dynamic;
            }

            _userData = bd.userData;

            _fixtureList = null;
            _fixtureCount = 0;
        }
Exemple #2
0
        /// Create a rigid body given a definition. No reference to the definition
        /// is retained.
        /// @warning This function is locked during callbacks.
        public Body CreateBody(BodyDef def)
        {
            Debug.Assert(!IsLocked);
            if (IsLocked)
            {
                return null;
            }

            var b = new Body(def, this);

            // Add to world doubly linked list.
            b._prev = null;
            b._next = _bodyList;
            if (_bodyList != null)
            {
                _bodyList._prev = b;
            }
            _bodyList = b;
            ++_bodyCount;

            return b;
        }