| 262 | } |
| 263 | |
| 264 | bool SpherePrimitiveEvaluator::pointAtUV( const Imath::V2f &uv, PrimitiveEvaluator::Result *result ) const |
| 265 | { |
| 266 | assert( dynamic_cast<Result *>( result ) ); |
| 267 | |
| 268 | Result *sr = static_cast<Result *>( result ); |
| 269 | |
| 270 | /// \todo Once we support partial spheres we'll need to get these quantities from the primitive |
| 271 | const float zMin = -1.0f; |
| 272 | const float zMax = 1.0f; |
| 273 | const float thetaMax = 2.0f * M_PI; |
| 274 | |
| 275 | /// This is from the Renderman specification |
| 276 | const float phiMin = asin( zMin ); |
| 277 | const float phiMax = asin( zMax ); |
| 278 | |
| 279 | float phi = phiMin + uv.y * ( phiMax - phiMin ); |
| 280 | float theta = uv.x * thetaMax; |
| 281 | |
| 282 | sr->m_p = m_sphere->radius() * V3f( |
| 283 | cos( theta ) * cos( phi ), |
| 284 | sin( theta ) * cos( phi ), |
| 285 | sin( phi ) |
| 286 | ); |
| 287 | |
| 288 | return true; |
| 289 | } |
| 290 | |
| 291 | /// Implementation derived from Wild Magic (Version 2) Software Library, available |
| 292 | /// from http://www.geometrictools.com/Downloads/WildMagic2p5.zip under free license |