- Timestamp:
- 07/30/15 19:47:02 (10 years ago)
- Location:
- trunk/src
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/core/random.cc
r443 r451 110 110 nv::vec2 nv::random::precise_unit_vec2() 111 111 { 112 f loat angle = frand( glm::pi<float>() * 2.f );113 return vec2( glm::cos( angle ), glm::sin( angle ) );112 f32 angle = frand( math::pi<f32>() * 2.f ); 113 return vec2( math::cos( angle ), math::sin( angle ) ); 114 114 } 115 115 116 116 nv::vec3 nv::random::precise_unit_vec3() 117 117 { 118 f loatcos_theta = frange( -1.0f, 1.0f );119 f loat sin_theta = glm::sqrt( 1.0f - cos_theta * cos_theta );120 f loat phi = frand( 2 * glm::pi<float>() );118 f32 cos_theta = frange( -1.0f, 1.0f ); 119 f32 sin_theta = math::sqrt( 1.0f - cos_theta * cos_theta ); 120 f32 phi = frand( 2 * math::pi<f32>() ); 121 121 return vec3( 122 sin_theta * glm::sin(phi),123 sin_theta * glm::cos(phi),122 sin_theta * math::sin(phi), 123 sin_theta * math::cos(phi), 124 124 cos_theta 125 125 ); … … 128 128 nv::vec2 nv::random::fast_disk_point() 129 129 { 130 f loatr1 = frand();131 f loatr2 = frand();130 f32 r1 = frand(); 131 f32 r2 = frand(); 132 132 if ( r1 > r2 ) swap( r1, r2 ); 133 f loat rf = 2*glm::pi<float>()*(r1/r2);134 return vec2( r2* glm::cos( rf ), r2*glm::sin( rf ) );133 f32 rf = 2* math::pi<f32>()*(r1/r2); 134 return vec2( r2*math::cos( rf ), r2*math::sin( rf ) ); 135 135 } 136 136 137 137 nv::vec2 nv::random::precise_disk_point() 138 138 { 139 f loat r = glm::sqrt( frand() );140 f loat rangle = frand( glm::pi<float>() );141 return vec2( r* glm::cos( rangle ), r*glm::sin( rangle ) );139 f32 r = math::sqrt( frand() ); 140 f32 rangle = frand( math::pi<f32>() ); 141 return vec2( r*math::cos( rangle ), r*math::sin( rangle ) ); 142 142 } 143 143 144 144 nv::vec3 nv::random::fast_sphere_point() 145 145 { 146 f loatrad = frand();147 f loat pi = glm::pi<float>();148 f loat phi = glm::asin( frange( -1.0f, 1.0f ) ) + pi*.5f;149 f loat theta = frange( 0.0f, 2 * glm::pi<float>() );150 f loat sin_phi = glm::sin( phi );146 f32 rad = frand(); 147 f32 pi = math::pi<f32>(); 148 f32 phi = math::asin( frange( -1.0f, 1.0f ) ) + pi*.5f; 149 f32 theta = frange( 0.0f, 2 * math::pi<f32>() ); 150 f32 sin_phi = math::sin( phi ); 151 151 return vec3( 152 rad * glm::cos(theta) * sin_phi,153 rad * glm::sin(theta) * sin_phi,154 rad * glm::cos(phi)152 rad * math::cos(theta) * sin_phi, 153 rad * math::sin(theta) * sin_phi, 154 rad * math::cos(phi) 155 155 ); 156 156 } … … 158 158 nv::vec3 nv::random::precise_sphere_point() 159 159 { 160 f loat radius = glm::pow( frand(), 1.f/3.f );161 f loatcos_theta = frange( -1.0f, 1.0f );162 f loat sin_theta = glm::sqrt( 1.0f - cos_theta * cos_theta );163 f loat phi = frange( 0.0f, 2 * glm::pi<float>() );160 f32 radius = math::pow( frand(), 1.f/3.f ); 161 f32 cos_theta = frange( -1.0f, 1.0f ); 162 f32 sin_theta = math::sqrt( 1.0f - cos_theta * cos_theta ); 163 f32 phi = frange( 0.0f, 2 * math::pi<f32>() ); 164 164 return vec3( 165 radius * sin_theta * glm::sin(phi),166 radius * sin_theta * glm::cos(phi),165 radius * sin_theta * math::sin(phi), 166 radius * sin_theta * math::cos(phi), 167 167 radius * cos_theta 168 168 ); … … 199 199 } 200 200 201 nv::vec2 nv::random::fast_hollow_disk_point( f loat iradius, floatoradius )202 { 203 f loatidist2 = iradius * iradius;204 f loatodist2 = oradius * oradius;205 f loat rdist = glm::sqrt( frange( idist2, odist2 ) );201 nv::vec2 nv::random::fast_hollow_disk_point( f32 iradius, f32 oradius ) 202 { 203 f32 idist2 = iradius * iradius; 204 f32 odist2 = oradius * oradius; 205 f32 rdist = math::sqrt( frange( idist2, odist2 ) ); 206 206 return rdist * precise_unit_vec2(); 207 207 } 208 208 209 nv::vec2 nv::random::precise_hollow_disk_point( f loat iradius, floatoradius )209 nv::vec2 nv::random::precise_hollow_disk_point( f32 iradius, f32 oradius ) 210 210 { 211 211 return fast_hollow_disk_point( iradius, oradius ); 212 212 } 213 213 214 nv::vec3 nv::random::fast_hollow_sphere_point( f loat iradius, floatoradius )215 { 216 f loatidist3 = iradius * iradius * iradius;217 f loatodist3 = oradius * oradius * oradius;218 f loat rdist = glm::pow( frange( idist3, odist3 ), 1.f/3.f );214 nv::vec3 nv::random::fast_hollow_sphere_point( f32 iradius, f32 oradius ) 215 { 216 f32 idist3 = iradius * iradius * iradius; 217 f32 odist3 = oradius * oradius * oradius; 218 f32 rdist = math::pow( frange( idist3, odist3 ), 1.f/3.f ); 219 219 return rdist * precise_unit_vec3(); 220 220 } 221 221 222 nv::vec3 nv::random::precise_hollow_sphere_point( f loat iradius, floatoradius )222 nv::vec3 nv::random::precise_hollow_sphere_point( f32 iradius, f32 oradius ) 223 223 { 224 224 return fast_hollow_sphere_point( iradius, oradius ); … … 232 232 vec2 opoint2 = opoint * opoint; 233 233 vec2 odir = glm::normalize( opoint ); 234 f loatodist2 = opoint2.x + opoint2.y;235 236 f loatlow = iradii2.y * opoint2.x + iradii2.x * opoint2.y;237 f loatidist2 = ((iradii2.x * iradii2.y) / low ) * odist2;238 239 f loat rdist = glm::sqrt( frange( idist2, odist2 ) );234 f32 odist2 = opoint2.x + opoint2.y; 235 236 f32 low = iradii2.y * opoint2.x + iradii2.x * opoint2.y; 237 f32 idist2 = ((iradii2.x * iradii2.y) / low ) * odist2; 238 239 f32 rdist = math::sqrt( frange( idist2, odist2 ) ); 240 240 return odir * rdist; 241 241 } … … 252 252 vec3 opoint2 = opoint * opoint; 253 253 vec3 odir = glm::normalize( opoint ); 254 f loatodist2 = opoint2.x + opoint2.y + opoint2.z;255 256 f loatlow =254 f32 odist2 = opoint2.x + opoint2.y + opoint2.z; 255 256 f32 low = 257 257 iradii2.y * iradii2.z * opoint2.x + 258 258 iradii2.x * iradii2.z * opoint2.y + 259 259 iradii2.x * iradii2.y * opoint2.z; 260 f loatidist2 = ((iradii2.x * iradii2.y * iradii2.z) / low ) * odist2;261 262 f loat odist3 = odist2 * glm::sqrt( odist2 );263 f loat idist3 = idist2 * glm::sqrt( idist2 );264 265 f loat rdist = glm::pow( frange( idist3, odist3 ), 1.f/3.f );260 f32 idist2 = ((iradii2.x * iradii2.y * iradii2.z) / low ) * odist2; 261 262 f32 odist3 = odist2 * math::sqrt( odist2 ); 263 f32 idist3 = idist2 * math::sqrt( idist2 ); 264 265 f32 rdist = math::pow( frange( idist3, odist3 ), 1.f/3.f ); 266 266 return odir * rdist; 267 267 } -
trunk/src/engine/particle_engine.cc
r439 r451 231 231 datap->plane_normal = normalize_safe( datap->plane_normal, vec3(0.0f,1.0f,0.0f) ); 232 232 datap->bounce = table->get<float>("bounce", 0.0f ); 233 datap->distance = -glm::dot( datap->plane_normal, datap->plane_point ) / glm::sqrt(glm::dot( datap->plane_normal, datap->plane_normal ) );233 datap->distance = -glm::dot( datap->plane_normal, datap->plane_point ) / math::sqrt(glm::dot( datap->plane_normal, datap->plane_normal ) ); 234 234 return true; 235 235 } … … 411 411 edata.dir = glm::normalize( element.get<vec3>("direction", vec3(0,1,0) ) ); 412 412 413 edata.odir = glm::vec3( 0, 0, 1 );413 edata.odir = vec3( 0, 0, 1 ); 414 414 if ( edata.dir != vec3( 0, 1, 0 ) && edata.dir != vec3( 0, -1, 0 ) ) 415 415 edata.odir = glm::normalize( glm::cross( edata.dir, vec3( 0, 1, 0 ) ) ); edata.cdir = glm::cross( edata.dir, edata.odir ); … … 750 750 { 751 751 float emission_angle = glm::radians( edata.angle ); 752 float cos_theta = r.frange( glm::cos( emission_angle ), 1.0f );753 float sin_theta = glm::sqrt(1.0f - cos_theta * cos_theta );754 float phi = r.frange( 0.0f, 2* glm::pi<float>() );752 float cos_theta = r.frange( math::cos( emission_angle ), 1.0f ); 753 float sin_theta = math::sqrt(1.0f - cos_theta * cos_theta ); 754 float phi = r.frange( 0.0f, 2* math::pi<float>() ); 755 755 pinfo.velocity = orient * 756 ( edata.odir * ( glm::cos(phi) * sin_theta ) +757 edata.cdir * ( glm::sin(phi)*sin_theta ) +756 ( edata.odir * ( math::cos(phi) * sin_theta ) + 757 edata.cdir * ( math::sin(phi)*sin_theta ) + 758 758 edata.dir * cos_theta ); 759 759 } -
trunk/src/formats/assimp_loader.cc
r432 r451 139 139 vec2 s = assimp_st_cast( mesh->mTextureCoords[0][i] ); 140 140 141 glm::vec3 t_i = glm::normalize( t - n * glm::dot( n, t ) );141 vec3 t_i = glm::normalize( t - n * glm::dot( n, t ) ); 142 142 float det = ( glm::dot( glm::cross( n, t ), b ) ); 143 143 det = ( det < 0.0f ? -1.0f : 1.0f ); … … 440 440 // if ( node->mNumScalingKeys > 0 ) 441 441 // { 442 // nv::vec3 scale_vec0 = assimp_vec3_cast( node->mScalingKeys[0].mValue );443 // float scale_value = glm::length( glm::abs( scale_vec0 - nv::vec3(1,1,1) ) );442 // vec3 scale_vec0 = assimp_vec3_cast( node->mScalingKeys[0].mValue ); 443 // float scale_value = glm::length( math::abs( scale_vec0 - vec3(1,1,1) ) ); 444 444 // if ( node->mNumScalingKeys > 1 || scale_value > 0.001 ) 445 445 // { -
trunk/src/formats/md3_loader.cc
r431 r451 240 240 if ( !s_normal_ready ) 241 241 { 242 float pi = glm::pi<float>();242 float pi = math::pi<float>(); 243 243 float convert = (2 * pi) / 255.0f; 244 244 int n = 0; … … 246 246 { 247 247 float flat = lat * convert; 248 float sin_lat = glm::sin( flat );249 float cos_lat = glm::cos( flat );248 float sin_lat = math::sin( flat ); 249 float cos_lat = math::cos( flat ); 250 250 for ( int lng = 0; lng < 256; ++lng, ++n ) 251 251 { 252 252 float flng = lng * convert; 253 float sin_lng = glm::sin( flng );254 float cos_lng = glm::cos( flng );253 float sin_lng = math::sin( flng ); 254 float cos_lng = math::cos( flng ); 255 255 s_normal_cache[n].x = cos_lat * sin_lng; 256 256 // s_normal_cache[n].y = sin_lat * sin_lng; -
trunk/src/gfx/keyframed_mesh.cc
r430 r451 93 93 } 94 94 } 95 m_last_frame = static_cast<uint32>( glm::floor( tick_time ) + anim->get_start() );95 m_last_frame = static_cast<uint32>( math::floor( tick_time ) + anim->get_start() ); 96 96 m_next_frame = m_last_frame + 1; 97 97 if ( m_next_frame > static_cast<uint32>( anim->get_end() ) ) m_next_frame = static_cast<uint32>( anim->get_start() ); 98 m_interpolation = tick_time - glm::floor( tick_time );98 m_interpolation = tick_time - math::floor( tick_time ); 99 99 } 100 100 } -
trunk/src/lua/lua_glm.cc
r449 r451 56 56 static inline T unit() { return T( 1, 1, 1 ); } 57 57 static inline T construct( lua_State* L, int index ) { 58 typedef nv:: tvec2<typename T::value_type> vec2;58 typedef nv::math::tvec2<typename T::value_type> vec2; 59 59 if ( lua_type( L, index ) == LUA_TUSERDATA ) 60 60 { … … 77 77 static inline T unit() { return T( 1, 1, 1, 1 ); } 78 78 static inline T construct( lua_State* L, int index ) { 79 typedef nv:: tvec2<typename T::value_type> vec2;80 typedef nv:: tvec3<typename T::value_type> vec3;79 typedef nv::math::tvec2<typename T::value_type> vec2; 80 typedef nv::math::tvec3<typename T::value_type> vec3; 81 81 if ( lua_type( L, index ) == LUA_TUSERDATA ) 82 82 { … … 242 242 { 243 243 switch (len) { 244 case 2 : push_vec( L, nv:: tvec2<typename T::value_type>( (*v)[nlua_swizzel_lookup[key[0]]], (*v)[nlua_swizzel_lookup[key[1]]] ) ); return 1;245 case 3 : push_vec( L, nv:: tvec3<typename T::value_type>( (*v)[nlua_swizzel_lookup[key[0]]], (*v)[nlua_swizzel_lookup[key[1]]], (*v)[nlua_swizzel_lookup[key[2]]] ) ); return 1;246 case 4 : push_vec( L, nv:: tvec4<typename T::value_type>( (*v)[nlua_swizzel_lookup[key[0]]], (*v)[nlua_swizzel_lookup[key[1]]], (*v)[nlua_swizzel_lookup[key[2]]], (*v)[nlua_swizzel_lookup[key[3]]] ) ); return 1;244 case 2 : push_vec( L, nv::math::tvec2<typename T::value_type>( (*v)[nlua_swizzel_lookup[key[0]]], (*v)[nlua_swizzel_lookup[key[1]]] ) ); return 1; 245 case 3 : push_vec( L, nv::math::tvec3<typename T::value_type>( (*v)[nlua_swizzel_lookup[key[0]]], (*v)[nlua_swizzel_lookup[key[1]]], (*v)[nlua_swizzel_lookup[key[2]]] ) ); return 1; 246 case 4 : push_vec( L, nv::math::tvec4<typename T::value_type>( (*v)[nlua_swizzel_lookup[key[0]]], (*v)[nlua_swizzel_lookup[key[1]]], (*v)[nlua_swizzel_lookup[key[2]]], (*v)[nlua_swizzel_lookup[key[3]]] ) ); return 1; 247 247 default: break; 248 248 } … … 258 258 int nlua_vec_newindex( lua_State* L ) 259 259 { 260 typedef nv:: tvec2<typename T::value_type> vec2;261 typedef nv:: tvec3<typename T::value_type> vec3;262 typedef nv:: tvec4<typename T::value_type> vec4;260 typedef nv::math::tvec2<typename T::value_type> vec2; 261 typedef nv::math::tvec3<typename T::value_type> vec3; 262 typedef nv::math::tvec4<typename T::value_type> vec4; 263 263 264 264 T* v = to_pvec<T>( L, 1 );
Note: See TracChangeset
for help on using the changeset viewer.