~ubuntu-branches/ubuntu/gutsy/blender/gutsy-security

« back to all changes in this revision

Viewing changes to source/blender/src/editview.c

  • Committer: Bazaar Package Importer
  • Author(s): Florian Ernst
  • Date: 2007-05-17 11:47:59 UTC
  • mfrom: (1.2.6 upstream)
  • Revision ID: james.westby@ubuntu.com-20070517114759-yp4ybrnhp2u7pk66
Tags: 2.44-1
* New upstream release.
* Drop debian/patches/01_64bits_stupidity, not needed anymore: as of this
  version blender is 64 bits safe again. Adjust README.Debian accordingly.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/**
2
 
 * $Id: editview.c,v 1.130 2007/01/25 21:43:49 ton Exp $
 
2
 * $Id: editview.c,v 1.144 2007/05/01 00:01:20 campbellbarton Exp $
3
3
 *
4
4
 * ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
5
5
 *
115
115
/* editmball.c */
116
116
extern ListBase editelems;
117
117
 
118
 
/* fly mode ises this */
 
118
/* fly mode uses this */
119
119
extern void setcameratoview3d(void);
120
120
 
121
121
/* local prototypes */
164
164
 
165
165
void EM_backbuf_checkAndSelectTFaces(Mesh *me, int select)
166
166
{
167
 
        MTFace *tface = me->mtface;
 
167
        MFace *mface = me->mface;
168
168
        int a;
169
169
 
170
 
        if (tface) {
171
 
                for(a=1; a<=me->totface; a++, tface++) {
 
170
        if (mface) {
 
171
                for(a=1; a<=me->totface; a++, mface++) {
172
172
                        if(EM_check_backbuf(a)) {
173
 
                                tface->flag = select?(tface->flag|TF_SELECT):(tface->flag&~TF_SELECT);
 
173
                                mface->flag = select?(mface->flag|ME_FACE_SEL):(mface->flag&~ME_FACE_SEL);
174
174
                        }
175
175
                }
176
176
        }
635
635
        
636
636
        /* new method:
637
637
         * 
638
 
         * starting from end points, calculate centre with maximum distance
 
638
         * starting from end points, calculate center with maximum distance
639
639
         * dependant at the angle s / g / r is defined
640
640
         */
641
641
        
904
904
        base= FIRSTBASE;
905
905
        while(base) {
906
906
                /* is there a visible selected object */
907
 
                if TESTBASE(base) {
908
 
                        ok= a= 1;
909
 
                        break;
 
907
                if(base->lay & G.vd->lay &&
 
908
                  (base->object->restrictflag & OB_RESTRICT_VIEW)==0 &&
 
909
                  (base->object->restrictflag & OB_RESTRICT_SELECT)==0
 
910
                ) {
 
911
                        if (base->flag & SELECT) {
 
912
                                ok= a= 1;
 
913
                                break;
 
914
                        } else {
 
915
                                ok=1;
 
916
                        }
910
917
                }
911
 
                /* are there any objects in the view*/
912
 
                if(base->lay & G.vd->lay)
913
 
                        ok=1;
914
 
                
915
918
                base= base->next;
916
919
        }
917
920
        
919
922
        
920
923
        base= FIRSTBASE;
921
924
        while(base) {
922
 
                if(base->lay & G.vd->lay) {
 
925
                if(base->lay & G.vd->lay &&
 
926
                  (base->object->restrictflag & OB_RESTRICT_VIEW)==0 &&
 
927
                  (base->object->restrictflag & OB_RESTRICT_SELECT)==0
 
928
                ) {
923
929
                        if(a) 
924
930
                                select_base_v3d(base, BA_DESELECT);
925
931
                        else 
943
949
        Base *base;
944
950
 
945
951
        for(base= FIRSTBASE; base; base= base->next) {
946
 
                if(base->lay & G.vd->lay) {
 
952
                if(base->lay & G.vd->lay &&
 
953
                  (base->object->restrictflag & OB_RESTRICT_VIEW)==0
 
954
                ) {
947
955
                        if TESTBASE(base)
948
956
                                select_base_v3d(base, BA_DESELECT);
949
957
                        else
968
976
        
969
977
        base= FIRSTBASE;
970
978
        while(base) {
971
 
                if((base->lay & G.vd->lay) && (base->object->type == obtype)) {
 
979
                if((base->lay & G.vd->lay) &&
 
980
                  (base->object->type == obtype) &&
 
981
                  (base->object->restrictflag & OB_RESTRICT_VIEW)==0
 
982
                ) {
972
983
                        select_base_v3d(base, BA_SELECT);
973
984
                        base->object->flag= base->flag;
974
985
                }
989
1000
        
990
1001
        base= FIRSTBASE;
991
1002
        while(base) {
992
 
                if (base->lay == (1<< (layernum -1))) {
 
1003
                if(base->lay == (1<< (layernum -1)) &&
 
1004
                  (base->object->restrictflag & OB_RESTRICT_VIEW)==0
 
1005
                ) {
993
1006
                        select_base_v3d(base, BA_SELECT);
994
1007
                        base->object->flag= base->flag;
995
1008
                }
1142
1155
                        for(go= group->gobject.first; go; go= go->next) {
1143
1156
                                if(deselect) go->ob->flag &= ~SELECT;
1144
1157
                                else {
1145
 
                                        if (!(go->ob->restrictflag & OB_RESTRICT_SELECT))
 
1158
                                        if ((go->ob->restrictflag & OB_RESTRICT_SELECT)==0 &&
 
1159
                                                (go->ob->restrictflag & OB_RESTRICT_VIEW)==0)
1146
1160
                                                go->ob->flag |= SELECT;
1147
1161
                                }
1148
1162
                        }
1169
1183
        char str[32];
1170
1184
        
1171
1185
        for(base=FIRSTBASE; base; base= base->next) {
1172
 
                if(base->lay & G.vd->lay) {
 
1186
                if BASE_SELECTABLE(base) {
1173
1187
                        baseList[baseCount] = NULL;
1174
1188
                        
1175
1189
                        /* two selection methods, the CTRL select uses max dist of 15 */
1220
1234
        short has_bones15=0, has_bones9=0, has_bones5=0;
1221
1235
        
1222
1236
        hits15= view3d_opengl_select(buffer, MAXPICKBUF, mval[0]-14, mval[1]-14, mval[0]+14, mval[1]+14);
1223
 
        if(hits15) {
 
1237
        if(hits15>0) {
1224
1238
                for(a=0; a<hits15; a++) if(buffer[4*a+3] & 0xFFFF0000) has_bones15= 1;
1225
1239
                
1226
1240
                offs= 4*hits15;
1227
1241
                hits9= view3d_opengl_select(buffer+offs, MAXPICKBUF-offs, mval[0]-9, mval[1]-9, mval[0]+9, mval[1]+9);
1228
 
                if(hits9) {
 
1242
                if(hits9>0) {
1229
1243
                        for(a=0; a<hits9; a++) if(buffer[offs+4*a+3] & 0xFFFF0000) has_bones9= 1;
1230
1244
                        
1231
1245
                        offs+= 4*hits9;
1232
1246
                        hits5= view3d_opengl_select(buffer+offs, MAXPICKBUF-offs, mval[0]-5, mval[1]-5, mval[0]+5, mval[1]+5);
1233
 
                        if(hits5) {
 
1247
                        if(hits5>0) {
1234
1248
                                for(a=0; a<hits5; a++) if(buffer[offs+4*a+3] & 0xFFFF0000) has_bones5= 1;
1235
1249
                        }
1236
1250
                }
1249
1263
                        return hits15;
1250
1264
                }
1251
1265
                
1252
 
                if(hits5) {
 
1266
                if(hits5>0) {
1253
1267
                        offs= 4*hits15 + 4*hits9;
1254
1268
                        memcpy(buffer, buffer+offs, 4*offs);
1255
1269
                        return hits5;
1256
1270
                }
1257
 
                if(hits9) {
 
1271
                if(hits9>0) {
1258
1272
                        offs= 4*hits15;
1259
1273
                        memcpy(buffer, buffer+offs, 4*offs);
1260
1274
                        return hits9;
1278
1292
 
1279
1293
        getmouseco_areawin(mval);
1280
1294
        
1281
 
        /* This block uses the control key to make the object selected by its centre point rather then its contents */
 
1295
        /* This block uses the control key to make the object selected by its center point rather then its contents */
1282
1296
        if(G.obedit==0 && (G.qual & LR_CTRLKEY)) {
1283
1297
                
1284
1298
                /* note; shift+alt goes to group-flush-selecting */
1287
1301
                else {
1288
1302
                        base= startbase;
1289
1303
                        while(base) {
1290
 
                                
1291
 
                                if(base->lay & G.vd->lay) {
1292
 
                                        
 
1304
                                if BASE_SELECTABLE(base) {
1293
1305
                                        project_short(base->object->obmat[3], &base->sx);
1294
1306
                                        
1295
1307
                                        temp= abs(base->sx -mval[0]) + abs(base->sy -mval[1]);
1409
1421
                        if(has_bones && basact) {
1410
1422
                                if( do_pose_selectbuffer(basact, buffer, hits) ) {      /* then bone is found */
1411
1423
                                
 
1424
                                        /* we make the armature selected: 
 
1425
                                           not-selected active object in posemode won't work well for tools */
 
1426
                                        basact->flag|= SELECT;
 
1427
                                        basact->object->flag= basact->flag;
 
1428
                                        
1412
1429
                                        /* in weightpaint, we use selected bone to select vertexgroup, so no switch to new active object */
1413
1430
                                        if(G.f & G_WEIGHTPAINT) {
1414
 
                                                /* we make the armature selected */
1415
 
                                                basact->flag|= SELECT;
1416
 
                                                basact->object->flag= basact->flag;
1417
1431
                                                /* prevent activating */
1418
1432
                                                basact= NULL;
1419
1433
                                        }
1434
1448
                        select_base_v3d(basact, BA_SELECT);
1435
1449
                }
1436
1450
                /* also prevent making it active on mouse selection */
1437
 
                else if (!(basact->object->restrictflag & OB_RESTRICT_SELECT)) {
 
1451
                else if BASE_SELECTABLE(basact) {
1438
1452
 
1439
1453
                        oldbasact= BASACT;
1440
1454
                        BASACT= basact;
1656
1670
                face_borderselect();
1657
1671
                return;
1658
1672
        }
1659
 
        
1660
 
        setlinestyle(2);
 
1673
 
 
1674
        a = 0;
 
1675
#ifdef __APPLE__
 
1676
        a = is_a_really_crappy_intel_card();
 
1677
#endif
 
1678
        if (!a) setlinestyle(2);
1661
1679
        val= get_border(&rect, 3);
1662
 
        setlinestyle(0);
 
1680
        if (!a) setlinestyle(0);
1663
1681
        
1664
1682
        if(val==0)
1665
1683
                return;
1764
1782
                unsigned int *vbuffer=NULL; /* selection buffer */
1765
1783
                unsigned int *col;                      /* color in buffer      */
1766
1784
                short selecting = 0;
1767
 
 
 
1785
                Object *ob= OBACT;
 
1786
                int bone_only;
 
1787
                
 
1788
                if((ob) && (ob->flag & OB_POSEMODE))
 
1789
                        bone_only= 1;
 
1790
                else
 
1791
                        bone_only= 0;
 
1792
                
1768
1793
                if (val==LEFTMOUSE)
1769
1794
                        selecting = 1;
1770
1795
                
1783
1808
                does it incorrectly.
1784
1809
                */
1785
1810
 
1786
 
                if (hits) { /* no need to loop if there's no hit */
 
1811
                if (hits>0) { /* no need to loop if there's no hit */
1787
1812
                        base= FIRSTBASE;
1788
1813
                        col = vbuffer + 3;
1789
1814
                        while(base && hits) {
1804
1829
                                                                }
1805
1830
                                                        }
1806
1831
                                                }
1807
 
                                                else {
 
1832
                                                else if(!bone_only) {
1808
1833
                                                        if (selecting)
1809
1834
                                                                select_base_v3d(base, BA_SELECT);
1810
1835
                                                        else
2052
2077
        short val;
2053
2078
        float dvec[3], vb[2], xscale, yscale, scale;
2054
2079
        
 
2080
        /* SMOOTHVIEW */
 
2081
        float new_dist;
 
2082
        float new_ofs[3];
 
2083
        
2055
2084
        /* doesn't work fine for perspective */
2056
2085
        if(G.vd->persp==1)
2057
2086
                return;
2063
2092
                vb[0] = G.vd->area->winx;
2064
2093
                vb[1] = G.vd->area->winy;
2065
2094
                
 
2095
                new_dist = G.vd->dist;
 
2096
                new_ofs[0] = G.vd->ofs[0];
 
2097
                new_ofs[1] = G.vd->ofs[1];
 
2098
                new_ofs[2] = G.vd->ofs[2];
 
2099
                
2066
2100
                /* convert the drawn rectangle into 3d space */
2067
 
                initgrabz(-G.vd->ofs[0], -G.vd->ofs[1], -G.vd->ofs[2]);
 
2101
                initgrabz(-new_ofs[0], -new_ofs[1], -new_ofs[2]);
 
2102
                
2068
2103
                window_to_3d(dvec, (rect.xmin+rect.xmax-vb[0])/2, (rect.ymin+rect.ymax-vb[1])/2);
2069
2104
                
2070
2105
                /* center the view to the center of the rectangle */
2071
 
                VecSubf(G.vd->ofs, G.vd->ofs, dvec);
 
2106
                VecSubf(new_ofs, new_ofs, dvec);
2072
2107
                
2073
2108
                /* work out the ratios, so that everything selected fits when we zoom */
2074
2109
                xscale = ((rect.xmax-rect.xmin)/vb[0]);
2076
2111
                scale = (xscale >= yscale)?xscale:yscale;
2077
2112
                
2078
2113
                /* zoom in as required, or as far as we can go */
2079
 
                G.vd->dist = ((G.vd->dist*scale) >= 0.001*G.vd->grid)? G.vd->dist*scale:0.001*G.vd->grid;
 
2114
                new_dist = ((new_dist*scale) >= 0.001*G.vd->grid)? new_dist*scale:0.001*G.vd->grid;
 
2115
                
 
2116
                smooth_view(G.vd, new_ofs, NULL, &new_dist, NULL);
 
2117
                
2080
2118
        }
2081
2119
}
2082
2120
 
2103
2141
        moffset[2], /* mouse offset from the views center */
2104
2142
        tmp_quat[4], /* used for rotating the view */
2105
2143
        winxf, winyf, /* scale the mouse movement by this value - scales mouse movement to the view size */
2106
 
        time_redraw, time_redraw_clamped; /*time how fast it takes for us to redraw, this is so simple scenes dont fly too fast */
2107
 
        
2108
 
        
2109
 
        double time_current, time_lastdraw;
 
2144
        time_redraw, time_redraw_clamped, time_wheel; /*time how fast it takes for us to redraw, this is so simple scenes dont fly too fast */
 
2145
        
 
2146
        /* time_lastwheel is used to accelerate when using the mousewheel a lot */
 
2147
        double time_current, time_lastdraw, time_currwheel, time_lastwheel;
2110
2148
        
2111
2149
        short val, /* used for toets to see if a buttons pressed */
2112
2150
        cent_orig[2], /* view center */
2135
2173
        int cfra = -1; /*so the first frame always has a key added */
2136
2174
        char *actname="";
2137
2175
        
2138
 
        
2139
2176
        if(curarea->spacetype!=SPACE_VIEW3D) return;
2140
2177
                
2141
2178
        if(G.vd->persp==2 && G.vd->camera->id.lib) {
2197
2234
        /* the dist defines a vector that is infront of the offset
2198
2235
        to rotate the view about.
2199
2236
        this is no good for fly mode because we
2200
 
        want to rotate about the viewers centre.
 
2237
        want to rotate about the viewers center.
2201
2238
        but to correct the dist removal we must
2202
2239
        alter offset so the view dosent jump. */
2203
2240
        
2217
2254
        winyf= (float)(curarea->winy)-(ymargin*2); 
2218
2255
        
2219
2256
        
2220
 
        time_lastdraw= PIL_check_seconds_timer();
 
2257
        time_lastdraw= time_lastwheel= PIL_check_seconds_timer();
2221
2258
        
2222
2259
        G.vd->flag2 |= V3D_FLYMODE; /* so we draw the corner margins */
2223
2260
        scrarea_do_windraw(curarea);
2236
2273
                                        action= 1; /* Accepted */
2237
2274
                                        break;
2238
2275
                                } else if(toets==PADPLUSKEY || toets==EQUALKEY || toets==WHEELUPMOUSE) {
 
2276
                                        time_currwheel= PIL_check_seconds_timer();
 
2277
                                        time_wheel = (float)(time_currwheel - time_lastwheel);
 
2278
                                        time_lastwheel = time_currwheel;
 
2279
                                        /*printf("Wheel %f\n", time_wheel);*/
 
2280
                                        /*Mouse wheel delays range from 0.5==slow to 0.01==fast*/ 
 
2281
                                        time_wheel = 1+ (10 - (20*MIN2(time_wheel, 0.5))); /* 0-0.5 -> 0-5.0 */
 
2282
                                        
2239
2283
                                        if (speed<0) speed=0;
2240
 
                                        else speed+= G.vd->grid;
 
2284
                                        else {
 
2285
                                                if (G.qual & LR_SHIFTKEY)
 
2286
                                                        speed+= G.vd->grid*time_wheel*0.1;
 
2287
                                                else
 
2288
                                                        speed+= G.vd->grid*time_wheel;
 
2289
                                        }
 
2290
                                        
2241
2291
                                } else if(toets==PADMINUS || toets==MINUSKEY || toets==WHEELDOWNMOUSE) {
 
2292
                                        time_currwheel= PIL_check_seconds_timer();
 
2293
                                        time_wheel = (float)(time_currwheel - time_lastwheel);
 
2294
                                        time_lastwheel = time_currwheel;
 
2295
                                        time_wheel = 1+ (10 - (20*MIN2(time_wheel, 0.5))); /* 0-0.5 -> 0-5.0 */
 
2296
                                        
2242
2297
                                        if (speed>0) speed=0;
2243
 
                                        else speed-= G.vd->grid;
 
2298
                                        else {
 
2299
                                                if (G.qual & LR_SHIFTKEY)
 
2300
                                                        speed-= G.vd->grid*time_wheel*0.1;
 
2301
                                                else
 
2302
                                                        speed-= G.vd->grid*time_wheel;
 
2303
                                        }
2244
2304
                                
2245
2305
                                } else if (toets==MIDDLEMOUSE) {
2246
2306
                                        /* make it so the camera direction dosent follow the view
2342
2402
                                dvec_tmp[0]= -moffset[0];
2343
2403
                                dvec_tmp[1]= -moffset[1];
2344
2404
                                dvec_tmp[2]= 0;
2345
 
                                /* z axis can stay teh same, just keep costing */
 
2405
                                
 
2406
                                if (G.qual & LR_SHIFTKEY) {
 
2407
                                        dvec_tmp[0] *= 0.1;
 
2408
                                        dvec_tmp[1] *= 0.1;
 
2409
                                }
2346
2410
                                
2347
2411
                                Mat3MulVecfl(mat, dvec_tmp);
2348
2412
                                VecMulf(dvec_tmp, time_redraw*200.0 * G.vd->grid);
2442
2506
                                        
2443
2507
                                        Mat3MulVecfl(mat, dvec_tmp);
2444
2508
                                        
2445
 
                                        VecMulf(dvec_tmp, speed*time_redraw*0.5);
 
2509
                                        VecMulf(dvec_tmp, speed*time_redraw*0.25);
2446
2510
                                }
2447
2511
                        }
2448
2512
                        
2452
2516
                        dvec[1] = dvec_tmp[1]*(1-dvec_lag) + dvec_old[1]*dvec_lag;
2453
2517
                        dvec[2] = dvec_tmp[2]*(1-dvec_lag) + dvec_old[2]*dvec_lag;
2454
2518
                        
 
2519
                        
 
2520
                        if (G.vd->persp==2) {
 
2521
                                if (G.vd->camera->protectflag & OB_LOCK_LOCX)
 
2522
                                        dvec[0] = 0.0;
 
2523
                                if (G.vd->camera->protectflag & OB_LOCK_LOCY)
 
2524
                                        dvec[1] = 0.0;
 
2525
                                if (G.vd->camera->protectflag & OB_LOCK_LOCZ)
 
2526
                                        dvec[2] = 0.0;
 
2527
                        }
 
2528
                        
2455
2529
                        VecAddf(G.vd->ofs, G.vd->ofs, dvec);
2456
2530
                        if (zlock && xlock)
2457
2531
                                headerprint("FlyKeys  Speed:(+/- | Wheel),  Upright Axis:X  on/Z on,   Slow:Shift,  Direction:WASDRF,  Ok:LMB,  Pan:MMB,  Cancel:RMB");