Simply calculate the average for 2 Quaternions should work like follows right? :
Quaternion.Lerp(rotationlist[0].transform.rotation, rotationlist[1].transform.rotation, 0.5f);
And now I tried to put this into a recursive function, like this:
private Quaternion calcAvg(int pos, List<GameObject> rotationlist)
{
if (pos < rotationlist.Count)
{
return Quaternion.Lerp(rotationlist[pos].transform.rotation, calcAvg(++pos, rotationlist), 0.5f);
}
return ???;
}
But I'm not absolutely sure, what to put into the second return.
Edit, I added the last position into the second return but now I get an out of bounds exception:
private Quaternion calcAvg(int pos, List<GameObject> markerList)
{
if (pos < markerList.Count)
{
return Quaternion.Lerp(markerList[pos].transform.rotation, calcAvg(++pos, markerList), 0.5f);
}
return markerList[pos].transform.rotation;
}
Edit, fixed the issue, I will test this now but it looks alright :
private Quaternion calcAvg(int pos, List<GameObject> markerList)
{
if (pos < markerList.Count)
{
return Quaternion.Lerp(markerList[pos].transform.rotation, calcAvg(++pos, markerList), 0.5f);
}
return markerList[pos].transform.rotation;
}