Commit 52dc0aa0 authored by JOVANE Alberto's avatar JOVANE Alberto
Browse files

Reorganization of the camera modes (adding Look at mode) + added the smooth...

Reorganization of the camera modes (adding Look at mode) + added the smooth parameter for first person and torsum view
parent e5c58ed4
......@@ -28,12 +28,28 @@ using System.IO;
public class CamMvt : MonoBehaviour
{
#region camera modes name
public const string DEFAULT = "Default";
public const string FREE_MOVMENT = "Free_Movement";
public const string FOLLOW = "Follow";
public const string LOOK_AT = "Look_At";
public const string FIRST_PERSON = "First_Person";
public const string TORSUM = "Torsum";
#endregion
#region attributes
// Parameters interface
public GameObject panelMovCamera; // panel with the camera parameters on the interface
public Dropdown camSelect; // the downdrop of the camera parameters
[SerializeField()]
// Camera mode
public string current_camera_mode = "empty"; // the current Mode
public Vector3 _default_position;
public Vector3 _default_rotation;
public Vector3 _default_position; // default position defined by the config file
public Vector3 _default_rotation; // default rotation defined by the config file
// Rotation - Looking at an agent
public bool activateLookAt = false; // if true: lock the view to look at the selected agent - else : free movment
......@@ -59,16 +75,21 @@ public class CamMvt : MonoBehaviour
private Transform agent_reference_transform; // transform reference of the head of the torsum followID agent
public bool lockFirstPersonView = false; // if true: lock the view - else (default) : the user can move the view (mouse right click + movment)
public bool smoothFirstPersonView = true; // if true: the movment of the camera is smoothed on the y - else : the camera move with the head or torsum
private float smooth_y_head; // the y value to keep in first person view
private float smooth_y_torsum; // the y value to keep in torsum view
// values holding the updates at run time
private Vector3 _position_follow; // the current follow position
private Vector3 _position_first_person; // the current first person position
private Vector3 _position_torsum; // the current torsum position
public GameObject panelMovCamera;
public Dropdown camSelect;
#endregion
// Use this for initialization
void Start()
{
......@@ -139,13 +160,136 @@ public class CamMvt : MonoBehaviour
}
public void readCameraMovParamOnScene()
{
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);
followOnX = panelMovCamera.transform.Find("FollowX").GetComponent<Toggle>().isOn;
followOnY = panelMovCamera.transform.Find("FollowY").GetComponent<Toggle>().isOn;
lockFirstPersonView = panelMovCamera.transform.Find("LockPerson").GetComponent<Toggle>().isOn;
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);
followOnX = panelMovCamera.transform.Find("FollowX").GetComponent<Toggle>().isOn;
followOnY = panelMovCamera.transform.Find("FollowY").GetComponent<Toggle>().isOn;
lockFirstPersonView = panelMovCamera.transform.Find("LockPerson").GetComponent<Toggle>().isOn;
//smoothFirstPersonView = panelMovCamera.transform.Find("smoothPerson").GetComponent<Toggle>().isOn;
}
//It detects changes in the Current Camera Mode and intialize the parameters accordingly
private void check_mode_changes_and_initialize()
{
if(current_camera_mode != camSelect.options[camSelect.value].text)
{
//PREVIOUS CAMERA deinitialization
if (current_camera_mode == DEFAULT)
{
//
}
else if (current_camera_mode == FREE_MOVMENT)
{
//
}
else if (current_camera_mode == FOLLOW)
{
activateFollow = false;
panelMovCamera.transform.Find("Followat").GetComponent<Toggle>().isOn = false;
}
else if (current_camera_mode == LOOK_AT)
{
activateLookAt = false;
panelMovCamera.transform.Find("Lookat").GetComponent<Toggle>().isOn = false;
}
else if (current_camera_mode == FIRST_PERSON)
{
activateFollow = false;
panelMovCamera.transform.Find("Followat").GetComponent<Toggle>().isOn = false;
}
else if (current_camera_mode == TORSUM)
{
activateFollow = false;
panelMovCamera.transform.Find("Followat").GetComponent<Toggle>().isOn = false;
}
current_camera_mode = camSelect.options[camSelect.value].text;
//NEW CAMERA initialization
if (current_camera_mode == DEFAULT)
{
//
}
else if(current_camera_mode == FREE_MOVMENT)
{
//
}
else if (current_camera_mode == FOLLOW)
{
//activate and set 0 id in case or not predefined id
GameObject[] list = GameObject.FindGameObjectsWithTag("Player");
if (follow_Id < 0 && list.Length > 0)
{
follow_Id = 0;
panelMovCamera.transform.Find("FollowAgentID").GetComponent<InputField>().text = follow_Id.ToString();
}
activateFollow = true;
panelMovCamera.transform.Find("Followat").GetComponent<Toggle>().isOn = true;
//set default rotation
transform.eulerAngles = _default_rotation;
}
else if (current_camera_mode == LOOK_AT)
{
//activate and set 0 id in case or not predefined id
GameObject[] list = GameObject.FindGameObjectsWithTag("Player");
if (lookAt_Id < 0 && list.Length > 0)
{
lookAt_Id = 0;
panelMovCamera.transform.Find("LookAgentID").GetComponent<InputField>().text = lookAt_Id.ToString();
}
activateLookAt = true;
panelMovCamera.transform.Find("Lookat").GetComponent<Toggle>().isOn = true;
//set default position and rotation
transform.eulerAngles = _default_rotation;
transform.position = _default_position;
}
else if (current_camera_mode == FIRST_PERSON)
{
//activate and set 0 id in case or not predefined id
GameObject[] list = GameObject.FindGameObjectsWithTag("Player");
if (follow_Id < 0 && list.Length > 0)
{
follow_Id = 0;
panelMovCamera.transform.Find("FollowAgentID").GetComponent<InputField>().text = follow_Id.ToString();
}
activateFollow = true;
panelMovCamera.transform.Find("Followat").GetComponent<Toggle>().isOn = true;
//set default rotation
update_follow_target();
transform.forward = agent_reference_transform.forward;
//initialize smooth value
smooth_y_head = agent_head_transform.position.y;
}
else if (current_camera_mode == TORSUM)
{
//activate and set 0 id in case or not predefined id
GameObject[] list = GameObject.FindGameObjectsWithTag("Player");
if (follow_Id < 0 && list.Length > 0)
{
follow_Id = 0;
panelMovCamera.transform.Find("FollowAgentID").GetComponent<InputField>().text = follow_Id.ToString();
}
activateFollow = true;
panelMovCamera.transform.Find("Followat").GetComponent<Toggle>().isOn = true;
//set default rotation
update_follow_target();
transform.forward = agent_reference_transform.forward;
//initalize smooth value
smooth_y_torsum = agent_torsum_transform.position.y;
}
}
}
// Update is called once per frame
......@@ -155,9 +299,9 @@ public class CamMvt : MonoBehaviour
// ----------------------------
// UPDATE VALUES
// update follow id
readCameraMovParamOnScene();
check_mode_changes_and_initialize();
if (follow_Id != _previous_follow_Id && activateFollow)
{
update_follow_target();
......@@ -172,32 +316,30 @@ public class CamMvt : MonoBehaviour
#region ROTATION
// ------------------------------
// ROTATION - LOOKING AT AN AGENT
if(camSelect.options[camSelect.value].text == "Default")
if(current_camera_mode == DEFAULT)
{
transform.eulerAngles = _default_rotation;
}
else if (lookAt_Agent != null && activateLookAt)
if(current_camera_mode == LOOK_AT)
{
if (lockFirstPersonView)
{
if (camSelect.options[camSelect.value].text == "First_Person")
{
transform.forward = agent_reference_transform.forward;
}
else if (camSelect.options[camSelect.value].text == "Torsum")
{
transform.forward = agent_reference_transform.forward;
}
}
else if(camSelect.options[camSelect.value].text != "Free_Movement")
if (lookAt_Agent != null && activateLookAt)
transform.LookAt(lookAt_Agent.transform);
}
if (current_camera_mode == FIRST_PERSON)
{
if (lockFirstPersonView)
transform.forward = agent_reference_transform.forward;
}
else if (current_camera_mode == TORSUM)
{
if (lockFirstPersonView)
transform.forward = agent_reference_transform.forward;
}
#endregion
#region TRANSLATION
if (camSelect.options[camSelect.value].text == "Default")
if (current_camera_mode == DEFAULT)
{
transform.position = _default_position;
}
......@@ -205,14 +347,12 @@ public class CamMvt : MonoBehaviour
{
Vector3 delta = follow_Agent.transform.position - follow_LastPosition;
follow_LastPosition = follow_Agent.transform.position;
if (!followOnX){
delta.x = 0;
}
if (!followOnY){
delta.z = 0;
}
_position_follow = _position_follow + delta;
_position_first_person = agent_head_transform.position;
......@@ -222,17 +362,23 @@ public class CamMvt : MonoBehaviour
// --------------------------------
// TRANSLATION - FOLLOWING AN AGENT
if (camSelect.options[camSelect.value].text == "Follow")
if (current_camera_mode == FOLLOW)
{
transform.position = _position_follow;
}
else if (camSelect.options[camSelect.value].text == "First_Person")
else if (current_camera_mode == FIRST_PERSON)
{
transform.position = _position_first_person;
if (smoothFirstPersonView)
transform.position = new Vector3(_position_first_person.x, smooth_y_head, _position_first_person.z);
else
transform.position = _position_first_person;
}
else if (camSelect.options[camSelect.value].text == "Torsum")
else if (current_camera_mode == TORSUM)
{
transform.position = _position_torsum;
if (smoothFirstPersonView)
transform.position = new Vector3(_position_torsum.x, smooth_y_torsum, _position_torsum.z);
else
transform.position = _position_torsum;
}
}
#endregion
......
......@@ -8,7 +8,7 @@
<rotation x="0" y="0" z="0" />
</env_stageInfos>
<cam>
<cameraType typeID="1" />
<cameraType typeID="2" />
<position x="-26.90744" y="-2.035934" z="4.73512" />
<rotation x="31.03411" y="-1.992795E-06" z="85.52567" />
<lookAtAgent agentID="-1" />
......
......@@ -8,7 +8,7 @@
<rotation x="0" y="0" z="0" />
</env_stageInfos>
<cam>
<cameraType typeID="4" />
<cameraType typeID="2" />
<position x="-28" y="-3" z="5" />
<rotation x="30.00002" y="0" z="90" />
<lookAtAgent agentID="-1" />
......
......@@ -8,7 +8,7 @@
<rotation x="0" y="0" z="90" />
</env_stageInfos>
<cam>
<cameraType typeID="4" />
<cameraType typeID="3" />
<position x="15" y="2" z="5" />
<rotation x="12.94866" y="4.380253E-07" z="115.3439" />
<lookAtAgent agentID="22" />
......
......@@ -8,7 +8,7 @@
<rotation x="0" y="0" z="0" />
</env_stageInfos>
<cam>
<cameraType typeID="4" />
<cameraType typeID="0" />
<position x="0" y="0" z="30" />
<rotation x="90" y="0" z="0" />
<lookAtAgent agentID="-1" />
......
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