コード例 #1
0
ファイル: api.c プロジェクト: taohonker/Ovito
void rt_camera_setup(SceneHandle voidscene, flt zoom, flt aspectratio, 
	             int antialiasing, int raydepth, 
                     apivector camcent, apivector viewvec, apivector upvec) {
  scenedef * scene = (scenedef *) voidscene;

  cameradefault(&scene->camera);

  rt_camera_zoom(voidscene, zoom);

  rt_camera_position(voidscene, camcent, viewvec, upvec);

  rt_aspectratio(voidscene, aspectratio);

  rt_aa_maxsamples(voidscene, antialiasing);

  rt_camera_raydepth(voidscene, raydepth);
}
コード例 #2
0
/*
 * main loop for creating animations by playing recorded camera fly-throughs
 */
static int animate_scene(argoptions opt, SceneHandle scene, int node) {
    char outfilename[1000];
    FILE * camfp;
    dispHandle * dh = NULL;

    if (node == 0)
        dh = tachyon_display_create(scene);

    /* if we have a camera file, then animate.. */
    if ((camfp = fopen(opt.camfilename, "r")) != NULL) {
        floatvec cv, cu, cc;
        apivector cmv, cmu, cmc;
        int frameno = 0;
        float fps;
        rt_timerhandle fpstimer;
        rt_timerhandle animationtimer;

        rt_set_ui_message(NULL);
        rt_set_ui_progress(NULL);

        if (node == 0)
            printf("Running Camera File: %s\n", opt.camfilename);

        fpstimer=rt_timer_create();
        animationtimer=rt_timer_create();

        rt_timer_start(animationtimer);

        while (!feof(camfp)) {
            fscanf(camfp, "%f %f %f  %f %f %f  %f %f %f",
                   &cv.x, &cv.y, &cv.z, &cu.x, &cu.y, &cu.z, &cc.x, &cc.y, &cc.z);

            cmv.x = cv.x;
            cmv.y = cv.y;
            cmv.z = cv.z;
            cmu.x = cu.x;
            cmu.y = cu.y;
            cmu.z = cu.z;
            cmc.x = cc.x;
            cmc.y = cc.y;
            cmc.z = cc.z;

            if (frameno != 0) {
                rt_timer_stop(fpstimer);
                fps = 1.0f / rt_timer_time(fpstimer);
            } else {
                fps = 0.0;
            }

            rt_timer_start(fpstimer);
            outfilename[0] = '\0';
            if (opt.nosave == 1) {
                if (node == 0) {
                    printf("\rRendering Frame: %9d   %10.4f FPS       ", frameno, fps);
                    fflush(stdout);
                }
            }
            else {
                sprintf(outfilename, opt.outfilename, frameno);
                if (node == 0) {
                    printf("\rRendering Frame to %s   (%10.4f FPS)       ", outfilename, fps);
                    fflush(stdout);
                }
            }

            rt_outputfile(scene, outfilename);
            rt_camera_position(scene, cmc, cmv, cmu);

            rt_renderscene(scene);

            if (dh != NULL)
                tachyon_display_draw(dh);

            frameno++;
        }
        rt_timer_stop(animationtimer);
        fps = frameno / rt_timer_time(animationtimer);
        if (node == 0) {
            printf("\rCompleted animation of %d frames                            \n", frameno);
            printf("Animation Time: %10.4f seconds  (Averaged %7.4f FPS)\n",
                   rt_timer_time(animationtimer), fps);
        }
        rt_timer_destroy(fpstimer);
        fclose(camfp);
    } else {
        if (node == 0) {
            printf("Couldn't open camera file: %s\n", opt.camfilename);
            printf("Aborting render.\n");
        }
        rt_deletescene(scene); /* free the scene */
        rt_finalize(); /* close down the rendering library and MPI */
        return -1;
    }

    if (node == 0) {
        printf("\nFinished Running Camera.\n");

        if (dh !=NULL)
            tachyon_display_delete(dh);
    }

    rt_deletescene(scene); /* free the scene */
    rt_finalize(); /* close down the rendering library and MPI */

    return 0;
}
コード例 #3
0
int tachyon_spaceball_update(sbHandle * bh, SceneHandle scene) {
  int tx, ty, tz, rx, ry, rz, buttons;
  float qq[4];
  float xx[3]={1.0, 0.0, 0.0};
  float yy[3]={0.0, 1.0, 0.0};
  float zz[3]={0.0, 0.0, 1.0};

  float m[4][4];
  float t[3];

  static float transdivisor = 5000.0;
  static float angdivisor = 20000.0;

  if (bh->sball == NULL)
    return -1;
 
  if (sball_getstatus(bh->sball, &tx, &ty, &tz, &rx, &ry, &rz, &buttons)) {
    /* negate rotations given by spaceball */
    rx = -rx;
    ry = -ry;
    rz = -rz;

    if (buttons) {
      if (buttons & SBALL_BUTTON_PICK) {
        bh->curtrans[0] = 0.0;
        bh->curtrans[1] = 0.0;
        bh->curtrans[2] = 0.0;
        trackball(bh->curquat, 0.0, 0.0, 0.0, 0.0);
        transdivisor = 5000.0;
        angdivisor = 20000.0; 
  
        bh->camviewvec = bh->orig_camviewvec;
        bh->camupvec = bh->orig_camupvec;
        bh->camcent = bh->orig_camcent;
      }

      if (buttons & SBALL_BUTTON_1) {
        transdivisor /= 1.2;
        angdivisor /= 1.2;
      }
      else if (buttons & SBALL_BUTTON_2) {
        transdivisor *= 1.2; 
        angdivisor *= 1.2;
      }

      if (buttons & SBALL_BUTTON_3)
        transdivisor /= 1.2;
      else if (buttons & SBALL_BUTTON_4)
        transdivisor *= 1.2; 

      if (buttons & SBALL_BUTTON_5) 
        angdivisor *= 1.2;
      else if (buttons & SBALL_BUTTON_6)
        angdivisor /= 1.2;


      if (buttons & SBALL_BUTTON_7) {
        return 1;  /* quit the fly through */
      }
    } /* end of button handling */
      
    t[0] = tx / transdivisor; 
    t[1] = ty / transdivisor;
    t[2] = tz / transdivisor;

    /* 
     * convert rotations and translations from the
     * spaceball's coordinate frame into the camera's frame.
     */
    bh->newtrans[0] = 
      t[0] * bh->orig_camrightvec.x +
      t[1] * bh->orig_camupvec.x +
      t[2] * bh->orig_camviewvec.x;

    bh->newtrans[1] = 
      t[0] * bh->orig_camrightvec.y +
      t[1] * bh->orig_camupvec.y +
      t[2] * bh->orig_camviewvec.y;

    bh->newtrans[2] = 
      t[0] * bh->orig_camrightvec.z +
      t[1] * bh->orig_camupvec.z +
      t[2] * bh->orig_camviewvec.z;

    /* 
     * rotate around camera's coordinate frame
     */ 
    xx[0] = bh->orig_camrightvec.x;
    xx[1] = bh->orig_camrightvec.y;
    xx[2] = bh->orig_camrightvec.z;

    yy[0] = bh->orig_camupvec.x;
    yy[1] = bh->orig_camupvec.y;
    yy[2] = bh->orig_camupvec.z;

    zz[0] = bh->orig_camviewvec.x;
    zz[1] = bh->orig_camviewvec.y;
    zz[2] = bh->orig_camviewvec.z;
 
    /* do rotations */ 
    axis_to_quat(xx, rx / angdivisor, bh->lastquat);

    axis_to_quat(yy, ry / angdivisor, qq);
    add_quats(qq, bh->lastquat, bh->lastquat);

    axis_to_quat(zz, rz / angdivisor, qq);
    add_quats(qq, bh->lastquat, bh->lastquat);

    add_quats(bh->lastquat, bh->curquat, bh->curquat);
  }
  else {
    usleep(5); /* if no movement then sleep for a tiny bit.. */
  }

  build_rotmatrix(m, bh->curquat);

  /*
   * translate along the new axes
   */
  t[0] = m[0][0] * bh->newtrans[0] + m[0][1] * bh->newtrans[1] + m[0][2] * bh->newtrans[2];
  t[1] = m[1][0] * bh->newtrans[0] + m[1][1] * bh->newtrans[1] + m[1][2] * bh->newtrans[2];
  t[2] = m[2][0] * bh->newtrans[0] + m[2][1] * bh->newtrans[1] + m[2][2] * bh->newtrans[2];

  bh->camcent.x += t[0];
  bh->camcent.y += t[1];
  bh->camcent.z += t[2];


  /*
   * rotate view system with spaceball
   */
  bh->camviewvec.x = m[0][0] * bh->orig_camviewvec.x + m[0][1] * bh->orig_camviewvec.y + m[0][2] * bh->orig_camviewvec.z;
  bh->camviewvec.y = m[1][0] * bh->orig_camviewvec.x + m[1][1] * bh->orig_camviewvec.y + m[1][2] * bh->orig_camviewvec.z;
  bh->camviewvec.z = m[2][0] * bh->orig_camviewvec.x + m[2][1] * bh->orig_camviewvec.y + m[2][2] * bh->orig_camviewvec.z;

  bh->camupvec.x = m[0][0] * bh->orig_camupvec.x + m[0][1] * bh->orig_camupvec.y + m[0][2] * bh->orig_camupvec.z;
  bh->camupvec.y = m[1][0] * bh->orig_camupvec.x + m[1][1] * bh->orig_camupvec.y + m[1][2] * bh->orig_camupvec.z;
  bh->camupvec.z = m[2][0] * bh->orig_camupvec.x + m[2][1] * bh->orig_camupvec.y + m[2][2] * bh->orig_camupvec.z;

  /*
   * update camera parameters before we render again
   */
  rt_camera_position(scene, bh->camcent, bh->camviewvec, bh->camupvec);

  return 0;
}