21 #include <grass/gis.h>
22 #include <grass/glocale.h>
23 #include <grass/ogsf.h>
25 static int _add_key(Keylist *,
int,
float);
26 static void _remove_key(Keylist *);
28 static Keylist *Keys =
NULL;
29 static Keylist *Keytail =
NULL;
30 static Viewnode *Views =
NULL;
31 static float Keystartpos = 0.0;
32 static float Keyendpos = 1.0;
33 static float Tension = 0.8;
34 static int Viewsteps = 0;
35 static int Numkeys = 0;
36 static int Interpmode = KF_SPLINE;
40 static int _add_key(Keylist * newk,
int force_replace,
float precis)
42 Keylist *k, *tempk, *prev;
49 for (k = Keys; k; k = k->next) {
50 if (k->pos >= newk->pos - precis && k->pos <= newk->pos + precis) {
54 k->prior->next = newk;
62 newk->prior = k->prior;
76 if (newk->pos < Keys->pos) {
85 if (k->pos > newk->pos) {
97 Keytail = prev->next = newk;
103 Keys = Keytail = newk;
110 static void _remove_key(Keylist * k)
113 k->prior->next = k->next;
115 k->next->prior = k->prior;
124 k->next->prior =
NULL;
127 k->next = k->prior =
NULL;
142 if (KF_LEGAL_MODE(mode)) {
157 Tension = tens > 1.0 ? 1.0 : (tens < 0.0 ? 0.0 : tens);
215 if (
NULL == (fp = fopen(name,
"w"))) {
216 G_fatal_error(_(
"Unable to open file <%s> for writing"), name);
219 fprintf(fp,
"30 \n");
221 for (k = Keys; k; k = k->next) {
224 "{%f {{FromX %f} {FromY %f} {FromZ %f} {DirX %f} {DirY %f} {DirZ %f} {FOV %f} {TWIST %f} {cplane-0 {{pos_x 0.000000} {pos_y 0.000000} {pos_z 0.000000} {blend_type OFF} {rot 0.000000} {tilt 0.000000}}}} keyanimtag%d 0} ",
225 k->pos, k->fields[KF_FROMX], k->fields[KF_FROMY],
226 k->fields[KF_FROMZ], k->fields[KF_DIRX], k->fields[KF_DIRY],
227 k->fields[KF_DIRZ], k->fields[KF_FOV] / 10.,
228 k->fields[KF_TWIST], cnt);
253 if (k->fields[KF_FROMX] == Keys->fields[KF_FROMX] &&
254 k->fields[KF_FROMY] == Keys->fields[KF_FROMY] &&
255 k->fields[KF_FROMZ] == Keys->fields[KF_FROMZ]) {
260 Keystartpos = Keys->pos;
263 if (Interpmode == KF_LINEAR && Numkeys > 1) {
272 G_warning(_(
"Check no. of frames requested and keyframes marked"));
275 else if (Numkeys > 2) {
282 (Keys, Numkeys, Viewsteps, loop, 1.0 - Tension);
285 G_warning(_(
"Check no. of frames requested and keyframes marked"));
299 Viewsteps = newsteps;
340 for (k = Keys; k; k = k->next) {
341 if (k->pos >= oldpos - precis && k->pos <= oldpos + precis) {
344 _add_key(k, 1, precis);
372 for (cnt = 0, k = Keys; k;) {
375 if (k->pos >= pos - precis && k->pos <= pos + precis) {
429 int GK_add_key(
float pos,
unsigned long fmask,
int force_replace,
435 if (
NULL == (newk = (Keylist *) malloc(
sizeof(Keylist)))) {
436 fprintf(stderr,
"Out of memory\n");
443 newk->fields[KF_FROMX] = tmp[
X];
444 newk->fields[KF_FROMY] = tmp[
Y];
445 newk->fields[KF_FROMZ] = tmp[Z];
447 G_debug(3,
"KEY FROM: %f %f %f", tmp[
X], tmp[
Y], tmp[Z]);
458 newk->fields[KF_DIRX] = tmp[
X];
459 newk->fields[KF_DIRY] = tmp[
Y];
460 newk->fields[KF_DIRZ] = tmp[Z];
465 newk->fieldmask = fmask;
469 if (0 < _add_key(newk, force_replace, precis)) {
489 if (step > 0 && step <= Viewsteps) {
void gk_free_key(Keylist *ok)
Free keyframe list.
void GK_clear_keys(void)
Deletes all keyframes, resets field masks.
void GK_show_vect(int flag)
Show vector sets.
int GS_get_fov(void)
Get fied of view.
void GS_get_from(float *fr)
Get viewpoint 'from' position.
void GK_update_tension(void)
Update tension.
void GK_show_vol(int flag)
Show volumes.
void GS_draw_all_list(void)
Draw all glLists.
void GK_set_tension(float tens)
Set value for tension when interpmode is KF_SPLINE.
Viewnode * gk_make_framesfromkeys(Keylist *keys, int keysteps, int newsteps, int loop, float t)
Generate viewnode from keyframes.
int GK_delete_key(float pos, float precis, int justone)
void GV_alldraw_vect(void)
Draw all loaded vector sets.
int GS_get_twist(void)
Get twist value.
void G_fatal_error(const char *msg,...)
Print a fatal error message to stderr.
int gk_draw_path(Viewnode *views, int steps, Keylist *keys)
Draw path.
Viewnode * gk_make_linear_framesfromkeys(Keylist *keys, int keysteps, int newsteps, int loop)
Generate viewnode from keyframe list (linear interpolation)
void GK_do_framestep(int step, int render)
Moves the animation to frame number "step".
int G_debug(int level, const char *msg,...)
Print debugging message.
int GK_set_interpmode(int mode)
Set interpolation mode.
void gk_follow_frames(Viewnode *view, int numsteps, Keylist *keys, int step, int onestep, int render, unsigned long mode)
Checks key masks.
void GK_show_path(int flag)
Draw the current path.
void GS_clear(int col)
Clear view.
void GK_showtension_stop(void)
Show tension stop ?
void GP_alldraw_site(void)
Draw all available point sets.
unsigned int GS_background_color(void)
Get background color.
void GS_get_viewdir(float *dir)
Get viewdir.
void GVL_alldraw_vol(void)
Draw all volume sets.
void GK_show_site(int flag)
Show point sets.
void GS_set_draw(int where)
Sets which buffer to draw to.
int GK_add_key(float pos, unsigned long fmask, int force_replace, float precis)
Add keyframe.
void GS_alldraw_wire(void)
Draw all wires.
void GK_set_numsteps(int newsteps)
Set the number of frames to be interpolated from keyframes.
void GK_print_keys(const char *name)
Print keyframe info.
void GK_show_list(int flag)
Show list.
void GK_showtension_start(void)
void GK_update_frames(void)
Recalculate path using the current number of frames requested.
void G_warning(const char *msg,...)
Print a warning message to stderr.
int GK_move_key(float oldpos, float precis, float newpos)
Move keyframe.
void GS_done_draw(void)
Draw done, swap buffers.