int morphMesh(pScene sc,pMesh mesh1) { pMesh mesh2; pPoint ppt1,ppt2; int k; static float dt = 1.0 / MAX_MORPH; imstep++; if ( imstep == 0 ) { imstep = 2; dt = -dt; if ( !imreverse ) { glutIdleFunc(NULL); morphing = 0; return(0); } } else if ( imstep == MAX_MORPH+1 ) { imstep = -MAX_MORPH+1; dt = -dt; if ( !imreverse ) { glutIdleFunc(NULL); morphing = 0; return(0); } } mesh2 = cv.mesh[1]; for (k=1; k<=mesh1->np; k++) { ppt1 = &mesh1->point[k]; ppt2 = &mesh2->point[k]; ppt1->c[0] += dt*ppt2->c[0]; ppt1->c[1] += dt*ppt2->c[1]; ppt1->c[2] += dt*ppt2->c[2]; } doLists(sc,mesh1); return(1); }
/* new scene */ int createScene (pScene sc, int idmesh) { pMesh mesh; char data[128]; /* default */ mesh = cv.mesh[idmesh]; if (!quiet) fprintf(stdout, " Computing 3D scene\n"); /* set default mode */ sc->idmesh = idmesh; sc->par.xi = sc->par.yi = 10; if (option == SCHNAUZER) { sc->par.xs = schw; sc->par.ys = schh; } else { if (sc->par.xs == 0) sc->par.xs = 600; if (sc->par.ys == 0) sc->par.ys = 600; } if (!sc->mode) sc->mode = HIDDEN; sc->item = 0; sc->shrink = 1.0; sc->slave = sc->master = -1; sc->picked = 0; if (mesh->nvn == 0) sc->type ^= S_FLAT; if (mesh->ne == 0) sc->item |= S_GEOM; /* compute scene depth */ sc->dmax = sc->dmin = mesh->xmax - mesh->xmin; sc->dmax = max(sc->dmax, mesh->ymax - mesh->ymin); sc->dmin = min(sc->dmin, mesh->ymax - mesh->ymin); if (mesh->dim == 3) { sc->dmax = max(sc->dmax, mesh->zmax - mesh->zmin); sc->dmin = min(sc->dmin, mesh->zmax - mesh->zmin); } sc->dmax = fabs(sc->dmax); sc->dmin = fabs(sc->dmin); if (!sc->par.sunp) { sc->par.sunpos[0] *= 2.0 * sc->dmax; sc->par.sunpos[1] *= 2.0 * sc->dmax; sc->par.sunpos[2] *= 2.0 * sc->dmax; } sc->par.sunpos[3] = 1.0; /* create window */ glutInitWindowSize(sc->par.xs, sc->par.ys); sc->idwin = glutCreateWindow(""); assert(sc->idwin != 0); if (fullscreen) { glutFullScreen(); sc->par.xs = glutGet(GLUT_SCREEN_WIDTH); sc->par.ys = glutGet(GLUT_SCREEN_HEIGHT); } /* set window name */ sprintf(data, "Medit - [%s] #%d", mesh->name, sc->idwin); glutSetWindowTitle(data); glutSetIconTitle(data); /* required! to change background color */ glClearColor(sc->par.back[0], sc->par.back[1], sc->par.back[2], sc->par.back[3]); /* init perspective */ sc->persp = initPersp(0, sc->dmax); sc->camera = (pCamera)initCamera(sc, Y_AXIS); if (mesh->typ == 2) { sc->persp->pmode = CAMERA; sc->persp->depth *= 0.5; } /* create default view */ sc->view = (pTransform)createTransform(); if (!sc->view) return (0); sc->type |= S_RESET + S_DECO; sc->clip = (pClip)createClip(sc, mesh); if (!sc->clip) return (0); sc->cube = (pCube)createCube(sc, mesh); if (!sc->cube) return (0); /* create menus */ if (!createMenus(sc, mesh)) return (0); /* assign callbacks */ if (sc->type & S_SCISSOR) { glutDisplayFunc(scissorScene); } else if (option == SCHNAUZER) { glutDisplayFunc(redrawSchnauzer); } else if (sc->persp->pmode == CAMERA) { glutMouseFunc(mouseCamera); glutMotionFunc(motionCamera); glutDisplayFunc(redrawScene); } else { glutMouseFunc(mouse); glutMotionFunc(motion); glutDisplayFunc(redrawScene); } glutReshapeFunc(reshapeScene); glutKeyboardFunc(keyScene); glutSpecialFunc(special); glutAttachMenu(GLUT_RIGHT_BUTTON); /* create display lists by geom type */ glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); doLists(sc, mesh); sc->glist = geomList(sc, mesh); sc->type |= S_FOLLOW; /* local stack */ if (!pilmat) { pilmat = (int *)calloc(sc->par.nbmat + 2, sizeof(int)); if (!pilmat) return (0); } /* color list */ setupPalette(sc, mesh); sc->stream = NULL; initGrafix(sc, mesh); return (1); }