Changeset 454


Ignore:
Timestamp:
07/31/15 20:25:22 (10 years ago)
Author:
epyon
Message:
  • math library work
  • glm only referenced in math/common.hh
  • still a lot work to do, but its WURF
Location:
trunk
Files:
6 added
23 edited

Legend:

Unmodified
Added
Removed
  • trunk/nv/core/arcball.hh

    r453 r454  
    5050                        vec3 vb = get_arcball_vector( nposition );
    5151
    52                         m_angle = math::acos( glm::min( 1.0f, math::dot( va, vb ) ) );
    53                         m_axis  = glm::cross( va, vb );
     52                        m_angle = math::acos( math::min( 1.0f, math::dot( va, vb ) ) );
     53                        m_axis  = math::cross( va, vb );
    5454                        m_last  = nposition;
    5555                }
     
    6565                                p.z = sqrt( 1.0f - sq );
    6666                        else
    67                                 p = glm::normalize( p );
     67                                p = math::normalize( p );
    6868                        return p;
    6969                }
  • trunk/nv/core/position.hh

    r395 r454  
    279279                {
    280280                        if (r.contains(*this)) return false;
    281                         ul = glm::max( ul, r.ul );
    282                         lr = glm::min( lr, r.lr );
    283                         ul = glm::min( ul, lr );
     281                        ul = math::max( ul, r.ul );
     282                        lr = math::min( lr, r.lr );
     283                        ul = math::min( ul, lr );
    284284                        return true;
    285285                }
     
    294294                {
    295295                        if ( r.get_width() < get_width() || r.get_height() < get_height() ) return false;
    296                         ( *this ) += glm::min( r.ul - ul, position() );
    297                         ( *this ) -= glm::min( lr - r.lr, position() );
     296                        ( *this ) += math::min( r.ul - ul, position() );
     297                        ( *this ) -= math::min( lr - r.lr, position() );
    298298                        return true;
    299299                }
     
    315315                void include_point( position p )
    316316                {
    317                         lr = glm::max( lr, p );
    318                         ul = glm::min( ul, p );
     317                        lr = math::max( lr, p );
     318                        ul = math::min( ul, p );
    319319                }
    320320
  • trunk/nv/core/transform.hh

    r398 r454  
    2626                void set_orientation( const quat& a_orientation ) { m_orientation = a_orientation; }
    2727                void set_orientation( float radians, const vec3& axis )
    28                 { // use math::radians if degrees!
    29                         m_orientation = glm::angleAxis( radians, axis );
     28                {
     29                        m_orientation = math::angle_axis( radians, axis );
    3030                }
    3131
     
    3636                void move( const vec3& heading, float distance )
    3737                {
    38                         m_position += glm::normalize( heading ) * distance;
     38                        m_position += math::normalize( heading ) * distance;
    3939                }
    4040                void translate( const vec3& absolute )
     
    4242                        m_position += absolute;
    4343                }
    44 //              void rotate( const vec3& axis, f32 angle )
    45 //              { // use math::radians if degrees!
    46 //                      quat temp( angle, axis );
    47 //                      m_orientation = temp * m_orientation;
    48 //              }
     44                void rotate( const vec3& axis, f32 angle )
     45                {
     46                        quat temp( angle, axis );
     47                        m_orientation = temp * m_orientation;
     48                }
    4949                void set( const mat4& from )
    5050                {
     
    5454                mat4 extract() const
    5555                {
    56                         mat4 result = mat4_cast( m_orientation );
     56                        mat4 result = math::mat4_cast( m_orientation );
    5757                        result[3] = vec4( m_position, 1.0f );
    5858                        return result;
     
    6060                transform inverse() const
    6161                {
    62                         quat new_orient( glm::inverse( m_orientation ) );
     62                        quat new_orient( math::inverse( m_orientation ) );
    6363                        // TODO: simplify
    64                         return transform( -mat3_cast(new_orient) * m_position, new_orient );
     64                        return transform( -math::mat3_cast(new_orient) * m_position, new_orient );
    6565                }
    6666
     
    9999        {
    100100                return transform(
    101                         glm::mix  ( a.get_position(), b.get_position(), value ),
    102                         glm::slerp( a.get_orientation(), b.get_orientation(), value )
     101                        math::mix  ( a.get_position(), b.get_position(), value ),
     102                        math::slerp( a.get_orientation(), b.get_orientation(), value )
    103103                );
    104104        }
  • trunk/nv/gfx/animation.hh

    r423 r454  
    108108                                float time1 = fdata[index1 * static_cast<int>( keyfsize )];
    109109                                float delta = time1 - time0;
    110                                 factor = glm::clamp( ( time - time0 ) / delta, 0.0f, 1.0f );
     110                                factor = math::clamp( ( time - time0 ) / delta, 0.0f, 1.0f );
    111111                        }
    112112                        else
     
    117117                                        return keyfresult;
    118118                                }
    119                                 index0 = glm::clamp<int>( int( time ), 0, int( channel.size() ) - 2 );
     119                                index0 = math::clamp( int( time ), 0, int( channel.size() ) - 2 );
    120120                                index1 = index0 + 1;
    121                                 factor = glm::clamp<float>( time - index0, 0.0f, 1.0f );
     121                                factor = math::clamp( time - index0, 0.0f, 1.0f );
    122122                        }
    123123                        uint32 ret = 0;
     
    167167//                              return;
    168168//                      }
    169 //                      size_t index = glm::clamp<size_t>( size_t( frame ), 0, count - 2 );
    170 //                      float factor = glm::clamp<float> ( frame - index, 0.0f, 1.0f );
     169//                      size_t index = math::clamp( size_t( frame ), 0, count - 2 );
     170//                      float factor = math::clamp( frame - index, 0.0f, 1.0f );
    171171//                      interpolate_key( result, keys[index], keys[index+1], factor );
    172172//              }
     
    208208//                      NV_ASSERT( index >= 0, "animation time fail!");
    209209//                      float delta  = keys[index + 1].time - keys[index].time;
    210 //                      float factor = glm::clamp( (time - keys[index].time) / delta, 0.0f, 1.0f );
     210//                      float factor = math::clamp( (time - keys[index].time) / delta, 0.0f, 1.0f );
    211211//                      interpolate_key( result, keys[index], keys[index+1], factor );
    212212//              }
  • trunk/nv/interface/camera.hh

    r453 r454  
    2828                        m_view      = math::look_at( eye, focus, up );
    2929                        m_position  = eye;
    30                         m_direction = glm::normalize( focus - eye );
     30                        m_direction = math::normalize( focus - eye );
    3131                }
    3232
     
    7979                mat4 get_mvp()        const { return m_camera.get_projection() * get_modelview(); }
    8080
    81                 mat4 get_view_inv()   const { return glm::inverse( get_view() ); }
    82                 mat4 get_model_inv()  const { return glm::inverse( get_model() ); }
    83                 mat3 get_normal()     const { return glm::transpose(glm::inverse( mat3( get_modelview() ) ) ); }
     81                mat4 get_view_inv()   const { return math::inverse( get_view() ); }
     82                mat4 get_model_inv()  const { return math::inverse( get_model() ); }
     83                mat3 get_normal()     const { return math::transpose( math::inverse( mat3( get_modelview() ) ) ); }
    8484        protected:
    8585                mat4   m_model;
  • trunk/nv/interface/interpolation_template.hh

    r410 r454  
    8787
    8888                template < typename KEY >
    89                 mat4 extract_matrix_p_impl( const KEY& k ) { return glm::translate(mat4(),k.translation); }
    90                 template < typename KEY >
    91                 mat4 extract_matrix_r_impl( const KEY& k ) { return glm::mat4_cast( k.rotation ); }
    92                 template < typename KEY >
    93                 mat4 extract_matrix_s_impl( const KEY& k ) { return glm::scale(mat4(),k.scale); }
     89                mat4 extract_matrix_p_impl( const KEY& k ) { return math::translate(mat4(),k.translation); }
     90                template < typename KEY >
     91                mat4 extract_matrix_r_impl( const KEY& k ) { return math::mat4_cast( k.rotation ); }
     92                template < typename KEY >
     93                mat4 extract_matrix_s_impl( const KEY& k ) { return math::scale(mat4(),k.scale); }
    9494                template < typename KEY >
    9595                mat4 extract_matrix_pr_impl( const KEY& k )
    9696                {
    9797                        // TODO: this is obviously unoptimized
    98                         mat4 result = glm::mat4_cast( k.rotation );
     98                        mat4 result = math::mat4_cast( k.rotation );
    9999                        result[3] = vec4( k.translation, 1.0f );
    100100                        return result;
     
    104104                {
    105105                        // TODO: this is obviously unoptimized
    106                         mat4 result = glm::mat4_cast( k.rotation );
    107                         return glm::scale(result,k.scale);
     106                        mat4 result = math::mat4_cast( k.rotation );
     107                        return math::scale(result,k.scale);
    108108                }
    109109                template < typename KEY >
     
    111111                {
    112112                        // TODO: this is obviously unoptimized
    113                         return glm::scale(glm::translate(mat4(),k.translation),k.scale);
     113                        return math::scale( math::translate(mat4(),k.translation),k.scale);
    114114                }
    115115                template < typename KEY >
     
    117117                {
    118118                        // TODO: this is obviously unoptimized
    119                         return glm::translate(mat4(),k.translation) * glm::mat4_cast( k.rotation ) * glm::scale(mat4(),k.scale);
     119                        return math::translate(mat4(),k.translation) * math::mat4_cast( k.rotation ) * math::scale(mat4(),k.scale);
    120120                }
    121121
  • trunk/nv/lib/assimp.hh

    r406 r454  
    6868        {
    6969                const float* p = reinterpret_cast<const float*>( &m );
    70                 return glm::transpose( make_mat4( p ) );
     70                return math::transpose( make_mat4( p ) );
    7171        }
    7272
    7373        inline quat assimp_quat_cast( const aiQuaternion& q )
    7474        {
    75                 return nv::quat( q.w, q.x, q.y, q.z );
     75                return quat( q.w, q.x, q.y, q.z );
    7676        }
    7777
  • trunk/nv/stl/math.hh

    r453 r454  
    1010#define NV_STL_MATH_HH
    1111
    12 #include <nv/common.hh>
    1312#include <nv/stl/math/common.hh>
    1413#include <nv/stl/math/constants.hh>
     14#include <nv/stl/math/relational.hh>
     15#include <nv/stl/math/epsilon.hh>
    1516#include <nv/stl/math/geometric.hh>
     17#include <nv/stl/math/exponential.hh>
    1618#include <nv/stl/math/matrix_transform.hh>
     19#include <nv/stl/math/angle.hh>
     20#include <nv/stl/math/quaternion.hh>
     21
    1722#include <nv/stl/math/cast.hh>
    1823
     
    211216        T interpolate( const T& lhs, const T& rhs, float f )
    212217        {
    213                 return glm::mix( lhs, rhs, f );
     218                return math::mix( lhs, rhs, f );
    214219        }
    215220
     
    217222        inline quat interpolate( const quat& lhs, const quat& rhs, float f )
    218223        {
    219                 return glm::slerp( lhs, rhs, f );
     224                return math::slerp( lhs, rhs, f );
    220225        }
    221226
     
    227232        {
    228233                typename math::tvec3<T>::value_type sqr = x.x * x.x + x.y * x.y + x.z * x.z;
    229                 return ( sqr > 0 ? x * glm::inversesqrt(sqr) : def );
     234                return ( sqr > 0 ? x * math::inversesqrt(sqr) : def );
    230235        }
    231236
  • trunk/nv/stl/math/common.hh

    r453 r454  
    1515
    1616#include <nv/common.hh>
    17 #include <nv/stl/type_traits/common.hh>
    18 
     17#include <nv/stl/utility/common.hh>
     18#include <nv/stl/type_traits.hh>
    1919#if NV_COMPILER == NV_GNUC
    2020#pragma GCC system_header
     
    3333        namespace math
    3434        {
     35
     36                // TODO: Remove
     37                using glm::inverse;
     38                using glm::transpose;
     39
     40                using glm::detail::component_count_t;
     41                using glm::detail::component_count;
     42
     43                using glm::ctor;
     44
    3545                using ::cos;
    3646                using ::sin;
     
    3949                using ::cosh;
    4050                using ::sinh;
    41                 using ::abs;
    4251                using ::tan;
     52
    4353                using ::sqrt;
    4454                using ::pow;
     55                using ::log2;
     56                using ::log;
     57                using ::exp;
     58
    4559                using ::floor;
    46                 using ::ceil;
    4760                using ::round;
     61
    4862#if 0
    4963                template < typename T > using tvec2 = ::glm::detail::tvec2<T, glm::precision::highp>;
     
    6175                template < typename T > using tmat3 = ::glm::tmat3x3<T>;
    6276                template < typename T > using tmat4 = ::glm::tmat4x4<T>;
    63                 template < typename T > using tquat = ::glm::tquat<T,glm::highp>;
     77                template < typename T > using tquat = ::glm::tquat<T, glm::highp>;
    6478#endif
    6579
    6680                typedef glm::quat quat;
    67                 using glm::ctor;
     81
     82                template < typename T > struct is_vec : false_type {};
     83                template < typename T > struct is_mat : false_type {};
     84                template < typename T > struct is_quat : false_type {};
     85
     86                template < typename T > struct is_fp : is_floating_point< T > {};
     87                template < typename T > struct is_fp_vec : false_type {};
     88                template < typename T > struct is_fp_mat : false_type {};
     89                template < typename T > struct is_fp_quat : false_type {};
     90
     91                template < typename T > struct is_bool_vec : false_type {};
     92
     93                template < typename T > struct is_vec < tvec2< T > > : true_type {};
     94                template < typename T > struct is_vec < tvec3< T > > : true_type {};
     95                template < typename T > struct is_vec < tvec4< T > > : true_type {};
     96                template < typename T > struct is_mat < tmat2< T > > : true_type {};
     97                template < typename T > struct is_mat < tmat3< T > > : true_type {};
     98                template < typename T > struct is_mat < tmat4< T > > : true_type {};
     99                template < typename T > struct is_quat< tquat< T > > : true_type {};
     100
     101                template < typename T > struct is_fp     < tvec2< T > > : is_floating_point< T > {};
     102                template < typename T > struct is_fp     < tvec3< T > > : is_floating_point< T > {};
     103                template < typename T > struct is_fp     < tvec4< T > > : is_floating_point< T > {};
     104                template < typename T > struct is_fp_vec < tvec2< T > > : is_floating_point< T > {};
     105                template < typename T > struct is_fp_vec < tvec3< T > > : is_floating_point< T > {};
     106                template < typename T > struct is_fp_vec < tvec4< T > > : is_floating_point< T > {};
     107                template < typename T > struct is_fp_mat < tmat2< T > > : is_floating_point< T > {};
     108                template < typename T > struct is_fp_mat < tmat3< T > > : is_floating_point< T > {};
     109                template < typename T > struct is_fp_mat < tmat4< T > > : is_floating_point< T > {};
     110                template < typename T > struct is_fp_quat< tquat< T > > : is_floating_point< T > {};
     111
     112                template <> struct is_bool_vec < tvec2< bool > > : true_type {};
     113                template <> struct is_bool_vec < tvec3< bool > > : true_type {};
     114                template <> struct is_bool_vec < tvec4< bool > > : true_type {};
     115
     116                namespace detail
     117                {
     118                        template < typename Vec, typename R = value_type_t<Vec>, typename T = value_type_t<Vec> >
     119                        struct unary_functor {};
     120
     121                        template < typename R, typename T >
     122                        struct unary_functor< tvec2< T >, R, T >
     123                        {
     124                                inline static tvec2<R> call( R( *func )( T ), const tvec2<T>& v )
     125                                {
     126                                        return tvec2<R>( func( v.x ), func( v.y ) );
     127                                }
     128                        };
     129
     130                        template < typename R, typename T >
     131                        struct unary_functor< tvec3< T >, R, T >
     132                        {
     133                                inline static tvec3<R> call( R( *func )( T ), const tvec3<T>& v )
     134                                {
     135                                        return tvec3<R>( func( v.x ), func( v.y ), func( v.z ) );
     136                                }
     137                        };
     138
     139                        template < typename R, typename T >
     140                        struct unary_functor< tvec4< T >, R, T >
     141                        {
     142                                inline static tvec4<R> call( R( *Func ) ( T x ), const tvec4<T>& v )
     143                                {
     144                                        return tvec4<R>( func( v.x ), func( v.y ), func( v.z ), func( v.w ) );
     145                                }
     146                        };
     147
     148                        template < typename Vec, typename T = value_type_t<Vec> >
     149                        struct binary_functor {};
     150
     151                        template < typename T >
     152                        struct binary_functor< tvec2< T >, T >
     153                        {
     154                                inline static tvec2<T> call( T( *func ) ( T, T ), const tvec2<T>& a, const tvec2<T>& b )
     155                                {
     156                                        return tvec2<T>( func( a.x, b.x ), func( a.y, b.y ) );
     157                                }
     158                        };
     159
     160                        template < typename T >
     161                        struct binary_functor< tvec3< T >, T >
     162                        {
     163                                inline static tvec3<T> call( T( *func ) ( T, T ), const tvec3<T>& a, const tvec3<T>& b )
     164                                {
     165                                        return tvec3<T>( func( a.x, b.x ), func( a.y, b.y ), func( a.z, b.z ) );
     166                                }
     167                        };
     168
     169                        template < typename T >
     170                        struct binary_functor< tvec4< T >, T >
     171                        {
     172                                inline static tvec4<T> call( T( *func ) ( T, T ), const tvec4<T>& a, const tvec4<T>& b )
     173                                {
     174                                        return tvec4<T>( func( a.x, b.x ), func( a.y, b.y ), func( a.z, b.z ), func( a.w, b.w ) );
     175                                }
     176                        };
     177
     178                        template < typename Vec, typename T = value_type_t<Vec> >
     179                        struct binary_scalar_functor {};
     180
     181                        template < typename T >
     182                        struct binary_scalar_functor< tvec2< T >, T >
     183                        {
     184                                inline static tvec2<T> call( T( *func ) ( T, T ), const tvec2<T>& a, T b )
     185                                {
     186                                        return tvec2<T>( func( a.x, b ), func( a.y, b ) );
     187                                }
     188                        };
     189
     190                        template < typename T >
     191                        struct binary_scalar_functor< tvec3< T >, T >
     192                        {
     193                                inline static tvec3<T> call( T( *func ) ( T, T ), const tvec3<T>& a, T b )
     194                                {
     195                                        return tvec3<T>( func( a.x, b ), func( a.y, b ), func( a.z, b ) );
     196                                }
     197                        };
     198
     199                        template < typename T >
     200                        struct binary_scalar_functor< tvec4< T >, T >
     201                        {
     202                                inline static tvec4<T> call( T( *func ) ( T, T ), const tvec4<T>& a, T b )
     203                                {
     204                                        return tvec4<T>( func( a.x, b ), func( a.y, b ), func( a.z, b ), func( a.w, b ) );
     205                                }
     206                        };
     207                }
    68208        }
    69 
    70         template < typename T >
    71         struct is_math_vector : false_type {};
    72 
    73         template < typename T >
    74         struct is_math_matrix : false_type {};
    75 
    76         template < typename T >
    77         struct is_math_quat : false_type {};
    78 
    79         template < typename T >
    80         struct is_math_class : bool_constant<
    81                 is_math_vector< T >::value ||
    82                 is_math_matrix< T >::value ||
    83                 is_math_quat< T >::value
    84         > {};
    85 
    86         template < typename T > struct is_math_vector< math::tvec2< T > > : true_type {};
    87         template < typename T > struct is_math_vector< math::tvec3< T > > : true_type {};
    88         template < typename T > struct is_math_vector< math::tvec4< T > > : true_type {};
    89         template < typename T > struct is_math_matrix< math::tmat2< T > > : true_type {};
    90         template < typename T > struct is_math_matrix< math::tmat3< T > > : true_type {};
    91         template < typename T > struct is_math_matrix< math::tmat4< T > > : true_type {};
    92         template < typename T > struct is_math_quat  < math::tquat< T > > : true_type {};
    93209
    94210        typedef math::tvec2<sint8> i8vec2;
     
    118234        typedef math::quat quat;
    119235
     236
     237
     238        template < typename T >
     239        struct make_unsigned< math::tvec2< T > >
     240        {
     241                typedef math::tvec2< make_unsigned_t< T > > type;
     242        };
     243
     244        template < typename T >
     245        struct make_unsigned< math::tvec3< T > >
     246        {
     247                typedef math::tvec3< make_unsigned_t< T > > type;
     248        };
     249
     250        template < typename T >
     251        struct make_unsigned< math::tvec4< T > >
     252        {
     253                typedef math::tvec4< make_unsigned_t< T > > type;
     254        };
     255
     256        template < typename T >
     257        struct make_signed< math::tvec2< T > >
     258        {
     259                typedef math::tvec2< make_signed_t< T > > type;
     260        };
     261
     262        template < typename T >
     263        struct make_signed< math::tvec3< T > >
     264        {
     265                typedef math::tvec3< make_signed_t< T > > type;
     266        };
     267
     268        template < typename T >
     269        struct make_signed< math::tvec4< T > >
     270        {
     271                typedef math::tvec4< make_signed_t< T > > type;
     272        };
     273
    120274}
    121275
  • trunk/nv/stl/math/geometric.hh

    r453 r454  
    1515
    1616#include <nv/stl/math/common.hh>
     17#include <nv/stl/math/basic.hh>
     18#include <nv/stl/math/exponential.hh>
    1719
    1820namespace nv
     
    5860                }
    5961
    60                 template < typename T >
     62                template < typename T, typename enable_if< is_floating_point<T>::value >::type* = nullptr >
    6163                inline T length( T x )
    6264                {
    63                         static_assert( is_floating_point<T>::value, "Type expected to be floating point!" );
    6465                        return abs( x );
    6566                }
    6667
    67                 template < typename T, template <typename> class Vec >
    68                 inline T length( const Vec<T>& v )
     68                template < typename T, typename enable_if< is_fp_vec<T>::value >::type* = nullptr >
     69                inline value_type_t<T> length( const T& v )
    6970                {
    70                         static_assert( is_math_vector< Vec<T> >::value, "math::vecX expected!" );
    71                         static_assert( is_floating_point<T>::value, "Type expected to be floating point!" );
    7271                        return sqrt( dot( v, v ) );
    7372                }
    7473
    75                 template <typename T>
    76                 inline T distance( const T& a, const T& b )
     74                template < typename T, typename enable_if< is_floating_point<T>::value >::type* = nullptr >
     75                inline T distance( T a, T b )
    7776                {
    78                         static_assert( is_floating_point<T>::value, "Type expected to be floating point!" );
    7977                        return length( b - a );
    8078                }
    8179
    82                 template < typename T, template <typename> class Vec >
    83                 inline T distance( const Vec<T>& a, const Vec<T>& b )
     80                template < typename T, typename enable_if< is_fp_vec<T>::value >::type* = nullptr >
     81                inline value_type_t<T> distance( const T& a, const T& b )
    8482                {
    85                         static_assert( is_math_vector< Vec<T> >::value, "math::vecX expected!" );
    86                         static_assert( is_floating_point<T>::value, "Type expected to be floating point!" );
    8783                        return length( b - a );
    8884                }
    8985
    90                 template < typename T >
     86                template < typename T, typename enable_if< is_floating_point<T>::value >::type* = nullptr >
    9187                inline T dot( T a, T b )
    9288                {
     
    9591                }
    9692
    97                 template < typename T, template <typename> class Vec >
    98                 inline T dot( const Vec<T>& a, const Vec<T>& b )
     93                template < typename T, typename enable_if< is_fp_vec<T>::value >::type* = nullptr >
     94                inline value_type_t<T> dot( const T& a, const T& b )
    9995                {
    100                         static_assert( is_math_vector< Vec<T> >::value, "math::vecX expected!" );
    101                         static_assert( is_floating_point<T>::value, "Type expected to be floating point!" );
    102                         return detail::dot_impl< Vec, T >::get( a, b );
     96                        return detail::dot_impl< T >::get( a, b );
    10397                }
    10498
    105                 template < typename T >
     99                template < typename T, typename enable_if< is_floating_point<T>::value >::type* = nullptr >
    106100                inline tvec3<T> cross( const tvec3<T>& a, const tvec3<T>& b )
    107101                {
    108                         static_assert( is_floating_point<T>::value, "Type expected to be floating point!" );
    109102                        return tvec3<T>(
    110                                 a.y * b.z - y.y * b.z,
    111                                 a.z * b.x - y.z * b.x,
    112                                 a.x * b.y - y.x * b.y
     103                                a.y * b.z - b.y * a.z,
     104                                a.z * b.x - b.z * a.x,
     105                                a.x * b.y - b.x * a.y
    113106                        );
    114107                }
    115108
    116                 template < typename T >
    117                 inline T normalize( const T& x )
     109                template < typename T, typename enable_if< is_floating_point<T>::value >::type* = nullptr >
     110                inline T normalize( T x )
    118111                {
    119                         static_assert( is_floating_point<T>::value, "Type expected to be floating point!" );
    120112                        return x < T( 0 ) ? T( -1 ) : T( 1 );
    121113                }
    122114
    123                 template < typename T, template <typename> class Vec >
    124                 inline Vec<T> normalize( const Vec<T>& x )
     115                template < typename T, typename enable_if< is_fp_vec<T>::value >::type* = nullptr >
     116                inline T normalize( const T& x )
    125117                {
    126                         static_assert( is_math_vector< Vec<T> >::value, "math::vecX expected!" );
    127                         static_assert( is_floating_point<T>::value, "Type expected to be floating point!" );
    128118                        return x * inversesqrt( dot( x, x ) );
    129119                }
    130120
    131                 template < typename T >
    132                 inline T faceforward( const T& n, const T& i, const T& nref )
     121                template < typename T, typename enable_if< is_floating_point<T>::value >::type* = nullptr >
     122                inline T faceforward( T n, T i, T nref )
    133123                {
    134124                        return dot( nref, i ) < static_cast<T>( 0 ) ? n : -n;
    135125                }
    136126
    137                 template < typename T, template <typename> class Vec >
    138                 inline Vec<T> faceforward( const Vec<T>& n, const Vec<T>& i, const Vec<T>& nref )
     127                template < typename T, typename enable_if< is_fp_vec<T>::value >::type* = nullptr >
     128                inline T faceforward( const T& n, const T& i, const T& nref )
    139129                {
    140                         static_assert( is_math_vector< Vec<T> >::value, "math::vecX expected!" );
    141                         return dot( nref, i ) < static_cast<T>( 0 ) ? n : -n;
     130                        return dot( nref, i ) < static_cast<value_type_t<T>>( 0 ) ? n : -n;
    142131                }
    143132
    144                 template < typename T >
     133                template < typename T, typename enable_if< is_fp<T>::value >::type* = nullptr >
    145134                inline T reflect( const T& i, const T& n )
    146135                {
     
    148137                }
    149138
    150                 template < typename T >
     139                template < typename T, typename enable_if< is_floating_point<T>::value >::type* = nullptr >
    151140                inline T refract( const T& i, const T& n, const T& eta )
    152141                {
    153                         static_assert( is_floating_point<T>::value, "Type expected to be floating point!" );
    154 
    155142                        const T dotv( dot( n, i ) );
    156143                        const T k( static_cast<T>( 1 ) - eta * eta * ( static_cast<T>( 1 ) - dotv * dotv ) );
     
    158145                }
    159146
    160                 template < typename T, template <typename> class Vec >
    161                 inline Vec<T> refract( const Vec<T>& i, const Vec<T>& n, T eta )
     147                template < typename T, typename enable_if< is_fp_vec<T>::value >::type* = nullptr >
     148                inline T refract( const T& i, const T& n, value_type_t<T> eta )
    162149                {
    163                         static_assert( is_math_vector< Vec<T> >::value, "math::vecX expected!" );
    164                         static_assert( is_floating_point<T>::value, "Type expected to be floating point!" );
     150                        typedef value_type_t<T> value_type;
    165151
    166                         T const dotv( dot( n, i ) );
    167                         T const k( static_cast<T>( 1 ) - eta * eta * ( static_cast<T>( 1 ) - dotv * dotv ) );
    168                         return ( eta * i - ( eta * dotv + sqrt( k ) ) * n ) * static_cast<T>( k >= static_cast<T>( 0 ) );
     152                        value_type const dotv( dot( n, i ) );
     153                        value_type const k( static_cast<T>( 1 ) - eta * eta * ( static_cast<value_type>( 1 ) - dotv * dotv ) );
     154                        return ( eta * i - ( eta * dotv + sqrt( k ) ) * n ) * static_cast<value_type>( k >= static_cast<value_type>( 0 ) );
    169155                }
    170156
  • trunk/nv/stl/math/matrix_transform.hh

    r451 r454  
    3737                        T const s = math::sin( a );
    3838
    39                         tvec3<T> axis( glm::normalize( v ) );
     39                        tvec3<T> axis( normalize( v ) );
    4040                        tvec3<T> temp( ( T( 1 ) - c ) * axis );
    4141
     
    7070                        result[3] = m[3];
    7171                        return result;
     72                }
     73
     74                template < typename T >
     75                inline tmat4<T> translate( const tvec3<T>& v )
     76                {
     77                        return translate( tmat4<T>( 1.0f ), v );
     78                }
     79
     80                template < typename T >
     81                inline tmat4<T> rotate( T angle, const tvec3<T>& v )
     82                {
     83                        return rotate( tmat4<T>( 1.0f ), angle, v );
     84                }
     85
     86                template < typename T >
     87                inline tmat4<T> scale( const tvec3<T>& v )
     88                {
     89                        return scale( tmat4<T>( 1.0f ), v );
    7290                }
    7391
     
    183201                inline tvec3<T> unproject( const tvec3<T>& win, const tmat4<T>& model, const tmat4<T>& proj, const tvec4<U>& viewport )
    184202                {
    185                         tmat4<T> invp = glm::inverse( proj * model );
     203                        tmat4<T> invp = inverse( proj * model );
    186204
    187205                        tvec4<T> temp = tvec4<T>( win, T( 1 ) );
     
    215233                inline tmat4<T> look_at( const tvec3<T>& eye, const tvec3<T>& center, const tvec3<T>& up )
    216234                {
    217                         const tvec3<T> f( glm::normalize( center - eye ) );
    218                         const tvec3<T> s( glm::normalize( glm::cross( f, up ) ) );
    219                         const tvec3<T> u( glm::cross( s, f ) );
     235                        const tvec3<T> f( normalize( center - eye ) );
     236                        const tvec3<T> s( normalize( cross( f, up ) ) );
     237                        const tvec3<T> u( cross( s, f ) );
    220238
    221239                        tmat4<T> result( 1 );
     
    229247                        result[1][2] = -f.y;
    230248                        result[2][2] = -f.z;
    231                         result[3][0] = -glm::dot( s, eye );
    232                         result[3][1] = -glm::dot( u, eye );
    233                         result[3][2] = glm::dot( f, eye );
     249                        result[3][0] = -dot( s, eye );
     250                        result[3][1] = -dot( u, eye );
     251                        result[3][2] = dot( f, eye );
    234252                        return result;
    235253                }
  • trunk/nv/stl/type_traits/common.hh

    r402 r454  
    227227                return detail::addressof_impl<T>::f( detail::addressof_helper<T>( v ), 0 );
    228228        }
     229
     230
     231        template < typename T >
     232        struct extract_value_type
     233        {
     234                typedef typename T::value_type type;
     235        };
     236
     237        template < typename T >
     238        struct extract_size_type
     239        {
     240                typedef typename T::size_type type;
     241        };
     242
     243        template < typename T >
     244        using value_type_t = typename extract_value_type<T>::type;
     245        template < typename T >
     246        using size_type_t = typename extract_size_type<T>::type;
    229247
    230248        namespace detail
  • trunk/nv/stl/type_traits/transforms.hh

    r410 r454  
    8282                        typedef signed_type< remove_cv_t<T> > signed_type_result;
    8383                public:
    84                         typedef match_cv< T, typename signed_type_result::type > type;
     84                        typedef typename match_cv< T, typename signed_type_result::type >::type type;
    8585                };
    8686
     
    107107                        typedef unsigned_type<remove_cv_t<T>> unsigned_type_result;
    108108                public:
    109                         typedef match_cv< T, typename unsigned_type_result::type > type;
     109                        typedef typename match_cv< T, typename unsigned_type_result::type >::type type;
    110110                };
    111111
  • trunk/src/core/random.cc

    r451 r454  
    231231        vec2 opoint     = ellipse_edge( oradii );
    232232        vec2 opoint2    = opoint * opoint;
    233         vec2 odir       = glm::normalize( opoint );
     233        vec2 odir       = math::normalize( opoint );
    234234        f32 odist2    = opoint2.x + opoint2.y;
    235235
     
    251251        vec3 opoint     = ellipsoid_edge( oradii );
    252252        vec3 opoint2    = opoint * opoint;
    253         vec3 odir       = glm::normalize( opoint );
     253        vec3 odir       = math::normalize( opoint );
    254254        f32 odist2    = opoint2.x + opoint2.y + opoint2.z;
    255255
  • trunk/src/engine/particle_engine.cc

    r453 r454  
    231231        datap->plane_normal = normalize_safe( datap->plane_normal, vec3(0.0f,1.0f,0.0f) );
    232232        datap->bounce       = table->get<float>("bounce", 0.0f );
    233         datap->distance     = -glm::dot( datap->plane_normal, datap->plane_point ) / math::sqrt(glm::dot( datap->plane_normal, datap->plane_normal ) );
     233        datap->distance     = -math::dot( datap->plane_normal, datap->plane_point ) / math::sqrt( math::dot( datap->plane_normal, datap->plane_normal ) );
    234234        return true;
    235235}
     
    242242                particle& pt = p[i];
    243243                vec3 direction  = pt.velocity * factor;
    244                 if ( glm::dot( datap->plane_normal, pt.position + direction ) + datap->distance <= 0.0f )
     244                if ( math::dot( datap->plane_normal, pt.position + direction ) + datap->distance <= 0.0f )
    245245                {
    246                         float val = glm::dot( datap->plane_normal, pt.position ) + datap->distance;
     246                        float val = math::dot( datap->plane_normal, pt.position ) + datap->distance;
    247247                        if ( val > 0.0f )
    248248                        {
    249                                 vec3 part_dir = direction * ( -val / glm::dot( datap->plane_normal, direction ) );
     249                                vec3 part_dir = direction * ( -val / math::dot( datap->plane_normal, direction ) );
    250250                                pt.position = pt.position + part_dir + ( part_dir - direction ) * datap->bounce;
    251                                 pt.velocity = glm::reflect( pt.velocity, datap->plane_normal ) * datap->bounce;
     251                                pt.velocity = math::reflect( pt.velocity, datap->plane_normal ) * datap->bounce;
    252252                        }
    253253                }
     
    273273        for ( uint32 i = 0; i < count; ++i )
    274274        {
    275                 p[i].color = glm::clamp( p[i].color + adjustment, 0.0f, 1.0f );
     275                p[i].color = math::clamp( p[i].color + adjustment, 0.0f, 1.0f );
    276276        }
    277277}
     
    296296        for ( uint32 i = 0; i < count; ++i )
    297297        {
    298                 p[i].size = glm::max( p[i].size + adjustment, vec2() );
     298                p[i].size = math::max( p[i].size + adjustment, vec2() );
    299299        }
    300300}
     
    347347        }
    348348
    349         data.common_up  = glm::normalize( table.get<vec3>("common_up",  vec3(1,0,0) ) );
    350         data.common_dir = glm::normalize( table.get<vec3>("common_dir", vec3(0,1,0) ) );
     349        data.common_up  = math::normalize( table.get<vec3>("common_up",  vec3(1,0,0) ) );
     350        data.common_dir = math::normalize( table.get<vec3>("common_dir", vec3(0,1,0) ) );
    351351
    352352        vec2 def_size        = table.get<vec2>("size", vec2(0.1,0.1) );
     
    409409
    410410                                edata.rate         = element.get<float>("rate", 1.0f );
    411                                 edata.dir          = glm::normalize( element.get<vec3>("direction", vec3(0,1,0) ) );
     411                                edata.dir          = math::normalize( element.get<vec3>("direction", vec3(0,1,0) ) );
    412412                               
    413413                                edata.odir = vec3( 0, 0, 1 );
    414414                                if ( edata.dir != vec3( 0, 1, 0 ) && edata.dir != vec3( 0, -1, 0 ) )
    415                                         edata.odir = glm::normalize( glm::cross( edata.dir, vec3( 0, 1, 0 ) ) );                edata.cdir = glm::cross( edata.dir, edata.odir );
     415                                        edata.odir = math::normalize( math::cross( edata.dir, vec3( 0, 1, 0 ) ) );
     416                                edata.cdir = math::cross( edata.dir, edata.odir );
    416417
    417418                                data.emmiter_count++;
     
    563564                m_model_matrix = s.get_model();
    564565                m_camera_pos   = s.get_camera().get_position();
    565                 m_inv_view_dir = glm::normalize(-s.get_camera().get_direction());
     566                m_inv_view_dir = math::normalize(-s.get_camera().get_direction());
    566567
    567568                update_emmiters( info, m_last_update );
     
    636637
    637638                vec3 view_dir( m_inv_view_dir );
    638                 if ( accurate_facing ) view_dir = glm::normalize( m_camera_pos - pdata.position );
     639                if ( accurate_facing ) view_dir = math::normalize( m_camera_pos - pdata.position );
    639640
    640641                switch ( orientation )
    641642                {
    642643                case particle_orientation::POINT :
    643                         right   = glm::normalize( glm::cross( view_dir, vec3( 0, 1, 0 ) ) );
    644                         rot_mat = mat3( right, glm::cross( right, -view_dir ), -view_dir );
     644                        right   = math::normalize( math::cross( view_dir, vec3( 0, 1, 0 ) ) );
     645                        rot_mat = mat3( right, math::cross( right, -view_dir ), -view_dir );
    645646                        break;
    646647                case particle_orientation::ORIENTED :
    647648                        pdir    = normalize_safe( pdata.velocity, pdir );
    648                         right   = glm::normalize( glm::cross( pdir, view_dir ) );
    649                         rot_mat = mat3( right, pdir, glm::cross( pdir, right ) );
     649                        right   = math::normalize( math::cross( pdir, view_dir ) );
     650                        rot_mat = mat3( right, pdir, math::cross( pdir, right ) );
    650651                        break;
    651652                case particle_orientation::ORIENTED_COMMON :
    652                         right   = glm::normalize( glm::cross( common_dir, view_dir ) );
    653                         rot_mat = mat3( right, common_dir, glm::cross( common_dir, right ) );
     653                        right   = math::normalize( math::cross( common_dir, view_dir ) );
     654                        rot_mat = mat3( right, common_dir, math::cross( common_dir, right ) );
    654655                        break;
    655656                case particle_orientation::PERPENDICULAR :
    656657                        pdir    = normalize_safe( pdata.velocity, pdir );
    657                         right   = glm::normalize( glm::cross( common_up, pdir ) );
    658                         rot_mat = mat3( right, common_up, glm::cross( common_up, right ) );
     658                        right   = math::normalize( math::cross( common_up, pdir ) );
     659                        rot_mat = mat3( right, common_up, math::cross( common_up, right ) );
    659660                        break;
    660661                case particle_orientation::PERPENDICULAR_COMMON :
    661                         right   = glm::normalize( glm::cross( common_up, common_dir ) );
    662                         rot_mat = mat3( right, common_up, glm::cross( common_up, right ) );
     662                        right   = math::normalize( math::cross( common_up, common_dir ) );
     663                        rot_mat = mat3( right, common_up, math::cross( common_up, right ) );
    663664                        break;
    664665                }
  • trunk/src/formats/assimp_loader.cc

    r451 r454  
    134134                {
    135135                        vec3 v = assimp_vec3_cast( mesh->mVertices[i] );
    136                         vec3 n = glm::normalize( assimp_vec3_cast( mesh->mNormals[i] ) );
    137                         vec3 t = glm::normalize( assimp_vec3_cast( mesh->mTangents[i] ) );
    138                         vec3 b = glm::normalize( assimp_vec3_cast( mesh->mBitangents[i] ) );
     136                        vec3 n = math::normalize( assimp_vec3_cast( mesh->mNormals[i] ) );
     137                        vec3 t = math::normalize( assimp_vec3_cast( mesh->mTangents[i] ) );
     138                        vec3 b = math::normalize( assimp_vec3_cast( mesh->mBitangents[i] ) );
    139139                        vec2 s = assimp_st_cast( mesh->mTextureCoords[0][i] );
    140140
    141                         vec3 t_i = glm::normalize( t - n * glm::dot( n, t ) );
    142                         float det = ( glm::dot( glm::cross( n, t ), b ) );
     141                        vec3 t_i = math::normalize( t - n * math::dot( n, t ) );
     142                        float det = ( math::dot( math::cross( n, t ), b ) );
    143143                        det = ( det < 0.0f ? -1.0f : 1.0f );
    144144                        nv::vec4 vt( t_i[0], t_i[1], t_i[2], det );
     
    441441//      {
    442442//              vec3 scale_vec0 = assimp_vec3_cast( node->mScalingKeys[0].mValue );
    443 //              float scale_value   = glm::length( math::abs( scale_vec0 - vec3(1,1,1) ) );
     443//              float scale_value   = math::length( math::abs( scale_vec0 - vec3(1,1,1) ) );
    444444//              if ( node->mNumScalingKeys > 1 || scale_value > 0.001 )
    445445//              {
  • trunk/src/formats/obj_loader.cc

    r442 r454  
    283283                        if ( ! (tv.x == 0.0f && tv.y == 0.0f && tv.z == 0.0f) )
    284284                        {
    285                                 m_data[a].tangent    = vec4( glm::normalize(tv - nv * glm::dot( nv, tv )), 0.0f );
    286                                 m_data[a].tangent[3] = (glm::dot(glm::cross(nv, tv), tan2[a]) < 0.0f) ? -1.0f : 1.0f;
     285                                m_data[a].tangent    = vec4( math::normalize(tv - nv * math::dot( nv, tv )), 0.0f );
     286                                m_data[a].tangent[3] = ( math::dot( math::cross(nv, tv), tan2[a]) < 0.0f) ? -1.0f : 1.0f;
    287287                        }
    288288                }
  • trunk/src/gfx/keyframed_mesh.cc

    r451 r454  
    217217                for ( size_t i = 0; i < m_vertex_count; ++i )
    218218                {
    219                         vtx[i].position = glm::mix( prev[i].position, next[i].position, m_interpolation );
    220                         vtx[i].normal   = glm::mix( prev[i].normal,   next[i].normal,   m_interpolation );
    221                         vtx[i].tangent  = glm::mix( prev[i].tangent,  next[i].tangent,   m_interpolation );
     219                        vtx[i].position = math::mix( prev[i].position, next[i].position, m_interpolation );
     220                        vtx[i].normal   = math::mix( prev[i].normal,   next[i].normal,   m_interpolation );
     221                        vtx[i].tangent  = math::mix( prev[i].tangent,  next[i].tangent,   m_interpolation );
    222222                }
    223223        }
     
    231231                for ( size_t i = 0; i < m_vertex_count; ++i )
    232232                {
    233                         vtx[i].position = glm::mix( prev[i].position, next[i].position, m_interpolation );
    234                         vtx[i].normal   = glm::mix( prev[i].normal,   next[i].normal,   m_interpolation );
     233                        vtx[i].position = math::mix( prev[i].position, next[i].position, m_interpolation );
     234                        vtx[i].normal   = math::mix( prev[i].normal,   next[i].normal,   m_interpolation );
    235235                }
    236236        }
  • trunk/src/gfx/mesh_creator.cc

    r430 r454  
    9595void nv::mesh_nodes_creator::transform( float scale, const mat3& r33 )
    9696{
    97         mat3 ri33 = glm::inverse( r33 );
     97        mat3 ri33 = math::inverse( r33 );
    9898        mat4 pre_transform ( scale * r33 );
    9999        mat4 post_transform( 1.f/scale * ri33 );
     
    150150                        {
    151151                                vec3& n = *reinterpret_cast<vec3*>( raw_data + vtx_size*i + n_offset );
    152                                 n = glm::normalize( normal_transform * n );
     152                                n = math::normalize( normal_transform * n );
    153153                        }
    154154                if ( t_offset != -1 )
     
    156156                        {
    157157                                vec4& t = *reinterpret_cast<vec4*>(raw_data + vtx_size*i + t_offset );
    158                                 t = vec4( glm::normalize( normal_transform * vec3(t) ), t[3] );
     158                                t = vec4( math::normalize( normal_transform * vec3(t) ), t[3] );
    159159                        }
    160160        }
     
    299299                        vec3 xyz2 = v2 - v1;
    300300
    301                         //vec3 normal = glm::cross( xyz1, xyz2 );
     301                        //vec3 normal = math::cross( xyz1, xyz2 );
    302302                        //
    303303                        //vtcs[ ti0 ].normal += normal;
     
    323323                if ( ! ( t.x == 0.0f && t.y == 0.0f && t.z == 0.0f ) )
    324324                {
    325                         tangents[i]    = vec4( glm::normalize(t - n * glm::dot( n, t )), 0.0f );
    326                         tangents[i][3] = (glm::dot(glm::cross(n, t), tangents2[i]) < 0.0f) ? -1.0f : 1.0f;
     325                        tangents[i]    = vec4( math::normalize(t - n * math::dot( n, t )), 0.0f );
     326                        tangents[i][3] = ( math::dot( math::cross(n, t), tangents2[i]) < 0.0f) ? -1.0f : 1.0f;
    327327                }
    328328        }
  • trunk/src/lua/lua_area.cc

    r449 r454  
    255255        nv::rectangle* a = to_parea( L, 1 );
    256256        nv::ivec2*     c = to_pcoord( L, 2 );
    257         *c = glm::clamp( *c, a->ul, a->lr );
     257        *c = nv::math::clamp( *c, a->ul, a->lr );
    258258        return 0;
    259259}
     
    263263        nv::rectangle* a = to_parea( L, 1 );
    264264        nv::ivec2*     c = to_pcoord( L, 2 );
    265         push_coord( L, glm::clamp( *c, a->ul, a->lr ) );
     265        push_coord( L, nv::math::clamp( *c, a->ul, a->lr ) );
    266266        return 0;
    267267}
  • trunk/src/lua/lua_values.cc

    r449 r454  
    2525void* nv::lua::detail::raw_check_userdata( lua_State *L, int index, const char* metatable )
    2626{
    27         return luaL_checkudata( L, index, metatable );
     27        return luaL_testudata( L, index, metatable );
    2828}
    2929
  • trunk/src/rogue/fov_recursive_shadowcasting.cc

    r406 r454  
    2424        {
    2525                position max_radius = m_size-m_position;
    26                 max_radius = glm::max(max_radius,m_position);
    27                 m_radius = static_cast<int>( glm::length( vec2( max_radius ) ) )+1;
     26                max_radius = math::max(max_radius,m_position);
     27                m_radius = static_cast<int>( math::length( vec2( max_radius ) ) )+1;
    2828        }
    2929        m_radius2 = m_radius * m_radius;
  • trunk/src/sdl/sdl_audio.cc

    r453 r454  
    7575                        if ( relative != vec3() )
    7676                        {
    77                                 angle = math::degrees( -glm::orientedAngle( m_forward, glm::normalize( relative ), m_up ) );
    78                                 distance = glm::clamp( 20.0f * glm::length( relative ), 0.0f, 255.0f );
     77                                angle = math::degrees( -math::oriented_angle( m_forward, math::normalize( relative ), m_up ) );
     78                                distance = math::clamp( 20.0f * math::length( relative ), 0.0f, 255.0f );
    7979                        }
    8080                        if ( angle < 0.0f ) angle += 360.0f;
Note: See TracChangeset for help on using the changeset viewer.