hjkhjjkh
using UnityEngine; using System.Collections; using UnityEngine.Networking; using UnityEngine.UI; using UnityEngine.EventSystems; using System.Collections.Generic; public class Argos_VR_Navigate : MonoBehaviour { public float ArrowSpeed = 1f; public float MouseLLnearSpeed = 60f; public float MouseAngularSpeed = 60f; public float damping = 0.1f; public float ReleaseTime = 1.2f; bool bLMButtonisDown = false; bool bRMButtonisDown = false; bool bMMMouseButtonisDown = false; bool bLMButtonWasDown = false; bool bRMButtonWasDown = false; bool bMMMouseButtonWasDown = false; bool bAnyMouseButton = false; float xMouse_Damped; float yMouse_Damped; float[] arrowsDamped = new float[4]; bool[] bArrow = new bool[4]; bool[] bArrowWasDown = new bool[4]; float[] MTimer = new float[3]; float[] ATimer = new float[4]; GameObject argosSphere; //GameObject userMovement; //GameObject NavSphere_Pivot; //GameObject NavSphere; //UI_Control ui_control; public Text txtInputIndicator; Vector2 touchPos; Vector3 vHoldPivot; bool bRotaPivot_On = false; bool m_bAllowInput = true; public RMF_RadialMenu rmf_Radial_Menu; public enum Arrows { UP = 0, DOWN, LEFT, RIGHT, } public static class Arrow { public const int UP = 0; public const int DOWN = 1; public const int LEFT = 2; public const int RIGHT = 3; } public enum MouseButts { LMB, RMB, MMB, } public static class MouseButt { public const int LMB = 0; public const int RMB = 1; public const int MMB = 2; } public Vector3 baseOVR_Pos; public Quaternion baseOVR_Rota; public int iMode_GearVR; public static class GVR_MODE { public const int LMB = 0; public const int RMB = 1; public const int HOME = 2; public const int MMB = 3; } public GameObject OVR_Main_Cam; public float seeX; public float seeY; public void Start() { argosSphere = GameObject.Find("ARGOS_Fibonacci_Second_Generation"); //userMovement = GameObject.Find("User_Movement"); //ui_control = GameObject.Find("UI_Control_Canvas").GetComponent<UI_Control>(); //NavSphere_Pivot = GameObject.Find("NavSphere_Pivot"); //NavSphere = GameObject.Find("Argos_NavSphere"); OVRTouchpad.Create(); OVRTouchpad.TouchHandler += HandleTouchHandler; baseOVR_Pos = OVR_Main_Cam.transform.position; baseOVR_Rota = OVR_Main_Cam.transform.rotation; } void HandleTouchHandler(object sender, System.EventArgs e) { OVRTouchpad.TouchArgs touchArgs = (OVRTouchpad.TouchArgs)e; OVRTouchpad.TouchEvent touchEvent = touchArgs.TouchType; /*if(touchArgs.TouchType == OVRTouchpad.TouchEvent.SingleTap) { //TODO: Insert code here to handle a single tap. Note that there are other TouchTypes you can check for like directional swipes, but double tap is not currently implemented I believe. }*/ switch (touchEvent) { case OVRTouchpad.TouchEvent.SingleTap: txtInputIndicator.text = "SingleTap"; rmf_Radial_Menu.onNavSelect(); TouchPadHandler(); break; case OVRTouchpad.TouchEvent.Left: txtInputIndicator.text = "Left"; break; case OVRTouchpad.TouchEvent.Right: txtInputIndicator.text = "Right"; break; case OVRTouchpad.TouchEvent.Up: txtInputIndicator.text = "Up"; break; case OVRTouchpad.TouchEvent.Down: txtInputIndicator.text = "Down"; break; } } public void onGreenButton() { m_bAllowInput = true; } public void onRedButton() { m_bAllowInput = !m_bAllowInput; } void TouchPadHandler() { if (rmf_Radial_Menu.idxSelected == GVR_MODE.HOME) { OVR_Main_Cam.transform.position = baseOVR_Pos; OVR_Main_Cam.transform.rotation = baseOVR_Rota; } if (rmf_Radial_Menu.idxSelected == GVR_MODE.LMB) { bLMButtonisDown = true; bLMButtonWasDown = true; MTimer[MouseButt.RMB] = 0f; bRMButtonWasDown = false; MTimer[MouseButt.MMB] = 0f; bMMMouseButtonWasDown = false; } else { bLMButtonisDown = false; } if (rmf_Radial_Menu.idxSelected == GVR_MODE.RMB) { bRMButtonisDown = true; bRMButtonWasDown = true; MTimer[MouseButt.LMB] = 0f; bLMButtonWasDown = false; MTimer[MouseButt.MMB] = 0f; bMMMouseButtonWasDown = false; } else { bRMButtonisDown = false; } if (rmf_Radial_Menu.idxSelected == GVR_MODE.MMB) { bMMMouseButtonisDown = true; bMMMouseButtonWasDown = true; MTimer[MouseButt.LMB] = 0f; bLMButtonWasDown = false; MTimer[MouseButt.RMB] = 0f; bRMButtonWasDown = false; } else { bMMMouseButtonisDown = false; } bAnyMouseButton = bLMButtonisDown || bRMButtonisDown || bMMMouseButtonisDown || Input.GetKey("right ctrl") || Input.GetKey("e"); } void checkMouseButts() { if (Input.GetMouseButtonDown(0)) { bLMButtonisDown = true; bLMButtonWasDown = true; MTimer[MouseButt.RMB] = 0f; bRMButtonWasDown = false; MTimer[MouseButt.MMB] = 0f; bMMMouseButtonWasDown = false; } if (Input.GetMouseButtonUp(0)) { bLMButtonisDown = false; } if (Input.GetMouseButtonDown(1)) { bRMButtonisDown = true; bRMButtonWasDown = true; MTimer[MouseButt.LMB] = 0f; bLMButtonWasDown = false; MTimer[MouseButt.MMB] = 0f; bMMMouseButtonWasDown = false; } if (Input.GetMouseButtonUp(1)) { bRMButtonisDown = false; } if (Input.GetMouseButtonDown(2)) { bMMMouseButtonisDown = true; bMMMouseButtonWasDown = true; MTimer[MouseButt.LMB] = 0f; bLMButtonWasDown = false; MTimer[MouseButt.RMB] = 0f; bRMButtonWasDown = false; } if (Input.GetMouseButtonUp(2)) { bMMMouseButtonisDown = false; } bAnyMouseButton = bLMButtonisDown || bRMButtonisDown || bMMMouseButtonisDown || Input.GetKey("right ctrl") || Input.GetKey("e"); } void Update() { //test OVR single tap if(Input.GetMouseButtonDown(0)) { rmf_Radial_Menu.onNavSelect(); } iMode_GearVR = rmf_Radial_Menu.idxSelected; MouseHandler(); if (!EventSystem.current.IsPointerOverGameObject()) { //NavSphere_Pivot.transform.position = transform.position; //if(ui_control.isLocked_NavSpheretoCam) //{ // NavSphere_Pivot.transform.rotation = transform.rotation; //} } //if (Input.touchCount > 0) //{ // if (Input.GetTouch(0).phase == TouchPhase.Began) // { // PointerEventData ped = new PointerEventData(null); // ped.position = Input.GetTouch(0).position; // List<RaycastResult> results = new List<RaycastResult>(); // GR.Raycast(ped, results); // if (results.Count == 0) // { // } // } //} } void MouseHandler() { //checkMouseButts(); float x = GearVRInput.GetAxisX; float y = GearVRInput.GetAxisY; seeX = x; seeY = y; if (bAnyMouseButton) { xMouse_Damped = Mathf.Lerp(xMouse_Damped, x, damping); yMouse_Damped = Mathf.Lerp(yMouse_Damped, y, damping); //MTimer[MouseButt.LMB] = MTimer[MouseButt.RMB] = MTimer[MouseButt.MMB] = 0f; } else { xMouse_Damped = Mathf.Lerp(xMouse_Damped, 0f, damping); yMouse_Damped = Mathf.Lerp(yMouse_Damped, 0f, damping); } float xMD_TimeScaled_AngVel = xMouse_Damped * MouseAngularSpeed * Time.deltaTime; float yMD_TimeScaled_AngVel = yMouse_Damped * MouseAngularSpeed * Time.deltaTime; float xMD_TimeScaled_LinVel = xMouse_Damped * MouseLLnearSpeed * Time.deltaTime; float yMD_TimeScaled_LinVel = yMouse_Damped * MouseLLnearSpeed * Time.deltaTime; //bArrow[Arrow.UP] = Input.GetKey(KeyCode.UpArrow); //bArrow[Arrow.DOWN] = Input.GetKey(KeyCode.DownArrow); //bArrow[Arrow.LEFT] = Input.GetKey(KeyCode.LeftArrow); //bArrow[Arrow.RIGHT] = Input.GetKey(KeyCode.RightArrow); //arrowsDamped[Arrow.UP] = Mathf.Lerp(arrowsDamped[Arrow.UP], ArrowSpeed*(bArrow[Arrow.UP] ?1f:0f), damping); //arrowsDamped[Arrow.DOWN] = Mathf.Lerp(arrowsDamped[Arrow.DOWN], ArrowSpeed * (bArrow[Arrow.DOWN] ? 1f : 0f), damping); //arrowsDamped[Arrow.LEFT] = Mathf.Lerp(arrowsDamped[Arrow.LEFT], ArrowSpeed * (bArrow[Arrow.LEFT] ? 1f : 0f), damping); //arrowsDamped[Arrow.RIGHT] = Mathf.Lerp(arrowsDamped[Arrow.RIGHT], ArrowSpeed * (bArrow[Arrow.RIGHT] ? 1f : 0f), damping); for (int i = 0; i<4; i++) { if (bArrow[i]) { if (ATimer[i] > 0.0f) { bArrowWasDown[i] = false; ATimer[i] = 0f; } else { bArrowWasDown[i] = true; } } } if (bLMButtonisDown || bLMButtonWasDown) { OVR_Main_Cam.transform.Translate(0, -yMD_TimeScaled_LinVel, xMD_TimeScaled_LinVel); if (!bLMButtonisDown) { MTimer[MouseButt.LMB] += Time.deltaTime; if (MTimer[MouseButt.LMB] > ReleaseTime) { MTimer[MouseButt.LMB] = 0f; bLMButtonWasDown = false; } } } if (bRMButtonisDown || bRMButtonWasDown) { OVR_Main_Cam.transform.Translate(-xMD_TimeScaled_LinVel, -yMD_TimeScaled_LinVel, 0); if (!bRMButtonisDown) { MTimer[MouseButt.RMB] += Time.deltaTime; if (MTimer[MouseButt.RMB] > ReleaseTime) { MTimer[MouseButt.RMB] = 0f; bRMButtonWasDown = false; } } } if (bMMMouseButtonisDown || bMMMouseButtonWasDown) { OVR_Main_Cam.transform.Translate(0, 0, yMD_TimeScaled_LinVel); OVR_Main_Cam.transform.RotateAround(argosSphere.transform.position, OVR_Main_Cam.transform.up, xMD_TimeScaled_AngVel); if (!bMMMouseButtonisDown) { MTimer[MouseButt.MMB] += Time.deltaTime; if (MTimer[MouseButt.MMB] > ReleaseTime) { MTimer[MouseButt.MMB] = 0f; bMMMouseButtonWasDown = false; } } } if (Input.GetKey("right ctrl") || Input.GetKey("left ctrl")) { //if (!bRotaPivot_On) //{ // vHoldPivot = userMovement.GetComponent<UserMovement>().getCursorPostiion() + argosSphere.transform.position; // bRotaPivot_On = true; //} OVR_Main_Cam.transform.RotateAround(vHoldPivot, OVR_Main_Cam.transform.up, xMD_TimeScaled_AngVel); OVR_Main_Cam.transform.RotateAround(vHoldPivot, OVR_Main_Cam.transform.right, yMD_TimeScaled_AngVel); return; } else { bRotaPivot_On = false; } if (Input.GetKey("e")) { Vector3 pos = argosSphere.transform.position; OVR_Main_Cam.transform.RotateAround(pos, OVR_Main_Cam.transform.up, xMD_TimeScaled_AngVel); OVR_Main_Cam.transform.RotateAround(pos, transform.right, -yMD_TimeScaled_AngVel); return; } if (bArrow[Arrow.UP] || bArrowWasDown[Arrow.UP]) { //transform.Translate(0,arrowsDamped[Arrow.UP]*Time.deltaTime, 0); Vector3 pos = argosSphere.transform.position; //if (ui_control.rotateOnNavSphere) //{ // transform.RotateAround(pos, NavSphere.transform.right, -arrowsDamped[Arrow.UP] * Time.deltaTime); //} //else //{ OVR_Main_Cam.transform.RotateAround(pos, transform.right, -arrowsDamped[Arrow.UP] * Time.deltaTime); //} if (!bArrow[Arrow.UP]) { ATimer[Arrow.UP] += Time.deltaTime; if (ATimer[Arrow.UP] > ReleaseTime) { ATimer[Arrow.UP] = 0f; bArrowWasDown[Arrow.UP] = false; } } } if (bArrow[Arrow.DOWN] || bArrowWasDown[Arrow.DOWN]) { //transform.Translate(0, -arrowsDamped[Arrow.DOWN] * Time.deltaTime, 0); Vector3 pos = argosSphere.transform.position; transform.RotateAround(pos, transform.right, arrowsDamped[Arrow.DOWN] * Time.deltaTime); //if (ui_control.rotateOnNavSphere) //{ // transform.RotateAround(pos, NavSphere.transform.right, arrowsDamped[Arrow.DOWN] * Time.deltaTime); //} //else //{ transform.RotateAround(pos, transform.right, arrowsDamped[Arrow.DOWN] * Time.deltaTime); //} if (!bArrow[Arrow.DOWN]) { ATimer[Arrow.DOWN] += Time.deltaTime; if (ATimer[Arrow.DOWN] > ReleaseTime) { ATimer[Arrow.DOWN] = 0f; bArrowWasDown[Arrow.DOWN] = false; } } } if (bArrow[Arrow.LEFT] || bArrowWasDown[Arrow.LEFT]) { //transform.Translate(-arrowsDamped[Arrow.LEFT] * Time.deltaTime, 0, 0); Vector3 pos = argosSphere.transform.position; //if (ui_control.rotateOnNavSphere) //{ // transform.RotateAround(pos, NavSphere.transform.up, arrowsDamped[Arrow.LEFT] * Time.deltaTime); //} //else //{ transform.RotateAround(pos, transform.up, arrowsDamped[Arrow.LEFT] * Time.deltaTime); //} if (!bArrow[Arrow.LEFT]) { ATimer[Arrow.LEFT] += Time.deltaTime; if (ATimer[Arrow.LEFT] > ReleaseTime) { ATimer[Arrow.LEFT] = 0f; bArrowWasDown[Arrow.LEFT] = false; } } } if (bArrow[Arrow.RIGHT] || bArrowWasDown[Arrow.RIGHT]) { //transform.Translate(arrowsDamped[Arrow.RIGHT] * Time.deltaTime, 0, 0); Vector3 pos = argosSphere.transform.position; transform.RotateAround(pos, transform.up, -arrowsDamped[Arrow.RIGHT] * Time.deltaTime); //if (ui_control.rotateOnNavSphere) //{ // transform.RotateAround(pos, NavSphere.transform.up, -arrowsDamped[Arrow.RIGHT] * Time.deltaTime); //} //else //{ transform.RotateAround(pos, transform.up, -arrowsDamped[Arrow.RIGHT] * Time.deltaTime); //} if (!bArrow[Arrow.RIGHT]) { ATimer[Arrow.RIGHT] += Time.deltaTime; if (ATimer[Arrow.RIGHT] > ReleaseTime) { ATimer[Arrow.RIGHT] = 0f; bArrowWasDown[Arrow.RIGHT] = false; } } } } }
using UnityEngine; using System.Collections; using System.Collections.Generic; using System.Linq; using System; public class Hexsphere : MonoBehaviour { public static Hexsphere instance; public Transform core; public int TileCount; [Range(1, 4)] public int detailLevel; public int numColors; public static float unitScale; public Material hexMat; public Material pentMat; public Material hexInsideMat; public Material pentInsideMat; private float radialScale; private float maxEdgeLength; private float maxTileRadius; private float worldRadius; private List<Vector3> vectors = new List<Vector3>(); private List<int> indices = new List<int>(); private List<GameObject> Tiles = new List<GameObject>(); void Start() { instance = this; //radialScale = detailLevel; //Build the HexSphere BuildWorld (); //Set Tile colors, Generate Regions, Spawn gameobjects etc MapBuilder (); } private void BuildWorld(){ if (detailLevel < 1) { detailLevel = 1; } //Mesh generation freezes up for detail levels greater than 4 if (detailLevel > 4) { detailLevel = 4; } radialScale = detailLevel; unitScale = detailLevel; #region Generate Icosahedron Vertices //HEX VERTICES Geometry.Icosahedron(vectors, indices); //subdivide for (int i = 0; i < detailLevel; i++) Geometry.Subdivide(vectors, indices, true); /// normalize vectors to "inflate" the icosahedron into a sphere. for (int i = 0; i < vectors.Count; i++) vectors[i]=Vector3.Normalize(vectors[i]) * radialScale;// * Mathf.Pow(2.17f, (float)detailLevel); #endregion List<Vector3> centers = getTriangleIncenter(vectors, indices); maxEdgeLength = getMaxEdgeDistance (centers); maxTileRadius = getMaxTileRadius (centers, vectors); generateSubMeshes (centers, vectors); TileCount = Tiles.Count; worldRadius = Vector3.Magnitude (centers [0]); } private void generateSubMeshes(List<Vector3> centers, List<Vector3> vertices) { //Generate the hex/pent mesh for each vertex in the main mesh by associating it to its surrounding triangle centers for(int i = 0; i < vertices.Count; i++) { GameObject tile = new GameObject ("Tile"); Mesh submesh = new Mesh (); tile.AddComponent<MeshFilter> (); //tile.transform.localPosition = vertices[i]; List<Vector3> submeshVs = new List<Vector3>(); for(int j = 0; j < centers.Count; j++) { if(Vector3.Distance(vertices[i], centers[j]) <= maxTileRadius) { submeshVs.Add(centers[j]); } } //If its a pentagon if(submeshVs.Count == 5) { bool[] isUsed = new bool[5]; List<int> orderedIndices = new List<int>(); Vector3 current = submeshVs[0]; orderedIndices.Add(0); isUsed[0] = true; //starting at the first point in submeshVs, find a point on the perimeter of the tile that is within one edgelength from point current, then add its index to the list while(orderedIndices.Count < 5) { foreach(Vector3 c in submeshVs) { if(Vector3.Distance(c, current) <= maxEdgeLength && Vector3.Distance(c, current) >= 0.001f && !isUsed[submeshVs.IndexOf(c)]) { //triangles[h + j] = submeshVs.IndexOf(c); orderedIndices.Add(submeshVs.IndexOf(c)); isUsed[submeshVs.IndexOf(c)] = true; current = c; break; } } } int[] triangles = new int[9]; triangles[0] = 0; triangles[1] = orderedIndices[1]; triangles[2] = orderedIndices[2]; triangles[3] = orderedIndices[2]; triangles[4] = orderedIndices[3]; triangles[5] = orderedIndices[0]; triangles[6] = orderedIndices[3]; triangles[7] = orderedIndices[4]; triangles[8] = orderedIndices[0]; Vector3[] subVsArray = submeshVs.ToArray(); submesh.vertices = subVsArray; submesh.triangles = triangles; Vector2[] uvs = new Vector2[submeshVs.Count]; uvs[orderedIndices[0]] = new Vector2(0f, 0.625f); uvs[orderedIndices[1]] = new Vector2(0.5f, 1f); uvs[orderedIndices[2]] = new Vector2(1f, 0.625f); uvs[orderedIndices[3]] = new Vector2(0.8f, 0.0162f); uvs[orderedIndices[4]] = new Vector2(.1875f, 0.0162f); submesh.uv = uvs; //tile.AddComponent<MeshRenderer>().material = pentMat; tile.AddComponent<MeshRenderer>(); //When using multiple materials.. // Material[] pentMats = new Material[2]; // pentMats[0] = pentInsideMat; // pentMats[1] = pentMat; // tile.GetComponent<Renderer>().materials = pentMats; //Single material tile.GetComponent<Renderer>().material = pentMat; } //If its a hexagon else if(submeshVs.Count == 6){ bool[] isUsed = new bool[6]; List<int> orderedIndices = new List<int>(); Vector3 current = submeshVs[0]; orderedIndices.Add(0); isUsed[0] = true; //starting at the first point in submeshVs, find a point on the perimeter of the tile that is within one edgelength from point current, then add its index to the list while(orderedIndices.Count < 6) { foreach(Vector3 c in submeshVs) { if(Vector3.Distance(c, current) <= maxEdgeLength && Vector3.Distance(c, current) >= 0.001f && !isUsed[submeshVs.IndexOf(c)]) { orderedIndices.Add(submeshVs.IndexOf(c)); isUsed[submeshVs.IndexOf(c)] = true; current = c; break; } } } int[] triangles = new int[12]; triangles[0] = 0; triangles[1] = orderedIndices[1]; triangles[2] = orderedIndices[2]; triangles[3] = orderedIndices[2]; triangles[4] = orderedIndices[3]; triangles[5] = 0; triangles[6] = orderedIndices[3]; triangles[7] = orderedIndices[4]; triangles[8] = 0; triangles[9] = orderedIndices[4]; triangles[10] = orderedIndices[5]; triangles[11] = 0; Vector3[] subVsArray = submeshVs.ToArray(); submesh.vertices = subVsArray; submesh.triangles = triangles; //Vector2[] uvs = new Vector2[submeshVs.Count]; Vector2[] uvs = new Vector2[6]; //UV Coords based on geometry of hexagon uvs[orderedIndices[0]] = new Vector2(0.0543f, 0.2702f); uvs[orderedIndices[1]] = new Vector2(0.0543f, 0.7272f); uvs[orderedIndices[2]] = new Vector2(0.5f, 1f); uvs[orderedIndices[3]] = new Vector2(0.946f, 0.7272f); uvs[orderedIndices[4]] = new Vector2(0.946f, 0.2702f); uvs[orderedIndices[5]] = new Vector2(0.5f, 0f); submesh.uv = uvs; //tile.AddComponent<MeshRenderer>().material = hexMat; tile.AddComponent<MeshRenderer>(); // Material[] hexMats = new Material[2]; // hexMats[0] = hexInsideMat; // hexMats[1] = hexMat; // tile.GetComponent<Renderer>().materials = hexMats; //Single material tile.GetComponent<Renderer>().material = hexMat; } //Assign mesh tile.GetComponent<MeshFilter>().mesh = submesh; submesh.RecalculateBounds(); submesh.RecalculateNormals(); tile.AddComponent<Tile>(); //Fix any upsidedown tiles by checking their normal vector if((submesh.normals[0] + vertices[i]).magnitude < vertices[i].magnitude) { submesh.triangles = submesh.triangles.Reverse().ToArray(); submesh.RecalculateBounds(); submesh.RecalculateNormals(); } //Initialize tile attributes tile.AddComponent<MeshCollider>(); //tile.GetComponent<MeshCollider>().convex = true; //tile.GetComponent<MeshCollider>().isTrigger = true; tile.transform.parent = this.transform; tile.isStatic = true; tile.GetComponent<Tile>().Initialize(vertices[i]); tile.GetComponent<Renderer>().material.color = Color.white; tile.tag = "Tile"; tile.GetComponent<Tile>().setTileRadius(maxTileRadius); Tiles.Add(tile); } } private void MapBuilder(){ //Randomly assign colors for (int i = 0; i < Tiles.Count; i++) { Tiles[i].GetComponent<Tile>().setColor(UnityEngine.Random.Range(1, numColors+1)); } //find each tiles neighbors for (int i = 0; i < Tiles.Count; i++) { Tiles[i].GetComponent<Tile>().FindNeighbors(); } } private float getMaxTileRadius(List<Vector3> centers, List<Vector3> vertices){ float delta = 1.5f; Vector3 v = Vector3.zero; if (detailLevel != 0) { v = vertices [12]; } else{ v = vertices [0]; } float minDistance = Mathf.Infinity; foreach (Vector3 c in centers) { float dist = Vector3.Distance(v, c); if (dist < minDistance){ minDistance = dist; } } minDistance = minDistance * (delta); return minDistance; } private float getMaxEdgeDistance(List<Vector3> centers) { //Returns the approximate distance between adjacent triangle centers //delta is the approximate variation in edge lengths, as not all edges are the same length float delta = 1.4f; Vector3 point = centers [0]; // scan all vertices to find nearest float minDistance = Mathf.Infinity; foreach (Vector3 n in centers) { if(!point.Equals(n)){ float dist = Vector3.Distance(point, n); if (dist < minDistance){ minDistance = dist; } } } minDistance = minDistance * (delta); return minDistance; } private List<Vector3> getTriangleIncenter(List<Vector3> vertices, List<int> triangles){ List<Vector3> centers = new List<Vector3> (); for (int i = 0; i < triangles.Count - 2; i += 3) { Vector3 A = vertices[triangles[i]]; Vector3 B = vertices[triangles[i + 1]]; Vector3 C = vertices[triangles[i + 2]]; float a = Vector3.Distance(C, B); float b = Vector3.Distance(A, C); float c = Vector3.Distance(A, B); float P = a + b + c; Vector3 abc = new Vector3(a, b, c); float x = Vector3.Dot (abc, new Vector3(A.x, B.x, C.x)) / P; float y = Vector3.Dot (abc, new Vector3(A.y, B.y, C.y)) / P; float z = Vector3.Dot (abc, new Vector3(A.z, B.z, C.z)) / P; Vector3 center = new Vector3(x, y, z); centers.Add(center); } return centers; } }