In controller script that control the camera I trying to apply a changes from the PoseClient script that calculate the data of change position and rotation
ControllerScript.cs
void Update()
{
Camera cam = GetComponent<Camera>();
cam.transform.localPosition = PoseClient.getPosition();
cam.transform.localEulerAngles= PoseClient.getRotation();
cam.ResetStereoViewMatrices();
cam.SetStereoViewMatrix(Camera.StereoscopicEye.Left, cam.worldToCameraMatrix);
cam.SetStereoViewMatrix(Camera.StereoscopicEye.Right, cam.worldToCameraMatrix);
}
PoseClient.cs
public Vector3 getPosition()
{
Vector3 pos;
pos.x = -(float)curr_pose.t_y;
pos.y = (float)curr_pose.t_z;
pos.z = (float)curr_pose.t_x;
return pos;
}
public Quaternion getRotation()
{
Quaternion rotation;
rotation.x = -curr_pose.q_y;
rotation.y = curr_pose.q_z;
rotation.z = -curr_pose.q_x;
rotation.w = curr_pose.q_w;
Vector3 eul_rotation;
eul_rotation.x = -rotation.eulerAngles.x;
eul_rotation.y = -rotation.eulerAngles.y;
eul_rotation.z = rotation.eulerAngles.z;
Quaternion adjusted_rotation = Quaternion.Euler(eul_rotation);
return adjusted_rotation;
}
I tried different options to link them but it don’t work, please help
Raelyr
August 5, 2017, 12:23am
2
I’m not positive I understand what you’re asking, but it looks like you might need to GetComponent for the getPosition script in the controller one, since you’re trying to reference it there?
I don’t know how to make reference to getPosition, to receive data from it
I tried
cam.transform.localPosition = new Vector 3(VRVUPoseClient.getPosition);
and a option that directly trying to get data from getPosition
cam.transform.localPosition = PoseClient.getPosition();
Raelyr
August 5, 2017, 12:36am
4
The same way you did with the camera!
posecli = GetComponent<PoseClient> ();
Add that line near where you did the same with the camera in the ControllerScript
But it’s making no sense I see the PoseClient script but I don’t know the form that I can link to the cam.transform.localPosition
By this reference Unity - Scripting API: Transform.localPosition
it says that transform.localPosition = new Vector3 (0, 0, 0);
So it setting to Vector3 with 3 values
that way I tried to get my
cam.transform.localPosition = new Vector 3(VRVUPoseClient.getPosition);
but getting error that says that Vector3 does not taking constructor that takes 1 argument
P.S. output of getPosition function if you look in it is return value of Vector3 pos;
Ok, so I just delete ControllerScript.cs
and paste in PoseClient.cs in new class and that works fine
public void setNewData()
{
Camera cam = GetComponent<Camera>();
cam.SetStereoViewMatrix(Camera.StereoscopicEye.Left, cam.worldToCameraMatrix);
cam.SetStereoViewMatrix(Camera.StereoscopicEye.Right, cam.worldToCameraMatrix);
cam.transform.localPosition = getPosition();
cam.transform.localRotation = getRotation();
}