示例#1
0
        public static SBSMatrix4x4 TRS(SBSVector3 t, SBSQuaternion q, SBSVector3 s)
        {
            SBSMatrix4x4 r = new SBSMatrix4x4();

            float xy2 = 2.0f * q.x * q.y, xz2 = 2.0f * q.x * q.z, xw2 = 2.0f * q.x * q.w,
                  yz2 = 2.0f * q.y * q.z, yw2 = 2.0f * q.y * q.w, zw2 = 2.0f * q.z * q.w,
                  xx = q.x * q.x, yy = q.y * q.y, zz = q.z * q.z, ww = q.w * q.w,
                  sx = s.x, sy = s.y, sz = s.z;

            r.m00 = (xx - yy - zz + ww) * sx;
            r.m01 = (xy2 + zw2) * sx;
            r.m02 = (xz2 - yw2) * sx;
            r.m03 = 0.0f;
            r.m10 = (xy2 - zw2) * sy;
            r.m11 = (-xx + yy - zz + ww) * sy;
            r.m12 = (yz2 + xw2) * sy;
            r.m13 = 0.0f;
            r.m20 = (xz2 + yw2) * sz;
            r.m21 = (yz2 - xw2) * sz;
            r.m22 = (-xx - yy + zz + ww) * sz;
            r.m23 = 0.0f;
            r.m30 = t.x;
            r.m31 = t.y;
            r.m32 = t.z;
            r.m33 = 1.0f;

            return(r);
        }
示例#2
0
    public override void Initialize()
    {
        base.Initialize();

        _prevLocalToWorld = _transform.localToWorldMatrix;
        _prevWorldToLocal = _transform.worldToLocalMatrix;
    }
示例#3
0
    void Awake()
    {
        matWorld = transform.localToWorldMatrix;

        if (isCenterPivot)
        {
            matWorld *= SBSMatrix4x4.TRS(-Vector3.forward * lengthOrRadius * 0.5f, SBSQuaternion.identity, SBSVector3.one);
        }

        matInvWorld = matWorld.inverseFast;
    }
示例#4
0
    void OnDrawGizmosSelected()
    {
        matWorld = transform.localToWorldMatrix;

        if (isCenterPivot)
        {
            matWorld *= SBSMatrix4x4.TRS(-Vector3.forward * lengthOrRadius * 0.5f, SBSQuaternion.identity, SBSVector3.one);
        }

        matInvWorld = matWorld.inverseFast;

        Gizmos.color = Color.white;
        Gizmos.DrawSphere(transform.position, HandleUtility.GetHandleSize(transform.position) * 0.1f);

        this.DrawGizmos(-1.0f, Color.white);
        this.DrawGizmos(1.0f, Color.white);
    }
示例#5
0
    void Update()
    {
        if (GetComponent <Renderer>() != null)
        {
            _bounds = GetComponent <Renderer>().bounds;
        }
        else if (GetComponent <Collider>() != null)
        {
            _bounds = GetComponent <Collider>().bounds;
        }
        else
        {
            _bounds = new SBSBounds(_transform.position, SBSVector3.zero);
        }

        if (null == cell)
        {
            cell = LevelRoot.Instance.RootCell;
            if (null == cell)
            {
                return;
            }
            cell.AttachObject(this);
        }

        LevelCell newCell = cell.FindObjectContainmentCell(this);

        if (newCell != cell)
        {
            if (cell != null)
            {
                cell.DetachObject(this);
            }

            cell = newCell;
            cell.AttachObject(this);
        }

        _prevLocalToWorld = _localToWorld;
        _prevWorldToLocal = _worldToLocal;

        _localToWorld = _transform.localToWorldMatrix;
        _worldToLocal = _transform.worldToLocalMatrix;
    }
示例#6
0
        public void Transform(SBSMatrix4x4 matrix)
        {
            int i = 0;

            SBSVector3[] vertices = this.GetVertices();

            for (; i < 8; ++i)
#if UNITY_FLASH
            { matrix.MultiplyPoint3x4(vertices[i], vertices[i]); }
#else
            { matrix.MultiplyPoint3x4(vertices[i], out vertices[i]); }
#endif

            this.Reset();
            for (i = 0; i < 8; ++i)
            {
                this.Encapsulate(vertices[i]);
            }
        }
示例#7
0
        public static SBSMatrix4x4 operator *(SBSMatrix4x4 m1, SBSMatrix4x4 m0)
        {
            SBSMatrix4x4 r = new SBSMatrix4x4();

            r.m00 = m0.m00 * m1.m00 + m0.m01 * m1.m10 + m0.m02 * m1.m20 + m0.m03 * m1.m30;
            r.m01 = m0.m00 * m1.m01 + m0.m01 * m1.m11 + m0.m02 * m1.m21 + m0.m03 * m1.m31;
            r.m02 = m0.m00 * m1.m02 + m0.m01 * m1.m12 + m0.m02 * m1.m22 + m0.m03 * m1.m32;
            r.m03 = m0.m00 * m1.m03 + m0.m01 * m1.m13 + m0.m02 * m1.m23 + m0.m03 * m1.m33;
            r.m10 = m0.m10 * m1.m00 + m0.m11 * m1.m10 + m0.m12 * m1.m20 + m0.m13 * m1.m30;
            r.m11 = m0.m10 * m1.m01 + m0.m11 * m1.m11 + m0.m12 * m1.m21 + m0.m13 * m1.m31;
            r.m12 = m0.m10 * m1.m02 + m0.m11 * m1.m12 + m0.m12 * m1.m22 + m0.m13 * m1.m32;
            r.m13 = m0.m10 * m1.m03 + m0.m11 * m1.m13 + m0.m12 * m1.m23 + m0.m13 * m1.m33;
            r.m20 = m0.m20 * m1.m00 + m0.m21 * m1.m10 + m0.m22 * m1.m20 + m0.m23 * m1.m30;
            r.m21 = m0.m20 * m1.m01 + m0.m21 * m1.m11 + m0.m22 * m1.m21 + m0.m23 * m1.m31;
            r.m22 = m0.m20 * m1.m02 + m0.m21 * m1.m12 + m0.m22 * m1.m22 + m0.m23 * m1.m32;
            r.m23 = m0.m20 * m1.m03 + m0.m21 * m1.m13 + m0.m22 * m1.m23 + m0.m23 * m1.m33;
            r.m30 = m0.m30 * m1.m00 + m0.m31 * m1.m10 + m0.m32 * m1.m20 + m0.m33 * m1.m30;
            r.m31 = m0.m30 * m1.m01 + m0.m31 * m1.m11 + m0.m32 * m1.m21 + m0.m33 * m1.m31;
            r.m32 = m0.m30 * m1.m02 + m0.m31 * m1.m12 + m0.m32 * m1.m22 + m0.m33 * m1.m32;
            r.m33 = m0.m30 * m1.m03 + m0.m31 * m1.m13 + m0.m32 * m1.m23 + m0.m33 * m1.m33;
            return(r);
        }
示例#8
0
    public void TokenToWorld(float longitudinal, float trasversal, out SBSVector3 pos, out SBSVector3 tang)
#endif
    {
        switch (type)
        {
        case TokenType.Cross:
        case TokenType.Rect:
#if UNITY_FLASH
            matWorld.MultiplyPoint3x4(SBSVector3.right * (trasversal * width * 0.5f) + SBSVector3.forward * (longitudinal * lengthOrRadius), pos);
            matWorld.MultiplyVector(SBSVector3.forward, tang);
#else
            pos  = matWorld.MultiplyPoint3x4(SBSVector3.right * (trasversal * width * 0.5f) + SBSVector3.forward * (longitudinal * lengthOrRadius));
            tang = matWorld.MultiplyVector(SBSVector3.forward);
#endif
            break;

        case TokenType.Curve:
            SBSVector3 center   = (-curveDir * lengthOrRadius) * SBSVector3.right,
                       offset   = ((trasversal * width * 0.5f) + (curveDir * lengthOrRadius)) * SBSVector3.right;
            SBSMatrix4x4 matTr  = SBSMatrix4x4.TRS(center, SBSQuaternion.identity, SBSVector3.one),
                         matRot = SBSMatrix4x4.TRS(SBSVector3.zero, SBSQuaternion.AngleAxis(-arcAngle * curveDir * longitudinal, SBSVector3.up), SBSVector3.one);

#if UNITY_FLASH
            (matWorld * matTr * matRot).MultiplyPoint3x4(offset, pos);
            (matWorld * matRot).MultiplyVector(SBSVector3.forward, tang);
#else
            pos  = (matWorld * matTr * matRot).MultiplyPoint3x4(offset);
            tang = (matWorld * matRot).MultiplyVector(SBSVector3.forward);
#endif
            break;

        default:
            pos.x  = pos.y = pos.z = 0.0f;
            tang.x = tang.y = tang.z = 0.0f;
            break;
        }
    }
示例#9
0
    public virtual void Initialize()
    {
        _transform    = transform;
        _localToWorld = _transform.localToWorldMatrix;
        _worldToLocal = _transform.worldToLocalMatrix;

        if (GetComponent <Renderer>() != null)
        {
            _bounds = GetComponent <Renderer>().bounds;
        }
        else if (GetComponent <Collider>() != null)
        {
            _bounds = GetComponent <Collider>().bounds;
        }
        else
        {
            _bounds = new SBSBounds(_localToWorld.position, SBSVector3.zero);
        }

        cell = LevelRoot.Instance.RootCell.FindObjectContainmentCell(this);
        cell.AttachObject(this);

        gameObject.SendMessage("OnInit", SendMessageOptions.DontRequireReceiver);
    }
示例#10
0
        public void Prepend(SBSMatrix4x4 m1)
        {
            float _m00 = m00, _m01 = m01, _m02 = m02, _m03 = m03,
                  _m10 = m10, _m11 = m11, _m12 = m12, _m13 = m13,
                  _m20 = m20, _m21 = m21, _m22 = m22, _m23 = m23,
                  _m30 = m30, _m31 = m31, _m32 = m32, _m33 = m33;

            m00 = _m00 * m1.m00 + _m01 * m1.m10 + _m02 * m1.m20 + _m03 * m1.m30;
            m01 = _m00 * m1.m01 + _m01 * m1.m11 + _m02 * m1.m21 + _m03 * m1.m31;
            m02 = _m00 * m1.m02 + _m01 * m1.m12 + _m02 * m1.m22 + _m03 * m1.m32;
            m03 = _m00 * m1.m03 + _m01 * m1.m13 + _m02 * m1.m23 + _m03 * m1.m33;
            m10 = _m10 * m1.m00 + _m11 * m1.m10 + _m12 * m1.m20 + _m13 * m1.m30;
            m11 = _m10 * m1.m01 + _m11 * m1.m11 + _m12 * m1.m21 + _m13 * m1.m31;
            m12 = _m10 * m1.m02 + _m11 * m1.m12 + _m12 * m1.m22 + _m13 * m1.m32;
            m13 = _m10 * m1.m03 + _m11 * m1.m13 + _m12 * m1.m23 + _m13 * m1.m33;
            m20 = _m20 * m1.m00 + _m21 * m1.m10 + _m22 * m1.m20 + _m23 * m1.m30;
            m21 = _m20 * m1.m01 + _m21 * m1.m11 + _m22 * m1.m21 + _m23 * m1.m31;
            m22 = _m20 * m1.m02 + _m21 * m1.m12 + _m22 * m1.m22 + _m23 * m1.m32;
            m23 = _m20 * m1.m03 + _m21 * m1.m13 + _m22 * m1.m23 + _m23 * m1.m33;
            m30 = _m30 * m1.m00 + _m31 * m1.m10 + _m32 * m1.m20 + _m33 * m1.m30;
            m31 = _m30 * m1.m01 + _m31 * m1.m11 + _m32 * m1.m21 + _m33 * m1.m31;
            m32 = _m30 * m1.m02 + _m31 * m1.m12 + _m32 * m1.m22 + _m33 * m1.m32;
            m33 = _m30 * m1.m03 + _m31 * m1.m13 + _m32 * m1.m23 + _m33 * m1.m33;
        }
