예제 #1
0
        public bool RotationValid(VoxelRotation rotation)
        {
            if (!AllowedRotationAxes.x && rotation.x != 0)
            {
                return(false);
            }
            if (!AllowedRotationAxes.y && rotation.y != 0)
            {
                return(false);
            }
            if (!AllowedRotationAxes.z && rotation.z != 0)
            {
                return(false);
            }

            int numRotationAxes = 0;

            if (rotation.x != 0)
            {
                numRotationAxes++;
            }

            if (rotation.y != 0)
            {
                numRotationAxes++;
            }

            if (rotation.z != 0)
            {
                numRotationAxes++;
            }

            if (numRotationAxes > MaximumSimultaneousRotations)
            {
                return(false);
            }

            if (allowedRotationsX.Count > 0 && !allowedRotationsX.Contains((AllowedRotationValue)rotation.x))
            {
                return(false);
            }

            if (allowedRotationsY.Count > 0 && !allowedRotationsY.Contains((AllowedRotationValue)rotation.y))
            {
                return(false);
            }

            if (allowedRotationsZ.Count > 0 && !allowedRotationsZ.Contains((AllowedRotationValue)rotation.z))
            {
                return(false);
            }

            return(true);
        }
예제 #2
0
        public void SetRotation(Vector3Int coords, VoxelRotation rotation)
        {
            var(x, y, z) = coords;
            var flat = Utils.Helpers.MultiIndexToFlat(x, y, z, Dimensions);

            if (rotation.isBlank)
            {
                rotatedVoxels.Remove(flat);
            }
            else
            {
                rotatedVoxels[flat] = new RotatedVoxelEntry()
                {
                    flatIndex = flat, rotation = rotation
                };
            }
        }
        public Direction GetDirectionAfterRotation(Direction dir, VoxelRotation rot)
        {
            for (int i = 0; i < rot.y; i++)
            {
                dir = YRotationMatix[(byte)dir];
            }

            for (int i = 0; i < rot.x; i++)
            {
                dir = XRotationMatix[(byte)dir];
            }

            for (int i = 0; i < rot.z; i++)
            {
                dir = ZRotationMatix[(byte)dir];
            }

            return(dir);
        }
예제 #4
0
        public void PlaceVoxel(Vector3 position, SOVoxelTypeDefinition voxelType, VoxelRotation rotation = default)
        {
            if (voxelType == null)
            {
                return;
            }

            bool replaceExisting = false;
            SOVoxelTypeDefinition existingVoxelType;

            if (TryGetVoxelType(position, out existingVoxelType) && existingVoxelType != null)
            {
                replaceExisting = existingVoxelType.isReplaceable;
            }

            if (voxelType.rotationConfiguration == null)
            {
                if (rotation.x != 0 || rotation.y != 0 || rotation.z != 0)
                {
                    return;//Cannot place non-rotable voxel with a rotation value
                }
                else
                {
                    chunkManager.TrySetVoxel(position, voxelTypeManager.GetId(voxelType), overrideExisting: replaceExisting);
                }
            }
            else
            {
                if (voxelType.rotationConfiguration.RotationValid(rotation))
                {
                    Debug.Log($"Placed voxel {voxelType.DisplayName} with rotation x:{rotation.x}, y:{rotation.y}, z{rotation.z}");

                    chunkManager.TrySetVoxel(position, voxelTypeManager.GetId(voxelType), rotation, replaceExisting);
                }
                else
                {
                    Debug.Log($"Failed to place voxel {voxelType.DisplayName} because the rotation was not valid");
                }
            }
        }
        public Direction GetDirectionBeforeRotation(Direction dir, VoxelRotation rot)
        {
            rot = rot.Inverse();//Opposite rotation

            //Opposite order of rotations
            for (int i = 0; i < rot.z; i++)
            {
                dir = ZRotationMatix[(byte)dir];
            }

            for (int i = 0; i < rot.x; i++)
            {
                dir = XRotationMatix[(byte)dir];
            }

            for (int i = 0; i < rot.y; i++)
            {
                dir = YRotationMatix[(byte)dir];
            }

            return(dir);
        }
 public quaternion GetRotationQuat(VoxelRotation rotation)
 {
     return(quaternion.Euler(PI_2 * rotation.x, PI_2 * rotation.y, PI_2 * rotation.z, math.RotationOrder.YXZ));
 }