Skip to content

Commit

Permalink
cleaning up comments, rename one variable
Browse files Browse the repository at this point in the history
cleaning up some comments and spelling, changing the following nomenclature:

//for third party camera
agentPositionRelativeThirdPartyCameraRotation -> agentRotationRelativeThirdPartyCameraRotation

//for main camera
agentPositionRelativeCameraRotation -> agentRotationRelativeCameraRotation

as rotation relative to the agent position doesn't mean anything.
  • Loading branch information
winthos committed Sep 10, 2024
1 parent c7c3aff commit ef3bfb2
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 24 deletions.
17 changes: 8 additions & 9 deletions unity/Assets/Scripts/AgentManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1295,7 +1295,7 @@ bool shouldRenderImageSynthesis
Camera camera = thirdPartyCameras.ToArray()[i];
cMetadata.thirdPartyCameraId = i;

//to be depracated at some point, will be replaced by more descriptive worldRelativeThirdPartyCamera....
//to be deprecated at some point, will be replaced by more descriptive worldRelativeThirdPartyCamera....
cMetadata.position = camera.transform.position;
cMetadata.rotation = camera.transform.eulerAngles;
//currently redundant data as it is the same as metadata.position/rotation, but more descriptive naming convention
Expand All @@ -1313,7 +1313,7 @@ bool shouldRenderImageSynthesis
cMetadata.parentPositionRelativeThirdPartyCameraPosition =
camera.transform.parent.InverseTransformPoint(camera.transform.position);

//get third party camera rotation as quaternion in world space
//get third party camera rotation as quaternion in parent space
var parentSpaceCameraRotationAsQuaternion =
Quaternion.Inverse(camera.transform.parent.rotation)
* worldSpaceCameraRotationAsQuaternion;
Expand All @@ -1325,23 +1325,22 @@ bool shouldRenderImageSynthesis
cMetadata.parentPositionRelativeThirdPartyCameraRotation = null;
}

//if this camera is part of the agent's heirarchy at all, get agent relative info
//if this camera is part of the agent's hierarchy at all, get agent relative info
if (camera.GetComponentInParent<BaseAgentComponent>() != null) {
GameObject agent = camera.GetComponentInParent<BaseAgentComponent>().gameObject;

cMetadata.agentPositionRelativeThirdPartyCameraPosition =
agent.transform.InverseTransformPoint(camera.gameObject.transform.position);

//get third party camera rotation as quaternion in world space
var agentSpaceCameraRotationAsQuaternion =
Quaternion.Inverse(agent.transform.rotation)
* worldSpaceCameraRotationAsQuaternion;
cMetadata.agentPositionRelativeThirdPartyCameraRotation =
cMetadata.agentRotationRelativeThirdPartyCameraRotation =
agentSpaceCameraRotationAsQuaternion.eulerAngles;
} else {
//if this third party camera is not a child of the agent, we don't need agent-relative coordinates
cMetadata.agentPositionRelativeThirdPartyCameraPosition = null;
cMetadata.agentPositionRelativeThirdPartyCameraRotation = null;
cMetadata.agentRotationRelativeThirdPartyCameraRotation = null;
}

cMetadata.fieldOfView = camera.fieldOfView;
Expand Down Expand Up @@ -1877,12 +1876,12 @@ public class ThirdPartyCameraMetadata {
//note these should only be returned with values
//if the third party camera is a child of the agent
public Vector3? agentPositionRelativeThirdPartyCameraPosition;
public Vector3? agentPositionRelativeThirdPartyCameraRotation;
public Vector3? agentRotationRelativeThirdPartyCameraRotation;

//return the local space coordinates if this third party camera has a parent object, this may be the same as agentPositionRelative depending on how things are parented
public Vector3? parentPositionRelativeThirdPartyCameraPosition;
public Vector3? parentPositionRelativeThirdPartyCameraRotation;
public string parentObjectName; //if this third party camera is in a heirarchy, return the name of the parent object
public string parentObjectName; //if this third party camera is in a hierarchy, return the name of the parent object
}

[Serializable]
Expand Down Expand Up @@ -2314,7 +2313,7 @@ public struct MetadataWrapper {
public Vector3 worldRelativeCameraPosition;
public Vector3 worldRelativeCameraRotation;
public Vector3 agentPositionRelativeCameraPosition;
public Vector3 agentPositionRelativeCameraRotation;
public Vector3 agentRotationRelativeCameraRotation;
public float cameraOrthSize;
public ThirdPartyCameraMetadata[] thirdPartyCameras;
public bool collided;
Expand Down
8 changes: 4 additions & 4 deletions unity/Assets/Scripts/BaseFPSAgentController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2627,8 +2627,8 @@ public virtual MetadataWrapper generateMetadataWrapper() {
metaMessage.screenWidth = Screen.width;
metaMessage.screenHeight = Screen.height;

metaMessage.cameraPosition = m_Camera.transform.position;
metaMessage.cameraRotation = m_Camera.transform.eulerAngles;
metaMessage.cameraPosition = m_Camera.transform.position; //to be deprecated
metaMessage.cameraRotation = m_Camera.transform.eulerAngles; //to be deprecated
metaMessage.worldRelativeCameraPosition = m_Camera.transform.position;
metaMessage.worldRelativeCameraRotation = m_Camera.transform.eulerAngles;

Expand All @@ -2645,9 +2645,9 @@ public virtual MetadataWrapper generateMetadataWrapper() {
var worldSpaceCameraRotationAsQuaternion = m_Camera.transform.rotation;
var localSpaceCameraRotationAsQuaternion =
Quaternion.Inverse(transform.rotation) * worldSpaceCameraRotationAsQuaternion;
metaMessage.agentPositionRelativeCameraRotation =
metaMessage.agentRotationRelativeCameraRotation =
localSpaceCameraRotationAsQuaternion.eulerAngles;
//Debug.Log($"agentRelativeCameraRotation: {metaMessage.agentPositionRelativeCameraRotation}");
//Debug.Log($"agentRelativeCameraRotation: {metaMessage.agentRotationRelativeCameraRotation}");

metaMessage.cameraOrthSize = cameraOrthSize;
cameraOrthSize = -1f;
Expand Down
22 changes: 11 additions & 11 deletions unity/Assets/UnitTests/TestThirdPartyCameraAndMainCamera.cs
Original file line number Diff line number Diff line change
Expand Up @@ -358,17 +358,17 @@ public IEnumerator TestMainCameraMetadataReturn()
);
Assert.AreEqual(result, true);
result = Mathf.Approximately(
metadata.agentPositionRelativeCameraRotation.x,
metadata.agentRotationRelativeCameraRotation.x,
0.0000000000f
);
Assert.AreEqual(result, true);
result = Mathf.Approximately(
metadata.agentPositionRelativeCameraRotation.y,
metadata.agentRotationRelativeCameraRotation.y,
0.0000000000f
);
Assert.AreEqual(result, true);
result = Mathf.Approximately(
metadata.agentPositionRelativeCameraRotation.z,
metadata.agentRotationRelativeCameraRotation.z,
0.0000000000f
);
Assert.AreEqual(result, true);
Expand Down Expand Up @@ -409,17 +409,17 @@ public IEnumerator TestMainCameraMetadataReturn()
);
Assert.AreEqual(result, true);
result = Mathf.Approximately(
metadata.agentPositionRelativeCameraRotation.x,
metadata.agentRotationRelativeCameraRotation.x,
30.0000000000f
);
Assert.AreEqual(result, true);
result = Mathf.Approximately(
metadata.agentPositionRelativeCameraRotation.y,
metadata.agentRotationRelativeCameraRotation.y,
10.0000000000f
);
Assert.AreEqual(result, true);
result = Mathf.Approximately(
metadata.agentPositionRelativeCameraRotation.z,
metadata.agentRotationRelativeCameraRotation.z,
12.0000000000f
);
Assert.AreEqual(result, true);
Expand Down Expand Up @@ -483,7 +483,7 @@ public IEnumerator TestThirdPartyCameraMetadataReturn()
null
);
Assert.AreEqual(
metadata.thirdPartyCameras[0].agentPositionRelativeThirdPartyCameraRotation,
metadata.thirdPartyCameras[0].agentRotationRelativeThirdPartyCameraRotation,
null
);
Assert.AreEqual(
Expand Down Expand Up @@ -514,7 +514,7 @@ public IEnumerator TestThirdPartyCameraMetadataReturn()
// Debug.Log($"world relative camera rot: {metadata.thirdPartyCameras[0].worldRelativeThirdPartyCameraRotation:F10}");
// //agent relative
// Debug.Log($"agent relative camera pos: {metadata.thirdPartyCameras[0].agentPositionRelativeThirdPartyCameraPosition:F10}");
// Debug.Log($"agent relative camera rot: {metadata.thirdPartyCameras[0].agentPositionRelativeThirdPartyCameraRotation:F10}");
// Debug.Log($"agent relative camera rot: {metadata.thirdPartyCameras[0].agentRotationRelativeThirdPartyCameraRotation:F10}");
// //parent relative
// Debug.Log($"parent relative camera rot: {metadata.thirdPartyCameras[0].parentPositionRelativeThirdPartyCameraPosition:F10}");
// Debug.Log($"parent relative camera rot: {metadata.thirdPartyCameras[0].parentPositionRelativeThirdPartyCameraRotation:F10}");
Expand Down Expand Up @@ -566,17 +566,17 @@ public IEnumerator TestThirdPartyCameraMetadataReturn()
);
Assert.AreEqual(result, true);
result = Mathf.Approximately(
metadata.thirdPartyCameras[0].agentPositionRelativeThirdPartyCameraRotation.Value.x,
metadata.thirdPartyCameras[0].agentRotationRelativeThirdPartyCameraRotation.Value.x,
20.0000000000f
);
Assert.AreEqual(result, true);
result = Mathf.Approximately(
metadata.thirdPartyCameras[0].agentPositionRelativeThirdPartyCameraRotation.Value.y,
metadata.thirdPartyCameras[0].agentRotationRelativeThirdPartyCameraRotation.Value.y,
20.0000000000f
);
Assert.AreEqual(result, true);
result = Mathf.Approximately(
metadata.thirdPartyCameras[0].agentPositionRelativeThirdPartyCameraRotation.Value.z,
metadata.thirdPartyCameras[0].agentRotationRelativeThirdPartyCameraRotation.Value.z,
20.0000000000f
);
Assert.AreEqual(result, true);
Expand Down

0 comments on commit ef3bfb2

Please sign in to comment.