Hi, DrBlort
Thank your for your answer again.
I am using the class of the 3rd party code to give die tracking transform to my unity (finger) objects directly, i am sure about it.
But i am not sure that the function which reads the position and rotation data to my finger objects will prevent that problem in my video…because it also uses EulerAngles function…
In the 3rd party code is the following function of the class to read the data from Motive:
// Unpack RigidBody data
private static void ReadRigidBody(Byte[] b, ref int offset, OptiTrackRigidBody rb)
{
try
{
int[] iData = new int[100];
float[] fData = new float[100];
// RB ID
Buffer.BlockCopy(b, offset, iData, 0, 4); offset += 4;
//int iSkelID = iData[0] >> 16; // hi 16 bits = ID of bone's parent skeleton
//int iBoneID = iData[0] & 0xffff; // lo 16 bits = ID of bone
rb.ID = iData[0]; // already have it from data descriptions
// RB pos
float[] pos = new float[3];
Buffer.BlockCopy(b, offset, pos, 0, 4 * 3); offset += 4 * 3;
rb.position.x = pos[0]; rb.position.y = pos[1]; rb.position.z = pos[2];
// RB ori
float[] ori = new float[4];
Buffer.BlockCopy(b, offset, ori, 0, 4 * 4); offset += 4 * 4;
rb.orientation.x = ori[0]; rb.orientation.y = ori[1]; rb.orientation.z = ori[2]; rb.orientation.w = ori[3];
Buffer.BlockCopy(b, offset, iData, 0, 4); offset += 4;
int nMarkers = iData[0];
Buffer.BlockCopy(b, offset, fData, 0, 4 * 3 * nMarkers); offset += 4 * 3 * nMarkers;
Buffer.BlockCopy(b, offset, iData, 0, 4 * nMarkers); offset += 4 * nMarkers;
Buffer.BlockCopy(b, offset, fData, 0, 4 * nMarkers); offset += 4 * nMarkers;
Buffer.BlockCopy(b, offset, fData, 0, 4); offset += 4;
} catch (Exception e)
{
Debug.LogError(e.ToString());
}
}
And in the following function of another class to get the positions and rotations from that class:
public Vector3 getPosition(int rigidbodyIndex)
{
if(OptitrackManagement.DirectMulticastSocketClient.IsInit())
{
DataStream networkData = OptitrackManagement.DirectMulticastSocketClient.GetDataStream();
Vector3 pos = origin + networkData.getRigidbody(rigidbodyIndex).position * scale;
pos.x = -pos.x; // not really sure if this is the best way to do it
//pos.y = pos.y; // these may change depending on your configuration and calibration
//pos.z = -pos.z;
return pos;
}
else
{
return Vector3.zero;
}
}
public Quaternion getOrientation(int rigidbodyIndex)
{
// should add a way to filter it
if(OptitrackManagement.DirectMulticastSocketClient.IsInit())
{
DataStream networkData = OptitrackManagement.DirectMulticastSocketClient.GetDataStream();
Quaternion rot = networkData.getRigidbody(rigidbodyIndex).orientation;
// change the handedness from motive
//rot = new Quaternion(rot.z, rot.y, rot.x, rot.w); // depending on calibration
// Invert pitch and yaw
Vector3 euler = rot.eulerAngles;
rot.eulerAngles = new Vector3(euler.x, -euler.y, euler.z); // these may change depending on your calibration
return rot;
}
else
{
return Quaternion.identity;
}
}
How should i only use quaternion instead of euler angles ???
Thank you very much.
regards, Carvin