medfall

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

commit f8c8a82bc9b1cbb4b177ae2e7bc7c2fc00678906
parent ef11daf3fb6c8132c3905286784c06f1645aca5c
Author: Michael Savage <mikejsavage@gmail.com>
Date:   Wed Aug 26 21:52:37 +0200

Add immediate_sphere

Diffstat:
immediate.cc | 45+++++++++++++++++++++++++++++++++++++++++++++
immediate.h | 4++++
2 files changed, 49 insertions(+), 0 deletions(-)
diff --git a/immediate.cc b/immediate.cc @@ -38,6 +38,51 @@ void immediate_triangle( ctx->triangles[ ctx->num_triangles++ ] = triangle; } +void immediate_sphere( + ImmediateContext * const ctx, const glm::vec3 centre, const float radius, + const glm::vec4 colour, const u32 subdivisions +) { + const float azimuth_max = 2.0f * M_PI; + const float pitch_max = M_PI; + + for( u32 a = 0; a < subdivisions * 2; a++ ) { + const float azimuth0 = azimuth_max * ( float ) a / ( subdivisions * 2 ); + const float azimuth1 = azimuth_max * ( float ) ( a + 1 ) / ( subdivisions * 2 ); + + for( u32 p = 0; p < subdivisions; p++ ) { + const float pitch0 = pitch_max * ( float ) p / subdivisions; + const float pitch1 = pitch_max * ( float ) ( p + 1 ) / subdivisions; + + const glm::vec3 top_left = centre + glm::vec3( + radius * cosf( azimuth0 ) * sinf( pitch0 ), + radius * sinf( azimuth0 ) * sinf( pitch0 ), + radius * cosf( pitch0 ) + ); + + const glm::vec3 top_right = centre + glm::vec3( + radius * cosf( azimuth1 ) * sinf( pitch0 ), + radius * sinf( azimuth1 ) * sinf( pitch0 ), + radius * cosf( pitch0 ) + ); + + const glm::vec3 bottom_left = centre + glm::vec3( + radius * cosf( azimuth0 ) * sinf( pitch1 ), + radius * sinf( azimuth0 ) * sinf( pitch1 ), + radius * cosf( pitch1 ) + ); + + const glm::vec3 bottom_right = centre + glm::vec3( + radius * cosf( azimuth1 ) * sinf( pitch1 ), + radius * sinf( azimuth1 ) * sinf( pitch1 ), + radius * cosf( pitch1 ) + ); + + immediate_triangle( ctx, top_left, top_right, bottom_left, colour ); + immediate_triangle( ctx, bottom_left, top_right, bottom_right, colour ); + } + } +} + void immediate_render( ImmediateContext * const ctx, const GLint at_position, const GLint at_colour, diff --git a/immediate.h b/immediate.h @@ -31,6 +31,10 @@ void immediate_render( ImmediateContext * const ctx, const GLint at_position, const GLint at_colour, const bool textured = false, const GLint at_uv = 0, const GLint un_texture = 0 ); +void immediate_sphere( ImmediateContext * const ctx, + const glm::vec3 centre, const float radius, const glm::vec4 colour, + const u32 subdivisions = 32 ); + void immediate_clear( ImmediateContext * const ctx ); #endif // _IMMEDIATE_H_