Пример #1
0
void keyScene(unsigned char key,int x,int y) {
  pMaterial   pm;
  pTetra      ptt;
  pHexa       ph;
  pTriangle   pt;
  pQuad       pq;
  pScene      sc,sc1;
  pMesh       mesh;
  pClip       clip;
  pCube       cube;
  pPersp      p;
  pCamera     cam;
  double      dd;
  float       a,b,c,d;
  int         k,keyact,numit,idw = currentScene();
  ubyte       post = FALSE,dolist = FALSE;


  if ( idw < 0 ) exit(0);

  /* ESC = end medit */
  if ( key == 'q' || key == 27 ) 
#ifdef IGL
  {
    deleteScene(cv.scene[idw]);
    exit(0);
  }
#else
    exit(0);
#endif
  else if ( key == 'h' || key == '?' )
Пример #2
0
void farclip (GLboolean b) {
	pScene sc;
	pPersp p;
	pCamera c;
	float look[3], ratio, units;
	int idw = currentScene();
	static GLfloat up[3] = {0.0, 1.0, 0.0};

	/* default */
	sc = cv.scene[idw];
	p = sc->persp;
	c = sc->camera;
	ratio = (GLfloat)sc->par.xs / sc->par.ys;

	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();

	switch (p->pmode) {
	case ORTHO:
		glOrtho(-1., 1., -1., 0.1, 0.01, 0.01);
		break;

	case PERSPECTIVE:
		if (b)
			gluPerspective(p->fovy, ratio, sc->dmax, 4.0 * sc->dmax);
		else
			gluPerspective(p->fovy, ratio, 0.01, 10000.0 * sc->dmax);

		units = 1.e-02;
		glPolygonOffset(1.0, units);
		break;

	case CAMERA:
		gluPerspective(p->fovy, ratio, 0.001 * sc->dmax, 4.0 * sc->dmax);
		look[0] = c->eye[0] + 0.001 * sc->dmax * c->speed[0];
		look[1] = c->eye[1] + 0.001 * sc->dmax * c->speed[1];
		look[2] = c->eye[2] + 0.001 * sc->dmax * c->speed[2];
		gluLookAt(c->eye[0], c->eye[1], c->eye[2],
		          look[0], look[1], look[2],
		          up[0], up[1], up[2]);
		break;
	}

	/* zoom transformation */
	if (p->rubber == 2) {
		glPushMatrix();
		glLoadIdentity();
		glRotatef(-p->gamma, 1., 0., 0.);
		glRotatef(p->alpha, 0., 1., 0.);
		glMultMatrixf(p->matrix);
		glGetFloatv(GL_PROJECTION_MATRIX, p->matrix);
		glPopMatrix();
		p->rubber = 0;
	}

	/* apply transformation */
	glMultMatrixf(p->matrix);

	glMatrixMode(GL_MODELVIEW);
}
Пример #3
0
void copyView(pTransform view,pCamera cam,pPersp persp) {
  cscene = currentScene();

  if ( !cview ) {
    cview = (pTransform)calloc(1,sizeof(struct transform));
    if ( !cview )  exit(2);
  }
  cview = (pTransform)memcpy(cview,view,sizeof(struct transform));
  if ( !cview )  exit(2);
  
  if ( !ccam ) {
    ccam = (pCamera)calloc(1,sizeof(struct camera));
    if ( !ccam )  exit(2);
  }
  ccam = (pCamera)memcpy(ccam,cam,sizeof(struct camera));
  if ( !ccam )  exit(2);
  
  if ( !cpersp ) {
    cpersp = (pPersp)calloc(1,sizeof(struct sperspective));
    if ( !cpersp )  exit(2);
  }
  cpersp = (pPersp)memcpy(cpersp,persp,sizeof(struct sperspective));
  if ( !cpersp )  exit(2);

  curview = 1;
}
Пример #4
0
void streamIdle (void) {
	pScene sc;
	pMesh mesh;
	static clock_t timbase = 0;
	static float maxtim = 0.;

	sc = cv.scene[currentScene()];
	sc->par.cumtim += sc->par.dt;
	sc->par.advtim = 1;
	if (sc->par.cumtim > sc->par.maxtime) {
		sc->par.cumtim = 0.0;
		sc->par.cumpertime = 0.0;
		saveimg = 0;
		sc->isotyp &= ~S_PARTICLE;
		glutIdleFunc(0);
		printf("\nfin");
	} else if (sc->par.cumpertime >= sc->par.pertime) {
		mesh = cv.mesh[sc->idmesh];
		sc->par.cumpertime = 0.0;
		if (!animParticle(sc, mesh)) {
			sc->par.cumtim = 0.0;
			sc->par.cumpertime = 0.0;
			saveimg = 0;
			glutIdleFunc(0);
			printf("\nfin");
		} else {
			glutPostRedisplay();
		}
	} else {
		glutPostRedisplay();
	}

	return;

	if (timbase < 1) {
		timbase = clock();
		maxtim = 0.0;
		sc->par.advtim = 0;
		glutPostRedisplay();
	} else {
		float elp;
		clock_t tim;

		tim = clock();
		elp = (tim - timbase) / (float)CLOCKS_PER_SEC;
		if (elp > sc->par.dt) {
			timbase = tim;
			maxtim += elp;
			sc->par.advtim = 1;
			if (maxtim > sc->par.maxtime)
				glutIdleFunc(0);
		}

		sc->par.cumtim += sc->par.dt;
		glutPostRedisplay();
	}
}
Пример #5
0
/* display cube */
void updateCube(pCube cube,pMesh mesh) {
    pScene      sc;
    pTransform  cubetr,view;
    GLfloat     inv[16],axis[4],trans[4];
    int         idw;

    /* default */
    if ( ddebug ) printf("updateCube\n");

    /* retrieve context */
    idw    = currentScene();
    sc     = cv.scene[idw];
    view   = sc->view;
    cubetr = cube->cubetr;

    /* compute cube transform */
    if ( cube->active & C_EDIT ) {
        invertMatrix(view->matrix,inv);
        inv[3] = inv[7] = inv[11] = 0.0f;
        inv[15] = 1.0;

        /* rotation cumulative */
        if ( cubetr->angle != 0.0 ) {
            transformVector(trans,cubetr->axis,inv);
            glPushMatrix();
            glLoadIdentity();
            glRotatef(cubetr->angle,trans[0],trans[1],trans[2]);
            glMultMatrixf(cubetr->rot);
            glGetFloatv(GL_MODELVIEW_MATRIX,cubetr->rot);
            glPopMatrix();
        }

        /* translation cumulative */
        axis[0] = cubetr->panx;
        axis[1] = cubetr->pany;
        axis[2] = 0.0;
        axis[3] = 1.0;
        transformVector(trans,axis,inv);

        cubetr->tra[12] = trans[0];
        cubetr->tra[13] = trans[1];
        cubetr->tra[14] = trans[2];

        /* final transformation */
        glPushMatrix();
        glLoadIdentity();
        glMultMatrixf(cubetr->tra);
        glMultMatrixf(cubetr->rot);
        glGetFloatv(GL_MODELVIEW_MATRIX,cubetr->matrix);
        glPopMatrix();
    }
    if ( !cubetr->manim ) {
        cubetr->angle = 0.0;
        cube->active ^= C_UPDATE;
    }
}
Пример #6
0
void reshapeScene (int width, int height) {
	pScene sc;

	if (ddebug) printf("reshape scene\n");

	sc = cv.scene[currentScene()];
	sc->par.xs = width;
	sc->par.ys = height;

	glViewport(0, 0, width, height);
	farclip(GL_TRUE);
}
Пример #7
0
/* OpenGL callbacks */
void redrawSchnauzer () {
	pScene sc = cv.scene[currentScene()];
	pMesh mesh;
	char *ptr, data[256];

	mesh = cv.mesh[sc->idmesh];
	strcpy(data, mesh->name);
	ptr = (char *)strstr(data, ".mesh");
	if (ptr) *ptr = '\0';

	ptr = (char *)strstr(data, ".gis");
	if (ptr) *ptr = '\0';

	strcat(data, ".ppm");
	redrawScene();
	imgHard(sc, data, 'H');

	exit(0);
}
Пример #8
0
void animateCamera() {
  pScene   sc;
  pCamera  c;
  double   dazim,delev,azim,elev;
  float    cfelev,cfazim;

  if ( !animate || !ctracking )  return;
  sc = cv.scene[currentScene()];
  c  = sc->camera;
  azim  = Azimuth(c);
  elev  = Elevation(c);

  switch (cbutton) {
    case GLUT_LEFT_BUTTON:
      cfelev = 3.0;
      cfazim = 3.0;
      delev  = 2.0*(cury-starty)/(float)sc->par.ys;
      dazim  = 2.0*(curx-startx)/(float)sc->par.xs;
      if ( delev >= 0.0 ) delev *= delev;
      else                delev = -delev*delev;
      if ( dazim >= 0.0 ) dazim *= dazim;
      else                dazim  = -dazim*dazim;
      elev += cfelev * delev;
      azim -= cfazim * dazim;
      break;
    
    case GLUT_MIDDLE_BUTTON:
      break;
    case GLUT_BUTTON_3:
      puts("button3");
      break;
    case GLUT_BUTTON_4:
      puts("button4");
      break;
  }
  updateCamera(sc,c,azim,elev);
  reshapeScene(sc->par.xs,sc->par.ys);
  glutPostRedisplay();
}
Пример #9
0
void motionCamera(int x,int y) {
  pScene   sc;
  pCamera  c;
  double   dazim,delev,azim,elev;
  float    cfelev,cfazim;

  /* keep current pos */
  curx = x;
  cury = y;

  if ( animate ) return;
  sc = cv.scene[currentScene()];
  c  = sc->camera;
  azim  = Azimuth(c);
  elev  = Elevation(c);
   switch (cbutton) {
    case GLUT_LEFT_BUTTON:
      cfelev = 50.0;
      cfazim = 50.0;
      delev  = cfelev * (y-starty)/(float)sc->par.ys;
      dazim  = cfazim * (x-startx)/(float)sc->par.xs;
      startx = x;
      starty = y;
      elev  += delev;
      azim  -= dazim;
      break;
    case GLUT_MIDDLE_BUTTON:
      break;
    case GLUT_BUTTON_3:
      puts("button3");
      break;
    case GLUT_BUTTON_4:
      puts("button4");
      break;
  }
  updateCamera(sc,c,azim,elev);
  reshapeScene(sc->par.xs,sc->par.ys);
  glutPostRedisplay();
}
Пример #10
0
void zoomMotion(int x,int y) {
  pScene      sc;
  pPersp      p;
  int         dy;

  sc = cv.scene[currentScene()];
  p  = sc->persp;

  dy = starty - y;
  if ( dy > 0 )
    if ( p->fovy < 1.0e-02 )  
      return;
    else 
      p->fovy = MEDIT_MAX(0.95*p->fovy,1e-05);
  else if ( p->fovy > 160.0 )  return;
  else
    p->fovy = MEDIT_MIN(1.1*p->fovy,179.0);

  farclip(1);
  starty = y;
  glutPostRedisplay();
}
Пример #11
0
/* link scene 1 (slave) to scene 2 (master) */
int linkView(pScene slave) {
  pScene master;
  int    idw = currentScene();

  /* default */
  if ( ddebug ) printf("link view\n");

  if ( !curview || idw == cscene )   return(0);

  /* link 2 scenes */
  master         = cv.scene[cscene];
  master->slave  = idw;
  master->master = -1;
  memcpy(slave->view,master->view,sizeof(struct transform));
  memcpy(slave->camera,master->camera,sizeof(struct camera));
  memcpy(slave->persp,master->persp,sizeof(struct sperspective));
  memcpy(slave->clip->eqn,master->clip->eqn,4*sizeof(float));
  memcpy(slave->clip->cliptr,master->clip->cliptr,sizeof(struct transform));
  slave->slave  = -1;
  slave->master = cscene;
  curview       = 0;

  return(1);
}
Пример #12
0
static void rubberMotion(int x,int y) {
  pScene      sc;
  pPersp      p;

  sc = cv.scene[currentScene()];
  p  = sc->persp;

  glEnable(GL_COLOR_LOGIC_OP);
  glLogicOp(GL_XOR);

  /* draw frame */
  drawRubberBand(rxi,ryi,rx1,ry1);
  rx2 = x;
  ry2 = sc->par.ys-y;
  drawRubberBand(rxi,ryi,rx2,ry2);
  glFlush();

  glLogicOp(GL_COPY);
  glDisable(GL_COLOR_LOGIC_OP);

  /* keep old coords */
  rx1 = rx2;
  ry1 = ry2;
}
Пример #13
0
void mouse(int button,int state,int x,int y) {
  button = alt_ctrl_left_to_middle(button);
  pScene      sc;
  pTransform  tr;
  pPersp      p;
  int         keyact,idw = currentScene();
  static int  olds = -1;
#ifdef IGL
  // Tweakbar has precedence over everything else
  if(TwEventMouseButtonGLUT(button,state,x,y) && state == GLUT_DOWN)
  {
    return;
  }
#endif

  /* default */
  if ( ddebug ) printf("control mouse %d\n",state);
  sc = cv.scene[idw];
  p  = sc->persp;
  if ( sc->cube->active & C_EDIT )
    tr = sc->cube->cubetr;
  else if ( sc->clip->active & C_EDIT ) 
    tr = sc->clip->cliptr;
  else
    tr = sc->view;
  tr->mstate  = state;
  tr->mbutton = button;

  /* check if ctrl-shift-alt pressed */
  keyact = glutGetModifiers();

  if ( state == GLUT_DOWN ) {
  
  picking=GL_FALSE;
    tracking = GL_TRUE;
    lasttime = glutGet(GLUT_ELAPSED_TIME);

    if ( button == GLUT_LEFT_BUTTON ) {
      if ( keyact & GLUT_ACTIVE_SHIFT ) {
        /* entity designation */
        picking = GL_TRUE;
	if ( sc->picklist ) glDeleteLists(sc->picklist,1);
	sc->picklist = pickingScene(sc,x,y,0);
	return;
      }

      else if ( keyact & GLUT_ACTIVE_ALT ) {
	    /* zoom */
	    starty = y;
	    glutMotionFunc(zoomMotion);
	    return;
      }

      else if ( keyact & GLUT_ACTIVE_CTRL ) {
        /* rubberband selection */
        glutSetCursor(GLUT_CURSOR_CROSSHAIR);
        p->rubix  = p->rubfx = x;
        p->rubiy  = p->rubfy = sc->par.ys-y;
        rxi = rx1 = x;
        ryi = ry1 = sc->par.ys-y;
        p->rubber = 1;
        glDrawBuffer(GL_BACK_LEFT);
        ortho2D(sc,ON);
        glutMotionFunc(rubberMotion);
        return;
      }
    }
    
    else if ( button == GLUT_MIDDLE_BUTTON && keyact & GLUT_ACTIVE_SHIFT ) {
      picking = GL_TRUE;
      if ( sc->picklist ) glDeleteLists(sc->picklist,1);
      sc->picklist = pickingScene(sc,x,y,LPoint);
      return;
    }

    /* transformation */
    startx = x;
    starty = y;
    point2Vect(x,y,sc->par.xs,sc->par.ys,tr->pos);
    glutSetCursor(GLUT_CURSOR_INFO);
  }

  else if ( state == GLUT_UP ) {

    if ( button == GLUT_LEFT_BUTTON ) {
      
      if ( keyact & GLUT_ACTIVE_CTRL ) {
        /* rubberband selection */
        p->rubfx  = x;
        p->rubfy  = sc->par.ys-y;
        p->rubber = 2;
        glDrawBuffer(GL_BACK_LEFT);
        ortho2D(sc,OFF);
        glutMotionFunc(motion);
        return;
      }
      
      else if ( keyact & GLUT_ACTIVE_ALT ) {
        glutMotionFunc(motion);
	    return;
      }

      else if ( picking == GL_TRUE ) {
        picking = GL_FALSE;
        reshapeScene(sc->par.xs,sc->par.ys);
        glutPostRedisplay();
      }
    }
    
    glutMotionFunc(motion);
    if ( sc->clip->active & C_EDIT )
      sc->clip->active |= C_REDO;

    /* transformation */
    glutSetCursor(GLUT_CURSOR_INHERIT);
    tracking = GL_FALSE;
    if ( glutGet(GLUT_ELAPSED_TIME) >= lasttime ) { 
      if ( tr->manim == GL_TRUE )  glutIdleFunc(glutIdle);
      else  tr->angle = 0.0;
      /*if ( abs(startx-x) + abs(starty-y) > 0 )*/
        glutPostRedisplay();
    }
    else if ( tr->manim == GL_TRUE && olds == idw )  
      glutIdleFunc(NULL);
  }

  olds = idw;
}
Пример #14
0
/* special keys PERSPECTIVE mode */
void special(int key,int x,int y) {
  pTransform  view;
  pScene      sc;
  pMesh       mesh;
  pClip       clip;
  pCube       cube;
  float       pancoeff = 0.1f;
  int         keyact,idw = currentScene();
  ubyte       post = TRUE;
 
  /* default */
  if ( ddebug ) printf("special key  %d\n",key);
  sc   = cv.scene[idw];

  /* special mode camera */
  if ( sc->persp->pmode == CAMERA ) {
    specCamera(sc,key);
    return;
  }
  
  view = sc->view;
  mesh = cv.mesh[sc->idmesh];
  clip = sc->clip;
  cube = sc->cube;
  keyact = glutGetModifiers();
  if ( keyact & GLUT_ACTIVE_SHIFT )
    pancoeff = 0.01;

  switch(key) {
  case GLUT_KEY_F1:  /* toggle clipping plane */
    if ( mesh->dim == 3 ) {
      if ( cube->active & C_ON)
    keyCube('C',0,0);
      else
    keyClip('C',0,0);
    }
    post = FALSE;
    break;
  case GLUT_KEY_F2:  /* edit clipping plane */
    if ( mesh->dim == 3 ) {
      if ( cube->active & C_ON)
        keyCube('E',0,0);     
      else if ( clip->active & C_ON ) 
    keyClip('E',0,0);
    }
    post = FALSE;
    break;
  case GLUT_KEY_F3:  /* freeze clipping plane */
    if ( cube->active & C_ON )
      keyCube('F',0,0);
    else if ( clip->active & C_ON ) 
      keyClip('F',0,0);
    post = FALSE;
    break;
  case GLUT_KEY_F4:  /* toggle Vclip */
    if ( mesh->dim == 3 )  keyClip('Z',0,0);
    post = FALSE;
    break;
  case GLUT_KEY_F5:  /* Toggle Shrink */
    if ( mesh->ntet+mesh->nhex > 0 )
      keyFeature('V',0,0);
    else
      keyFeature('S',0,0);
    break;
  case GLUT_KEY_F6:  /* Increase Shrink */
    keyFeature('I',0,0);
    break;
  case GLUT_KEY_F7:  /* Decrease Shrink */
    keyFeature('i',0,0);
    break;

  case GLUT_KEY_LEFT:  /* translate eyes or object */
    if ( clip->active & C_EDIT ) {
      clip->cliptr->panx -= 0.02 * sc->dmax;
      clip->cliptr->angle = 0.0;
      clip->active |= C_UPDATE + C_REDO;
    }
    else if ( keyact & GLUT_ACTIVE_CTRL ) {
      sc->par.eyesep *= 0.9;
      printf("eyesep %f\n",sc->par.eyesep);
    }
    else
      view->panx -= pancoeff * sc->dmax;
    break;
  case GLUT_KEY_RIGHT:
    if ( clip->active & C_EDIT ) {
      clip->cliptr->panx += 0.02 * sc->dmax;
      clip->cliptr->angle = 0.0;
      clip->active |= C_UPDATE + C_REDO;
    }
    else if ( keyact & GLUT_ACTIVE_CTRL ) {
      sc->par.eyesep *= 1.1;
      printf("eyesep %f\n",sc->par.eyesep);
    }
    else
      view->panx += pancoeff * sc->dmax;
    break;
  case GLUT_KEY_UP:
    if ( clip->active & C_EDIT ) {
      clip->cliptr->pany += 0.02 * sc->dmax;
      clip->cliptr->angle = 0.0;
      clip->active |= C_UPDATE + C_REDO;
    }
    else
      view->pany += pancoeff * sc->dmax;
    break;
  case GLUT_KEY_DOWN:
    if ( clip->active & C_EDIT ) {
      clip->cliptr->pany -= 0.02 * sc->dmax;
      clip->cliptr->angle = 0.0;
      clip->active |= C_UPDATE + C_REDO;
    }
    else
      view->pany -= pancoeff * sc->dmax;
    break;
  default:
    return;
  }
  if ( post )  glutPostRedisplay();
}
Пример #15
0
int coreps(FILE *file,GLsizei size,GLfloat *buffer) {
    Token           *ttoken;
    pScene           sc;
    Feedback3Dcolor *v;
    GLfloat         *ptr;
    int              i,k,idw,token,nit,nbv,sorting=TRUE;

    /* default */
    if ( ddebug ) printf("dump EPS file\n");
    idw = currentScene();
    sc = cv.scene[idw];

    /* Count tokens */
    nit = 0;
    ptr = buffer;
    while ( *ptr && ptr < buffer+size ) {
        token = (int)*ptr;
        switch (token) {
        case GL_LINE_TOKEN:
        case GL_LINE_RESET_TOKEN:
            nit++;
            ptr += 14;
            break;

        case GL_POLYGON_TOKEN:
            nit++;
            ++ptr;
            nbv = *ptr;
            ptr += (7 * nbv);
            break;

        case GL_POINT_TOKEN:
            ptr += 7;
            break;

        case GL_BITMAP_TOKEN:
            puts("BITMAP");
            nit++;
            ++ptr;
            nbv = *ptr;
            printf("nbv = %d\n",nbv);
            break;

        default:
            fprintf(stdout,"  Unrecognized token %d\n",token);
            break;
        }
        ptr++;
    }

    if ( ddebug )
        printf("size = %d  ptr = %p  buffer = %p  -> size = %d\n",
               size,ptr,buffer,ptr-buffer);

    /* allocate mem to store tokens */
    if ( ddebug ) printf("%d tokens found\n",nit);
    ttoken = (Token *)malloc((1+nit)*sizeof(struct Token));
    assert(ttoken);

    /* store tokens */
    nit = 0;
    ptr = buffer;
    while ( *ptr && ptr < buffer+size ) {
        ttoken[++nit].ptr = ptr;
        token = (int)*ptr;
        ptr++;
        switch (token) {
        case GL_LINE_TOKEN:
        case GL_LINE_RESET_TOKEN:
            v = (Feedback3Dcolor *)ptr;
            ttoken[nit].depth = 0.5*(v[0].z+v[1].z);
            ptr += 14;
            break;

        case GL_POLYGON_TOKEN:
            nbv = *ptr;
            ptr++;
            v = (Feedback3Dcolor *)ptr;
            ttoken[nit].depth = v[0].z;
            for (k=1; k<nbv; k++)
                ttoken[nit].depth += v[k].z;
            ttoken[nit].depth /= nbv;
            ptr += (7 * nbv);
            break;

        case GL_POINT_TOKEN:
            ptr += 7;
            nit--;
            break;

        default:
            ptr += 4;
            break;
        }
    }

    /* Sort the primitives according to depth */
    if ( sc->mode == WIRE || sc->mode == WIRE+S_MATERIAL )
        sorting = FALSE;
    if ( ddebug ) printf("prim = %d  size = %d, %d\n",nit,ptr-buffer-1,size);

    if ( sorting == TRUE ) {
        if ( ddebug ) printf("start sorting %d tokens...\n",nit);
        qsort(ttoken+1,nit,sizeof(struct Token),compare);
        if ( ddebug ) printf("end sorting\n");
    }

    /* write tokens in EPS file */
    for (k=1; k<=nit; k++) {
        ptr = ttoken[k].ptr;
        if ( *ptr == 0 )  continue;
        token = *ptr;
        ptr++;
        switch(token) {
        case GL_LINE_RESET_TOKEN:
        case GL_LINE_TOKEN:
            v = (Feedback3Dcolor *)ptr;
            fprintf(file,"%g %g %g stc\n",v[0].r,v[0].g,v[0].b);
            fprintf(file,"%g %g %g %g sgm\n",v[0].x,v[0].y,v[1].x,v[1].y);
            ptr += 14;
            break;

        case GL_POLYGON_TOKEN:
            nbv = *ptr;
            ptr++;
            v = (Feedback3Dcolor *)ptr;

            /* draw filled polygon */
            if ( sorting == TRUE ) {
                /* fprintf(file,"1. stg\n"); */
                fprintf(file, "dc ");
                for (i=0; i<nbv; i++)
                    fprintf(file," %g %g",v[i].x,v[i].y);
                fprintf(file,"  %g %g %g fc\n",v[0].r,v[0].g,v[0].b);
            }

            /* draw polygon border */
            if ( sc->mode & S_BDRY ) {
                fprintf(file,"0. stg\n");
                for (i=0; i<nbv-1; i++)
                    fprintf(file,"%g %g %g %g sgm\n",v[i].x,v[i].y,v[i+1].x,v[i+1].y);
                fprintf(file,"%g %g %g %g sgm\n\n",v[nbv-1].x,v[nbv-1].y,v[0].x,v[0].y);
            }

            ptr += (7*nbv);
            break;

        case GL_POINT_TOKEN:
            v = (Feedback3Dcolor *)ptr;
            ptr += 7;
            break;
        default:
            printf("problem: token %d\n",token);
        }
    }

    return(1);
}
Пример #16
0
void scissorScene() {
  pScene      sc;
  pMesh       mesh;
  pPersp      p;
  pTransform  view;
  int         width,height;

  /* default */
  if ( ddebug ) printf("enable scissoring\n");
  sc   = cv.scene[currentScene()];
  mesh = cv.mesh[sc->idmesh];
  view = sc->view;
  p    = sc->persp; 

  /* subdivide main window */
  glViewport(0,0,sc->par.xs,sc->par.ys);
  glMatrixMode(GL_PROJECTION);
  glLoadIdentity();
  gluOrtho2D(0,sc->par.xs,0,sc->par.ys);
  glMatrixMode(GL_MODELVIEW);
  glLoadIdentity();
  glClearColor(sc->par.back[0],sc->par.back[1],sc->par.back[2],sc->par.back[3]);
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

  /* split window */
  glDisable(GL_LIGHTING);
  glColor4fv(sc->par.line);
  glBegin(GL_LINES);
  glVertex2i(sc->par.xs/2,0);
  glVertex2i(sc->par.xs/2,sc->par.ys);
  glVertex2i(0,sc->par.ys/2);
  glVertex2i(sc->par.xs,sc->par.ys/2);
  glEnd();
  glEnable(GL_LIGHTING);

  width  = (sc->par.xs + 1)/2;
  height = (sc->par.ys + 1)/2;

  glDisable(GL_LIGHTING);
  glColor4fv(sc->par.line);
  output2(5,sc->par.ys/2+5,"Top");
  output2(5,5,"Front");
  output2(sc->par.xs/2+5,5,"Right");

  glEnable(GL_SCISSOR_TEST);

  /* draw top right : normal */
  glViewport(width,height,width,height);
  glScissor(width,height,width,height);
  farclip(1);

  glMatrixMode(GL_MODELVIEW);
  glLoadIdentity();
  gluLookAt(0.,0.,-p->depth, 0.,0.,0., 0.0,1.0,0.0);
  setupView(sc);
  glMultMatrixf(view->matrix);
  glTranslatef(sc->cx,sc->cy,sc->cz);
  drawModel(sc);
  if ( sc->type & S_DECO )  redrawStatusBar(sc);

  /* draw top left : top view */
  glViewport(0,height,width,height);
  glScissor(0,height,width,height);
  farclip(1);  

  glMatrixMode(GL_MODELVIEW);
  glLoadIdentity();
  gluLookAt(0.,0.,-p->depth, 0.,0.,0., 0.0,1.0,0.0);
  setupView(sc);
  glTranslatef(sc->cx,sc->cy,sc->cz);
  glRotatef(-90,0.0,0.0,1.0);
  glTranslatef(view->opanx,0.,0.);
  drawModel(sc);

  /* draw bottom left : front */
  glViewport(0,0,width,height);
  glScissor(0,0,width,height);
  farclip(1);

  glMatrixMode(GL_MODELVIEW);
  glLoadIdentity();
  gluLookAt(0.,0.,-p->depth, 0.,0.,0., 0.0,1.0,0.0);
  setupView(sc);
  glTranslatef(sc->cx,sc->cy,sc->cz);
  glRotatef(-90.0,1.0,0.0,0.0);
  glTranslatef(view->opanx,0.,0.);
  drawModel(sc);

  /* draw bottom right : right */
  glViewport(width,0,width,height);
  glScissor(width,0,width,height);
  farclip(1);

  glMatrixMode(GL_MODELVIEW);
  glLoadIdentity();
  gluLookAt(0.,0.,-p->depth, 0.,0.,0., 0.0,1.0,0.0);
  setupView(sc);
  glRotatef(-90.0,1.0,0.0,0.0);
  glRotatef(-90.0,0.0,0.0,1.0);
  glTranslatef(0.,view->opany,0.);
  drawModel(sc);

  glutSwapBuffers();
  glDisable(GL_SCISSOR_TEST);
  glViewport(0,0,sc->par.xs,sc->par.ys);
 
  if ( saveimg ) keyFile('H',0,0);
}
Пример #17
0
/* OpenGL callbacks */
void redrawScene () {
	pScene sc;
	pTransform view;
	pPersp p;
	pCamera c;

	sc = cv.scene[currentScene()];
	view = sc->view;
	p = sc->persp;
	c = sc->camera;

	if (stereoMode == MONO || !hasStereo) {
		glDrawBuffer(GL_BACK_LEFT);
		glClearColor(sc->par.back[0], sc->par.back[1],
		             sc->par.back[2], sc->par.back[3]);
		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

		glMatrixMode(GL_MODELVIEW);
		glLoadIdentity();
		gluLookAt(0., 0., -p->depth, 0., 0., 0., 0.0, 1.0, 0.0);

		setupView(sc);
		glMultMatrixf(view->matrix);
		glTranslatef(sc->cx, sc->cy, sc->cz);
		drawModel(sc);
		if (sc->type & S_DECO) redrawStatusBar(sc);
	} else {
		double ndfl, ratio, top, bottom;
		double left, right, nnear, ffar;

		nnear = -p->depth - 0.5 * sc->dmax;
		if (nnear < 0.1) nnear = 0.1;

		ffar = -p->depth + 0.5 * sc->dmax;
		ratio = sc->par.xs / (double)sc->par.ys;
		top = nnear * tan(DTOR * 0.5 * p->fovy);
		ndfl = nnear / p->depth;
		if (sc->par.eyesep < 0.0)
			sc->par.eyesep = fabs(p->depth / 20.0);

		/* left view */
		glDrawBuffer(GL_BACK_LEFT);
		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

		left = -ratio * top + 0.5 * sc->par.eyesep * ndfl;
		right = ratio * top + 0.5 * sc->par.eyesep * ndfl;
		bottom = -top;

		glMatrixMode(GL_PROJECTION);
		glLoadIdentity();
		glFrustum(left, right, top, bottom, nnear, ffar);
		glMatrixMode(GL_MODELVIEW);
		glLoadIdentity();
		gluLookAt(-sc->par.eyesep, 0., -p->depth,
		          sc->par.eyesep / 3.0, 0., 0.,
		          0.0, 1.0, 0.0);

		setupView(sc);
		glMultMatrixf(view->matrix);
		glTranslatef(sc->cx, sc->cy, sc->cz);
		drawModel(sc);
		if (sc->type & S_DECO) redrawStatusBar(sc);

		/* right view */
		glDrawBuffer(GL_BACK_RIGHT);
		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

		left = -ratio * top - 0.5 * sc->par.eyesep * ndfl;
		right = ratio * top - 0.5 * sc->par.eyesep * ndfl;

		glMatrixMode(GL_PROJECTION);
		glLoadIdentity();
		glFrustum(left, right, top, bottom, nnear, ffar);
		glMatrixMode(GL_MODELVIEW);
		glLoadIdentity();
		gluLookAt(sc->par.eyesep, 0., -p->depth,
		          sc->par.eyesep / 3.0, 0., 0.,
		          0.0, 1.0, 0.0);

		setupView(sc);
		glMultMatrixf(view->matrix);
		glTranslatef(sc->cx, sc->cy, sc->cz);
		drawModel(sc);
		if (sc->type & S_DECO) redrawStatusBar(sc);
	}

	/* refresh screen */
	if (saveimg && animate)
		glFlush();
	else
		glutSwapBuffers();

	if (ddebug) checkErrors();

	if (saveimg && !(sc->type & S_SCISSOR)) keyFile('H', 0, 0);

	/* redraw linked scene */
	if (!animate && sc->slave > -1) {
		pScene slave;

		slave = cv.scene[sc->slave];
		glutSetWindow(slave->idwin);
		redrawScene();
	}
}
Пример #18
0
void motion(int x,int y) {
  pScene      sc;
  pTransform  tr;
  pPersp      p;
  GLuint      gtime;
  double      deltax,deltay;
  float       coeff,pos[3],dx,dy,dz;
  int         idw = currentScene();

  /* default */
  if ( picking )  return;
  if ( ddebug ) fprintf(stdout,"motion\n");

#ifdef IGL
  // Tweakbar has precedence over everything else
  if(TwEventMouseMotionGLUT(x,y))
  {
    if(!tracking)
    {
      glutPostRedisplay();
    }
  }
#endif

  if ( tracking == GL_FALSE )  return;
  sc = cv.scene[idw];
  p  = sc->persp;
  if ( p->rubber == 1 )  return;

  /* what is transformed ? */
  if ( sc->cube->active & C_EDIT ) 
    tr = sc->cube->cubetr;
  else if ( sc->clip->active & C_EDIT ) 
    tr = sc->clip->cliptr;
  else
    tr = sc->view;

  if ( tr->mstate != GLUT_DOWN )  return;
  if ( picking )  tr->angle = 0.0f;

  gtime = glutGet(GLUT_ELAPSED_TIME);
  if ( (animate || sc->type & S_FOLLOW) && gtime < lasttime+40 )  return;

  if ( tr->mbutton == GLUT_LEFT_BUTTON ) {
    /* calculate axis of rotation: cross product */
    point2Vect(x,y,sc->par.xs,sc->par.ys,pos);
    tr->axis[0] = tr->pos[1]*pos[2] - tr->pos[2]*pos[1];
    tr->axis[1] = tr->pos[2]*pos[0] - tr->pos[0]*pos[2];
    tr->axis[2] = tr->pos[0]*pos[1] - tr->pos[1]*pos[0];
 
    /* calculate angle to rotate by */
    if ( animate && saveimg )
      tr->angle = 2.0f;
    else {
      dx = pos[0] - tr->pos[0];
      dy = pos[1] - tr->pos[1];
      dz = pos[2] - tr->pos[2];
      tr->angle = 180.0*sqrt(dx*dx+dy*dy+dz*dz);
    }

    /* reset for next time */
    tr->pos[0] = pos[0];
    tr->pos[1] = pos[1];
    tr->pos[2] = pos[2];
    lasttime   = gtime;

    if ( sc->cube->active & C_ON && sc->cube->active & C_EDIT )
      sc->cube->active |= C_UPDATE;
    else if ( sc->clip->active & C_ON && 
	         (sc->clip->active & C_EDIT || sc->clip->active & C_FREEZE) )
      sc->clip->active |= C_UPDATE;

    glutPostRedisplay();
  }

  else if ( tr->mbutton == GLUT_MIDDLE_BUTTON ) {
    coeff  = tr->manim == GL_TRUE ? 0.2 : 2.0;
    deltax = coeff * (x-startx) / (float)sc->par.xs;
    deltay = coeff * (starty-y) / (float)sc->par.ys;

    if ( deltax != 0.0 )
      tr->panx += -deltax * p->depth * tan(p->fovy/360.*M_PI);
    if ( deltay != 0.0 )
      tr->pany += -deltay * p->depth * tan(p->fovy/360.*M_PI);
    tr->angle = 0.0;
    startx = x;
    starty = y;

    lasttime = gtime;
    if ( sc->cube->active & C_ON && sc->cube->active & C_EDIT )
      sc->cube->active |= C_UPDATE;
    else if ( sc->clip->active & C_ON && 
        (sc->clip->active & C_EDIT || sc->clip->active & C_FREEZE) )
      sc->clip->active |= C_UPDATE;

    glutPostRedisplay();
  }
}
	static float currentCamHeight() { return currentScene()->cameraPos().y; }