Strange Rotation Results

Ryborg
Posts: 3
Joined: Sat Oct 24, 2009 4:33 am

Strange Rotation Results

Post by Ryborg »

Hello everyone. I've just started using bullet, and I have to say I really like it. Finally I can actually *hit* walls instead of passing through them as I did prior bullet. Recently I've been working on a first person camera controller that uses the mouse to determine pitch about the x-axis and yaw about the y-axis. It uses a btTransform to represent its rotation and position in the world. However, I've run into something unexpected while experimenting with pitch, yaw, and roll. Take a look at this little code snippet:

Code: Select all

	float pitch = 0;
	float yaw = 90;
	float roll = 0;

	cout << "Pitch = " << pitch << endl;
	cout << "Yaw = " << yaw << endl;
	cout << "Roll = " << roll << endl;
	cout << "--------------------" << endl;

	btQuaternion rotation(btRadians(yaw), btRadians(pitch), btRadians(roll));
	btVector3 axis = rotation.getAxis();
	btScalar angle = rotation.getAngle();

	cout << "Axis X = " << axis.x() << endl;
	cout << "Axis Y = " << axis.y() << endl;
	cout << "Axis Z = " << axis.z() << endl;
	cout << "Angle = " << btDegrees(angle) << endl;
	cout << "--------------------" << endl;

	btMatrix3x3(rotation).getEulerYPR(yaw, pitch, roll);
	pitch = btDegrees(pitch);
	yaw = btDegrees(yaw);
	roll = btDegrees(roll);

	cout << "Pitch = " << pitch << endl;
	cout << "Yaw = " << yaw << endl;
	cout << "Roll = " << roll << endl;
	cout << "--------------------" << endl;

	rotation = btQuaternion(btRadians(yaw), btRadians(pitch), btRadians(roll));
	axis = rotation.getAxis();
	angle = rotation.getAngle();
	cout << "Axis X = " << axis.x() << endl;
	cout << "Axis Y = " << axis.y() << endl;
	cout << "Axis Z = " << axis.z() << endl;
	cout << "Angle = " << btDegrees(angle) << endl;
	cout << "--------------------" << endl;
Here are the printed results from the code above:
Pitch = 0
Yaw = 90
Roll = 0
--------------------
Axis X = 0
Axis Y = 1
Axis Z = 0
Angle = 90
--------------------
Pitch = 90
Yaw = 180
Roll = 180
--------------------
Axis X = 1
Axis Y = 0
Axis Z = 0
Angle = 90
--------------------
The first section is as I would expect.
The second section is as I would expect.
But the third section seems crazy. It doesn't seem to be an equivalent rotation.
RBD
Posts: 141
Joined: Tue Sep 16, 2008 11:31 am

Re: Strange Rotation Results

Post by RBD »

Have you tried getEulerZYX instead?
Check the Bullet issues list and look at issues 282 and 157.