示例#11
0
        public void Append(SBSMatrix4x4 m0)
        {
            float _m00 = m00, _m01 = m01, _m02 = m02, _m03 = m03,
                  _m10 = m10, _m11 = m11, _m12 = m12, _m13 = m13,
                  _m20 = m20, _m21 = m21, _m22 = m22, _m23 = m23,
                  _m30 = m30, _m31 = m31, _m32 = m32, _m33 = m33;

            m00 = m0.m00 * _m00 + m0.m01 * _m10 + m0.m02 * _m20 + m0.m03 * _m30;
            m01 = m0.m00 * _m01 + m0.m01 * _m11 + m0.m02 * _m21 + m0.m03 * _m31;
            m02 = m0.m00 * _m02 + m0.m01 * _m12 + m0.m02 * _m22 + m0.m03 * _m32;
            m03 = m0.m00 * _m03 + m0.m01 * _m13 + m0.m02 * _m23 + m0.m03 * _m33;
            m10 = m0.m10 * _m00 + m0.m11 * _m10 + m0.m12 * _m20 + m0.m13 * _m30;
            m11 = m0.m10 * _m01 + m0.m11 * _m11 + m0.m12 * _m21 + m0.m13 * _m31;
            m12 = m0.m10 * _m02 + m0.m11 * _m12 + m0.m12 * _m22 + m0.m13 * _m32;
            m13 = m0.m10 * _m03 + m0.m11 * _m13 + m0.m12 * _m23 + m0.m13 * _m33;
            m20 = m0.m20 * _m00 + m0.m21 * _m10 + m0.m22 * _m20 + m0.m23 * _m30;
            m21 = m0.m20 * _m01 + m0.m21 * _m11 + m0.m22 * _m21 + m0.m23 * _m31;
            m22 = m0.m20 * _m02 + m0.m21 * _m12 + m0.m22 * _m22 + m0.m23 * _m32;
            m23 = m0.m20 * _m03 + m0.m21 * _m13 + m0.m22 * _m23 + m0.m23 * _m33;
            m30 = m0.m30 * _m00 + m0.m31 * _m10 + m0.m32 * _m20 + m0.m33 * _m30;
            m31 = m0.m30 * _m01 + m0.m31 * _m11 + m0.m32 * _m21 + m0.m33 * _m31;
            m32 = m0.m30 * _m02 + m0.m31 * _m12 + m0.m32 * _m22 + m0.m33 * _m32;
            m33 = m0.m30 * _m03 + m0.m31 * _m13 + m0.m32 * _m23 + m0.m33 * _m33;
        }
 public void Prepend(SBSMatrix4x4 m1)
 {
     float _m00 = m00, _m01 = m01, _m02 = m02, _m03 = m03,
           _m10 = m10, _m11 = m11, _m12 = m12, _m13 = m13,
           _m20 = m20, _m21 = m21, _m22 = m22, _m23 = m23,
           _m30 = m30, _m31 = m31, _m32 = m32, _m33 = m33;
     m00 = _m00 * m1.m00 + _m01 * m1.m10 + _m02 * m1.m20 + _m03 * m1.m30;
     m01 = _m00 * m1.m01 + _m01 * m1.m11 + _m02 * m1.m21 + _m03 * m1.m31;
     m02 = _m00 * m1.m02 + _m01 * m1.m12 + _m02 * m1.m22 + _m03 * m1.m32;
     m03 = _m00 * m1.m03 + _m01 * m1.m13 + _m02 * m1.m23 + _m03 * m1.m33;
     m10 = _m10 * m1.m00 + _m11 * m1.m10 + _m12 * m1.m20 + _m13 * m1.m30;
     m11 = _m10 * m1.m01 + _m11 * m1.m11 + _m12 * m1.m21 + _m13 * m1.m31;
     m12 = _m10 * m1.m02 + _m11 * m1.m12 + _m12 * m1.m22 + _m13 * m1.m32;
     m13 = _m10 * m1.m03 + _m11 * m1.m13 + _m12 * m1.m23 + _m13 * m1.m33;
     m20 = _m20 * m1.m00 + _m21 * m1.m10 + _m22 * m1.m20 + _m23 * m1.m30;
     m21 = _m20 * m1.m01 + _m21 * m1.m11 + _m22 * m1.m21 + _m23 * m1.m31;
     m22 = _m20 * m1.m02 + _m21 * m1.m12 + _m22 * m1.m22 + _m23 * m1.m32;
     m23 = _m20 * m1.m03 + _m21 * m1.m13 + _m22 * m1.m23 + _m23 * m1.m33;
     m30 = _m30 * m1.m00 + _m31 * m1.m10 + _m32 * m1.m20 + _m33 * m1.m30;
     m31 = _m30 * m1.m01 + _m31 * m1.m11 + _m32 * m1.m21 + _m33 * m1.m31;
     m32 = _m30 * m1.m02 + _m31 * m1.m12 + _m32 * m1.m22 + _m33 * m1.m32;
     m33 = _m30 * m1.m03 + _m31 * m1.m13 + _m32 * m1.m23 + _m33 * m1.m33;
 }
 public void Append(SBSMatrix4x4 m0)
 {
     float _m00 = m00, _m01 = m01, _m02 = m02, _m03 = m03,
           _m10 = m10, _m11 = m11, _m12 = m12, _m13 = m13,
           _m20 = m20, _m21 = m21, _m22 = m22, _m23 = m23,
           _m30 = m30, _m31 = m31, _m32 = m32, _m33 = m33;
     m00 = m0.m00 * _m00 + m0.m01 * _m10 + m0.m02 * _m20 + m0.m03 * _m30;
     m01 = m0.m00 * _m01 + m0.m01 * _m11 + m0.m02 * _m21 + m0.m03 * _m31;
     m02 = m0.m00 * _m02 + m0.m01 * _m12 + m0.m02 * _m22 + m0.m03 * _m32;
     m03 = m0.m00 * _m03 + m0.m01 * _m13 + m0.m02 * _m23 + m0.m03 * _m33;
     m10 = m0.m10 * _m00 + m0.m11 * _m10 + m0.m12 * _m20 + m0.m13 * _m30;
     m11 = m0.m10 * _m01 + m0.m11 * _m11 + m0.m12 * _m21 + m0.m13 * _m31;
     m12 = m0.m10 * _m02 + m0.m11 * _m12 + m0.m12 * _m22 + m0.m13 * _m32;
     m13 = m0.m10 * _m03 + m0.m11 * _m13 + m0.m12 * _m23 + m0.m13 * _m33;
     m20 = m0.m20 * _m00 + m0.m21 * _m10 + m0.m22 * _m20 + m0.m23 * _m30;
     m21 = m0.m20 * _m01 + m0.m21 * _m11 + m0.m22 * _m21 + m0.m23 * _m31;
     m22 = m0.m20 * _m02 + m0.m21 * _m12 + m0.m22 * _m22 + m0.m23 * _m32;
     m23 = m0.m20 * _m03 + m0.m21 * _m13 + m0.m22 * _m23 + m0.m23 * _m33;
     m30 = m0.m30 * _m00 + m0.m31 * _m10 + m0.m32 * _m20 + m0.m33 * _m30;
     m31 = m0.m30 * _m01 + m0.m31 * _m11 + m0.m32 * _m21 + m0.m33 * _m31;
     m32 = m0.m30 * _m02 + m0.m31 * _m12 + m0.m32 * _m22 + m0.m33 * _m32;
     m33 = m0.m30 * _m03 + m0.m31 * _m13 + m0.m32 * _m23 + m0.m33 * _m33;
 }
		public static SBSMatrix4x4 TRS(SBSVector3 t, SBSQuaternion q, SBSVector3 s)
		{
			SBSMatrix4x4 r = new SBSMatrix4x4();

			float xy2 = 2.0f * q.x * q.y, xz2 = 2.0f * q.x * q.z, xw2 = 2.0f * q.x * q.w,
				  yz2 = 2.0f * q.y * q.z, yw2 = 2.0f * q.y * q.w, zw2 = 2.0f * q.z * q.w,
				  xx = q.x * q.x, yy = q.y * q.y, zz = q.z * q.z, ww = q.w * q.w,
				  sx = s.x, sy = s.y, sz = s.z;
			
			r.m00 = (xx - yy - zz + ww) * sx;
			r.m01 = (xy2 + zw2) * sx;
			r.m02 = (xz2 - yw2) * sx;
			r.m03 = 0.0f;
			r.m10 = (xy2 - zw2) * sy;
			r.m11 = (-xx + yy - zz + ww) * sy;
			r.m12 = (yz2 + xw2) * sy;
			r.m13 = 0.0f;
			r.m20 = (xz2 + yw2) * sz;
			r.m21 = (yz2 - xw2) * sz;
			r.m22 = (-xx - yy + zz + ww) * sz;
			r.m23 = 0.0f;
			r.m30 = t.x;
			r.m31 = t.y;
			r.m32 = t.z;
			r.m33 = 1.0f;

			return r;
		}
		public static SBSMatrix4x4 operator *(SBSMatrix4x4 m1, SBSMatrix4x4 m0)
		{
            SBSMatrix4x4 r = new SBSMatrix4x4();
	        r.m00 = m0.m00 * m1.m00 + m0.m01 * m1.m10 + m0.m02 * m1.m20 + m0.m03 * m1.m30;
	        r.m01 = m0.m00 * m1.m01 + m0.m01 * m1.m11 + m0.m02 * m1.m21 + m0.m03 * m1.m31;
	        r.m02 = m0.m00 * m1.m02 + m0.m01 * m1.m12 + m0.m02 * m1.m22 + m0.m03 * m1.m32;
	        r.m03 = m0.m00 * m1.m03 + m0.m01 * m1.m13 + m0.m02 * m1.m23 + m0.m03 * m1.m33;
	        r.m10 = m0.m10 * m1.m00 + m0.m11 * m1.m10 + m0.m12 * m1.m20 + m0.m13 * m1.m30;
	        r.m11 = m0.m10 * m1.m01 + m0.m11 * m1.m11 + m0.m12 * m1.m21 + m0.m13 * m1.m31;
	        r.m12 = m0.m10 * m1.m02 + m0.m11 * m1.m12 + m0.m12 * m1.m22 + m0.m13 * m1.m32;
	        r.m13 = m0.m10 * m1.m03 + m0.m11 * m1.m13 + m0.m12 * m1.m23 + m0.m13 * m1.m33;
	        r.m20 = m0.m20 * m1.m00 + m0.m21 * m1.m10 + m0.m22 * m1.m20 + m0.m23 * m1.m30;
	        r.m21 = m0.m20 * m1.m01 + m0.m21 * m1.m11 + m0.m22 * m1.m21 + m0.m23 * m1.m31;
	        r.m22 = m0.m20 * m1.m02 + m0.m21 * m1.m12 + m0.m22 * m1.m22 + m0.m23 * m1.m32;
	        r.m23 = m0.m20 * m1.m03 + m0.m21 * m1.m13 + m0.m22 * m1.m23 + m0.m23 * m1.m33;
	        r.m30 = m0.m30 * m1.m00 + m0.m31 * m1.m10 + m0.m32 * m1.m20 + m0.m33 * m1.m30;
	        r.m31 = m0.m30 * m1.m01 + m0.m31 * m1.m11 + m0.m32 * m1.m21 + m0.m33 * m1.m31;
	        r.m32 = m0.m30 * m1.m02 + m0.m31 * m1.m12 + m0.m32 * m1.m22 + m0.m33 * m1.m32;
	        r.m33 = m0.m30 * m1.m03 + m0.m31 * m1.m13 + m0.m32 * m1.m23 + m0.m33 * m1.m33;
			return r;
		}