public Quaternion ToQuaternion() { // https://en.wikipedia.org/wiki/Conversion_between_quaternions_and_Euler_angles // [X=Yaw, Y=Pitch, Z=Roll] to Quaternion float yaw = RyneMath.DegreesToRadians(X) * 0.5f; float pitch = RyneMath.DegreesToRadians(Y) * 0.5f; float roll = RyneMath.DegreesToRadians(Z) * 0.5f; float cy = RyneMath.Cos(yaw); float sy = RyneMath.Sin(yaw); float cp = RyneMath.Cos(pitch); float sp = RyneMath.Sin(pitch); float cr = RyneMath.Cos(roll); float sr = RyneMath.Sin(roll); Quaternion result = new Quaternion { W = cy * cp * cr + sy * sp * sr, X = cy * cp * sr - sy * sp * cr, Y = sy * cp * sr + cy * sp * cr, Z = sy * cp * cr - cy * sp * sr }; return(result); }
public Quaternion(Float3 axis, float angle, bool degrees = true) { //qx = ax * sin(angle/2) //qy = ay * sin(angle/2) //qz = az * sin(angle/2) //qw = cos(angle/2) if (degrees) { angle = RyneMath.DegreesToRadians(angle); } float halfAngle = angle * 0.5f; Float4 data = new Float4(axis * RyneMath.Sin(halfAngle), RyneMath.Cos(halfAngle)).Normalize(); SetData(out this, data); }