예제 #1
0
파일: glmain.c 프로젝트: Choino/school
void parse_obj(char *buffer){
  OBJECT *po;
  char *pshape, *pshine, *pemi, *pamb, *pdiff, *pspec, *ptranslate, *pscale, *protate;



  my_assert ((num_objects < NUM_OBJECTS), "too many objects");
  po = &my_objects[num_objects++];

  pshape  = strtok(buffer, " ");
  //printf("pshape is %s\n",pshape);

  ptranslate    = strtok(NULL, "()");  strtok(NULL, "()");
  pscale        = strtok(NULL, "()");  strtok(NULL, "()"); 
  protate       = strtok(NULL, "()");  strtok(NULL, "()");  

  pshine  = strtok(NULL, "()");strtok(NULL, "()");
  //printf("pshine is %s\n",pshine);
 
  pemi    = strtok(NULL, "()");  strtok(NULL, "()"); 
  pamb    = strtok(NULL, "()");  strtok(NULL, "()"); 
  pdiff   = strtok(NULL, "()");  strtok(NULL, "()"); 
  pspec   = strtok(NULL, "()");  strtok(NULL, "()"); 


  po->sid  = atoi(pshape);
  po->shine = atof(pshine);

  parse_floats(ptranslate, po->translate);
  parse_floats(pscale, po->scale);
  parse_floats(protate, po->rotate);

  parse_floats(pemi, po->emi);
  parse_floats(pamb, po->amb);
  parse_floats(pdiff, po->diff);
  parse_floats(pspec, po->spec);

  // use switch to create your objects, cube given as example
  switch (po->sid){
  case 1: //cube
    make_cube_smart(po, 1);
    break;
  }
  
  // scale, rotate, translate using your real tranformations from assignment 3 depending on input from spec file
  
  real_scaling(po, po->scale[0], po->scale[1], po->scale[2]);  
  real_rotation(po, po->rotate[0], 1, 0, 0);
  real_rotation(po, po->rotate[1], 0, 1, 0);
  real_rotation(po, po->rotate[2], 0, 0, 1);
  real_translation(po, po->translate[0], po->translate[1], po->translate[2]);
  
  printf("read object\n");
}
예제 #2
0
파일: glmain.cpp 프로젝트: JGelpi97/School
void my_TimeOut(int id) 
{	
	/* Camera controls
		Controls go in here so there is no delay when pressing keys to move
		It also allows us to move forward and backwards while turning
		WASD for forward/back + strafing left/right
		R/F for up/down
	*/
	if (wDown)
	{
		cam->translate(-CAM_MOVE_SPEED, 0, 0, 1);
		glutPostRedisplay();
	}
	if (aDown)
	{
		cam->translate(-CAM_MOVE_SPEED, 1, 0, 0);
		glutPostRedisplay();
	}
	if (sDown)
	{
		cam->translate(CAM_MOVE_SPEED, 0, 0, 1);
		glutPostRedisplay();
	}
	if (dDown)
	{
		cam->translate(CAM_MOVE_SPEED, 1, 0, 0);
		glutPostRedisplay();
	}
	if (rDown)	//go up
	{
		cam->pos[1] += CAM_MOVE_SPEED;
		glutPostRedisplay();
	}
	if (fDown)	//go down
	{
		cam->pos[1] -= CAM_MOVE_SPEED;
		glutPostRedisplay();		
	}

	/* Player(cone) controls
		I/K = forward/back
		J/L = turn left/right
		U/H = up/down

		For rotation, rotate the cones uvw axes with player->rotate()
		Then translate to origin, rotate by y, translate back
	*/
	if (iDown)
	{
		player->translate(PLAYER_MOVE_SPEED, 0, 0, 1);
		glutPostRedisplay();
	}
	if (jDown)	//Rotate left
	{
		GLfloat cx = player->pos[0];
		GLfloat cy = player->pos[1];
		GLfloat cz = player->pos[2];

		player->rotate(PLAYER_TURN_SPEED, 0, 1, 0);
		real_translation(player, -cx, -cy, -cz);
		real_rotation(player, PLAYER_TURN_SPEED, 0, 1, 0);
		real_translation(player, cx, cy, cz);
		glutPostRedisplay();
	}
	if (kDown)
	{
		player->translate(-PLAYER_MOVE_SPEED, 0, 0, 1);
		glutPostRedisplay();
	}
	if (lDown)	//Rotate right
	{
		GLfloat cx = player->pos[0];
		GLfloat cy = player->pos[1];
		GLfloat cz = player->pos[2];

		player->rotate(-PLAYER_TURN_SPEED, 0, 1, 0);
		real_translation(player, -cx, -cy, -cz);
		real_rotation(player, -PLAYER_TURN_SPEED, 0, 1, 0);
		real_translation(player, cx, cy, cz);
		glutPostRedisplay();
	}
	if (uDown)	//up
	{
		player->translate(PLAYER_MOVE_SPEED, 0, 1, 0);
		glutPostRedisplay();
	}
	if (hDown)	//down
	{
		player->translate(-PLAYER_MOVE_SPEED, 0, 1, 0);
		glutPostRedisplay();
	}


	/* Camera truning */
	if (turnRight)
	{
		cam->rotate(turnRightLen * .07, 0, 1, 0);	//Scale by .07, we can't rotate by num of pixels moved degrees
		turnRightLen = 0;
		glutPostRedisplay();
		turnRight = false;
		glutWarpPointer(wWidth / 2, wHeight / 2);	//Move pointer back to middle
	}
	else if (turnLeft)
	{
		cam->rotate(-turnLeftLen * .07, 0, 1, 0);
		turnLeftLen = 0;
		glutPostRedisplay();
		turnLeft = false;
		glutWarpPointer(wWidth / 2, wHeight / 2);
	}

	glutTimerFunc(20, my_TimeOut, 0);
}
예제 #3
0
파일: glmain.cpp 프로젝트: JGelpi97/School
void parse_obj(char *buffer){
	OBJECT *po;
	char *pshape, *pshine, *pemi, *pamb, *pdiff, *pspec, *ptranslate, *pscale, *protate;
	Shape *s = NULL;


	my_assert ((num_objects < NUM_OBJECTS), "too many objects");
	po = &my_objects[num_objects++];

	pshape  = strtok(buffer, " ");
	//printf("pshape is %s\n",pshape);

	ptranslate    = strtok(NULL, "()");  strtok(NULL, "()");
	pscale        = strtok(NULL, "()");  strtok(NULL, "()"); 
	protate       = strtok(NULL, "()");  strtok(NULL, "()");  

	pshine  = strtok(NULL, "()");strtok(NULL, "()");
	//printf("pshine is %s\n",pshine);

	pemi    = strtok(NULL, "()");  strtok(NULL, "()"); 
	pamb    = strtok(NULL, "()");  strtok(NULL, "()"); 
	pdiff   = strtok(NULL, "()");  strtok(NULL, "()"); 
	pspec   = strtok(NULL, "()");  strtok(NULL, "()"); 


	po->sid  = atoi(pshape);
	po->shine = atof(pshine);

	parse_floats(ptranslate, po->translate);
	parse_floats(pscale, po->scale);
	parse_floats(protate, po->rotate);

	parse_floats(pemi, po->emi);
	parse_floats(pamb, po->amb);
	parse_floats(pdiff, po->diff);
	parse_floats(pspec, po->spec);

	//Create the shape
	switch (po->sid)
	{
		case 1: //cube
		{
			s = new Shape(CUBE, 1, 1, 1, 1);
			break;
		}
		case 2:	//house
		{
			s = new Shape(HOUSE, 1, 1, 1, 1);
			break;
		}
		case 3:
		{
			s = new Shape(SPHERE, 1, 1, 25, 25);
			break;
		}
		case 4:
		{
			s = new Shape(CYLINDER, 1, 1, 10, 10);
			break;
		}
		case 5:
		{
			s = new Shape(CONE, 1, 1, 10, 10);
			break;
		}
		case 6:	//Torus
		{
			s = new Shape(1.2, .2, 15, 40);
			break;
		}

	}
	if (s != NULL)
		s->switchRenderMode();

	// scale, rotate, translate the shape using the struct values
	real_scaling(s, po->scale[0], po->scale[1], po->scale[2]);  
	real_rotation(s, po->rotate[0], 1, 0, 0);
	real_rotation(s, po->rotate[1], 0, 1, 0);
	real_rotation(s, po->rotate[2], 0, 0, 1);
	real_translation(s, po->translate[0], po->translate[1], po->translate[2]);
	
	//Add to list
	shapeList.push_back(s);

	printf("read object\n");
}
예제 #4
0
파일: glmain.c 프로젝트: Choino/school
/*TODO: expand to add hmwk 3 keyboard events */
void my_keyboard( unsigned char key, int x, int y ) {
  switch( key ) {
  case 'O':
  case 'o': {
    reset();
    glutPostRedisplay(); 
  }; break;


  case 'y': {
	switch( crt_transform) {
	case ROTATION_MODE: real_rotation(-2,0,1,0); break;
	case TRANSLATION_MODE: real_translation(0,-1,0); break;
	//... etc: handle real-translation, rotation, scaling
	}
    glutPostRedisplay(); 
  }; break;
  case 'Y': {
	switch( crt_transform) {
	case ROTATION_MODE: real_rotation(2,0,1,0); break;
	case TRANSLATION_MODE: real_translation(0,1,0); break;
	//... etc: handle real-translation, rotation, scaling
	}
    glutPostRedisplay(); 
  }; break;

  //etc...

  case '1': {
    crt_shape = CUBE;
    glutPostRedisplay();
  }; break;
  case '0': {
    crt_shape = HOUSE;
    glutPostRedisplay();
  }; break;
  case '3':{
    crt_shape = CYLINDER;
    glutPostRedisplay();
  }; break;
  case '4': {
    crt_shape = SPHERE;
    glutPostRedisplay();
  }; break;
  case '6': {
    crt_shape = MESH;
    glutPostRedisplay();
  }; break; 

  //etc ... EC shapes from hmwk2

  case 'S':
  case 's': {
    crt_transform = REAL_SCALING_MODE;
  }; break;

  case 'T':
  case 't': {
    crt_transform = REAL_TRANSLATION_MODE;
  }; break;

  case 'R':
  case 'r': {
    crt_transform = REAL_ROTATION_MODE;
  }; break;


 

  //add camera controls...
  //...

  //add your tessellation code from hmwk2
  case '+': {
  }; break;

  case '-': {
  }; break;

  case '>': {
  }; break;

  case '<': {
  }; break;

  case 'q': 
  case 'Q':

    exit(0) ;

    break ;	

  default: break;

  }

  

  return ;

}