00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00029 #include "ssgLocal.h"
00030 #include "../Include/FlyLegacy.h"
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059 ssgKeyframeTransform::ssgKeyframeTransform (int n,
00060 float minValue,
00061 float maxValue)
00062 {
00063 type = ssgTypeKeyframeTransform();
00064
00065
00066 nFrames = n;
00067 data = new SKeyframe[nFrames];
00068 next = 0;
00069
00070 min = minValue;
00071 max = maxValue;
00072 }
00073
00074
00075
00076
00077
00078 ssgKeyframeTransform::~ssgKeyframeTransform (void)
00079 {
00080 delete data;
00081 }
00082
00083
00084 void ssgKeyframeTransform::addKeyframe (float frame, sgCoord *xform)
00085 {
00086 if (next < nFrames) {
00087
00088 data[next].frame = frame;
00089
00090
00091 sgCopyCoord (&data[next].transform, xform);
00092
00093
00094 next++;
00095 }
00096 }
00097
00098
00099 void ssgKeyframeTransform::setKeyframe (float frame)
00100 {
00101
00102 SKeyframe *pPre = NULL;
00103 SKeyframe *pPost = NULL;
00104 SKeyframe *pMatch = NULL;
00105
00106 if (frame <= min) {
00107 pMatch = &data[0];
00108 } else if (frame >= max) {
00109 pMatch = &data[nFrames-1];
00110 } else
00111 for (int i=0; i<nFrames; i++) {
00112 SKeyframe *f = &data[i];
00113
00114 if (f->frame == frame) {
00115
00116 pMatch = f;
00117 break;
00118 } else {
00119 if (f->frame < frame) {
00120
00121 pPre = f;
00122 } else {
00123 if ((f->frame > frame) && (pPost == NULL)) {
00124 pPost = f;
00125 }
00126 }
00127 }
00128 }
00129
00130
00131 if (pMatch) {
00132 setTransform (&pMatch->transform);
00133 } else {
00134 if ((pPre == NULL) || (pPost == NULL)) {
00135 gtfo ("ssgKeyframeTransform::setKeyframe : Could not find pre/post entries");
00136 } else {
00137
00138 float scale = (frame - pPre->frame) / (pPost->frame - pPre->frame);
00139 float dx = pPost->transform.xyz[0] - pPre->transform.xyz[0];
00140 float dy = pPost->transform.xyz[1] - pPre->transform.xyz[1];
00141 float dz = pPost->transform.xyz[2] - pPre->transform.xyz[2];
00142 float dh = pPost->transform.hpr[0] - pPre->transform.hpr[0];
00143 float dp = pPost->transform.hpr[1] - pPre->transform.hpr[1];
00144 float dr = pPost->transform.hpr[2] - pPre->transform.hpr[2];
00145
00146 sgCoord coord;
00147 coord.xyz[0] = pPre->transform.xyz[0] + (scale * dx);
00148 coord.xyz[1] = pPre->transform.xyz[1] + (scale * dy);
00149 coord.xyz[2] = pPre->transform.xyz[2] + (scale * dz);
00150 coord.hpr[0] = pPre->transform.hpr[0] + (scale * dh);
00151 coord.hpr[1] = pPre->transform.hpr[1] + (scale * dp);
00152 coord.hpr[2] = pPre->transform.hpr[2] + (scale * dr);
00153 setTransform (&coord);
00154 }
00155 }
00156 }
00157
00158