Esempio n. 1
0
        internal void DoDamping()
        {
            if (bodyID == dBodyID.Zero)
            {
                return;
            }

            Ode.dMass mass = new Ode.dMass();
            Ode.dBodyGetMass(bodyID, ref mass);

            // Linear damping
            if (LinearDamping != 0)
            {
                // The damping force depends on the damping amount, mass, and velocity
                // (i.e. damping amount and momentum).
                float factor = -LinearDamping * mass.mass;
                Vec3  force  = LinearVelocity * factor;

                // Add a global force opposite to the global linear velocity.
                Ode.dBodyAddForce(bodyID, force.X, force.Y, force.Z);
            }

            // Angular damping
            if (AngularDamping != 0)
            {
                Vec3 localVelocity;
                {
                    Ode.dVector3 aVelLocal = new Ode.dVector3();
                    Ode.dBodyVectorFromWorld(bodyID, AngularVelocity.X, AngularVelocity.Y,
                                             AngularVelocity.Z, ref aVelLocal);
                    localVelocity = Convert.ToNet(aVelLocal);
                }

                // The damping force depends on the damping amount, mass, and velocity
                // (i.e. damping amount and momentum).
                float factor = -AngularDamping;

                Vec3 momentum = new Vec3(
                    Vec3.Dot(new Vec3(mass.I.M00, mass.I.M01, mass.I.M02), localVelocity),
                    Vec3.Dot(new Vec3(mass.I.M10, mass.I.M11, mass.I.M12), localVelocity),
                    Vec3.Dot(new Vec3(mass.I.M20, mass.I.M21, mass.I.M22), localVelocity));

                Vec3 torque = momentum * factor;

                // Add a local torque opposite to the local angular velocity.
                Ode.dBodyAddRelTorque(bodyID, torque.X, torque.Y, torque.Z);
            }
        }
Esempio n. 2
0
        //public override Mat3 GetInertiaTensor()
        //{
        //   if( Static )
        //      return Mat3.Identity;
        //   if( bodyID == dBodyID.Zero )
        //      return Mat3.Zero;

        //   Ode.dMass mass = new Ode.dMass();
        //   Ode.dBodyGetMass( bodyID, ref mass );

        //   return new Mat3(
        //      mass.I.M00, mass.I.M01, mass.I.M02,
        //      mass.I.M10, mass.I.M11, mass.I.M12,
        //      mass.I.M20, mass.I.M21, mass.I.M22 );
        //}

        protected override void ApplyForce(ForceType type, ref Vec3 vector, ref Vec3 pos)
        {
            if (bodyID == dBodyID.Zero)
            {
                return;
            }

            Ode.dBodyEnable(bodyID);

            switch (type)
            {
            case ForceType.Local:
                Ode.dBodyAddRelForce(bodyID, vector.X, vector.Y, vector.Z);
                break;

            case ForceType.Global:
                Ode.dBodyAddForce(bodyID, vector.X, vector.Y, vector.Z);
                break;

            case ForceType.LocalTorque:
                Ode.dBodyAddRelTorque(bodyID, vector.X, vector.Y, vector.Z);
                break;

            case ForceType.GlobalTorque:
                Ode.dBodyAddTorque(bodyID, vector.X, vector.Y, vector.Z);
                break;

            case ForceType.LocalAtLocalPos:
                Ode.dBodyAddRelForceAtRelPos(bodyID, vector.X, vector.Y, vector.Z, pos.X, pos.Y, pos.Z);
                break;

            case ForceType.LocalAtGlobalPos:
                Ode.dBodyAddRelForceAtPos(bodyID, vector.X, vector.Y, vector.Z, pos.X, pos.Y, pos.Z);
                break;

            case ForceType.GlobalAtLocalPos:
                Ode.dBodyAddForceAtRelPos(bodyID, vector.X, vector.Y, vector.Z, pos.X, pos.Y, pos.Z);
                break;

            case ForceType.GlobalAtGlobalPos:
                Ode.dBodyAddForceAtPos(bodyID, vector.X, vector.Y, vector.Z, pos.X, pos.Y, pos.Z);
                break;
            }

            //// Invalidate the "freely-spinning" parameter.
            //freelySpinning = false;
        }