public void ActivateHUD() { //Assesses which cues should be illuminated and their appropriate size foreach (ObstInfo obst in ObstInfos) { /* * //Calculate minimum, maximum, and absolute minimum X and Y angles for each obstacle * float minX = 100; * float minY = 100; * float maxX = -100; * float maxY = -100; * float absMinX = 100; * float absMinY = 100; * * foreach (float x in obst.ObstXAngles) * { * if (x <= minX) * minX = x; * * if (x >= maxX) * maxX = x; * * if (Mathf.Abs(absMinX) >= Mathf.Abs(x)) * absMinX = Mathf.Abs(x); * } * * foreach (float y in obst.ObstYAngles) * { * if (y <= minY) * minY = y; * * if (y >= maxY) * maxY = y; * * if (Mathf.Abs(absMinY) >= Mathf.Abs(y)) * absMinY = Mathf.Abs(y); * } */ foreach (float x in obst.ObstXAngles) { if (x <= obst.ObstMinX) { obst.ObstMinX = x; } else if (x >= obst.ObstMaxX) { obst.ObstMaxX = x; } if (Mathf.Abs(x) <= Mathf.Abs(obst.ObstMinAbsX)) { obst.ObstMinAbsX = Mathf.Abs(x); } } foreach (float y in obst.ObstYAngles) { if (y <= obst.ObstMinY) { obst.ObstMinY = y; } else if (y >= obst.ObstMaxY) { obst.ObstMaxY = y; } if (Mathf.Abs(y) <= Mathf.Abs(obst.ObstMinAbsY)) { obst.ObstMinAbsY = Mathf.Abs(y); } } } //For each cue, scan the obstacle info list and see if it should be on or not foreach (GameObject Cue in HUDCues) { //Debug.Log("Cue name: " + Cue.name); bool resetTrigger = false; //If cue is on from a previous frame and hasn't passed the fade time threshold yet, keep it on; otherwise, reset it if (Cue.name == "HUD Cue East") { if (Time.time <= eastTrigger + fadeTime) { //Do nothing } else { Cue.SetActive(false); eastMultiplier = 1.0f; Cue.transform.localScale = Vector3.one; resetTrigger = true; } } else if (Cue.name == "HUD Cue South") { if (Time.time <= southTrigger + fadeTime) { //Do nothing } else { Cue.SetActive(false); southMultiplier = 1.0f; Cue.transform.localScale = Vector3.one; resetTrigger = true; //Debug.Log("South cue reset."); } } else if (Cue.name == "HUD Cue West") { if (Time.time <= westTrigger + fadeTime) { //Do nothing } else { Cue.SetActive(false); westMultiplier = 1.0f; Cue.transform.localScale = Vector3.one; resetTrigger = true; } } else if (Cue.name == "HUD Cue North") { if (Time.time <= northTrigger + fadeTime) { //Do nothing } else { Cue.SetActive(false); northMultiplier = 1.0f; Cue.transform.localScale = Vector3.one; resetTrigger = true; } } else { Debug.Log("Strange item found in Cues list."); } if (HUDCalibration) { //Keep all cues visible and reset to default positions Cue.SetActive(true); if (Cue.name == "HUD Cue East") { Cue.transform.localPosition = new Vector3(0.5f - 0.05f, Cue.transform.localPosition.y, Cue.transform.localPosition.z); } else if (Cue.name == "HUD Cue South") { Cue.transform.localPosition = new Vector3(Cue.transform.localPosition.x, -0.5f + 0.05f, Cue.transform.localPosition.z); } else if (Cue.name == "HUD Cue West") { Cue.transform.localPosition = new Vector3(-0.5f + 0.05f, Cue.transform.localPosition.y, Cue.transform.localPosition.z); } else if (Cue.name == "HUD Cue North") { Cue.transform.localPosition = new Vector3(Cue.transform.localPosition.x, 0.5f - 0.05f, Cue.transform.localPosition.z); } } else { foreach (ObstInfo obst in ObstInfos) { //Check whether the obstacle is behind the user bool isFront = true; var heading = Vector3.Normalize(obst.ObstObject.transform.position - Camera.main.transform.position); float dot = Vector3.Dot(heading, Camera.main.transform.forward); if (dot < 0) { isFront = false; } //Debug.Log("Dot for " + obst.ObstName + ": " + (Mathf.Round(dot * 100))/100); //Check that absolute value of X or Y exceed the min angle, and that it's not behind the user if ((obst.ObstMinAbsX > minAngle || obst.ObstMinAbsY > minAngle) && isFront) { //Check for each HUD cue portion whether or not to light up. Set cue multiplier based on closest object. if (Cue.name == "HUD Cue East" && obst.ObstMinY > minAngle && !(obst.ObstMaxY < minAngle * -1)) //&& obst.ObstMinAbsX <= minAngle) { Cue.SetActive(true); if (resetTrigger) { eastTrigger = Time.time; } eastMultiplier = 1.0f; float tempMultiplier = CalculateCueMultiplier(cueWidthMaxMultiplier, minDist, maxDist, obst.ObstMinDist); if (tempMultiplier >= eastMultiplier) { eastMultiplier = tempMultiplier; Cue.transform.localScale = new Vector3(Vector3.one.x * eastMultiplier, Cue.transform.localScale.y, Cue.transform.localScale.z); Cue.transform.localPosition = new Vector3(0.5f - 0.05f * eastMultiplier, Cue.transform.localPosition.y, Cue.transform.localPosition.z); } if (debugText.activeSelf) { debugText.GetComponent <TextMeshProUGUI>().text += "\nEast Cue width multiplier: " + Mathf.Round(eastMultiplier * 100) / 100; } } else if (Cue.name == "HUD Cue South" && obst.ObstMinX > minAngle && !(obst.ObstMaxX < minAngle * -1)) //&& obst.ObstMinAbsY <= minAngle) { Cue.SetActive(true); if (resetTrigger) { southTrigger = Time.time; } southMultiplier = 1.0f; float tempMultiplier = CalculateCueMultiplier(cueWidthMaxMultiplier, minDist, maxDist, obst.ObstMinDist); if (tempMultiplier >= southMultiplier) { southMultiplier = tempMultiplier; Cue.transform.localScale = new Vector3(Vector3.one.x * southMultiplier, Cue.transform.localScale.y, Cue.transform.localScale.z); Cue.transform.localPosition = new Vector3(Cue.transform.localPosition.x, -0.5f + 0.05f * southMultiplier, Cue.transform.localPosition.z); //Debug.Log("South cue on. Width multiplier: " + cueMultiplier); } if (debugText.activeSelf) { debugText.GetComponent <TextMeshProUGUI>().text += "\nSouth Cue width multiplier: " + Mathf.Round(southMultiplier * 100) / 100; } } else if (Cue.name == "HUD Cue West" && obst.ObstMaxY < minAngle * -1 && !(obst.ObstMinY > minAngle)) //&& obst.ObstMinAbsX <= minAngle) { Cue.SetActive(true); if (resetTrigger) { westTrigger = Time.time; } westMultiplier = 1.0f; float tempMultiplier = CalculateCueMultiplier(cueWidthMaxMultiplier, minDist, maxDist, obst.ObstMinDist); if (tempMultiplier >= westMultiplier) { westMultiplier = tempMultiplier; Cue.transform.localScale = new Vector3(Vector3.one.x * westMultiplier, Cue.transform.localScale.y, Cue.transform.localScale.z); Cue.transform.localPosition = new Vector3(-0.5f + 0.05f * westMultiplier, Cue.transform.localPosition.y, Cue.transform.localPosition.z); //Debug.Log("West cue on. Width multiplier: " + cueMultiplier); } if (debugText.activeSelf) { debugText.GetComponent <TextMeshProUGUI>().text += "\nWest Cue width multiplier: " + Mathf.Round(westMultiplier * 100) / 100; } } else if (Cue.name == "HUD Cue North" && obst.ObstMaxX < minAngle * -1 && !(obst.ObstMinX > minAngle)) //&& obst.ObstMinAbsY <= minAngle) { Cue.SetActive(true); if (resetTrigger) { northTrigger = Time.time; } northMultiplier = 1.0f; float tempMultiplier = CalculateCueMultiplier(cueWidthMaxMultiplier, minDist, maxDist, obst.ObstMinDist); if (tempMultiplier >= northMultiplier) { northMultiplier = tempMultiplier; Cue.transform.localScale = new Vector3(Vector3.one.x * northMultiplier, Cue.transform.localScale.y, Cue.transform.localScale.z); Cue.transform.localPosition = new Vector3(Cue.transform.localPosition.x, 0.5f - 0.05f * northMultiplier, Cue.transform.localPosition.z); //Debug.Log("North cue on. Width multiplier: " + cueMultiplier); } if (debugText.activeSelf) { debugText.GetComponent <TextMeshProUGUI>().text += "\nNorth Cue width multiplier: " + Mathf.Round(northMultiplier * 100) / 100; } } } } } } }
public void ActivateHUD() { //Assesses which cues should be illuminated and their appropriate size //Determine closest obstacle within acceptable distance in front of the user as the target obstacle float closestDist = 1000f; ObstInfo targetObst = null; foreach (ObstInfo obst in ObstInfos) { if (obst.IsFront) { if (obst.ObstMinDist < closestDist && obst.ObstMinDist <= maxDist) { targetObst = obst; closestDist = obst.ObstMinDist; } } } //If calibration mode is on, keep all cues visible and reset to default positions and sizes if (HUDCalibration) { cueSizeMultiplier = 1.0f; foreach (GameObject Cue in HUDCues) { Cue.SetActive(true); Cue.transform.localScale = Vector3.one; } HUD_East.transform.localPosition = new Vector3(0.5f - 0.05f, HUD_East.transform.localPosition.y, HUD_East.transform.localPosition.z); HUD_South.transform.localPosition = new Vector3(HUD_South.transform.localPosition.x, -0.5f + 0.05f, HUD_South.transform.localPosition.z); HUD_West.transform.localPosition = new Vector3(-0.5f + 0.05f, HUD_West.transform.localPosition.y, HUD_West.transform.localPosition.z); HUD_North.transform.localPosition = new Vector3(HUD_North.transform.localPosition.x, 0.5f - 0.05f, HUD_North.transform.localPosition.z); } //Reset and turn off all cues else { cueSizeMultiplier = 1.0f; foreach (GameObject Cue in HUDCues) { Cue.SetActive(false); Cue.transform.localScale = Vector3.one; } HUD_East.transform.localPosition = new Vector3(0.5f - 0.05f, HUD_East.transform.localPosition.y, HUD_East.transform.localPosition.z); HUD_South.transform.localPosition = new Vector3(HUD_South.transform.localPosition.x, -0.5f + 0.05f, HUD_South.transform.localPosition.z); HUD_West.transform.localPosition = new Vector3(-0.5f + 0.05f, HUD_West.transform.localPosition.y, HUD_West.transform.localPosition.z); HUD_North.transform.localPosition = new Vector3(HUD_North.transform.localPosition.x, 0.5f - 0.05f, HUD_North.transform.localPosition.z); } //If no target obstacle, do nothing if (targetObst == null) { Debug.Log("No valid targets."); } else //Turn on and resize cues for current obstacle { cueSizeMultiplier = CalculateCueMultiplier(cueWidthMaxMultiplier, minDist, maxDist, targetObst.ObstMinDist); if (targetObst.ObstXmin >= HUDThreshold) //Turn on right HUD { GameObject Cue = HUD_East; Cue.SetActive(true); Cue.transform.localScale = new Vector3(Vector3.one.x * cueSizeMultiplier, Cue.transform.localScale.y, Cue.transform.localScale.z); Cue.transform.localPosition = new Vector3(0.5f - 0.05f * cueSizeMultiplier, Cue.transform.localPosition.y, Cue.transform.localPosition.z); } if (targetObst.ObstXmax <= -1 * HUDThreshold) //Turn on left HUD { GameObject Cue = HUD_West; Cue.SetActive(true); Cue.transform.localScale = new Vector3(Vector3.one.x * cueSizeMultiplier, Cue.transform.localScale.y, Cue.transform.localScale.z); Cue.transform.localPosition = new Vector3(-0.5f + 0.05f * cueSizeMultiplier, Cue.transform.localPosition.y, Cue.transform.localPosition.z); } if (targetObst.ObstYmin >= HUDThreshold * HUDTopMultiplier) //Turn on top HUD. Modified by HUD Top Multiplier. { GameObject Cue = HUD_North; Cue.SetActive(true); Cue.transform.localScale = new Vector3(Vector3.one.x * cueSizeMultiplier, Cue.transform.localScale.y, Cue.transform.localScale.z); Cue.transform.localPosition = new Vector3(Cue.transform.localPosition.x, 0.5f - 0.05f * cueSizeMultiplier, Cue.transform.localPosition.z); } else if (targetObst.ObstYmax <= -1 * HUDThreshold) //Turn on bottom HUD { GameObject Cue = HUD_South; Cue.SetActive(true); Cue.transform.localScale = new Vector3(Vector3.one.x * cueSizeMultiplier, Cue.transform.localScale.y, Cue.transform.localScale.z); Cue.transform.localPosition = new Vector3(Cue.transform.localPosition.x, -0.5f + 0.05f * cueSizeMultiplier, Cue.transform.localPosition.z); } //Debug.Log("Target obstacle: " + targetObst.ObstName); if (debugText.activeSelf) { debugText.GetComponent <TextMeshProUGUI>().text += "\nTarget obstacle: " + targetObst.ObstName.ToString() + "\nDistance: " + Mathf.Round(100 * targetObst.ObstMinDist) / 100 + "\nCue Size Multiplier: " + Mathf.Round(100 * cueSizeMultiplier) / 100 + "\nMin and max angle: " + Mathf.Round(targetObst.ObstAngleMin) + ", " + Mathf.Round(targetObst.ObstAngleMax) + "\nMin and max X factor: " + Mathf.Round(100 * targetObst.ObstXmin) / 100 + ", " + Mathf.Round(100 * targetObst.ObstXmax) / 100 + "\nMin and max Y factor: " + Mathf.Round(100 * targetObst.ObstYmin) / 100 + ", " + Mathf.Round(100 * targetObst.ObstYmax) / 100; } } }