Witam,
W jaki sposób stworzyć sferę 3d w xna z tekstury 2d. Próbowałem kilku przykładów np:
public void Tesellate()
{
int slices = 20;
int stacks = 3;
int radius = 10;
VertexPositionNormalTexture[] vpnt = new VertexPositionNormalTexture[(slices + 1) * (stacks + 1)];
float phi, theta;
float dphi = MathHelper.Pi / stacks;
float dtheta = MathHelper.TwoPi / slices;
float x, y, z, sc;
int index = 0;
for (int stack = 0; stack <= stacks; stack++)
{
phi = MathHelper.PiOver2 - stack * dphi;
y = radius * (float)Math.Sin(phi);
sc = -radius * (float)Math.Cos(phi);
for (int slice = 0; slice <= slices; slice++)
{
theta = slice * dtheta;
x = sc * (float)Math.Sin(theta);
z = sc * (float)Math.Cos(theta);
vpnt[index++] = new VertexPositionNormalTexture(new Vector3(x, y, z),
new Vector3(x, y, z),
new Vector2((float)slice / (float)slices, (float)stack / (float)stacks));
}
}
int [] indices = new int[slices * stacks * 6];
index = 0;
int k = slices + 1;
for (int stack = 0; stack < stacks; stack++)
{
for (int slice = 0; slice < slices; slice++)
{
indices[index++] = (stack + 0) * k + slice;
indices[index++] = (stack + 1) * k + slice;
indices[index++] = (stack + 0) * k + slice + 1;
indices[index++] = (stack + 0) * k + slice + 1;
indices[index++] = (stack + 1) * k + slice;
indices[index++] = (stack + 1) * k + slice + 1;
}
}
terenIndeksy = new IndexBuffer(graphics.GraphicsDevice, typeof(int), slices * stacks * 6, BufferUsage.WriteOnly);
terenIndeksy.SetData<int>(indices);
terenWierzcholki = new VertexBuffer(graphics.GraphicsDevice, typeof(VertexPositionNormalTexture),
(slices + 1) * (stacks + 1), BufferUsage.WriteOnly);
terenWierzcholki.SetData<VertexPositionNormalTexture>(vpnt);
}
Może ten przykład jest poprawny tylko ja nie wiem w jaki sposób go dobrze wywołać, co powinno być w metodzie draw?
Proszę o sugestie ;)
Pozdrawiam