Unity3d TweenRotation 使用

/*
	 * parentQuate:須要變換的對像
	 * angleX,angleY,angleZ:	旋轉哪一個方向
	 * angle:須要旋轉的角度   0~360
	 */
	static public Quaternion ChangeRotation(GameObject parnetQuate, float angleX, float angleY, float angleZ, float angle,bool IsAnimation,float duration)
	{
        Quaternion ans	=	Quaternion.identity;
		if( parnetQuate == null )return ans;
		float norm; 
        float ccc, sss; 
          
		angle  *= 3.14f / 180.0f;
        ans.w = ans.x = ans.y = ans.z = 0.0f; 
  
        norm = angleX * angleX + angleY * angleY + angleZ * angleZ; 
        if(norm <= 0.0f) 
		{
			if( IsAnimation)
  				TweenRotation.Begin(parnetQuate,duration,ans);
			return ans; 
		}
        norm = 1.0f / Mathf.Sqrt(norm); 
        angleX *= norm; 
        angleY *= norm; 
        angleZ *= norm; 
  
        ccc = Mathf.Cos(0.5f * angle); 
        sss = Mathf.Sin(0.5f * angle); 
  		
        ans.w = ccc; 
        ans.x = sss * angleX; 
        ans.y = sss * angleY; 
        ans.z = sss * angleZ; 
		if( IsAnimation)
  			TweenRotation.Begin(parnetQuate,duration,ans);
        return ans; 
	}
相關文章
相關標籤/搜索