Example #1
0
        protected override void Apply()
        {
            if (IsDynamic(Object))
            {
                IPhysicsObject physObj       = (IPhysicsObject)Object;
                double         d             = Math.PI * (Object.Angle.Radians - Center.Radians);
                double         k             = Math.Pow(Frequency, 2) * physObj.MomentOfInertia;
                double         torque        = -k * d;
                double         dampingTorque = physObj.AngularVelocity * Damping * physObj.MomentOfInertia;
                double         totalTorque   = torque - dampingTorque;

                physObj.ApplyTorque(totalTorque);
            }
            else
            {
                Object.Angle = Angle.Sum(Center, GetOffset());
            }
        }
Example #2
0
        protected override void Apply()
        {
            if (IsDynamic(Object))
            {
                IPhysicsObject physObj       = (IPhysicsObject)Object;
                double         d             = Math.Cos(W * t + Phase);
                double         k             = physObj.MomentOfInertia * Math.Pow(W, 2) * Amplitude.Radians;
                double         torque        = -k * d;
                double         dampingTorque = physObj.AngularVelocity * Damping * physObj.MomentOfInertia;
                double         totalTorque   = torque - dampingTorque;

                physObj.ApplyTorque(totalTorque);
            }
            else if (Object is PhysicsObject obj)
            {
                obj.AngularVelocity = GetAngularVelocity();
            }
            else
            {
                Object.Angle = Angle.Sum(Center, GetOffset());
            }
            if (stopGradually)
            {
                double origDst = (OriginalAngle - prevAngle).Degrees;
                double currDst = (OriginalAngle - Object.Angle).Degrees;
                if (!distanceDecreasing && origDst > currDst)
                {
                    distanceDecreasing = true;
                }
                if (distanceDecreasing && origDst < currDst)
                {
                    Stop(true);
                }
            }
            prevAngle = Object.Angle;
        }