Box2D.Common.Vec2.Normalize C# (CSharp) Method

Normalize() public method

Normalize this vector and return the length before normalization. Alters this vector.
public Normalize ( ) : float
return float
        public float Normalize()
        {
            float length = Length();
            if (length < Settings.EPSILON)
            {
                return 0f;
            }

            float invLength = 1.0f / length;
            X *= invLength;
            Y *= invLength;
            return length;
        }

Usage Example

Beispiel #1
0
        public PrismaticJoint(IWorldPool argWorld, PrismaticJointDef def)
            : base(argWorld, def)
        {
            LocalAnchorA = new Vec2(def.LocalAnchorA);
            LocalAnchorB = new Vec2(def.LocalAnchorB);
            LocalXAxisA = new Vec2(def.LocalAxisA);
            LocalXAxisA.Normalize();
            LocalYAxisA = new Vec2();
            Vec2.CrossToOutUnsafe(1f, LocalXAxisA, LocalYAxisA);
            ReferenceAngle = def.ReferenceAngle;

            Impulse = new Vec3();
            MotorMass = 0.0f;
            MotorImpulse = 0.0f;

            LowerTranslation = def.LowerTranslation;
            UpperTranslation = def.UpperTranslation;
            m_maxMotorForce = def.MaxMotorForce;
            m_motorSpeed = def.MotorSpeed;
            m_limitEnabled = def.EnableLimit;
            m_motorEnabled = def.EnableMotor;
            LimitState = LimitState.Inactive;

            K = new Mat33();
            Axis = new Vec2();
            Perp = new Vec2();
        }