Exemplo n.º 1
0
int main(int argc, char **argv)
{
	glutInit(&argc, argv);
	glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
	glutInitContextVersion(3, 2);
	glutInitWindowSize (halfWindowWidth*2, halfWindowHeight*2);
	glutCreateWindow ("TSBK07 Lab 4");
	glutDisplayFunc(display);
	init ();
	glutTimerFunc(20, &timer, 0);
    glutTimerFunc(20, &moveTimer, 0);
    
    glutKeyboardFunc(keyboardControl);
	glutPassiveMotionFunc(mouse);
    // move cursor to middle of window, maybe unneccesary
    glutWarpPointer(halfWindowWidth, halfWindowHeight);
    glutHideCursor();
    printf("\nExit with Esc. Fullscreen with H\n\n");
    
	glutMainLoop();
	exit(0);
}
Exemplo n.º 2
0
int main()
{
	// Initializing glut
	glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
	glutInitWindowSize(WND_WIDTH, WND_HEIGHT);
	glutCreateWindow("MyStudio");
	glutSetCursor(GLUT_CURSOR_NONE); 
	glutWarpPointer(glutGet(GLUT_WINDOW_WIDTH) / 2, glutGet(GLUT_WINDOW_HEIGHT) / 2);
	glClearColor(0.0, 0.0, 0.0, 1.0);

	// Registering callback function
	glutDisplayFunc(display_callback);
	glutReshapeFunc(reshape_callback);
	glutKeyboardFunc(keyboard_callback);
	glutKeyboardUpFunc(keyboardUp_callback);	
	//glutMouseFunc(mouse);
	glutPassiveMotionFunc(passiveMouse_callback);
	glutTimerFunc(50, checkForMovement_callback, 0);

	// Create our sparkling new camera
	vector3D<float> position = {0, 3, -5};
	vector3D<float> look = {0, 0, 1};
	vector3D<float> up = {0, 1, 0};
	camera = WZ_Camera(position, look, up, 5);
	
	// Setting up perspective camera
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	gluPerspective(60, WND_WIDTH / WND_HEIGHT, 0.1, 100);
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
	gluLookAt(camera.getCameraPosition().x, camera.getCameraPosition().y, camera.getCameraPosition().z, 
		camera.lookAt().x, camera.lookAt().y, camera.lookAt().z, 
		camera.getUpVector().x, camera.getUpVector().y, camera.getUpVector().z);
	
	glutMainLoop();
	return 0;
}
Exemplo n.º 3
0
void updateCamera(Camera& c) {

	// update camera movement
	if ((state & FORWARD) == FORWARD) {
		c.pos += c.dir * c.movementSpeed;
	} else if ((state & BACKWARD) == BACKWARD) {
		c.pos -= c.dir * c.movementSpeed;
	}

	if ((state & LEFT) == LEFT) {
		c.pos -= cross(c.dir, UP) * c.movementSpeed;
	} else if ((state & RIGHT) == RIGHT) {
		c.pos += cross(c.dir, UP) * c.movementSpeed;
	}

	if ((state & UPWARD) == UPWARD) {
		c.pos += UP * c.movementSpeed;
	} else if ((state & DOWNWARD) == DOWNWARD) {
		c.pos -= UP * c.movementSpeed;
	}

	// update camera distance
	c.dist = glm::max(c.dist - ((float) scroll_buffer * c.scrollSpeed), glm::vec3());
	scroll_buffer = 0;

	// update camera rotation
	glm::vec3 axis = cross(c.dir, UP);
	glm::quat pitch = glm::angleAxis(glm::radians(dy), axis);
	glm::quat yaw = glm::angleAxis(glm::radians(dx), UP);

	glm::quat dir = normalize(pitch * yaw);

	c.dir = glm::rotate(dir, c.dir);

	dx = dy = 0.0f;

	glutWarpPointer(Registry::window.resolution.first / 2, Registry::window.resolution.second / 2);
}
Exemplo n.º 4
0
/* gestisce il mouse */
void mouseHandler(int x, int y){
  float tmpX = 0.0f, tmpY = 0.0f;
  if((worldData.angleY != worldData.nextAngleY) || (worldData.angleX != worldData.nextAngleX))
    return;

  tmpX = x - (programData.width / 2);
  tmpY = y - (programData.height / 2);

  if((tmpX == 0.0f) && (tmpY == 0.0f))
    return;

  worldData.angleMX += tmpY * 0.25f;
  worldData.angleMY += tmpX * 0.25f;
  
  if( (worldData.angleMY > (worldData.angleY+45.0f)) ||  (worldData.angleMY< (worldData.angleY-45.0f) ))
    worldData.angleMY -= tmpX * 0.25f;

  if( (worldData.angleMX > (worldData.angleX+45.0f)) ||  (worldData.angleMX< (worldData.angleX-45.0f) ))
    worldData.angleMX -= tmpY * 0.25f;

  glutWarpPointer(programData.width/2, programData.height/2);

}
Exemplo n.º 5
0
//Check the user input and performs the rendering
void GameLoop()
{
	int t1, t2;
	t1 = glutGet(GLUT_ELAPSED_TIME);

	if (glutGet(GLUT_ELAPSED_TIME) - earthquakeTime > 3000){
		earthquake = false;
	}
	//Process Input
	if (input)
	{
		Player.Update(keys, mouseX, mouseY);
		glutWarpPointer(glutGet(GLUT_WINDOW_X) + glutGet(GLUT_WINDOW_WIDTH) / 2, glutGet(GLUT_WINDOW_Y) + glutGet(GLUT_WINDOW_HEIGHT) / 2);
		input = false;
	}

	//Do The Rendering
	GameRender();

	// Frame rate sync: 1000/20 = 50 fps
	do { t2 = glutGet(GLUT_ELAPSED_TIME); 
	} while (t2 - t1 < 20);	
}
Exemplo n.º 6
0
void Viewer::mouseMove(int x, int y){
	static bool just_warped = false;
	if(just_warped) {
        just_warped = false;
        return;
    }
	if(mousePros){
		int difX = x-WINDOW_WIDTH/2;
		int difY = y-WINDOW_HEIGHT/2;

		if(abs(difX)>abs(difY)){
			camera.rotateY(-difX*CAMERA_ROTATE_SPEED);
		}else{
			camera.rotateX(-difY*CAMERA_ROTATE_SPEED);
		}
		
		glutWarpPointer(WINDOW_WIDTH / 2, WINDOW_HEIGHT / 2);

		just_warped = true;
		
	}
	
}
Exemplo n.º 7
0
void Input::trackMouse(int x, int y){
	if(pointerLock){
		deltaX = x - screen_width / 2;
		deltaY = y - screen_height / 2;

		// this prevents us from going into a feedback loop from the pointer warp below
		if(deltaX == 0 && deltaY == 0) return;

		mouseX += deltaX;
		mouseY += deltaY;

		glutWarpPointer(screen_width / 2, screen_height / 2);
	} else {
		deltaX = 0;
		deltaY = 0;

		mouseX = x;
		mouseY = y;
	}

	Debug::trace("Mouse delta: %i, %i\n", deltaX, deltaY);
	Debug::trace("Mouse position: %i, %i\n", mouseX, mouseY);
}
Exemplo n.º 8
0
void mouse_moved(int x, int y){

   /* on first load set mouse to curson position so we don't have a jump */
   if(mouse_x == -1 && mouse_y == -1){
      mouse_x = x;
      mouse_y = y;
   }

   angle_x -= (x - mouse_x)* 60 * PI / (180 * window_width / 2);
   angle_z -= (y - mouse_y)* 60 * PI / (180 * window_height / 2);

   if(warping % 2 == 1){
      glutWarpPointer( window_width/2, window_height/2 );
      warping = 0;
   }
   else
      warping++;

   mouse_x = window_width/2;
   mouse_y = window_height/2;

   glutPostRedisplay();
}
Exemplo n.º 9
0
void camera::control(int b, int x, int y)
{
	std::cout << "move cam\n";
	if(mi)
	{
		int MidX=320;
		int MidY=240;
		glutSetCursor(GLUT_CURSOR_NONE);
//		SDL_ShowCursor(SDL_DISABLE);
		int tmpx,tmpy;
		
//		SDL_GetMouseState(&tmpx,&tmpy);
		
//		camYaw+=mousespeed*(MidX-tmpx);
//		camPitch+=mousespeed*(MidY-tmpy);
		lockCamera();
		glutWarpPointer(MidX,MidY);
		const Uint8* state=SDL_GetKeyboardState(NULL);
		if(b == GLUT_KEY_LEFT) {
			std::cout << "keyboard\n";
		}
		if(state[SDLK_w])
		{
				moveCamera(0.0);
		}else if(state[SDLK_s])
		{
				moveCamera(180.0);
		}		
		if(state[SDLK_a])
			moveCamera(90.0);
		else if(state[SDLK_d])
			moveCamera(270);	
	}
	
//	glRotatef(-camPitch,1.0,0.0,0.0);
//	glRotatef(-camYaw,0.0,1.0,0.0);
}
Exemplo n.º 10
0
void igvInterfaz::set_glutPassiveMotionFunc(GLint x,GLint y) {
	if (!interfaz.boton_retenido && interfaz.objeto_seleccionado == -1) {
		if (!((x == glutGet(GLUT_WINDOW_WIDTH) / 2) && (y == glutGet(GLUT_WINDOW_HEIGHT) / 2))) {
			if (interfaz.objeto_seleccionado == -1) {
				float incr = 1.5;
				float incry = (interfaz.cursorY - y)/100.0;
				if (x < interfaz.cursorX) {
					interfaz.angulo_vision -= incr;
					interfaz.camara.girarX(-incr*PI/180);
					interfaz.escena->rotar_linternax(-incr*PI/180);
				}
				if (x > interfaz.cursorX) {
					interfaz.angulo_vision += incr;
					interfaz.camara.girarX(incr*PI/180);
					interfaz.escena->rotar_linternax(incr*PI/180);
				}
				if (y > interfaz.cursorY) {
					if (interfaz.camara.r[1] + incry > 0) {
						interfaz.camara.girarY(incry);
						interfaz.escena->rotar_linternay(incry);
					}
				}
				if (y < interfaz.cursorY) {
					if (interfaz.camara.r[1] + incry < 2) {
						interfaz.camara.girarY(incry);
						interfaz.escena->rotar_linternay(incry);
					}
				}
				/* Traslado el puntero al centro para que no se salga de la ventana */
				glutWarpPointer(glutGet(GLUT_WINDOW_WIDTH)/2, glutGet(GLUT_WINDOW_HEIGHT)/2);
				interfaz.cursorX = interfaz.ancho_ventana/2;
				interfaz.cursorY = interfaz.alto_ventana/2;
				glutPostRedisplay();
			}
		}
	}
}
Exemplo n.º 11
0
void MoveMouse(int x, int y)
{
	double centroX=glutGet(GLUT_WINDOW_WIDTH)/2, centroY=glutGet(GLUT_WINDOW_HEIGHT)/2;
	float velMouse = 0.03;

    anguloy += (x - x_temp)*velMouse;
    x_temp=x;

    angulox += (y - y_temp)*velMouse;
    y_temp = y;

    EspecificaParametrosVisualizacao();
    glutPostRedisplay();
    //travador de mouse

    if((x>=centroX+10 || x<=centroX-10 || y>=centroY+10 || y<=centroY-10) && trava_mouse==1) //delimitar uma area de acesso ao mouse de 600x450
    {
    	x_temp = centroX;
    	y_temp = centroY;
        glutWarpPointer(centroX,centroY);
        EspecificaParametrosVisualizacao();
        glutPostRedisplay();
    }
}
Exemplo n.º 12
0
void passiveMotion( int x, int y ){

    static bool warped = false;

    if( warped )
    {
        warped = false;
        return;
    }

    if( capture )
    {
        warped = true;        
        int metade_width = width/2;
        int metade_height = height/2;
        if ( x > metade_width ){
        	deltaAngle += sensibilidade;
        }
        else {
        	deltaAngle = -sensibilidade;

        }
        angle += deltaAngle;
	    // update camera's direction
	    lx = sin(angle + deltaAngle);
	    lz = -cos(angle + deltaAngle);

        // Trava o mouse no centro da tela
        glutWarpPointer( width/2 , height/2 );
        
    }
    else
    {
    	glutSetCursor(GLUT_CURSOR_CROSSHAIR);
    }
}
Exemplo n.º 13
0
void CglicScene::toogleFlyingMode(){
  pcv->profile.displayAxes = ((pcv->profile.flyingMode)?1:0);
  pcv->mice.lastPassivePos = pcv->mice.lastPos = glm::vec2(view->width/2, view->height/2);

  //FROM FLYING TO NORMAL
  if(pcv->profile.flyingMode){
    m_cam *= 1.0f * glm::length(m_cam);
    m_look = -m_cam;
    glutSetCursor(GLUT_CURSOR_RIGHT_ARROW);
    pcv->mice.lastPos = glm::vec2(view->width/2, view->height/2);
    m_right = glm::normalize(glm::vec3(m_cam.z, 0, -m_cam.x));
    m_up = glm::cross(m_right, m_look);
  }
  //FROM NORMAL TO FLYING
  else{
    glutSetCursor(GLUT_CURSOR_CROSSHAIR);
    glutWarpPointer(view->width/2, view->height/2);
    m_look = -m_cam;
  }

  pcv->profile.flyingMode = !pcv->profile.flyingMode;
  select();
  transform.reset();
}
Exemplo n.º 14
0
void mouse( int button, int state, int x, int y )
{
								if( button == GLUT_LEFT_BUTTON && !State.inAnimation && !State.inRotation )
								{
																if( state == GLUT_DOWN  )
																{ //pick a vertex
																								printf("MOUSE_X : %d ; MOUSE_Y : %d\n",x, y );
																								Line line = View.cursorLine( x, y );
																								line.print();
																								Vector destination = Origami.pickVertex( line );
																								destination.print();
																								View.world2window( destination, Cursor3D.x, Cursor3D.y, Cursor3D.z );
																								glutWarpPointer( Cursor3D.x, Cursor3D.y );
																								State.inFolding = true;

																								printf("\n");
																}
																else
																{ // GLUT_UP
																								Origami.releaseVertex();
																								State.inFolding = false;
																}
								}
}
Exemplo n.º 15
0
// Changes the angle of the camera based on mouse movement, then re-centers the mouse cursor
void MouseMovement(int x, int y) {
	angleX = Mod(angleX + (float)(x - centerX) * smoothX, 360.0);
	angleY = max(min(angleY + (float)(y - centerY) * smoothY, 90.0F), -90.0F);
	if (x != centerX || y != centerY)
		glutWarpPointer(centerX, centerY);
}
void mouse_move_func ( int x, int y )
{
	int dx = x - last_x;
	int dy = y - last_y;

	switch ( mode ) {
	case MODE_CAM:
		if ( dragging == DRAG_LEFT ) {
			cam_angs.x += dx;
			cam_angs.y += dy;
			if ( cam_angs.x >= 360.0 )	cam_angs.x -= 360.0;
			if ( cam_angs.x < 0 )		cam_angs.x += 360.0;
			if ( cam_angs.y >= 180.0 )	cam_angs.y = 180.0;
			if ( cam_angs.y <= -180.0 )	cam_angs.y = -180.0;
			printf ( "Cam Ang: %f %f %f\n", cam_angs.x, cam_angs.y, cam_angs.z );
			printf ( "Cam To:  %f %f %f\n", cam_to.x, cam_to.y, cam_to.z );
			printf ( "Cam FOV: %f\n", cam_fov);
		} else if ( dragging == DRAG_RIGHT ) {
			cam_angs.z += dy*.15;
			if ( cam_angs.z < 0)		cam_angs.z = 0;
			printf ( "Cam Ang: %f %f %f\n", cam_angs.x, cam_angs.y, cam_angs.z );
			printf ( "Cam To:  %f %f %f\n", cam_to.x, cam_to.y, cam_to.z );
			printf ( "Cam FOV: %f\n", cam_fov );
		}
		break;
	case MODE_CAM_TO:
		if ( dragging == DRAG_LEFT ) {
			cam_to.x += dx;
			cam_to.y += dy;			
		} else if ( dragging == DRAG_RIGHT ) {
			cam_to.z += dy*.05;
			if ( cam_to.z < 0) 	cam_to.z = 0;
		}
		break;	
	case MODE_OBJ:
		if ( dragging == DRAG_LEFT ) {
			obj_angs.x -= dx*0.1;
			obj_angs.y += dy*0.1;
			printf ( "Obj Angs:  %f %f %f\n", obj_angs.x, obj_angs.y, obj_angs.z );
			//force_x += dx*.1;
			//force_y += dy*.1;
		} else if (dragging == DRAG_RIGHT) {
			obj_angs.z -= dy*.005;			
			printf ( "Obj Angs:  %f %f %f\n", obj_angs.x, obj_angs.y, obj_angs.z );
		}
		psys.SetVec ( EMIT_ANG, Vector3DF ( obj_angs.x, obj_angs.y, obj_angs.z ) );
		break;
	case MODE_OBJPOS:
		if ( dragging == DRAG_LEFT ) {
			obj_from.x -= dx*.1;
			obj_from.y += dy*.1;
			printf ( "Obj:  %f %f %f\n", obj_from.x, obj_from.y, obj_from.z );
		} else if (dragging == DRAG_RIGHT) {
			obj_from.z -= dy*.1;
			printf ( "Obj:  %f %f %f\n", obj_from.x, obj_from.y, obj_from.z );
		}
		psys.SetVec ( EMIT_POS, Vector3DF ( obj_from.x, obj_from.y, obj_from.z ) );
		//psys.setPos ( obj_x, obj_y, obj_z, obj_ang, obj_tilt, obj_dist );
		break;
	case MODE_LIGHTPOS:
		if ( dragging == DRAG_LEFT ) {
			light[0].x -= dx*.1;
			light[0].y += dy*.1;		
			printf ( "Light: %f %f %f\n", light[0].x, light[0].y, light[0].z );
		} else if (dragging == DRAG_RIGHT) {
			light[0].z -= dy*.1;			
			printf ( "Light: %f %f %f\n", light[0].x, light[0].y, light[0].z );
		}	
		#ifdef USE_SHADOWS
			setShadowLight ( light[0].x, light[0].y, light[0].z, light_to[0].x, light_to[0].y, light_to[0].z, light_fov );
		#endif
		break;
	}

	if ( x < 10 || y < 10 || x > 1000 || y > 700 ) {
		glutWarpPointer ( 1024/2, 768/2 );
		last_x = 1024/2;
		last_y = 768/2;
	} else {
		last_x = x;
		last_y = y;
	}
}
void mouse_enter(int state)
{
    if (state==GLUT_ENTERED)
    glutWarpPointer(window_width / 2, window_height / 2);
}
Exemplo n.º 18
0
void keyboard(unsigned char key, int x, int y)
{
	bool changed = true;

	switch (key)
	{
		case 'q':
			//std::cout << "LEFT ROLL" << std::endl;
			win.rotateAroundAxis(2, -rotationDegree);
			break;
		case 'e':
			//std::cout << "RIGHT ROLL" << std::endl;
			win.rotateAroundAxis(2, rotationDegree);
			break;

		case 'w':
			//std::cout << "Moving forward." << std::endl;
			win.moveAlongAxis(2, -1, mouseDown);
			break;
		case 's':
			//std::cout << "Moving backward." << std::endl;
			win.moveAlongAxis(2, 1, mouseDown);
			break;

		case 'a':
			//std::cout << "Moving left." << std::endl;
			win.moveAlongAxis(0, -1, mouseDown);
			break;
		case 'd':
			//std::cout << "Moving right." << std::endl;
			win.moveAlongAxis(0, 1, mouseDown);
			break;

		case 'r':
			//std::cout << "Moving up." << std::endl;
			win.moveAlongAxis(1, 1, mouseDown);
			break;
		case 'f':
			//std::cout << "Moving down." << std::endl;
			win.moveAlongAxis(1, -1, mouseDown);
			break;

		case 'R':
			win.reset();
			break;

		case ' ':
			std::cout << std::endl;
			win.dumpInfos();
			tellLights();
			changed = false;
			break;

		case 't':
			raymarching_stepsize = raymarching_stepsize_lo;
			raymarching_hq = false;
			break;

		case 'T':
			raymarching_stepsize = raymarching_stepsize_hi;
			raymarching_hq = false;
			break;

		case 'g':
			raymarching_accuracy = raymarching_accuracy_lo;
			raymarching_hq = false;
			break;

		case 'G':
			raymarching_accuracy = raymarching_accuracy_hi;
			raymarching_hq = false;
			break;

		case 'h':
			raymarching_hq = !raymarching_hq;
			if (raymarching_hq)
			{
				raymarching_stepsize = raymarching_stepsize_hi;
				raymarching_accuracy = raymarching_accuracy_hi;
			}
			else
			{
				raymarching_stepsize = raymarching_stepsize_lo;
				raymarching_accuracy = raymarching_accuracy_lo;
			}
			break;

		case '1':
			lights_enabled[0] = !lights_enabled[0];
			break;

		case '2':
			lights_enabled[1] = !lights_enabled[1];
			break;

		case 'c':
			drawCS = !drawCS;
			break;

		case 'm':
			mouseLook = !mouseLook;
			if (mouseLook)
			{
				glutSetCursor(GLUT_CURSOR_NONE);

				// Init the algorithm: Warp to center.
				glutWarpPointer(win.w() * 0.5, win.h() * 0.5);

				std::cout << "Mouse look activated." << std::endl;
			}
			else
			{
				glutSetCursor(GLUT_CURSOR_INHERIT);
				std::cout << "Mouse look deactivated." << std::endl;
			}
			changed = false;
			break;

		case 'i':
			mouseInverted = !mouseInverted;
			if (mouseInverted)
				std::cout << "Mouse inverted." << std::endl;
			else
				std::cout << "Mouse not inverted." << std::endl;
			changed = false;
			break;

		case 27:
			exit(EXIT_SUCCESS);
			break;

		case 13:
			if (settings_target == 0)
				settings_target = 1;
			else
				settings_target = 0;
			std::cout << "Settings target: "
				<< (settings_target == 0 ? "user_params" : "lights")
				<< std::endl;
			changed = false;
			break;
	}

	if (changed)
		glutPostRedisplay();
}
Exemplo n.º 19
0
/** Set the mouse position
    @ingroup	gui
    @param	x	mouse x pos
    @param	y	mouse y pos
    @return	none
*/
void GfuiMouseSetPos(int x, int y)
{
	glutWarpPointer(x, y);
}
Exemplo n.º 20
0
void SystemWarpPointer(int x, int y) {
  glutWarpPointer(x, y);
}
Exemplo n.º 21
0
void Player::recenterCursor()
{
    glutWarpPointer(CENTER_X, CENTER_Y);
}
Exemplo n.º 22
0
	void CameraView::renderCameraView()
	{

	    int currentTime = glutGet(GLUT_ELAPSED_TIME);
	    int timeInterval = currentTime - previousTime;

	    //Berechne Blickrichtung
	    GLdouble tmpEyeX, tmpEyeY, tmpEyeZ;

	    tmpEyeX = sin(mouseDirectionY*PI/180)*sin(mouseDirectionX*PI/180);
	    tmpEyeZ = sin(mouseDirectionY*PI/180)*cos(mouseDirectionX*PI/180);
	    tmpEyeY = cos(mouseDirectionY*PI/180);

	    //Bewegung Berechnen
	    if(forward)
	    {
	    	eyeX += timeInterval * tmpEyeX / 10;
	    	eyeY += timeInterval * tmpEyeY / 10;
	    	eyeZ += timeInterval * tmpEyeZ / 10;
	    }
	    if(backward)
	    {
	    	eyeZ -= timeInterval * tmpEyeZ / 10;
	    	eyeY -= timeInterval * tmpEyeY / 10;
	    	eyeX -= timeInterval * tmpEyeX / 10;
	    }
	    if(left)
	    {
	    	eyeX += timeInterval * sin((mouseDirectionX+90)*PI/180) / 10;
	    	eyeZ += timeInterval * cos((mouseDirectionX+90)*PI/180) / 10;
	    }
	    if(right)
	    {
	    	eyeX -= timeInterval * sin((mouseDirectionX+90)*PI/180) / 10;
	    	eyeZ -= timeInterval * cos((mouseDirectionX+90)*PI/180) / 10;
	    }

	    //Mausbewegung =>

	    previousTime = currentTime;

	    glLoadIdentity();
/*
		glPushMatrix();
		glDepthMask(false);
	    glPushAttrib(GL_ENABLE_BIT);
	    glEnable(GL_TEXTURE_2D);

	    glDisable(GL_DEPTH_TEST);
	    glDisable(GL_LIGHTING);
	    glDisable(GL_BLEND);

	    glRotatef(mouseDirectionX, 0, 1, 0);
		glBegin(GL_QUADS);
				glColor3f(1,1,1);
		        glVertex3f(  5.0f, -5.0f, -5.0f );
		        glColor3f(1,0,0);
		        glVertex3f( -5, -5, -5 );
		        glVertex3f( -5,  5, -5 );
		        glVertex3f(  5,  5, -5 );
		glEnd();

		glPopAttrib();
		glPopMatrix();
	    glEnable( GL_DEPTH_TEST );
		glDepthMask(true);


*/


		gluLookAt(	eyeX, eyeY, eyeZ,
					eyeX + tmpEyeX, eyeY + tmpEyeY, eyeZ + tmpEyeZ ,
					0.0f, 10.0f,  0.0f);


		//Maus wieder in die mitte Positionieren
		if(mouseWarp)
			glutWarpPointer(this->windowWidth / 2, this->windowHeight / 2);
	}
