Skip to content

Commit

Permalink
Trajectory - design and follow
Browse files Browse the repository at this point in the history
Need some Refinement but the idea is there (must be ready for 17/12)
  • Loading branch information
matthieupoyade committed Dec 14, 2015
1 parent ef6a93b commit 17da78e
Show file tree
Hide file tree
Showing 20 changed files with 430 additions and 46 deletions.
Binary file not shown.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file not shown.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ public void SelectSoundObj(GameObject myPanel)
//Debug.Log("Selected Sound Object: " + DraggedObj.name);

//Deactivate Collider
DraggedObj.GetComponent<Collider>().enabled = false;
//DraggedObj.GetComponent<Collider>().enabled = false;
}
}

Expand All @@ -309,7 +309,7 @@ public void ReleaseSoundObj(GameObject myPanel)
if (DraggedObj)
{
//Reset collider
DraggedObj.GetComponent<Collider>().enabled = true;
//DraggedObj.GetComponent<Collider>().enabled = true;

//Reset Dragged Obj
DraggedObj = null;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using UnityEngine;
using System.Collections;

public class ListOfVertices
{
public int Id;
public Vector3 pos;

public ListOfVertices(int newId, Vector3 newPos)
{
Id = newId;
pos = newPos;
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,15 @@ public class PathCreator : MonoBehaviour {

public Mesh DefaultMesh;

private List<TrajectoryVerticesList> myPtList;
private List<TrajectoryPtList> myPtList;
private List<TrajectoryVerticesList> myVtList;
private LineRenderer lineRenderer;

private int traj_Acc_ratio = 2;

private SphereCollider[] mySCArray;

private int PathId = 0;

// Use this for initialization
void OnEnable ()
Expand All @@ -27,10 +30,13 @@ void OnEnable ()
myKinectManagerScript = GameObject.Find("SceneObjects").GetComponent<myKinectManager>();

//Init new list of point for the new trajectory
myPtList = new List<TrajectoryVerticesList>();
myPtList = new List<TrajectoryPtList>();

//Init new list of Vertices for the new trajectory
myVtList = new List<TrajectoryVerticesList>();

//Create a main path Object
myPath = new GameObject("path");
myPath = new GameObject("path_"+PathId);
//Debug.Log("New Path Object Created");

myPath.transform.parent = transform;
Expand All @@ -39,14 +45,30 @@ void OnEnable ()
//Create a line Renderer for each object
lineRenderer = myPath.AddComponent<LineRenderer>();
lineRenderer.SetWidth(0.075f, 0.075f);

/********************************************************************************/
//We aim to obtain a colour Controlled i saturation and light
/********************************************************************************/
Color trajectorycolor = new Color(Random.Range(0.0f, 1.0f), Random.Range(0.0f, 1.0f), Random.Range(0.0f, 1.0f), 1);

float hue;
float sat;
float val;
float highlight = 1.0f;

mySceneManagerScript.RGBToHSV(trajectorycolor, out hue, out sat, out val);
trajectorycolor = mySceneManagerScript.HSVToRGB(hue, Random.Range(0.5f, 1.0f), Random.Range(0.8f, 1.0f));
/********************************************************************************/

lineRenderer.SetColors(trajectorycolor, trajectorycolor);
lineRenderer.material = new Material(Shader.Find("Standard"));
lineRenderer.material.color = trajectorycolor;

id = 0;
mySimpleId = 0;

PathId++;

}

// Update is called once per frame
Expand All @@ -61,14 +83,29 @@ void Update ()
//Set the position of the node
myPathNode.transform.position = myKinectManagerScript.RightHandObj.transform.position;*/

//Store the node object into the list
myPtList.Add(new TrajectoryVerticesList(myKinectManagerScript.RightHandObj.transform.position));
//Store the node object into the list - Needed for the line rendering
myPtList.Add(new TrajectoryPtList(myKinectManagerScript.RightHandObj.transform.position));

//Set the line vertices - Reduce the number of point
if (id % traj_Acc_ratio == 0)
{
lineRenderer.SetVertexCount((int)Mathf.Floor(myPtList.Count / traj_Acc_ratio) +1);

//clamp the position of the trajectory so the objects following it do not into the walls
myPtList[id].pos = new Vector3(Mathf.Clamp(myPtList[id].pos.x, GameObject.Find("Left").transform.position.x + 0.5f, GameObject.Find("Right").transform.position.x - 0.5f),
Mathf.Clamp(myPtList[id].pos.y, GameObject.Find("Floor").transform.position.y + 0.5f, GameObject.Find("Ceiling").transform.position.y - 0.5f),
Mathf.Clamp(myPtList[id].pos.z, GameObject.Find("Front").transform.position.z + 0.5f, GameObject.Find("Back").transform.position.z - 0.5f));

lineRenderer.SetPosition(mySimpleId, myPtList[id].pos);

//Add Sphere collider to the vertex of the trajectory curve
SphereCollider myNewCollider = myPath.AddComponent<SphereCollider>();
myNewCollider.center = myPtList[id].pos;
myNewCollider.radius = 0.25f;

//Set the Vertex Postion and collider in rthe vertices list
myVtList.Add(new TrajectoryVerticesList(mySimpleId, myPtList[id].pos, myNewCollider));

mySimpleId++;
}

Expand All @@ -77,6 +114,13 @@ void Update ()

}

void OnDisable()
{
//Attach the Trajetory node to the path

}


/*void OnDrawGizmos()
{
if (myPtList.Count > 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ void FixedUpdate()
//Reset the state machine
myKinectManagerScript.selectionStateMachine = 0.0f;
}

//If Hand state from open to close -> TrashAll Items
if (myKinectManagerScript.selectionStateMachine == 1 && rectTransform.gameObject.tag == "trashAll")
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ void FixedUpdate()

}



void LateUpdate()
{
float hue;
Expand All @@ -100,21 +102,29 @@ void LateUpdate()
//Compare location distance
float howFar = Vector3.Distance(GameObject.Find("SoundsObjGrpInScene").transform.GetChild(i).position, GameObject.Find("SoundsObjGrpInScene").transform.GetChild(j).position);

if (howFar > 0.0f && howFar < SpherePattern.transform.lossyScale.z)
{
//Highlight the object in contact
float highlight = 1.0f;
/*EditorGUIUtility.*/RGBToHSV(GameObject.Find("SoundsObjGrpInScene").transform.GetChild(i).GetComponent<Renderer>().material.color, out hue, out sat, out val);
GameObject.Find("SoundsObjGrpInScene").transform.GetChild(i).GetComponent<Renderer>().material.color = /*EditorGUIUtility.*/HSVToRGB(hue, sat, highlight);
break;
}
else
TestTrajectoryWithObj mycollisionTestOfTrajectoryWithObj = GameObject.Find("SoundsObjGrpInScene").transform.GetChild(i).FindChild("CentralCollider").GetComponent<TestTrajectoryWithObj>();

if (!mycollisionTestOfTrajectoryWithObj.HighlightObjWithTrajectory)
{
//Highlight the object in contact
float highlight = 0.5f;
/*EditorGUIUtility.*/RGBToHSV(GameObject.Find("SoundsObjGrpInScene").transform.GetChild(i).GetComponent<Renderer>().material.color, out hue, out sat, out val);
GameObject.Find("SoundsObjGrpInScene").transform.GetChild(i).GetComponent<Renderer>().material.color = /*EditorGUIUtility.*/HSVToRGB(hue, sat, highlight);
if (howFar > 0.0f && howFar < SpherePattern.transform.lossyScale.z)
{
//Highlight the object in contact
float highlight = 1.0f;
/*EditorGUIUtility.*/
RGBToHSV(GameObject.Find("SoundsObjGrpInScene").transform.GetChild(i).GetComponent<Renderer>().material.color, out hue, out sat, out val);
GameObject.Find("SoundsObjGrpInScene").transform.GetChild(i).GetComponent<Renderer>().material.color = /*EditorGUIUtility.*/HSVToRGB(hue, sat, highlight);
break;
}
else
{
//Highlight the object in contact
float highlight = 0.5f;
/*EditorGUIUtility.*/
RGBToHSV(GameObject.Find("SoundsObjGrpInScene").transform.GetChild(i).GetComponent<Renderer>().material.color, out hue, out sat, out val);
GameObject.Find("SoundsObjGrpInScene").transform.GetChild(i).GetComponent<Renderer>().material.color = /*EditorGUIUtility.*/HSVToRGB(hue, sat, highlight);
}
}

}
}
}
Expand Down Expand Up @@ -340,10 +350,10 @@ public void ManageHandIconVisibility(GameObject myPanel, GameObject handObj, Gam
if (Physics.SphereCast(rayPerspective, 0.25f, out hit, Vector3.Distance(rayPerspective.origin, handObj.transform.position) - handObj.transform.localScale.z))
{
//Only if hit object is a musical object
if (hit.collider.gameObject.layer == LayerMask.NameToLayer("VRWigdets"))
if (hit.collider.gameObject.layer == LayerMask.NameToLayer("SoundObject") || hit.collider.gameObject.layer == LayerMask.NameToLayer("Trajectory"))
{
handIcon.GetComponent<RawImage>().enabled = false;
Debug.Log(hit.collider.name);
//Debug.Log(hit.collider.name);
}
else
handIcon.GetComponent<RawImage>().enabled = true;
Expand Down Expand Up @@ -399,6 +409,19 @@ public void OnDownObj(GameObject obj)

//Inactivate All Musical Object Collider - So we can place two sound at the same place
//SetAllColliderState(false);


/***********************************************************************************************************************************/
//Reset the previous in case the object has been on a trajectory previously
/***********************************************************************************************************************************/
TestTrajectoryWithObj myTestOnTrajectory = Sphere.transform.FindChild("CentralCollider").GetComponent<TestTrajectoryWithObj>();
/*//Reset dumbly previous Path
myTestOnTrajectory.previousPath = null;
//Clear the List of node
myTestOnTrajectory.myList.Clear();*/
myTestOnTrajectory.currentPath = null;
myTestOnTrajectory.releaseOnTrajectory = false;
/***********************************************************************************************************************************/
}

public void OnUpObj(GameObject obj, Vector3 myInput)
Expand Down Expand Up @@ -439,7 +462,7 @@ public void OnUpObj(GameObject obj, Vector3 myInput)
Sphere.transform.parent = MusicObjGroup.transform;

//Assign to Layer
Sphere.layer = LayerMask.NameToLayer("VRWigdets");
Sphere.layer = LayerMask.NameToLayer("SoundObject");

//Activate Object collider
Sphere.GetComponent<Collider>().enabled = true;
Expand All @@ -462,11 +485,29 @@ public void OnUpObj(GameObject obj, Vector3 myInput)
}
}

