diff options
author | Clément Foucault <foucault.clem@gmail.com> | 2017-02-12 21:19:35 +0300 |
---|---|---|
committer | Clément Foucault <foucault.clem@gmail.com> | 2017-02-14 02:35:25 +0300 |
commit | 9c35907ca2c7963d722de469e9116350da70b71b (patch) | |
tree | 4bb192a0b32c7d7789615a41c58864eb9c4b80df /source/blender/editors/screen/glutil.c | |
parent | 1634cef2b3dece45a015e7f89676942461119b8a (diff) |
OpenGL immediate mode: Replacement for gluCylinder
Diffstat (limited to 'source/blender/editors/screen/glutil.c')
-rw-r--r-- | source/blender/editors/screen/glutil.c | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/source/blender/editors/screen/glutil.c b/source/blender/editors/screen/glutil.c index dde4762676d..4a8edef4ca2 100644 --- a/source/blender/editors/screen/glutil.c +++ b/source/blender/editors/screen/glutil.c @@ -251,6 +251,57 @@ void imm_cpack(unsigned int x) (((x) >> 16) & 0xFF)); } +void imm_cylinder(unsigned int pos, unsigned int nor, float base, float top, float height, int slices, int stacks) +{ + immBegin(GL_TRIANGLES, 6 * slices * stacks); + for (int i = 0; i < slices; ++i) { + const float angle1 = 2 * M_PI * ((float)i / (float)slices); + const float angle2 = 2 * M_PI * ((float)(i+1) / (float)slices); + const float cos1 = cosf(angle1); + const float sin1 = sinf(angle1); + const float cos2 = cosf(angle2); + const float sin2 = sinf(angle2); + + for (int j = 0; j < stacks; ++j) { + float fac1 = (float)j / (float)stacks; + float fac2 = (float)(j+1) / (float)stacks; + float r1 = base * (1.f - fac1) + top * fac1; + float r2 = base * (1.f - fac2) + top * fac2; + float h1 = height * ((float)j / (float)stacks); + float h2 = height * ((float)(j+1) / (float)stacks); + + float v1[3] = {r1 * cos2, r1 * sin2, h1}; + float v2[3] = {r2 * cos2, r2 * sin2, h2}; + float v3[3] = {r2 * cos1, r2 * sin1, h2}; + float v4[3] = {r1 * cos1, r1 * sin1, h1}; + float n1[3], n2[3]; + + /* calc normals */ + sub_v3_v3v3(n1, v2, v1); + normalize_v3(n1); + n1[0] = cos1; n1[1] = sin1; n1[2] = 1-n1[2]; + + sub_v3_v3v3(n2, v3, v4); + normalize_v3(n2); + n2[0] = cos2; n2[1] = sin2; n2[2] = 1-n2[2]; + + /* first tri */ + immAttrib3fv(nor, n2); + immVertex3fv(pos, v1); + immVertex3fv(pos, v2); + immAttrib3fv(nor, n1); + immVertex3fv(pos, v3); + + /* second tri */ + immVertex3fv(pos, v3); + immVertex3fv(pos, v4); + immAttrib3fv(nor, n2); + immVertex3fv(pos, v1); + } + } + immEnd(); +} + float glaGetOneFloat(int param) { GLfloat v; |