//Handles scaling of UI tools for different room sizes void Position3DUI() { ToolContainer = GameObject.Find("ToolContainer").transform; foreach (var wc in FindObjectsOfType <WandController>()) { wc.DrawingControlContainer = ToolContainer; } //Shelves = GameObject.Find("ControlContainer").transform; Valve.VR.HmdQuad_t roomDims = new Valve.VR.HmdQuad_t(); SteamVR_PlayArea.GetBounds(SteamVR_PlayArea.Size.Calibrated, ref roomDims); RoomScale = new Vector3(Mathf.Abs(roomDims.vCorners0.v0 - roomDims.vCorners2.v0), Mathf.Abs(roomDims.vCorners0.v2 - roomDims.vCorners2.v2), 1); if (false)//RoomScale.x < 0.1f && RoomScale.y < 0.1f) { // Destroy(GameObject.Find("ToolContainer")); //Destroy(GameObject.Find("ControlContainer")); ToolContainer.Translate(-0.5f * 3, 0, 0); Shelves.Translate(0, 0, 0.5f * 3); } else { ToolContainer.Translate(-0.5f * RoomScale.x, 0, 0); //Shelves.Translate(0, 0, 0.5f * RoomScale.y); } }
void ScaleToPlayArea() { var rect = new Valve.VR.HmdQuad_t(); SteamVR_PlayArea.GetBounds(SteamVR_PlayArea.Size.Calibrated, ref rect); transform.localScale = new Vector3(Mathf.Abs(rect.vCorners0.v0 - rect.vCorners2.v0), transform.localScale.y, transform.localScale.z); }
void Start() { var rect = new HmdQuad_t(); SteamVR_PlayArea.GetBounds(SteamVR_PlayArea.Size.Calibrated, ref rect); corner1.x = rect.vCorners0.v0; corner1.y = rect.vCorners0.v1; corner1.z = rect.vCorners0.v2; corner2.x = rect.vCorners1.v0; corner2.y = rect.vCorners1.v1; corner2.z = rect.vCorners1.v2; corner3.x = rect.vCorners2.v0; corner3.y = rect.vCorners2.v1; corner3.z = rect.vCorners2.v2; corner4.x = rect.vCorners3.v0; corner4.y = rect.vCorners3.v1; corner4.z = rect.vCorners3.v2; bot = getmidPoint(corner1, corner2); top = getmidPoint(corner3, corner4); left = getmidPoint(corner2, corner3); right = getmidPoint(corner1, corner4); roomInitialization(); //creates the first room, namely the starter room createRoom("1"); }
/** * Funkcia pre vypocet faktoru - ak nieje build premenna USE_STEAMVR definovana, vrati 1 (bez zmeny scale) * pre build so SteamVR vypocita scale faktor nasledovne: * spocita 4 body pre x a pre z suradnice z hracej plochy hraca a vydeli 2 (pretoze obdlznik ma 4 vrcholi a pre zistenie * velkosti steny nam staci spocitat 2 (len nevieme ktore)) * * nasledne vezme minimum z velkosti x a z suradnice a to je nas faktor (aby sa scena zmestila na hraciu plochu) * */ public static float GetFactor() { #if USE_STEAMVR var rect = new HmdQuad_t(); if (SteamVR_PlayArea.GetBounds(SteamVR_PlayArea.Size.Calibrated, ref rect)) { float countx = Mathf.Abs(convertValveVector(rect.vCorners0).x) + Mathf.Abs(convertValveVector(rect.vCorners1).x) + Mathf.Abs(convertValveVector(rect.vCorners2).x) + Mathf.Abs(convertValveVector(rect.vCorners3).x); float countz = Mathf.Abs(convertValveVector(rect.vCorners0).z) + Mathf.Abs(convertValveVector(rect.vCorners1).z) + Mathf.Abs(convertValveVector(rect.vCorners2).z) + Mathf.Abs(convertValveVector(rect.vCorners3).z); // Debug.Log("Counting scaleFactor; sum: x=" + (countx / 2) / optimalPlayAreaSize.x + ", y=" + (countz / 2) / optimalPlayAreaSize.z); return(Mathf.Min((countx / 2) / optimalPlayAreaSize.x, (countz / 2) / optimalPlayAreaSize.z)); } else { return(1f); } #else return(1f); #endif }
// Use this for initialization void Start() { var rect = new HmdQuad_t(); if (!SteamVR_PlayArea.GetBounds(SteamVR_PlayArea.Size.Calibrated, ref rect)) { return; } // Could do without that var cornersVR = new HmdVector3_t[] { rect.vCorners0, rect.vCorners1, rect.vCorners2, rect.vCorners3 }; corners = new Vector3[cornersVR.Length]; for (int i = 0; i < cornersVR.Length; i++) { var c = cornersVR[i]; corners[i] = new Vector3(c.v0, 0.01f, c.v2); } // Make sure this is always the case minX = -Mathf.Abs(corners[0].x); maxX = Mathf.Abs(corners[0].x); minZ = -Mathf.Abs(corners[0].z); maxZ = Mathf.Abs(corners[0].z); music = transform.GetComponent <AudioSource>(); mixer = music.outputAudioMixerGroup.audioMixer; // Debugging text = GetComponentInChildren <TextMesh>(); }
bool CheckDespawn() { if (myState == RespawnObjectState.Valid) { //Turn off myself. Valve.VR.HmdQuad_t quad = new Valve.VR.HmdQuad_t(); SteamVR_PlayArea.GetBounds(SteamVR_PlayArea.Size.Calibrated, ref quad); //Debug.DrawLine(GetPoint(quad.vCorners0), Vector3.one, Color.red, 5.0f); //Debug.DrawLine(GetPoint(quad.vCorners1), Vector3.one, Color.green, 5.0f); //Debug.DrawLine(GetPoint(quad.vCorners2), Vector3.one, Color.grey, 5.0f); //Debug.DrawLine(GetPoint(quad.vCorners3), Vector3.one, Color.yellow, 5.0f); bool[] FarFromCorner = new bool[4]; float flatDistAway = 0; flatDistAway += FlatDistFrom(GetPoint(quad.vCorners0)); flatDistAway += FlatDistFrom(GetPoint(quad.vCorners1)); flatDistAway += FlatDistFrom(GetPoint(quad.vCorners2)); flatDistAway += FlatDistFrom(GetPoint(quad.vCorners3)); //failCount += Convert.ToInt32(FlatDistFrom(GetPoint(quad.vCorners0)) > ResetAtDistFromBounds); //failCount += Convert.ToInt32(FlatDistFrom(GetPoint(quad.vCorners1)) > ResetAtDistFromBounds); //failCount += Convert.ToInt32(FlatDistFrom(GetPoint(quad.vCorners2)) > ResetAtDistFromBounds); //failCount += Convert.ToInt32(FlatDistFrom(GetPoint(quad.vCorners3)) > ResetAtDistFromBounds); //Debug.Log(failCount + "\n"); if (flatDistAway >= 13) { return(true); } } return(false); }
// Use this for initialization void Start() { SteamVR_PlayArea playAreaScript = VRCamera.GetComponent <SteamVR_PlayArea>(); Valve.VR.HmdQuad_t quad = new Valve.VR.HmdQuad_t(); SteamVR_PlayArea.GetBounds(playAreaScript.size, ref quad); // Calc width of room float sizeX = quad.vCorners0.v0 - quad.vCorners3.v0; float sizeZ = quad.vCorners0.v2 - quad.vCorners2.v2; Debug.Log(sizeX); Debug.Log(sizeZ); //Instantiate(box, new Vector3(quad.vCorners0.v0, quad.vCorners0.v1, quad.vCorners0.v2), Quaternion.identity); //Instantiate(box, new Vector3(quad.vCorners1.v0, quad.vCorners1.v1, quad.vCorners1.v2), Quaternion.identity); //Instantiate(box, new Vector3(quad.vCorners2.v0, quad.vCorners2.v1, quad.vCorners2.v2), Quaternion.identity); //Instantiate(box, new Vector3(quad.vCorners3.v0, quad.vCorners3.v1, quad.vCorners3.v2), Quaternion.identity); Vector3 center = VRCamera.transform.position; /// Create the walls // Horizontal (along x axis), which means z varies Instantiate(Wall, new Vector3(0, 0, sizeZ), new Quaternion()); Instantiate(Wall, new Vector3(0, 0, -sizeZ), new Quaternion()); // Vertical (along z axis), which means 90 degree rotation and x varies //Instantiate(Wall, new Vector3(sizeX, 0, 0), new Quaternion()); //Instantiate(Wall, new Vector3(-sizeX, 0, 0), new Quaternion()); Instantiate(Wall, new Vector3(sizeX, 0, 0), Quaternion.Euler(0, 90, 0)); Instantiate(Wall, new Vector3(-sizeX, 0, 0), Quaternion.Euler(0, 90, 0)); //Vector3 FrontWallPosition = ; }
// Use this for initialization void Start() { rect = new Valve.VR.HmdQuad_t(); SteamVR_PlayArea.GetBounds(SteamVR_PlayArea.Size.Calibrated, ref rect); transform.localScale = new Vector3(Mathf.Abs(rect.vCorners0.v0 - rect.vCorners2.v0), floorThickness, Mathf.Abs(rect.vCorners0.v2 - rect.vCorners2.v2)); transform.position = new Vector3(0f, -floorThickness / 2f, 0f); }
void Awake() { Valve.VR.HmdQuad_t roomSize = new Valve.VR.HmdQuad_t(); SteamVR_PlayArea.GetBounds(SteamVR_PlayArea.Size.Calibrated, ref roomSize); Vector3 calibratedScale = transform.localScale; calibratedScale.x = Mathf.Abs(roomSize.vCorners0.v0 - roomSize.vCorners1.v0); calibratedScale.z = Mathf.Abs(roomSize.vCorners0.v2 - roomSize.vCorners3.v2); transform.localScale = calibratedScale; }
public void ApplyPlacement() { var rect = new HmdQuad_t(); if (SteamVR_PlayArea.GetBounds(SteamVR_PlayArea.Size.Calibrated, ref rect)) { var corners = new HmdVector3_t[] { rect.vCorners0, rect.vCorners1, rect.vCorners2, rect.vCorners3 }; Bounds playareaBounds = new Bounds(Vector3.zero, new Vector3(Mathf.Abs(corners[0].v0 - corners[1].v0), 0, Mathf.Abs(corners[0].v2 - corners[3].v2))); Vector3 closestPt = playareaBounds.ClosestPoint(playarea.InverseTransformPoint(transform.position)); transform.position = playarea.TransformPoint(closestPt); } }
/// <summary> /// Draws the gridlines based on the size of the play area provided by steam VR. /// </summary> void DrawGridlines() { if (SnapDistance == 0) { return; } ClearGridlines(); Valve.VR.HmdQuad_t roomDims = new Valve.VR.HmdQuad_t(); SteamVR_PlayArea.GetBounds(SteamVR_PlayArea.Size.Calibrated, ref roomDims); Vector3 RoomScale = new Vector3(Mathf.Abs(roomDims.vCorners0.v0 - roomDims.vCorners2.v0), Mathf.Abs(roomDims.vCorners0.v2 - roomDims.vCorners2.v2), 1); float roomWidth = RoomScale.x; float roomDepth = RoomScale.y; float height = 3; for (int i = -(int)((roomWidth / SnapDistance)); i <= (int)((roomWidth / SnapDistance)); i++) { for (int j = -(int)((height / SnapDistance)); j <= (int)((height / SnapDistance)); j++) { var gl = Instantiate(GridlinePrefab); var lr = gl.GetComponent <LineRenderer>(); lr.SetPosition(0, new Vector3(i * SnapDistance, j * SnapDistance, -roomDepth)); lr.SetPosition(1, new Vector3(i * SnapDistance, j * SnapDistance, roomDepth)); gl.transform.position = new Vector3(i * SnapDistance, j * SnapDistance, 0); Gridlines.Add(gl); } } for (int i = -(int)((roomDepth / SnapDistance)); i <= (int)((roomDepth / SnapDistance)); i++) { for (int j = -(int)((height / SnapDistance)); j <= (int)((height / SnapDistance)); j++) { var gl = Instantiate(GridlinePrefab); var lr = gl.GetComponent <LineRenderer>(); lr.SetPosition(0, new Vector3(-roomWidth, j * SnapDistance, i * SnapDistance)); lr.SetPosition(1, new Vector3(roomWidth, j * SnapDistance, i * SnapDistance)); gl.transform.position = new Vector3(0, j * SnapDistance, i * SnapDistance); Gridlines.Add(gl); } } for (int i = -(int)((roomWidth / SnapDistance)); i <= (int)((roomWidth / SnapDistance)); i++) { for (int j = -(int)((roomDepth / SnapDistance)); j <= (int)((roomDepth / SnapDistance)); j++) { var gl = Instantiate(GridlinePrefab); var lr = gl.GetComponent <LineRenderer>(); lr.SetPosition(0, new Vector3(i * SnapDistance, -height, j * SnapDistance)); lr.SetPosition(1, new Vector3(i * SnapDistance, height, j * SnapDistance)); gl.transform.position = new Vector3(i * SnapDistance, 0, j * SnapDistance); Gridlines.Add(gl); } } }
internal override Vector2 GetPlayAreaSize() { var rect = new Valve.VR.HmdQuad_t(); if (!SteamVR_PlayArea.GetBounds(SteamVR_PlayArea.Size.Calibrated, ref rect)) { return(Vector2.zero); } return(new Vector2(Mathf.Abs(rect.vCorners0.v0 - rect.vCorners2.v0), Mathf.Abs(rect.vCorners0.v2 - rect.vCorners2.v2))); }
private IEnumerator CorrectStartingAreaSteamVR() { yield return(null); var rect = new HmdQuad_t(); if (!SteamVR_PlayArea.GetBounds(SteamVR_PlayArea.Size.Calibrated, ref rect)) { Debug.LogError("Could not get the bounds of the play area!"); yield break; } float minX = Mathf.Min(rect.vCorners0.v0, rect.vCorners1.v0, rect.vCorners2.v0, rect.vCorners3.v0); float maxX = Mathf.Max(rect.vCorners0.v0, rect.vCorners1.v0, rect.vCorners2.v0, rect.vCorners3.v0); float minZ = Mathf.Min(rect.vCorners0.v2, rect.vCorners1.v2, rect.vCorners2.v2, rect.vCorners3.v2); float maxZ = Mathf.Max(rect.vCorners0.v2, rect.vCorners1.v2, rect.vCorners2.v2, rect.vCorners3.v2); var playerLocation = VRTK_DeviceFinder.HeadsetTransform().transform.position - sdkManager.transform.position; var sdkPosition = sdkManager.transform.position; if (playerLocation.XZ().magnitude < 0.5f) { sdkPosition += new Vector3(Mathf.Abs(playerLocation.x), 0, -Mathf.Abs(playerLocation.z)); } if (playerLocation.x >= 0) { if (playerLocation.z > 0) { sdkPosition.z -= playerLocation.z; } else { // Totally fine! } } else { sdkPosition.x -= playerLocation.x; if (playerLocation.z > 0) { sdkPosition.z -= playerLocation.z; } else { // Totally fine! } } sdkManager.transform.position = sdkPosition; }
IEnumerator SetPanelBounds() { Valve.VR.HmdQuad_t rect = new Valve.VR.HmdQuad_t(); while (!SteamVR_PlayArea.GetBounds(SteamVR_PlayArea.Size.Calibrated, ref rect)) { yield return(new WaitForSeconds(0.1f)); } Vector3 newScale = new Vector3(Mathf.Abs(rect.vCorners0.v0 - rect.vCorners2.v0), this.transform.localScale.y, Mathf.Abs(rect.vCorners0.v2 - rect.vCorners2.v2)); this.transform.localScale = newScale; }
private void Start() { //area. HmdQuad_t pRect = new HmdQuad_t(); if (SteamVR_PlayArea.GetBounds(SteamVR_PlayArea.Size.Calibrated, ref pRect) && cornerMarkers.Length == 4) { cornerMarkers[0].transform.position = new Vector3(pRect.vCorners0.v0, pRect.vCorners0.v1, pRect.vCorners0.v2); cornerMarkers[1].transform.position = new Vector3(pRect.vCorners1.v0, pRect.vCorners1.v1, pRect.vCorners1.v2); cornerMarkers[2].transform.position = new Vector3(pRect.vCorners2.v0, pRect.vCorners2.v1, pRect.vCorners2.v2); cornerMarkers[3].transform.position = new Vector3(pRect.vCorners3.v0, pRect.vCorners3.v1, pRect.vCorners3.v2); } }
private List <Vector3> GetVector3VerticesOfPlayArea() { HmdQuad_t quad = new HmdQuad_t(); SteamVR_PlayArea.GetBounds(playArea.size, ref quad); return(new List <Vector3>() { GetVector3FromHmdVector(quad.vCorners0), GetVector3FromHmdVector(quad.vCorners1), GetVector3FromHmdVector(quad.vCorners2), GetVector3FromHmdVector(quad.vCorners3) }); }
// This will resize the given object to match the player play area void Start() { var rect = new HmdQuad_t(); if (SteamVR_PlayArea.GetBounds(SteamVR_PlayArea.Size.Calibrated, ref rect)) { var corners = new HmdVector3_t[] { rect.vCorners0, rect.vCorners1, rect.vCorners2, rect.vCorners3 }; Vector3 scale = transform.localScale; var width = Mathf.Abs(corners[0].v0 - corners[1].v0) / meshWidth * scale.x; var length = Mathf.Abs(corners[0].v2 - corners[3].v2) / meshHeight * scale.y; scale.Set(length, width, scale.z); transform.localScale = scale; } }
private void checkAndUpdateBounds() { if (lastSize != steamVR_PlayArea.size) { bool success = SteamVR_PlayArea.GetBounds(steamVR_PlayArea.size, ref steamVrBounds); if (success) { lastSize = steamVR_PlayArea.size; } else { Debug.LogWarning("Could not get the Play Area bounds. " + steamVR_PlayArea.size); } } }
void Start() { if (vertices == null || vertices.Length == 0) { bool success = SteamVR_PlayArea.GetBounds(steamVR_PlayArea.size, ref steamVrBounds); if (success) { lastSize = steamVR_PlayArea.size; BuildMesh(); } else { Debug.LogWarning("Could not get the chaperon size. This may happen if you use the calibrated size."); } } }
void Start() { if (SteamVR_PlayArea.GetBounds(SteamVR_PlayArea.Size.Calibrated, ref area)) { Debug.Log("Calibrating Area"); Vector3 c0 = new Vector3(area.vCorners0.v0, area.vCorners0.v1, area.vCorners0.v2); Vector3 c1 = new Vector3(area.vCorners1.v0, area.vCorners1.v1, area.vCorners1.v2); Vector3 c2 = new Vector3(area.vCorners2.v0, area.vCorners2.v1, area.vCorners2.v2); Vector3 c3 = new Vector3(area.vCorners3.v0, area.vCorners3.v1, area.vCorners3.v2); // Instantiate(corner, c0, Quaternion.identity); // Instantiate(corner, c1, Quaternion.identity); float width = Mathf.Abs(c0.x - c1.x); goal.transform.localScale = new Vector3(width, goal.transform.localScale.y, goal.transform.localScale.z); // Instantiate(corner, c2, Quaternion.identity); // Instantiate(corner, c3, Quaternion.identity); } StartRound(); }
void ScaleToPlayArea() { var rect = new HmdQuad_t(); if (!SteamVR_PlayArea.GetBounds(steamVR_PlayArea.size, ref rect)) { return; } Vector3 average = Vector3.zero; foreach (var corner in new HmdVector3_t[] { rect.vCorners0, rect.vCorners1, rect.vCorners2, rect.vCorners3 }) { average += new Vector3(corner.v0, corner.v1, corner.v2); } average /= 4; transform.position = average; Debug.Log("Moved '" + this.name + "' to the center of the SteamVR_PlayArea bounds."); }
void OnEnable() { steamVR_PlayArea = GameObject.FindObjectOfType <SteamVR_PlayArea>(); vrtk_RoomExtender = GameObject.FindObjectOfType <VRTK_RoomExtender>(); if (steamVR_PlayArea == null || vrtk_RoomExtender == null) { Debug.LogWarning("Could not find 'SteamVR_PlayArea' or 'VRTK_RoomExtender'. Please check if they are attached to the 'CameraRig'"); return; } bool success = SteamVR_PlayArea.GetBounds(steamVR_PlayArea.size, ref steamVrBounds); if (success) { lastSize = steamVR_PlayArea.size; BuildMesh(); } else { Debug.LogWarning("Could not get the Calibrated Play Area bounds. This script 'RoomExtender_PlayArea' tries to get the size when SteamVR is running."); } }
IEnumerator getPlayArea() { var rect = new Valve.VR.HmdQuad_t(); while (!SteamVR_PlayArea.GetBounds(SteamVR_PlayArea.Size.Calibrated, ref rect)) { yield return(new WaitForSeconds(1f)); } Vector3 newScale = new Vector3(Mathf.Abs(rect.vCorners0.v0 - rect.vCorners2.v0), this.transform.localScale.y, Mathf.Abs(rect.vCorners0.v2 - rect.vCorners2.v2)); if (false) { Debug.Log("Quad Ecke0 x:" + rect.vCorners0.v0 + " y: " + rect.vCorners0.v1 + " z: " + rect.vCorners0.v2); Debug.Log("Quad Ecke1 x:" + rect.vCorners1.v0 + " y: " + rect.vCorners1.v1 + " z: " + rect.vCorners1.v2); Debug.Log("Quad Ecke2 x:" + rect.vCorners2.v0 + " y: " + rect.vCorners2.v1 + " z: " + rect.vCorners2.v2); Debug.Log("Quad Ecke3 x:" + rect.vCorners3.v0 + " y: " + rect.vCorners3.v1 + " z: " + rect.vCorners3.v2); Debug.Log("New Scale would be x:" + newScale.x + " y: " + newScale.y + " z:" + newScale.z); } playAreaX = newScale.x; playAreaY = newScale.z; }
void pointToEdge(SteamVR_PlayArea playArea, GainsZone gainsZone, Transform player, Direction direction) { HmdQuad_t rect = new HmdQuad_t(); SteamVR_PlayArea.GetBounds(playArea.size, ref rect); float width = Mathf.Abs(rect.vCorners0.v0 - rect.vCorners2.v0); float length = Mathf.Abs(rect.vCorners0.v2 - rect.vCorners2.v2); switch (direction) { case Direction.PosX: float posXVirtual = (gainsZone.Trans.position.x - player.position.x) + gainsZone.Size.x / 2; float posXReal = width / 2 - player.localPosition.x; PosX = posXVirtual / posXReal; break; case Direction.NegX: float negXVirtual = (gainsZone.Trans.position.x - player.position.x) * -1 + gainsZone.Size.x / 2; float negXReal = width / 2 + player.localPosition.x; NegX = negXVirtual / negXReal; break; case Direction.PosZ: float posZVirtual = (gainsZone.Trans.position.z - player.position.z) + gainsZone.Size.z / 2; float posZReal = length / 2 - player.localPosition.z; PosZ = posZVirtual / posZReal; break; case Direction.NegZ: float negZVirtual = (gainsZone.Trans.position.z - player.position.z) * -1 + gainsZone.Size.z / 2; float negZReal = length / 2 + player.localPosition.z; NegZ = negZVirtual / negZReal; break; default: break; } }
private IEnumerator CorrectStartingAreaSteamVR() { yield return(null); var rect = new HmdQuad_t(); if (!SteamVR_PlayArea.GetBounds(SteamVR_PlayArea.Size.Calibrated, ref rect)) { Debug.LogError("Could not get the bounds of the play area!"); headsetEat.enabled = true; yield break; } float minX = Mathf.Min(rect.vCorners0.v0, rect.vCorners1.v0, rect.vCorners2.v0, rect.vCorners3.v0); float maxX = Mathf.Max(rect.vCorners0.v0, rect.vCorners1.v0, rect.vCorners2.v0, rect.vCorners3.v0); float minZ = Mathf.Min(rect.vCorners0.v2, rect.vCorners1.v2, rect.vCorners2.v2, rect.vCorners3.v2); float maxZ = Mathf.Max(rect.vCorners0.v2, rect.vCorners1.v2, rect.vCorners2.v2, rect.vCorners3.v2); float centreX = (maxX + minX) / 2; var playerLocation = VRTK_DeviceFinder.HeadsetTransform().transform.position - sdkManager.transform.position; beforeCheck?.Invoke(); if (playerLocation.x < centreX) { sdkManager.transform.rotation = Quaternion.Euler(0, 180, 0); Debug.Log("Rotating play area!"); } if (startingPoint) { startingPoint.DoTeleport(); } afterCheck?.Invoke(); headsetEat.enabled = true; }
public void resizePlatform() { var rect = new HmdQuad_t(); if (!SteamVR_PlayArea.GetBounds(SteamVR_PlayArea.Size.Calibrated, ref rect)) { Debug.LogError("VRACMAN ERROR: Failed to get Calibrated Play Area bounds! Make sure you have tracking first, and that your space is calibrated."); return; } var corners = new HmdVector3_t[] { rect.vCorners0, rect.vCorners1, rect.vCorners2, rect.vCorners3 }; Vector3 chapScale = transform.localScale; chapScale.x = Mathf.Abs(corners[0].v0 - corners[1].v0) / 10; chapScale.z = Mathf.Abs(corners[0].v2 - corners[3].v2) / 10; transform.localScale = chapScale; Platform.transform.localScale = chapScale; bounds = Platform.GetComponentInChildren <MeshFilter>().mesh.bounds; minx = bounds.min.x; maxx = bounds.max.x; miny = bounds.min.y; minz = bounds.min.z; maxz = bounds.max.z; }
public void ShowShelf(bool show) { if (!show) { BurstBubble(); StartCoroutine(DelayHideShelf()); } else { mGadgetShelf.SetActive(show); mGadgetShelf.GetComponent <AudioSource>().Play(); Transform myCamera = GameManager.Instance.MainCamera.transform; Vector3 pureCameraRotation = myCamera.rotation.eulerAngles; // Get play area size Valve.VR.HmdQuad_t roomSize = new Valve.VR.HmdQuad_t(); Vector3 offset = Vector3.zero; if (SteamVR_PlayArea.GetBounds(SteamVR_PlayArea.Size.Calibrated, ref roomSize)) { Valve.VR.HmdVector3_t[] roomCorners = new Valve.VR.HmdVector3_t[] { roomSize.vCorners0, roomSize.vCorners1, roomSize.vCorners2, roomSize.vCorners3 }; Vector3[] cornerPositions = new Vector3[roomCorners.Length]; for (int i = 0; i < roomCorners.Length; i++) { cornerPositions[i] = new Vector3(roomCorners[i].v0, roomCorners[i].v1, roomCorners[i].v2); } // Get two corners float minX = 0.0f; float minZ = 0.0f; float maxX = 0.0f; float maxZ = 0.0f; for (int i = 0; i < cornerPositions.Length; i++) { minX = Math.Min(minX, cornerPositions[i].x); maxX = Math.Max(maxX, cornerPositions[i].x); minZ = Math.Min(minZ, cornerPositions[i].z); maxZ = Math.Max(maxZ, cornerPositions[i].z); } // Calculate the shelf's position Vector3 shelfPosition = myCamera.position + myCamera.forward * shelfRadius; if (shelfPosition.x < 0 && shelfPosition.x < minX) { offset += new Vector3(minX - shelfPosition.x, 0, 0); } else if (shelfPosition.x > 0 && shelfPosition.x > maxX) { offset -= new Vector3(shelfPosition.x - maxX, 0, 0); } if (shelfPosition.z < 0 && shelfPosition.z < minZ) { offset += new Vector3(0, 0, minZ - shelfPosition.z); } else if (shelfPosition.z > 0 && shelfPosition.z > maxZ) { offset -= new Vector3(0, 0, shelfPosition.z - maxZ); } } mGadgetShelf.transform.position = myCamera.position + offset; mGadgetShelf.transform.rotation = Quaternion.Euler(0.0f, myCamera.rotation.eulerAngles.y - 90.0f, 0.0f); for (int i = 0; i < shelfGadgetContainersPositions.Length; i++) { StartCoroutine(ShiftContainer(i, shelfGadgetContainersPositions[i])); StartCoroutine(RotateGadget(i)); } for (int i = 0; i < NUM_SAVE_SLOTS; i++) { StartCoroutine(ShiftContainer(shelfGadgetContainersPositions.Length + i, shelfFileContainersPositions[i])); StartCoroutine(RotateGadget(shelfGadgetContainersPositions.Length + i)); } } }
void calculateAnalytics() { //gonna need a better algorithm for more tools if (Valve.VR.OpenVR.IsHmdPresent()) { Valve.VR.HmdQuad_t roomDims = new Valve.VR.HmdQuad_t(); SteamVR_PlayArea.GetBounds(SteamVR_PlayArea.Size.Calibrated, ref roomDims); Vector3 roomScale = new Vector3(Mathf.Abs(roomDims.vCorners0.v0 - roomDims.vCorners2.v0), Mathf.Abs(roomDims.vCorners0.v2 - roomDims.vCorners2.v2), 1); roomWidth = roomScale.x; roomHeight = roomScale.y; } int mostToolNum = 0; float mostToolTimed = 0; foreach (KeyValuePair <string, ToolData> pair in toolMap) { if (pair.Value.Count > mostToolNum) { mostToolGrab = pair.Value.Name; mostToolNum = pair.Value.Count; } if (pair.Value.Time > mostToolTimed) { mostToolTime = pair.Value.Name; mostToolTimed = pair.Value.Time; } } string mostCommonPairLetters = MostCommonSubstring(); if (mostCommonPairLetters.Length == 2) { string firstTool = toolMap[mostCommonPairLetters[0].ToString()].Name; string secondTool = toolMap[mostCommonPairLetters[1].ToString()].Name; mostCommonToolPairs = firstTool + " to " + secondTool; } timeCamera = toolMap["A"].Time; numCamera = toolMap["A"].Count; timeBoolean = toolMap["B"].Time; numBoolean = toolMap["B"].Count; timeClone = toolMap["C"].Time; numClone = toolMap["C"].Count; timeDrawFace = toolMap["D"].Time; numDrawFace = toolMap["D"].Count; timeExtrude = toolMap["E"].Time; numExtrude = toolMap["E"].Count; timeLoft = toolMap["F"].Time; numLoft = toolMap["F"].Count; timeGroup = toolMap["G"].Time; numGroup = toolMap["G"].Count; timePrimitive = toolMap["I"].Time; numPrimitive = toolMap["I"].Count; timeClipping = toolMap["K"].Time; numClipping = toolMap["K"].Count; timeLine = toolMap["L"].Time; numLine = toolMap["L"].Count; timeMirror = toolMap["M"].Time; numMirror = toolMap["M"].Count; timeSelection = toolMap["N"].Time; numSelection = toolMap["N"].Count; timePolygon = toolMap["O"].Time; numPolygon = toolMap["O"].Count; timePaint = toolMap["P"].Time; numPaint = toolMap["P"].Count; timeEraser = toolMap["R"].Time; numEraser = toolMap["R"].Count; timeSpline = toolMap["S"].Time; numSpline = toolMap["S"].Count; timeGravity = toolMap["V"].Time; numGravity = toolMap["V"].Count; timeExtrudeCurve = toolMap["X"].Time; numExtrudeCurve = toolMap["X"].Count; timeMeasuring = toolMap["Z"].Time; numMeasuring = toolMap["Z"].Count; //here i get the most used shapes and sections // this can be done more efficiently List <int> shapeList = new List <int>(); List <int> sectionList = new List <int>(); shapeList.Add(numTriangle); shapeList.Add(numSquare); shapeList.Add(numCircle); sectionList.Add(numIsec); sectionList.Add(numCsec); sectionList.Add(numLsec); sectionList.Add(numTsec); int shapeNum = shapeList[0]; int shapeInd = 0; int secNum = sectionList[0]; int secInd = 0; for (int k = 0; k < shapeList.Count; k++) { if (shapeList[k] > shapeNum) { shapeNum = shapeList[k]; shapeInd = k; } } for (int l = 0; l < sectionList.Count; l++) { if (sectionList[l] > shapeNum) { secNum = sectionList[l]; secInd = l; } } if (shapeNum > 0) { switch (shapeInd) { case 0: commonShape = "Triangle"; break; case 1: commonShape = "Square"; break; case 2: commonShape = "Circle"; break; } } else { commonShape = "NONE"; } if (secNum > 0) { switch (secInd) { case 0: commonSection = "I Section"; break; case 1: commonSection = "C Section"; break; case 2: commonSection = "L Section"; break; case 3: commonSection = "T Section"; break; } } else { commonSection = "NONE"; } if (shapeNum > secNum) { shapeVsSection = "Shape"; } else if (secNum > shapeNum) { shapeVsSection = "Section"; } else if (secNum == shapeNum) { shapeVsSection = "Equal"; } float saveSum = 0; numSaves = saveSizes.Count; if (numSaves > 0) { for (int i = 0; i < numSaves; i++) { saveSum += saveSizes[i]; } avgSaveSize = saveSum / numSaves; } else { avgSaveSize = 0; } //for now, just get color average, not common colors - pretty innacurate float sumR = 0; float sumG = 0; float sumB = 0; for (int ci = 0; ci < colors.Count; ci++) { float r = colors[ci].r; float g = colors[ci].g; float b = colors[ci].b; sumR += r; sumG += g; sumB += b; } float avgR = sumR / colors.Count; float avgG = sumG / colors.Count; float avgB = sumB / colors.Count; avgR *= 255.0f; avgG *= 255.0f; avgB *= 255.0f; avgColor = "(" + avgR + "," + avgG + "," + avgB + ")"; if (heights.Count > 0) { userHeight = heights[heights.Count * 3 / 4]; } else { userHeight = 0; } userHeight *= 1.5f; maxPeople = maxActive + maxPassiveVR + maxPassiveController + maxTheatre; TrackerScript.AddAction("*"); }
void Awake() { resetDimensions(); // Remember the dimensions of the base: initialBaseWidth = rectBase.GetComponent <Renderer>().bounds.size.x; initialBaseDepth = rectBase.GetComponent <Renderer>().bounds.size.z; if (viveRig.activeInHierarchy) { // Default values: float width = 3f; float depth = 2f; // Try to get the room size from the mesh: SteamVR_PlayArea playArea = viveRig.GetComponent <SteamVR_PlayArea>(); if (playArea != null) { Valve.VR.HmdQuad_t rect = new Valve.VR.HmdQuad_t(); if (SteamVR_PlayArea.GetBounds(playArea.size, ref rect)) { var corners = new Valve.VR.HmdVector3_t[] { rect.vCorners0, rect.vCorners1, rect.vCorners2, rect.vCorners3 }; Vector2 min = new Vector2(float.MaxValue, float.MaxValue); Vector2 max = new Vector2(float.MinValue, float.MinValue); for (int i = 0; i < corners.Length; i++) { if (corners [i].v0 < min.x) { min.x = corners [i].v0; } if (corners [i].v2 < min.y) { min.y = corners [i].v2; } if (corners [i].v0 > max.x) { max.x = corners [i].v0; } if (corners [i].v2 > max.y) { max.y = corners [i].v2; } } Vector2 size = max - min; width = size.x; depth = size.y; } } /*Mesh roomMesh = viveRig.GetComponent<MeshFilter>().mesh; * if (roomMesh != null) { * width = roomMesh.bounds.size.x; * depth = roomMesh.bounds.size.z; * SteamVR_PlayArea playArea. * Debug.Log ("Room mesh found. Setting room size to " + width + "x" + depth + "m."); * }*/ setRectangular(width, depth); } else { setRounded(); } }
public void BuildMesh() { HmdQuad_t hmdQuad_t = default(HmdQuad_t); if (!SteamVR_PlayArea.GetBounds(this.size, ref hmdQuad_t)) { return; } HmdVector3_t[] array = new HmdVector3_t[] { hmdQuad_t.vCorners0, hmdQuad_t.vCorners1, hmdQuad_t.vCorners2, hmdQuad_t.vCorners3 }; this.vertices = new Vector3[array.Length * 2]; for (int i = 0; i < array.Length; i++) { HmdVector3_t hmdVector3_t = array[i]; this.vertices[i] = new Vector3(hmdVector3_t.v0, 0.01f, hmdVector3_t.v2); } if (this.borderThickness == 0f) { base.GetComponent <MeshFilter>().mesh = null; return; } for (int j = 0; j < array.Length; j++) { int num = (j + 1) % array.Length; int num2 = (j + array.Length - 1) % array.Length; Vector3 normalized = (this.vertices[num] - this.vertices[j]).normalized; Vector3 normalized2 = (this.vertices[num2] - this.vertices[j]).normalized; Vector3 vector = this.vertices[j]; vector += Vector3.Cross(normalized, Vector3.up) * this.borderThickness; vector += Vector3.Cross(normalized2, Vector3.down) * this.borderThickness; this.vertices[array.Length + j] = vector; } int[] triangles = new int[] { 0, 4, 1, 1, 4, 5, 1, 5, 2, 2, 5, 6, 2, 6, 3, 3, 6, 7, 3, 7, 0, 0, 7, 4 }; Vector2[] uv = new Vector2[] { new Vector2(0f, 0f), new Vector2(1f, 0f), new Vector2(0f, 0f), new Vector2(1f, 0f), new Vector2(0f, 1f), new Vector2(1f, 1f), new Vector2(0f, 1f), new Vector2(1f, 1f) }; Color[] colors = new Color[] { this.color, this.color, this.color, this.color, new Color(this.color.r, this.color.g, this.color.b, 0f), new Color(this.color.r, this.color.g, this.color.b, 0f), new Color(this.color.r, this.color.g, this.color.b, 0f), new Color(this.color.r, this.color.g, this.color.b, 0f) }; Mesh mesh = new Mesh(); base.GetComponent <MeshFilter>().mesh = mesh; mesh.vertices = this.vertices; mesh.uv = uv; mesh.colors = colors; mesh.triangles = triangles; MeshRenderer component = base.GetComponent <MeshRenderer>(); component.material = new Material(Shader.Find("Sprites/Default")); component.reflectionProbeUsage = ReflectionProbeUsage.Off; component.shadowCastingMode = ShadowCastingMode.Off; component.receiveShadows = false; component.lightProbeUsage = LightProbeUsage.Off; }