コード例 #1
0
        // apply a force at 'fromCenter' relative to center of the shape
        public void ApplyTorque(Vector2f force, Vector2f fromCenter)
        {
            var radius = fromCenter.Magnitude();

            // check if 'fromCenter' is outside of the shape.
            if(radius > GetRadiusOn(fromCenter))
                return;

            // torque is the amount of force in the perpendicular direction
            var torque = force.Cross(fromCenter);

            // linear force is the amount of force in the parallel direction
            var linearForce = force.Dot(fromCenter) / (radius != 0 ? radius : 1f);

            // moment of inertia of the mass at this radius
            var inertia = mass * radius * radius;

            AngularAcceleration += -torque / (inertia != 0 ? inertia : 1);
            ApplyForce(linearForce * force.Unit());
        }