MulLocal() public method

Multiply this vector by a number and return result - alters this vector.
public MulLocal ( float a ) : Vec2
a float
return Vec2
Beispiel #1
0
        public void ComputeCentroidToOut(Vec2[] vs, int count, Vec2 result)
        {
            Debug.Assert(count >= 3);

            result.Set(0.0f, 0.0f);
            float area = 0.0f;

            // pRef is the reference point for forming triangles.
            // It's location doesn't change the result (except for rounding error).
            Vec2 pRef = pool1;
            pRef.SetZero();

            Vec2 e1 = pool2;
            Vec2 e2 = pool3;

            const float inv3 = 1.0f / 3.0f;

            for (int i = 0; i < count; ++i)
            {
                // Triangle vertices.
                Vec2 p1 = pRef;
                Vec2 p2 = vs[i];
                Vec2 p3 = i + 1 < count ? vs[i + 1] : vs[0];

                e1.Set(p2).SubLocal(p1);
                e2.Set(p3).SubLocal(p1);

                float D = Vec2.Cross(e1, e2);

                float triangleArea = 0.5f * D;
                area += triangleArea;

                // Area weighted centroid
                e1.Set(p1).AddLocal(p2).AddLocal(p3).MulLocal(triangleArea * inv3);
                result.AddLocal(e1);
            }

            // Centroid
            Debug.Assert(area > Settings.EPSILON);
            result.MulLocal(1.0f / area);
        }
Beispiel #2
0
 /// <seealso cref="Joint.GetReactionForce(float, Vec2)"></seealso>
 public override void GetReactionForce(float inv_dt, Vec2 argOut)
 {
     argOut.Set(m_impulse.X, m_impulse.Y);
     argOut.MulLocal(inv_dt);
 }