How to properly convert PxQuat to x, y, z axis degrees and back to PxQuat

Hi, I’m new to this forum. I’m learning PhysX, cause i want to implement physics module to my engine. Now i am interested in converting rotations. I am new to quaternions and i would like to know how to properly change from PxQuat to uVector3F (my 3d vector class) and uVector3F to PxQuat.
Here is my actual code:

physx::PxQuat uVector3F::toQuaternion() const
		uVector3F angles = this->toRadians();
		physx::PxReal cos_x = cosf(angles.x);
		physx::PxReal cos_y = cosf(angles.y);
		physx::PxReal cos_z = cosf(angles.z);

		physx::PxReal sin_x = sinf(angles.x);
		physx::PxReal sin_y = sinf(angles.y);
		physx::PxReal sin_z = sinf(angles.z);

		physx::PxQuat quat = physx::PxQuat();

		quat.w = cos_x*cos_y*cos_z + sin_x*sin_y*sin_z;
		quat.x = sin_x*cos_y*cos_z - cos_x*sin_y*sin_z;
		quat.y = cos_x*sin_y*cos_z + sin_x*cos_y*sin_z;
		quat.z = cos_x*cos_y*sin_z - sin_x*sin_y*cos_z;

		return quat;

	uVector3F uVector3F::quaternionToEuler(const physx::PxQuat &quat)
		float sqw = quat.w*quat.w;
		float sqx = quat.x*quat.x;
		float sqy = quat.y*quat.y;
		float sqz = quat.z*quat.z;
		uVector3F euler;
		euler.x = atan2f(2.f * (quat.z*quat.y + quat.x*quat.w), 1 - 2 * (sqx + sqy));
		euler.y = asinf(-2.f * (quat.x*quat.z - quat.y*quat.w));
		euler.z = atan2f(2.f * (quat.x*quat.y + quat.z*quat.w), 1 - 2 * (sqy + sqz));
		return euler;

The first function uVector3F::toQuaternion i found in this forum, so i think it’s working. I think the problem is in second function.
The problem:
I put simple barrel about 40 units above other (super-sized in x,z cause i use this like temporary ground :] ) barrel. I’ve set dynamic barrel rotation to (X,Y,Z) (90, 0, 0) and the barrel is not rotated :( Also, when it ALWAYS returns to 0,0,0 rotation even if it lays on side.


A quaternion can be thought of as the rotation that is generated from pointing an object along a vector and then twisting it around that vector by an angle.

PxQuat can be constructed from an angle/axis representation

PxQuat(float angleRadians, const PvVec3& unitAxis)

You can also get the angle/axis representatin back from a PxQuat

void toRadiansAndUnitAxis(float& angle, PvVec3& axis) const

I think this is what you are looking for in your functions toQuaternion and quaternionToEuler.