Exemplo n.º 23
0
	void MyFPSCamera::update( unsigned long ellapsedMilis ) {
		
		glutWarpPointer( _winSize[ 0 ] / 2.0, _winSize[ 1 ] / 2.0);

	}
Exemplo n.º 24
0
void keyboard(unsigned char key, int x, int y)
{
	switch (key)
	{
		case 'w':
			std::cout << "DOWN" << std::endl;
			win.rotateAroundAxis(0, rotationDegree);
			break;
		case 's':
			std::cout << "UP" << std::endl;
			win.rotateAroundAxis(0, -rotationDegree);
			break;

		case 'a':
			std::cout << "LEFT" << std::endl;
			win.rotateAroundAxis(1, -rotationDegree);
			break;
		case 'd':
			std::cout << "RIGHT" << std::endl;
			win.rotateAroundAxis(1, rotationDegree);
			break;

		case 'q':
			std::cout << "LEFT ROLL" << std::endl;
			win.rotateAroundAxis(2, -rotationDegree);
			break;
		case 'e':
			std::cout << "RIGHT ROLL" << std::endl;
			win.rotateAroundAxis(2, rotationDegree);
			break;

		case 'j':
			std::cout << "Moving forward." << std::endl;
			win.moveAlongAxis(2, movingStep);
			break;
		case 'k':
			std::cout << "Moving backward." << std::endl;
			win.moveAlongAxis(2, -movingStep);
			break;

		case 'h':
			std::cout << "Moving left." << std::endl;
			win.moveAlongAxis(0, movingStep);
			break;
		case 'l':
			std::cout << "Moving right." << std::endl;
			win.moveAlongAxis(0, -movingStep);
			break;

		case 'r':
			std::cout << "Reset." << std::endl;
			win.reset();
			break;

		case 'm':
			mouseLook = !mouseLook;
			if (mouseLook)
			{
				glutSetCursor(GLUT_CURSOR_NONE);

				// Init the algorithm: Warp to center
				glutWarpPointer(win.w() * 0.5, win.h() * 0.5);

				std::cout << "Mouse look activated." << std::endl;
			}
			else
			{
				glutSetCursor(GLUT_CURSOR_INHERIT);
				std::cout << "Mouse look deactivated." << std::endl;
			}
			break;

		case 'n':
			smoothAutoLevel = !smoothAutoLevel;
			if (smoothAutoLevel)
			{
				std::cout << "Smooth Auto-Leveling activated." << std::endl;

				glutTimerFunc(smoothAutoLevelInterval, autoLevelTimer, 0);
			}
			else
				std::cout << "Smooth Auto-Leveling deactivated." << std::endl;
			break;

		case 'N':
			win.toggleDirectAutoLevel();
			if (win.doesDirectAutoLevel())
				std::cout << "Direct Auto-Leveling activated." << std::endl;
			else
				std::cout << "Direct Auto-Leveling deactivated." << std::endl;
			break;

		case 'i':
			mouseInverted = !mouseInverted;
			if (mouseInverted)
				std::cout << "Mouse inverted." << std::endl;
			else
				std::cout << "Mouse not inverted." << std::endl;
			break;

		case ' ':
			std::cout << "Smooth Auto-Leveling. "
				<< "Press 'n' to toggle a timer!" << std::endl;
			win.autoLevel(smoothAutoLevelScale, smoothAutoLevelMaxPhi);
			break;

		case 27:
			exit(EXIT_SUCCESS);
			break;
	}

	glutPostRedisplay();
}
Exemplo n.º 25
0
void onReshape(int width, int height) {
  screen_width = width;
  screen_height = height;
  glViewport(0, 0, screen_width, screen_height);
  glutWarpPointer(screen_width/2, screen_height/2);
}
Exemplo n.º 26
0
void Affichage() {
	int i, j;

	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	gluPerspective(70, (double)WIDTH/HEIGHT, 1, 600);
//	glFrustum(-5, 5, -5, 5, 5, 500);
	gluLookAt(lookat.x, lookat.y, lookat.z, vue.x, vue.y , vue.z, 0, 0, 1);
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	//glColor3f(0, 0, 0);
	//afficher_surface(-50, 50, GL_QUADS);
	
	tree(-30, 10, 10);
	tree(-50, 40, 10);
	tree(-50, 20, 10);
	tree(15, -100, 100);
	tree(-60, 40, 50);
	/* LE SOLEILLLLLLL */
	glPushMatrix();
		glTranslatef(0,150,300); 
		glColor3f(1, 1, 0);
		glutWireSphere(20., 15, 15);
	glPopMatrix();

	/* 1250 : LARGEUR laby = HAUTEUR laby ici*/ 
	/* Génération du sol */
	glColor3f(0, 1, 1);
	for ( i = 0; i < 1250; i += 25 ) {
		for ( j = 0; j < 1250; j += 25) { 
			glBegin(GL_LINE_LOOP);
			glVertex3f(i, j, 0);
			glVertex3f(i + 25, j, 0);
			glVertex3f(i + 25, j + 25, 0); 
			glVertex3f(i, j + 25, 0);
			glEnd();
		}
	}
	
	/* Mur confinement */
	glColor4f(1, 0, 0,0.1);
	glBegin(GL_QUADS);
	glVertex3f(0, 0, 5);
	glVertex3f(0, 1250, 5);
	glVertex3f(0, 1250, 10);
	glVertex3f(0, 0, 10);

	glVertex3f(0, 1250, 5);
	glVertex3f(1250, 1250, 5);
	glVertex3f(1250, 1250, 10);
	glVertex3f(0, 1250, 10);

	glVertex3f(1250, 1250, 5);
	glVertex3f(1250, 0, 5);
	glVertex3f(1250, 0, 10);
	glVertex3f(1250, 1250, 10);

	glVertex3f(1250, 0, 5);
	glVertex3f(0, 0, 5);
	glVertex3f(0, 0, 10);
	glVertex3f(1250, 0, 10);
	glEnd();

	glColor3f(1, 0, 0);

	/* boiboite */
	glBegin(GL_QUADS);
	/* Boiboite de la face gauche au spawn */
	glVertex3f(0, 0, 4.5);
	glVertex3f(0, 1250, 4.5);
	glVertex3f(0, 1250, 5);
	glVertex3f(0, 0, 5);

	glVertex3f(0, 0, 10);
	glVertex3f(0, 1250, 10);
	glVertex3f(0, 1250, 10.5);
	glVertex3f(0, 0, 10.5);

	/* Autre boibote */
	glVertex3f(0, 1250, 4.5);
	glVertex3f(1250, 1250, 4.5);
	glVertex3f(1250, 1250, 5);
	glVertex3f(0, 1250, 5);

	glVertex3f(0, 1250, 10);
	glVertex3f(1250, 1250, 10);
	glVertex3f(1250, 1250, 10.5);
	glVertex3f(0, 1250, 10.5);

	/* autre boiboite */
	glVertex3f(1250, 1250, 4.5);
	glVertex3f(1250, 0, 4.5);
	glVertex3f(1250, 0, 5);
	glVertex3f(1250, 1250, 5);

	glVertex3f(1250, 1250, 10);
	glVertex3f(1250, 0, 10);
	glVertex3f(1250, 0, 10.5);
	glVertex3f(1250, 1250, 10.5);

	/* autre boiboite */
	glVertex3f(1250, 0, 4.5);
	glVertex3f(0, 0, 4.5);
	glVertex3f(0, 0, 5);
	glVertex3f(1250, 0, 5);

	glVertex3f(1250, 0, 10);
	glVertex3f(0, 0, 10);
	glVertex3f(0, 0, 10.5);
	glVertex3f(1250, 0, 10.5);


	glEnd();


	glutWarpPointer(MID_WIDTH, MID_HEIGHT);
	
	glutPostRedisplay();
	glutSwapBuffers();
}
Exemplo n.º 27
0
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);
}
Exemplo n.º 28
0
void pmotionfunc(int x, int y)
{
    if (bound)
    {
        glutSetMenu(canvas_menu_id);

        int deltax = x - mousex;
        int deltay = y - mousey;

        mousex = x;
        mousey = y;

        bool warp = false;
        if (mousex > 3*canvas.get_width()/4 || mousex < canvas.get_width()/4)
        {
            mousex = canvas.get_width()/2;
            warp = true;
        }

        if (mousey > 3*canvas.get_height()/4 || mousey < canvas.get_height()/4)
        {
            mousey = canvas.get_height()/2;
            warp = true;
        }

        if (warp)
            glutWarpPointer(mousex, mousey);

        if (scene.active_camera_valid())
        {
            scene.cameras[scene.active_camera]->orientation[1] -= (float)deltax/500.0;
            scene.cameras[scene.active_camera]->orientation[0] -= (float)deltay/500.0;
        }

        glutPostRedisplay();
    }
    else if (scene.active_camera_valid())
    {
        vec3f direction;
        vec3f position;

        if (scene.active_camera_valid())
        {
            if (scene.cameras[scene.active_camera]->type == "ortho")
            {
                position = canvas.unproject(canvas.to_window(vec2i(x, y)));
                direction = ror3(vec3f(0.0f, 0.0f, 1.0f), scene.cameras[scene.active_camera]->orientation);
            }
            else
            {
                position = scene.cameras[scene.active_camera]->position;
                direction = norm(canvas.unproject(canvas.to_window(vec2i(x, y))));
            }
        }

        int old_active_object = scene.active_object;
        scene.active_object = -1;
        for (int i = 0; i < scene.objects.size(); i++)
        {
            if (scene.objects[i] != NULL && scene.cameras[scene.active_camera]->model != scene.objects[i])
            {
                bool is_light = false;
                bool is_camera = false;

                // TODO Assignment 3: uncomment this
                //for (int j = 0; j < scene.lights.size() && !is_light; j++)
                //	if (scene.lights[j] != NULL && scene.lights[j]->model == scene.objects[i])
                //		is_light = true;

                for (int j = 0; j < scene.cameras.size() && !is_camera; j++)
                    if (scene.cameras[j] != NULL && scene.cameras[j]->model == scene.objects[i])
                        is_camera = true;

                if ((!is_light && !is_camera) || (is_light && scene.render_lights) || (is_camera && scene.render_cameras))
                {
                    vec3f invdir = 1.0f/direction;
                    vec3i sign((int)(invdir[0] < 0), (int)(invdir[1] < 0), (int)(invdir[2] < 0));
                    vec3f origin = position - scene.objects[i]->position;
                    float tmin, tmax, tymin, tymax, tzmin, tzmax;
                    tmin = (scene.objects[i]->bound[0 + sign[0]]*scene.objects[i]->scale - origin[0])*invdir[0];
                    tmax = (scene.objects[i]->bound[0 + 1-sign[0]]*scene.objects[i]->scale - origin[0])*invdir[0];
                    tymin = (scene.objects[i]->bound[2 + sign[1]]*scene.objects[i]->scale - origin[1])*invdir[1];
                    tymax = (scene.objects[i]->bound[2 + 1-sign[1]]*scene.objects[i]->scale - origin[1])*invdir[1];
                    if ((tmin <= tymax) && (tymin <= tmax))
                    {
                        if (tymin > tmin)
                            tmin = tymin;
                        if (tymax < tmax)
                            tmax = tymax;

                        tzmin = (scene.objects[i]->bound[4 + sign[2]]*scene.objects[i]->scale - origin[2])*invdir[2];
                        tzmax = (scene.objects[i]->bound[4 + 1-sign[2]]*scene.objects[i]->scale - origin[2])*invdir[2];

                        if ((tmin <= tzmax) && (tzmin <= tmax))
                        {
                            scene.active_object = i;
                            i = scene.objects.size();
                        }
                    }
                }
            }
        }

        if (scene.active_object != old_active_object)
        {
            bool is_light = false;
            bool is_camera = false;

            // TODO Assignment 3: uncomment this
            //for (int i = 0; i < scene.lights.size() && !is_light; i++)
            //	if (scene.lights[i] != NULL && scene.active_object_valid() && scene.lights[i]->model == scene.objects[scene.active_object])
            //		is_light = true;

            for (int i = 0; i < scene.cameras.size() && !is_camera; i++)
                if (scene.cameras[i] != NULL && scene.active_object_valid() && scene.cameras[i]->model == scene.objects[scene.active_object])
                    is_camera = true;

            glutDetachMenu(GLUT_RIGHT_BUTTON);
            if (scene.active_object == -1)
                glutSetMenu(canvas_menu_id);
            else if (is_light)
                glutSetMenu(light_menu_id);
            else if (is_camera)
                glutSetMenu(camera_menu_id);
            else
                glutSetMenu(object_menu_id);
            glutAttachMenu(GLUT_RIGHT_BUTTON);
            glutPostRedisplay();
        }
    }
}
Exemplo n.º 29
0
void Mouse::centerMouse()
{
	glutWarpPointer(glutGet(GLUT_WINDOW_WIDTH)/2,glutGet(GLUT_WINDOW_HEIGHT)/2);
}
Exemplo n.º 30
0
void GlutWindow::setRelativeMousePosition(double x, double y) {
    glutWarpPointer(iRound(x), iRound(y));
}