Show
Ignore:
Timestamp:
08/05/07 00:26:17 (16 months ago)
Author:
krobillard
Message:

Added ++/-- to replace word inc/dec.
Renamed UR_FLAG_EOL as UR_FLAG_SOL.
GL - Added 'sphere draw opcode and 'curve-value call.

Files:
1 modified

Legend:

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

    r440 r442  
    11881188 
    11891189 
    1190 // (val1 val2 time -- valI) 
    1191 UR_CALL( uc_lerp ) 
    1192 { 
    1193     UCell* v1; 
    1194     UCell* v2; 
    1195  
    1196 #define INTERP(A,B)     A += (B - A) * frac; 
    1197  
    1198     if( ur_is(tos, UT_DECIMAL) ) 
    1199     { 
    1200         double frac = ur_decimal(tos); 
    1201  
     1190#define INTERP(R,A,B)     R = A + (B - A) * frac; 
     1191 
     1192/* 
     1193   res may be v1 or v2. 
     1194 
     1195   \return non-zero if successful. 
     1196*/ 
     1197static int _lerpCells( UCell* v1, UCell* v2, double frac, UCell* res ) 
     1198{ 
     1199    if( ur_type(v1) == ur_type(v2) ) 
     1200    { 
    12021201        if( frac < 0.0 ) 
    12031202            frac = 0.0; 
     
    12051204            frac = 1.0; 
    12061205 
     1206        if( ur_is(v1, UT_DECIMAL) ) 
     1207        { 
     1208            ur_initType(res, UT_DECIMAL); 
     1209            INTERP( ur_decimal(res), ur_decimal(v1), ur_decimal(v2) ); 
     1210            return 1; 
     1211        } 
     1212        else if( ur_is(v1, UT_VEC3) ) 
     1213        { 
     1214            ur_initType(res, UT_VEC3); 
     1215            INTERP( res->vec3.xyz[0], v1->vec3.xyz[0], v2->vec3.xyz[0] ); 
     1216            INTERP( res->vec3.xyz[1], v1->vec3.xyz[1], v2->vec3.xyz[1] ); 
     1217            INTERP( res->vec3.xyz[2], v1->vec3.xyz[2], v2->vec3.xyz[2] ); 
     1218            return 1; 
     1219        } 
     1220        else if( ur_is(v1, UT_COORD) ) 
     1221        { 
     1222            int i; 
     1223            int len = v1->coord.len; 
     1224            if( v2->coord.len < len ) 
     1225                len = v2->coord.len; 
     1226            for( i = 0; i < len; ++i ) 
     1227            { 
     1228                INTERP( res->coord.elem[i], 
     1229                        v1->coord.elem[i], v2->coord.elem[i] ); 
     1230            } 
     1231            ur_initType(res, UT_COORD); 
     1232            res->coord.len = len; 
     1233            return 1; 
     1234        } 
     1235    } 
     1236    return 0; 
     1237} 
     1238 
     1239 
     1240// (val1 val2 time -- valI) 
     1241UR_CALL( uc_lerp ) 
     1242{ 
     1243    UCell* v1; 
     1244    UCell* v2; 
     1245 
     1246    if( ur_is(tos, UT_DECIMAL) ) 
     1247    { 
    12071248        v2 = ur_s_prev(tos); 
    12081249        v1 = ur_s_prev(v2); 
    1209         if( ur_type(v1) == ur_type(v2) ) 
    1210         { 
    1211             if( ur_is(v1, UT_DECIMAL) ) 
    1212             { 
    1213                 INTERP( ur_decimal(v1), ur_decimal(v2) ); 
    1214             } 
    1215             else if( ur_is(v1, UT_VEC3) ) 
    1216             { 
    1217                 INTERP( v1->vec3.xyz[0], v2->vec3.xyz[0] ); 
    1218                 INTERP( v1->vec3.xyz[1], v2->vec3.xyz[1] ); 
    1219                 INTERP( v1->vec3.xyz[2], v2->vec3.xyz[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" ); 
    1236                 return; 
    1237             } 
     1250        if( _lerpCells( v1, v2, ur_decimal(tos), v1 ) ) 
     1251        { 
    12381252            UR_S_DROPN( 2 ); 
    12391253            return; 
    12401254        } 
    12411255        ur_throwErr( UR_ERR_DATATYPE, 
    1242                      "lerp expected 2 values of the same type" ); 
     1256                     "lerp expected 2 decimal!/vec3!/coord! values" ); 
    12431257        return; 
    12441258    } 
    12451259    ur_throwErr( UR_ERR_DATATYPE, "lerp expected decimal! fraction" ); 
     1260} 
     1261 
     1262 
     1263// (curve t -- val) 
     1264UR_CALL( uc_curve_value ) 
     1265{ 
     1266    double t, t1, d; 
     1267    int len; 
     1268    UCell* v1; 
     1269    UCell* cv; 
     1270    UCell* it; 
     1271    UCell* end; 
     1272    UBlock* blk; 
     1273 
     1274    if( ur_is(tos, UT_DECIMAL) ) 
     1275        t = ur_decimal(tos); 
     1276    else if( ur_is(tos, UT_INT) ) 
     1277        t = (double) ur_int(tos); 
     1278    else 
     1279        goto bad_dt; 
     1280 
     1281    cv = ur_s_prev(tos); 
     1282    if( ur_is(cv, UT_BLOCK) ) 
     1283    { 
     1284        blk = ur_block( cv ); 
     1285        UR_ITER_BLOCK( it, end, blk, cv ); 
     1286        len = end - it; 
     1287        if( len & 1 ) 
     1288        { 
     1289            --len; 
     1290            --end; 
     1291        } 
     1292        if( len ) 
     1293        { 
     1294            v1 = 0; 
     1295            while( it != end ) 
     1296            { 
     1297                // Assume decimal! for speed. 
     1298                if( t <= ur_decimal(it) ) 
     1299                { 
     1300                    if( ! v1 ) 
     1301                    { 
     1302                        ur_copyCell( cv, it[1] ); 
     1303                        goto finish; 
     1304                    } 
     1305 
     1306                    t1 = ur_decimal(v1); 
     1307                    d  = ur_decimal(it) - t1; 
     1308                    if( ! d ) 
     1309                        goto copy; 
     1310 
     1311                    if( _lerpCells( v1 + 1, it + 1, (t - t1) / d, cv ) ) 
     1312                        goto finish; 
     1313                    ur_throwErr( UR_ERR_DATATYPE, 
     1314                             "lerp expected 2 decimal!/vec3!/coord! values" ); 
     1315                    return; 
     1316                } 
     1317                v1 = it; 
     1318                it += 2; 
     1319            } 
     1320copy: 
     1321            ur_copyCell( cv, v1[1] ); 
     1322        } 
     1323        else 
     1324        { 
     1325            ur_setNone( cv ); 
     1326        } 
     1327 
     1328finish: 
     1329        UR_S_DROP; 
     1330        return; 
     1331    } 
     1332 
     1333bad_dt: 
     1334 
     1335    ur_throwErr( UR_ERR_DATATYPE, 
     1336                 "curve-value expected block! int!/decimal!" ); 
    12461337} 
    12471338 
     
    12861377 
    12871378#if 0 
    1288 #if 0 
     1379#if 1 
    12891380extern float perlinNoise2D( float x, float y, int octaves, float persist ); 
    12901381#define PReal   float 
     
    13411432                    for( x = 0.0f; x < w; x += 1.0f ) 
    13421433                    { 
    1343                       //n = perlinNoise2D( x * 0.1, y * 0.1, octaves, persist ); 
    1344                         n = perlinNoise2D( x/w, y/h, persist, 2, octaves ); 
     1434                        n = perlinNoise2D( x * 0.1, y * 0.1, octaves, persist ); 
     1435                      //n = perlinNoise2D( x/w, y/h, persist, 2, octaves ); 
    13451436 
    13461437                        //printf( "%g\n", n ); 
     
    14641555    { uc_look_at,        "look-at" }, 
    14651556    { uc_lerp,           "lerp" }, 
     1557    { uc_curve_value,    "curve-value" }, 
    14661558    { uc_gl_extensions,  "gl-extensions" }, 
    14671559    { uc_gl_max_textures,"gl-max-textures" }, 
     
    15821674#endif 
    15831675 
    1584     gView = glv_create( GLV_ATTRIB_DOUBLEBUFFER ); 
     1676    gView = glv_create( GLV_ATTRIB_DOUBLEBUFFER | GLV_ATTRIB_MULTISAMPLE ); 
    15851677    if( ! gView ) 
    15861678    {