Beispiel #1
0
void Input::mouseVisible(bool visible)
{
    if (visible)
    {
#ifdef __APPLE__
    	CGAssociateMouseAndMouseCursorPosition(TRUE);
	    CGDisplayShowCursor(kCGDirectMainDisplay);
#else
        glfwEnable(GLFW_MOUSE_CURSOR);
        glfwSetMousePos(m_mouseMiddleX, m_mouseMiddleY);
#endif
    }
    else
    {
#ifdef __APPLE__
	    glfwSetMousePos(m_mouseMiddleX, m_mouseMiddleY);
        CGDisplayHideCursor(kCGDirectMainDisplay);
	    CGPoint p;
	    p.x = m_mouseMiddleX;
	    p.y = m_mouseMiddleY;
	    //CGDisplayMoveCursorToPoint(kCGDirectMainDisplay, p);
	    CGWarpMouseCursorPosition(p);
	    CGAssociateMouseAndMouseCursorPosition(FALSE);
#else
        glfwDisable(GLFW_MOUSE_CURSOR);
        glfwSetMousePos(m_mouseMiddleX, m_mouseMiddleY);
#endif
    }
    m_mouseVisible = visible;
}
Beispiel #2
0
int sgInit(int argc, char *argv[], sgEvents *event, int res_x, int res_y, bool fullscreen)
{
	sgMain::eventhandler = event;
    bool running = true;

    glfwInit();
	glfwOpenWindowHint(GLFW_FSAA_SAMPLES, 8);
    if(!glfwOpenWindow( res_x, res_y, 0, 0, 0, 0, 24, 8, fullscreen?GLFW_FULLSCREEN:GLFW_WINDOW))
    {
        glfwTerminate();
        return 0;
    }

	printf("Multisampling samples: %i\n", glfwGetWindowParam(GLFW_FSAA_SAMPLES));
    glEnable(GL_MULTISAMPLE_ARB);

    sgRenderer::backingWidth = res_x;
    sgRenderer::backingHeight = res_y;

    glfwSetWindowTitle("iSDGE");

    glfwSetMousePos(res_x*0.5, res_y*0.5);

    GLenum err = glewInit();
	if (GLEW_OK != err)
	{
	  /* Problem: glewInit failed, something is seriously wrong. */
	  printf("Error: %s\n", glewGetErrorString(err));
	  return -1;
	}
	printf("Status: Using GLEW %s\n", glewGetString(GLEW_VERSION));

	//Initialize the renderer
	sgMain *sgmain = new sgMain(2);

	int mouse_x, mouse_y;
    while(running)
    {
    	glfwGetMousePos(&mouse_x, &mouse_y);
		glfwSetMousePos(res_x*0.5, res_y*0.5);
		sgMouse::currdir = sgVector2(mouse_x-res_x*0.5, mouse_y-res_y*0.5);
		sgMouse::currpos = sgVector2(mouse_x, mouse_y);

        sgmain->drawView();
        glfwSwapBuffers();

        // exit if ESC was pressed or window was closed
        running = !glfwGetKey(GLFW_KEY_ESC) && glfwGetWindowParam(GLFW_OPENED);
    }

	delete sgmain;
    glfwTerminate();

    return 0;
}
//----------------------------------------------------------------------------//
void GLFWCALL CEGuiGLFWSharedBase::glfwMousePosCallback(int x, int y)
{
    if (!d_mouseDisableCalled)
    {
        // if cursor didn't leave the window nothing changes
        d_sampleApp->injectMousePosition(static_cast<float>(x), static_cast<float>(y));
    }
    else
    {
        // if the cursor left the window, we need to use the saved position
        // because glfw beams the cursor to the middle of the window if 
        // the cursor is disabled
        d_sampleApp->injectMousePosition(static_cast<float>(d_oldMousePosX), static_cast<float>(d_oldMousePosY));
        glfwSetMousePos(d_oldMousePosX, d_oldMousePosY);
        d_mouseDisableCalled = false;
    }

#ifndef DEBUG
    if (x < 0 || y < 0
        || x > d_newWindowWidth
        || y > d_newWindowHeight)
    {
        // show cursor
        glfwEnable(GLFW_MOUSE_CURSOR);

        // move the cursor to the position where it left the window
        glfwSetMousePos(x, y);
        
        // "note down" that the cursor left the window
        d_mouseLeftWindow = true;
    }
    else
    {
        if (d_mouseLeftWindow)
        {
            // get cursor position to restore afterwards
            glfwGetMousePos(&d_oldMousePosX, &d_oldMousePosY);

            // we need to inject the previous cursor position because
            // glfw moves the cursor to the centre of the render 
            // window if it gets disabled. therefore notify the 
            // next MousePosCallback invocation of the "mouse disabled" event.
            d_mouseDisableCalled = true;

            // disable cursor
            glfwDisable(GLFW_MOUSE_CURSOR);

            // "note down" that the cursor is back in the render window
            d_mouseLeftWindow = false;
        }
    }
#endif
}
Beispiel #4
0
void modifyCamera(float dt)
{
    int x,y;

    glfwGetMousePos(&x, &y);

    vec3 camrot = cam->getOrientation();

    camrot.x -= (float)(y-HEIGHT/2) * MOUSE_SPEED * dt;
    camrot.y -= (float)(x-WIDTH/2)  * MOUSE_SPEED * dt;
    
    if(camrot.x > 90.0f) camrot.x = 90.0f;
    if(camrot.x < -90.0f) camrot.x = -90.0f;
    if(camrot.y > 360.0f) camrot.y -= 360.0f;
    if(camrot.y < -360.0f) camrot.y += 360.0f;
    
    cam->setOrientation(camrot);
    glfwSetMousePos(WIDTH/2, HEIGHT/2);

    vec3 movevec;

    if(glfwGetKey('W'))
        movevec.z -= MOVE_SPEED;
    if(glfwGetKey('A'))
        movevec.x -= MOVE_SPEED;
    if(glfwGetKey('S'))
        movevec.z += MOVE_SPEED;
    if(glfwGetKey('D'))
        movevec.x += MOVE_SPEED;

    cam->move(movevec * dt);
}
Beispiel #5
0
void TheMaze2::handleMouseInput(double time_delta) {
    int xPos, yPos;
    glfwGetMousePos(&xPos, &yPos);
    player_.xFacing_ -= player_.look_speed_ * time_delta * float(window_width_/2 - xPos);
    player_.yFacing_ += player_.look_speed_ * time_delta * float(window_height_/2 - yPos);
    glfwSetMousePos(window_width_/2, window_height_/2);
}
Beispiel #6
0
void GLFWCALL handleMouseMove(int mouseX, int mouseY)
{

    //TODO: move logic to World class
    GLfloat mouseSpeed  = 0.0001f;

    float DeltaX = 0;
    float DeltaY = 0;
    DeltaX = (float)mouseX - GLContext::I().SceneParam.midWindowX ;
    DeltaY = (float)mouseY - GLContext::I().SceneParam.midWindowY ;

    float camXRot = DeltaX * mouseSpeed;
    float camYRot = DeltaY * mouseSpeed;


//    if (camXRot < -90.0f){
//        camXRot = -90.0f;
//    }
//    // Limit looking down to vertically down
//    if (camXRot > 90.0f){
//        camXRot = 90.0f;
//    }
//    // Looking left and right. Keep the angles in the range -180.0f (anticlockwise turn looking behind) to 180.0f (clockwise turn looking behind)
//    if (camYRot < -180.0f){
//        camYRot += 360.0f;
//    }
//    if (camYRot > 180.0f){
//        camYRot -= 360.0f;
//    }

    core::World::I().cam.rotate(camXRot , camYRot ,0.0f);

    glfwSetMousePos(GLContext::I().SceneParam.midWindowX,
                    GLContext::I().SceneParam.midWindowY);
}
Beispiel #7
0
Fengine_camera::Fengine_camera():
		m_projection_mat(0.0f),
		m_horizontal_angle(3.14f),
		m_vertical_angle(0.0f),
		m_initial_fov(45.0f),
		m_speed(3.0f),
		m_mouse_speed(0.005f),
		m_perspective(4.0f / 3.0f)
{
	int width = 0;
	int height = 0;
	glfwGetWindowSize(&width, &height);

	//Ensure we can capture the escape key being pressed below
	glfwEnable( GLFW_STICKY_KEYS );
	glfwSetMousePos(width/2, height/2);

	// Projection matrix : 45° Field of View, 4:3 ratio, display range : 0.1 unit <-> 100 units
	m_projection_mat = perspective(
			m_initial_fov,	// The horizontal Field of View, in degrees : the amount of "zoom". Think "camera lens". Usually between 90° (extra wide) and 30° (quite zoomed in)
			m_perspective,	// Aspect Ratio. Depends on the size of your window. Notice that 4/3 == 800/600 == 1280/960, sounds familiar ?
			0.1f,			// Near clipping plane. Keep as big as possible, or you'll get precision issues.
			100.0f			// Far clipping plane. Keep as little as possible.
			);
}
Beispiel #8
0
void ClassicMode::ProcessMouseButton(int MouseButton, int Action)
{//printf("  mb\n");
	static int nPrevMouseButtonsDown = 0;

	if (GLFW_PRESS == Action)
	{
		nMouseButtonsDown |= (1 << MouseButton);

		if (!nPrevMouseButtonsDown && nMouseButtonsDown)
		{
			glfwGetMousePos(&nDesktopCursorX, &nDesktopCursorY);
			bCursorArmed = true;
		}
	}
	else
	{
		nMouseButtonsDown &= ~(1 << MouseButton);

		if (nPrevMouseButtonsDown && !nMouseButtonsDown)
		{
			if (bCursorArmed)
			{
				bCursorArmed = false;
				bSelectPerformed = true;
			}
			else
			{
				glfwEnable(GLFW_MOUSE_CURSOR);// printf("mouse visible\n");
				glfwSetMousePos(nDesktopCursorX, nDesktopCursorY);
			}
		}
	}

	nPrevMouseButtonsDown = nMouseButtonsDown;
}
void InputManager::SetMouseCursorVisibility(bool Visible)
{
	static int MouseCursorDesktopPositionX, MouseCursorDesktopPositionY;

	// Hide Mouse Cursor
	if (!Visible && m_MouseCursorVisible)
	{
		glfwPollEvents();
		m_MouseIgnorePositionAlways = true;
		glfwGetMousePos(&MouseCursorDesktopPositionX, &MouseCursorDesktopPositionY);
		glfwDisable(GLFW_MOUSE_CURSOR);
		m_MouseIgnorePositionOnce = true;
		m_MouseIgnorePositionAlways = false;

		m_MouseCursorVisible = false;
	}
	// Show Mouse Cursor
	else if (Visible && !m_MouseCursorVisible)
	{
		m_MouseIgnorePositionAlways = true;
		glfwEnable(GLFW_MOUSE_CURSOR);
		glfwSetMousePos(MouseCursorDesktopPositionX, MouseCursorDesktopPositionY);
		m_MouseIgnorePositionOnce = true;
		m_MouseIgnorePositionAlways = false;

		m_MouseCursorVisible = true;

		// Create a mouse position event
		//ProcessMousePos(m_MousePositionX, m_MousePositionY);
	}
}
Beispiel #10
0
void obp_trackball_rot () {

    int xpos, ypos;
    glfwGetMousePos(&xpos, &ypos);

    glfwSetMousePos(obp_window_width /2, obp_window_height /2);

    verticalAngle   += mouseRotateSpeed * float(obp_window_width  /2 - xpos);
    horizontalAngle += mouseRotateSpeed * float(obp_window_height /2 - ypos);
        
    if (horizontalAngle >=  89.99) horizontalAngle =  89.99;
    if (horizontalAngle <= -89.99) horizontalAngle = -89.99;

    float initial_distance = 10;

    float distance = initial_distance - 1.0f * glfwGetMouseWheel();

    float camX =  distance * -sinf(verticalAngle     * (PI / 180)) * cosf((horizontalAngle) * (PI / 180));
    float camY =  distance * -sinf((horizontalAngle) * (PI / 180));
    float camZ = -distance *  cosf((verticalAngle)   * (PI / 180)) * cosf((horizontalAngle) * (PI / 180));

    ProjectionMatrix = glm::perspective(initial_fov, float(obp_window_width) / float(obp_window_height), 0.1f, 100.0f);

    ViewMatrix       = glm::lookAt(
                            glm::vec3(camX, camY, camZ),           
                            glm::vec3(0.0f, 0.0f, 0.0f), 
                            glm::vec3(0.0f, 1.0f, 0.0f));            
}
Beispiel #11
0
int main()
{
	if(!glfwInit() )
	{
		std::cerr << "Failed to initialize GLFW" << std::endl;
		return -1;
	}

	glfwOpenWindowHint(GLFW_FSAA_SAMPLES, 4); // 4x antialiasing
	//	glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, 3); // OpenGL 3.2
	//	glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, 2);
	//	glfwOpenWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); //We don't want the old OpenGL

	// Open a window and create its OpenGL context
	if(!glfwOpenWindow(Window_Width, Window_Height, 0,0,0,0, 32,0, GLFW_WINDOW))
	{
		std::cerr << "Failed to open GLFW window" << std::endl;
		glfwTerminate();
		return -1;
	}

	// Initialize GLEW
	glewExperimental=true; // Needed in core profile
	if (glewInit() != GLEW_OK)
	{
		std::cerr << "Failed to initialize GLEW" << std::endl;
		return -1;
	}

	glfwSetWindowTitle("ShipRace");

	// Ensure we can capture the escape key being pressed below
	glfwEnable( GLFW_STICKY_KEYS );

	glEnable(GL_DEPTH_TEST);
	//glEnable(GL_CULL_FACE);

	// Initialize Mouse Position
	//glfwDisable( GLFW_MOUSE_CURSOR);
	glfwSetMousePos(Window_Width/2, Window_Height/2);

	Renderer renderer(Window_Width, Window_Height);
	renderer.init();

	//VSync
	//glfwSwapInterval(1);
	do
	{
		renderer.render();

		// Swap buffers
		glfwSwapBuffers();
	}
	while( glfwGetKey( GLFW_KEY_ESC ) != GLFW_PRESS && glfwGetWindowParam( GLFW_OPENED ) );


	glfwTerminate();
	return 0;
}
Beispiel #12
0
void GLFWCALL set_window_size(int w, int h) {
	*window_width() = w;
	*window_height() = h;

	glfwSetMousePos(*window_width()/2, *window_height()/2);
	
	window_set_perspective();
}
Beispiel #13
0
SGenum SG_EXPORT sgmCoreMouseSetPosition(void* mouse, SGint x, SGint y)
{
    if(mouse == NULL)
        return SG_OK; // SG_INVALID_VALUE

    glfwSetMousePos(x, y);

    return SG_OK;
}
Beispiel #14
0
/**
 * Set the mouse location
 */
int Canvas::_setMouse(lua_State *l) {
	Point p = Point::pop(l);

	Viewport &view = _canvas->view;
	if (view.is2d) {
		double vwidth = view.right - view.left;
		double vheight = view.bottom - view.top;

		// convert from canvas to window coordinates
		double wx = (p.x - view.left) * (_canvas->width() / vwidth);
		double wy = (p.y - view.top) * (_canvas->height() / vheight);
		glfwSetMousePos((int)wx, (int)wy);
	} else {
		glfwSetMousePos((int)p.x, (int)p.y);
	}

	return 0;
}
Beispiel #15
0
void AppMain() {
    if(!glfwInit())
        throw std::runtime_error("glfwInit failed");
    
    glfwOpenWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
    glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, 3);
    glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, 2);
    glfwOpenWindowHint(GLFW_WINDOW_NO_RESIZE, GL_FALSE);
    
    if(!glfwOpenWindow(SCREEN_SIZE.x, SCREEN_SIZE.y, 8, 8, 8, 8, 0, 0, GLFW_WINDOW))
        throw std::runtime_error("glfwOpenWindow failed. Can your hardware handle OpenGL 3.2?");
    
    glewExperimental = GL_TRUE; //stops glew crashing on OSX :-/
    if(glewInit() != GLEW_OK)
        throw std::runtime_error("glewInit failed");
    
    
    std::cout << "OpenGL version: " << glGetString(GL_VERSION) << std::endl;
    std::cout << "GLSL version: " << glGetString(GL_SHADING_LANGUAGE_VERSION) << std::endl;
    std::cout << "Vendor: " << glGetString(GL_VENDOR) << std::endl;
    std::cout << "Renderer: " << glGetString(GL_RENDERER) << std::endl;
    
    if(!GLEW_VERSION_3_2)
        throw std::runtime_error("OpenGL 3.2 API is not available.");
    
    glfwDisable(GLFW_MOUSE_CURSOR);
    glfwSetMousePos(0,0);
    glfwSetMouseWheel(0);
    
    LoadShaders();
    LoadTriangle();
    
    //intialise the Camera position
    gCamera.setPosition(glm::vec3(0,0,4));
    gCamera.setViewportAspectRatio(SCREEN_SIZE.x / SCREEN_SIZE.y);
    gCamera.setNearAndFarPlanes(0.5, 100.0f);
    Axis = glm::vec3(0,1,0);
    
    //intialise the Light attribute
    gLight.position = glm::vec3(0.0f,0.1f,-0.1f);
    gLight.intensities = glm::vec3(0.8,0.78,1); // white light
    gLight.attenuation = 0.2f;
    gLight.ambientCoefficient = 0.005f;
    
    double lastTime = glfwGetTime();
    while(glfwGetWindowParam(GLFW_OPENED)){
        
        double thisTime = glfwGetTime();
        Update(thisTime - lastTime);
        lastTime  = thisTime;
        Render();
        
    }
    
    glfwTerminate();
}
Beispiel #16
0
void processMouseEvents(float factor)
{
    int x;
    int y;

    int cx = scene->context->w / 2;
    int cy = scene->context->h / 2;

    float sensitivity = 0.05f;

    float dx, dy;

    glfwGetMousePos(&x, &y);

    dx = sensitivity * ((float) cx - (float) x);
    dy = sensitivity * ((float) cy - (float) y);

    if (dx == 0.0f && dy == 0.0f)
    {
        return;
    }

    if (glfwGetKey(GLFW_KEY_LSHIFT) == GLFW_PRESS ||
        glfwGetKey(GLFW_KEY_RSHIFT) == GLFW_PRESS)
    {
        float slide = SLIDE_STEP * factor;

        dx *= slide;
        dy *= slide;

        slideCamera(scene->camera, -dx, dy, 0.0f);
    }
    else
    {
        float rotate = ROTATE_STEP * factor;

        dx *= rotate;
        dy *= rotate;

        rotateCamera(scene->camera, dx, 0.0f, 0.0f);
        rotateCamera(scene->camera, 0.0f, -dy, 0.0f);
    }

    if (scene->world != NULL)
    {
        setupCamera(scene->world->sp, scene->camera);
    }

    if (scene->water != NULL)
    {
        setupCameraAlter(scene->water->modifySP, scene->camera);
        setupCamera(scene->water->drawSP, scene->camera);
    }

    glfwSetMousePos(cx, cy);
}
Beispiel #17
0
    void App::Update(const delta_t dt, const delta_t elapsed)
    {
		// retrieve current mouse state
        mouse_info mi = GetMouse();
		string buffer;

		// write program information to window title
		if (blurEnabled) buffer = "[B]";
        SetWindowTitle("firefly-demo v%d.%d (FPS: %.2lf)"
                       " x-%d y-%d %s",
                       FF_MAJOR_VERSION, FF_MINOR_VERSION,
                       GetFPS(), mi.x, mi.y, buffer.c_str());

		// calculate movement rate and direction
		bool forceBlur = false;
		if (GetKey('A')) {
			cameraFrame.MoveRight(MOVE_SPEED*dt);
			forceBlur = true;
		}
		if (GetKey('D')) {
			cameraFrame.MoveRight(-MOVE_SPEED*dt);
			forceBlur = true;
		}
		if (GetKey('W')) {
			cameraFrame.MoveForward(MOVE_SPEED*dt);
			forceBlur = true;
		}
		if (GetKey('S')) {
			cameraFrame.MoveForward(-MOVE_SPEED*dt);
			forceBlur = true;
		}

		// calculate mouse delta
		float delta = (GetWidth() / 2.f) - mi.x;
		moveBlur = (abs(delta) > BLUR_MIN_DELTA || forceBlur) ? true : false;
		cameraFrame.RotateWorld( -delta * TURN_SPEED * dt / 4, 0, 1, 0);

		// keep the mouse centered
		glfwSetMousePos(GetWidth() / 2, GetHeight() / 2);

		// handle current jumping state
		if (jumping) {		
			jumpVel -= JUMP_GRAVITY * dt;
			cameraFrame.MoveUp(jumpVel * dt);

			// if we have landed
			if (cameraFrame.GetOriginY() < 0) {
				jumping = false;
				jumpVel = 0;

				// make sure we are positioned back at ground height
				float dist = cameraFrame.GetOriginY();
				cameraFrame.MoveUp(cameraFrame.GetOriginY() - dist);
			}
		}
	}
Beispiel #18
0
void GLFWApp::HandleInput()
{
	isRunning = !glfwGetKey(GLFW_KEY_ESC) && glfwGetWindowParam(GLFW_OPENED);
	int x = 0;
	int y = 0;
	glfwGetMousePos(&x, &y);
	deltaX = x - midWidth;
	deltaY = y - midHeight;
	glfwSetMousePos(midWidth, midHeight);
}
void computeMatricesFromInputs() {
    // glfwGetTime is called only once (first time this function is called)
    static double lastTime = glfwGetTime();

    // compute time difference between current and last frame
    double curTime = glfwGetTime();
    float deltaTime = float(curTime - lastTime);

    // get and reset mouse pos
    int xpos, ypos;
    glfwGetMousePos(&xpos, &ypos);
    glfwSetMousePos(1024/2, 768/2);

    float mouseDeltaX = float(1024/2 - xpos);
    float mouseDeltaY = float( 768/2 - ypos);

    if (glfwGetMouseButton(GLFW_MOUSE_BUTTON_MIDDLE) == GLFW_PRESS) {
        // pan position
        cam.move_up(mouseSpeed * mouseDeltaY);
        cam.move_right(-mouseSpeed * mouseDeltaX);
    } else {
        cam.rotate_up(mouseSpeed * mouseDeltaY);
        cam.rotate_right(mouseSpeed * mouseDeltaX);
    }


    // move forward
    if ((glfwGetKey(GLFW_KEY_UP) == GLFW_PRESS) || (glfwGetKey('W') == GLFW_PRESS)) {
        cam.move_forward(deltaTime * speed);
    }
    // move backward
    if ((glfwGetKey(GLFW_KEY_DOWN) == GLFW_PRESS) || (glfwGetKey('S') == GLFW_PRESS)) {
        cam.move_forward(-1 * deltaTime * speed);
    }

    // strafe right
    if ((glfwGetKey(GLFW_KEY_RIGHT) == GLFW_PRESS) || (glfwGetKey('D') == GLFW_PRESS)) {
        cam.move_right(deltaTime * speed);
    }
    // strafe left
    if ((glfwGetKey(GLFW_KEY_LEFT) == GLFW_PRESS) || (glfwGetKey('A') == GLFW_PRESS)) {
        cam.move_right(-1 * deltaTime * speed);
    }

    // strafe up
    if (glfwGetKey('I') == GLFW_PRESS) {
        cam.move_up(deltaTime * speed);
    }
    // strafe down
    if (glfwGetKey('K') == GLFW_PRESS) {
        cam.move_up(-1 * deltaTime * speed);
    }

    lastTime = curTime;
}
Beispiel #20
0
// update the scene based on the time elapsed since last update
static void Update(float secondsElapsed) {
    //rotate the first instance in `gInstances`
    const GLfloat degreesPerSecond = 180.0f;
    gDegreesRotated += secondsElapsed * degreesPerSecond;
    while(gDegreesRotated > 360.0f) gDegreesRotated -= 360.0f;
    gInstances.front().transform = glm::rotate(glm::mat4(), gDegreesRotated, glm::vec3(0,1,0));

    //move position of camera based on WASD keys, and XZ keys for up and down
    const float moveSpeed = 4.0; //units per second
    if(glfwGetKey('S')){
        gCamera.offsetPosition(secondsElapsed * moveSpeed * -gCamera.forward());
    } else if(glfwGetKey('W')){
        gCamera.offsetPosition(secondsElapsed * moveSpeed * gCamera.forward());
    }
    if(glfwGetKey('A')){
        gCamera.offsetPosition(secondsElapsed * moveSpeed * -gCamera.right());
    } else if(glfwGetKey('D')){
        gCamera.offsetPosition(secondsElapsed * moveSpeed * gCamera.right());
    }
    if(glfwGetKey('Z')){
        gCamera.offsetPosition(secondsElapsed * moveSpeed * -glm::vec3(0,1,0));
    } else if(glfwGetKey('X')){
        gCamera.offsetPosition(secondsElapsed * moveSpeed * glm::vec3(0,1,0));
    }

    //move light
    if(glfwGetKey('1'))
        gLight.position = gCamera.position();

    // change light color
    if(glfwGetKey('2'))
        gLight.intensities = glm::vec3(1,0,0); //red
    else if(glfwGetKey('3'))
        gLight.intensities = glm::vec3(0,1,0); //green
    else if(glfwGetKey('4'))
        gLight.intensities = glm::vec3(1,1,1); //white


    //rotate camera based on mouse movement
    const float mouseSensitivity = 0.1f;
    int mouseX, mouseY;
    glfwGetMousePos(&mouseX, &mouseY);
    gCamera.offsetOrientation(mouseSensitivity * mouseY, mouseSensitivity * mouseX);
    glfwSetMousePos(0, 0); //reset the mouse, so it doesn't go out of the window

    //increase or decrease field of view based on mouse wheel
    const float zoomSensitivity = -0.2f;
    float fieldOfView = gCamera.fieldOfView() + zoomSensitivity * (float)glfwGetMouseWheel();
    if(fieldOfView < 5.0f) fieldOfView = 5.0f;
    if(fieldOfView > 130.0f) fieldOfView = 130.0f;
    gCamera.setFieldOfView(fieldOfView);
    glfwSetMouseWheel(0);
}
Beispiel #21
0
int main()
{
    int frameCnt = 0;
    struct timeval curTime;
    float dSecond = 0;
    float dSecondSum = 0; /* droped if more than 0.5 sec */

    timeval_diff_replace(&curTime);

    flags.pause = GL_FALSE;
    flags.vsync = GL_TRUE;

    scene = newScene(flags.vsync);

    setupGLFWCallbacks();
    glfwSetMousePos(scene->context->w / 2, scene->context->h / 2);

    while (running)
    {
        if (glfwGetWindowParam(GLFW_OPENED) == GL_FALSE)
        {
            running = GL_FALSE;
            break;
        }

        processKeyboardEvents(dSecond * BASE_FPS);
        processMouseEvents(dSecond * BASE_FPS);

        ++frameCnt;
        dSecond = timeval_diff_replace(&curTime);
        dSecondSum += dSecond;

        if (dSecondSum > 0.5f)
        {
            viewFps(frameCnt, dSecondSum);
            frameCnt = 0;
            dSecondSum = 0.0f;
        }

        if (!flags.pause)
        {
            modifyWaterMesh(scene->water, dSecond);
        }

        draw();
        glfwSwapBuffers();
    }

    freeScene(scene);

    return EXIT_SUCCESS;
}
Beispiel #22
0
void Input::init()
{
    glfwGetWindowSize(&m_mouse.x, &m_mouse.y);
    m_mouse.x /= 2;
    m_mouse.y /= 2;
    m_mouse.z = 0;

    m_mouseMiddleX = m_mouse.x;
    m_mouseMiddleY = m_mouse.y;

    glfwSetMousePos(m_mouse.x, m_mouse.y);
    glfwSetMouseWheel(0);
}
Beispiel #23
0
int
main(int argc, char **argv)
{
    shmup_game *g;
    GLFWvidmode d_mode;

    if(!glfwInit()) {
        fprintf( stderr, "Failed to initialize GLFW\n" );
        exit(EXIT_FAILURE);
    }

    glfwGetDesktopMode(&d_mode);
    //d_mode.Width/1.5, d_mode.Height/1.5
    if(!glfwOpenWindow(800, 600, d_mode.RedBits,
                       d_mode.GreenBits, d_mode.BlueBits, 8, 8, 0, GLFW_WINDOW)) {
        fprintf(stderr, "Failed to open GLFW window\n");
        glfwTerminate();
        exit(EXIT_FAILURE);
    }

    g = shmup_game_init();

    glfwSetWindowTitle("ShmupEngine");
//	glfwSetWindowSizeCallback(resize);
    glfwSwapInterval(1);
    glfwSetMousePos(g->window_width/2, g->window_height/2);
    glfwEnable(GLFW_MOUSE_CURSOR);

    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glOrtho(0, g->window_width, 0, g->window_height, 100, -100);
    glMatrixMode(GL_MODELVIEW);



    g->network_type = CLIENT;
    for (int i=0; i<argc; ++i) {
        if (strcmp("-a", argv[i])) g->network_type = SERVER;
    }

    shmup_game_run(g);
    shmup_game_close(g);

    glfwTerminate();
    exit(EXIT_SUCCESS);
}
Beispiel #24
0
int	main(int	argc,	char*	argv[])	{	
	Screen::Instance().Refresh();
	Screen::Instance().Open( 800, 600, false );

	glfwSetMousePos(400, 300);
	//glfwDisable(GLFW_MOUSE_CURSOR);



	while(Screen::Instance().IsOpened()	&& !Screen::Instance().KeyPressed( GLFW_KEY_ESC ))
	{	
  
		Screen::Instance().Refresh();
	}

    AudioEngine::Instance().Finish();
	return	0;	
}
Beispiel #25
0
bool kl_input_poll(kl_evt_generic_t *evt) {
  static bool keystates[KL_BTN_COUNT];
  while (current_button < KL_BTN_COUNT) {
    int i = current_button++;
    int c = glfwcode(i);
    if (c < 0) continue;
	int state = glfwGetKey(c);
    if (state == GLFW_PRESS && !keystates[i]) {
      evt->event.type    = KL_EVT_BUTTON;
      evt->button.code   = i;
      evt->button.isdown = true;
      keystates[i] = true;
      return true;
    }
	if (state == GLFW_RELEASE && keystates[i]) {
      evt->event.type    = KL_EVT_BUTTON;
      evt->button.code   = i;
      evt->button.isdown = false;
      keystates[i] = false;
      return true;
    }
  }
  
  if (!mouse_polled) {
    int w, h;
    glfwGetWindowSize(&w, &h);
    
    int x, y;
    glfwGetMousePos(&x, &y);
    glfwSetMousePos(w/2, h/2);
    
    evt->event.type   = KL_EVT_MOUSE;
    evt->mouse.x      = x;
    evt->mouse.y      = y;
    evt->mouse.dx     = x - w/2;
    evt->mouse.dy     = y - h/2;
    
    mouse_polled = true;
    return true;
  }
        
  evt->event.type   = KL_EVT_NONE;
  return false;
}
Beispiel #26
0
void init() {
	srand (time(NULL));

	if(!glfwInit()) {
        throw std::runtime_error("glfwInit failed");
		return;
	}
    
    glfwOpenWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
    glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, 3);
    glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, 2);
    glfwOpenWindowHint(GLFW_WINDOW_NO_RESIZE, GL_FALSE);
	if(!glfwOpenWindow(SCREEN_SIZE.x, SCREEN_SIZE.y, 8, 8, 8, 8, 16, 0, GLFW_WINDOW)) {
        throw std::runtime_error("glfwOpenWindow failed. Can your hardware handle OpenGL 3.2?");
		return;
	}

	glfwSetWindowPos(400, 100);

    //GLFW settings.
	glfwDisable(GLFW_MOUSE_CURSOR);
    glfwSetMousePos(SCREEN_SIZE.x / 2, SCREEN_SIZE.y / 2);
    glfwSetMouseWheel(0);
	
	glewExperimental = GL_TRUE;
    if(glewInit() != GLEW_OK) {
        throw std::runtime_error("glewInit failed");
		return;
	}

	while(glGetError() != GL_NO_ERROR) {}    
	
	std::cout << "OpenGL version: " << glGetString(GL_VERSION) << std::endl;
    std::cout << "GLSL version: " << glGetString(GL_SHADING_LANGUAGE_VERSION) << std::endl;
    std::cout << "Vendor: " << glGetString(GL_VENDOR) << std::endl;
    std::cout << "Renderer: " << glGetString(GL_RENDERER) << std::endl;

    if(!GLEW_VERSION_3_2) {
        throw std::runtime_error("OpenGL 3.2 API is not available.");
		return;
	}
}
Beispiel #27
0
bool GLContext::_glfwInit(){
    if( !glfwInit() ){
        LOG_ERROR( "Failed to initialize GLFW\n" );
        return false;
    }
    glfwOpenWindowHint(GLFW_FSAA_SAMPLES, 8);
    glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, 4);
    glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, 2);
    glfwOpenWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
    if( !glfwOpenWindow(
                GLContext::I().SceneParam.Width,
                GLContext::I().SceneParam.Height,
                0,
                0,
                0,
                0,
                32,
                0,
                GLFW_WINDOW) ){
        LOG_ERROR( "Failed to load Window\n" );
        glfwTerminate();
        return false;
    }
    glfwSetWindowTitle( "CorVision" );

    GLContext::I().SceneParam.AspectRatio =
            (float)GLContext::I().SceneParam.Width /
            (float)GLContext::I().SceneParam.Height;


    glfwEnable( GLFW_STICKY_KEYS );
    glfwEnable( GLFW_KEY_REPEAT );

    glfwDisable(GLFW_MOUSE_CURSOR);
    glfwSetMousePos(GLContext::I().SceneParam.midWindowX,
                    GLContext::I().SceneParam.midWindowY);


    glfwSwapInterval(1);
    return true;
}
Beispiel #28
0
orxSTATUS orxFASTCALL orxMouse_GLFW_SetPosition(const orxVECTOR *_pvPosition)
{
  orxS32    s32X, s32Y;
  orxSTATUS eResult = orxSTATUS_SUCCESS;

  /* Checks */
  orxASSERT((sstMouse.u32Flags & orxMOUSE_KU32_STATIC_FLAG_READY) == orxMOUSE_KU32_STATIC_FLAG_READY);

  /* Gets mouse position */
  glfwGetMousePos((int *)&s32X, (int *)&s32Y);

  /* Updates accumulator */
  sstMouse.vMouseAcc.fX += orxS2F(s32X) - _pvPosition->fX;
  sstMouse.vMouseAcc.fY += orxS2F(s32Y) - _pvPosition->fY;

  /* Moves mouse */
  glfwSetMousePos((int)orxF2S(_pvPosition->fX), (int)orxF2S(_pvPosition->fY));

  /* Done! */
  return eResult;
}
Beispiel #29
0
// update the scene based on the time elapsed since last update
void Update(float secondsElapsed) {
    //rotate the cube
    const GLfloat degreesPerSecond = 180.0f;
    gDegreesRotated += secondsElapsed * degreesPerSecond;
    while(gDegreesRotated > 360.0f) gDegreesRotated -= 360.0f;

    //move position of camera based on WASD keys, and XZ keys for up and down
    const float moveSpeed = 2.0; //units per second
    if(glfwGetKey('S')){
        gCamera.offsetPosition(secondsElapsed * moveSpeed * -gCamera.forward());
    } else if(glfwGetKey('W')){
        gCamera.offsetPosition(secondsElapsed * moveSpeed * gCamera.forward());
    }
    if(glfwGetKey('A')){
        gCamera.offsetPosition(secondsElapsed * moveSpeed * -gCamera.right());
    } else if(glfwGetKey('D')){
        gCamera.offsetPosition(secondsElapsed * moveSpeed * gCamera.right());
    }
    if(glfwGetKey('Z')){
        gCamera.offsetPosition(secondsElapsed * moveSpeed * -glm::vec3(0,1,0));
    } else if(glfwGetKey('X')){
        gCamera.offsetPosition(secondsElapsed * moveSpeed * glm::vec3(0,1,0));
    }

    //rotate camera based on mouse movement
    const float mouseSensitivity = 0.1;
    int mouseX, mouseY;
    glfwGetMousePos(&mouseX, &mouseY);
    gCamera.offsetOrientation(mouseSensitivity * mouseY, mouseSensitivity * mouseX);
    glfwSetMousePos(0, 0); //reset the mouse, so it doesn't go out of the window

    //increase or decrease field of view based on mouse wheel
    const float zoomSensitivity = -0.2;
    float fieldOfView = gCamera.fieldOfView() + zoomSensitivity * (float)glfwGetMouseWheel();
    if(fieldOfView < 5.0f) fieldOfView = 5.0f;
    if(fieldOfView > 130.0f) fieldOfView = 130.0f;
    gCamera.setFieldOfView(fieldOfView);
    glfwSetMouseWheel(0);
}
Beispiel #30
0
void Input::update()
{
    m_mouse.z = glfwGetMouseWheel();
    glfwSetMouseWheel(0);
    if (m_mouseVisible == false)
    {
#ifdef __APPLE__
 		CGGetLastMouseDelta(&m_mouse.x, &m_mouse.y);
        GLFWvidmode mode;
        glfwGetDesktopMode(&mode);
	    CGPoint p;
		p.x = m_mouseMiddleX;
		p.y = m_mouseMiddleY;
		CGWarpMouseCursorPosition(p);
#else
        glfwGetMousePos(&m_mouse.x, &m_mouse.y);
        m_mouse.x -= m_mouseMiddleX;
        m_mouse.y -= m_mouseMiddleY;
        glfwSetMousePos(m_mouseMiddleX, m_mouseMiddleY);
#endif
    }
    else
    {
        glfwGetMousePos(&m_mouse.x, &m_mouse.y);
    }
    
    m_mouse.b = 0;
    if (glfwGetMouseButton(GLFW_MOUSE_BUTTON_1))
    {
        m_mouse.b |= 1;
    }
    if (glfwGetMouseButton(GLFW_MOUSE_BUTTON_2))
    {
        m_mouse.b |= 2;
    }
}