Ejemplo n.º 1
0
            //

            public void UpdateToLibrary(bool updateDirection)
            {
                if (joint.jointID == IntPtr.Zero)
                {
                    return;
                }

                if (updateDirection)
                {
                    Ode.dJointSetHingeAxis(joint.jointID, Direction.X, Direction.Y, Direction.Z);
                }

                //limits

                Range range;

                if (LimitsEnabled)
                {
                    if (joint.Body1.Static)
                    {
                        range = new Range(LimitLow.InRadians(), LimitHigh.InRadians());
                    }
                    else
                    {
                        range = new Range(-LimitHigh.InRadians(), -LimitLow.InRadians());
                    }
                }
                else
                {
                    range = new Range(-Ode.dInfinity, Ode.dInfinity);
                }

                // Both limits must be set twice because of a ODE bug in
                // the limit setting function.
                Ode.dJointSetHingeParam(joint.jointID, Ode.dJointParams.dParamLoStop, range.Minimum);
                Ode.dJointSetHingeParam(joint.jointID, Ode.dJointParams.dParamHiStop, range.Maximum);
                Ode.dJointSetHingeParam(joint.jointID, Ode.dJointParams.dParamLoStop, range.Minimum);
                Ode.dJointSetHingeParam(joint.jointID, Ode.dJointParams.dParamHiStop, range.Maximum);

                float h = LimitsRestitution * (Defines.maxERP - Defines.minERP) + Defines.minERP;

                Ode.dJointSetHingeParam(joint.jointID, Ode.dJointParams.dParamStopERP, h);

                float b = LimitsRestitution * (Defines.maxERP - Defines.minERP) + Defines.minERP;

                Ode.dJointSetHingeParam(joint.jointID, Ode.dJointParams.dParamBounce, b);
            }
            public void UpdateToLibrary(bool updateDirection)
            {
                if (joint.jointID == IntPtr.Zero)
                {
                    return;
                }

                if (updateDirection)
                {
                    if (index == 1)
                    {
                        Ode.dJointSetUniversalAxis1(joint.jointID, Direction.X, Direction.Y, Direction.Z);
                    }
                    else
                    {
                        Ode.dJointSetUniversalAxis2(joint.jointID, Direction.X, Direction.Y, Direction.Z);
                    }
                }

                //limits

                int useIndex;

                if (!joint.Body1.Static)
                {
                    useIndex = index == 1 ? 1 : 2;
                }
                else
                {
                    useIndex = index == 1 ? 2 : 1;
                }

                Range range;

                if (LimitsEnabled)
                {
                    if (!joint.Body1.Static)
                    {
                        range = new Range(LimitLow.InRadians(), LimitHigh.InRadians());
                    }
                    else
                    {
                        range = new Range(-LimitHigh.InRadians(), -LimitLow.InRadians());
                    }
                }
                else
                {
                    range = new Range(-Ode.dInfinity, Ode.dInfinity);
                }

                // Both limits must be set twice because of a ODE bug in
                // the limit setting function.

                Ode.dJointSetUniversalParam(joint.jointID, (useIndex == 1) ?
                                            Ode.dJointParams.dParamLoStop : Ode.dJointParams.dParamLoStop2, range.Minimum);
                Ode.dJointSetUniversalParam(joint.jointID, (useIndex == 1) ?
                                            Ode.dJointParams.dParamHiStop : Ode.dJointParams.dParamHiStop2, range.Maximum);
                Ode.dJointSetUniversalParam(joint.jointID, (useIndex == 1) ?
                                            Ode.dJointParams.dParamLoStop : Ode.dJointParams.dParamLoStop2, range.Minimum);
                Ode.dJointSetUniversalParam(joint.jointID, (useIndex == 1) ?
                                            Ode.dJointParams.dParamHiStop : Ode.dJointParams.dParamHiStop2, range.Maximum);

                float h = LimitsRestitution * (Defines.maxERP - Defines.minERP) + Defines.minERP;

                Ode.dJointSetUniversalParam(joint.jointID, (useIndex == 1) ?
                                            Ode.dJointParams.dParamStopERP : Ode.dJointParams.dParamStopERP2, h);

                float b = LimitsRestitution * (Defines.maxERP - Defines.minERP) + Defines.minERP;

                Ode.dJointSetUniversalParam(joint.jointID, (useIndex == 1) ?
                                            Ode.dJointParams.dParamBounce : Ode.dJointParams.dParamBounce2, b);
            }