/***********************************************************************************************************************************/
//set the position of the object when dropped on a path (trajectory)
/***********************************************************************************************************************************/
TestTrajectoryWithObj myTestOnTrajectory = Sphere.transform.FindChild("CentralCollider").GetComponent<TestTrajectoryWithObj>();

//if the object is on a trajectory
if (myTestOnTrajectory.HighlightObjWithTrajectory)
{
//Refine the position of the object on the trajectory
GameObject myObjOnTrajectory = Sphere;
myObjOnTrajectory.transform.position = myTestOnTrajectory.closestStartPos;
//Debug.Log(myTestOnTrajectory.closestStartPos.x + " " + myTestOnTrajectory.closestStartPos.y + " " + " " + myTestOnTrajectory.closestStartPos.z);
Debug.Log(myTestOnTrajectory.currentPath);
myTestOnTrajectory.releaseOnTrajectory = true;
}
/***********************************************************************************************************************************/

//Disable the selection of the Icon
myLastSelectedIcon.GetComponent<RectTest>().enabled = false;

//Reset Last selected Icon
myLastSelectedIcon = null;

}
}

Expand Down Expand Up @@ -527,33 +568,67 @@ public void SelectSoundObj(GameObject myPanel, GameObject handObj, GameObject ha
//if (Physics.Raycast(rayPerspective, out hit, GameObject.Find("Floor").transform.lossyScale.z * 10))// we want to able to grasp the object anytime the handicon is located in front of it - for a more antural interaction
{
//Only if hit object is a musical object
if (hit.collider.gameObject.layer == LayerMask.NameToLayer("VRWigdets"))
if (hit.collider.gameObject.layer == LayerMask.NameToLayer("SoundObject"))
{

//if (hit.distance > Vector3.Distance(rayPerspective.origin, handObj.transform.position) - 0.6f)
{
DraggedObj = hit.collider.gameObject;
//Debug.Log("Selected Sound Object: " + DraggedObj.name);

//Deactivate Collider
DraggedObj.GetComponent<Collider>().enabled = false;
//Deactivate Collider - commented on 14/12/15 because collider is needed for the trajectory line detection
//DraggedObj.GetComponent<Collider>().enabled = false;

//Inactivate All Musical Object Collider - So we can place two sound at the same place
//SetAllColliderState(false);

/***********************************************************************************************************************************/
//Reset the previous in case the object has been on a trajectory previously
/***********************************************************************************************************************************/
TestTrajectoryWithObj myTestOnTrajectory = DraggedObj.transform.FindChild("CentralCollider").GetComponent<TestTrajectoryWithObj>();
//Reset dumbly previous Path
myTestOnTrajectory.previousPath = null;
myTestOnTrajectory.currentPath = null;
//Debug.Log("Current Path is " + myTestOnTrajectory.currentPath);
myTestOnTrajectory.releaseOnTrajectory = false;
//ClearList of nodes of trajectory
myTestOnTrajectory.myList.Clear();
/***********************************************************************************************************************************/
}
}
}

}



