public Corner(CornerId x, int y) { _pos = x; _ori = y%3; if (_ori < 0) _ori += 3; }
} //Empty constructor //Creates a new collider corner by copying an existing one public ColliderCorner(ColliderCorner cc) { cornerLocation = cc.cornerLocation; normalizedCornerLocation = cc.normalizedCornerLocation; localPos = cc.localPos; axleRadii = cc.axleRadii; radiusOffsets = cc.radiusOffsets; }
public Corner(CornerId x) { _pos = x; _ori = 0; }
public Corner() { _pos = 0; _ori = 0; }
//Sets the corner location based on its local position; does not work if local position is zero on any axis public void SetCornerLocationFromPosition() { if (Math.Sign(localPos.x) == 0 || Math.Sign(localPos.y) == 0 || Math.Sign(localPos.z) == 0) { Debug.LogWarning("Corner location cannot be identified because at least one component of the local position is zero."); return; } //Basic nested switch statements are satisfactory, using the sign of the local position on each axis switch ((int)Mathf.Sign(localPos.z)) { case 1: switch ((int)Mathf.Sign(localPos.y)) { case 1: switch ((int)Mathf.Sign(localPos.x)) { case 1: cornerLocation = CornerId.FrontTopRight; normalizedCornerLocation = Vector3.one; break; case -1: cornerLocation = CornerId.FrontTopLeft; normalizedCornerLocation.Set(-1.0f, 1.0f, 1.0f); break; } break; case -1: switch ((int)Mathf.Sign(localPos.x)) { case 1: cornerLocation = CornerId.FrontBottomRight; normalizedCornerLocation.Set(1.0f, -1.0f, 1.0f); break; case -1: cornerLocation = CornerId.FrontBottomLeft; normalizedCornerLocation.Set(-1.0f, -1.0f, 1.0f); break; } break; } break; case -1: switch ((int)Mathf.Sign(localPos.y)) { case 1: switch ((int)Mathf.Sign(localPos.x)) { case 1: cornerLocation = CornerId.BackTopRight; normalizedCornerLocation.Set(1.0f, 1.0f, -1.0f); break; case -1: cornerLocation = CornerId.BackTopLeft; normalizedCornerLocation.Set(-1.0f, 1.0f, -1.0f); break; } break; case -1: switch ((int)Mathf.Sign(localPos.x)) { case 1: cornerLocation = CornerId.BackBottomRight; normalizedCornerLocation.Set(1.0f, -1.0f, -1.0f); break; case -1: cornerLocation = CornerId.BackBottomLeft; normalizedCornerLocation = -Vector3.one; break; } break; } break; } }