Skip to content

Instantly share code, notes, and snippets.

@ZsemberiDaniel
Last active April 19, 2021 09:47
Show Gist options
  • Save ZsemberiDaniel/8568eae2d2f3cd9aedc58a0616fd4be9 to your computer and use it in GitHub Desktop.
Save ZsemberiDaniel/8568eae2d2f3cd9aedc58a0616fd4be9 to your computer and use it in GitHub Desktop.
// Torusz feladat:
const int N = 30;
const int M = 30;
std::vector<Vertex> vert((N + 1) * (M + 1));
for (int i = 0; i <= N; ++i)
for (int j = 0; j <= M; ++j)
{
float u = i / (float)N;
float v = j / (float)M;
vert[i + j * (N + 1)].p = GetPos(u, v);
vert[i + j * (N + 1)].n = GetNorm(u, v);
vert[i + j * (N + 1)].t = { u, v };
}
std::vector<unsigned int> indices(3 * 2 * (N) * (M));
for (int i = 0; i < N; ++i)
for (int j = 0; j < M; ++j)
{
indices[6 * i + j * 3 * 2 * (N)+0] = (i)+(j) * (N + 1);
indices[6 * i + j * 3 * 2 * (N)+1] = (i + 1) + (j) * (N + 1);
indices[6 * i + j * 3 * 2 * (N)+2] = (i)+(j + 1) * (N + 1);
indices[6 * i + j * 3 * 2 * (N)+3] = (i + 1) + (j) * (N + 1);
indices[6 * i + j * 3 * 2 * (N)+4] = (i + 1) + (j + 1) * (N + 1);
indices[6 * i + j * 3 * 2 * (N)+5] = (i)+(j + 1) * (N + 1);
}
glm::vec3 du = glm::vec3((R + r * cv) * -su, (R + r * cv) * cu, 0);
glm::vec3 dv = glm::vec3(r * cu * -sv, r * su * -sv, r * cv);
return glm::normalize(glm::cross(du, dv));
// height map:
https://raw.githubusercontent.com/ZsemberiDaniel/2020OszGrafikaGyak/master/01_OGLBase/01_OGLBase/Assets/heightMap.png
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment