- Home /
PS3 Move.Me : angularVelocity to local space
Hello guys,
I'm working with the PS3 Move.Me package for Unity3D developed by Xun Zhang and having some trouble wrapping my head around converting the angularVelocity - which is relative to the world space - into an angularVelocity relative to the local space.
What I have so far is this:
public Camera cam;
private float camDecelRate = 0.12f;
private Vector3 camRotateVelocity = new Vector3();
void FixedUpdate ()
{
//---pan the camera if the trigger is being pressed---
//trigger is pressed (equilelant to isButton)
if (psMoveWrapper.valueT[0] >= psMoveWrapper.thresholdT)
{
float xPan = psMoveWrapper.angularVelocity[0].x;
float yPan = psMoveWrapper.angularVelocity[0].y;
cam.transform.Rotate(new Vector3(xPan, yPan, 0) * Time.fixedDeltaTime);
}
//trigger just released
if (psMoveWrapper.WasReleased(0, PSMoveWrapper.T))
{
float xPan = psMoveWrapper.angularVelocity[0].x;
float yPan = psMoveWrapper.angularVelocity[0].y;
camRotateVelocity = new Vector3(xPan, yPan, 0) * Time.fixedDeltaTime;
}
//trigger not pressed AND still decelerating
if (psMoveWrapper.valueT[0] < psMoveWrapper.thresholdT &&
camRotateVelocity != Vector3.zero)
{
Vector3 velocity = Vector3.zero;
camRotateVelocity = Vector3.SmoothDamp(camRotateVelocity, Vector3.zero, ref velocity, camDecelRate);
cam.transform.Rotate(camRotateVelocity);
}
}
Basically, the plan is that the camera will never move, but can be panned around by depressing the trigger and swiping the PS3 controller in a direction (similar to touch screens).
The trouble is (again) that the angularVelocity for the wand is relative to the world space, but I need it relative to the local space. Also, the wand orientation (what I think I would use to translate the angularVelocity to local space) is in world space.
I know this is referencing an external package that people may not be familiar with at all, but any insight would be greatly appreciated :)
EDIT: I've just noticed this question and I'm not sure if there is such a thing as "local angular velocity", but basically what I need is for the same result to happen in both of these cases:
I am facing the PS3 Eye with the controller pointing forward ([0, 0, 0] rotation) and swipe downward ([-x, 0, 0] angularVelocity) to rotate the camera upward (which functions right now)
I am facing to the left of my previous orientation (with the PS3 Eye 90 deg. to my right) with the controller pointing straight ahead of me ([0, +90, 0] rotation) and swipe downward ([0, 0, +z] angularVelocity) to rotate the camera upward (which doesn't function right now obviously because when I turn, the swipe affects the z axis)