Changeset 3987


Ignore:
Timestamp:
11/21/09 11:28:58 (4 years ago)
Author:
jylam
Message:
  • Indentation fixes
Location:
libcaca/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • libcaca/trunk/caca/triangle.c

    r3926 r3987  
    1 /* 
     1/*  
    22 *  libcaca       Colour ASCII-Art library 
    33 *  Copyright (c) 2002-2006 Sam Hocevar <sam@zoy.org> 
     
    1313 */ 
    1414 
    15 /* 
     15/*  
    1616 *  This file contains triangle drawing functions, both filled and outline. 
    1717 */ 
     
    4040 *  \return This function always returns 0. 
    4141 */ 
    42 int caca_draw_triangle(caca_canvas_t *cv, int x1, int y1, int x2, int y2, 
    43                         int x3, int y3, uint32_t ch) 
     42int caca_draw_triangle(caca_canvas_t * cv, int x1, int y1, int x2, int y2, 
     43                       int x3, int y3, uint32_t ch) 
    4444{ 
    4545    caca_draw_line(cv, x1, y1, x2, y2, ch); 
     
    6363 *  \return This function always returns 0. 
    6464 */ 
    65 int caca_draw_thin_triangle(caca_canvas_t *cv, int x1, int y1, 
    66                              int x2, int y2, int x3, int y3) 
     65int caca_draw_thin_triangle(caca_canvas_t * cv, int x1, int y1, 
     66                            int x2, int y2, int x3, int y3) 
    6767{ 
    6868    caca_draw_thin_line(cv, x1, y1, x2, y2); 
     
    8787 *  \return This function always returns 0. 
    8888 */ 
    89 int caca_fill_triangle(caca_canvas_t *cv, int x1, int y1, int x2, int y2, 
    90                         int x3, int y3, uint32_t ch) 
     89int caca_fill_triangle(caca_canvas_t * cv, int x1, int y1, int x2, int y2, 
     90                       int x3, int y3, uint32_t ch) 
    9191{ 
    9292    int x, y, xmin, xmax, ymin, ymax; 
     
    9494 
    9595    /* Bubble-sort y1 <= y2 <= y3 */ 
    96     if(y1 > y2) 
     96    if (y1 > y2) 
    9797        return caca_fill_triangle(cv, x2, y2, x1, y1, x3, y3, ch); 
    9898 
    99     if(y2 > y3) 
     99    if (y2 > y3) 
    100100        return caca_fill_triangle(cv, x1, y1, x3, y3, x2, y2, ch); 
    101101 
     
    112112    ymax = y3 + 1 < cv->height ? y3 + 1 : cv->height; 
    113113 
    114     if(ymin < y2) 
     114    if (ymin < y2) 
    115115    { 
    116116        xa = x1 + sl21 * (ymin - y1); 
    117117        xb = x1 + sl31 * (ymin - y1); 
    118118    } 
    119     else if(ymin == y2) 
     119    else if (ymin == y2) 
    120120    { 
    121121        xa = x2; 
    122122        xb = (y1 == y3) ? x3 : x1 + sl31 * (ymin - y1); 
    123123    } 
    124     else /* (ymin > y2) */ 
     124    else                        /* (ymin > y2) */ 
    125125    { 
    126126        xa = x3 + sl32 * (ymin - y3); 
     
    129129 
    130130    /* Rasterize our triangle */ 
    131     for(y = ymin; y < ymax; y++) 
     131    for (y = ymin; y < ymax; y++) 
    132132    { 
    133133        /* Rescale xa and xb, recentering the division */ 
    134         if(xa < xb) 
     134        if (xa < xb) 
    135135        { 
    136136            xx1 = (xa + 0x800) / 0x10000; 
     
    146146        xmax = xx2 + 1 < cv->width ? xx2 + 1 : cv->width; 
    147147 
    148         for(x = xmin; x < xmax; x++) 
     148        for (x = xmin; x < xmax; x++) 
    149149            caca_put_char(cv, x, y, ch); 
    150150 
     
    156156} 
    157157 
    158 /* This function actually renders the triangle,  
    159  * but is not exported due to sam's pedantic will. */ 
    160 static int caca_fill_triangle_textured_l(caca_canvas_t *cv, 
    161                                 int x1, int y1, 
    162                                 int x2, int y2, 
    163                                         int x3, int y3, 
    164                                 caca_canvas_t *tex, 
    165                                 float u1, float v1, 
    166                                 float u2, float v2, 
    167                                         float u3, float v3) 
    168                                  
     158/* This function actually renders the triangle, but is not exported due to 
     159   sam's pedantic will. */ 
     160static int caca_fill_triangle_textured_l(caca_canvas_t * cv, 
     161                                         int x1, int y1, 
     162                                         int x2, int y2, 
     163                                         int x3, int y3, 
     164                                         caca_canvas_t * tex, 
     165                                         float u1, float v1, 
     166                                         float u2, float v2, 
     167                                         float u3, float v3) 
    169168{ 
    170169    uint32_t savedattr; 
    171170 
    172     #define SWAP_F(a, b) {float c = a; a = b; b = c; } 
    173      
    174     /* (very) Naive and  
    175      * (very) float-based affine and 
    176      * (very) non-clipped and 
    177      * (very) non-corrected triangle mapper  
    178      * 
    179      * Accepts arbitrary texture sizes 
    180      * Coordinates clamped to [0.0 - 1.0] (no repeat) 
    181      */ 
    182     if(!cv || !tex) return -1; 
     171#define SWAP_F(a, b) {float c = a; a = b; b = c; } 
     172 
     173    /* (very) Naive and (very) float-based affine and (very) non-clipped and 
     174       (very) non-corrected triangle mapper Accepts arbitrary texture sizes 
     175       Coordinates clamped to [0.0 - 1.0] (no repeat) */ 
     176    if (!cv || !tex) 
     177        return -1; 
    183178 
    184179    /* Bubble-sort y1 <= y2 <= y3 */ 
    185     if(y1 > y2) 
    186         return caca_fill_triangle_textured_l(cv,  
     180    if (y1 > y2) 
     181        return caca_fill_triangle_textured_l(cv, 
    187182                                             x2, y2, x1, y1, x3, y3, 
    188                                              tex, 
    189                                              u2, v2, u1, v1, u3, v3); 
    190     if(y2 > y3)  
    191         return caca_fill_triangle_textured_l(cv,  
     183                                             tex, u2, v2, u1, v1, u3, v3); 
     184    if (y2 > y3) 
     185        return caca_fill_triangle_textured_l(cv, 
    192186                                             x1, y1, x3, y3, x2, y2, 
    193                                              tex, 
    194                                              u1, v1, u3, v3, u2, v2); 
     187                                             tex, u1, v1, u3, v3, u2, v2); 
    195188 
    196189    savedattr = caca_get_attr(cv, -1, -1); 
    197190 
    198191    /* Clip texture coordinates */ 
    199     if(u1<0.0f) u1 = 0.0f; if(v1<0.0f) v1 = 0.0f; 
    200     if(u2<0.0f) u2 = 0.0f; if(v2<0.0f) v2 = 0.0f; 
    201     if(u3<0.0f) u3 = 0.0f; if(v3<0.0f) v3 = 0.0f; 
    202     if(u1>1.0f) u1 = 1.0f; if(v1>1.0f) v1 = 1.0f; 
    203     if(u2>1.0f) u2 = 1.0f; if(v2>1.0f) v2 = 1.0f; 
    204     if(u3>1.0f) u3 = 1.0f; if(v3>1.0f) v3 = 1.0f; 
    205      
     192    if (u1 < 0.0f) 
     193        u1 = 0.0f; 
     194    if (v1 < 0.0f) 
     195        v1 = 0.0f; 
     196    if (u2 < 0.0f) 
     197        u2 = 0.0f; 
     198    if (v2 < 0.0f) 
     199        v2 = 0.0f; 
     200    if (u3 < 0.0f) 
     201        u3 = 0.0f; 
     202    if (v3 < 0.0f) 
     203        v3 = 0.0f; 
     204    if (u1 > 1.0f) 
     205        u1 = 1.0f; 
     206    if (v1 > 1.0f) 
     207        v1 = 1.0f; 
     208    if (u2 > 1.0f) 
     209        u2 = 1.0f; 
     210    if (v2 > 1.0f) 
     211        v2 = 1.0f; 
     212    if (u3 > 1.0f) 
     213        u3 = 1.0f; 
     214    if (v3 > 1.0f) 
     215        v3 = 1.0f; 
     216 
    206217    /* Convert relative tex coordinates to absolute */ 
    207218    int tw = caca_get_canvas_width(tex); 
    208219    int th = caca_get_canvas_height(tex); 
    209      
    210     u1*=(float)tw; u2*=(float)tw; u3*=(float)tw; 
    211     v1*=(float)th; v2*=(float)th; v3*=(float)th; 
    212      
     220 
     221    u1 *= (float)tw; 
     222    u2 *= (float)tw; 
     223    u3 *= (float)tw; 
     224    v1 *= (float)th; 
     225    v2 *= (float)th; 
     226    v3 *= (float)th; 
     227 
    213228    int x, y; 
    214     float y2y1 = y2-y1; 
    215     float y3y1 = y3-y1; 
    216     float y3y2 = y3-y2; 
    217      
     229    float y2y1 = y2 - y1; 
     230    float y3y1 = y3 - y1; 
     231    float y3y2 = y3 - y2; 
     232 
    218233    /* Compute slopes, making sure we don't divide by zero */ 
    219234    /* (in this case, we don't need the value anyway) */ 
    220235    /* FIXME : only compute needed slopes */ 
    221     float sl12 = ((float)x2 - x1) / (y2y1==0?1:y2y1); 
    222     float sl13 = ((float)x3 - x1) / (y3y1==0?1:y3y1); 
    223     float sl23 = ((float)x3 - x2) / (y3y2==0?1:y3y2); 
    224      
    225     float usl12 = (u2 - u1) / (y2y1==0?1:y2y1); 
    226     float usl13 = (u3 - u1) / (y3y1==0?1:y3y1); 
    227     float usl23 = (u3 - u2) / (y3y2==0?1:y3y2); 
    228     float vsl12 = (v2 - v1) / (y2y1==0?1:y2y1); 
    229     float vsl13 = (v3 - v1) / (y3y1==0?1:y3y1); 
    230     float vsl23 = (v3 - v2) / (y3y2==0?1:y3y2); 
    231      
    232     float xa = (float) x1, xb = (float) x1; 
     236    float sl12 = ((float)x2 - x1) / (y2y1 == 0 ? 1 : y2y1); 
     237    float sl13 = ((float)x3 - x1) / (y3y1 == 0 ? 1 : y3y1); 
     238    float sl23 = ((float)x3 - x2) / (y3y2 == 0 ? 1 : y3y2); 
     239 
     240    float usl12 = (u2 - u1) / (y2y1 == 0 ? 1 : y2y1); 
     241    float usl13 = (u3 - u1) / (y3y1 == 0 ? 1 : y3y1); 
     242    float usl23 = (u3 - u2) / (y3y2 == 0 ? 1 : y3y2); 
     243    float vsl12 = (v2 - v1) / (y2y1 == 0 ? 1 : y2y1); 
     244    float vsl13 = (v3 - v1) / (y3y1 == 0 ? 1 : y3y1); 
     245    float vsl23 = (v3 - v2) / (y3y2 == 0 ? 1 : y3y2); 
     246 
     247    float xa = (float)x1, xb = (float)x1; 
    233248    float ua = u1, ub = u1; 
    234249    float va = v1, vb = v1; 
    235250    float u, v; 
    236      
     251 
    237252    int s = 0; 
    238      
     253 
    239254    /* Top */ 
    240     for(y = y1 ; y < y2; y++) 
    241     { 
    242          
    243         if(xb < xa) { 
    244             SWAP_F(xb, xa);    
     255    for (y = y1; y < y2; y++) 
     256    { 
     257 
     258        if (xb < xa) 
     259        { 
     260            SWAP_F(xb, xa); 
    245261            SWAP_F(sl13, sl12); 
    246262            SWAP_F(ua, ub); 
    247             SWAP_F(va, vb);             
     263            SWAP_F(va, vb); 
    248264            SWAP_F(usl13, usl12); 
    249265            SWAP_F(vsl13, vsl12); 
    250             s=1; 
    251         } 
    252          
     266            s = 1; 
     267        } 
     268 
    253269        float tus = (ub - ua) / (xb - xa); 
    254270        float tvs = (vb - va) / (xb - xa); 
    255         v = va; u = ua; 
    256          
     271        v = va; 
     272        u = ua; 
     273 
    257274        /* scanline */ 
    258         for(x = xa ; x < xb; x++) 
    259         { 
    260             u+=tus; 
    261             v+=tvs; 
    262             /* FIXME: use caca_get_canvas_attrs / caca_get_canvas_chars  */ 
     275        for (x = xa; x < xb; x++) 
     276        { 
     277            u += tus; 
     278            v += tvs; 
     279            /* FIXME: use caca_get_canvas_attrs / caca_get_canvas_chars */ 
    263280            uint32_t attr = caca_get_attr(tex, u, v); 
    264             uint32_t c    = caca_get_char(tex, u, v); 
     281            uint32_t c = caca_get_char(tex, u, v); 
    265282            caca_set_attr(cv, attr); 
    266283            caca_put_char(cv, x, y, c); 
    267284        } 
    268          
    269         xa+=sl13; 
    270         xb+=sl12; 
    271          
    272         ua+=usl13; va+=vsl13; 
    273         ub+=usl12; vb+=vsl12; 
    274     } 
    275      
    276     if(s) 
     285 
     286        xa += sl13; 
     287        xb += sl12; 
     288 
     289        ua += usl13; 
     290        va += vsl13; 
     291        ub += usl12; 
     292        vb += vsl12; 
     293    } 
     294 
     295    if (s) 
    277296    { 
    278297        SWAP_F(xb, xa); 
     
    283302        SWAP_F(vsl13, vsl12); 
    284303    } 
    285      
    286      
     304 
     305 
    287306    /* Bottom */ 
    288     xb = (float) x2; 
    289  
    290     /* These variables are set by 'top' routine  
    291      * and are in an incorrect state if we only draw the bottom part 
    292      */ 
    293         if(y1 == y2) { 
     307    xb = (float)x2; 
     308 
     309    /* These variables are set by 'top' routine and are in an incorrect state  
     310       if we only draw the bottom part */ 
     311    if (y1 == y2) 
     312    { 
    294313        ua = u1; 
    295314        ub = u2; 
     
    297316        vb = v2; 
    298317    } 
    299      
    300     for(y = y2 ; y < y3; y++) 
    301     { 
    302         if(xb <= xa) 
     318 
     319    for (y = y2; y < y3; y++) 
     320    { 
     321        if (xb <= xa) 
    303322        { 
    304323            SWAP_F(xb, xa); 
     
    308327            SWAP_F(usl13, usl23); 
    309328            SWAP_F(vsl13, vsl23); 
    310         }  
    311          
     329        } 
     330 
    312331        float tus = (ub - ua) / ((float)xb - xa); 
    313332        float tvs = (vb - va) / ((float)xb - xa); 
    314         u = ua; v = va; 
    315          
     333        u = ua; 
     334        v = va; 
     335 
    316336        /* scanline */ 
    317         for(x = xa ; x < xb; x++) 
    318         {     
    319             u+=tus; 
    320             v+=tvs; 
    321             /* FIXME, can be heavily optimised  */ 
     337        for (x = xa; x < xb; x++) 
     338        { 
     339            u += tus; 
     340            v += tvs; 
     341            /* FIXME, can be heavily optimised */ 
    322342            uint32_t attr = caca_get_attr(tex, u, v); 
    323             uint32_t c    = caca_get_char(tex, u, v); 
     343            uint32_t c = caca_get_char(tex, u, v); 
    324344            caca_set_attr(cv, attr); 
    325345            caca_put_char(cv, x, y, c); 
    326346        } 
    327347 
    328         xa+=sl13; 
    329         xb+=sl23; 
    330          
    331         ua+=usl13; va+=vsl13; 
    332         ub+=usl23; vb+=vsl23; 
     348        xa += sl13; 
     349        xb += sl23; 
     350 
     351        ua += usl13; 
     352        va += vsl13; 
     353        ub += usl23; 
     354        vb += vsl23; 
    333355    } 
    334356 
     
    348370 *  \return This function return 0 if ok, -1 if canvas or texture are missing. 
    349371 */ 
    350 int caca_fill_triangle_textured(caca_canvas_t *cv, 
     372int caca_fill_triangle_textured(caca_canvas_t * cv, 
    351373                                int coords[6], 
    352                                 caca_canvas_t *tex, 
    353                                 float uv[6]) { 
    354      
     374                                caca_canvas_t * tex, float uv[6]) 
     375{ 
     376 
    355377    return caca_fill_triangle_textured_l(cv, 
    356378                                         coords[0], coords[1], 
     
    358380                                         coords[4], coords[5], 
    359381                                         tex, 
    360                                          uv[0],     uv[1], 
    361                                          uv[2],     uv[3], 
    362                                          uv[4],     uv[5]); 
    363 } 
    364  
    365  
    366  
    367 /* 
     382                                         uv[0], uv[1], 
     383                                         uv[2], uv[3], uv[4], uv[5]); 
     384} 
     385 
     386 
     387 
     388/*  
    368389 * XXX: The following functions are aliases. 
    369390 */ 
    370391 
    371392int cucul_draw_triangle(cucul_canvas_t *, int, int, int, int, int, 
    372                       int, uint32_t) CACA_ALIAS(caca_draw_triangle); 
    373 int cucul_draw_thin_triangle(cucul_canvas_t *, int, int, int, int, 
    374                              int, int) CACA_ALIAS(caca_draw_thin_triangle); 
    375 int cucul_fill_triangle(cucul_canvas_t *, int, int, int, int, int, 
    376                         int, uint32_t) CACA_ALIAS(caca_fill_triangle); 
    377  
     393                        int, uint32_t) CACA_ALIAS(caca_draw_triangle); 
     394     int cucul_draw_thin_triangle(cucul_canvas_t *, int, int, int, int, 
     395                                  int, 
     396                                  int) CACA_ALIAS(caca_draw_thin_triangle); 
     397     int cucul_fill_triangle(cucul_canvas_t *, int, int, int, int, int, int, 
     398                             uint32_t) CACA_ALIAS(caca_fill_triangle); 
  • libcaca/trunk/examples/trifiller.c

    r3928 r3987  
    1 /* 
     1/*  
    22 *  trifiller     texture mapping features 
    33 *  Copyright (c) 2009 Jean-Yves Lamoureux <jylam@lnxscene.org> 
     
    2828 
    2929/* M_PI / cos / sin */ 
    30 #include <math.h>  
     30#include <math.h> 
    3131 
    3232 
     
    3535int main(int argc, char *argv[]) 
    3636{ 
    37      
     37 
    3838    /* libcaca/libcaca contexts */ 
    39     caca_canvas_t *cv; caca_display_t *dp; 
     39    caca_canvas_t *cv; 
     40    caca_display_t *dp; 
    4041    caca_canvas_t *tex; 
    41      
     42 
    4243    /* cached canvas size */ 
    4344    int ww, wh, tw, th; 
    44      
     45 
    4546    /* logic */ 
    46     int quit  = 0; 
     47    int quit = 0; 
    4748    int update = 1; 
    4849    int px, py; 
    4950    float angle = 0; 
    50      
    51      
     51 
     52 
    5253    float square[6][2] = { 
    5354        {-SQUARE_SIZE, -SQUARE_SIZE}, 
    54         { SQUARE_SIZE, -SQUARE_SIZE}, 
    55         { SQUARE_SIZE, SQUARE_SIZE}, 
    56         {-SQUARE_SIZE,  SQUARE_SIZE}, 
     55        {SQUARE_SIZE, -SQUARE_SIZE}, 
     56        {SQUARE_SIZE, SQUARE_SIZE}, 
     57        {-SQUARE_SIZE, SQUARE_SIZE}, 
    5758    }; 
    5859    float uv1[6] = { 
    59         0, 0,  
     60        0, 0, 
    6061        1, 0, 
    6162        1, 1 
    6263    }; 
    6364    float uv2[6] = { 
    64         0, 0,  
     65        0, 0, 
    6566        1, 1, 
    6667        0, 1 
    6768    }; 
    68      
    69      
     69 
     70 
    7071    float rotated[4][2]; 
    7172    int coords1[6], coords2[6]; 
    72      
     73 
    7374    /* Create displayed canvas */ 
    7475    cv = caca_create_canvas(0, 0); 
    75     if(!cv) 
     76    if (!cv) 
    7677    { 
    7778        fprintf(stderr, "%s: unable to initialise libcaca\n", argv[0]); 
    7879        return 1; 
    7980    } 
    80      
     81 
    8182    /* Create texture holding canvas */ 
    8283    tex = caca_create_canvas(16, 16); 
    83     if(!tex) 
     84    if (!tex) 
    8485    { 
    8586        fprintf(stderr, "%s: unable to initialise libcaca\n", argv[0]); 
    8687        return 1; 
    8788    } 
    88      
     89 
    8990    /* Open window */ 
    9091    dp = caca_create_display(cv); 
    91     if(!dp) 
     92    if (!dp) 
    9293    { 
    9394        fprintf(stderr, "%s: unable to initialise libcaca\n", argv[0]); 
    9495        return 1; 
    9596    } 
    96      
    97      
    98      
     97 
     98 
     99 
    99100    /* Set the window title */ 
    100101    caca_set_display_title(dp, "trifiller"); 
    101      
     102 
    102103    /* Frame duration */ 
    103104    caca_set_display_time(dp, 10000); 
    104      
     105 
    105106    /* Get displayed canvas size */ 
    106107    ww = caca_get_canvas_width(cv); 
    107108    wh = caca_get_canvas_height(cv); 
    108      
     109 
    109110    /* Texture size */ 
    110111    tw = caca_get_canvas_width(tex); 
    111112    th = caca_get_canvas_height(tex); 
    112      
     113 
    113114    /* Load texture if any */ 
    114     if(argc == 2) 
     115    if (argc == 2) 
    115116    { 
    116117        struct image *im = load_image(argv[1]); 
    117         if(!im) 
    118         { 
    119             fprintf(stderr, "%s: unable to load image '%s'\n", argv[0], argv[1]); 
     118        if (!im) 
     119        { 
     120            fprintf(stderr, "%s: unable to load image '%s'\n", argv[0], 
     121                    argv[1]); 
    120122            return 1; 
    121123        } 
    122          
     124 
    123125        caca_set_dither_algorithm(im->dither, 
    124126                                  caca_get_dither_algorithm_list(NULL)[4]); 
    125         caca_dither_bitmap(tex,  
    126                            0, 0,  
    127                            tw, th,   
    128                            im->dither, im->pixels); 
     127        caca_dither_bitmap(tex, 0, 0, tw, th, im->dither, im->pixels); 
    129128        unload_image(im); 
    130     }  
     129    } 
    131130    /* or generate one */ 
    132     else  
    133     { 
    134          
     131    else 
     132    { 
     133 
    135134        int i; 
    136         for(i = 0; i < 16; i ++)  
    137         { 
    138             caca_set_color_ansi(tex, (i+1)%0xF, i%0xF); 
     135        for (i = 0; i < 16; i++) 
     136        { 
     137            caca_set_color_ansi(tex, (i + 1) % 0xF, i % 0xF); 
    139138            caca_put_str(tex, 0, i, "0123456789ABCDEF"); 
    140139        } 
    141140    } 
    142      
     141 
    143142 
    144143    px = 0; 
    145144    py = 0; 
    146      
    147     while(!quit) 
     145 
     146    while (!quit) 
    148147    { 
    149148        caca_event_t ev; 
    150149        unsigned int const event_mask = CACA_EVENT_KEY_PRESS 
    151         | CACA_EVENT_RESIZE 
    152         | CACA_EVENT_QUIT; 
     150            | CACA_EVENT_RESIZE | CACA_EVENT_QUIT; 
    153151        int event; 
    154          
    155         if(update) 
     152 
     153        if (update) 
    156154            event = caca_get_event(dp, event_mask, &ev, 0); 
    157155        else 
    158156            event = caca_get_event(dp, event_mask, &ev, -1); 
    159          
    160         while(event) 
    161         { 
    162             if(caca_get_event_type(&ev) & CACA_EVENT_KEY_PRESS) 
    163                 switch(caca_get_event_key_ch(&ev))  
    164             { 
     157 
     158        while (event) 
     159        { 
     160            if (caca_get_event_type(&ev) & CACA_EVENT_KEY_PRESS) 
     161                switch (caca_get_event_key_ch(&ev)) 
     162                { 
    165163                case 'q': 
    166164                case 'Q': 
     
    181179                    break; 
    182180                case 'a': 
    183                     angle+=1.0f; 
     181                    angle += 1.0f; 
    184182                    break; 
    185183                case 's': 
    186                     angle-=1.0f; 
    187                     break;                     
    188             } 
    189             else if(caca_get_event_type(&ev) == CACA_EVENT_RESIZE) 
     184                    angle -= 1.0f; 
     185                    break; 
     186                } 
     187            else if (caca_get_event_type(&ev) == CACA_EVENT_RESIZE) 
    190188            { 
    191189                caca_refresh_display(dp); 
     
    193191                wh = caca_get_event_resize_height(&ev); 
    194192                update = 1; 
    195             }  
    196             else if(caca_get_event_type(&ev) & CACA_EVENT_QUIT) 
     193            } 
     194            else if (caca_get_event_type(&ev) & CACA_EVENT_QUIT) 
    197195                quit = 1; 
    198              
     196 
    199197            event = caca_get_event(dp, CACA_EVENT_KEY_PRESS, &ev, 0); 
    200198        } 
    201          
    202          
    203          
     199 
     200 
     201 
    204202        /* 2D Rotation around screen center */ 
    205203        int p; 
    206         for(p=0; p<4; p++)  
    207         { 
    208             rotated[p][0] = square[p][0] * cos(angle*M_PI/180.0f) - square[p][1] * sin(angle*M_PI/180.0f); 
    209             rotated[p][1] = square[p][0] * sin(angle*M_PI/180.0f) + square[p][1] * cos(angle*M_PI/180.0f); 
    210              
    211             rotated[p][0] += ww/2 + px; 
    212             rotated[p][1] += wh/2 + py; 
    213         } 
    214          
    215         angle+=1.0f; 
    216          
    217          
     204        for (p = 0; p < 4; p++) 
     205        { 
     206            rotated[p][0] = 
     207                square[p][0] * cos(angle * M_PI / 180.0f) - 
     208                square[p][1] * sin(angle * M_PI / 180.0f); 
     209            rotated[p][1] = 
     210                square[p][0] * sin(angle * M_PI / 180.0f) + 
     211                square[p][1] * cos(angle * M_PI / 180.0f); 
     212 
     213            rotated[p][0] += ww / 2 + px; 
     214            rotated[p][1] += wh / 2 + py; 
     215        } 
     216 
     217        angle += 1.0f; 
     218 
     219 
    218220        /* Reaarange coordinates to fit libcaca's format */ 
    219         coords1[0] = rotated[0][0]; coords1[1] = rotated[0][1]; 
    220         coords1[2] = rotated[1][0]; coords1[3] = rotated[1][1]; 
    221         coords1[4] = rotated[2][0]; coords1[5] = rotated[2][1]; 
    222         
    223         coords2[0] = rotated[0][0]; coords2[1] = rotated[0][1]; 
    224         coords2[2] = rotated[2][0]; coords2[3] = rotated[2][1]; 
    225         coords2[4] = rotated[3][0]; coords2[5] = rotated[3][1]; 
    226          
     221        coords1[0] = rotated[0][0]; 
     222        coords1[1] = rotated[0][1]; 
     223        coords1[2] = rotated[1][0]; 
     224        coords1[3] = rotated[1][1]; 
     225        coords1[4] = rotated[2][0]; 
     226        coords1[5] = rotated[2][1]; 
     227 
     228        coords2[0] = rotated[0][0]; 
     229        coords2[1] = rotated[0][1]; 
     230        coords2[2] = rotated[2][0]; 
     231        coords2[3] = rotated[2][1]; 
     232        coords2[4] = rotated[3][0]; 
     233        coords2[5] = rotated[3][1]; 
     234 
    227235        /* Display two triangles */ 
    228         caca_fill_triangle_textured(cv,      /* canvas */ 
    229                                     coords1, /* triangle coordinates */ 
    230                                     tex,     /* texture canvas */ 
    231                                     uv1);    /* texture coordinates */ 
    232         caca_fill_triangle_textured(cv, 
    233                                     coords2, 
    234                                     tex, 
    235                                     uv2); 
    236          
     236        caca_fill_triangle_textured(cv, /* canvas */ 
     237                                    coords1,    /* triangle coordinates */ 
     238                                    tex,        /* texture canvas */ 
     239                                    uv1);       /* texture coordinates */ 
     240        caca_fill_triangle_textured(cv, coords2, tex, uv2); 
     241 
    237242        /* Refresh display and clear for next frame */ 
    238243        caca_refresh_display(dp); 
    239244        caca_clear_canvas(cv); 
    240          
    241     } 
    242      
     245 
     246    } 
     247 
    243248    caca_free_display(dp); 
    244249    caca_free_canvas(cv); 
    245250    caca_free_canvas(tex); 
    246      
     251 
    247252    return 0; 
    248253} 
Note: See TracChangeset for help on using the changeset viewer.