/// <summary> /// 旋转点位 /// </summary> /// <param name="vert"></param> /// <returns></returns> public virtual Vector3 RotatePosition(BlockDirectionEnum direction, Vector3 position, Vector3 centerPosition) { if (block.blockInfo.rotate_state == 0) { //不旋转 return(position); } else if (block.blockInfo.rotate_state == 1) { //已中心点旋转 Vector3 angles = GetRotateAngles(direction); //旋转6面 Vector3 rotatePosition = VectorUtil.GetRotatedPosition(centerPosition, position, angles); return(rotatePosition); } else if (block.blockInfo.rotate_state == 2) { //已中心点旋转 Vector3 angles = GetRotateAngles(direction); //旋转6面 Vector3 rotatePosition = VectorUtil.GetRotatedPosition(centerPosition, position, angles); return(rotatePosition); } else if (block.blockInfo.rotate_state == 3) { return(position); } return(position); }
/// <summary> /// 增加链接的mesh数据 /// </summary> /// <param name="chunk"></param> /// <param name="localPosition"></param> /// <param name="angle"></param> protected void AddOtherMeshData(Chunk chunk, Vector3Int localPosition, float angle) { Vector3[] rotatePositionArray = VectorUtil.GetRotatedPosition(new Vector3(0.5f, 0.5f, 0.5f), vertsAddLink, new Vector3(0, angle, 0)); BaseAddTrisForCustom(chunk, localPosition, BlockDirectionEnum.UpForward, trisAddLink); BaseAddVertsUVsColorsForCustom(chunk, localPosition, BlockDirectionEnum.UpForward, rotatePositionArray, uvsAddLink, colorAddLink, new Vector3[0]); }
public MeshDataDetailsCustom(float size, Vector3 offset, Vector3 rotate) { vertices = new Vector3[0]; uv = new Vector2[0]; triangles = new int[0]; vertices = VectorUtil.GetRotatedPosition(Vector3.zero, vertices, rotate); for (int i = 0; i < vertices.Length; i++) { Vector3 itemVer = vertices[i]; Vector3 newVer = itemVer * size + offset; vertices[i] = newVer; } }
/// <summary> /// 增加建筑 /// </summary> /// <param name="addRate"></param> /// <param name="randomData"></param> /// <param name="startPosition"></param> /// <param name="buildingType"></param> public static bool AddBuilding(float addRate, uint randomData, Vector3Int startPosition, BuildingTypeEnum buildingType) { float randomRate; if (addRate < 0.00001f) { //概率小于万分之一的用RandomTools int seed = WorldCreateHandler.Instance.manager.GetWorldSeed(); RandomTools randomTools = RandomUtil.GetRandom(seed, startPosition.x, startPosition.y, startPosition.z); //生成概率 randomRate = randomTools.NextFloat(); } else { randomRate = WorldRandTools.GetValue(startPosition, randomData); } if (randomRate < addRate) { BuildingInfoBean buildingInfo = BiomeHandler.Instance.manager.GetBuildingInfo(buildingType); List <BuildingBean> listBuildingData = buildingInfo.listBuildingData; int randomAngle = WorldRandTools.Range(0, 4, startPosition) * 90; for (int i = 0; i < listBuildingData.Count; i++) { BuildingBean buildingData = listBuildingData[i]; Vector3Int targetPosition = startPosition + buildingData.GetPosition(); float createRate = WorldRandTools.GetValue(targetPosition); if (buildingData.randomRate == 0 || createRate < buildingData.randomRate) { VectorUtil.GetRotatedPosition(startPosition, targetPosition, new Vector3(0, randomAngle, 0)); WorldCreateHandler.Instance.manager.AddUpdateBlock(targetPosition, buildingData.blockId, (BlockDirectionEnum)buildingData.direction); } } return(true); } return(false); }
protected Vector3[] RotateOtherMeshVerts(float angle) { return(VectorUtil.GetRotatedPosition(new Vector3(0.5f, 0.5f, 0.5f), vertsAddDirection, new Vector3(0, angle, 0))); }