/* * routines for managing runtime display of ray traced scene */ static dispHandle * tachyon_display_create(SceneHandle scene) { dispHandle * dh; dh = (dispHandle *) malloc(sizeof(dispHandle)); if (dh != NULL) { memset(dh, 0, sizeof(dispHandle)); rt_get_resolution(scene, &dh->xsize, &dh->ysize); #if defined(USEOPENGL) || defined(USERTVI) dh->img = malloc((dh->xsize)*(dh->ysize)*3); if (dh->img != NULL) { #if defined(USEOPENGL) dh->glwin = glwin_create("Tachyon Parallel/Multiprocessor Ray Tracer", dh->xsize, dh->ysize); #elif defined(USERTVI) dh->rtviwin = rt_rtvi_init(dh->xsize, dh->ysize); #endif rt_rawimage_rgb24(scene, dh->img); } else { printf("Couldn't allocate image buffer for framebuffer display!!\n"); free(dh); return NULL; } #endif } return dh; }
int main(int argc, char **argv) { if (argc < 2) { printf("%s: Invalid parms\n", argv[0]); printf("usage: \n"); printf(" %s Tracker0@host\n", argv[0]); return -1; } char *server = argv[1]; pos *phan_position = new pos; pos *phan_offset = new pos; force *phan_force = new force; state *atom_state = new state; int ff_enabled, ff_active; double kspr = 500.0; // Units??? vrpn_Tracker_Remote *tkr; vrpn_Button_Remote *btn; vrpn_ForceDevice_Remote *fdv; printf("Opening: %s ...\n", server); tkr = new vrpn_Tracker_Remote(server); tkr->register_change_handler(phan_position, handle_tracker); btn = new vrpn_Button_Remote(server); btn->register_change_handler(&ff_enabled, handle_button); fdv = new vrpn_ForceDevice_Remote(server); fdv->register_force_change_handler(phan_force, handle_force); void * myglwin = glwin_create(700, 700); if (myglwin == NULL) { printf("Failed to open OpenGL window!!\n"); return -1; } atom_state->x = 0.0; atom_state->y = 0.0; atom_state->z = 0.0; atom_state->vx = 0.0; atom_state->vy = 0.0; atom_state->vz = 0.0; atom_state->ax = 0.0; atom_state->ay = 0.0; atom_state->az = 0.0; atom_state->mass = .001; ff_active = 0; init_graphics(myglwin); GLUquadricObj *qobj = gluNewQuadric(); GLUquadricObj *qatom = gluNewQuadric(); /* * main interactive loop */ while (1) { // Let the tracker do its thing tkr->mainloop(); btn->mainloop(); fdv->mainloop(); run_dynamics(atom_state, phan_force); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); if (ff_enabled ) { if (!ff_active) { // Set up force field so initially the force is zero phan_offset->x = phan_position->x - .2*atom_state->x; phan_offset->y = phan_position->y - .2*atom_state->y; phan_offset->z = phan_position->z - .2*atom_state->z; } // Now turn the force field on // scene -> haptic: rotate 180 about the y axis fdv->setConstraintMode(vrpn_ForceDevice::POINT_CONSTRAINT); float cpos[3]; cpos[0] = -(.2*atom_state->x + phan_offset->x); cpos[1] = (.2*atom_state->y + phan_offset->y); cpos[2] = -(.2*atom_state->z + phan_offset->z); fdv->setConstraintPoint(cpos); fdv->setConstraintKSpring(kspr); fdv->enableConstraint(1); // enable force field ff_active = 1; } else if (ff_active) { fdv->enableConstraint(0); // disable force field ff_active = 0; } draw_axes(); draw_tracker_and_atom(phan_force, qobj, atom_state, qatom); glwin_swap_buffers(myglwin); } } /* main */