@@ -141,7 +141,7 @@ public void WriteObjectPacked(object value)
141141 }
142142 else if ( value is Quaternion )
143143 {
144- WriteRotation ( ( Quaternion ) value , 3 ) ;
144+ WriteRotationPacked ( ( Quaternion ) value ) ;
145145 return ;
146146 }
147147 else if ( value is char )
@@ -389,23 +389,31 @@ public void WriteRangedDouble(double value, double minValue, double maxValue, in
389389 }
390390
391391 /// <summary>
392- /// Write a rotation to the stream.
392+ /// Writes the rotation to the stream.
393393 /// </summary>
394394 /// <param name="rotation">Rotation to write</param>
395- /// <param name="bytesPerAngle">How many bytes each written angle should occupy. Must be between 1 and 4 (inclusive)</param>
396- public void WriteRotation ( Quaternion rotation , int bytesPerAngle )
395+ public void WriteRotationPacked ( Quaternion rotation )
397396 {
398- if ( bytesPerAngle < 1 || bytesPerAngle > 4 ) throw new ArgumentOutOfRangeException ( "Bytes per angle must be at least 1 byte and at most 4 bytes!" ) ;
399- if ( bytesPerAngle == 4 ) WriteVector3 ( rotation . eulerAngles ) ;
397+ if ( Mathf . Sign ( rotation . w ) < 0 )
398+ {
399+ WriteSinglePacked ( - rotation . x ) ;
400+ WriteSinglePacked ( - rotation . y ) ;
401+ WriteSinglePacked ( - rotation . z ) ;
402+ }
400403 else
401404 {
402- Vector3 rot = rotation . eulerAngles ;
403- WriteRangedSingle ( rot . x , 0f , 360f , bytesPerAngle ) ;
404- WriteRangedSingle ( rot . y , 0f , 360f , bytesPerAngle ) ;
405- WriteRangedSingle ( rot . z , 0f , 360f , bytesPerAngle ) ;
405+ WriteSinglePacked ( rotation . x ) ;
406+ WriteSinglePacked ( rotation . y ) ;
407+ WriteSinglePacked ( rotation . z ) ;
406408 }
407409 }
408410
411+ [ Obsolete ( "Use WriteRotationPacked instead" ) ]
412+ public void WriteRotation ( Quaternion rotation , int bytesPerAngle )
413+ {
414+ WriteRotationPacked ( rotation ) ;
415+ }
416+
409417 /// <summary>
410418 /// Writes a single bit
411419 /// </summary>
0 commit comments