Changeset 440

Show
Ignore:
Timestamp:
08/05/07 00:26:14 (1 year ago)
Author:
krobillard
Message:

Improved 'lerp.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/thune/thread_safe/gl/gx.c

    r438 r440  
    11941194    UCell* v2; 
    11951195 
    1196 #define INTERP(A,B)     A += (B - A) * ur_decimal(tos) 
     1196#define INTERP(A,B)     A += (B - A) * frac; 
    11971197 
    11981198    if( ur_is(tos, UT_DECIMAL) ) 
    11991199    { 
     1200        double frac = ur_decimal(tos); 
     1201 
     1202        if( frac < 0.0 ) 
     1203            frac = 0.0; 
     1204        else if( frac > 1.0 ) 
     1205            frac = 1.0; 
     1206 
    12001207        v2 = ur_s_prev(tos); 
    12011208        v1 = ur_s_prev(v2); 
     
    12051212            { 
    12061213                INTERP( ur_decimal(v1), ur_decimal(v2) ); 
    1207                 UR_S_DROPN( 2 ); 
    1208                 return; 
    12091214            } 
    12101215            else if( ur_is(v1, UT_VEC3) ) 
     
    12131218                INTERP( v1->vec3.xyz[1], v2->vec3.xyz[1] ); 
    12141219                INTERP( v1->vec3.xyz[2], v2->vec3.xyz[2] ); 
    1215                 UR_S_DROPN( 2 ); 
     1220            } 
     1221            else if( ur_is(v1, UT_COORD) ) 
     1222            { 
     1223                int i; 
     1224                int len = v1->coord.len; 
     1225                if( v2->coord.len < len ) 
     1226                    len = v2->coord.len; 
     1227                for( i = 0; i < len; ++i ) 
     1228                { 
     1229                    INTERP( v1->coord.elem[i], v2->coord.elem[i] ); 
     1230                } 
     1231            } 
     1232            else 
     1233            { 
     1234                ur_throwErr( UR_ERR_DATATYPE, 
     1235                             "lerp expected decimal!/vec3!/coord! value" ); 
    12161236                return; 
    12171237            } 
    1218         } 
    1219     } 
    1220     ur_throwErr( UR_ERR_DATATYPE, 
    1221                  "lerp expected decimal!/vec3! decimal!/vec3! decimal!" ); 
     1238            UR_S_DROPN( 2 ); 
     1239            return; 
     1240        } 
     1241        ur_throwErr( UR_ERR_DATATYPE, 
     1242                     "lerp expected 2 values of the same type" ); 
     1243        return; 
     1244    } 
     1245    ur_throwErr( UR_ERR_DATATYPE, "lerp expected decimal! fraction" ); 
    12221246} 
    12231247