22 #include <grass/gis.h>
23 #include <grass/glocale.h>
24 #include <grass/gstypes.h>
25 #include <grass/keyframe.h>
26 #include <grass/kftypes.h>
28 static float spl3(
float,
double,
double,
double,
double,
double,
double,
31 static float spl3(
float tension,
double data0,
double data1,
double x,
32 double x2,
double x3,
double lderiv,
double rderiv)
35 (data0 * (2 * x3 - 3 * x2 + 1) + data1 * (-2 * x3 + 3 * x2) +
36 (
double)tension * lderiv * (x3 - 2 * x2 + x) +
37 (
double)tension * rderiv * (x3 - x2)));
52 newk = (Keylist *) G_malloc(
sizeof(Keylist));
57 for (i = 0; i < KF_NUMFIELDS; i++) {
58 newk->fields[i] = k->fields[i];
62 newk->look_ahead = k->look_ahead;
63 newk->fieldmask = k->fieldmask;
64 newk->next = newk->prior =
NULL;
84 float startpos, endpos, curpos;
85 unsigned long mask = 0xFFFFFFFF;
89 for (k = keys; k->next; k = k->next) ;
93 curpos = startpos + time * (endpos - startpos);
95 for (k = keys; k->next; k = k->next) {
96 if (k->pos <= curpos) {
120 for (k = keys; k; k = k->next) {
121 if ((mask & k->fieldmask) == mask) {
144 int onestep,
int render,
unsigned long mode)
153 for (frame = step - 1; frame < numsteps; frame++) {
163 if ((mask & KF_FROMX_MASK)) {
164 tmp[
X] = v->fields[KF_FROMX];
166 if ((mask & KF_FROMY_MASK)) {
167 tmp[
Y] = v->fields[KF_FROMY];
169 if ((mask & KF_FROMZ_MASK)) {
170 tmp[Z] = v->fields[KF_FROMZ];
176 G_debug(3,
"gk_follow_frames():");
177 G_debug(3,
" MASK: %lx", mask);
178 G_debug(3,
" FROM: %f %f %f", tmp[
X], tmp[
Y], tmp[Z]);
185 if ((mask & KF_DIRX_MASK)) {
186 tmp[
X] = v->fields[KF_DIRX];
188 if ((mask & KF_DIRY_MASK)) {
189 tmp[
Y] = v->fields[KF_DIRY];
191 if ((mask & KF_DIRZ_MASK)) {
192 tmp[Z] = v->fields[KF_DIRZ];
200 G_debug(3,
"gk_follow_frames():");
202 G_debug(3,
" DIR: %f %f %f\n", tmp[X], tmp[Y], tmp[Z]);
204 if ((mask & KF_TWIST_MASK)) {
208 if ((mask & KF_FOV_MASK)) {
238 if (mode & FM_PATH) {
242 if (mode & FM_VECT) {
246 if (mode & FM_SITE) {
256 if (mode & FM_LABEL) {
307 Viewnode *v, *newview;
308 Keylist *k, *kp1, *kp2, *km1, **tkeys;
309 float startpos, endpos;
310 double dt1, dt2, x, x2, x3,
range, time, time_step, len, rderiv, lderiv;
313 tkeys = (Keylist **) G_malloc(keysteps *
sizeof(Keylist *));
320 if (keys && keysteps) {
322 G_warning(_(
"Need at least 3 keyframes for spline"));
328 for (k = keys; k->next; k = k->next) ;
330 startpos = keys->pos;
332 range = endpos - startpos;
333 time_step = range / (newsteps - 1);
335 newview = (Viewnode *) G_malloc(newsteps *
sizeof(Viewnode));
341 for (i = 0; i < newsteps; i++) {
346 time = startpos + i * time_step;
348 if (i == newsteps - 1) {
352 for (field = 0; field < KF_NUMFIELDS; field++) {
356 k = kp1 = kp2 = km1 =
NULL;
361 loop, tkeys, &k, &kp1, &kp2, &km1,
368 if (len == 0.0 || nvk == 0) {
372 v->fields[field] = keys->fields[field];
376 v->fields[field] = k->fields[field];
381 else if (!km1 && !kp2) {
383 v->fields[field] =
lin_interp((time - k->pos) / len,
389 x = (time - k->pos) / len;
395 rderiv = (kp2->fields[field] - k->fields[field]) / dt2;
396 lderiv = (3 * (kp1->fields[field] -
397 k->fields[field]) / dt1 - rderiv) / 2.0;
398 v->fields[field] = spl3(t, k->fields[field],
399 kp1->fields[field], x, x2, x3,
404 lderiv = (kp1->fields[field] - km1->fields[field]) / dt1;
405 rderiv = (3 * (kp1->fields[field] -
406 k->fields[field]) / dt2 - lderiv) / 2.0;
407 v->fields[field] = spl3(t, k->fields[field],
408 kp1->fields[field], x, x2, x3,
413 lderiv = (kp1->fields[field] - km1->fields[field]) / dt1;
414 rderiv = (kp2->fields[field] - k->fields[field]) / dt2;
415 v->fields[field] = spl3(t, k->fields[field],
416 kp1->fields[field], x, x2, x3,
458 Keylist * karray[], Keylist ** km1, Keylist ** kp1,
459 Keylist ** kp2, Keylist ** km2,
double *dt1,
465 *km1 = *kp1 = *kp2 = *km2 =
NULL;
468 for (i = 0; i < nvk; i++) {
469 if (time < karray[i]->
pos) {
480 *km1 = karray[nvk - 1];
485 *km1 = karray[i - 1];
487 len = karray[i]->pos - karray[i - 1]->pos;
492 *km2 = karray[nvk - 2];
493 *kp2 = karray[(i + 1) % nvk];
497 *kp2 = karray[i + 1];
501 else if (i == nvk - 1) {
504 *km2 = nvk > 2 ? karray[i - 2] : karray[1];
509 *km2 = karray[i - 2];
514 *km2 = karray[i - 2];
515 *kp2 = karray[i + 1];
518 *dt1 = (*km2) ? (*kp1)->pos - (*km2)->pos : len;
519 *dt2 = (*kp2) ? (*kp2)->pos - (*km1)->pos : len;
521 if (i == 1 && loop) {
525 if (i == nvk - 1 && loop) {
543 return ((
double)(val1 + dt * (val2 - val1)));
561 Keylist * karray[], Keylist ** km1, Keylist ** kp1)
568 for (i = 0; i < nvk; i++) {
569 if (time < karray[i]->
pos) {
580 *km1 = karray[nvk - 1];
585 *km1 = karray[i - 1];
587 len = karray[i]->pos - karray[i - 1]->pos;
607 int newsteps,
int loop)
610 Viewnode *v, *newview;
611 Keylist *k, *k1, *k2, **tkeys;
612 float startpos, endpos, dt,
range, time, time_step, len;
615 tkeys = (Keylist **) G_malloc(keysteps *
sizeof(Keylist *));
622 if (keys && keysteps) {
624 G_warning(_(
"Need at least 2 keyframes for interpolation"));
630 for (k = keys; k->next; k = k->next) ;
632 startpos = keys->pos;
634 range = endpos - startpos;
635 time_step = range / (newsteps - 1);
637 newview = (Viewnode *) G_malloc(newsteps *
sizeof(Viewnode));
643 for (i = 0; i < newsteps; i++) {
648 time = startpos + i * time_step;
649 if (i == newsteps - 1) {
653 for (field = 0; field < KF_NUMFIELDS; field++) {
658 v->fields[field] = keys->fields[field];
668 if (len == 0.0 || nvk == 0) {
672 v->fields[field] = keys->fields[field];
676 v->fields[field] = k1->fields[field];
680 dt = (time - k1->pos) / len;
709 for (c = k; c; c = c->next) {
711 if ((c->fields[KF_TWIST] - p->fields[KF_TWIST]) > 1800.) {
712 for (t = c; t; t = t->next) {
713 t->fields[KF_TWIST] -= 3600.;
716 else if ((p->fields[KF_TWIST] - c->fields[KF_TWIST]) > 1800.) {
717 for (t = k, j = 0; j < cnt; j++, t = t->next) {
718 t->fields[KF_TWIST] -= 3600.;
747 if (!views || !keys) {
761 for (frame = 0; frame < steps; frame++) {
771 for (k = keys; k; k = k->next) {
void gsd_zwritemask(unsigned long n)
Write out z-mask.
void GS_set_fov(int fov)
Set field of view.
void gk_free_key(Keylist *ok)
Free keyframe list.
void GS_getlight_position(int num, float *xpos, float *ypos, float *zpos, int *local)
Get light position.
void G_free(void *buf)
Free allocated memory.
unsigned long gk_get_mask_sofar(float time, Keylist *keys)
Get mask value.
double lin_interp(float dt, float val1, float val2)
Linear interpolation.
void GS_done_draw(void)
Draw done, swap buffers.
void GS_get_from(float *fr)
Get viewpoint 'from' position.
Viewnode * gk_make_framesfromkeys(Keylist *keys, int keysteps, int newsteps, int loop, float t)
Generate viewnode from keyframes.
void gsd_colormode(int cm)
Set color mode.
void correct_twist(Keylist *k)
Correct twist value.
void gsd_color_func(unsigned int col)
Set current color.
void GS_clear(int col)
Clear view.
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.
void gsd_x(geosurf *gs, float *center, int colr, float siz)
ADD.
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.
double get_key_neighbors(int nvk, double time, double range, int loop, Keylist *karray[], Keylist **km1, Keylist **kp1, Keylist **kp2, Keylist **km2, double *dt1, double *dt2)
Find interval containing time.
void gsd_endline(void)
End line.
int gk_viable_keys_for_mask(unsigned long mask, Keylist *keys, Keylist **keyret)
ADD.
void GS_set_viewdir(float *dir)
Set viewdir.
void GVL_alldraw_vol(void)
Draw all volume sets.
void GS_alldraw_surf(void)
Draw all surfaces.
void gk_follow_frames(Viewnode *view, int numsteps, Keylist *keys, int step, int onestep, int render, unsigned long mode)
Checks key masks.
void GS_moveto(float *pt)
Move viewpoint.
void GS_alldraw_wire(void)
Draw all wires.
void gsd_vert_func(float *pt)
ADD.
void GS_set_twist(int t)
Set viewpoint twist value.
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.
void gsd_linewidth(short n)
Set width of rasterized lines.
int GS_get_longdim(float *dim)
Get largest dimension.
double get_2key_neighbors(int nvk, float time, float range, int loop, Keylist *karray[], Keylist **km1, Keylist **kp1)
Finds interval containing time, putting left (or equal) key at km1, right at kp1. ...
unsigned int GS_default_draw_color(void)
Get default draw color.
void gsd_bgnline(void)
Begin line.
Keylist * gk_copy_key(Keylist *k)
Copy keyframes.
void GS_set_draw(int where)
Sets which buffer to draw to.
void GS_setlight_position(int num, float xpos, float ypos, float zpos, int local)
Set light position.
void GS_alldraw_cplane_fences(void)
Draw all cplace fences ?