Exemplo n.º 1
0
void Game::update(double seconds_elapsed)
{
	//to navigate with the mouse fixed in the middle
	if (mouse_locked)
	{
		SDL_WarpMouseInWindow(this->window, window_width*0.5, window_height*0.5); //put the mouse back in the middle of the screen
		this->mouse_position.x = window_width*0.5;
		this->mouse_position.y = window_height*0.5;
	}

	double speed = seconds_elapsed * 1000; //the speed is defined by the seconds_elapsed so it goes constant

	//mouse input to rotate the cam
	if ((mouse_state & SDL_BUTTON_LEFT) || mouse_locked ) //is left button pressed?
	{
		camera->rotate(speed * mouse_delta.x * 0.0005, Vector3(0,-1,0));
		camera->rotate(speed * mouse_delta.y * 0.0005, camera->getLocalVector( Vector3(-1,0,0)));
	}

	//async input to move the camera around
	if(keystate[SDL_SCANCODE_LSHIFT]) speed *= 10; //move faster with left shift
	if (keystate[SDL_SCANCODE_W]) camera->move(Vector3(0,0,1) * speed);
	if (keystate[SDL_SCANCODE_S]) camera->move(Vector3(0,0,-1) * speed);
	if (keystate[SDL_SCANCODE_A]) camera->move(Vector3(1,0,0) * speed);
	if (keystate[SDL_SCANCODE_D]) camera->move(Vector3(-1,0,0) * speed);

	angle += seconds_elapsed * 10;
}
Exemplo n.º 2
0
Arquivo: sdl.c Projeto: adurdin/fs-uae
static void post_main_loop(void)
{
    /* We want to improve the transitioning from FS-UAE back to e.g.
     * FS-UAE Game Center - avoid blinking cursor - so we try to move it (to
     * the bottom right of the screen). This probably requires that the
     * cursor is not grabbed (SDL often keeps the cursor in the center of the
     * screen then). */
    if (g_fs_emu_video_fullscreen) {
        if (SDL_getenv("FSGS_RETURN_CURSOR_TO") &&
                SDL_getenv("FSGS_RETURN_CURSOR_TO")[0]) {
            int x = -1; int y = -1;
            sscanf(SDL_getenv("FSGS_RETURN_CURSOR_TO"), "%d,%d", &x, &y);
            if (x != -1 && y != -1) {
#if 0
                fs_log("trying to move mouse cursor to x=%d y=%d\n", x, y);
#endif
                Uint8 data[] = "\0";
                SDL_SetWindowGrab(g_fs_ml_window, SDL_FALSE);
                /* Setting invisible cursor so we won't see it when we
                 * enable the cursor in order to move it. */
                SDL_Cursor *cursor = SDL_CreateCursor(data, data, 8, 1, 0, 0);
                SDL_SetCursor(cursor);
                SDL_ShowCursor(SDL_ENABLE);
                SDL_WarpMouseInWindow(g_fs_ml_window, x, y);
            }
        }
    }
}
Exemplo n.º 3
0
 /// \brief Moves the mouse to the specified point within the viewport
 void InputWrapper::warpMouse(int x, int y)
 {
     SDL_WarpMouseInWindow(mSDLWindow, x, y);
     mWarpCompensate = true;
     mWarpX = x;
     mWarpY = y;
 }
Exemplo n.º 4
0
bool Game::init(int width, int height, string name){
    cout << "Init game\n";
    
    m_Name = name;
    
    // Initialize the SDL library.
	if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_AUDIO) < 0)
	{
		fprintf(stderr, "SDL_Init() failed: %s\n", SDL_GetError());
		return false;
	}
	
	m_pWindow = SDL_CreateWindow(m_Name.c_str(), SDL_WINDOWPOS_CENTERED,
                                 SDL_WINDOWPOS_CENTERED, width, height, SDL_WINDOW_SHOWN);
    
	m_pRenderer = SDL_CreateRenderer(m_pWindow, -1,
                                     SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
    
    SDL_WarpMouseInWindow(m_pWindow, 300, 320);
    SDL_SetRelativeMouseMode(SDL_TRUE);
    SDL_ShowCursor(SDL_FALSE);
    TTF_Init();
    
    if (m_pWindow && m_pRenderer){
        cout << "Created window and renderer successfully\n";
        return true;
    }
    
    return false;
}
Exemplo n.º 5
0
/*
===============
IN_DeactivateMouse
===============
*/
static void IN_DeactivateMouse( void )
{
	if( !SDL_WasInit( SDL_INIT_VIDEO ) )
		return;

	// Always show the cursor when the mouse is disabled,
	// but not when fullscreen
	if( !Cvar_VariableIntegerValue("r_fullscreen") )
		SDL_ShowCursor( 1 );

	if( !mouseAvailable )
		return;

	if( mouseActive )
	{
		IN_GobbleMotionEvents( );

		SDL_SetWindowGrab( SDL_window, SDL_FALSE );
		SDL_SetRelativeMouseMode( SDL_FALSE );

		// Don't warp the mouse unless the cursor is within the window
		if( SDL_GetWindowFlags( SDL_window ) & SDL_WINDOW_MOUSE_FOCUS )
			SDL_WarpMouseInWindow( SDL_window, cls.glconfig.vidWidth / 2, cls.glconfig.vidHeight / 2 );

		mouseActive = qfalse;
	}
}
Exemplo n.º 6
0
int
SDL_SetRelativeMouseMode(SDL_bool enabled)
{
    SDL_Mouse *mouse = SDL_GetMouse();
    SDL_Window *focusWindow = SDL_GetKeyboardFocus();
    int original_x = mouse->x, original_y = mouse->y;

    if (enabled == mouse->relative_mode) {
        return 0;
    }

    if (!mouse->SetRelativeMouseMode) {
        return SDL_Unsupported();
    }

    if (enabled && focusWindow) {
        /* Center it in the focused window to prevent clicks from going through
         * to background windows.
         */
        SDL_SetMouseFocus(focusWindow);
        SDL_WarpMouseInWindow(focusWindow, focusWindow->w/2, focusWindow->h/2);
    }

    if (mouse->SetRelativeMouseMode(enabled) < 0) {
        return -1;
    }

    /* Set the relative mode */
    mouse->relative_mode = enabled;

    if (enabled) {
        /* Save the expected mouse position */
        mouse->original_x = original_x;
        mouse->original_y = original_y;
    } else if (mouse->focus) {
        /* Restore the expected mouse position */
        SDL_WarpMouseInWindow(mouse->focus, mouse->original_x, mouse->original_y);
    }

    /* Flush pending mouse motion */
    SDL_FlushEvent(SDL_MOUSEMOTION);

    /* Update cursor visibility */
    SDL_SetCursor(NULL);

    return 0;
}
Exemplo n.º 7
0
	void Mouse::setPosition(Window*window, unsigned int mouseIndex, const Vector2d&pos)
	{
		//TODO add support for multiple mouse indexes
		if(mouseIndex==0)
		{
			SDL_WarpMouseInWindow((SDL_Window*)EventManager::getDataFromWindow(window), (int)pos.x, (int)pos.y);
		}
	}
Exemplo n.º 8
0
void EventosMouse::posicionarEm(int x, int y)
{
	this->x = x;
	this->y = y;
	SDL_WarpMouseInWindow(janela.sdl_window, x, y);
	nx = (float)x/(float)janela.getLarguraTela();
	ny = (float)y/(float)janela.getAlturaTela();
}
void SDLHardwareRenderDevice::hideMouseCursor() {
	// place the mouse in the bottom-right of the screen by default because
	// flare-game doesn't place any menus here
	SDL_WarpMouseInWindow(window, SCREEN_W-1, SCREEN_H-1);

	curs->show_cursor = false;
	inpt->hideCursor();
}
Exemplo n.º 10
0
void Mouse::setY(int y)
{
    _y = y;
    auto renderer = Game::getInstance()->renderer();
    float scaleX = renderer->scaleX();
    float scaleY = renderer->scaleY();
    SDL_WarpMouseInWindow(renderer->sdlWindow(), _x*scaleX, _y*scaleY);
}
Exemplo n.º 11
0
 void Mouse::setPosition(const Point& pos)
 {
     _position = pos;
     auto renderer = Game::getInstance()->renderer();
     float scaleX = renderer->scaleX();
     float scaleY = renderer->scaleY();
     SDL_WarpMouseInWindow(renderer->sdlWindow(), (int)(pos.x() * scaleX), (int)(pos.y() * scaleY));
 }
Exemplo n.º 12
0
void Camera::setFirstPerson(bool firstPerson)
{
	this->firstPerson = firstPerson;
	SDL_ShowCursor(!firstPerson);

	if (firstPerson)
		SDL_WarpMouseInWindow(window->sdlWindow, window->width / 2, window->height / 2);
}
Exemplo n.º 13
0
bool mapHandleEvent(SDL_Event *event) {
	switch (event->type) {
	case SDL_MOUSEMOTION:
		// Drag the map with the right mouse button
		if (event->motion.state & SDL_BUTTON_RMASK) {
			map.offset.x += event->motion.x - map.dragPos.x;
			map.offset.y += event->motion.y - map.dragPos.y;
			SDL_WarpMouseInWindow(engine.window, map.dragPos.x, map.dragPos.y);
		}
		
		// Update block selection
		map.selEnd = (Vector){
			eucDiv(event->motion.x - map.offset.x, TILE_SIZE*map.zoom),
			eucDiv(event->motion.y - map.offset.y, TILE_SIZE*map.zoom),
		};
		if (!(event->motion.state & SDL_BUTTON_LMASK)) {
			map.selStart = map.selEnd;
		}
		break;
	
	case SDL_MOUSEBUTTONDOWN:
		if (event->button.button == SDL_BUTTON_RIGHT) {
			// Capture cursor for map dragging
			SDL_GetMouseState(&map.dragPos.x, &map.dragPos.y);
			SDL_ShowCursor(0);
		}
		break;
	
	case SDL_MOUSEBUTTONUP:
		if (event->button.button == SDL_BUTTON_LEFT) {
			// Holding in SHIFT deselects the block
			SDL_Keymod mod = SDL_GetModState();
			if (mod & KMOD_SHIFT) {
				mapDeselect();
			}
			else {
				mapSelect();
			}
			
			map.selStart = map.selEnd;
		}
		else if (event->button.button == SDL_BUTTON_RIGHT) {
			// Uncapture cursor
			SDL_ShowCursor(1);
		}
		break;
		
	case SDL_KEYDOWN:
		if (event->key.keysym.sym == SDLK_1) {
			map.zoom = 1;
		}
		else if (event->key.keysym.sym == SDLK_2) {
			map.zoom = 2;
		}
	}
	
	return true;
}
Exemplo n.º 14
0
Camera::Camera(vec3 pos, float speed, float horizontalAngle, float verticalAngle)
{
    // Get game instance
    Game *game = Game::GetInstance();

    // Initialize variables
    position  = pos;
    direction = vec3(0, 0, 0);
    right     = vec3(0, 0, 0);
    up        = vec3(0, 1, 0);

    this->horizontalAngle  = horizontalAngle;
    this->verticalAngle    = verticalAngle;
    initialFOV             = 45.0f;
    curFOV                 = initialFOV;
    this->speed            = speed;
    pitchSensitivity       = 0.005f;
    yawSensitivity         = 0.005f;

    mouseX = game->GetScreenWidth() / 2;
    mouseY = game->GetScreenHeight() / 2;

    forward = false;

    // Set mouse to center of the screen
    SDL_WarpMouseInWindow(game->GetWindow(), game->GetScreenWidth() / 2, game->GetScreenHeight() / 2);

    // Hide the mouse
    SDL_ShowCursor(SDL_DISABLE);

    inputEnabled = false;

    // 1.55f radians is 89 degrees, which is a reasonable vertical constraint
    if(verticalAngle > 1.55f)
        verticalAngle = 1.55f;
    else if(verticalAngle < -1.55f)
        verticalAngle = -1.55f;

    // Set new direction by converting spherical coordinates to cartesian
    direction = vec3(
            cos(verticalAngle) * sin(horizontalAngle),
            sin(verticalAngle),
            cos(verticalAngle) * cos(horizontalAngle)
            );

    // Calculate right vector
    right = vec3(
            sin(horizontalAngle - pi<float>() / 2),
            0,
            cos(horizontalAngle - pi<float>() / 2)
            );

    // Calculate up vector
    up = cross(right, direction);

    projectionMatrix = perspective(initialFOV, Game::GetInstance()->GetAspectRatio(), 0.1f, 1000.0f);
    viewMatrix       = lookAt(position, position + direction, up);
}
Exemplo n.º 15
0
void FLinuxCursor::SetPosition( const int32 X, const int32 Y )
{
	int WndX, WndY;

	SDL_HWindow WndFocus = SDL_GetMouseFocus();

	SDL_GetWindowPosition( WndFocus, &WndX, &WndY );	//	get top left
	SDL_WarpMouseInWindow( NULL, X - WndX, Y - WndY );
}
Exemplo n.º 16
0
GHOST_TSuccess GHOST_SystemSDL::setCursorPosition(GHOST_TInt32 x, GHOST_TInt32 y)
{
  int x_win, y_win;
  SDL_Window *win = SDL_GetMouseFocus();
  SDL_GetWindowPosition(win, &x_win, &y_win);

  SDL_WarpMouseInWindow(win, x - x_win, y - y_win);
  return GHOST_kSuccess;
}
Exemplo n.º 17
0
        void WindowSDL2::set_cursor_position(int x, int y) {

            if(closed) {
                return;
            }

            SDL_WarpMouseInWindow( window, x, y);

        } //set_cursor_position
Exemplo n.º 18
0
/**
 * @brief Check call to SDL_WarpMouseInWindow
 *
 * @sa http://wiki.libsdl.org/moin.cgi/SDL_WarpMouseInWindow
 */
int
mouse_warpMouseInWindow(void *arg)
{
    const int w = MOUSE_TESTWINDOW_WIDTH, h = MOUSE_TESTWINDOW_HEIGHT;
    int numPositions = 6;
    int xPositions[] = {-1, 0, 1, w-1, w, w+1 };
    int yPositions[] = {-1, 0, 1, h-1, h, h+1 };
    int x, y, i, j;
    SDL_Window *window;

    /* Create test window */
    window = _createMouseSuiteTestWindow();
    if (window == NULL) return TEST_ABORTED;

    /* Mouse to random position inside window */
    x = SDLTest_RandomIntegerInRange(1, w-1);
    y = SDLTest_RandomIntegerInRange(1, h-1);
    SDL_WarpMouseInWindow(window, x, y);
    SDLTest_AssertPass("SDL_WarpMouseInWindow(...,%i,%i)", x, y);

        /* Same position again */
    SDL_WarpMouseInWindow(window, x, y);
    SDLTest_AssertPass("SDL_WarpMouseInWindow(...,%i,%i)", x, y);

    /* Mouse to various boundary positions */
    for (i=0; i<numPositions; i++) {
      for (j=0; j<numPositions; j++) {
        x = xPositions[i];
        y = yPositions[j];
        SDL_WarpMouseInWindow(window, x, y);
        SDLTest_AssertPass("SDL_WarpMouseInWindow(...,%i,%i)", x, y);

        /* TODO: add tracking of events and check that each call generates a mouse motion event */
        SDL_PumpEvents();
        SDLTest_AssertPass("SDL_PumpEvents()");
      }
    }


        /* Clean up test window */
    _destroyMouseSuiteTestWindow(window);

    return TEST_COMPLETED;
}
Exemplo n.º 19
0
int main(int argc, char* argv[])
{
    InitOpenCL();
    
    memset(viewMatrix, 0, sizeof(float)*16);
    viewMatrix[0] = viewMatrix[5] = viewMatrix[10] = viewMatrix[15] = 1;
    
    
    SDL_Init(SDL_INIT_EVERYTHING);

        Uint32 flags = SDL_WINDOW_OPENGL;
        if ( kFullscreen ){
            flags |= SDL_WINDOW_FULLSCREEN;

            SDL_ShowCursor(0);
        }

        window = SDL_CreateWindow("RayTracer",
                SDL_WINDOWPOS_UNDEFINED,
                SDL_WINDOWPOS_UNDEFINED,
                kWidth, kHeight,
                flags);
    
    SDL_GL_CreateContext(window);
    
    SDL_WarpMouseInWindow(window, kWidth/2.0f, kHeight/2.0f);
    
    glEnable(GL_TEXTURE_2D);
    
        bool loop = true;
        int lastTicks = SDL_GetTicks();
        while(loop){
            int delta = SDL_GetTicks() - lastTicks;
            lastTicks = SDL_GetTicks();
            SDL_Event e;
            while(SDL_PollEvent(&e)){
                if ( e.type == SDL_QUIT){
                    loop = false;
                }
                else if ( e.type == SDL_KEYDOWN && e.key.keysym.sym == SDLK_ESCAPE){
                    loop = false;
                }
            }
        
            delta *= 0.1;
        Update(delta);
        Render(delta);
        
            std::stringstream ss;
            ss << 1000.0f / delta ;
            SDL_SetWindowTitle(window, ss.str().c_str());
        }
    
    SDL_DestroyWindow(window);
    return 0;
}
Exemplo n.º 20
0
void esGame_captureMouse(int on) {
	SDL_bool b = on ? SDL_TRUE : SDL_FALSE;
	SDL_SetRelativeMouseMode(b);
	SDL_CaptureMouse(b);

	if (b == SDL_FALSE) {
		SDL_WarpMouseInWindow(window, 0, 0);
		blockNextMouse = 1;
	}
}
Exemplo n.º 21
0
void Input::centerMouse()
{
	int window_width, window_height;
	SDL_GetWindowSize(window, &window_width, &window_height);

	int center_x = (int)floor(window_width*0.5f);
	int center_y = (int)floor(window_height*0.5f);
	SDL_WarpMouseInWindow(window, center_x, center_y); //put the mouse back in the middle of the screen
	Input::mouse_position.x = (float)center_x;
	Input::mouse_position.y = (float)center_y;
}
Exemplo n.º 22
0
Arquivo: game.cpp Projeto: AntiSC2/SGL
//Updates the position of things
void Game::update() {
   input.update();
   player.update(level);


   if(Input::mouse_grabbed())
   {
      SDL_WarpMouseInWindow(_screen.getWindow(), _screen.getWidth() / 2, _screen.getHeight() / 2);
   }

}
BOOL CBPlatform::SetCursorPos(int X, int Y)
{
	CBRenderSDL* renderer = static_cast<CBRenderSDL*>(Game->m_Renderer);

	POINT p;
	p.x = X;
	p.y = Y;
	renderer->PointToScreen(&p);

	SDL_WarpMouseInWindow(renderer->GetSdlWindow(), p.x, p.y);
	return TRUE;
}
Exemplo n.º 24
0
Vector2 Input::mouseDelta(){
	SDL_ShowCursor(0);
	Vector2 d(0,0);
	int mx=0;
	int my=0;
	SDL_GetMouseState(&mx, &my);
	d.x = ((float)(dem/2- mx) * sensitivity.x);
	d.y = (float)(dem /2- my) * sensitivity.y;
	 
	SDL_WarpMouseInWindow(window, dem / 2, dem/2);
	return d;
}
Exemplo n.º 25
0
void vid_mouse_button (SDL_MouseButtonEvent *event)
{
    SDL_Event dummy_event;
    int32 cx;
    int32 cy;
    SIM_MOUSE_EVENT ev;
    t_bool state;

    if (!vid_mouse_captured) {
        if ((event->state == SDL_PRESSED) &&
                (event->button == SDL_BUTTON_LEFT)) {               /* left click and cursor not captured? */
            sim_debug (SIM_VID_DBG_KEY, vid_dev, "vid_mouse_button() - Cursor Captured\n");
            SDL_SetRelativeMouseMode(SDL_TRUE);                 /* lock cursor to window, hide cursor */
            cx = vid_width / 2;
            cy = vid_height / 2;
            SDL_WarpMouseInWindow (NULL, cx, cy);               /* back to centre */
            SDL_PumpEvents ();
            while (SDL_PeepEvents (&dummy_event, 1, SDL_GETEVENT, SDL_MOUSEMOTION, SDL_MOUSEMOTION)) {};
            vid_mouse_captured = TRUE;
        }
        return;
    }
    if (!sim_is_running)
        return;
    if (SDL_SemWait (vid_mouse_events.sem) == 0) {
        sim_debug (SIM_VID_DBG_MOUSE, vid_dev, "Mouse Button Event: State: %d, Button: %d, (%d,%d)\n", event->state, event->button, event->x, event->y);
        if (vid_mouse_events.count < MAX_EVENTS) {
            state = (event->state == SDL_PRESSED) ? TRUE : FALSE;
            ev.x_rel = 0;
            ev.y_rel = 0;
            switch (event->button) {
            case SDL_BUTTON_LEFT:
                vid_mouse_events.b1_state = state;
                break;
            case SDL_BUTTON_MIDDLE:
                vid_mouse_events.b2_state = state;
                break;
            case SDL_BUTTON_RIGHT:
                vid_mouse_events.b3_state = state;
                break;
            }
            ev.b1_state = vid_mouse_events.b1_state;
            ev.b2_state = vid_mouse_events.b2_state;
            ev.b3_state = vid_mouse_events.b3_state;
            vid_mouse_events.events[vid_mouse_events.tail++] = ev;
            vid_mouse_events.count++;
            if (vid_mouse_events.tail == MAX_EVENTS)
                vid_mouse_events.tail = 0;
        }
        SDL_SemPost (vid_mouse_events.sem);
    }
}
void CameraFPS::mouseIsCaptured(GLboolean state) {
	_captureMouse = state;
	_wrapping = state;
	SDL_bool sdl_captured = _captureMouse ? SDL_TRUE : SDL_FALSE;
	SDL_ShowCursor(!sdl_captured);
	SDL_SetWindowGrab(_window, sdl_captured);

	if (_captureMouse) {
		int winWidth, winHeight;
		SDL_GetWindowSize(_window, &winWidth, &winHeight);
		SDL_WarpMouseInWindow(_window, winWidth / 2, winHeight / 2);
	}
}
Exemplo n.º 27
0
void input(SDL_Window* w,bool &quit){

SDL_Event event;

while (SDL_PollEvent(&event)) {
switch (event.type){
		
		case SDL_QUIT:
			quit=true;
			break;
		
		case SDL_KEYDOWN:
		case SDL_KEYUP:
			{
				// exit if ESCAPE is pressed
				if (event.key.keysym.sym == SDLK_ESCAPE){
						quit=true;
				}
				if (event.key.keysym.sym == SDLK_w){
						playerPos.z+=2;
				}
				if (event.key.keysym.sym == SDLK_s){
						playerPos.z-=2;
				}
				if (event.key.keysym.sym == SDLK_a){
						playerPos.x+=2;
				}
				if (event.key.keysym.sym == SDLK_d){
						playerPos.x-=2;
				}
				if (event.key.keysym.sym == SDLK_q){
						playerPos.y+=2;
				}
				if (event.key.keysym.sym == SDLK_e){
						playerPos.y-=2;
				}

				break;
			}
			
		case SDL_MOUSEMOTION:
		{
		
		yaw+=((event.motion.x)-300)/10.0;
		pit+=((event.motion.y)-300)/10.0;
		SDL_WarpMouseInWindow(w,300,300);
		
		}
	}
	}
}
Exemplo n.º 28
0
void Engine_Start()
{
#if defined(__MACOSX__)
    FindConfigFile();
#endif

    // Set defaults parameters and load config file.
    Engine_InitConfig("config.lua");

    // Primary initialization.
    Engine_Init_Pre();

    // Init generic SDL interfaces.
    Engine_InitSDLControls();
    Engine_InitSDLVideo();

#if !defined(__MACOSX__)
    Engine_InitSDLImage();
#endif

    // Additional OpenGL initialization.
    Engine_InitGL();
    renderer.doShaders();

    // Secondary (deferred) initialization.
    Engine_Init_Post();

    // Initial window resize.
    Engine_Resize(screen_info.w, screen_info.h, screen_info.w, screen_info.h);

    // OpenAL initialization.
    Engine_InitAL();

    ConsoleInfo::instance().addLine("Engine inited!", FONTSTYLE_CONSOLE_EVENT);

    // Clearing up memory for initial level loading.
    engine_world.prepare();

#ifdef NDEBUG
    // Setting up mouse.
    SDL_SetRelativeMouseMode(SDL_TRUE);
    SDL_WarpMouseInWindow(sdl_window, screen_info.w/2, screen_info.h/2);
    SDL_ShowCursor(0);
#endif

    // Make splash screen.
    Gui_FadeAssignPic(FADER_LOADSCREEN, "resource/graphics/legal.png");
    Gui_FadeStart(FADER_LOADSCREEN, GUI_FADER_DIR_OUT);

    luaL_dofile(engine_lua.getState(), "autoexec.lua");
}
Exemplo n.º 29
0
void Camera::OnMouse(int x, int y,SDL_Window* gWindow)
{
	//printf("x=%i y=%i\n", x, y);
	const int DeltaX = 2*(x - m_windowWidth / 2);
	const int DeltaY = 2*(y - m_windowHeight / 2);
	
	if (DeltaX == 0 && DeltaY == 0)return;
	SDL_WarpMouseInWindow(gWindow, m_windowWidth / 2, m_windowHeight / 2);

	m_mousePos.x = x;
	m_mousePos.y = y;

	m_AngleH += (float)DeltaX / 20.0f;
	m_AngleV += (float)DeltaY / 20.0f;

	if (DeltaX == 0)
	{
		if (x <= MARGIN)
		{
			m_OnLeftEdge = true;
		}
		else if (x >= m_windowWidth - MARGIN)
		{
			m_OnRightEdge = true;
		}
	}
	else
	{
		m_OnLeftEdge = false;
		m_OnRightEdge = false;
	}

	if (DeltaY == 0)
	{
		if (y <= MARGIN)
		{
			m_OnUpperEdge = true;
		}
		else if (y >= m_windowHeight - MARGIN)
		{
			m_OnLowerEdge = true;
		}
	}
	else
	{
		m_OnUpperEdge = false;
		m_OnLowerEdge = false;
	}

	Update();
}
Exemplo n.º 30
0
void SDLFrontend::setCursorPosition (int x, int y)
{
	// special case to disable the mouse cursor
	if (x == -1 && y == -1) {
		UI::get().setCursorPosition(x, y);
		return;
	}
	x = clamp(x, 0, _width);
	y = clamp(y, 0, _height);
	UI::get().setCursorPosition(x, y);
	if (!SDL_GetRelativeMouseMode()) {
		SDL_WarpMouseInWindow(_window, x, y);
	}
}