public List <Side> oppositeSide(Tetrahedron tetrahedron, Side side) { HashSet <int> sideEndPts = TetraUtil.vertexIDs(side.vertices); HashSet <int> notSideEndPts = new HashSet <int>(); List <Side> outputSides = new List <Side>(); foreach (Tetrahedron t in tetrahedrons) { if (t.type != 2) { if (t.sides.Contains(side)) { HashSet <int> tempSet = TetraUtil.vertexIDs(t.vertices); notSideEndPts.UnionWith(tempSet.Except(sideEndPts)); } foreach (Side s in t.sides) { HashSet <int> tempSideVtx = TetraUtil.vertexIDs(s.vertices); tempSideVtx.IntersectWith(notSideEndPts); if (tempSideVtx.Count == 2) { outputSides.Add(s); } } } } return(outputSides); }
//Run to update list of tetrahedrons public void setupTetras() { Debug.Log("---------Vertices---------"); vertices.Clear(); tetrahedrons.Clear(); tr.renderTetras.Clear(); int maxVertexCount = maxVertex(); Debug.Log("max vertex count: " + maxVertexCount); Vertex[] tempVertices = new Vertex[maxVertexCount]; for (int i = 0; i < maxVertexCount; i++) { Vertex tempVertex = new Vertex(i); Debug.Log("Vertex: " + tempVertex + "; ID: " + tempVertex.ID + "; Pos: " + tempVertex.pos); tempVertices[i] = tempVertex; vertices.Add(tempVertex); } TetraUtil.isNull(tempVertices); tetrahedrons.Add(new Tetrahedron(tempVertices[0], tempVertices[1], tempVertices[2], tempVertices[3], 1)); for (int j = 1; j < vertexList.Count; j++) { tetrahedrons.Add(new Tetrahedron( tempVertices[vertexList[j][0]], tempVertices[vertexList[j][1]], tempVertices[vertexList[j][2]], tempVertices[vertexList[j][3]], vertexList[j][4] )); } Debug.Log(tetrahedrons.Count + " tetrahedron(s)"); foreach (Tetrahedron tetra in tetrahedrons) { tr.renderTetras.Add(tetra); } Debug.Log(tr.renderTetras.Count + " render tetrahedron(s)"); quickSideSet = true; }
void OnGUI() { //Display tracking and selected tetrahedrons if (selection.Count == 1) { ui.singleTracking(trackingActive, selection[0].name); if (trackingActive) { if (edgeView) { foreach (Tetrahedron tetrahedron in selection[0].tetrahedrons) { if (tetrahedron.type != 2) { foreach (Side side in tetrahedron.sides) { Vector3 finalPos = TetraUtil.averageVertices(side.vertices, selection[0].transform); ui.numberAtPos(finalPos, side.ID, false, "s"); } } } } else { foreach (Vertex vertex in selection[0].vertices) { Vector3 tempPos = selection[0].transform.TransformPoint(vertex.pos); ui.numberAtPos(tempPos, vertex.ID, selection[0].newTetraVtx.Contains(vertex.ID)); } } } } else if (selection.Count > 1) { ui.multipleTracking(trackingActive, selection.Count); } ui.loop(); inc.loop(); }
public void loop() { if (type == 0) { vertices[3].pos = TetraUtil.trilaterate( vertices[0].pos, vertices[1].pos, vertices[2].pos, sides[0].length, sides[1].length, sides[2].length, inverted ); } else if (type == 1) { Vector3[] outputVertices = TetraUtil.originVertices( sides[0].length, sides[1].length, sides[2].length, sides[3].length, sides[4].length, sides[5].length ); vertices[0].pos = outputVertices[0]; vertices[1].pos = outputVertices[1]; vertices[2].pos = outputVertices[2]; vertices[3].pos = outputVertices[3]; } }
//Physics update, runs repeatedly void FixedUpdate() { //Sets center of mass centerMass = TetraUtil.averageVertices(vertices, this.transform); if (tr == null) { Start(); } //Tells tetraRenderer to pick color if (!colorPicked) { colorPicked = true; tr.pickRandomColor(); } //Runs setup of tetrahedrons if (runSetup) { runSetup = false; setupTetras(); } //Sets side lengths in tetrahedrons int p = 0; bool quickSetReset = false; HashSet <int> alreadySetIDs = new HashSet <int>(); foreach (Tetrahedron tetrahedron in tetrahedrons) { if (tetrahedron.type != 2) { foreach (Side side in tetrahedron.sides) { if (sideSetList.Count < p + 1) { sideSetList.Add(2.0f); } if (disphenoidMode) { foreach (Side tempSide in oppositeSide(tetrahedron, side)) { if (!alreadySetIDs.Contains(tempSide.ID)) { sideSetList[tempSide.ID] = sideSetList[side.ID]; } } alreadySetIDs.Add(side.ID); } if (quickSideSet) { quickSetReset = true; side.length = sideSetList[p]; } else { side.length = Mathf.SmoothStep(side.length, sideSetList[p], 0.10f); } side.ID = p; if (runOppositeSide && p == sideVal) { runOppositeSide = false; Debug.Log("----------"); int oppositeID = oppositeSide(tetrahedron, side)[0].ID; Debug.Log("Opposite side is: " + oppositeID); } p++; } } } if (quickSetReset) { quickSideSet = false; } //Runs loop of tetrahedrons foreach (Tetrahedron tetra in tetrahedrons) { tetra.loop(); } //Catches if tetraRenderer does not exist if (tr == null) { tr = new TetraRenderer(this.gameObject); } //Loops tetraRenderer tr.loop(); if (tetrahedrons.Count == 1 && walkControl) { sw.loop(); } }
void Update() { if (ui == null) { Start(); } goalPoint = GameObject.FindGameObjectWithTag("GoalPoint").transform; Vector3 newPosition = transform.position; float zoomAmount = zoomSpeed * Input.GetAxis("Mouse ScrollWheel"); if (!trackingActive) //Not Tracking { // Screen scrolling if (Input.mousePosition.x < screenWidth && Input.mousePosition.x > screenWidth - boundary) { newPosition.x += speed * Time.deltaTime; // move on +X axis } if (Input.mousePosition.x > 0 && Input.mousePosition.x < 0 + boundary) { newPosition.x -= speed * Time.deltaTime; // move on -X axis } if (Input.mousePosition.y < screenHeight && Input.mousePosition.y > screenHeight - boundary) { newPosition.z += speed * Time.deltaTime; // move on +Z axis } if (Input.mousePosition.y > 0 && Input.mousePosition.y < 0 + boundary) { newPosition.z -= speed * Time.deltaTime; // move on -Z axis } //Zoom while untracked Vector3 zoomDelta; Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); zoomDelta = ray.direction.normalized * zoomAmount; if (newPosition.y + zoomDelta.y >= zoomMin && newPosition.y + zoomDelta.y <= zoomMax) { newPosition += zoomDelta; } } else if (trackingActive && selection.Count > 0) //Tracking Tetrahedron(s) { //Movment while tracked Vector3 trackingCenter = TetraUtil.averageSelection(selection); newPosition.x = trackingCenter.x; if (trackingCenter.y > 1f) { heightOffsetY = trackingCenter.y; } else { heightOffsetY = 0f; } optimalZ = trackingCenter.z; //Zooming while tracked trackingDistance -= zoomAmount / 2; trackingDistance = Mathf.Clamp(trackingDistance, zoomMin, zoomMax); newPosition.y = trackingDistance + heightOffsetY; newPosition.z = optimalZ - trackingDistance; //Rotate selected tetrahedron if (buildHover && selection.Count == 1) { if (yawLeft) { selection[0].setYawRate(1.0f); } else if (yawRight) { selection[0].setYawRate(-1.0f); } else { selection[0].setYawRate(0.0f); } if (pitchUp) { selection[0].setPitchRate(1.0f); } else if (pitchDown) { selection[0].setPitchRate(-1.0f); } else { selection[0].setPitchRate(0.0f); } yawLeft = false; yawRight = false; pitchUp = false; pitchDown = false; } } if (Input.GetKeyUp(KeyCode.LeftControl)) { inputID = 0; } //Unit Selection if (Input.GetMouseButtonDown(0)) { Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast(ray, out hit, 100)) { if (Input.GetKey(KeyCode.LeftShift)) { if (!hit.transform.CompareTag("Terrain")) { bool copyDetected = false; for (int i = 0; i < selection.Count; i++) { if (hit.transform == selection[i]) { copyDetected = true; } } if (!copyDetected) { selection.Add(hit.transform.GetComponent <TetraController>()); } } } else if (!hit.transform.CompareTag("Terrain") && Input.GetKey(KeyCode.LeftControl) && inputID < 4) { globVertexId = hit.transform.GetComponent <TetraController>().closestVertex(hit.point); hitPos = hit.point; hit.transform.GetComponent <TetraController>().newTetraVtx[inputID] = globVertexId; inputID++; Debug.Log("Detected vertex: " + globVertexId + " added on ID: " + inputID); } else { if (!hit.transform.CompareTag("Terrain")) { selection.Clear(); selection.Add(hit.transform.GetComponent <TetraController>()); } else { if (buildHover) { toggleHover_(); } selection.Clear(); trackingActive = false; globVertexId = -1; } } } } //Unit Movement Command if (Input.GetMouseButtonDown(1) && (selection.Count > 0)) { Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast(ray, out hit, 100)) { if (hit.transform.CompareTag("Terrain")) { goalPoint.position = hit.point; for (int i = 0; i < selection.Count; i++) { selection[i].sw.startContinuousWalk(goalPoint); } } } } transform.position = Vector3.MoveTowards(transform.position, newPosition, 0.5f); }