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

« back to all changes in this revision

Viewing changes to source/blender/blenkernel/intern/anim.c

  • Committer: Bazaar Package Importer
  • Author(s): Florian Ernst
  • Date: 2005-11-06 12:40:03 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20051106124003-3pgs7tcg5rox96xg
Tags: 2.37a-1.1
* Non-maintainer upload.
* Split out parts of 01_SConstruct_debian.dpatch again: root_build_dir
  really needs to get adjusted before the clean target runs - closes: #333958,
  see #288882 for reference

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/** anim.c
2
2
 *
3
3
 *
4
 
 * $Id: anim.c,v 1.9 2004/03/20 22:55:37 zuster Exp $
 
4
 * $Id: anim.c,v 1.18 2004/12/03 20:22:37 ton Exp $
5
5
 *
6
6
 * ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
7
7
 *
95
95
        else nu= cu->nurb.first;
96
96
        
97
97
        if(cu->path) free_path(cu->path);
98
 
        cu->path= 0;
99
 
        
100
 
        if((cu->flag & CU_PATH)==0) return;
 
98
        cu->path= NULL;
101
99
        
102
100
        bl= cu->bev.first;
103
 
        if(bl==0) {
 
101
        if(bl==NULL) {
104
102
                makeDispList(ob);
105
103
                bl= cu->bev.first;
106
104
        }
107
 
        if(bl==0) return;
 
105
        if(bl==NULL) return;
108
106
 
109
107
        cu->path=path= MEM_callocN(sizeof(Path), "path");
110
108
        
204
202
        return p1;
205
203
}
206
204
 
 
205
/* warning, *vec needs FOUR items! */
207
206
int where_on_path(Object *ob, float ctime, float *vec, float *dir)      /* returns OK */
208
207
{
209
208
        Curve *cu;
213
212
        float *fp, *p0, *p1, *p2, *p3, fac;
214
213
        float data[4];
215
214
        int cycl=0, s0, s1, s2, s3;
216
 
        
 
215
 
217
216
        if(ob==0 || ob->type != OB_CURVE) return 0;
218
217
        cu= ob->data;
219
 
        if(cu->path==0 || cu->path->data==0) calc_curvepath(ob);
 
218
        if(cu->path==0 || cu->path->data==0) {
 
219
                calc_curvepath(ob);
 
220
                if(cu->path==0 || cu->path->data==0) return 0;
 
221
        }
220
222
        path= cu->path;
221
223
        fp= path->data;
222
224
        
224
226
        bl= cu->bev.first;
225
227
        if(bl && bl->poly> -1) cycl= 1;
226
228
 
227
 
        /* ctime is between 0.0-1.0 */
228
229
        ctime *= (path->len-1);
229
230
        
230
231
        s1= (int)floor(ctime);
272
273
        return 1;
273
274
}
274
275
 
 
276
static Object *new_dupli_object(ListBase *lb, Object *ob, Object *par)
 
277
{
 
278
        Object *newob;
 
279
        
 
280
        newob= MEM_mallocN(sizeof(Object), "newobj dupli");
 
281
        memcpy(newob, ob, sizeof(Object));
 
282
        newob->flag |= OB_FROMDUPLI;
 
283
        newob->id.newid= (ID *)par;     /* store duplicator */
 
284
        
 
285
        /* only basis-ball gets displist */
 
286
        if(newob->type==OB_MBALL) newob->disp.first= newob->disp.last= NULL;
 
287
 
 
288
        if(ob!=par) {   // dupliverts, particle
 
289
                newob->parent= NULL;
 
290
                newob->track= NULL;
 
291
        }       
 
292
        BLI_addtail(lb, newob);
 
293
        
 
294
        return newob;
 
295
}
 
296
 
275
297
void frames_duplilist(Object *ob)
276
298
{
277
299
        extern int enable_cu_speed;     /* object.c */
304
326
                        else ok= 0;
305
327
                }
