[SOLVED] PhysX Rotation Problem.

CodeKrash

17-03-2011 04:13:36

Hello, I'm having some luck with character controllers in physx, and have run into a mathematical noob problem that I need help with.

It works well, but the issue is that I'm totally limited to a 180 degree radius, and multiplying that by 2 to somehow increase its "resolution" only makes the rotation break. What critical piece of knowledge am I lacking here?

private bool mouseMoved(MouseEvent arg)
{
float RotateScale_CameraPitch = .001f;//mouse sensitivity
float RotateScale_PlayerTurn = .05f;//mouse sensitivity
MouseState_NativePtr s = arg.state;
if (arg.state.buttons == 2)
{
axleaxis = s.X.rel * RotateScale_PlayerTurn;
chat("____________________________________________________________");
nodes["orbit0"].Pitch(s.Y.rel * RotateScale_CameraPitch);
Mogre.Quaternion orient1 = control.Actor.GlobalOrientationQuaternion;
Mogre.Vector3 rkAxis = new Mogre.Vector3();
Degree rfAngle = new Degree();
orient1.ToRotationMatrix().ToAxisAngle(out rkAxis, out rfAngle);
//chat(rfAngle.ValueDegrees.ToString() + " | " + (s.X.rel * RotateScale_PlayerTurn).ToString());//0-180
orient2 = new Quaternion(new Radian(new Degree(rfAngle.ValueDegrees + (-s.X.rel * RotateScale_PlayerTurn))), new Mogre.Vector3(0, 1, 0));
control.Actor.GlobalOrientationQuaternion = orient2;

updateCam();
}

float mouseZ = (float)OgreWindow.g_m.MouseState.Z.rel * .1f;
//chat(mouseZ.ToString());
if (mouseZ > 0)
{
middleMouseState = middleMouseStates.scrollup;
middlemousetimer.reset();
middlemousetimer.start();
}
else if (mouseZ < 0)
{
middleMouseState = middleMouseStates.scrolldown;
middlemousetimer.reset();
middlemousetimer.start();
}

return true;
}

CodeKrash

17-03-2011 04:49:47

I think I'm using camus' answer at http://www.gamedev.net/topic/499004-physx-rotations/

but im not sure

CodeKrash

18-03-2011 19:31:50

I decided to use a shortcut to add or subtract a relative mouse X axis to the quaternion: I wonder if I can use a kind of "temp" SceneNode to accomplish this better?

nodes["drone"].Yaw(-s.X.rel * RotateScale_PlayerTurn);
setOrient(nodes["drone"]._getDerivedOrientation());

CodeKrash

19-03-2011 20:20:03

One important note is that the "degree" is relative, not absolute. I believe the more orthodox way to do this non gimbal locking procedure is:

setOrient(control.Actor.GlobalOrientationQuaternion * ModifyAngleAroundAxis(new Degree(-s.X.rel * RotateScale_PlayerTurn), new Mogre.Vector3(0, 1, 0)));

using:

private Quaternion ModifyAngleAroundAxis(Degree a, Mogre.Vector3 axis)
{
//To determine the quaternion for a rotation of α degrees/radians around an axis defined by a vector (x, y, z):
Quaternion q = new Quaternion();
q.w = (float)System.Math.Cos((double)(0.5 * a.ValueDegrees));
q.x = axis.x * (float)System.Math.Sin((double)(0.5 * a.ValueDegrees));
q.y = axis.y * (float)System.Math.Sin((double)(0.5 * a.ValueDegrees));
q.z = axis.z * (float)System.Math.Sin((double)(0.5 * a.ValueDegrees));
return q;
}