Changeset 398


Ignore:
Timestamp:
06/13/15 11:20:22 (10 years ago)
Author:
epyon
Message:
  • cleanup of glm usage
Location:
trunk
Files:
14 edited

Legend:

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

    r395 r398  
    1616#include <nv/common.hh>
    1717#include <nv/stl/math.hh>
     18#include <nv/stl/utility/common.hh>
    1819
    1920namespace nv
     
    4647                void drag( ivec2 nposition )
    4748                {
    48                         glm::vec3 va = get_arcball_vector( m_last );
    49                         glm::vec3 vb = get_arcball_vector( nposition );
     49                        vec3 va = get_arcball_vector( m_last );
     50                        vec3 vb = get_arcball_vector( nposition );
    5051
    5152                        m_angle = glm::acos( glm::min( 1.0f, glm::dot( va, vb ) ) );
     
    5657                f32 get_angle() const { return m_angle; }
    5758        private:
    58                 glm::vec3 get_arcball_vector( const nv::ivec2& s )
     59                vec3 get_arcball_vector( const ivec2& s )
    5960                {
    60                         glm::vec3 p( 1.0*s.x / m_window.x * 2 - 1.0, 1.0*s.y / m_window.y * 2 - 1.0, 0 );
     61                        vec3 p( 1.0*s.x / m_window.x * 2 - 1.0, 1.0*s.y / m_window.y * 2 - 1.0, 0 );
    6162                        p.y = -p.y;
    6263                        float sq = p.x * p.x + p.y * p.y;
     
    6465                                p.z = sqrt( 1.0f - sq );
    6566                        else
    66                                 p = glm::normalize( p );
     67                                p = math::normalize( p );
    6768                        return p;
    6869                }
  • trunk/nv/core/transform.hh

    r397 r398  
    2626                void set_orientation( const quat& a_orientation ) { m_orientation = a_orientation; }
    2727                void set_orientation( float radians, const vec3& axis )
    28                 { // use glm::radians if degrees!
     28                { // use math::radians if degrees!
    2929                        m_orientation = glm::angleAxis( radians, axis );
    3030                }
     
    4343                }
    4444//              void rotate( const vec3& axis, f32 angle )
    45 //              { // use glm::radians if degrees!
     45//              { // use math::radians if degrees!
    4646//                      quat temp( angle, axis );
    4747//                      m_orientation = temp * m_orientation;
     
    5454                mat4 extract() const
    5555                {
    56                         mat4 result = glm::mat4_cast( m_orientation );
     56                        mat4 result = mat4_cast( m_orientation );
    5757                        result[3] = vec4( m_position, 1.0f );
    5858                        return result;
     
    6262                        quat new_orient( glm::inverse( m_orientation ) );
    6363                        // TODO: simplify
    64                         return transform( -glm::mat3_cast(new_orient) * m_position, new_orient );
     64                        return transform( -mat3_cast(new_orient) * m_position, new_orient );
    6565                }
    6666
     
    100100                return transform(
    101101                        glm::mix  ( a.get_position(), b.get_position(), value ),
    102                         glm::slerp( a.get_orientation(), b.get_orientation(), value ) 
     102                        glm::slerp( a.get_orientation(), b.get_orientation(), value )
    103103                );
    104104        }
  • trunk/nv/formats/md5_loader.hh

    r395 r398  
    6363                struct md5_weight
    6464                {
    65                         size_t    joint_id;
    66                         float     bias;
    67                         glm::vec3 pos;
     65                        size_t joint_id;
     66                        float  bias;
     67                        vec3  pos;
    6868                };
    6969
  • trunk/nv/interface/interpolation_raw.hh

    r395 r398  
    6464                        {
    6565                        case animation_slot::TIME:     return mat4();
    66                         case animation_slot::POSITION: return glm::translate( mat4(),glm::make_vec3( data ) );
    67                         case animation_slot::ROTATION: return glm::mat4_cast( make_quat_fixed( data ) );
    68                         case animation_slot::SCALE:    return glm::scale( mat4(),glm::make_vec3( data ) );
    69                         case animation_slot::TFORM:    return transform( glm::make_vec3( data ), make_quat_fixed( data + 3 ) ).extract();
     66                        case animation_slot::POSITION: return glm::translate( mat4(), make_vec3( data ) );
     67                        case animation_slot::ROTATION: return mat4_cast( make_quat_fixed( data ) );
     68                        case animation_slot::SCALE:    return glm::scale( mat4(),make_vec3( data ) );
     69                        case animation_slot::TFORM:    return transform( make_vec3( data ), make_quat_fixed( data + 3 ) ).extract();
    7070                        default:
    7171                                return mat4();
     
    8484                                case animation_slot::TIME:     break;
    8585                                case animation_slot::POSITION:
    86                                         position = glm::translate( position,glm::make_vec3( data + offset ) ); break;
     86                                        position = glm::translate( position,make_vec3( data + offset ) ); break;
    8787                                case animation_slot::ROTATION:
    88                                         rotation = glm::mat4_cast( make_quat_fixed( data + offset ) ); break;
     88                                        rotation = mat4_cast( make_quat_fixed( data + offset ) ); break;
    8989                                case animation_slot::SCALE:   
    90                                         scale    = glm::scale( mat4(),glm::make_vec3( data + offset ) ); break;
    91                                 case animation_slot::TFORM:    return transform( glm::make_vec3( data + offset ), make_quat_fixed( data + offset + 3 ) ).extract();
     90                                        scale    = glm::scale( mat4(),make_vec3( data + offset ) ); break;
     91                                case animation_slot::TFORM:    return transform( make_vec3( data + offset ), make_quat_fixed( data + offset + 3 ) ).extract();
    9292                                default:
    9393                                        break;
     
    105105                        {
    106106                        case animation_slot::TIME:     return transform();
    107                         case animation_slot::POSITION: return transform( glm::make_vec3( data ) );
     107                        case animation_slot::POSITION: return transform( make_vec3( data ) );
    108108                        case animation_slot::ROTATION: return transform( make_quat_fixed( data ) );
    109109                        case animation_slot::SCALE:    return transform();
    110                         case animation_slot::TFORM:    return transform( glm::make_vec3( data ), make_quat_fixed( data + 3 ) );
     110                        case animation_slot::TFORM:    return transform( make_vec3( data ), make_quat_fixed( data + 3 ) );
    111111                        default:
    112112                                return transform();
     
    124124                                case animation_slot::TIME:     break;
    125125                                case animation_slot::POSITION:
    126                                         position = glm::make_vec3( data + offset ); break;
     126                                        position = make_vec3( data + offset ); break;
    127127                                case animation_slot::ROTATION:
    128128                                        rotation = make_quat_fixed( data + offset ); break;
    129129                                case animation_slot::SCALE:        break;
    130                                 case animation_slot::TFORM:    return transform( glm::make_vec3( data + offset ), make_quat_fixed( data + 3 ) );
     130                                case animation_slot::TFORM:    return transform( make_vec3( data + offset ), make_quat_fixed( data + 3 ) );
    131131                                default:
    132132                                        break;
     
    145145        {
    146146                quat& r = *((quat*)(data));
    147                 r = glm::quat_cast( r33 * glm::mat3_cast( r ) * ri33 );
     147                r = quat_cast( r33 * mat3_cast( r ) * ri33 );
    148148        }
    149149        inline void transform_key_scale( void* data, float scale )
     
    157157                t = transform(
    158158                        r33 * t.get_position() * scale,
    159                         glm::quat_cast( r33 * glm::mat3_cast( t.get_orientation() ) * ri33 )
     159                        quat_cast( r33 * mat3_cast( t.get_orientation() ) * ri33 )
    160160                );
    161161        }
  • trunk/nv/lib/assimp.hh

    r395 r398  
    6868        {
    6969                const float* p = (float*)&m;
    70                 return glm::transpose( glm::make_mat4( p ) );
     70                return glm::transpose( make_mat4( p ) );
    7171        }
    7272
  • trunk/nv/stl/math.hh

    r397 r398  
    4343        template < typename T > using tquat = ::glm::tmat4x4<T>;
    4444#endif
     45
     46        using ::glm::mat3_cast;
     47        using ::glm::mat4_cast;
     48        using ::glm::quat_cast;
     49        using ::glm::make_vec2;
     50        using ::glm::make_vec3;
     51        using ::glm::make_vec4;
     52        using ::glm::make_mat2;
     53        using ::glm::make_mat3;
     54        using ::glm::make_mat4;
    4555
    4656        typedef tvec2<sint8> i8vec2;
  • trunk/src/formats/md5_loader.cc

    r395 r398  
    3131}
    3232
    33 static void unit_quat_w( glm::quat& quat )
     33static void unit_quat_w( nv::quat& quat )
    3434{
    3535        float t = 1.0f - ( quat.x * quat.x ) - ( quat.y * quat.y ) - ( quat.z * quat.z );
     
    343343                md5_vtx_pnt& vtc = vtcs[i];
    344344
    345                 vtc.position = glm::vec3(0);
    346                 vtc.normal   = glm::vec3(0);
    347                 vtc.tangent  = glm::vec3(0);
     345                vtc.position = vec3(0);
     346                vtc.normal   = vec3(0);
     347                vtc.tangent  = vec3(0);
    348348
    349349                stable_sort( weights + start_weight, weights + start_weight + weight_count, [] ( const md5_weight& a, const md5_weight& b ) -> bool { return a.bias > b.bias; } );
     
    386386                                const mesh_node_data&  joint = nodes[weight.joint_id];
    387387                                const transform tr = transform( joint.transform ).inverse();
    388                                 glm::vec3 rot_pos = tr.get_orientation() * weight.pos;
     388                                vec3 rot_pos = tr.get_orientation() * weight.pos;
    389389
    390390                                vtc.position += ( tr.get_position() + rot_pos ) * weight.bias;
     
    404404                uint32 ti2 = idata[ i * 3 + 2 ];
    405405 
    406                 glm::vec3 v1 = vtcs[ ti0 ].position;
    407                 glm::vec3 v2 = vtcs[ ti1 ].position;
    408                 glm::vec3 v3 = vtcs[ ti2 ].position;
    409                 glm::vec3 xyz1 = v3 - v1;
    410                 glm::vec3 xyz2 = v2 - v1;
    411 
    412                 glm::vec3 normal = glm::cross( xyz1, xyz2 );
     406                vec3 v1 = vtcs[ ti0 ].position;
     407                vec3 v2 = vtcs[ ti1 ].position;
     408                vec3 v3 = vtcs[ ti2 ].position;
     409                vec3 xyz1 = v3 - v1;
     410                vec3 xyz2 = v2 - v1;
     411
     412                vec3 normal = glm::cross( xyz1, xyz2 );
    413413
    414414                vtcs[ ti0 ].normal += normal;
     
    436436                md5_vtx_pntiw& vdata = vtx_data[i];
    437437
    438                 glm::vec3 normal  = glm::normalize( vtcs[i].normal );
    439                 glm::vec3 tangent = glm::normalize( vtcs[i].tangent );
     438                vec3 normal  = glm::normalize( vtcs[i].normal );
     439                vec3 tangent = glm::normalize( vtcs[i].tangent );
    440440                vtcs[i].normal   = normal;
    441441                vtcs[i].tangent  = tangent;
    442442
    443443                vdata.position = vtcs[i].position;
    444                 vdata.normal   = glm::vec3(0);
    445                 vdata.tangent  = glm::vec3(0);
     444                vdata.normal   = vec3(0);
     445                vdata.tangent  = vec3(0);
    446446 
    447447                for ( size_t j = 0; j < 4; ++j )
     
    484484                        transform ptr;
    485485                        if ( pjoint.data->get_channel(0)->count > index ) ptr = ptv[ index ];
    486                         glm::vec3 rot_pos = ptr.get_orientation() * pos;
     486                        vec3 rot_pos = ptr.get_orientation() * pos;
    487487
    488488                        pos    = ptr.get_position() + rot_pos;
  • trunk/src/gfx/image.cc

    r395 r398  
    1010using namespace nv;
    1111
    12 image::image( glm::ivec2 size, nv::size_t depth )
     12image::image( ivec2 size, nv::size_t depth )
    1313        : m_size( size ), m_depth( depth ), m_data( nullptr )
    1414{
     
    2323
    2424
    25 image::image( glm::ivec2 size, nv::size_t depth, const uint8 * data, bool reversed )
     25image::image( ivec2 size, nv::size_t depth, const uint8 * data, bool reversed )
    2626        : m_size( size ), m_depth( depth ), m_data( nullptr )
    2727{
  • trunk/src/gfx/mesh_creator.cc

    r395 r398  
    2121                size_t count     = ( keys ? keys->get_channel(0)->count : 0 );
    2222                size_t pcount    = ( pkeys ? pkeys->get_channel(0)->count : 0 );
    23                 max_frames = glm::max<uint32>( count, max_frames );
     23                max_frames = nv::max<uint32>( count, max_frames );
    2424                if ( pkeys && pkeys->get_channel_count() > 0 && keys && keys->get_channel_count() > 0 )
    2525                {
     
    2828                        for ( unsigned n = 0; n < count; ++n )
    2929                        {
    30                                 channel[n].tform = pchannel[ glm::min( n, pcount-1 ) ].tform * channel[n].tform;
     30                                channel[n].tform = pchannel[ nv::min( n, pcount-1 ) ].tform * channel[n].tform;
    3131                        }
    3232                }
     
    6363                        for ( size_t c = 0; c < chan_count; ++c )
    6464                        {
    65                                 max_keys = glm::max( max_keys, old_keys->get_channel(c)->count );
     65                                max_keys = nv::max( max_keys, old_keys->get_channel(c)->count );
    6666                        }
    6767
     
    7979                                for ( uint16 c = 0; c < chan_count; ++c )
    8080                                {
    81                                         size_t idx = glm::min( old_keys->get_channel(c)->count - 1, n );
     81                                        size_t idx = nv::min( old_keys->get_channel(c)->count - 1, n );
    8282                                        pkey += old_keys->get_channel(c)->get_raw( idx, pkey );
    8383                                }
     
    119119void nv::mesh_data_creator::transform( float scale, const mat3& r33 )
    120120{
    121         vec3 vertex_offset     = glm::vec3();
     121        vec3 vertex_offset     = vec3();
    122122        mat3 vertex_transform  = scale * r33;
    123123        mat3 normal_transform  = r33;
     
    297297                        vec3 xyz2 = v2 - v1;
    298298
    299                         //glm::vec3 normal = glm::cross( xyz1, xyz2 );
     299                        //vec3 normal = glm::cross( xyz1, xyz2 );
    300300                        //
    301301                        //vtcs[ ti0 ].normal += normal;
  • trunk/src/gfx/texture_atlas.cc

    r395 r398  
    1111using namespace nv;
    1212
    13 texture_atlas::texture_atlas( glm::ivec2 size, nv::size_t depth, nv::size_t border /*= 1*/ )
     13texture_atlas::texture_atlas( ivec2 size, nv::size_t depth, nv::size_t border /*= 1*/ )
    1414        : image( size, depth ), m_used( 0 ), m_border( border )
    1515{
    16         m_nodes.push_back( glm::ivec3( m_border, m_border, m_size.x - 2 * static_cast<int>( m_border ) ) );
     16        m_nodes.push_back( ivec3( m_border, m_border, m_size.x - 2 * static_cast<int>( m_border ) ) );
    1717        fill( 0 );
    1818}
    1919
    20 region texture_atlas::get_region( glm::ivec2 size )
     20region texture_atlas::get_region( ivec2 size )
    2121{
    22         region r ( glm::ivec2(0,0), size );
     22        region r ( ivec2(0,0), size );
    2323
    2424        int best_height = INT_MAX;
     
    3131                if ( y >= 0 )
    3232                {
    33                         glm::ivec3 node = m_nodes[ i ];
     33                        ivec3 node = m_nodes[ i ];
    3434                        if ( ( (y + size.y) < best_height ) ||
    3535                                ( ((y + size.y) == best_height) && (node.z < best_width)) )
     
    4646        if ( best_index == -1 )
    4747        {
    48                 return region( glm::ivec2( -1, -1 ), glm::ivec2( 0, 0 ) );
     48                return region( ivec2( -1, -1 ), ivec2( 0, 0 ) );
    4949        }
    5050
    51         m_nodes.insert( m_nodes.begin() + best_index, glm::ivec3( r.pos.x, r.pos.y + size.y, size.x ) );
     51        m_nodes.insert( m_nodes.begin() + best_index, ivec3( r.pos.x, r.pos.y + size.y, size.x ) );
    5252
    5353        for( size_t i = static_cast<size_t>( best_index )+1; i < m_nodes.size(); ++i )
    5454        {
    55                 glm::ivec3 node = m_nodes[ i ];
    56                 glm::ivec3 prev = m_nodes[ i-1 ];
     55                ivec3 node = m_nodes[ i ];
     56                ivec3 prev = m_nodes[ i-1 ];
    5757
    5858                if ( node.x < prev.x + prev.z )
     
    8282}
    8383
    84 int texture_atlas::fit( nv::size_t index, glm::ivec2 size )
     84int texture_atlas::fit( nv::size_t index, ivec2 size )
    8585{
    86         glm::ivec3 node = m_nodes[ index ];
     86        ivec3 node = m_nodes[ index ];
    8787
    8888        if ( node.x + size.x > m_size.x - static_cast<int>( m_border ) )
     
    128128        m_nodes.clear();
    129129        m_used = 0;
    130         m_nodes.push_back( glm::ivec3( 1, 1, m_size.x - 2 ) );
     130        m_nodes.push_back( ivec3( 1, 1, m_size.x - 2 ) );
    131131        fill( 0 );
    132132}
  • trunk/src/gfx/texture_font.cc

    r395 r398  
    9494bool texture_font::load_glyphs( string_ref codes )
    9595{
    96         FT_Face face     = (FT_Face)(m_rface);
    97         size_t depth     = m_atlas->get_depth();
    98         glm::ivec2 asize = m_atlas->get_size();
     96        FT_Face face = (FT_Face)(m_rface);
     97        size_t depth = m_atlas->get_depth();
     98        ivec2 asize = m_atlas->get_size();
    9999        FT_Int32 flags = 0;
    100100        flags |= FT_LOAD_RENDER;
     
    137137                int reg_width       = ft_bitmap_width / (depth > 3 ? 3 : (int)depth);
    138138
    139                 glm::ivec2 gsize( reg_width + 1, ft_bitmap_rows + 1 );
     139                ivec2 gsize( reg_width + 1, ft_bitmap_rows + 1 );
    140140                region r = m_atlas->get_region( gsize );
    141141                if ( r.pos.x < 0 )
     
    164164                g->charcode = c;
    165165                g->size     = gsize;
    166                 g->offset   = glm::ivec2( ft_glyph_left, ft_glyph_top );
    167                 g->tl       = glm::vec2( r.pos.x/(float)asize.x, r.pos.y/(float)asize.y );
    168                 g->br       = glm::vec2( ( r.pos.x + gsize.x )/(float)asize.x, (r.pos.y + gsize.y )/(float)asize.y );
     166                g->offset   = ivec2( ft_glyph_left, ft_glyph_top );
     167                g->tl       = vec2( r.pos.x/(float)asize.x, r.pos.y/(float)asize.y );
     168                g->br       = vec2( ( r.pos.x + gsize.x )/(float)asize.x, (r.pos.y + gsize.y )/(float)asize.y );
    169169
    170170                // Discard hinting to get advance
    171171                FT_Load_Glyph( face, glyph_index, FT_LOAD_RENDER | FT_LOAD_NO_HINTING);
    172172                slot = face->glyph;
    173                 g->advance = glm::ivec2( slot->advance.x/64.0, slot->advance.y/64.0 );
     173                g->advance = ivec2( slot->advance.x/64.0, slot->advance.y/64.0 );
    174174        }
    175175        generate_kerning();
  • trunk/src/gl/gl_context.cc

    r395 r398  
    731731        }
    732732        unsigned int buffers[8];
    733         count = glm::min<uint32>( count, 8 );
     733        count = nv::min<uint32>( count, 8 );
    734734        for ( uint32 i = 0; i < count; ++i )
    735735        {
  • trunk/src/gl/gl_device.cc

    r395 r398  
    5353        assert( image->format->BytesPerPixel > 2 );
    5454        image_format format(image->format->BytesPerPixel == 3 ? RGB : RGBA, UBYTE );
    55         image_data* data = new image_data( format, glm::ivec2( image->w, image->h ), (nv::uint8*)image->pixels );
     55        image_data* data = new image_data( format, ivec2( image->w, image->h ), (nv::uint8*)image->pixels );
    5656        return data;
    5757}
     
    7171        assert( image->format->BytesPerPixel > 2 );
    7272        image_format format( image->format->BytesPerPixel == 3 ? RGB : RGBA, UBYTE );
    73         image_data* idata = new image_data( format, glm::ivec2( image->w, image->h ), ( nv::uint8* )image->pixels );
     73        image_data* idata = new image_data( format, ivec2( image->w, image->h ), ( nv::uint8* )image->pixels );
    7474        return idata;
    7575}
  • trunk/src/rogue/fov_recursive_shadowcasting.cc

    r395 r398  
    2424        {
    2525                position max_radius = m_size-m_position;
    26                 max_radius.x=glm::max(max_radius.x,m_position.x);
    27                 max_radius.y=glm::max(max_radius.y,m_position.y);
    28                 m_radius = (int)glm::length((glm::vec2)max_radius)+1;
     26                max_radius = glm::max(max_radius,m_position);
     27                m_radius = (int)glm::length((vec2)max_radius)+1;
    2928        }
    3029        m_radius2 = m_radius * m_radius;
Note: See TracChangeset for help on using the changeset viewer.