306
328
                if(ok) {
307
 
                        newob= MEM_mallocN(sizeof(Object), "newobobj dupli");
308
 
                        memcpy(newob, ob, sizeof(Object));
309
 
                        
310
 
                        /*only the basis-ball gets a displist */
311
 
                        if(newob->type==OB_MBALL) newob->disp.first= newob->disp.last= 0;
 
329
                        newob= new_dupli_object(&duplilist, ob, ob);
312
330
 
313
 
                        BLI_addtail(&duplilist, newob);
314
331
                        do_ob_ipo(newob);
315
 
                        where_is_object(newob);
316
 
 
317
 
                        newob->flag |= OB_FROMDUPLI;
318
 
                        newob->id.newid= (ID *)ob;      /* store duplicator */
 
332
                        where_is_object_time(newob, (float)G.scene->r.cfra);
319
333
                }
320
334
        }
321
335
 
331
345
        Base *base;
332
346
        MVert *mvert;
333
347
        Mesh *me;
334
 
        float vec[3], pvec[3], pmat[4][4], mat[3][3], tmat[4][4];
 
348
        DispList *dl;
 
349
        float *extverts=NULL, vec[3], pvec[3], pmat[4][4], mat[3][3], tmat[4][4];
335
350
        float *q2;
336
351
        int lay, totvert, a;
337
352
        
341
356
        
342
357
        lay= G.scene->lay;
343
358
        
 
359
        dl= find_displist(&par->disp, DL_VERTS);
 
360
        if(dl) extverts= dl->verts;
 
361
 
344
362
        base= sce->base.first;
