#include "../ctl/ctldef.h"
#include "iterator.h"
Go to the source code of this file.
Functions | |
void | LinePath_init (LinePath *self, int x1, int y1, int z1, unsigned msBegin, int x2, int y2, int z2, unsigned msFinish) |
Initialize linear motion. | |
void | LinePath_setpos (LinePath *self, int x, int y, int z, unsigned msCurrent) |
Set current position in space, now. | |
void | LinePath_moveto (LinePath *self, int x, int y, int z, unsigned msCurrent, unsigned msArrive) |
Move from current position to target. | |
bool | LinePath_curr (const LinePath *self, int *x, int *y, int *z, unsigned msCurrent) |
Get current position in space, given time. | |
int | Animator_init (Animator *self, int firstFrame, int lastFrame, Animator_Dir dir, unsigned msPerFrame) |
Initialize an animation. | |
int | Animator_set (Animator *self, int frame) |
Set animation to single frame. | |
bool | Animator_pending (const Animator *self) |
Return true if we're pending a oneshot event. | |
bool | Animator_curr (Animator *self, int *frame, unsigned msCurrent) |
Get current animation frame. |
Definition in file iterator.c.
bool Animator_curr | ( | Animator * | self, | |
int * | frame, | |||
unsigned | msCurrent | |||
) |
Get current animation frame.
self | Animation we're cycling | |
frame | Int to receive frame index | |
msCurrent | Realtime in milliseconds |
Definition at line 168 of file iterator.c.
00169 { 00170 if( msCurrent - self->msprev > self->msframe ) 00171 { 00172 if( !self->msprev ) 00173 { 00174 self->msprev = msCurrent; 00175 *frame = self->iFrame; 00176 return false; 00177 } 00178 self->msprev = msCurrent; 00179 switch( self->aDir ) 00180 { 00181 case an_Stop: 00182 break; 00183 case an_ForwardOneshot: 00184 if( ++self->iFrame > self->lastFrame ) 00185 { 00186 *frame = self->iFrame = self->lastFrame; 00187 self->aDir = an_Stop; 00188 return false; 00189 } 00190 break; 00191 case an_BackwardOneshot: 00192 if( --self->iFrame < self->firstFrame ) 00193 { 00194 *frame = self->iFrame = self->firstFrame; 00195 self->aDir = an_Stop; 00196 return false; 00197 } 00198 break; 00199 case an_ForwardLoop: 00200 if( ++self->iFrame > self->lastFrame ) 00201 self->iFrame = self->firstFrame; 00202 break; 00203 case an_BackwardLoop: 00204 if( --self->iFrame < self->firstFrame ) 00205 self->iFrame = self->lastFrame; 00206 break; 00207 case an_ForwardPingPong: 00208 if( ++self->iFrame > self->lastFrame ) 00209 { 00210 self->iFrame = self->lastFrame-1; 00211 self->aDir = an_BackwardPingPong; 00212 } 00213 break; 00214 case an_BackwardPingPong: 00215 if( --self->iFrame < self->firstFrame ) 00216 { 00217 self->iFrame = self->firstFrame + 1; 00218 self->aDir = an_ForwardPingPong; 00219 } 00220 break; 00221 case an_Random: 00222 self->iFrame = self->firstFrame + (rand() % (1+self->lastFrame-self->firstFrame)); 00223 break; 00224 } 00225 00226 } 00227 *frame = self->iFrame; 00228 return true; 00229 }
int Animator_init | ( | Animator * | self, | |
int | firstFrame, | |||
int | lastFrame, | |||
Animator_Dir | dir, | |||
unsigned | msPerFrame | |||
) |
Initialize an animation.
self | Animation we're cycling | |
firstFrame | First frame index in set we're animating | |
lastFrame | Last frame index in set we're animating | |
dir | Animation type to apply | |
msPerFrame | How many milliseconds each frame should be displayed |
Definition at line 106 of file iterator.c.
00107 { 00108 self->msprev = 0; 00109 self->msframe = msPerFrame; 00110 self->firstFrame = firstFrame; 00111 self->lastFrame = lastFrame; 00112 self->aDir = dir; 00113 switch( dir ) 00114 { 00115 case an_Stop: 00116 case an_ForwardOneshot: 00117 case an_ForwardLoop: 00118 case an_ForwardPingPong: 00119 case an_Random: 00120 self->iFrame = firstFrame; 00121 break; 00122 case an_BackwardOneshot: 00123 case an_BackwardLoop: 00124 case an_BackwardPingPong: 00125 self->iFrame = lastFrame; 00126 break; 00127 } 00128 return firstFrame; 00129 }
bool Animator_pending | ( | const Animator * | self | ) |
Return true if we're pending a oneshot event.
self | Animation we're cycling |
Definition at line 151 of file iterator.c.
00152 { 00153 if( self->aDir == an_ForwardOneshot ) 00154 return self->iFrame <= self->lastFrame; 00155 else if( self->aDir == an_BackwardOneshot ) 00156 return self->iFrame >= self->firstFrame; 00157 return false; 00158 }
int Animator_set | ( | Animator * | self, | |
int | frame | |||
) |
Set animation to single frame.
self | Animation we're cycling | |
frame | Frame to set |
Definition at line 136 of file iterator.c.
00137 { 00138 self->msprev = 0; 00139 self->msframe = 0; 00140 self->aDir = an_Stop; 00141 self->firstFrame = frame; 00142 self->lastFrame = frame; 00143 self->iFrame = frame; 00144 return frame; 00145 }
bool LinePath_curr | ( | const LinePath * | self, | |
int * | x, | |||
int * | y, | |||
int * | z, | |||
unsigned | msCurrent | |||
) |
Get current position in space, given time.
self | Motion we're operating | |
x,y,z | A place to put current position | |
msCurrent | Current time |
Definition at line 70 of file iterator.c.
Referenced by LinePath_moveto().
00071 { 00072 if( msCurrent <= self->begin ) 00073 { 00074 *x = self->x1; 00075 *y = self->y1; 00076 *z = self->z1; 00077 return true; 00078 } 00079 else if( msCurrent >= self->end ) 00080 { 00081 *x = self->x2; 00082 *y = self->y2; 00083 *z = self->z2; 00084 return false; 00085 } 00086 else 00087 { 00088 int total = (int)(1u + self->end - self->begin); 00089 int elapsed = (int)(msCurrent - self->begin); 00090 *x = self->x1 + ((self->x2-self->x1) * elapsed / total); 00091 *y = self->y1 + ((self->y2-self->y1) * elapsed / total); 00092 *z = self->z1 + ((self->z2-self->z1) * elapsed / total); 00093 return true; 00094 } 00095 }
void LinePath_init | ( | LinePath * | self, | |
int | x1, | |||
int | y1, | |||
int | z1, | |||
unsigned | msBegin, | |||
int | x2, | |||
int | y2, | |||
int | z2, | |||
unsigned | msFinish | |||
) |
Initialize linear motion.
self | Motion we're setting up | |
x1,y1,z1 | Start position | |
msBegin | Start time | |
x2,y2,z2 | End position | |
msFinish | End time |
Definition at line 19 of file iterator.c.
00020 { 00021 self->begin = msBegin; 00022 self->end = msFinish; 00023 self->x1 = x1; 00024 self->y1 = y1; 00025 self->z1 = z1; 00026 self->x2 = x2; 00027 self->y2 = y2; 00028 self->z2 = z2; 00029 }
void LinePath_moveto | ( | LinePath * | self, | |
int | x, | |||
int | y, | |||
int | z, | |||
unsigned | msCurrent, | |||
unsigned | msArrive | |||
) |
Move from current position to target.
self | Motion we're operating | |
x,y,z | A place to set current position | |
msCurrent | Current time | |
msArrive | Time to arrive |
Definition at line 53 of file iterator.c.
References LinePath_curr().
00054 { 00055 LinePath_curr( self, &self->x1,&self->y1,&self->z1, msCurrent ); 00056 self->begin = msCurrent; 00057 self->end = msArrive; 00058 self->x2 = x; 00059 self->y2 = y; 00060 self->z2 = z; 00061 }
void LinePath_setpos | ( | LinePath * | self, | |
int | x, | |||
int | y, | |||
int | z, | |||
unsigned | msCurrent | |||
) |
Set current position in space, now.
self | Motion we're operating | |
x,y,z | A place to set current position | |
msCurrent | Current time |
Definition at line 37 of file iterator.c.
00038 { 00039 self->begin = msCurrent; 00040 self->end = msCurrent; 00041 self->x2 = self->x1 = x; 00042 self->y2 = self->y1 = y; 00043 self->z2 = self->z1 = z; 00044 }