0

i want to convert my Quaternions in to euler angles but in this function I get an error on result.W. The error is CS0165.

public static Quaternion Euler(string[]text)
{
     double yaw = Convert.ToDouble(text[1]);
     double pitch = Convert.ToDouble(text[2]);
     double roll = Convert.ToDouble(text[3]);

     yaw = (Math.PI / 180) * yaw;
     pitch = (Math.PI / 180) * pitch;
     roll = (Math.PI / 180) * roll;

     double yawOver2 = yaw * 0.5f;
     float cosYawOver2 = (float)System.Math.Cos(yawOver2);
     float sinYawOver2 = (float)System.Math.Sin(yawOver2);
     double pitchOver2 = pitch * 0.5f;
     float cosPitchOver2 = (float)System.Math.Cos(pitchOver2);
     float sinPitchOver2 = (float)System.Math.Sin(pitchOver2);
     double rollOver2 = roll * 0.5f;
     float cosRollOver2 = (float)System.Math.Cos(rollOver2);
     float sinRollOver2 = (float)System.Math.Sin(rollOver2);
     Quaternion result;
     result.W = cosYawOver2 * cosPitchOver2 * cosRollOver2 + sinYawOver2 * sinPitchOver2 * sinRollOver2;
     result.X = sinYawOver2 * cosPitchOver2 * cosRollOver2 + cosYawOver2 * sinPitchOver2 * sinRollOver2;
     result.Y = cosYawOver2 * sinPitchOver2 * cosRollOver2 - sinYawOver2 * cosPitchOver2 * sinRollOver2;
     result.Z = cosYawOver2 * cosPitchOver2 * sinRollOver2 - sinYawOver2 * sinPitchOver2 * cosRollOver2;
     return result;

 }

What could be the problem?

Yurets
  • 3,999
  • 17
  • 54
  • 74

1 Answers1

0

Use of unassigned local variable 'name': https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/compiler-messages/cs0165

You cannot access W because most probably in your Quaternion definition you use properties or some other code that requires explicit object creation.

PepitoSh
  • 1,774
  • 14
  • 13