345
363
        while(base) {
346
364
 
365
383
                                        for(a=0; a<totvert; a++, mvert++) {
366
384
                                        
367
385
                                                /* calc the extra offset for children (wrt. centre parent)  */
368
 
                                                VECCOPY(vec, mvert->co);
 
386
                                                if(extverts) {
 
387
                                                        VECCOPY(vec, extverts+3*a);
 
388
                                                }
 
389
                                                else {
 
390
                                                        VECCOPY(vec, mvert->co);
 
391
                                                }
 
392
 
369
393
                                                Mat4MulVecfl(pmat, vec);
370
394
                                                VecSubf(vec, vec, pmat[3]);
371
395
                                                VecAddf(vec, vec, ob->obmat[3]);
372
396
                                                
373
 
                                                newob= MEM_mallocN(sizeof(Object), "newobj dupli");
374
 
                                                memcpy(newob, ob, sizeof(Object));
375
 
                                                newob->flag |= OB_FROMDUPLI;
376
 
                                                newob->id.newid= (ID *)par;     /* keep duplicator */
377
 
                                                
378
 
                                                /* only basis-ball gets displist */
379
 
                                                if(newob->type==OB_MBALL) newob->disp.first= newob->disp.last= 0;
380
 
                                                
 
397
                                                newob= new_dupli_object(&duplilist, ob, par);
381
398
                                                VECCOPY(newob->obmat[3], vec);
382
399
                                                
383
400
                                                if(par->transflag & OB_DUPLIROT) {
391
408
                                                        Mat4MulMat43(newob->obmat, tmat, mat);
392
409
                                                }
393
410
                                                
394
 
                                                newob->parent= 0;
395
 
                                                newob->track= 0;
396
 
                                                /* newob->borig= base; */
397
 
                                                
398
 
                                                BLI_addtail(&duplilist, newob);
399
 
                                                
400
411
                                                VECCOPY(pvec, vec);
401
412
                                        
402
413
                                        }
444
455
                                        pa= paf->keys;
445
456
                                        for(a=0; a<paf->totpart; a++, pa+=paf->totkey) {
446
457
                                                
447
 
                                                if(ctime > pa->time) {
448
 
                                                        if(ctime < pa->time+pa->lifetime) {
449
 
                                                                        
450
 
                                                                newob= MEM_mallocN(sizeof(Object), "newobj dupli");
451
 
                                                                memcpy(newob, ob, sizeof(Object));
452
 
                                                                newob->flag |= OB_FROMDUPLI;
453
 
                                                                newob->id.newid= (ID *)par;     /* keep duplicator */
454
 
 
455
 
                                                                /* only basis-ball gets displist */
456
 
                                                                if(newob->type==OB_MBALL) newob->disp.first= newob->disp.last= 0;
 
458
                                                if(paf->flag & PAF_STATIC) {
 
459
                                                        float mtime;
 
460
                                                        
 
461
                                                        where_is_particle(paf, pa, pa->time, vec1);
 
462
                                                        mtime= pa->time+pa->lifetime;
 
463
                                                        
 
464
                                                        for(ctime= pa->time; ctime<mtime; ctime+=paf->staticstep) {
 
465
                                                                newob= new_dupli_object(&duplilist, ob, par);
 
466
                                                                
 
467
                                                                /* make sure hair grows until the end.. */ 
 
468
                                                                if(ctime>pa->time+pa->lifetime) ctime= pa->time+pa->lifetime;
457
469
                                                                
458
470
                                                                /* to give ipos in object correct offset */
459
471
                                                                where_is_object_time(newob, ctime-pa->time);
 
472
 
 
473
                                                                where_is_particle(paf, pa, ctime, vec); // makes sure there's always a vec
 
474
                                                                Mat4MulVecfl(par->obmat, vec);
460
475
                                                                
461
 
                                                                where_is_particle(paf, pa, ctime, vec);
462
476
                                                                if(paf->stype==PAF_VECT) {
463
 
                                                                        where_is_particle(paf, pa, ctime+1.0f, vec1);
464
 
                                                                        
 
477
                                                                        where_is_particle(paf, pa, ctime+1.0, vec1); // makes sure there's always a vec
 
478
                                                                        Mat4MulVecfl(par->obmat, vec1);
 
479
 
465
480
                                                                        VecSubf(vec1, vec1, vec);
466
481
                                                                        q2= vectoquat(vec1, ob->trackflag, ob->upflag);
467
 
                                                
 
482
                                                                        
468
483
                                                                        QuatToMat3(q2, mat);
469
484
                                                                        Mat4CpyMat4(tmat, newob->obmat);
470
485
                                                                        Mat4MulMat43(newob->obmat, tmat, mat);
471
486
                                                                }
472
 
 
 
487
                                                                
473
488
                                                                VECCOPY(newob->obmat[3], vec);
 
489
                                                        }
 
490
                                                }
 
491
                                                else { // non static particles
 
492
                                                           
 
493
                                                        if(ctime > pa->time) {
 
494
                                                                if(ctime < pa->time+pa->lifetime) {
 
495
                                                                        newob= new_dupli_object(&duplilist, ob, par);
 
496
 
 
497
                                                                        /* to give ipos in object correct offset */
 
498
                                                                        where_is_object_time(newob, ctime-pa->time);
 
499
                                                                        
 
500
                                                                        where_is_particle(paf, pa, ctime, vec);
 
501
                                                                        if(paf->stype==PAF_VECT) {
 
502
                                                                                where_is_particle(paf, pa, ctime+1.0f, vec1);
 
503
                                                                                
 
504
                                                                                VecSubf(vec1, vec1, vec);
 
505
                                                                                q2= vectoquat(vec1, ob->trackflag, ob->upflag);
474
506
                                                        
475
 
                                                                newob->parent= 0;
476
 
                                                                newob->track= 0;
477
 
                                                                
478
 
                                                                BLI_addtail(&duplilist, newob);
479
 
                                                                
 
507
                                                                                QuatToMat3(q2, mat);
 
508
                                                                                Mat4CpyMat4(tmat, newob->obmat);
 
509
                                                                                Mat4MulMat43(newob->obmat, tmat, mat);
 
510
                                                                        }
 
511
 
 
512
                                                                        VECCOPY(newob->obmat[3], vec);
 
513
                                                                }
480
514
                                                        }
481
515
                                                }                                               
482
516
                                        }
494
528
{
495
529
        Object *ob;
496
530
        
497
 
        while( ob= duplilist.first) {
 
531
        while( (ob= duplilist.first) ) {
498
532
                BLI_remlink(&duplilist, ob);
499
533
                MEM_freeN(ob);
500
534
        }
509
543
                if(ob->transflag & OB_DUPLIVERTS) {
510
544
                        if(ob->type==OB_MESH) {
511
545
                                if(ob->transflag & OB_DUPLIVERTS) {
512
 
                                        if( paf=give_parteff(ob) ) particle_duplilist(sce, ob, paf);
 
546
                                        if( (paf=give_parteff(ob)) ) particle_duplilist(sce, ob, paf);
513
547
                                        else vertex_duplilist(sce, ob);
514
548
                                }
515
549
                        }