Commit 194922fd authored by ATREVI Dieudonne's avatar ATREVI Dieudonne
Browse files

merge dev branch with #24_real_menu brach

parents 2f698b2f 6bdc9b79
......@@ -82,74 +82,85 @@ public class FollowTrajectory : MonoBehaviour
// Use this for initialization
void Start ()
{
_bIsDone = false;
_IsLaunchable = (_TrajectroryFilename != "");
if(!_IsLaunchable)
{
Debug.LogError("Your CSV file is empty : " + _TrajectroryFilename);
return;
}
CurrentTime = 0.0f;
if(_Myreader == null)
{
_Myreader = new TrajectoryReader();
}
_Myreader.Init(_TrajectroryFilename, _SamplingInput, _SamplingFactor, _MergeClosedPoints, _ClosedPointsMinimumDistance);
_ReaderIndexCount = _Myreader.IndexList.Count;
InitLineRenderer();
InitFilter();
iCurrentInf = 0;
iCurrentSup = 1;
Vector4 iPosition = _Myreader.mSkeleton[0];
fCurrentTime = iPosition[0];
float yVal = 0.0f;
if(float.IsNaN(iPosition[3]))
{
yVal = this.transform.localPosition.y;
_AnimateYAxe = false;
Debug.Log("A non alpha numerique value has been detected in your trajectory file "+_TrajectroryFilename+". ensure x,y and z coordinates are set in the file if you want to animate Y coordinate. by default, the animation on Y axe is disable.");
}
else
{
yVal = (_AnimateYAxe) ? iPosition[3] : this.transform.localPosition.y;
}
this.transform.localPosition = new Vector3(iPosition[1], yVal, iPosition[2]);
_ZeNavMeshAgent = this.GetComponent<UnityEngine.AI.NavMeshAgent>();
if(_ZeNavMeshAgent)
{
_fAngularSpeed = _ZeNavMeshAgent.angularSpeed;
}
else
{
_fAngularSpeed = _DefaultAngularSpeed;
}
// init de la rotation
Vector3 vPosCurrent = new Vector3(0.0f, 0.0f, 1.0f);
Vector3 vPosSup = new Vector3(_Myreader.mSkeleton[1][1], 0.0f, _Myreader.mSkeleton[1][2]) - this.transform.localPosition; // y
if(Vector3.Magnitude(vPosSup) != 0)
{
_fOldAlpha = 57.2957795f*Mathf.Acos(Vector3.Dot(vPosCurrent, vPosSup)/(Vector3.Magnitude(vPosCurrent)*Vector3.Magnitude(vPosSup)));
if(Vector3.Cross(vPosCurrent, vPosSup).y<0)
_fOldAlpha *= -1;
this.transform.rotation = Quaternion.Euler(0, _fOldAlpha/*+this.transform.rotation.eulerAngles.y*/, 0);
}
else
_fOldAlpha = this.transform.rotation.eulerAngles.y;
_SavedParentPosition = Vector3.zero;
_InitialPositionWhenChangingParent = Vector3.zero;
_bIsDone = false;
_IsLaunchable = (_TrajectroryFilename != "" && _TrajectroryFilename != null);
CurrentTime = 0.0f;
iCurrentInf = 0;
iCurrentSup = 1;
}
public void initNewTrajectories()
{
_bIsDone = false;
_IsLaunchable = (_TrajectroryFilename != "" && _TrajectroryFilename != null);
if (!_IsLaunchable)
{
Debug.LogError("Your CSV file is empty : " + _TrajectroryFilename);
return;
}
CurrentTime = 0.0f;
if (_Myreader == null)
{
_Myreader = new TrajectoryReader();
}
_Myreader.Init(_TrajectroryFilename, _SamplingInput, _SamplingFactor, _MergeClosedPoints, _ClosedPointsMinimumDistance);
_ReaderIndexCount = _Myreader.IndexList.Count;
InitLineRenderer();
InitFilter();
iCurrentInf = 0;
iCurrentSup = 1;
Vector4 iPosition = _Myreader.mSkeleton[0];
fCurrentTime = iPosition[0];
float yVal = 0.0f;
if (float.IsNaN(iPosition[3]))
{
yVal = this.transform.localPosition.y;
_AnimateYAxe = false;
Debug.Log("A non alpha numerique value has been detected in your trajectory file " + _TrajectroryFilename + ". ensure x,y and z coordinates are set in the file if you want to animate Y coordinate. by default, the animation on Y axe is disable.");
}
else
{
yVal = (_AnimateYAxe) ? iPosition[3] : this.transform.localPosition.y;
}
this.transform.localPosition = new Vector3(iPosition[1], yVal, iPosition[2]);
_ZeNavMeshAgent = this.GetComponent<UnityEngine.AI.NavMeshAgent>();
if (_ZeNavMeshAgent)
{
_fAngularSpeed = _ZeNavMeshAgent.angularSpeed;
}
else
{
_fAngularSpeed = _DefaultAngularSpeed;
}
// init de la rotation
Vector3 vPosCurrent = new Vector3(0.0f, 0.0f, 1.0f);
Vector3 vPosSup = new Vector3(_Myreader.mSkeleton[1][1], 0.0f, _Myreader.mSkeleton[1][2]) - this.transform.localPosition; // y
if (Vector3.Magnitude(vPosSup) != 0)
{
_fOldAlpha = 57.2957795f * Mathf.Acos(Vector3.Dot(vPosCurrent, vPosSup) / (Vector3.Magnitude(vPosCurrent) * Vector3.Magnitude(vPosSup)));
if (Vector3.Cross(vPosCurrent, vPosSup).y < 0)
_fOldAlpha *= -1;
this.transform.rotation = Quaternion.Euler(0, _fOldAlpha/*+this.transform.rotation.eulerAngles.y*/, 0);
}
else
_fOldAlpha = this.transform.rotation.eulerAngles.y;
_SavedParentPosition = Vector3.zero;
_InitialPositionWhenChangingParent = Vector3.zero;
// init interface
ObjectInterface MyObjInterface = new ObjectInterface();
MyObjInterface.Init(this.gameObject);
RegisterInterface(MyObjInterface);
}
// init interface
ObjectInterface MyObjInterface = new ObjectInterface();
MyObjInterface.Init(this.gameObject);
RegisterInterface(MyObjInterface);
}
public bool IsDone()
{
return _bIsDone;
......@@ -318,7 +329,7 @@ public class FollowTrajectory : MonoBehaviour
// Update is called once per frame
void Update ()
{
if(!_IsLaunchable && _bIsDone)
if(!_IsLaunchable || _bIsDone)
return;
if(_SyncLaunchWithTrajectory && CurrentTime < _Myreader.mSkeleton[0][0] && 0.2 < _Myreader.mSkeleton[0][0])
......@@ -500,6 +511,6 @@ public class FollowTrajectory : MonoBehaviour
public void SetCsvFilename(string csv_filename)
{
_TrajectroryFilename = csv_filename;
this.Start();
initNewTrajectories();
}
}
......@@ -238,7 +238,7 @@ public class LoadEnv : MonoBehaviour
// -------------------
// SET BOUNDING BOXES ITEM
gameObject.AddComponent<GetMemberPositionRocketBox>();
gameObject.AddComponent<FollowTrajectory>();
//gameObject.AddComponent<FollowTrajectory>();
GameObject headBoundingBox = Instantiate(Resources.Load<GameObject>("HeadBoundingBoxes/Hbb_RocketBox"));
Transform Head = gameObject.transform.Find("Bip01/Bip01 Pelvis/Bip01 Spine/Bip01 Spine1/Bip01 Spine2/Bip01 Neck/Bip01 Head");
headBoundingBox.transform.parent = Head;
......
No preview for this file type
No preview for this file type
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