public void ReleaseSoundObj(GameObject myPanel)
{

if (DraggedObj)
{
//Debug.Log("Release: " + DraggedObj);

//Reset collider
DraggedObj.GetComponent<Collider>().enabled = true;

//Reset collider - commented on 14/12/15 because collider is needed for the trajectory line detection
//DraggedObj.GetComponent<Collider>().enabled = true;

/***********************************************************************************************************************************/
//set the position of the object when dropped on a path (trajectory)
/***********************************************************************************************************************************/
TestTrajectoryWithObj myTestOnTrajectory = DraggedObj.transform.FindChild("CentralCollider").GetComponent<TestTrajectoryWithObj>();

//if the object is on a trajectory
if (myTestOnTrajectory.HighlightObjWithTrajectory)
{
//Refine the position of the object on the trajectory
GameObject myObjOnTrajectory = DraggedObj;
myObjOnTrajectory.transform.position = myTestOnTrajectory.closestStartPos;
//Debug.Log(myTestOnTrajectory.closestStartPos.x + " " + myTestOnTrajectory.closestStartPos.y + " " + " " + myTestOnTrajectory.closestStartPos.z);
Debug.Log(myTestOnTrajectory.currentPath);
myTestOnTrajectory.releaseOnTrajectory = true;
}
/**************************************************************************************************************************************/


//Reset Dragged Obj
DraggedObj = null;
Expand Down Expand Up @@ -649,7 +724,7 @@ public void RecycleAllSounds()
/********************************************************************/
//Convert color HSV to RGB to HSV
/********************************************************************/
public static Color HSVToRGB(float H, float S, float V)
public /*static*/ Color HSVToRGB(float H, float S, float V)
{
if (S == 0f)
{
Expand Down Expand Up @@ -719,7 +794,7 @@ public static Color HSVToRGB(float H, float S, float V)
}
}

public static void RGBToHSV(Color rgbColor, out float H, out float S, out float V)
public /*static*/ void RGBToHSV(Color rgbColor, out float H, out float S, out float V)
{
if (rgbColor.b > rgbColor.g && rgbColor.b > rgbColor.r)
{
Expand Down
Loading

0 comments on commit 17da78e

Please sign in to comment.