private void SetRectangularTextureWithMouse(Vector2 texCoordStart, Vector2 texCoordEnd) { Vector2 texCoordStartQuantized = Quantize(texCoordStart, texCoordStart.X > texCoordEnd.X, texCoordStart.Y > texCoordEnd.Y, true); Vector2 texCoordEndQuantized = Quantize(texCoordEnd, !(texCoordStart.X > texCoordEnd.X), !(texCoordStart.Y > texCoordEnd.Y), true); texCoordEndQuantized = Vector2.Min(texCoordStartQuantized + new Vector2(MaxTextureSize), Vector2.Max(texCoordStartQuantized - new Vector2(MaxTextureSize), texCoordEndQuantized)); var selectedTexture = SelectedTexture; selectedTexture.TexCoord0 = new Vector2(texCoordStartQuantized.X, texCoordEndQuantized.Y); selectedTexture.TexCoord1 = texCoordStartQuantized; selectedTexture.TexCoord2 = new Vector2(texCoordEndQuantized.X, texCoordStartQuantized.Y); selectedTexture.TexCoord3 = texCoordEndQuantized; // Avoid mirroring the texture by rectangular selections if ((texCoordStartQuantized.X > texCoordEndQuantized.X) != (texCoordStartQuantized.Y > texCoordEndQuantized.Y)) { Swap.Do(ref selectedTexture.TexCoord0, ref selectedTexture.TexCoord2); } selectedTexture.Texture = VisibleTexture; if (selectedTexture.TriangleArea != 0 || selectedTexture.QuadArea != 0) { SelectedTexture = selectedTexture; } }
private void MirrorWallTexture(BlockFace oldFace, Func <BlockFace, BlockFaceShape> oldFaceIsTriangle) { switch (oldFaceIsTriangle(oldFace)) { case BlockFaceShape.Triangle: Swap.Do(ref _faceTextures[(int)oldFace].TexCoord0, ref _faceTextures[(int)oldFace].TexCoord1); break; case BlockFaceShape.Quad: Swap.Do(ref _faceTextures[(int)oldFace].TexCoord0, ref _faceTextures[(int)oldFace].TexCoord3); Swap.Do(ref _faceTextures[(int)oldFace].TexCoord1, ref _faceTextures[(int)oldFace].TexCoord2); break; } }
public void DoDoubleSwap() { if (DoubleSwap == true) { if (m_thingDoubleSwap != null) { m_swap.col = m_thingDoubleSwap.GetComponent <Collider2D>(); m_bDoubleSwap = true; m_swap.swapDamageOn = SwapDamage; m_swap.damageEffectOn = true; m_swap.Do(); m_swap.ResetSwapDamageOn(); m_bDoubleSwap = false; } } }
// Rotates and mirrors a sector according to a given transformation. The transformation can be combination of rotations and mirrors // but all possible transformation essentially are boiled down to a mirror on the x axis and a rotation afterwards. // Thus all that needs to be handled is mirroring on x and a single counterclockwise rotation (perhaps multiple times in a row). // When mirroring is done, a oldFaceIsTriangle must be provided that can return the previous shape of texture faces. // Set "onlyFloor" to true, to only modify the floor. // Set "onlyFloor" to false, to only modify the ceiling. public void Transform(RectTransformation transformation, bool?onlyFloor = null, Func <BlockFace, BlockFaceShape> oldFaceIsTriangle = null) { // Rotate sector flags if (transformation.MirrorX) { Flags = (Flags & ~(BlockFlags.ClimbPositiveX | BlockFlags.ClimbNegativeX)) | ((Flags & BlockFlags.ClimbPositiveX) != BlockFlags.None ? BlockFlags.ClimbNegativeX : BlockFlags.None) | ((Flags & BlockFlags.ClimbNegativeX) != BlockFlags.None ? BlockFlags.ClimbPositiveX : BlockFlags.None); } for (int i = 0; i < transformation.QuadrantRotation; ++i) { Flags = (Flags & ~(BlockFlags.ClimbPositiveX | BlockFlags.ClimbPositiveZ | BlockFlags.ClimbNegativeX | BlockFlags.ClimbNegativeZ)) | ((Flags & BlockFlags.ClimbPositiveX) != BlockFlags.None ? BlockFlags.ClimbPositiveZ : BlockFlags.None) | ((Flags & BlockFlags.ClimbPositiveZ) != BlockFlags.None ? BlockFlags.ClimbNegativeX : BlockFlags.None) | ((Flags & BlockFlags.ClimbNegativeX) != BlockFlags.None ? BlockFlags.ClimbNegativeZ : BlockFlags.None) | ((Flags & BlockFlags.ClimbNegativeZ) != BlockFlags.None ? BlockFlags.ClimbPositiveX : BlockFlags.None); } // Rotate sector geometry bool diagonalChange = transformation.MirrorX != (transformation.QuadrantRotation % 2 != 0); bool oldFloorSplitDirectionIsXEqualsZReal = Floor.SplitDirectionIsXEqualsZWithDiagonalSplit; if (onlyFloor != false) { bool requiredFloorSplitDirectionIsXEqualsZ = Floor.SplitDirectionIsXEqualsZ != diagonalChange; Floor.DiagonalSplit = TransformDiagonalSplit(Floor.DiagonalSplit, transformation); transformation.TransformValueDiagonalQuad(ref Floor.XpZp, ref Floor.XnZp, ref Floor.XnZn, ref Floor.XpZn); transformation.TransformValueDiagonalQuad(ref _ed[(int)BlockEdge.XpZp], ref _ed[(int)BlockEdge.XnZp], ref _ed[(int)BlockEdge.XnZn], ref _ed[(int)BlockEdge.XpZn]); if (requiredFloorSplitDirectionIsXEqualsZ != Floor.SplitDirectionIsXEqualsZ) { Floor.SplitDirectionToggled = !Floor.SplitDirectionToggled; } if (HasGhostBlock) { transformation.TransformValueDiagonalQuad(ref GhostBlock.Floor.XpZp, ref GhostBlock.Floor.XnZp, ref GhostBlock.Floor.XnZn, ref GhostBlock.Floor.XpZn); } } bool oldCeilingSplitDirectionIsXEqualsZReal = Ceiling.SplitDirectionIsXEqualsZWithDiagonalSplit; if (onlyFloor != true) { bool requiredCeilingSplitDirectionIsXEqualsZ = Ceiling.SplitDirectionIsXEqualsZ != diagonalChange; Ceiling.DiagonalSplit = TransformDiagonalSplit(Ceiling.DiagonalSplit, transformation); transformation.TransformValueDiagonalQuad(ref Ceiling.XpZp, ref Ceiling.XnZp, ref Ceiling.XnZn, ref Ceiling.XpZn); transformation.TransformValueDiagonalQuad(ref _rf[(int)BlockEdge.XpZp], ref _rf[(int)BlockEdge.XnZp], ref _rf[(int)BlockEdge.XnZn], ref _rf[(int)BlockEdge.XpZn]); if (requiredCeilingSplitDirectionIsXEqualsZ != Ceiling.SplitDirectionIsXEqualsZ) { Ceiling.SplitDirectionToggled = !Ceiling.SplitDirectionToggled; } if (HasGhostBlock) { transformation.TransformValueDiagonalQuad(ref GhostBlock.Ceiling.XpZp, ref GhostBlock.Ceiling.XnZp, ref GhostBlock.Ceiling.XnZn, ref GhostBlock.Ceiling.XpZn); } } // Rotate applied textures if (onlyFloor != false) { // Fix lower wall textures if (transformation.MirrorX) { MirrorWallTexture(BlockFace.PositiveX_QA, oldFaceIsTriangle); MirrorWallTexture(BlockFace.PositiveZ_QA, oldFaceIsTriangle); MirrorWallTexture(BlockFace.NegativeX_QA, oldFaceIsTriangle); MirrorWallTexture(BlockFace.NegativeZ_QA, oldFaceIsTriangle); MirrorWallTexture(BlockFace.DiagonalQA, oldFaceIsTriangle); MirrorWallTexture(BlockFace.PositiveX_ED, oldFaceIsTriangle); MirrorWallTexture(BlockFace.PositiveZ_ED, oldFaceIsTriangle); MirrorWallTexture(BlockFace.NegativeX_ED, oldFaceIsTriangle); MirrorWallTexture(BlockFace.NegativeZ_ED, oldFaceIsTriangle); MirrorWallTexture(BlockFace.DiagonalED, oldFaceIsTriangle); } transformation.TransformValueQuad( ref _faceTextures[(int)BlockFace.PositiveX_QA], ref _faceTextures[(int)BlockFace.PositiveZ_QA], ref _faceTextures[(int)BlockFace.NegativeX_QA], ref _faceTextures[(int)BlockFace.NegativeZ_QA]); transformation.TransformValueQuad( ref _faceTextures[(int)BlockFace.PositiveX_ED], ref _faceTextures[(int)BlockFace.PositiveZ_ED], ref _faceTextures[(int)BlockFace.NegativeX_ED], ref _faceTextures[(int)BlockFace.NegativeZ_ED]); // Fix floor textures if (Floor.IsQuad) { _faceTextures[(int)BlockFace.Floor] = _faceTextures[(int)BlockFace.Floor].Transform(transformation * new RectTransformation { QuadrantRotation = 2 }); } else { // Mirror if (transformation.MirrorX) { Swap.Do(ref _faceTextures[(int)BlockFace.Floor], ref _faceTextures[(int)BlockFace.FloorTriangle2]); Swap.Do(ref _faceTextures[(int)BlockFace.Floor].TexCoord0, ref _faceTextures[(int)BlockFace.Floor].TexCoord2); Swap.Do(ref _faceTextures[(int)BlockFace.FloorTriangle2].TexCoord0, ref _faceTextures[(int)BlockFace.FloorTriangle2].TexCoord2); if (Floor.DiagonalSplit != DiagonalSplit.None) // REMOVE this when we have better diaognal steps. { Swap.Do(ref _faceTextures[(int)BlockFace.Floor], ref _faceTextures[(int)BlockFace.FloorTriangle2]); } } // Rotation for (int i = 0; i < transformation.QuadrantRotation; ++i) { if (!oldFloorSplitDirectionIsXEqualsZReal) { Swap.Do(ref _faceTextures[(int)BlockFace.Floor], ref _faceTextures[(int)BlockFace.FloorTriangle2]); } if (Floor.DiagonalSplit != DiagonalSplit.None) // REMOVE this when we have better diaognal steps. { Swap.Do(ref _faceTextures[(int)BlockFace.Floor], ref _faceTextures[(int)BlockFace.FloorTriangle2]); } oldFloorSplitDirectionIsXEqualsZReal = !oldFloorSplitDirectionIsXEqualsZReal; } } } if (onlyFloor != true) { // Fix upper wall textures if (transformation.MirrorX) { MirrorWallTexture(BlockFace.PositiveX_WS, oldFaceIsTriangle); MirrorWallTexture(BlockFace.PositiveZ_WS, oldFaceIsTriangle); MirrorWallTexture(BlockFace.NegativeX_WS, oldFaceIsTriangle); MirrorWallTexture(BlockFace.NegativeZ_WS, oldFaceIsTriangle); MirrorWallTexture(BlockFace.DiagonalWS, oldFaceIsTriangle); MirrorWallTexture(BlockFace.PositiveX_RF, oldFaceIsTriangle); MirrorWallTexture(BlockFace.PositiveZ_RF, oldFaceIsTriangle); MirrorWallTexture(BlockFace.NegativeX_RF, oldFaceIsTriangle); MirrorWallTexture(BlockFace.NegativeZ_RF, oldFaceIsTriangle); MirrorWallTexture(BlockFace.DiagonalRF, oldFaceIsTriangle); } transformation.TransformValueQuad( ref _faceTextures[(int)BlockFace.PositiveX_WS], ref _faceTextures[(int)BlockFace.PositiveZ_WS], ref _faceTextures[(int)BlockFace.NegativeX_WS], ref _faceTextures[(int)BlockFace.NegativeZ_WS]); transformation.TransformValueQuad( ref _faceTextures[(int)BlockFace.PositiveX_RF], ref _faceTextures[(int)BlockFace.PositiveZ_RF], ref _faceTextures[(int)BlockFace.NegativeX_RF], ref _faceTextures[(int)BlockFace.NegativeZ_RF]); // Fix ceiling textures if (Ceiling.IsQuad) { _faceTextures[(int)BlockFace.Ceiling] = _faceTextures[(int)BlockFace.Ceiling].Transform(transformation * new RectTransformation { QuadrantRotation = 2 }); } else { // Mirror if (transformation.MirrorX) { Swap.Do(ref _faceTextures[(int)BlockFace.Ceiling], ref _faceTextures[(int)BlockFace.CeilingTriangle2]); Swap.Do(ref _faceTextures[(int)BlockFace.Ceiling].TexCoord0, ref _faceTextures[(int)BlockFace.Ceiling].TexCoord2); Swap.Do(ref _faceTextures[(int)BlockFace.CeilingTriangle2].TexCoord0, ref _faceTextures[(int)BlockFace.CeilingTriangle2].TexCoord2); if (Ceiling.DiagonalSplit != DiagonalSplit.None) // REMOVE this when we have better diaognal steps. { Swap.Do(ref _faceTextures[(int)BlockFace.Ceiling], ref _faceTextures[(int)BlockFace.CeilingTriangle2]); } } // Rotation for (int i = 0; i < transformation.QuadrantRotation; ++i) { if (!oldCeilingSplitDirectionIsXEqualsZReal) { Swap.Do(ref _faceTextures[(int)BlockFace.Ceiling], ref _faceTextures[(int)BlockFace.CeilingTriangle2]); } if (Ceiling.DiagonalSplit != DiagonalSplit.None) // REMOVE this when we have better diaognal steps. { Swap.Do(ref _faceTextures[(int)BlockFace.Ceiling], ref _faceTextures[(int)BlockFace.CeilingTriangle2]); } oldCeilingSplitDirectionIsXEqualsZReal = !oldCeilingSplitDirectionIsXEqualsZReal; } } } if (onlyFloor == null) { if (transformation.MirrorX) { MirrorWallTexture(BlockFace.PositiveX_Middle, oldFaceIsTriangle); MirrorWallTexture(BlockFace.PositiveZ_Middle, oldFaceIsTriangle); MirrorWallTexture(BlockFace.NegativeX_Middle, oldFaceIsTriangle); MirrorWallTexture(BlockFace.NegativeZ_Middle, oldFaceIsTriangle); MirrorWallTexture(BlockFace.DiagonalMiddle, oldFaceIsTriangle); } transformation.TransformValueQuad( ref _faceTextures[(int)BlockFace.PositiveX_Middle], ref _faceTextures[(int)BlockFace.PositiveZ_Middle], ref _faceTextures[(int)BlockFace.NegativeX_Middle], ref _faceTextures[(int)BlockFace.NegativeZ_Middle]); } }