Example #1
0
        protected Matrix GetTransformMatrix(GameObject go)
        {
            UnityEngine.Vector3 pos = go.transform.localPosition;
            Quaternion          rot = go.transform.localRotation;
            Matrix4x4           m   = Matrix4x4.TRS(pos, rot, UnityEngine.Vector3.one);

            return(m.ToBullet());
        }
        /// <summary>
        /// Get translation matrix.
        /// </summary>
        /// <param name="offset">Translation offset.</param>
        /// <returns>
        /// The translation transform matrix.
        /// </returns>
        public static Matrix4x4 TranslationMatrix(UnityEngine.Vector3 offset)
        {
            var matrix = IdentityMatrix;

            matrix.m03 = offset.x;
            matrix.m13 = offset.y;
            matrix.m23 = offset.z;
            return(matrix);
        }
Example #3
0
 protected void Add(PhyBody phyBody, UnityEngine.Vector3 pos)
 {
     Add(phyBody, pos, Quaternion.identity);
 }
Example #4
0
 protected void Add(PhyBody phyBody, UnityEngine.Vector3 pos, Quaternion rot)
 {
     Add(phyBody, Matrix4x4.TRS(pos, rot, UnityEngine.Vector3.one).ToBullet());
 }
 /// <summary>
 /// Convert a Unity Vector3 to BulletSharp
 /// </summary>
 /// <param name="v">Vector3 to be converted</param>
 /// <returns></returns>
 public static Vector3 ToBullet(this UnityEngine.Vector3 v)
 {
     return(new Vector3(v.x, v.y, v.z));
 }
 /// <summary>
 /// Extract position, rotation and scale from TRS matrix.
 /// </summary>
 /// <param name="matrix">Transform matrix. This parameter is passed by reference
 /// to improve performance; no changes will be made to it.</param>
 /// <param name="localPosition">Output position.</param>
 /// <param name="localRotation">Output rotation.</param>
 /// <param name="localScale">Output scale.</param>
 public static void DecomposeMatrix(ref Matrix4x4 matrix, out UnityEngine.Vector3 localPosition, out UnityEngine.Quaternion localRotation, out UnityEngine.Vector3 localScale)
 {
     localPosition = ExtractTranslationFromMatrix(ref matrix);
     localRotation = ExtractRotationFromMatrix(ref matrix);
     localScale    = ExtractScaleFromMatrix(ref matrix);
 }
        //Transform point without scaling
        public static UnityEngine.Vector3 TransformPointUnscaled(this Transform transform, UnityEngine.Vector3 position)
        {
            var localToWorldMatrix = Matrix4x4.TRS(transform.position, transform.rotation, UnityEngine.Vector3.one);

            return(localToWorldMatrix.MultiplyPoint3x4(position));
        }