public ViveSR_StaticColliderInfo GetFurthestColliderWithProps(Vector3 testPos, uint[] props) { _GetAllColliderHasProps_Internal(props); // get filtered info in tempList int found_id = -1; float max_dist = float.MinValue; for (int i = 0; i < _tempList.Count; i++) { ViveSR_StaticColliderInfo info = _tempList[i]; float dist = Vector3.Distance(info.GetComponent <MeshRenderer>().bounds.center, testPos); if (dist > max_dist) { max_dist = dist; found_id = i; } } return((found_id == -1) ? null : _tempList[found_id]); }
public void GetColliderUsableLocationsWithRightAxis(float intervalW, float intervalH, float surf_shift, List <Vector3> outLocations, out Quaternion rotation, ref Vector3 rightVec) { outLocations.Clear(); rotation = new Quaternion(); ViveSR_StaticColliderInfo bb_cldInfo = GetCorrespondingColliderOfType(ColliderShapeType.BOUND_RECT_SHAPE); if (bb_cldInfo != null) { // Get collider axes Vector3 bb_center = bb_cldInfo.GetComponent <MeshRenderer>().bounds.center; Vector3 up = bb_cldInfo.GroupNormal; Vector3 forward = Vector3.Cross(rightVec, up); forward.Normalize(); rightVec = Vector3.Cross(up, forward); rightVec.Normalize(); float bb_width = bb_cldInfo.RectWidth; float bb_height = bb_cldInfo.RectHeight; // return rotation rotation.SetLookRotation(forward, up); // Calculate new range new_height = new_width = Mathf.Sqrt(Mathf.Pow(bb_height, 2) + Mathf.Pow(bb_width, 2)); // Check if collider exists in each position by Raycast for (float j = -new_height / 2 + intervalH / 2; j <= new_height / 2; j += intervalH) { for (float i = -new_width / 2 + intervalW / 2; i <= new_width / 2; i += intervalW) { Vector3 pos = bb_center + rightVec * i + forward * j; Vector3 pos_raycast = pos + up * 0.1f; RaycastHit hit; Physics.Raycast(pos_raycast, -up, out hit); if (hit.collider != null && hit.collider.gameObject.name == this.gameObject.name) { outLocations.Add(pos + up * surf_shift); } } } } }
// get colliders within customized height range public ViveSR_StaticColliderInfo[] GetColliderByHeightRange(ColliderShapeType shapeType, float lowestHeight, float highestHeight) { _tempList.Clear(); if (lowestHeight <= highestHeight) { for (int i = 0; i < allColliders.Count; i++) { ViveSR_StaticColliderInfo info = allColliders[i]; if (info.CheckHasAllBit((uint)shapeType)) { Vector3 center = info.GetComponent <MeshRenderer>().bounds.center; if (center.y >= lowestHeight && center.y <= highestHeight) { _tempList.Add(info); } } } } return(_tempList.ToArray()); }