| | 1 | #include "system.h" |
| | 2 | #include "prototyp.h" |
| | 3 | |
| | 4 | void UpdateMorphing(MORPHCTRL *mcptr) |
| | 5 | { |
| | 6 | MORPHHEADER *mhdr = mcptr->ObMorphHeader; |
| | 7 | int UpdateRate; |
| | 8 | |
| | 9 | /*printf("UpdateMorphing\n");*/ |
| | 10 | |
| | 11 | if(mcptr->ObMorphFlags & mph_flag_play) |
| | 12 | { |
| | 13 | /* How fast? */ |
| | 14 | |
| | 15 | UpdateRate = (mcptr->ObMorphSpeed == ONE_FIXED) ? NormalFrameTime : MUL_FIXED(NormalFrameTime, mcptr->ObMorphSpeed); |
| | 16 | |
| | 17 | /* Update the current frame */ |
| | 18 | |
| | 19 | if(mcptr->ObMorphFlags & mph_flag_reverse) |
| | 20 | { |
| | 21 | mcptr->ObMorphCurrFrame -= UpdateRate; |
| | 22 | |
| | 23 | if(mcptr->ObMorphCurrFrame < 0) |
| | 24 | { |
| | 25 | if(mcptr->ObMorphFlags & mph_flag_noloop) |
| | 26 | { |
| | 27 | mcptr->ObMorphCurrFrame = 0; |
| | 28 | |
| | 29 | /* The sequence has finished and we are at the start */ |
| | 30 | |
| | 31 | mcptr->ObMorphFlags |= (mph_flag_finished | mph_flag_start); |
| | 32 | } |
| | 33 | else |
| | 34 | { |
| | 35 | mcptr->ObMorphCurrFrame += mhdr->mph_maxframes; |
| | 36 | |
| | 37 | /* The sequence has looped and we are back at the end */ |
| | 38 | |
| | 39 | mcptr->ObMorphFlags |= (mph_flag_looped | mph_flag_end); |
| | 40 | } |
| | 41 | } |
| | 42 | } |
| | 43 | else |
| | 44 | { |
| | 45 | mcptr->ObMorphCurrFrame += UpdateRate; |
| | 46 | |
| | 47 | if(mcptr->ObMorphCurrFrame >= mhdr->mph_maxframes) |
| | 48 | { |
| | 49 | if(mcptr->ObMorphFlags & mph_flag_noloop) |
| | 50 | { |
| | 51 | /* The sequence has finished and we are at the end */ |
| | 52 | |
| | 53 | mcptr->ObMorphFlags |= (mph_flag_finished | mph_flag_end); |
| | 54 | |
| | 55 | mcptr->ObMorphCurrFrame = mhdr->mph_maxframes - 1; |
| | 56 | } |
| | 57 | else |
| | 58 | { |
| | 59 | mcptr->ObMorphCurrFrame -= mhdr->mph_maxframes; |
| | 60 | |
| | 61 | /* The sequence has looped and we are back at the start */ |
| | 62 | |
| | 63 | mcptr->ObMorphFlags |= (mph_flag_looped | mph_flag_start); |
| | 64 | } |
| | 65 | |
| | 66 | } |
| | 67 | } |
| | 68 | } |
| | 69 | } |
| | 70 | |
| | 71 | /* |
| | 72 | |
| | 73 | Using the current frame, calculate the lerp values and find out which two |
| | 74 | shapes to interpolate between. |
| | 75 | |
| | 76 | Write this information back to a MORPHDISPLAY structure. |
| | 77 | |
| | 78 | */ |
| | 79 | |
| | 80 | void GetMorphDisplay(MORPHDISPLAY *md, DISPLAYBLOCK *dptr) |
| | 81 | { |
| | 82 | MORPHFRAME *mdata; |
| | 83 | MORPHCTRL *mc = dptr->ObMorphCtrl; |
| | 84 | MORPHHEADER *mhdr = mc->ObMorphHeader; |
| | 85 | |
| | 86 | md->md_lerp = mc->ObMorphCurrFrame & 0xffff; |
| | 87 | |
| | 88 | mdata = mhdr->mph_frames; |
| | 89 | mdata = &mdata[mc->ObMorphCurrFrame >> 16]; |
| | 90 | |
| | 91 | md->md_shape1 = mdata->mf_shape1; |
| | 92 | md->md_shape2 = mdata->mf_shape2; |
| | 93 | |
| | 94 | md->md_sptr1 = GetShapeData(md->md_shape1); |
| | 95 | md->md_sptr2 = GetShapeData(md->md_shape2); |
| | 96 | } |