private unsafe MeshVertex CreateVertex(CyCoord coords, float dTheta) { Vector3 *pos = stackalloc Vector3[3]; CyCoord tcoord = coords; for (int i = 0; i < 3; i++) { //compute 3 positions for computing the derivate respect theta pos[i] = tcoord.ToCartesian(); tcoord.Theta += dTheta; } var tangent = Vector3.Normalize(Numerics.DerivateForward1(pos, dTheta)); var normal = Vector3.Normalize(Vector3.Cross(tangent, new Vector3(0, -1, 0))); var texCoord = new Vector2(coords.Theta / Numerics.TwoPI, 0.5f - coords.Y / height); return(new MeshVertex(pos[0], normal, tangent, texCoord)); }
private void Generate() { vertices = new MeshVertex[slices + 1]; float step = Numerics.TwoPI / slices; CyCoord coords = new CyCoord(Numerics.PIover2, 0, radius); for (int i = 0; i <= slices; i++) { coords.Theta = i * step; vertices[i] = new MeshVertex(position: coords.ToCartesian()); } indices = new ushort[slices * 2]; for (int i = 0; i < slices; i++) { indices[2 * i] = (ushort)i; indices[2 * i + 1] = (ushort)(i + 1); } }