Commit cb8133bd authored by ATREVI Dieudonne's avatar ATREVI Dieudonne
Browse files

Merge branch 'dev_cameras' of https://gitlab.inria.fr/OCSR/chaos into #24_real_menu

- Add Camera movement parameters on the scene to allow user to play with
- Add supplementary camera parameters on the config parameters modification panel
parents f130b46a e5ab93b6
This diff is collapsed.
......@@ -85,13 +85,16 @@ public class LoadEnv : MonoBehaviour
// CAMERA CONFIG
cam_Rec.enabled = true;
cam_Movement.enabled = true;
cam_Movement._camera_type = (CamMvt.CameraType)ConfigReader.camType;
cam.transform.position = ConfigReader.camPosition;
cam.transform.rotation = Quaternion.Euler(ConfigReader.camRotation);
cam_Movement.lookAt_Id = ConfigReader.camLookAtTarget;
cam_Movement.follow_Id = ConfigReader.camFollowTarget;
cam_Movement.activateLookAt = ConfigReader.lookAtAgent;
cam_Movement.activateFollow = ConfigReader.followAgent;
cam_Movement.follow_LockX = !ConfigReader.camFollowOnX;
cam_Movement.follow_LockZ = !ConfigReader.camFollowOnY;
cam_Movement.lockFirstPersonView = ConfigReader.camLockFirstPerson;
// -------------
// RECORD CONFIG
......@@ -424,9 +427,12 @@ public class LoadEnv : MonoBehaviour
cam.transform.rotation = Quaternion.Euler(ConfigReader.camRotation);
cam_Movement.lookAt_Id = ConfigReader.camLookAtTarget;
cam_Movement.follow_Id = ConfigReader.camFollowTarget;
cam_Movement.activateLookAt = ConfigReader.lookAtAgent;
cam_Movement.activateFollow = ConfigReader.followAgent;
cam_Movement.follow_LockX = !ConfigReader.camFollowOnX;
cam_Movement.follow_LockZ = !ConfigReader.camFollowOnY;
cam_Movement.lockFirstPersonView = ConfigReader.camLockFirstPerson;
// -------------
// RECORD CONFIG
cam_Rec.record = ConfigReader.recording;
......
......@@ -219,13 +219,46 @@ public class MenuManager : MonoBehaviour
topMenuPanel.SetActive(true);
// Show the camera movement parameters on the scene to allow user to play with during the animation
cameraMovPanel.SetActive(true);
cameraMovPanel.transform.Find("cameraType").GetComponent<Dropdown>().value = ConfigReader.camType;
cameraMovPanel.transform.Find("Lookat").GetComponent<Toggle>().isOn = ConfigReader.lookAtAgent;
cameraMovPanel.transform.Find("LookAgentID").GetComponent<InputField>().text = ConfigReader.camLookAtTarget.ToString();
cameraMovPanel.transform.Find("Followat").GetComponent<Toggle>().isOn = ConfigReader.followAgent;
cameraMovPanel.transform.Find("FollowAgentID").GetComponent<InputField>().text = ConfigReader.camFollowTarget.ToString();
cameraMovPanel.transform.Find("FollowX").GetComponent<Toggle>().isOn = ConfigReader.camFollowOnX;
cameraMovPanel.transform.Find("FollowY").GetComponent<Toggle>().isOn = ConfigReader.camFollowOnY;
cameraMovPanel.transform.Find("LockPerson").GetComponent<Toggle>().isOn = ConfigReader.camLockFirstPerson;
checkLookatToggleOnScene();
//slider.SetActive(true);
GameObject.Find("/controlCanvas/fakePanel/topMenu").SetActive(false);
}
public void checkLookatToggleOnScene(){
GameObject PanelMovCamera = GameObject.Find("/controlCanvas/cameraMovPanel");
GameObject LookAgentIDtxt = GameObject.Find("/controlCanvas/cameraMovPanel/LookAgentIDtxt");
GameObject LookAgentID = GameObject.Find("/controlCanvas/cameraMovPanel/LookAgentID");
LookAgentIDtxt.SetActive(PanelMovCamera.transform.Find("Lookat").GetComponent<Toggle>().isOn);
LookAgentID.SetActive(PanelMovCamera.transform.Find("Lookat").GetComponent<Toggle>().isOn);
GameObject FollowAgentIDtxt = GameObject.Find("/controlCanvas/cameraMovPanel/FollowAgentIDtxt");
GameObject FollowAgentID = GameObject.Find("/controlCanvas/cameraMovPanel/FollowAgentID");
FollowAgentIDtxt.SetActive(PanelMovCamera.transform.Find("Followat").GetComponent<Toggle>().isOn);
FollowAgentID.SetActive(PanelMovCamera.transform.Find("Followat").GetComponent<Toggle>().isOn);
if(!PanelMovCamera.transform.Find("Followat").GetComponent<Toggle>().isOn){
PanelMovCamera.transform.Find("FollowX").GetComponent<Toggle>().interactable = false;
PanelMovCamera.transform.Find("FollowY").GetComponent<Toggle>().interactable = false;
PanelMovCamera.transform.Find("LockPerson").GetComponent<Toggle>().interactable = false;
}
else{
PanelMovCamera.transform.Find("FollowX").GetComponent<Toggle>().interactable = true;
PanelMovCamera.transform.Find("FollowY").GetComponent<Toggle>().interactable = true;
PanelMovCamera.transform.Find("LockPerson").GetComponent<Toggle>().interactable = true;
}
}
/// <summary>
/// show/hide menu
/// </summary>
......
......@@ -29,21 +29,13 @@ using System.IO;
public class CamMvt : MonoBehaviour
{
#region attributes
// different camera types
public enum CameraType
{
Default, //the option defined by the scenario
Follow, // follow the agent if defined by the scenario
First_Person, // First Person View
Torsum, // Torsum view
Free_Movement // Free Movement
}
[SerializeField()]
public CameraType _camera_type;
// Rotation - Looking at an agent
public bool activateLookAt = false; // if true: lock the view to look at the selected agent - else : free movment
public bool activateFollow = false; // if true: follow the selected agent
private int _previous_lookAt_Id; // Id of the previous agent to look at
public int lookAt_Id; // Id of the agent to look at
private GameObject lookAt_Agent = null; // Agent to look at
......@@ -70,13 +62,15 @@ public class CamMvt : MonoBehaviour
private Vector3 _position_first_person; // the current first person position
private Vector3 _position_torsum; // the current torsum position
private GameObject camTypePanel;
public GameObject panelMovCamera;
public Dropdown camSelect;
#endregion
// Use this for initialization
void Start()
{
//lockFirstPersonView = false;
panelMovCamera = GameObject.Find("/controlCanvas/cameraMovPanel");
camSelect = panelMovCamera.transform.Find("cameraType").GetComponent<Dropdown>();
}
/// <summary>
......@@ -84,21 +78,6 @@ public class CamMvt : MonoBehaviour
/// </summary>
public void initializeTargetObjects()
{
activateLookAt = ConfigReader.lookAtAgent;
lookAt_Id = ConfigReader.camLookAtTarget;
//follow_Agent = ConfigReader.followAgent;
follow_Id = ConfigReader.camFollowTarget;
if (!activateLookAt)
lookAt_Id = 0;
// initialize camera type
if (_camera_type == CameraType.Follow || _camera_type == CameraType.First_Person || _camera_type == CameraType.Torsum)
{
if (follow_Id < 0)
follow_Id = 0;
}
// initialize the look at and follow target
update_look_at_target();
update_follow_target();
......@@ -112,7 +91,7 @@ public class CamMvt : MonoBehaviour
public void update_look_at_target()
{
GameObject[] list = GameObject.FindGameObjectsWithTag("Player");
if (activateLookAt && lookAt_Id >= 0)
if (activateLookAt && lookAt_Id >= 0 && list.Length > 0)
{
if (lookAt_Id > list.Length - 1)
lookAt_Id = list.Length - 1;
......@@ -124,8 +103,6 @@ public class CamMvt : MonoBehaviour
lookAt_Id = -1;
_previous_lookAt_Id = lookAt_Id;
}
}
/// <summary>
/// Update the target of the follow camera and of the first_person/torsum camera
......@@ -133,7 +110,7 @@ public class CamMvt : MonoBehaviour
public void update_follow_target()
{
GameObject[] list = GameObject.FindGameObjectsWithTag("Player");
if (follow_Id >= 0 && list.Length > 0)
if (activateFollow && follow_Id >= 0 && list.Length > 0)
{
if (follow_Id > list.Length - 1)
follow_Id = list.Length - 1;
......@@ -152,8 +129,18 @@ public class CamMvt : MonoBehaviour
}
}
public void readCameraMovParamOnScene()
{
//GameObject PanelMovCamera = GameObject.Find("/controlCanvas/cameraMovPanel");
activateLookAt = panelMovCamera.transform.Find("Lookat").GetComponent<Toggle>().isOn;
activateFollow = panelMovCamera.transform.Find("Followat").GetComponent<Toggle>().isOn;
lookAt_Id = int.Parse(panelMovCamera.transform.Find("LookAgentID").GetComponent<InputField>().text);
follow_Id = int.Parse(panelMovCamera.transform.Find("FollowAgentID").GetComponent<InputField>().text);
follow_LockX = panelMovCamera.transform.Find("FollowX").GetComponent<Toggle>().isOn;
follow_LockZ = panelMovCamera.transform.Find("FollowY").GetComponent<Toggle>().isOn;
lockFirstPersonView = panelMovCamera.transform.Find("LockPerson").GetComponent<Toggle>().isOn;
}
// Update is called once per frame
void Update()
{
......@@ -161,7 +148,8 @@ public class CamMvt : MonoBehaviour
// ----------------------------
// UPDATE VALUES
// update follow id
if (follow_Id != _previous_follow_Id)
readCameraMovParamOnScene();
if (follow_Id != _previous_follow_Id && activateFollow)
{
update_follow_target();
}
......@@ -175,23 +163,13 @@ public class CamMvt : MonoBehaviour
#region ROTATION
// ------------------------------
// ROTATION - LOOKING AT AN AGENT
camTypePanel = GameObject.Find("/controlCanvas/cameraMovPanel");
Dropdown camSelect = camTypePanel.transform.Find("cameraType").GetComponent<Dropdown>();
if (lookAt_Agent != null && activateLookAt)
{
transform.LookAt(lookAt_Agent.transform);
}
if (lockFirstPersonView)
{
/*if (_camera_type == CameraType.First_Person)
{
transform.forward = agent_reference_transform.forward;
}
else if (_camera_type == CameraType.Torsum)
{
transform.forward = agent_reference_transform.forward;
}*/
if (camSelect.options[camSelect.value].text == "First_Person")
{
transform.forward = agent_reference_transform.forward;
......@@ -222,18 +200,6 @@ public class CamMvt : MonoBehaviour
// --------------------------------
// TRANSLATION - FOLLOWING AN AGENT
/*if (_camera_type == CameraType.Follow || _camera_type == CameraType.Default )
{
transform.position = _position_follow;
}
else if (_camera_type == CameraType.First_Person )
{
transform.position = _position_first_person;
}
else if (_camera_type == CameraType.Torsum )
{
transform.position = _position_torsum;
}*/
if (camSelect.options[camSelect.value].text == "Default" || camSelect.options[camSelect.value].text == "Follow")
{
transform.position = _position_follow;
......@@ -250,7 +216,6 @@ public class CamMvt : MonoBehaviour
#endregion
}
#region Additional Functions
//additional functions
......@@ -330,7 +295,7 @@ public class CamMvt : MonoBehaviour
}
}
//CAMERA TYPE parser
/*//CAMERA TYPE parser
/// <summary>
/// Get the camera Type from the string
/// </summary>
......@@ -392,6 +357,6 @@ public class CamMvt : MonoBehaviour
returned_camera_type = "Default";
}
return returned_camera_type;
}
}*/
#endregion
}
\ No newline at end of file
......@@ -37,6 +37,7 @@ public class ConfigManager : MonoBehaviour
{
// GameObject to store differents panel in the canvas
public static GameObject PanelCamera, PanelRecording, PanelTimeSetting, PanelStageEnv;
public static InputField LookAgent, FollowAgent;
/// <summary>
......@@ -60,11 +61,14 @@ public class ConfigManager : MonoBehaviour
// Look At Agent
PanelCamera.transform.Find("LookAgentID").GetComponent<InputField>().text = ConfigReader.camLookAtTarget.ToString();
PanelCamera.transform.Find("Lookat").GetComponent<Toggle>().isOn = ConfigReader.lookAtAgent;
// Follow Agent
PanelCamera.transform.Find("Followat").GetComponent<Toggle>().isOn = ConfigReader.followAgent;
PanelCamera.transform.Find("FollowAgentID").GetComponent<InputField>().text = ConfigReader.camFollowTarget.ToString();
PanelCamera.transform.Find("FollowX").GetComponent<Toggle>().isOn = ConfigReader.camFollowOnX;
PanelCamera.transform.Find("FollowY").GetComponent<Toggle>().isOn = ConfigReader.camFollowOnY;
PanelCamera.transform.Find("LockPerson").GetComponent<Toggle>().isOn = ConfigReader.camLockFirstPerson;
/// Get Recording parameters
// Duration
......@@ -125,13 +129,22 @@ public class ConfigManager : MonoBehaviour
ConfigReader.camRotation = camRot;
// Look At Agent
ConfigReader.camLookAtTarget = int.Parse(PanelCamera.transform.Find("LookAgentID").GetComponent<InputField>().text);
if(PanelCamera.transform.Find("Lookat").GetComponent<Toggle>().isOn)
{
ConfigReader.camLookAtTarget = int.Parse(PanelCamera.transform.Find("LookAgentID").GetComponent<InputField>().text);
}
// Follow Agent
ConfigReader.camFollowTarget = int.Parse(PanelCamera.transform.Find("FollowAgentID").GetComponent<InputField>().text);
ConfigReader.camFollowOnX = PanelCamera.transform.Find("FollowX").GetComponent<Toggle>().isOn;
ConfigReader.camFollowOnY = PanelCamera.transform.Find("FollowY").GetComponent<Toggle>().isOn;
if(PanelCamera.transform.Find("Followat").GetComponent<Toggle>().isOn){
ConfigReader.camFollowTarget = int.Parse(PanelCamera.transform.Find("FollowAgentID").GetComponent<InputField>().text);
ConfigReader.camFollowOnX = PanelCamera.transform.Find("FollowX").GetComponent<Toggle>().isOn;
ConfigReader.camFollowOnY = PanelCamera.transform.Find("FollowY").GetComponent<Toggle>().isOn;
ConfigReader.camLockFirstPerson = PanelCamera.transform.Find("LockPerson").GetComponent<Toggle>().isOn;
}
else{
ConfigReader.camFollowTarget = -1;
}
//// Set Recording parameters
// Duration
PanelRecording = GameObject.Find("/ConfigMenu/Panel/PanelRecording/Button/Panel");
......@@ -282,4 +295,88 @@ public class ConfigManager : MonoBehaviour
PanelTimeSetting.SetActive(PanelRecording.transform.Find("recordVal").GetComponent<Toggle>().isOn);
}
/// <summary>
/// Method to check if the lookAt and FollowAt toggle are on or off and display the suitable parameters accordingly.
/// </summary>
public void checkLookatToggle(){
PanelCamera = GameObject.Find("/ConfigMenu/Panel/PanelCamera/Button/Panel");
GameObject LookAgentIDtxt = GameObject.Find("/ConfigMenu/Panel/PanelCamera/Button/Panel/LookAgentIDtxt");
GameObject LookAgentID = GameObject.Find("/ConfigMenu/Panel/PanelCamera/Button/Panel/LookAgentID");
LookAgentIDtxt.SetActive(PanelCamera.transform.Find("Lookat").GetComponent<Toggle>().isOn);
LookAgentID.SetActive(PanelCamera.transform.Find("Lookat").GetComponent<Toggle>().isOn);
GameObject FollowAgentIDtxt = GameObject.Find("/ConfigMenu/Panel/PanelCamera/Button/Panel/FollowAgentIDtxt");
GameObject FollowAgentID = GameObject.Find("/ConfigMenu/Panel/PanelCamera/Button/Panel/FollowAgentID");
FollowAgentIDtxt.SetActive(PanelCamera.transform.Find("Followat").GetComponent<Toggle>().isOn);
FollowAgentID.SetActive(PanelCamera.transform.Find("Followat").GetComponent<Toggle>().isOn);
if(!PanelCamera.transform.Find("Followat").GetComponent<Toggle>().isOn){
PanelCamera.transform.Find("FollowX").GetComponent<Toggle>().interactable = false;
PanelCamera.transform.Find("FollowY").GetComponent<Toggle>().interactable = false;
PanelCamera.transform.Find("LockPerson").GetComponent<Toggle>().interactable = false;
}
else{
PanelCamera.transform.Find("FollowX").GetComponent<Toggle>().interactable = true;
PanelCamera.transform.Find("FollowY").GetComponent<Toggle>().interactable = true;
PanelCamera.transform.Find("LockPerson").GetComponent<Toggle>().interactable = true;
}
}
public void checkFollowXToggle(){
PanelCamera = GameObject.Find("/ConfigMenu/Panel/PanelCamera/Button/Panel");
if(PanelCamera.transform.Find("Followat").GetComponent<Toggle>().isOn){
PanelCamera.transform.Find("FollowY").GetComponent<Toggle>().isOn = !PanelCamera.transform.Find("FollowX").GetComponent<Toggle>().isOn;
}
}
public void checkFollowYToggle(){
PanelCamera = GameObject.Find("/ConfigMenu/Panel/PanelCamera/Button/Panel");
if(PanelCamera.transform.Find("Followat").GetComponent<Toggle>().isOn){
PanelCamera.transform.Find("FollowX").GetComponent<Toggle>().isOn = !PanelCamera.transform.Find("FollowY").GetComponent<Toggle>().isOn;
}
}
public void checkLookatToggleOnScene(){
GameObject PanelMovCamera = GameObject.Find("/controlCanvas/cameraMovPanel");
GameObject LookAgentIDtxt = GameObject.Find("/controlCanvas/cameraMovPanel/LookAgentIDtxt");
GameObject LookAgentID = GameObject.Find("/controlCanvas/cameraMovPanel/LookAgentID");
LookAgentIDtxt.SetActive(PanelMovCamera.transform.Find("Lookat").GetComponent<Toggle>().isOn);
LookAgentID.SetActive(PanelMovCamera.transform.Find("Lookat").GetComponent<Toggle>().isOn);
GameObject FollowAgentIDtxt = GameObject.Find("/controlCanvas/cameraMovPanel/FollowAgentIDtxt");
GameObject FollowAgentID = GameObject.Find("/controlCanvas/cameraMovPanel/FollowAgentID");
FollowAgentIDtxt.SetActive(PanelMovCamera.transform.Find("Followat").GetComponent<Toggle>().isOn);
FollowAgentID.SetActive(PanelMovCamera.transform.Find("Followat").GetComponent<Toggle>().isOn);
if(!PanelMovCamera.transform.Find("Followat").GetComponent<Toggle>().isOn){
PanelMovCamera.transform.Find("FollowX").GetComponent<Toggle>().interactable = false;
PanelMovCamera.transform.Find("FollowY").GetComponent<Toggle>().interactable = false;
PanelMovCamera.transform.Find("LockPerson").GetComponent<Toggle>().interactable = false;
}
else{
PanelMovCamera.transform.Find("FollowX").GetComponent<Toggle>().interactable = true;
PanelMovCamera.transform.Find("FollowY").GetComponent<Toggle>().interactable = true;
PanelMovCamera.transform.Find("LockPerson").GetComponent<Toggle>().interactable = true;
}
}
public void checkFollowXToggleOnScene(){
GameObject PanelMovCamera = GameObject.Find("/controlCanvas/cameraMovPanel");
if(PanelMovCamera.transform.Find("Followat").GetComponent<Toggle>().isOn){
PanelMovCamera.transform.Find("FollowY").GetComponent<Toggle>().isOn = !PanelMovCamera.transform.Find("FollowX").GetComponent<Toggle>().isOn;
}
}
public void checkFollowYToggleOnScene(){
GameObject PanelMovCamera = GameObject.Find("/controlCanvas/cameraMovPanel");
if(PanelMovCamera.transform.Find("Followat").GetComponent<Toggle>().isOn){
PanelMovCamera.transform.Find("FollowX").GetComponent<Toggle>().isOn = !PanelMovCamera.transform.Find("FollowY").GetComponent<Toggle>().isOn;
}
}
}
\ No newline at end of file
......@@ -195,6 +195,14 @@ public static class ConfigReader
set { data.cam.followAgent.followY = value;}
}
/// <summary>
/// Boolean, true if camera first person or torsum is stuck with the agent direction or free to move
/// </summary>
static public bool camLockFirstPerson
{
get { return data.cam.followAgent == null ? false : data.cam.followAgent.lockFirstPerson; }
set { data.cam.followAgent.lockFirstPerson = value; }
}
/// <summary>
/// Boolean, true if the animation should be recorded
/// </summary>
static public bool recording
......@@ -512,12 +520,15 @@ public class ConfigCamBehaviour2
public bool followX;
[XmlAttribute("followOnY")]
public bool followY;
[XmlAttribute("lockFirstPerson")]
public bool lockFirstPerson;
public ConfigCamBehaviour2()
{
id = -1;
followX = false;
followY = false;
lockFirstPerson = false;
}
}
......
......@@ -8,11 +8,11 @@
<rotation x="0" y="0" z="0" />
</env_stageInfos>
<cam>
<cameraType typeID="2"/>
<cameraType typeID="2" />
<position x="-30" y="-3" z="5" />
<rotation x="30.32365" y="0" z="92.53606" />
<rotation x="30" y="0" z="90.03349" />
<lookAtAgent agentID="-1" />
<followAgent agentID="0" followOnX="true" followOnY="false" />
<followAgent agentID="0" followOnX="true" followOnY="false" lockFirstPerson="false" />
<CamResolution x="-1" y="-1" />
</cam>
<recording start="0" end="0" framerate="15" width="320" height="240">
......@@ -27,4 +27,4 @@
<saveDir>./Output/</saveDir>
</recording>
<AgentColorList />
</ConfigData>
</ConfigData>
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment