Пример #1
0
int main()
{
  fprintf(stderr, "%s\n", "testing camera_new");
  camera *c1 = camera_new(vec_new(0.0, 0.0, 1.0), 10, 10);
  camera_print(c1);
  fprintf(stderr, "%s\n", "testing camera_dup");
  camera *c2 = camera_dup(c1);
  camera_free(c1);
  camera_print(c2);
  c1 = camera_dup(c2);
  fprintf(stderr, "%s\n", "VALGRIND TESTING");
  camera_free(c1);
  camera_free(c2);

}
Пример #2
0
void camera_rotate_animate(gint axis, gdouble *angle, gint overwrite, struct model_pak *model)
{
gdouble a, radian[3];
GSList *journey;
struct camera_pak *camera;

g_assert(model != NULL);

dialog_destroy_type(ANIM);

/* TODO - angle checks */
ARR3SET(radian, angle);
VEC3MUL(radian, D2R);

journey = NULL;
for (a=radian[0] ; a<radian[1]+0.5*radian[2] ; a+=radian[2])
  {
  camera = camera_dup(model->camera);
  switch (axis)
    {
    case 1:
      quat_concat_euler(camera->q, ROLL, a);
      break;

    case 2:
      quat_concat_euler(camera->q, YAW, a);
      break;

    default:
      quat_concat_euler(camera->q, PITCH, a);
    }
  journey = g_slist_prepend(journey, camera);
  }

journey = g_slist_reverse(journey);

if (overwrite)
  {
  free_slist(model->transform_list);
  model->transform_list = journey;
  }
else
  model->transform_list = g_slist_concat(model->transform_list, journey);

model->num_frames = g_slist_length(model->transform_list);
model->animation = TRUE;

redraw_canvas(SINGLE);
}
Пример #3
0
void camera_waypoint_animate(gint frames, gint overwrite, struct model_pak *model)
{
gint i;
gdouble a, af, v[3], e[3], o[3], tmp[3];
gdouble jf, jv[3], x[3], mat[9];
GSList *list, *journey;
struct camera_pak *cam, *cam1, *cam2;

/* checks */
g_assert(model != NULL);
g_assert(frames > 0);
if (g_slist_length(model->waypoint_list) < 2)
  {
  gui_text_show(ERROR, "You need to make at least 2 waypoint.\n");
  return;
  }

/* close any active animation dialog */
dialog_destroy_type(ANIM);

#if DEBUG_CAMERA_ANIMATE
printf("frames for each traversal: %d\n", frames);
#endif

list = model->waypoint_list;
cam1 = list->data;
list = g_slist_next(list);

/* create the camera journey */
journey = NULL;
while (list)
  {
  cam2 = list->data;

/* setup camera journey vector */
  ARR3SET(jv, cam2->x);
  ARR3SUB(jv, cam1->x);

/* add starting camera over journey leg */
  for (i=0 ; i<frames ; i++)
    {
/* journey fraction */
    jf = i;
    jf /= frames;

    ARR3SET(x, jv);
    VEC3MUL(x, jf);    

    cam = camera_dup(cam1);
    ARR3ADD(cam->x, x);

    journey = g_slist_prepend(journey, cam);
    }
 
/* approx 5 degrees */
#define ROTATION_INCREMENT 0.08727
/* (v x e plane alignment) */
proj_vop(v, cam2->v, cam1->o);
a = via(v, cam1->v, 3);

/* compute rotation increment */
af = (gint) nearest_int(a / ROTATION_INCREMENT);
if (!af)
  af = 1.0;

/* test rotation sense */
matrix_v_rotation(mat, cam1->o, a);
ARR3SET(tmp, cam1->v);
vecmat(mat, tmp);
if (via(tmp, v, 3) > 0.1)
  a *= -1.0;

/* build rotaton */
matrix_v_rotation(mat, cam1->o, a/af);

/* apply to camera */
ARR3SET(v, cam1->v);
ARR3SET(e, cam1->e);
for (i=af ; i-- ; )
  {
  cam = camera_dup(cam1);
  ARR3SET(cam->x, cam2->x);

  vecmat(mat, v);
  vecmat(mat, e);

  ARR3SET(cam->v, v);
  ARR3SET(cam->e, e);

  journey = g_slist_prepend(journey, cam);
  }

/* TODO - apply elevation to get v in complete coincidence */
/* rotate about e to achieve coincidence */
a = via(v, cam2->v, 3);

/* compute rotation increment */
af = (gint) nearest_int(a / ROTATION_INCREMENT);
if (!af)
  af = 1.0;

/* test rotation sense */
matrix_v_rotation(mat, e, a);
ARR3SET(tmp, v);
vecmat(mat, tmp);
if (via(tmp, cam2->v, 3) > 0.1)
  a *= -1.0;

/* build rotaton */
matrix_v_rotation(mat, e, a/af);

/* apply to camera */
ARR3SET(o, cam1->o);
for (i=af ; i-- ; )
  {
  cam = camera_dup(cam1);
  ARR3SET(cam->x, cam2->x);

  vecmat(mat, v);
  vecmat(mat, o);

  ARR3SET(cam->v, v);
  ARR3SET(cam->o, o);
  ARR3SET(cam->e, e);

  journey = g_slist_prepend(journey, cam);
  }

/* endpoint camera */
  journey = g_slist_prepend(journey, camera_dup(cam2));

/* get next journey leg */
  cam1 = cam2;
  list = g_slist_next(list);
  }
journey = g_slist_reverse(journey);

if (overwrite)
  {
  free_slist(model->transform_list);
  model->transform_list = journey;
  }
else
  model->transform_list = g_slist_concat(model->transform_list, journey);

model->num_frames = g_slist_length(model->transform_list);
model->animation = TRUE;

redraw_canvas(SINGLE);
}
Пример #4
0
gint read_frame(FILE *fp, gint n, struct model_pak *model)
{
    gint status;
    gdouble rmax, v1[3], v2[3];
    gpointer camera=NULL;
    GString *err_text;

    g_assert(model != NULL);

    rmax = model->rmax;

    /* conventional or transformation style animation */
    if (model->transform_list)
    {
        /* NEW - process transformation list as an animation */
        status = read_transform(n, model);
    }
    else
    {
        g_assert(fp != NULL);

        ARR3SET(v1, model->centroid);
        ARR3SET(v2, model->offset);

        status = read_raw_frame(fp, n, model);
        if (status)
        {
            err_text = g_string_new("");
            g_string_printf(err_text, "Error reading frame: %d\n", n);
            gui_text_show(ERROR, err_text->str);
            g_string_free(err_text, TRUE);
            return(1);
        }

        /* setup (have to save camera) */
        camera = camera_dup(model->camera);
        model_prep(model);
        model->camera = camera;
        g_free(model->camera_default);
        model->camera_default = camera;

        ARR3SET(model->centroid, v1);
        ARR3SET(model->offset, v2);
    }

    /* apply desired constraint */
    if (model->periodic && !model->anim_fix)
    {
        switch (model->anim_confine)
        {
        case PBC_CONFINE_ATOMS:
            coords_confine_cores(model->cores, model);

        case PBC_CONFINE_MOLS:
            coords_compute(model);
            connect_bonds(model);
            connect_molecules(model);
            break;
        }
    }

    if (model->anim_noscale)
        model->rmax = rmax;

    return(0);
}