Ejemplo n.º 3
0
            public void UpdateToLibrary(bool updateDirection)
            {
                if (joint.jointID == IntPtr.Zero)
                {
                    return;
                }

                //—уществует важное ограничение при использовании euler углов:
                //угол theta 1 не должен выходить за пределы - pi /2 ... pi /2.
                //≈сли это случитс¤ то AMotor станет не стабильным (эта особенность +/- pi /2).
                //“аким образом, вы должны установить подход¤щие остановки(stops) на оси 1.

                if (updateDirection)
                {
                    if (index == 1)
                    {
                        Ode.dJointSetAMotorAxis(joint.aMotorID, 0, joint.Body1.Static ? 0 : 1,
                                                Direction.X, Direction.Y, Direction.Z);
                    }
                    if (index == 3)
                    {
                        Ode.dJointSetAMotorAxis(joint.aMotorID, 2, joint.Body2.Static ? 0 : 2,
                                                Direction.X, Direction.Y, Direction.Z);
                    }
                }

                //limits

                Range range;

                if (LimitsEnabled)
                {
                    if (!joint.Body1.Static)
                    {
                        range = new Range(LimitLow.InRadians(), LimitHigh.InRadians());
                    }
                    else
                    {
                        range = new Range(-LimitHigh.InRadians(), -LimitLow.InRadians());
                    }
                }
                else
                {
                    range = new Range(-Ode.dInfinity, Ode.dInfinity);
                }

                Ode.dJointParams p = (Ode.dJointParams) 0;

                // Both limits must be set twice because of a ODE bug in
                // the limit setting function.
                for (int z = 0; z < 2; z++)
                {
                    if (!joint.Body1.Static)
                    {
                        switch (index)
                        {
                        case 1: p = Ode.dJointParams.dParamLoStop; break;

                        case 2: p = Ode.dJointParams.dParamLoStop2; break;

                        case 3: p = Ode.dJointParams.dParamLoStop3; break;
                        }
                    }
                    else
                    {
                        switch (index)
                        {
                        case 1: p = Ode.dJointParams.dParamLoStop; break;

                        case 2: p = Ode.dJointParams.dParamLoStop2; break;

                        case 3: p = Ode.dJointParams.dParamLoStop3; break;
                        }
                    }
                    Ode.dJointSetAMotorParam(joint.aMotorID, p, range.Minimum);

                    if (!joint.Body1.Static)
                    {
                        switch (index)
                        {
                        case 1: p = Ode.dJointParams.dParamHiStop; break;

                        case 2: p = Ode.dJointParams.dParamHiStop2; break;

                        case 3: p = Ode.dJointParams.dParamHiStop3; break;
                        }
                    }
                    else
                    {
                        switch (index)
                        {
                        case 1: p = Ode.dJointParams.dParamHiStop; break;

                        case 2: p = Ode.dJointParams.dParamHiStop2; break;

                        case 3: p = Ode.dJointParams.dParamHiStop3; break;
                        }
                    }
                    Ode.dJointSetAMotorParam(joint.aMotorID, p, range.Maximum);
                }

                if (!joint.Body1.Static)
                {
                    switch (index)
                    {
                    case 1: p = Ode.dJointParams.dParamStopERP; break;

                    case 2: p = Ode.dJointParams.dParamStopERP2; break;

                    case 3: p = Ode.dJointParams.dParamStopERP3; break;
                    }
                }
                else
                {
                    switch (index)
                    {
                    case 1: p = Ode.dJointParams.dParamStopERP; break;

                    case 2: p = Ode.dJointParams.dParamStopERP2; break;

                    case 3: p = Ode.dJointParams.dParamStopERP3; break;
                    }
                }
                float h = LimitsRestitution * (Defines.maxERP - Defines.minERP) + Defines.minERP;

                Ode.dJointSetAMotorParam(joint.aMotorID, p, h);

                if (!joint.Body1.Static)
                {
                    switch (index)
                    {
                    case 1: p = Ode.dJointParams.dParamBounce; break;

                    case 2: p = Ode.dJointParams.dParamBounce2; break;

                    case 3: p = Ode.dJointParams.dParamBounce3; break;
                    }
                }
                else
                {
                    switch (index)
                    {
                    case 1: p = Ode.dJointParams.dParamBounce; break;

                    case 2: p = Ode.dJointParams.dParamBounce2; break;

                    case 3: p = Ode.dJointParams.dParamBounce3; break;
                    }
                }
                float b = LimitsRestitution * (Defines.maxERP - Defines.minERP) + Defines.minERP;

                Ode.dJointSetAMotorParam(joint.aMotorID, p, b);
            }
