protected override void OnStateUpdate(DoorState prevState = new DoorState()) { float rotation = OrientationHelper.AngleBetween(Orientation.Horizontal, TileState.orientation); transform.localRotation = Quaternion.Euler(0, rotation, 0); UpdateWallCaps(); }
private void UpdateMeshAndDirection() { // Count number of connections along cardinal (which is all that we use atm) var generalCardinals = generalAdjacents.GetCardinalInfo(); float rotation = 0.0f; Mesh mesh; if (generalCardinals.IsO()) { mesh = o; } else if (generalCardinals.IsC()) { mesh = c; rotation = DirectionHelper.AngleBetween(Direction.North, generalCardinals.GetOnlyPositive()); } else if (generalCardinals.IsI()) { // Check for specific connections var specificCardinals = specificAdjacents.GetCardinalInfo(); if (specificCardinals.numConnections == 1) { mesh = iBorder; rotation = DirectionHelper.AngleBetween(Direction.South, specificCardinals.GetOnlyPositive()); } else { mesh = specificCardinals.numConnections == 2 ? i : iAlone; rotation = OrientationHelper.AngleBetween(Orientation.Vertical, generalCardinals.GetFirstOrientation()); } } else if (generalCardinals.IsL()) { mesh = l; rotation = DirectionHelper.AngleBetween(Direction.NorthEast, generalCardinals.GetCornerDirection()); } else if (generalCardinals.IsT()) { mesh = t; rotation = DirectionHelper.AngleBetween(Direction.South, generalCardinals.GetOnlyNegative()); } else { mesh = x; } if (filter == null) { filter = GetComponent <MeshFilter>(); } filter.mesh = mesh; transform.localRotation = Quaternion.Euler(transform.localRotation.eulerAngles.x, rotation, transform.localRotation.eulerAngles.z); }
private void UpdateMeshAndDirection() { // Count number of connections along cardinal (which is all that we use atm) var cardinalInfo = adjacents.GetCardinalInfo(); // Determine rotation and mesh specially for every single case. // TODO: add meshes mentioned in header to script float rotation = 0.0f; Mesh mesh; if (cardinalInfo.IsO()) { mesh = o; } else if (cardinalInfo.IsC()) { mesh = c; rotation = DirectionHelper.AngleBetween(Direction.North, cardinalInfo.GetOnlyPositive()); } else if (cardinalInfo.IsI()) { mesh = i; rotation = OrientationHelper.AngleBetween(Orientation.Vertical, cardinalInfo.GetFirstOrientation()); } else if (cardinalInfo.IsL()) { mesh = l; rotation = DirectionHelper.AngleBetween(Direction.NorthEast, cardinalInfo.GetCornerDirection()); } else if (cardinalInfo.IsT()) { mesh = t; rotation = DirectionHelper.AngleBetween(Direction.South, cardinalInfo.GetOnlyNegative()); } else // Must be X { mesh = xAll; } if (filter == null) { filter = GetComponent <MeshFilter>(); } filter.mesh = mesh; transform.localRotation = Quaternion.Euler(transform.localRotation.eulerAngles.x, rotation, transform.localRotation.eulerAngles.z); }
public float GetRotation() { var cardinalInfo = adjacents.GetCardinalInfo(); return(OrientationHelper.AngleBetween(Orientation.Vertical, cardinalInfo.GetFirstOrientation())); }
private void UpdateMeshAndDirection() { // Count number of connections along cardinal (which is all that we use atm) var cardinalInfo = adjacents.GetCardinalInfo(); // Determine rotation and mesh specially for every single case. float rotation = 0.0f; Mesh mesh; if (cardinalInfo.IsO()) { mesh = o; orientation = PipeOrientation.o; } else if (cardinalInfo.IsU()) { if (cardinalInfo.north > 0 || cardinalInfo.east > 0) { mesh = uNorth; orientation = PipeOrientation.uNorth; } else { mesh = uSouth; orientation = PipeOrientation.uSouth; } rotation = DirectionHelper.AngleBetween(Direction.North, cardinalInfo.GetOnlyPositive()); } else if (cardinalInfo.IsI()) { mesh = i; orientation = PipeOrientation.i; rotation = OrientationHelper.AngleBetween(Orientation.Vertical, cardinalInfo.GetFirstOrientation()); } else if (cardinalInfo.IsL()) { Direction sides = cardinalInfo.GetCornerDirection(); mesh = sides == Direction.NorthEast ? lNE : sides == Direction.SouthEast ? lSE : sides == Direction.SouthWest ? lSW : lNW; orientation = sides == Direction.NorthEast ? PipeOrientation.lNE : sides == Direction.SouthEast ? PipeOrientation.lSE : sides == Direction.SouthWest ? PipeOrientation.lSW : PipeOrientation.lNW; rotation = 90; } else if (cardinalInfo.IsT()) { Direction notside = cardinalInfo.GetOnlyNegative(); mesh = notside == Direction.North ? tSWE : notside == Direction.East ? tNSW : notside == Direction.South ? tNEW : tNSE; orientation = notside == Direction.North ? PipeOrientation.tSWE : notside == Direction.East ? PipeOrientation.tNSW : notside == Direction.South ? PipeOrientation.tNEW : PipeOrientation.tNSE; rotation = 90; } else // Must be X { mesh = x; orientation = PipeOrientation.x; rotation = 90; } if (filter == null) { filter = GetComponent <MeshFilter>(); } filter.mesh = mesh; transform.localRotation = Quaternion.Euler(transform.localRotation.eulerAngles.x, rotation, transform.localRotation.eulerAngles.z); }
/** * Sorry about the length, but each part is pretty well seperated, so it shouldn't be too difficult to * follow hopefully (-nonanon). * * This code takes the information about what tiles are adjacent (each of the 8 directions either has an adjacent connectable or not), * and converts this into the mesh to use, along with a direction to rotate the mesh in. */ private void UpdateMeshAndDirection() { // Count number of connections along cardinal, to determine which 'outer' mesh we use of O, C, I/L, T, X var generalCardinals = generalAdjacents.GetCardinalInfo(); float rotation = 0.0f; Mesh mesh; if (generalCardinals.IsO()) { mesh = o; } else if (generalCardinals.IsC()) { mesh = c; rotation = DirectionHelper.AngleBetween(Direction.East, generalCardinals.GetOnlyPositive()); } else if (generalCardinals.IsI()) { var specificCardinals = specificAdjacents.GetCardinalInfo(); if (specificCardinals.numConnections == 1) { mesh = iBorder; rotation = DirectionHelper.AngleBetween(Direction.West, specificCardinals.GetOnlyPositive()); } else { mesh = specificCardinals.numConnections == 2 ? i : iAlone; rotation = OrientationHelper.AngleBetween(Orientation.Horizontal, generalCardinals.GetFirstOrientation()); } } else if (generalCardinals.IsL()) { // Determine lSolid or lCorner by finding whether the area between the two connections is filled // We check for if any of the following bitfields matches the connection bitfield // N+NE+E = 0/1/2, E+SE+S = 2/3/4, S+SW+W = 4/5/6, W+NW+N = 6/7/0 bool isFilled = (generalAdjacents.Connections & 0b00000111) == 0b00000111 || (generalAdjacents.Connections & 0b00011100) == 0b00011100 || (generalAdjacents.Connections & 0b01110000) == 0b01110000 || (generalAdjacents.Connections & 0b11000001) == 0b11000001; mesh = isFilled ? lSingle : lNone; rotation = DirectionHelper.AngleBetween(Direction.SouthEast, generalCardinals.GetCornerDirection()); } else if (generalCardinals.IsT()) { // We make another bitfield (noticing a pattern?). 0x0 means no fills, 0x1 means right corner filled, 0x2 means left corner filled, // therefore both corners filled = 0x3. int corners = ((1 - generalCardinals.north) * 2 | (1 - generalCardinals.east)) * generalAdjacents.Adjacent(Direction.SouthWest) + ((1 - generalCardinals.east) * 2 | (1 - generalCardinals.south)) * generalAdjacents.Adjacent(Direction.NorthWest) + ((1 - generalCardinals.south) * 2 | (1 - generalCardinals.west)) * generalAdjacents.Adjacent(Direction.NorthEast) + ((1 - generalCardinals.west) * 2 | (1 - generalCardinals.north)) * generalAdjacents.Adjacent(Direction.SouthEast); mesh = corners == 0 ? tNone : corners == 1 ? tSingleLeft : corners == 2 ? tSingleRight : tDouble; rotation = DirectionHelper.AngleBetween(Direction.West, generalCardinals.GetOnlyNegative()); } else { // This sneaky piece of code uses the cardinal info to store diagonals by rotating everything -45 degrees // NE -> N, SW -> S, etc. var diagonals = new AdjacencyBitmap.CardinalInfo((byte)(generalAdjacents.Connections >> 1)); switch (diagonals.numConnections) { case 0: mesh = xNone; break; case 1: mesh = xSingle; rotation = DirectionHelper.AngleBetween(Direction.West, diagonals.GetOnlyPositive()); break; case 2: if (diagonals.north == diagonals.south) { mesh = xOpposite; rotation = OrientationHelper.AngleBetween(Orientation.Vertical, diagonals.GetFirstOrientation()); } else { mesh = xSide; rotation = DirectionHelper.AngleBetween(Direction.SouthWest, diagonals.GetCornerDirection()); } break; case 3: mesh = xTriple; rotation = DirectionHelper.AngleBetween(Direction.East, diagonals.GetOnlyNegative()); break; default: mesh = xQuad; break; } } if (filter == null) { filter = GetComponent <MeshFilter>(); } filter.mesh = mesh; transform.localRotation = Quaternion.Euler(transform.localRotation.eulerAngles.x, rotation, transform.localRotation.eulerAngles.z); }