Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor error in renderSphere #365

Open
Camouflager opened this issue Jul 27, 2023 · 0 comments
Open

Minor error in renderSphere #365

Camouflager opened this issue Jul 27, 2023 · 0 comments

Comments

@Camouflager
Copy link

For some reason I was going through sphere code, and I found that there's a minor error.

Here's how the positions are generated:

const unsigned int X_SEGMENTS = 64;
const unsigned int Y_SEGMENTS = 64;
const float PI = 3.14159265359f;
for (unsigned int x = 0; x <= X_SEGMENTS; ++x)
{
for (unsigned int y = 0; y <= Y_SEGMENTS; ++y)
{

Here's how the indices for the triangle strips were generated:

bool oddRow = false;
for (unsigned int y = 0; y < Y_SEGMENTS; ++y)
{
if (!oddRow) // even rows: y == 0, y == 2; and so on
{
for (unsigned int x = 0; x <= X_SEGMENTS; ++x)
{
indices.push_back(y * (X_SEGMENTS + 1) + x);
indices.push_back((y + 1) * (X_SEGMENTS + 1) + x);
}
}
else
{
for (int x = X_SEGMENTS; x >= 0; --x)
{
indices.push_back((y + 1) * (X_SEGMENTS + 1) + x);
indices.push_back(y * (X_SEGMENTS + 1) + x);
}
}

However this does not work when X_SEGMENTS != Y_SEGMENTS. It currently only works because x and y are interchangeable.

let X_SEGMENTS=32 we get the following result:
image

I'm a big fan of this website and I hope it gets better in the future. I hope this issue helps.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant