medfall

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

commit 5abf4bb24e9a1d81ba9853a0c7d8a34fe8df23bf
parent 281705c3846ecc0142613c6b12960c96731be930
Author: Michael Savage <mikejsavage@gmail.com>
Date:   Sun May  8 22:04:27 +0100

Optimise immediate_sphere

Diffstat:
immediate.cc | 53++++++++++++++++++++++++++++++++++++-----------------
1 file changed, 36 insertions(+), 17 deletions(-)
diff --git a/immediate.cc b/immediate.cc @@ -45,41 +45,60 @@ void immediate_sphere( const float azimuth_max = 2.0f * M_PI; const float pitch_max = M_PI; + const float dsa = sinf( 0.5f * azimuth_max / ( subdivisions - 1 ) ); + const float dca = cosf( 0.5f * azimuth_max / ( subdivisions - 1 ) ); + const float dsp = sinf( pitch_max / subdivisions ); + const float dcp = cosf( pitch_max / subdivisions ); + + float sa0 = 0; + float sa1 = dsa; + float ca0 = 0; + float ca1 = dca; + for( u32 a = 0; a < subdivisions * 2; a++ ) { - float azimuth0 = azimuth_max * ( float ) a / ( subdivisions * 2 ); - float azimuth1 = azimuth_max * ( float ) ( a + 1 ) / ( subdivisions * 2 ); + float sp0 = 0; + float sp1 = dsp; + float cp0 = 0; + float cp1 = dcp; for( u32 p = 0; p < subdivisions; p++ ) { - float pitch0 = pitch_max * ( float ) p / subdivisions; - float pitch1 = pitch_max * ( float ) ( p + 1 ) / subdivisions; - glm::vec3 top_left = centre + glm::vec3( - radius * cosf( azimuth0 ) * sinf( pitch0 ), - radius * sinf( azimuth0 ) * sinf( pitch0 ), - radius * cosf( pitch0 ) + radius * ca0 * sp0, + radius * sa0 * sp0, + radius * cp0 ); glm::vec3 top_right = centre + glm::vec3( - radius * cosf( azimuth1 ) * sinf( pitch0 ), - radius * sinf( azimuth1 ) * sinf( pitch0 ), - radius * cosf( pitch0 ) + radius * ca1 * sp0, + radius * sa1 * sp0, + radius * cp0 ); glm::vec3 bottom_left = centre + glm::vec3( - radius * cosf( azimuth0 ) * sinf( pitch1 ), - radius * sinf( azimuth0 ) * sinf( pitch1 ), - radius * cosf( pitch1 ) + radius * ca0 * sp1, + radius * sa0 * sp1, + radius * cp1 ); glm::vec3 bottom_right = centre + glm::vec3( - radius * cosf( azimuth1 ) * sinf( pitch1 ), - radius * sinf( azimuth1 ) * sinf( pitch1 ), - radius * cosf( pitch1 ) + radius * ca1 * sp1, + radius * sa1 * sp1, + radius * cp1 ); immediate_triangle( ctx, top_left, top_right, bottom_left, colour ); immediate_triangle( ctx, bottom_left, top_right, bottom_right, colour ); + + sp0 = sp1; + cp0 = cp1; + sp1 = sp0 * dcp + cp0 * dsp; + cp1 = cp0 * dcp - sp0 * dsp; } + + sa0 = sa1; + ca0 = ca1; + sa1 = sa0 * dca + ca0 * dsa; + ca1 = ca0 * dca - sa0 * dsa; } }