Created
December 4, 2018 12:49
-
-
Save baobao/f1a53b5c9c2c91d429d710668b4c20f7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 半径 | |
float r = size * 0.5f; | |
int cnt = 0; | |
int vertCount = divideX * (divideY - 1) + 2; | |
var vertices = new Vector3[vertCount]; | |
// 中心角 | |
float centerRadianX = 2f * Mathf.PI / (float) divideX; | |
float centerRadianY = 2f * Mathf.PI / (float) divideY; | |
// 天面 | |
vertices[cnt++] = new Vector3(0, r, 0); | |
for (int vy = 0; vy < divideY - 1; vy++) | |
{ | |
var yRadian = (float) (vy + 1) * centerRadianY / 2f; | |
// 1辺の長さ | |
var tmpLen = Mathf.Abs(Mathf.Sin(yRadian)); | |
var y = Mathf.Cos(yRadian); | |
for (int vx = 0; vx < divideX; vx++) | |
{ | |
var pos = new Vector3( | |
tmpLen * Mathf.Sin((float) vx * centerRadianX), | |
y, | |
tmpLen * Mathf.Cos((float) vx * centerRadianX) | |
); | |
// サイズ反映 | |
vertices[cnt++] = pos * r; | |
} | |
} | |
// 底面 | |
vertices[cnt] = new Vector3(0, -r, 0); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment