21 #include <grass/gis.h>
22 #include <grass/glocale.h>
23 #include <grass/gstypes.h>
24 #include <grass/keyframe.h>
25 #include <grass/kftypes.h>
28 static int _add_key(Keylist *,
int,
float);
29 static void _remove_key(Keylist *);
31 static Keylist *Keys =
NULL;
32 static Keylist *Keytail =
NULL;
33 static Viewnode *Views =
NULL;
34 static float Keystartpos = 0.0;
35 static float Keyendpos = 1.0;
36 static float Tension = 0.8;
37 static int Viewsteps = 0;
38 static int Numkeys = 0;
39 static int Interpmode = KF_SPLINE;
43 static int _add_key(Keylist * newk,
int force_replace,
float precis)
45 Keylist *k, *tempk, *prev;
52 for (k = Keys; k; k = k->next) {
53 if (k->pos >= newk->pos - precis && k->pos <= newk->pos + precis) {
57 k->prior->next = newk;
65 newk->prior = k->prior;
79 if (newk->pos < Keys->pos) {
88 if (k->pos > newk->pos) {
100 Keytail = prev->next = newk;
106 Keys = Keytail = newk;
113 static void _remove_key(Keylist * k)
116 k->prior->next = k->next;
118 k->next->prior = k->prior;
127 k->next->prior =
NULL;
130 k->next = k->prior =
NULL;
145 if (KF_LEGAL_MODE(mode)) {
160 Tension = tens > 1.0 ? 1.0 : (tens < 0.0 ? 0.0 : tens);
218 if (
NULL == (fp = fopen(name,
"w"))) {
219 G_fatal_error(_(
"Unable to open file <%s> for writing"), name);
222 fprintf(fp,
"30 \n");
224 for (k = Keys; k; k = k->next) {
227 "{%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} ",
228 k->pos, k->fields[KF_FROMX], k->fields[KF_FROMY],
229 k->fields[KF_FROMZ], k->fields[KF_DIRX], k->fields[KF_DIRY],
230 k->fields[KF_DIRZ], k->fields[KF_FOV] / 10.,
231 k->fields[KF_TWIST], cnt);
256 if (k->fields[KF_FROMX] == Keys->fields[KF_FROMX] &&
257 k->fields[KF_FROMY] == Keys->fields[KF_FROMY] &&
258 k->fields[KF_FROMZ] == Keys->fields[KF_FROMZ]) {
263 Keystartpos = Keys->pos;
266 if (Interpmode == KF_LINEAR && Numkeys > 1) {
275 G_warning(_(
"Check no. of frames requested and keyframes marked"));
278 else if (Numkeys > 2) {
285 (Keys, Numkeys, Viewsteps, loop, 1.0 - Tension);
288 G_warning(_(
"Check no. of frames requested and keyframes marked"));
302 Viewsteps = newsteps;
343 for (k = Keys; k; k = k->next) {
344 if (k->pos >= oldpos - precis && k->pos <= oldpos + precis) {
347 _add_key(k, 1, precis);
375 for (cnt = 0, k = Keys; k;) {
378 if (k->pos >= pos - precis && k->pos <= pos + precis) {
438 if (
NULL == (newk = (Keylist *)
malloc(
sizeof(Keylist)))) {
439 fprintf(stderr,
"Out of memory\n");
446 newk->fields[KF_FROMX] = tmp[
X];
447 newk->fields[KF_FROMY] = tmp[
Y];
448 newk->fields[KF_FROMZ] = tmp[Z];
450 G_debug(3,
"KEY FROM: %f %f %f", tmp[
X], tmp[
Y], tmp[Z]);
461 newk->fields[KF_DIRX] = tmp[
X];
462 newk->fields[KF_DIRY] = tmp[
Y];
463 newk->fields[KF_DIRZ] = tmp[Z];
468 newk->fieldmask = fmask;
472 if (0 < _add_key(newk, force_replace, precis)) {
492 if (step > 0 && step <= Viewsteps) {
void gk_free_key(Keylist *ok)
Free keyframe list.
void GK_update_tension(void)
Update tension.
void GS_done_draw(void)
Draw done, swap buffers.
void GS_get_from(float *fr)
Get viewpoint 'from' position.
int GS_get_twist(void)
Get twist value.
Viewnode * gk_make_framesfromkeys(Keylist *keys, int keysteps, int newsteps, int loop, float t)
Generate viewnode from keyframes.
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 GV_alldraw_vect(void)
Draw all vector sets.
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 GS_draw_all_list(void)
Draw all glLists.
void GVL_alldraw_vol(void)
Draw all volume sets.
void GK_set_numsteps(int newsteps)
Set the number of frames to be interpolated from keyframes.
void gk_follow_frames(Viewnode *view, int numsteps, Keylist *keys, int step, int onestep, int render, unsigned long mode)
Checks key masks.
int GK_delete_key(float pos, float precis, int justone)
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_show_list(int flag)
Show list.
G_warning("category support for [%s] in mapset [%s] %s", name, mapset, type)
int G_debug(int level, const char *msg,...)
Print debugging message.
void GS_get_viewdir(float *dir)
Get viewdir.
int GK_set_interpmode(int mode)
Set interpolation mode.
void GK_show_path(int flag)
Draw the current path.
void GK_showtension_start(void)
void GK_update_frames(void)
Recalculate path using the current number of frames requested.
void GK_clear_keys(void)
Deletes all keyframes, resets field masks.
void GK_show_vect(int flag)
Show vector sets.
void GK_print_keys(const char *name)
Print keyframe info.
void GK_do_framestep(int step, int render)
Moves the animation to frame number "step".
int G_fatal_error(const char *msg,...)
Print a fatal error message to stderr.
void GK_set_tension(float tens)
Set value for tension when interpmode is KF_SPLINE.
int GK_move_key(float oldpos, float precis, float newpos)
Move keyframe.
int GS_get_fov(void)
Get fied of view.
void GK_show_vol(int flag)
Show volumes.
void GK_show_site(int flag)
Show point sets.
void GS_set_draw(int where)
Sets which buffer to draw to.