Ejemplo n.º 4
0
            public void UpdateToLibrary(bool updateDirection)
            {
                if (joint.jointID == IntPtr.Zero)
                {
                    return;
                }

                if (updateDirection)
                {
                    if (index == 1)
                    {
                        Ode.dJointSetHinge2Axis1(joint.jointID, Direction.X, Direction.Y, Direction.Z);
                    }
                    else
                    {
                        Ode.dJointSetHinge2Axis2(joint.jointID, Direction.X, Direction.Y, Direction.Z);
                    }
                }

                //limits

                Range range;

                if (LimitsEnabled)
                {
                    range = new Range(LimitLow.InRadians(), LimitHigh.InRadians());
                }
                else
                {
                    range = new Range(-Ode.dInfinity, Ode.dInfinity);
                }

                // Both limits must be set twice because of a ODE bug in
                // the limit setting function.

                Ode.dJointSetHinge2Param(joint.jointID, (index == 1) ?
                                         Ode.dJointParams.dParamLoStop : Ode.dJointParams.dParamLoStop2, range.Minimum);
                Ode.dJointSetHinge2Param(joint.jointID, (index == 1) ?
                                         Ode.dJointParams.dParamHiStop : Ode.dJointParams.dParamHiStop2, range.Maximum);
                Ode.dJointSetHinge2Param(joint.jointID, (index == 1) ?
                                         Ode.dJointParams.dParamLoStop : Ode.dJointParams.dParamLoStop2, range.Minimum);
                Ode.dJointSetHinge2Param(joint.jointID, (index == 1) ?
                                         Ode.dJointParams.dParamHiStop : Ode.dJointParams.dParamHiStop2, range.Maximum);

                float h = LimitsRestitution * (Defines.maxERP - Defines.minERP) + Defines.minERP;

                Ode.dJointSetHinge2Param(joint.jointID, (index == 1) ?
                                         Ode.dJointParams.dParamStopERP : Ode.dJointParams.dParamStopERP2, h);

                // ODE's Hinge2 Joint also has a suspension parameter. Use axis 2
                // for this since axis 2 doesn't use limits anyway.
                if (index == 2)
                {
                    Ode.dJointSetHinge2Param(joint.jointID, Ode.dJointParams.dParamSuspensionERP,
                                             LimitsRestitution);
                }

                float b = LimitsRestitution * (Defines.maxERP - Defines.minERP) + Defines.minERP;

                Ode.dJointSetHinge2Param(joint.jointID, (index == 1) ?
                                         Ode.dJointParams.dParamBounce : Ode.dJointParams.dParamBounce2, b);
            }