Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void CGLRenderer::PrepareSphere(float radius)
- {
- float x, y, z;
- int k = 0;
- int i = 0;
- const float PI = 3.145926;
- const int sectors = 20;
- int r = 0;
- for (int i = 0; i < sectors + 1; i++)
- {
- for (int j = 0; j < sectors + 1; j++) {
- int nextStrip = j + (i + 1) * sectors;
- int currStrip = j + i * sectors;
- indicesSphere[r++] = currStrip;
- indicesSphere[r++] = nextStrip;
- indicesSphere[r++] = nextStrip + 1;
- indicesSphere[r++] = currStrip + 1;
- indicesSphere[r++] = currStrip;
- indicesSphere[r++] = nextStrip + 1;
- }
- }
- sphereVert = r;
- texSphere = new float[sectors * sectors * 2];
- int texCoords = 0;
- for (float lat = -PI / 2; lat <= PI / 2; lat += (PI / sectors)) {
- for (float lon = -PI; lon <= PI; lon += (2 * PI) / sectors) {
- x = radius * cos(lat) * cos(lon);
- y = radius * cos(lat) * sin(lon);
- z = radius * sin(lat);
- normalsSphere[i++] = x / radius;
- normalsSphere[i++] = y / radius;
- normalsSphere[i++] = z / radius;
- vertSphere[k++] = x;
- vertSphere[k++] = y;
- vertSphere[k++] = z;
- //Y = (X - A) / (B - A) * (D - C) + C
- texSphere[texCoords++] = (lat - (-PI / 2)) / PI;
- texSphere[texCoords++] = (lat - (-PI)) / (2*PI);
- }
- }
- //lat => x;
- //lon => y
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement