当前位置: 首页>>代码示例>>C++>>正文


C++ SDL_GetMouseState函数代码示例

本文整理汇总了C++中SDL_GetMouseState函数的典型用法代码示例。如果您正苦于以下问题:C++ SDL_GetMouseState函数的具体用法?C++ SDL_GetMouseState怎么用?C++ SDL_GetMouseState使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了SDL_GetMouseState函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: eventThread

static int eventThread(void *data)
{
	struct pt_data *gdata = (struct pt_data *) data;
	struct v4l2_control control;
	SDL_Surface *pscreen = *gdata->ptscreen;
	struct vdIn *videoIn = gdata->ptvideoIn;
	SDL_Event *sdlevent = gdata->ptsdlevent;
	SDL_Rect *drect = gdata->drect;
	SDL_mutex *affmutex = gdata->affmutex;
	int x, y;
	int mouseon = 0;
	int value = 0;
	int len = 0;
	short incpantilt = INCPANTILT;
	int boucle = 0;
	action_gui curr_action = A_VIDEO;
	while (videoIn->signalquit) {
		SDL_LockMutex(affmutex);
		float frmrate = gdata->frmrate;
		while (SDL_PollEvent(sdlevent)) {	//scan the event queue
			switch (sdlevent->type) {
			case SDL_KEYUP:
			case SDL_MOUSEBUTTONUP:
				mouseon = 0;
				incpantilt = INCPANTILT;
				boucle = 0;
				break;
			case SDL_MOUSEBUTTONDOWN:
				mouseon = 1;
			case SDL_MOUSEMOTION:
				SDL_GetMouseState(&x, &y);
				curr_action = GUI_whichbutton(x, y, pscreen, videoIn);
				break;
		/*	case SDL_VIDEORESIZE:
				pscreen =
				      SDL_SetVideoMode(sdlevent->resize.w,
				                       sdlevent->resize.h, 0,
				                       SDL_VIDEO_Flags);
				drect->w = sdlevent->resize.w;
				drect->h = sdlevent->resize.h;
				break;*/
			case SDL_KEYDOWN:
				curr_action = GUI_keytoaction(sdlevent->key.keysym.sym);
				if (curr_action != A_VIDEO)
					mouseon = 1;
				break;
			case SDL_QUIT:
				printf("\nQuit signal received.\n");
				videoIn->signalquit = 0;
				break;
			}
		}			//end if poll
		SDL_UnlockMutex(affmutex);
		/* traiter les actions */
		value = 0;
		if (mouseon) {
			boucle++;
			switch (curr_action) {
			case A_BRIGHTNESS_UP:
				if ((value = v4l2UpControl(videoIn, V4L2_CID_BRIGHTNESS)) < 0)
					printf("Set Brightness up error\n");
				break;
			case A_CONTRAST_UP:
				if ((value = v4l2UpControl(videoIn, V4L2_CID_CONTRAST)) < 0)
					printf("Set Contrast up error\n");
				break;
			case A_SATURATION_UP:
				if ((value = v4l2UpControl(videoIn, V4L2_CID_SATURATION)) < 0)
					printf("Set Saturation up error\n");
				break;
			case A_GAIN_UP:
				if ((value = v4l2UpControl(videoIn, V4L2_CID_GAIN)) < 0)
					printf("Set Gain up error\n");
				break;
			case A_SHARPNESS_UP:
				if ((value = v4l2UpControl(videoIn, V4L2_CID_SHARPNESS)) < 0)
					printf("Set Sharpness up error\n");
				break;
			case A_GAMMA_UP:
				if ((value = v4l2UpControl(videoIn, V4L2_CID_GAMMA)) < 0)
					printf("Set Gamma up error\n");
				break;
				
				/* Motor control events */
			case A_PAN_UP:
				if ((value = v4L2UpDownPan(videoIn, -incpantilt)) < 0)
					printf("Set Pan up error\n");
				break;
			case A_PAN_DOWN:
				if ((value = v4L2UpDownPan(videoIn, incpantilt)) < 0)
					printf("Set Pan down error\n");
				break;
			case A_TILT_UP:
				if ((value = v4L2UpDownTilt(videoIn, -incpantilt)) < 0)
					printf("Set Tilt up error\n");
				break;
			case A_TILT_DOWN:
				if ((value = v4L2UpDownTilt(videoIn, incpantilt)) < 0)
					printf("Set Tilt down error\n");
				break;
//.........这里部分代码省略.........
开发者ID:timon37,项目名称:zeawesome,代码行数:101,代码来源:luvcview.c

示例2: SDL_GetMouseState

void CLevelEditor::Input( CGameInput * pGameInput, float dps ) {
    
    if( !m_bEditorOn || !m_pCurLevel )
        return;
    
    int mx, my;
    auto mouseState = SDL_GetMouseState( &mx, &my );
    
    
    Vector2< float > cameraTranslate;
    
    if( m_pCamera ) {
        
        cameraTranslate = m_pCamera->GetTranslate();
        
    }
    
    int tX = ( mx - cameraTranslate.GetX() ) / TEXTURE_RENDER_WIDTH;
    int tY = ( my - cameraTranslate.GetY() ) / TEXTURE_RENDER_HEIGHT;
    
    if( mx - cameraTranslate.GetX() < 0 )
        tX--;
    
    if( my - cameraTranslate.GetY() < 0 )
        tY--;
    
    int x = tX * TEXTURE_RENDER_WIDTH;
    int y = tY * TEXTURE_RENDER_HEIGHT;

    
    if( mouseState & SDL_BUTTON( SDL_BUTTON_LEFT ) ) {
        
        if( m_CurTileIndex > -1  ) {
            
            m_SelectedTileIndex = m_CurTileIndex;
        
        } else if( m_SelectedTileIndex > -1 ) {
            
            m_pCurLevel->RemoveTileAt( mx - cameraTranslate.GetX(), my - cameraTranslate.GetY() );
            PlaceTile( m_SelectedTileIndex, x, y );
                
        }
            
    }
    
    if( m_pCamera ) {
    
        if( pGameInput->KeyDown( SDL_SCANCODE_UP ) ) {
         
            m_pCamera->Translate( 0.0f, -CAMERA_TRANSLATE_SPEED * dps );
            
        }

        if( pGameInput->KeyDown( SDL_SCANCODE_DOWN ) ) {
            
            m_pCamera->Translate( 0.0f, CAMERA_TRANSLATE_SPEED * dps );
            
        }
      
        if( pGameInput->KeyDown( SDL_SCANCODE_LEFT ) ) {
            
            m_pCamera->Translate( -CAMERA_TRANSLATE_SPEED * dps, 0.0f );
            
        }
        
        if( pGameInput->KeyDown( SDL_SCANCODE_RIGHT ) ) {
            
            m_pCamera->Translate( CAMERA_TRANSLATE_SPEED * dps, 0.0f );
            
        }

    }
    
    
    if( pGameInput->KeyDown( SDL_SCANCODE_1 ) ) {
        
        if( m_SelectedTileIndex > -1 ) {
            
            m_pCurLevel->RemoveTileAt( mx - cameraTranslate.GetX(), my - cameraTranslate.GetY() );
            PlaceTile( m_SelectedTileIndex, x, y );
        
        }
        
    }
    
    if( pGameInput->KeyDown( SDL_SCANCODE_3 ) ) {
        
        
        m_pCurLevel->RemoveTileAt( mx - cameraTranslate.GetX(), my - cameraTranslate.GetY() );

        
    }
    
    if( pGameInput->ShiftMod() && pGameInput->KeyDownOnce( SDLK_0 ) ) {
        
        if( m_pCurLevel ) {
            
            m_LastSaveTime = SDL_GetTicks();
            m_pCurLevel->Save( m_pCurLevel->GetPath() );
        
//.........这里部分代码省略.........
开发者ID:RickDork,项目名称:Sora,代码行数:101,代码来源:LevelEditor.cpp

示例3: menuCommand2

void menuCommand2()
{
	int mx, my;
	FILE *file;

	if( SDL_GetMouseState(&mx, &my) &SDL_BUTTON_LMASK )
	{
		if( (mx > MENU_X + 130) && (mx < (MENU_X + 510)) )
		{
			// Main Menu
			if( HUD.menu == 1 )
			{
				// New game
				if( (my > (MENU_Y + 40)) && (my < (MENU_Y + 105)) )
				{
					//endGame();
					if(!Mix_PlayingMusic())
						startMusic();
					else if(!players[0].inGame)
					{
						Mix_HookMusicFinished(nextSong);
						Mix_FadeOutMusic(100);
					}
					startGame(MAX_PLAYERS);
				}	

				// Resume
				else if( (my > (MENU_Y + 122)) && (my < (MENU_Y + 190)) )
				{
					if(players[0].inGame)
						HUD.menu = 0;
				}

				// Save/Load
				else if( (my > (MENU_Y + 205)) && (my < (MENU_Y + 275)) )
				{
					HUD.menu = 2;
				}

				// Options
				else if( (my > (MENU_Y + 285)) && (my < (MENU_Y + 355)) )
				{
					HUD.menu = 3;
				}

				// Quit
				else if( (my > (MENU_Y + 365)) && (my < (MENU_Y + 435)) )
				{
					exit(0);
				}
			}

			// Save/Load submenu
			else if( HUD.menu == 2 )
			{
				// Save
				if( (my > (MENU_Y + 40)) && (my < (MENU_Y + 105)) )
				{
					fprintf(stderr,"Saving not yet implemented.\n");
				}	

				// Load
				else if( (my > (MENU_Y + 122)) && (my < (MENU_Y + 190)) )
				{
					fprintf(stderr,"Loading not yet implemented.\n");
				}

				// Main Menu
				else if( (my > (MENU_Y + 365)) && (my < (MENU_Y + 435)) )
				{
					HUD.menu = 1;
				}
			}

			// Options submenu
			else if( HUD.menu == 3 )
			{
				// Sound
				if( (my > (MENU_Y + 40)) && (my < (MENU_Y + 105)) )
				{
					HUD.menu = 4;
				}	

				// Controls
				else if( (my > (MENU_Y + 122)) && (my < (MENU_Y + 190)) )
				{
					HUD.menu = 5;
				}

				// HUD
				else if( (my > (MENU_Y + 205)) && (my < (MENU_Y + 275)) )
				{
					HUD.menu = 6;
				}

				// Game
				else if( (my > (MENU_Y + 285)) && (my < (MENU_Y + 355)) )
				{
					HUD.menu = 7;
				}
//.........这里部分代码省略.........
开发者ID:vscuorzo,项目名称:mandest,代码行数:101,代码来源:cmd.c

示例4: handleEvent

	virtual void handleEvent(SDL_Event& e)
	{
		//If an event was detected for this window
		if (e.window.windowID != mWindowID)
			return;

		if (e.type == SDL_WINDOWEVENT)
		{
			//Caption update flag
			bool updateCaption = false;

			switch (e.window.event)
			{
				//Window appeared
				case SDL_WINDOWEVENT_SHOWN:
					mShown = true;
					break;

					//Window disappeared
				case SDL_WINDOWEVENT_HIDDEN:
					mShown = false;
					break;

					//Get new dimensions and repaint
				case SDL_WINDOWEVENT_SIZE_CHANGED:
					mWidth = e.window.data1;
					mHeight = e.window.data2;
					SDL_RenderPresent(mRenderer);
					break;

					//Repaint on expose
				case SDL_WINDOWEVENT_EXPOSED:
					SDL_RenderPresent(mRenderer);
					break;

					//Mouse enter
				case SDL_WINDOWEVENT_ENTER:
					mMouseFocus = true;
					updateCaption = true;
					break;

					//Mouse exit
				case SDL_WINDOWEVENT_LEAVE:
					mMouseFocus = false;
					updateCaption = true;
					break;

					//Keyboard focus gained
				case SDL_WINDOWEVENT_FOCUS_GAINED:
					mKeyboardFocus = true;
					updateCaption = true;
					break;

					//Keyboard focus lost
				case SDL_WINDOWEVENT_FOCUS_LOST:
					mKeyboardFocus = false;
					updateCaption = true;
					break;

					//Window minimized
				case SDL_WINDOWEVENT_MINIMIZED:
					mMinimized = true;
					break;

					//Window maxized
				case SDL_WINDOWEVENT_MAXIMIZED:
					mMinimized = false;
					break;

					//Window restored
				case SDL_WINDOWEVENT_RESTORED:
					mMinimized = false;
					break;

					//Hide and quit on close
				case SDL_WINDOWEVENT_CLOSE:
					SDL_HideWindow(mWindow);
					mClosed = true;
					break;
			}

			//Demo Update window caption with new data
			if (updateCaption)
			{
				std::stringstream caption;
				caption << mTitle << " - ID: " << mWindowID << " MouseFocus:"
						<< ((mMouseFocus) ? "On" : "Off") << " KeyboardFocus:"
						<< ((mKeyboardFocus) ? "On" : "Off");
				SDL_SetWindowTitle(mWindow, caption.str().c_str());
			}
		}

		//Case of Panels
		int x, y;
		//Get mouse position
		SDL_GetMouseState(&x, &y);

		for (std::list<Panel*>::iterator iter = pList_->begin(); iter != pList_->end(); iter++)
		{
			Panel *p = (*iter);
//.........这里部分代码省略.........
开发者ID:pmrobotix,项目名称:DemoFusion,代码行数:101,代码来源:IWindow.hpp

示例5: wrefresh

// This is how we're actually going to handle input events, SDL getch
// is simply a wrapper around this.
input_event input_manager::get_input_event(WINDOW *win) {
    // standards note: getch is sometimes required to call refresh
    // see, e.g., http://linux.die.net/man/3/getch
    // so although it's non-obvious, that refresh() call (and maybe InvalidateRect?) IS supposed to be there

    if(win == NULL) win = mainwin;

    wrefresh(win);
    lastchar=ERR;//ERR=-1
    input_event rval;

    if (inputdelay < 0)
    {
        do
        {
            rval.type = CATA_INPUT_ERROR;
            CheckMessages();
            if (lastchar!=ERR) break;
            SDL_Delay(1);
        }
        while (lastchar==ERR);
    }
    else if (inputdelay > 0)
    {
        unsigned long starttime=SDL_GetTicks();
        unsigned long endtime;
        bool timedout = false;
        do
        {
            rval.type = CATA_INPUT_ERROR;
            CheckMessages();
            endtime=SDL_GetTicks();
            if (lastchar!=ERR) break;
            SDL_Delay(1);
            timedout = endtime >= starttime + inputdelay;
            if (timedout) {
                rval.type = CATA_INPUT_TIMEOUT;
            }
        }
        while (!timedout);
    }
    else
    {
        CheckMessages();
    }

    if (rval.type != CATA_INPUT_TIMEOUT) {
        if (lastchar == ERR) {
            rval.type = CATA_INPUT_ERROR;
        } else if (lastchar_isbutton) {
            rval.type = CATA_INPUT_GAMEPAD;
            rval.add_input(lastchar);
        } else if (lastchar_is_mouse) {
            rval.type = CATA_INPUT_MOUSE;
            rval.add_input(lastchar);
            SDL_GetMouseState(&rval.mouse_x, &rval.mouse_y);
        } else {
            rval.type = CATA_INPUT_KEYBOARD;
            rval.add_input(lastchar);
        }
    }

    return rval;
}
开发者ID:JedrekD,项目名称:Cataclysm-DDA,代码行数:66,代码来源:sdltiles.cpp

示例6: SDL_GetMouseState

Player::Player()
{
	bomb = nullptr;
	
	SDL_GetMouseState(&mouseLastX, &mouseLastY);
	mouseLeftPressed = false;
	mouseRightPressed = false;
	boolKeyboardAngle = false;
	boolMove = false;

	allowedToFly = false;
	boolOnTheGround = false;
	ySpeed = 0;

	cameraAngleX = glm::radians(135.f);
	cameraAngleY = glm::radians(25.f);
	playerAngleX = cameraAngleX;
	playerAngleY = cameraAngleY;
	orientMe();
	camlx = playerlx;
	camlz = playerlz;
	camly = playerly;

	x = 0.5f;
	y = Game::Instance().getMap().getH(0, 0);
	z = 0.5f;

	deltaAngle = 0.0;
	deltaMove=0.0;

	shootAng = ANG_SHOOT_START;
	shootForce = SHOOT_FORCE_START;

	perna1Ang = 245.f;
	perna2Ang = 40.f;

	std::vector<glm::vec3> vertices;
	std::vector<glm::vec2> uvs;
	std::vector<glm::vec3> normals;

	float corDino[3] = {25/255.f, 80/255.f, 25/255.f};

	loadOBJ("Geometry/Objects/dinobody.obj", vertices, uvs, normals);

	std::vector<GLfloat> vColor;
	for(int i=0; i < (int)vertices.size(); i++){
		vColor.push_back(corDino[0]);
		vColor.push_back(corDino[1]);
		vColor.push_back(corDino[2]);
	}

	std::vector<GLfloat> vPos;
	for(int i=0; i < (int)vertices.size(); i++){
		vPos.push_back(vertices[i].x);
		vPos.push_back(vertices[i].y);
		vPos.push_back(vertices[i].z);
	}

	std::vector<GLfloat> vNormals;
	for(int i=0; i < (int)normals.size(); i++){
		vNormals.push_back(normals[i].x);
		vNormals.push_back(normals[i].y);
		vNormals.push_back(normals[i].z);
	}

	playerAvatar = new GlObject(Game::Instance().getNormalShader(), vertices.size(), &vPos[0], &vColor[0], normals.size(), &vNormals[0]);

	std::vector<glm::vec3> verticesLeg;
	std::vector<glm::vec2> uvsLeg;
	std::vector<glm::vec3> normalsLeg;

	loadOBJ("Geometry/Objects/dinoleg.obj", verticesLeg, uvsLeg, normalsLeg);

	std::vector<GLfloat> vColorLeg1;
	for(int i=0; i < (int)verticesLeg.size(); i++){
		vColorLeg1.push_back(corDino[0]);
		vColorLeg1.push_back(corDino[1]);
		vColorLeg1.push_back(corDino[2]);
	}

	std::vector<GLfloat> vPosLeg1;
	for(int i=0; i < (int)verticesLeg.size(); i++){
		vPosLeg1.push_back(verticesLeg[i].x);
		vPosLeg1.push_back(verticesLeg[i].y);
		vPosLeg1.push_back(verticesLeg[i].z);
	}

	std::vector<GLfloat> vNormalsLeg1;
	for(int i=0; i < (int)normalsLeg.size(); i++){
		vNormalsLeg1.push_back(normalsLeg[i].x);
		vNormalsLeg1.push_back(normalsLeg[i].y);
		vNormalsLeg1.push_back(normalsLeg[i].z);
	}

	playerLeg1 = new GlObject(Game::Instance().getNormalShader(), verticesLeg.size(), &vPosLeg1[0], &vColorLeg1[0], normalsLeg.size(), &vNormalsLeg1[0]);

	std::vector<GLfloat> vPosLeg2(vPosLeg1);
	std::vector<GLfloat> vColorLeg2(vColorLeg1);
	std::vector<GLfloat> vNormalsLeg2(vNormalsLeg1);
	playerLeg2 = new GlObject(Game::Instance().getNormalShader(), verticesLeg.size(), &vPosLeg2[0], &vColorLeg2[0], normalsLeg.size(), &vNormalsLeg2[0]);
//.........这里部分代码省略.........
开发者ID:S-ngularity,项目名称:ProjetoCG_Bombersauro,代码行数:101,代码来源:Player.cpp

示例7: IN_Frame

/**
 * @brief Handle input events like keys presses and joystick movement as well
 * as window events
 * @sa CL_Frame
 * @sa IN_Parse
 * @sa IN_JoystickMove
 */
void IN_Frame (void)
{
	int mouse_buttonstate;
	unsigned short unicode;
	unsigned int key;
	SDL_Event event;

	IN_Parse();

	IN_JoystickMove();

	if (vid_grabmouse->modified) {
		vid_grabmouse->modified = qfalse;

		if (!vid_grabmouse->integer) {
			/* ungrab the pointer */
			Com_Printf("Switch grab input off\n");
			SDL_WM_GrabInput(SDL_GRAB_OFF);
		/* don't allow grabbing the input in fullscreen mode */
		} else if (!vid_fullscreen->integer) {
			/* grab the pointer */
			Com_Printf("Switch grab input on\n");
			SDL_WM_GrabInput(SDL_GRAB_ON);
		} else {
			Com_Printf("No input grabbing in fullscreen mode\n");
			Cvar_SetValue("vid_grabmouse", 0);
		}
	}

	oldMousePosX = mousePosX;
	oldMousePosY = mousePosY;

	while (SDL_PollEvent(&event)) {
		switch (event.type) {
		case SDL_MOUSEBUTTONDOWN:
		case SDL_MOUSEBUTTONUP:
			switch (event.button.button) {
			case SDL_BUTTON_LEFT:
				mouse_buttonstate = K_MOUSE1;
				break;
			case SDL_BUTTON_MIDDLE:
				mouse_buttonstate = K_MOUSE3;
				break;
			case SDL_BUTTON_RIGHT:
				mouse_buttonstate = K_MOUSE2;
				break;
			case SDL_BUTTON_WHEELUP:
				mouse_buttonstate = K_MWHEELUP;
				break;
			case SDL_BUTTON_WHEELDOWN:
				mouse_buttonstate = K_MWHEELDOWN;
				break;
			case 6:
				mouse_buttonstate = K_MOUSE4;
				break;
			case 7:
				mouse_buttonstate = K_MOUSE5;
				break;
			default:
				mouse_buttonstate = K_AUX1 + (event.button.button - 8) % 16;
				break;
			}
			IN_EventEnqueue(mouse_buttonstate, 0, (event.type == SDL_MOUSEBUTTONDOWN));
			break;

		case SDL_MOUSEMOTION:
			SDL_GetMouseState(&mousePosX, &mousePosY);
			mousePosX /= viddef.rx;
			mousePosY /= viddef.ry;
			break;

		case SDL_KEYDOWN:
			IN_PrintKey(&event, 1);
#ifndef _WIN32
			if ((event.key.keysym.mod & KMOD_ALT) && event.key.keysym.sym == SDLK_RETURN) {
				SDL_Surface *surface = SDL_GetVideoSurface();
				if (!SDL_WM_ToggleFullScreen(surface)) {
					int flags = surface->flags ^= SDL_FULLSCREEN;
					SDL_SetVideoMode(surface->w, surface->h, 0, flags);
				}

				if (surface->flags & SDL_FULLSCREEN) {
					Cvar_SetValue("vid_fullscreen", 1);
					/* make sure, that input grab is deactivated in fullscreen mode */
					Cvar_SetValue("vid_grabmouse", 0);
				} else {
					Cvar_SetValue("vid_fullscreen", 0);
				}
				vid_fullscreen->modified = qfalse; /* we just changed it with SDL. */
				break; /* ignore this key */
			}
#endif

//.........这里部分代码省略.........
开发者ID:ptitSeb,项目名称:UFO--AI-OpenPandora,代码行数:101,代码来源:cl_input.c

示例8: draw

int draw( void )
{
    
    if(wireframe)
    {
        glClearColor(1, 1, 1, 1);
        glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
        glLineWidth(2);
    }
    else
    {
        glClearColor(0.2f, 0.2f, 0.2f, 1);
        glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
    }
    
    // effacer l'image
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    
    if(key_state('r'))
    {
        clear_key_state('r');
        reload_program();
    }
    
    // recupere les mouvements de la souris
    int mx, my;
    unsigned int mb= SDL_GetRelativeMouseState(&mx, &my);
    int mousex, mousey;
    SDL_GetMouseState(&mousex, &mousey);
    
    // deplace la camera
    if(mb & SDL_BUTTON(1))
        orbiter_rotation(camera, mx, my);      // tourne autour de l'objet
    else if(mb & SDL_BUTTON(2))
        orbiter_translation(camera, (float) mx / (float) window_width(), (float) my / (float) window_height()); // deplace le point de rotation
    else if(mb & SDL_BUTTON(3))
        orbiter_move(camera, mx);           // approche / eloigne l'objet
    
    // recupere les transformations
    Transform model= make_identity();
    Transform view= orbiter_view_transform(camera);
    Transform projection= orbiter_projection_transform(camera, window_width(), window_height(), 45);
    Transform viewport= make_viewport(window_width(), window_height());
    
    Transform mvp= projection * view * model;
    Transform mvpInv= make_inverse(mvp);
    Transform mv= model * view;
    
    // affiche l'objet
    if(program_failed == false)
    {
        if(key_state('w'))
        {
            clear_key_state('w');
            wireframe= !wireframe;
        }
        
        // configuration minimale du pipeline
        glBindVertexArray(vao);
        glUseProgram(program);
        
        // affecte une valeur aux uniforms
        // transformations standards
        program_uniform(program, "modelMatrix", model);
        program_uniform(program, "modelInvMatrix", make_inverse(model));
        program_uniform(program, "viewMatrix", view);
        program_uniform(program, "viewInvMatrix", make_inverse(view));
        program_uniform(program, "projectionMatrix", projection);
        program_uniform(program, "projectionInvMatrix", make_inverse(projection));
        program_uniform(program, "viewportMatrix", viewport);
        program_uniform(program, "viewportInvMatrix", make_inverse(viewport));
        
        program_uniform(program, "mvpMatrix", mvp);
        program_uniform(program, "mvpInvMatrix", mvpInv);
        
        program_uniform(program, "mvMatrix", mv);
        program_uniform(program, "normalMatrix", make_normal_transform(mv));
        
        // interactions
        program_uniform(program, "viewport", make_vec2(window_width(), window_height()));
        program_uniform(program, "time", (float) SDL_GetTicks());
        program_uniform(program, "motion", make_vec3(mx, my, mb & SDL_BUTTON(1)));
        program_uniform(program, "mouse", make_vec3(mousex, mousey, mb & SDL_BUTTON(1)));
        
        // textures
        for(unsigned int i= 0; i < (unsigned int) textures.size(); i++)
        {
            char uniform[1024];
            sprintf(uniform, "texture%d", i);
            program_use_texture(program, uniform, i, textures[i]);
        }
        
        // go
        glDrawArrays(GL_TRIANGLES, 0, vertex_count);
    }
    
    // affiche les infos
    begin(widgets);
    if(program_failed)
    {
//.........这里部分代码省略.........
开发者ID:PierreCAMILLI,项目名称:mif23-projet,代码行数:101,代码来源:shader_kit.cpp

示例9: main

int main(int argc, char* argv[])
{
    // Create our window
    MainScreen = new Screen;

    MainScreen->Clear();

    // For backwards-compatibility, we want project files that are drag-and-dropped
    // onto the executable to be automatically loaded when it starts.
    // First, we have to make sure the file's actually there.
    FILE* prjfile = (argc > 1) ? fopen(argv[1], "r") : NULL;
#ifdef _WIN32
    // Windows build allows a blank window to open, where the user can open a
    // project file using the menu bar
    if (prjfile != NULL)
    {
	fclose(prjfile);
        CurProject = new Project(argv[1]);

        // Process initial display
        CurProject->Redraw();
    }
#else
    if (prjfile == NULL)
    {
        SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Error", "You must supply the project file as a parameter", NULL);
        exit(1);
    }
    fclose(prjfile);
    CurProject = new Project(argv[1]);

    // Process initial display
    CurProject->Redraw();
#endif

    bool CtrlPress = false;
    
    //SDL_EnableKeyRepeat(400,SDL_DEFAULT_REPEAT_INTERVAL);

    //Main Loop including event Handling
    bool quit = false;
    while (!quit)
    {
        SDL_Event event;

        while ((!quit) && SDL_WaitEvent(&event))
        {
            if (event.type == SDL_QUIT) quit = true;
            if (event.type == SDL_MOUSEBUTTONDOWN) 
            {
		if (CurProject != NULL)
		{
                    CurProject->SelectionRect->Unselect();
                    //Checks if within selector bounds and selects tile
                    CurProject->LevelMap->CheckClickTile(event.button.x, event.button.y);
                    if (event.button.button == SDL_BUTTON_LEFT)
                        //Checks if valid map position and sets tile
                        CurProject->LevelMap->CheckSetTile(event.button.x, event.button.y);
                    else if (event.button.button == SDL_BUTTON_RIGHT) {
                        //Checks if valid map position and selects tile
                        CurProject->LevelMap->CheckSelectTile(event.button.x, event.button.y);
                        CurProject->SelectionRect->SelInit(event.button.x, event.button.y);
                    }
		}
            }
            if (event.type == SDL_MOUSEBUTTONUP) 
            {
                if (event.button.button == SDL_BUTTON_RIGHT) {
		    if (CurProject != NULL)
		    {
                        //Checks if valid map position and selects tile
                        CurProject->LevelMap->CheckSelectTile(event.button.x, event.button.y);
                        CurProject->SelectionRect->SelFinalize(event.button.x, event.button.y);
		    }
                }
            }
            if (event.type == SDL_MOUSEMOTION)
            {
		if (CurProject != NULL)
		{
                    if (SDL_GetMouseState(NULL, NULL)&SDL_BUTTON(1))
                        CurProject->LevelMap->CheckSetTile(event.motion.x, event.motion.y);
                    else {
                        CurProject->LevelMap->RefreshTileScreen(event.motion.x - event.motion.xrel, event.motion.y - event.motion.yrel, true);
                        CurProject->LevelMap->DrawSelectedTile(event.motion.x, event.motion.y);
                    }
		}
            }
            if (event.type == SDL_KEYDOWN)
            {
                //secondary cases usually for German keyboard layout support
                switch(event.key.keysym.sym)
                {
                    case SDLK_RCTRL:
                    case SDLK_LCTRL:
                        CtrlPress = true; break;
                    case '/':
                    case '-':
		        if (CurProject != NULL)
			{
//.........这里部分代码省略.........
开发者ID:Clownacy,项目名称:CaptainPlaneEd,代码行数:101,代码来源:PlaneEd.cpp

示例10: show

void SDLViewer::execute()
{
  bool redisplay = true;
  MouseButton button = NoButton;
  unsigned char key;
  int x, y;
  SDL_Event event;
  int modifiers = 0;
  static unsigned int stimer;

  //Ensure window visible for interaction
  show();

  // Enter event loop processing
  while ( !quitProgram )
  {
    // Check for events
    // Delay redisplay & resize until event queue empty
    if (SDL_PollEvent(&event) == 0)
    {
      // Resize window
      if (resized)
      {
        if (stimer < SDL_GetTicks())
        {
          // Create in new dimensions
          resized = false;
          open(width, height);
          redisplay = true;
        }
        else
          continue;   //Cycle until timer runs out
      }

      if (redisplay)
      {
        // Redraw Viewer (Call virtual to display)
        display();
        redisplay = false;
      }

      // Wait for next event
      SDL_WaitEvent( &event );
    }

    //Save shift states
    modifiers = SDL_GetModState();
    keyState.shift = (modifiers & KMOD_SHIFT);
    keyState.ctrl = (modifiers & KMOD_CTRL);
    keyState.alt = (modifiers & KMOD_ALT);

    // Process event
    switch (event.type)
    {
    case SDL_QUIT:
      quitProgram = true;
      break;
    case SDL_VIDEORESIZE:
      //Adjust viewport metrics etc...
      resize(event.resize.w, event.resize.h);
      resized = true;
      //Start timer to wait for sizing events to cease before calling actual context resize
      stimer = SDL_GetTicks() + 200;
      break;
    case SDL_KEYDOWN:
      //Pass keystrokes on KEYDOWN only, char info not provided by SDL on KEYUP
      key = event.key.keysym.unicode;
      if (!key)
      {
        int code = (int)event.key.keysym.sym;
        if (code == SDLK_KP8 || code == SDLK_UP) key = KEY_UP;
        if (code == SDLK_KP2 || code == SDLK_DOWN) key = KEY_DOWN;
        if (code == SDLK_KP4 || code == SDLK_LEFT) key = KEY_LEFT;
        if (code == SDLK_KP6 || code == SDLK_RIGHT) key = KEY_RIGHT;
        if (code == SDLK_KP9 || code == SDLK_PAGEUP) key = KEY_PAGEUP;
        if (code == SDLK_KP3 || code == SDLK_PAGEDOWN) key = KEY_PAGEDOWN;
        if (code == SDLK_KP7 || code == SDLK_HOME) key = KEY_HOME;
        if (code == SDLK_KP1 || code == SDLK_END) key = KEY_END;
        //key = (unsigned char)code;
        if (!key) continue;
      }
      SDL_GetMouseState(&x, &y);
      if (keyPress(key, x, y)) redisplay = true;
      break;
    case SDL_MOUSEMOTION:
      if (mouseState)
      {
        mouseMove(event.motion.x, event.motion.y);
        redisplay = true;
      }
      break;
    case SDL_MOUSEBUTTONDOWN:
      button = (MouseButton)event.button.button;
      // XOR state of three mouse buttons to the mouseState variable
      if (button <= RightButton) mouseState ^= (int)pow(2.0,button);
      mousePress( button, true, event.button.x, event.button.y);
      break;
    case SDL_MOUSEBUTTONUP:
      mouseState = 0;
      button = (MouseButton)event.button.button;
//.........这里部分代码省略.........
开发者ID:lmoresi,项目名称:LavaVu,代码行数:101,代码来源:SDLViewer.cpp

示例11: while

void CMain::GameLoop(void)
{
	while (!quit && csdl_setup->GetMainEvent()->type != SDL_QUIT)
	{
		csdl_setup->Begin();
		SDL_GetMouseState(&MouseX, &MouseY);

		grass->Draw();
		bob->Draw();

		float angle = atan2(Follow_Point_Y - bob->GetY(), Follow_Point_X - bob->GetX());
		angle = (angle * (180 / 3.14)) + 180;

		if (!stopAnimation)
		{
			if (angle > 45 && angle <= 135)
			{
				//up

				if (distance > 15)
					bob->PlayAnimation(0, 3, 3, 200);
				else
					bob->PlayAnimation(1, 1, 3, 200);
			}
			else if (angle > 135 && angle <= 225)
			{
				//right
				if (distance > 15)
					bob->PlayAnimation(0, 3, 2, 200);
				else
					bob->PlayAnimation(1, 1, 2, 200);
			}
			else if (angle > 225 && angle <= 315)
			{
				//down
				if (distance > 15)
					bob->PlayAnimation(0, 3, 0, 200);
				else
					bob->PlayAnimation(1, 1, 0, 200);
			}
			else if ((angle <= 360 && angle > 315) || (angle >= 0 && angle <= 45))
			{
				//left
				if (distance > 20)
					bob->PlayAnimation(0, 3, 1, 200);
				else
					bob->PlayAnimation(1, 1, 1, 200);
			}
		}



		if (csdl_setup->GetMainEvent()->type == SDL_MOUSEBUTTONDOWN || csdl_setup->GetMainEvent()->type == SDL_MOUSEMOTION)
		{
			if (csdl_setup->GetMainEvent()->button.button == SDL_BUTTON_LEFT)
			{
				Follow_Point_X = MouseX;
				Follow_Point_Y = MouseY;
				Follow = true;
			}
		}

		if (timeCheck + 10 < SDL_GetTicks() && Follow)
		{

			distance = GetDistance(bob->GetX(), bob->GetY(), Follow_Point_X, Follow_Point_Y);

			if (distance == 0)
				stopAnimation = true;
			else
				stopAnimation = false;


			if (distance > 15)
			{
				if (bob->GetX() != Follow_Point_X)
				{
					bob->SetX(bob->GetX() - ((bob->GetX() - Follow_Point_X) / distance) * 1.5f);
				}

				if (bob->GetY() != Follow_Point_Y)
				{
					bob->SetY(bob->GetY() - ((bob->GetY() - Follow_Point_Y) / distance) * 1.5f);
				}
			}
			else
				Follow = false;

			timeCheck = SDL_GetTicks();
		}

		csdl_setup->End();
	}
}
开发者ID:CodeThat,项目名称:TankGame,代码行数:94,代码来源:Main.cpp

示例12: input

static void
input()
{
	SDL_PumpEvents();

	vec3_t inputvec = {0,0,0};

	const uint8_t *keyboard = SDL_GetKeyboardState(0);

	if(takeinput)
	{
		if(state_has_controller() && usecontroller)
		{
			inputvec.x = leftstick.x;
			inputvec.z = leftstick.y;
			rotx += JOYSTICK_SENSITIVITY_LOOK*rightstick.x*dt/1000.0;
			roty -= JOYSTICK_SENSITIVITY_LOOK*rightstick.y*dt/1000.0;
		} else {
			if(keyboard[SDL_SCANCODE_W])
				inputvec.z -= 1;
			if(keyboard[SDL_SCANCODE_A])
				inputvec.x -= 1;
			if(keyboard[SDL_SCANCODE_S])
				inputvec.z += 1;
			if(keyboard[SDL_SCANCODE_D])
				inputvec.x += 1;
			if(keyboard[SDL_SCANCODE_LSHIFT])
				inputvec.y -= 1;
			if(keyboard[SDL_SCANCODE_SPACE])
				inputvec.y += 1;

			int mousex, mousey;
			SDL_GetMouseState(&mousex, &mousey);
			state_mouse_center();
			double deltamousex = mousex - windoww/2;
			double deltamousey = mousey - windowh/2;

			rotx += MOUSE_SENSITIVITY*deltamousex;
			roty -= MOUSE_SENSITIVITY*deltamousey;

			roty = roty > M_PI/2-.005 ? M_PI/2-.005 : roty;
			roty = roty < -M_PI/2+.005 ? -M_PI/2+.005 : roty;

			rotx = rotx > M_PI*2 ? rotx - M_PI*2: rotx;
			rotx = rotx < -M_PI*2 ? rotx + M_PI*2: rotx;
		}
	}

	forwardcamera.x = sin(rotx) * cos(roty);
	forwardcamera.y = sin(roty);
	forwardcamera.z = -cos(rotx) * cos(roty);

	vec3_t rotatevec;
	rotatevec.x = cos(rotx)*inputvec.x - sin(rotx)*inputvec.z;
	rotatevec.z = sin(rotx)*inputvec.x + cos(rotx)*inputvec.z;
	rotatevec.y = inputvec.y;

	if(dt < 500)
	{
		if(flying)
		{
			rotatevec.x *= PLAYER_FLY_SPEED * dt / 1000.0;
			rotatevec.y *= PLAYER_FLY_SPEED * dt / 1000.0;
			rotatevec.z *= PLAYER_FLY_SPEED * dt / 1000.0;
			entity_move(pos, &rotatevec);
		} else {
			rotatevec.x *= PLAYER_WALK_MAX_FORCE;
			rotatevec.y = 0;
			rotatevec.z *= PLAYER_WALK_MAX_FORCE;
			entity_update(pos, &rotatevec, dt/1000.0);
		}
	}

	if(keyboard[SDL_SCANCODE_R])
	{
		block_t b;
		b.id = SAND;
		b.metadata.number = SIM_WATER_LEVELS;
		world_ray_set(&headpos, &forwardcamera, b, 1, 1, 1000);
	}
	if(keyboard[SDL_SCANCODE_E])
	{
		world_ray_del(&headpos, &forwardcamera, 1, 1000);
	}
	if(keyboard[SDL_SCANCODE_X])
	{
		vec3_t dir;
		for(dir.x = -1; dir.x < 1; dir.x += .3)
		for(dir.y = -1; dir.y < 0; dir.y += .3)
		for(dir.z = -1; dir.z < 1; dir.z += .3)
			world_ray_del(&headpos, &dir, 1, 50);
	}

	headpos = *posptr;
	headpos.y += PLAYER_EYEHEIGHT;
}
开发者ID:nativeAndroid,项目名称:Blocks,代码行数:96,代码来源:state_game.c

示例13: main

int main(int argc,char*argv[])
{ 	int		row,cyc,cycC,iterc,f1,f2,
	                hei,wid,xmp,ymp,msx,msy;
	Uint8		*p,iter,mouse,tmpmouse;
	double          a,b,c,
			x_p,y_p,
			x_max=10,y_max=10,
			x_min=-10,y_min=-10,
			x_factor,y_factor,
			bri=10,gf=4,c_m=10;
	SDL_Surface    *scr;
	SDL_Event	event;
	char		flag=1;
	struct timespec	time;

	time.tv_sec=0;
	time.tv_nsec=1000000;

	row 	=hei=atoi(*++argv);
	wid 	=atoi(*++argv);
	cycC 	=atoi(*++argv);
	scr 	=SDL_SetVideoMode(hei,wid,24,0);
	SDL_Init(SDL_INIT_VIDEO);
while(1)
{ 	iter=10;
	x_p=hei/(x_max-x_min);
	y_p=wid/(y_max-y_min);
	x_factor=(x_max-x_min)/2;
	y_factor=(y_max-y_min)/2;
	xmp=x_max*x_p;
	ymp=y_max*y_p;

	while(iter--)
	{ 	a=c=1;
		b=iter<<3;
		cyc=cycC;
		iterc=iter/gf;
		while(cyc--){
			EQ1 EQ2 EQ3
			if(a<x_max&&a>x_min&&b<y_max&&b>y_min)
			{ 	f1=ymp-b*y_p;
				f2=xmp-a*x_p;
				p=(Uint8*)scr->pixels+f1*scr->pitch+f2*3;
				if(p[2]<230)
				{	p[2]+=bri;
					p[1]=iterc;
					if(p[0]<230)
						p[0]+=c*c_m;
				}
			}
		}
	}
	SDL_UpdateRect(scr,0,0,scr->w,scr->h);
	flag=1;
	mouse=0;
	while(flag)
	{ 	while(SDL_PollEvent(&event));
		nanosleep(&time,0x0);
		switch(event.type)
		{ 	case SDL_KEYDOWN:
				flag=0;
				switch(event.key.keysym.sym)
				{	case SDLK_SPACE:SDL_Quit();return 0;break;
					case SDLK_j:bri*=1.25;break;
					case SDLK_k:bri/=1.25;break;
					case SDLK_h:c_m*=2;break;
					case SDLK_l:c_m/=2;break;
					case SDLK_o:gf*=1.5;break;
					case SDLK_n:gf/=1.5;break;
					default:flag=1;
				}
				break;	
			case SDL_MOUSEBUTTONDOWN:
				tmpmouse=SDL_GetMouseState(&msx,&msy);
				if(tmpmouse)mouse=tmpmouse;
				break;
			case SDL_MOUSEBUTTONUP:
				if(mouse>0)
				{	if(mouse==2)
					{	x_factor*=2;	y_factor*=2;
						cycC/=2;
						bri/=2;
					}else
					if(mouse==4)
					{	x_factor/=2;	y_factor/=2;
						cycC*=2;
						bri*=2;
					}
					x_min+=(x_max-x_min)*((double)(hei-msx)/(double)hei)-x_factor;
					y_min+=(y_max-y_min)*((double)(wid-msy)/(double)wid)-y_factor;
					x_max=x_min+x_factor*2;y_max=y_min+y_factor*2;
					flag=0;
				}
		}
	}
	SDL_FillRect(scr,0x0,0x0);
	}
}
开发者ID:imclab,项目名称:js1k,代码行数:98,代码来源:SDLtest.slow.c

示例14: SDL_PumpEvents

//
// System platform methods
//
bool System::getPen3() {
  SDL_PumpEvents();
  return (SDL_BUTTON(SDL_BUTTON_LEFT) && SDL_GetMouseState(&_touchCurX, &_touchCurY));
}
开发者ID:MarcusWellby,项目名称:SmallBASIC,代码行数:7,代码来源:runtime.cpp

示例15: SDLGui_DoDialog

/**
 * Show and process a dialog. Returns the button number that has been
 * pressed or SDLGUI_UNKNOWNEVENT if an unsupported event occured (will be
 * stored in parameter pEventOut).
 */
int SDLGui_DoDialog(SGOBJ *dlg, SDL_Event *pEventOut)
{
	int obj=0;
	int oldbutton=0;
	int retbutton=0;
	int i, j, b;
	SDL_Event sdlEvent;
	SDL_Rect rct;
	Uint32 grey;
	SDL_Surface *pBgSurface;
	SDL_Rect dlgrect, bgrect;

	if (pSdlGuiScrn->h / sdlgui_fontheight < dlg[0].h)
	{
		fprintf(stderr, "Screen size too small for dialog!\n");
		return SDLGUI_ERROR;
	}

	grey = SDL_MapRGB(pSdlGuiScrn->format,181,183,170);

	dlgrect.x = dlg[0].x * sdlgui_fontwidth;
 	dlgrect.y = dlg[0].y * sdlgui_fontheight;
 	dlgrect.w = dlg[0].w * sdlgui_fontwidth;
 	dlgrect.h = dlg[0].h * sdlgui_fontheight;

	bgrect.x = bgrect.y = 0;
	bgrect.w = dlgrect.w;
	bgrect.h = dlgrect.h;

	/* Save background */
	pBgSurface = SDL_CreateRGBSurface(SDL_SWSURFACE, dlgrect.w, dlgrect.h, pSdlGuiScrn->format->BitsPerPixel,
	                                  pSdlGuiScrn->format->Rmask, pSdlGuiScrn->format->Gmask, pSdlGuiScrn->format->Bmask, pSdlGuiScrn->format->Amask);
	if (pSdlGuiScrn->format->palette != NULL)
	{
		SDL_SetPaletteColors(pBgSurface->format->palette, pSdlGuiScrn->format->palette->colors, 0, pSdlGuiScrn->format->palette->ncolors-1);
	}

	if (pBgSurface != NULL)
	{
		SDL_BlitSurface(pSdlGuiScrn,  &dlgrect, pBgSurface, &bgrect);
	}
	else
	{
		fprintf(stderr, "SDLGUI_DoDialog: CreateRGBSurface failed: %s\n", SDL_GetError());
	}

	/* (Re-)draw the dialog */
	SDLGui_DrawDialog(dlg);

	/* Is the left mouse button still pressed? Yes -> Handle TOUCHEXIT objects here */
	SDL_PumpEvents();
	b = SDL_GetMouseState(&i, &j);

 	/* If current object is the scrollbar, and mouse is still down, we can scroll it */
 	/* also if the mouse pointer has left the scrollbar */
 	if (dlg[current_object].type == SGSCROLLBAR) {
 		if (b & SDL_BUTTON(1)) {
 			obj = current_object;
 			dlg[obj].state |= SG_MOUSEDOWN;
 			oldbutton = obj;
 			retbutton = obj;
 		}
 		else {
			obj = current_object;
 			current_object = 0;
 			dlg[obj].state &= SG_MOUSEUP;
			retbutton = obj;
            oldbutton = obj;
		}
	}
    else {
 		obj = SDLGui_FindObj(dlg, i, j);
 		current_object = obj;
 		if (obj > 0 && (dlg[obj].flags&SG_TOUCHEXIT) )
 		{
 			oldbutton = obj;
			if (b & SDL_BUTTON(1))
 			{
 				dlg[obj].state |= SG_SELECTED;
 				retbutton = obj;
 			}
 		}
 	}

    
	/* The main loop */
	while (retbutton == 0 && !bQuitProgram)
	{
		if (SDL_WaitEvent(&sdlEvent) == 1)  /* Wait for events */
            
			switch (sdlEvent.type)
			{
			 case SDL_QUIT:
				retbutton = SDLGUI_QUIT;
				break;
//.........这里部分代码省略.........
开发者ID:jsdf,项目名称:previous,代码行数:101,代码来源:sdlgui.c


注:本文中的SDL_GetMouseState函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。