Esempio n. 1
0
void Gui::renderMouseLook() 
{
	auto engine = Engine::getSingleton();
	auto map = engine->getMap();
	auto mouse_pos = Vec2i(engine->getMouse().cx, engine->getMouse().cy);
	if (!map->isInFov(mouse_pos)) 
	{
        // if mouse is out of fov, nothing to render
        return;
    }

	std::string buf;

	bool first=true;
	auto actors = engine->getActors();
	for (unsigned int i = 0; i < actors.size(); i++) 
	{
		auto actor = actors[i];
		// find actors under the mouse cursor
		if (actor->getPosition() == mouse_pos) 
		{
			if(!first)	buf+=", ";
			else		first=false;

			buf += actor->getOwner()->getName();
		}
	}

	// display the list of actors under the mouse cursor
    con->setDefaultForeground(TCODColor::lightGrey);
	con->print(1,0,buf.c_str());
}
Esempio n. 2
0
int mouseInsideRec(Rec* rect){
	if(getMouse()->x >= rect->xi &&
			getMouse()->x <= rect->xf &&
			getMouse()->y >= rect->yi &&
			getMouse()->y <= rect->yf){
  		return 1;
	}
	else
		return 0;
}
Esempio n. 3
0
void			Spider::getTypeInfo(boost::asio::yield_context yield)
{
  for (;;) {
    uint8_t		id = 0;

    _buffer.reset();
    if (_socket->async_read(_buffer.data(), 1, yield)) {
      dieInDignity();
      return ;
    }

    id = _buffer.getValue<uint8_t>();
    switch (id)
    {
    case (Paquet::KEYSTROKES):
      getKeystrokes(yield);
      break ;

    case (Paquet::MOUSE):
      getMouse(yield);
      break ;

    case (Paquet::COMMAND_CLIENT):
      getClientCMD(yield);
      break ;

    default:
      std::cerr << "Wrong data with spider " << _name << std::endl;
      return ;
    }
  }
}
      void Menu::simulate(const float& seconds)
      {
        // inject events to cegui...
        for(std::set<Model::PlayerConfiguration::InputEvent>::const_iterator 
              event = getKeyboard()->getEvents().begin() ;
            event != getKeyboard()->getEvents().end() ;
            ++event)
        {
          
        }
        
        for(std::set<OIS::MouseButtonID>::const_iterator 
              event = getMouse()->getButtonPressed().begin() ;
            event != getMouse()->getButtonPressed().end() ;
            ++event)
        {
          CEGUI::System::getSingleton().injectMouseButtonDown(convertOgreButtonToCegui(*event)) ;
        }

        for(std::set<OIS::MouseButtonID>::const_iterator 
              event = getMouse()->getButtonReleased().begin() ;
            event != getMouse()->getButtonReleased().end() ;
            ++event)
        {
          CEGUI::System::getSingleton().injectMouseButtonUp(convertOgreButtonToCegui(*event)) ;
        }
        
        Kernel::Percentage mouse_x ;
        Kernel::Percentage mouse_y ;
        
        std::map<Model::PlayerConfiguration::InputAxis,
                 Kernel::Percentage>::const_iterator finder ;

        finder = getMouse()->getAxes().find(Model::PlayerConfiguration::InputAxis::mouseAxis(Mouse::X)) ;
        
        if (finder != getMouse()->getAxes().end())
          mouse_x = finder->second ;

        finder = getMouse()->getAxes().find(Model::PlayerConfiguration::InputAxis::mouseAxis(Mouse::Y)) ;
        
        if (finder != getMouse()->getAxes().end())
          mouse_y = finder->second ;
        
        unsigned int width ;
        unsigned int height ;
        unsigned int depth ;
        int left ;        
        int top ;
        
        Display::getWindowSize(width,height,depth,left,top) ;
        CEGUI::Point position(width*(float(mouse_x)+0.5),height*(float(mouse_y)+0.5)) ;
        CEGUI::MouseCursor::getSingleton().setPosition(position) ;
      }
//-----------------------------------------------------------------------------
// pick() -- Perform for select/pick operation; returns the selected (picked)
//           graphic or zero(0) if nothing was selected.
//
// 1) When item == 0, returns nearest (by depth buffer) selected entry.
// 2) When item < 0, returns furthest (by depth buffer) selected entry.
// 3) When item > 0, returns the item'th selected entry or the first entry if
//    there are less than 'item' entries
// 4) Returns zero(0) when there are no entries in the select buffer or if the
//    Graphic for the select ID is not found.
//-----------------------------------------------------------------------------
BasicGL::Graphic* GlutDisplay::pick(const int item)
{
   GLint viewport[4];
   glGetIntegerv(GL_VIEWPORT,viewport);

   // make sure we are starting at 0, 0
   int xm = 0, ym = 0;

   getMouse(&xm,&ym);
   int x = xm;
   int y = viewport[3] - ym;

   glMatrixMode(GL_PROJECTION);
   glPushMatrix();
   glLoadIdentity();
   gluPickMatrix(x, y, getPickWidth(), getPickHeight(), viewport);

   // Get our ortho parameters
   GLdouble oLeft(0), oRight(0), oBottom(0), oTop(0), oNear(0), oFar(0);
   getOrtho(oLeft, oRight, oBottom, oTop, oNear, oFar);

   glOrtho(oLeft, oRight, oBottom, oTop, oNear, oFar);
   glMatrixMode(GL_MODELVIEW);

   if (getDisplayOrientation() != NORMAL) {
      glPushMatrix();
      if (getDisplayOrientation() == CW90)
         glRotated(-90.0, 0.0, 0.0, 1.0);
      else if (getDisplayOrientation() == CCW90)
         glRotated(90.0, 0.0, 0.0, 1.0);
      else
         glRotated(180.0, 0.0, 0.0, 1.0);
   }

   static const unsigned int MAX_BUFF_SIZE = 1024;
   GLuint sbuff[MAX_BUFF_SIZE];
   clearSelectBuffer(sbuff,MAX_BUFF_SIZE);
   glSelectBuffer(MAX_BUFF_SIZE, sbuff);
   glRenderMode(GL_SELECT);

   glInitNames();
   draw();

   GLint hits = glRenderMode(GL_RENDER);

   if (getDisplayOrientation() != NORMAL) glPopMatrix();

   Graphic* selected = findSelected(hits, sbuff, item);

   glMatrixMode(GL_PROJECTION);
   glPopMatrix();
   glMatrixMode(GL_MODELVIEW);

   return selected;
}
Esempio n. 6
0
int main(int argc, char **argv) {
	srand(time(NULL));
	sef_startup();

	Whack* whack = startWhack();
	vg_init(0x114);
	int done = 0; //whack->done;
	//Bitmap* board = loadBitmap("/home/lcom/lcom1415-t3g15/projeto/res/board.bmp");
	//Bitmap* bt = loadBitmap("/home/lcom/lcom1415-t3g15/projeto/res/exit-button.bmp");
	//drawBitmapWithoutBg(board, 0, 0, ALIGN_LEFT);
	//drawBitmapWithoutBg(bt, 200, 120, ALIGN_LEFT);

	//MainMenu* teste = createMainMenu();
	//drawMainMenu(teste);

	//deleteMainMenu(teste);

	/*Game* teste = createGame();
	//OptionsMenu* teste = createOptionsMenu(0, 0);
		drawGame(teste);
	flipMouse();
					drawMouse();
					flipDisplay();

		sleep(10);

	deleteGame(teste);*/

	while (!whack->done) {
		updateWhack(whack);
		if (get_counter(whack->timer) % 4 == 0){
			if (!whack->done && whack->draw) {
				drawWhack(whack);
			}

			if (getMouse()->draw) {
				flipMouse();
				drawMouse();
				flipDisplay();
			}
		}
	}
	stopWhack(whack);


	vg_exit();



	printf("\nTerminated\n");

	return 0;
}
Esempio n. 7
0
    void App::init()
    {
        /* Check if main instance already exists */
        if (App::main_instance_)
        {
            throw Error ("Cannot create multiple apps at once.");
        }

        /* Initialize SDL */
        if (SDL_Init(SDL_INIT_VIDEO) < 0)
        {
            throw Error ("Could not initialize SDL.");
        }

        /* Allow app to modify config */
        Window::Config config;
        onInit(config);

        /* Create new window with config */
        window_ = std::make_unique<Window>(config);

        /* Initialize GLEW with created window context */
        glewExperimental = true;
        if (glewInit() != GLEW_OK)
        {
            throw Error ("Failed to init GLEW.");
        }

        /* Flush errors caused by GLEW */
        while (glGetError());

        /* Initialize controllers */
        keyboard_   = std::make_unique<Keyboard>();
        mouse_      = std::make_unique<Mouse>();

        /* Register SDL event handlers */
        addEventHandler(getWindow());
        addEventHandler(getKeyboard());
        addEventHandler(getMouse());

        scene_ = std::make_unique<Scene>();

        renderer_ = std::make_unique<Renderer>(
                window_->getWidth(),
                window_->getHeight());

        App::main_instance_ = this;
        should_quit_ = false;
        
        onPostInit();
    }
Esempio n. 8
0
int updateOptionsMenu(OptionsMenu* state) {

	if (mouseInsideRect(250, 200, 390, 280)) { //easy
		state->activeChoice = 1;
		if (getMouse()->leftBtnReleased) {
			state->choice = 1;
			state->difficulty = 2.0;
		}
	}
	else if (mouseInsideRect(250, 300, 390, 380)) { //medium
		state->activeChoice = 2;
		if (getMouse()->leftBtnReleased) {
			state->choice = 2;
			state->difficulty = 1.0;
		}
	}
	else if (mouseInsideRect(250, 400, 390, 480)) { //hard
		state->activeChoice = 3;
		if (getMouse()->leftBtnReleased){
			state->choice = 3;
			state->difficulty = 0.5;
		}
	}
	if (mouseInsideRect(400, 200, 540, 280)) { //30
		state->activeChoice = 4;
		if (getMouse()->leftBtnReleased) {
			state->gameTime = 30;
		}
	}
	else if (mouseInsideRect(400, 300, 540, 380)) { //90
		state->activeChoice = 5;
		if (getMouse()->leftBtnReleased) {
			state->gameTime = 90;
		}
	}
	else if (mouseInsideRect(400, 400, 540, 480)) { //120
		state->activeChoice = 6;
		if (getMouse()->leftBtnReleased){
			state->gameTime = 120;
		}
	}
	else if (mouseInsideRect(200, 500, 600, 590)) { //back to main menu
		state->activeChoice = 7;
		if (getMouse()->leftBtnReleased)
			state->choiceExit = 1;
	}
	else
		state->activeChoice = 0;
}
Esempio n. 9
0
File: Main.c Progetto: PTJohe/LCOM
int main(int argc, char *argv[]) {
	initLog();
	LOG("main", "Starting Where's Wally? ...");

	/* Initialize service */
	sef_startup();

	/* Enable IO-sensitive operations for ourselves */
	sys_enable_iop(SELF);

	printf("Starting \"Where's Wally?\" ....\n");

	initGraphics(MODE_1280_1024);

	WallyNIX* wally = (WallyNIX*) startWallyNIX();
	while (!wally->exit) {
		updateWallyNIX(wally);

		if (!wally->exit) {
			if (wally->timerFPS->ticked) {
				wally->timerFPS->ticked = 0;
				drawWallyNIX(wally);

				copyToMouseBuffer();
				if (getMouse()->draw) {
					drawMouse();
				}

				copyToVideoMem();
			}
		}
	}
	stopWallyNIX(wally);

	exitGraphics();

	LOG("main", "Terminated Where's Wally? ...");
	printf("\"Where's Wally?\" exited successfully.\n");

	return EXIT_SUCCESS;
}
Esempio n. 10
0
		virtual void main(const Arguments& argv) throw() override {


			initializeRenderSystem();

			m_mouseAxisDelegate = xdl::XdevLAxisDelegateType::Create<FontTest, &FontTest::mouse_axis_handle>(this);
			getMouse()->registerDelegate(m_mouseAxisDelegate);


			m_buttonDelegate = xdl::XdevLButtonIdDelegateType::Create<FontTest, &FontTest::escape_key_handle>(this);
			getKeyboard()->registerDelegate(STRING("KEY_ESCAPE"), m_buttonDelegate);


			getWindow()->show();
			getWindow()->setInputFocus();


			while(m_appRun) {
				getCore()->update();

				get3DProcessor()->setActiveDepthTest(xdl::xdl_true);
				get3DProcessor()->clearColorTargets(1.0f, 1.0f, 1.0f, 0.0f);
				get3DProcessor()->clearDepthTarget(1.0f);

				m_textEngine->setColor(200, 0, 0, 255);
				m_textEngine->useFont(m_font);
				m_textEngine->printText(L"The quick brown fox jumps over the lazy dog", m_xaxis, m_yaxis);

				m_textEngine->setColor(0, 0, 0, 255);
				m_textEngine->useFont(m_font2);
				m_textEngine->printText(L"The quick brown fox jumps over the lazy dog", 0, 0);

				get3DProcessor()->swapBuffers();
				xdl::sleep(0.002);
			}

		}
Esempio n. 11
0
void ShortcutsPlugin::applyKey(CommandDef *s)
{
    if (s->popup_id){
        const char *cfg = getMouse(s->id);
        if (cfg && *cfg){
            unsigned btn = stringToButton(cfg);
            if (mouseCmds.size() == 0)
                qApp->installEventFilter(this);
            mouseCmds.insert(MAP_CMDS::value_type(btn, *s));
        }
        return;
    }
    const char *cfg = getKey(s->id);
    if (cfg && *cfg){
        oldKeys.insert(MAP_STR::value_type(s->id, s->accel));
        if (strcmp(cfg, "-")){
            s->accel = cfg;
        }else{
            s->accel = NULL;
        }
    }
    cfg = getGlobal(s->id);
    if (cfg && *cfg){
        oldGlobals.insert(MAP_BOOL::value_type(s->id, (s->flags & COMMAND_GLOBAL_ACCEL) != 0));
        if (*cfg == '-'){
            s->flags &= ~COMMAND_GLOBAL_ACCEL;
        }else{
            s->flags |= COMMAND_GLOBAL_ACCEL;
        }
    }
    if (s->accel && (s->flags & COMMAND_GLOBAL_ACCEL)){
        if (globalKeys == NULL)
            globalKeys = new list<GlobalKey*>;
        globalKeys->push_back(new GlobalKey(s));
    }
}
Esempio n. 12
0
int main()
{


    // creates a window and GLES context
    if (makeContext() != 0)
        exit(-1);

    // all the shaders have at least texture unit 0 active so
    // activate it now and leave it active
    glActiveTexture(GL_TEXTURE0);

    flareTex = loadPNG("resources/textures/cloud.png");
	
	
    width = getDisplayWidth();
    height = getDisplayHeight();

    glViewport(0, 0, getDisplayWidth(), getDisplayHeight());

    // initialises glprint's matrix, shader and texture
    initGlPrint(getDisplayWidth(), getDisplayHeight());
    font1=createFont("resources/textures/font.png",0,256,16,16,16);
    initSprite(getDisplayWidth(), getDisplayHeight());
	

    fileid = 0;	
    loadfile();
    for (int i=0; i<max_flares; i++) {
        flares[i].x=rand_range(0,getDisplayWidth());
        flares[i].y=rand_range(0,getDisplayHeight());
        flares[i].vx=rand_range(0,10)-5;
        flares[i].vy=rand_range(0,10)-5;
    }
    /*for (int i=0; i<max_targets; i++) {
        targets[i].x=rand_range(0,getDisplayWidth());
        targets[i].y=rand_range(0,getDisplayHeight());
	targets[i].flares = 0;
    }*/

    /*for (int i=0; i<max_flares; i++) {
        flares[i].x=rand_range(0,getDisplayWidth());
        flares[i].y=rand_range(0,getDisplayHeight());
        flares[i].vx=rand_range(0,10)-5;
        flares[i].vy=rand_range(0,10)-5;
	flares[i].target = (int)rand_range(0,max_targets);
	targets[flares[i].target].flares ++;
    }*/


    // we don't want to draw the back of triangles
    // the blending is set up for glprint but disabled
    // while not in use
    glCullFace(GL_BACK);
    glEnable(GL_CULL_FACE);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    glEnable(GL_BLEND);
    glDisable(GL_DEPTH_TEST);
    glClearColor(0, 0.5, 1, 1);

    // count each frame
    int num_frames = 0;

    // set to true to leave main loop
    bool quit = false;
    
// get a pointer to the key down array
    keys = getKeys();
	int* mouse = getMouse();

    while (!quit) {		// the main loop

        doEvents();	// update mouse and key arrays

        if (keys[KEY_ESC])
            quit = true;	// exit if escape key pressed
        if (keys[KEY_SPACE])
            relocate_targets();	// exit if escape key pressed
        if (keys[KEY_RETURN])
            reassign_flares();	// exit if escape key pressed
        if (keys[KEY_S] && !lastkeys[KEY_S])
            save();	// exit if escape key pressed
        if (keys[KEY_CURSL] && !lastkeys[KEY_CURSL]){
            fileid--;
	    if (fileid <0) fileid = 0;
	    loadfile();	// exit if escape key pressed
	}
        if (keys[KEY_CURSR] && !lastkeys[KEY_CURSR]){
            fileid++;
	    loadfile();	// exit if escape key pressed
	}
        if (keys[KEY_C]){
            max_targets = 1;	// exit if escape key pressed
	    reassign_flares();    
	}
	lastkeys[KEY_S] = keys[KEY_S];
	lastkeys[KEY_CURSL] = keys[KEY_CURSL];
	lastkeys[KEY_CURSR] = keys[KEY_CURSR];
	
	mx = mouse[0];
	my = mouse[1];
	if(mouse[2] != 0){
		spawn_target(mx,my);
	}

	for (int i=0; i<RE_MULTIPLY; i++){
		random_events();
	}
	
	think();
        
        render();	// the render loop

        usleep(1600);	// no need to run cpu/gpu full tilt

    }

    closeContext();		// tidy up

    return 0;
}
Esempio n. 13
0
int window_mouse_get_x()  { return getMouse(2); }
Esempio n. 14
0
int window_mouse_get_y()  { return getMouse(3); }
Esempio n. 15
0
int display_mouse_get_x() { return getMouse(0); }
Esempio n. 16
0
int display_mouse_get_y() { return getMouse(1); }
Esempio n. 17
0
void drawMouse(ChopperDrop* game)
{
	drawBitmap(game->mouseCursor, getMouse()->x, getMouse()->y, ALIGN_LEFT);
	getMouse()->draw = 0;
}
Esempio n. 18
0
void updateChopperDrop(ChopperDrop* game)
{
	int ipc_status;
	message msg;

	resetTickedFlag(game->timer);

	if (driver_receive(ANY, &msg, &ipc_status) != 0)
		return;

	if (is_ipc_notify(ipc_status))
	{
		switch (_ENDPOINT_P(msg.m_source))
		{
		case HARDWARE:
			// Keyboard
			if (msg.NOTIFY_ARG & game->IRQ_SET_KB)
				game->scancode = readFromKBC(0);

			// Timer
			if (msg.NOTIFY_ARG & game->IRQ_SET_TIMER)
				timerHandler(game->timer);

			// Mouse
			if (msg.NOTIFY_ARG & game->IRQ_SET_MOUSE)
				updateMouse();

			// RTC
			if (msg.NOTIFY_ARG & game->IRQ_SET_RTC)
				updateDate(game->date);
			break;
		default:
			break;
		}
	}

	if (game->timer->ticked)
	{
		// Update game states and mouse at 60 FPS

		getMouse()->draw = 1;

		switch(game->currentState)
		{
		case MAIN_MENU_STATE:
			updateMainMenuState(game->state, game->scancode);
			break;
		case GAME_STATE:
			updateGameState(game->state, game->scancode, game->timer->counter);
			break;
		case GAME_OVER_STATE:
			updateGameOverState(game->state, game->scancode);
			break;
		case GAME_WON_STATE:
			updateGameWonState(game->state, game->scancode);
			break;
		default:
			break;
		}

		game->scancode = 0;
		game->draw = 1;
	}

	checkIfStateIsDone(game);
}
Esempio n. 19
0
int main()
{




    lightDir.x=0.5;
    lightDir.y=.7;
    lightDir.z=-0.5;
    kmVec3Normalize(&lightDir,&lightDir);

    // creates a window and GLES context
    if (makeContext() != 0)
        exit(-1);

    // all the shaders have at least texture unit 0 active so
    // activate it now and leave it active
    glActiveTexture(GL_TEXTURE0);

    // The obj shapes and their textures are loaded
    cubeTex = loadPNG("resources/textures/dice.png");
    loadObj(&cubeObj, "resources/models/cube.gbo",
            "resources/shaders/textured.vert", "resources/shaders/textured.frag");


    shipTex = loadPNG("resources/textures/shipv2.png");
    loadObjCopyShader(&shipObj,"resources/models/ship.gbo",&cubeObj);

    alienTex = loadPNG("resources/textures/alien.png");
    loadObjCopyShader(&alienObj, "resources/models/alien.gbo", &cubeObj);

    shotTex = loadPNG("resources/textures/shot.png");
    loadObjCopyShader(&shotObj, "resources/models/shot.gbo", &cubeObj);

    expTex = loadPNG("resources/textures/explosion.png");





    playerPos.x = 0;
    playerPos.y = 0;
    playerPos.z = 0;

    kmMat4Identity(&view);

    pEye.x = 0;
    pEye.y = 2;
    pEye.z = 4;
    pCenter.x = 0;
    pCenter.y = 0;
    pCenter.z = -5;
    pUp.x = 0;
    pUp.y = 1;
    pUp.z = 0;

    kmMat4LookAt(&view, &pEye, &pCenter, &pUp);

    // projection matrix, as distance increases
    // the way the model is drawn is effected
    kmMat4Identity(&projection);
    kmMat4PerspectiveProjection(&projection, 45,
                                (float)getDisplayWidth() / getDisplayHeight(), 0.1, 100);

    glViewport(0, 0, getDisplayWidth(), getDisplayHeight());

    // these two matrices are pre combined for use with each model render
    kmMat4Assign(&vp, &projection);
    kmMat4Multiply(&vp, &vp, &view);

    // initialises glprint's matrix shader and texture
    initGlPrint(getDisplayWidth(), getDisplayHeight());

	font1=createFont("resources/textures/font.png",0,256,16,16,16);
	font2=createFont("resources/textures/bigfont.png",32,512,9.5,32,48);

    glCullFace(GL_BACK);
    glEnable(GL_CULL_FACE);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    glDisable(GL_BLEND);	// only used by glprintf
    glEnable(GL_DEPTH_TEST);

    struct timeval t, ta, t1, t2;	// fps stuff
    gettimeofday(&t1, NULL);
    int num_frames = 0;

    bool quit = false;

    mouse = getMouse();
    keys = getKeys();

    resetAliens();

    for (int n = 0; n < MAX_PLAYER_SHOTS; n++) {
        playerShots[n].alive = false;
    }


    initPointClouds("resources/shaders/particle.vert",
                    "resources/shaders/particle.frag",(float)getDisplayWidth()/24.0);


    for (int n = 0; n < MAX_ALIENS; n++) {
        aliens[n].explosion=createPointCloud(40);
        resetExposion(aliens[n].explosion); // sets initials positions
    }



    while (!quit) {		// the main loop

        doEvents();	// update mouse and key arrays

        // mask of 4 is right mouse
        if (keys[KEY_ESC])
            quit = true;

        glClearColor(0, .5, 1, 1);

        // render between two gettimeofday calls so
        // we can sleep long enough to roughly sync
        // to ~60fps but not on the pi!

        // TODO find something a tad more elegent

        long i;
        gettimeofday(&t, NULL);
        i = t.tv_sec * 1e6 + t.tv_usec;

//        render();
        float rad;		// radians rotation based on frame counter

        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
        frame++;
        rad = frame * (0.0175f * 2);

        kmMat4Identity(&model);
        kmMat4Translation(&model, playerPos.x, playerPos.y, playerPos.z);

        playerCroll +=
            (PIDcal(playerRoll, playerCroll, &playerPre_error, &playerIntegral)
             / 2);
        kmMat4RotationPitchYawRoll(&model, 0, 3.1416, playerCroll * 3);	//

        kmMat4Assign(&mvp, &vp);
        kmMat4Multiply(&mvp, &mvp, &model);

        kmMat4Assign(&mv, &view);
        kmMat4Multiply(&mv, &mv, &model);

        glBindTexture(GL_TEXTURE_2D, shipTex);
        drawObj(&shipObj, &mvp, &mv, lightDir, viewDir);

        glPrintf(50 + sinf(rad) * 16, 240 + cosf(rad) * 16,
                 font2,"frame=%i fps=%3.2f", frame, lfps);

        kmVec3 tmp;

        playerFireCount--;

        if (keys[KEY_LCTRL] && playerFireCount < 0) {

            struct playerShot_t *freeShot;
            freeShot = getFreeShot();
            if (freeShot != 0) {
                playerFireCount = 15;
                freeShot->alive = true;
                kmVec3Assign(&freeShot->pos, &playerPos);
            }
        }

        for (int n = 0; n < MAX_PLAYER_SHOTS; n++) {
            if (playerShots[n].alive) {
                playerShots[n].pos.z -= .08;
                if (playerShots[n].pos.z < -10)
                    playerShots[n].alive = false;

                kmMat4Identity(&model);
                kmMat4Translation(&model, playerShots[n].pos.x,
                                  playerShots[n].pos.y,
                                  playerShots[n].pos.z);
                kmMat4RotationPitchYawRoll(&model, rad * 4, 0,
                                           -rad * 4);

                kmMat4Assign(&mvp, &vp);
                kmMat4Multiply(&mvp, &mvp, &model);

                kmMat4Assign(&mv, &view);
                kmMat4Multiply(&mv, &mv, &model);

                glBindTexture(GL_TEXTURE_2D, shotTex);
                drawObj(&shotObj, &mvp, &mv, lightDir, viewDir);
            }
        }

        playerRoll = 0;
        if (keys[KEY_CURSL] && playerPos.x > -10) {
            playerPos.x -= 0.1;
            playerRoll = .2;
        }
        if (keys[KEY_CURSR] && playerPos.x < 10) {
            playerPos.x += 0.1;
            playerRoll = -.2;
        }
        pEye.x = playerPos.x * 1.25;

        pCenter.x = playerPos.x;
        pCenter.y = playerPos.y + 1;
        pCenter.z = playerPos.z;

        int deadAliens;

        deadAliens = 0;

        for (int n = 0; n < MAX_ALIENS; n++) {
            if (aliens[n].alive == true) {

                kmMat4Identity(&model);
                kmMat4Translation(&model, aliens[n].pos.x,
                                  aliens[n].pos.y, aliens[n].pos.z);
                kmMat4RotationPitchYawRoll(&model, -.4, 0, 0);

                kmMat4Assign(&mvp, &vp);
                kmMat4Multiply(&mvp, &mvp, &model);

                kmMat4Assign(&mv, &view);
                kmMat4Multiply(&mv, &mv, &model);

                glBindTexture(GL_TEXTURE_2D, alienTex);
                drawObj(&alienObj, &mvp, &mv, lightDir, viewDir);

                kmVec3 d;
                for (int i = 0; i < MAX_PLAYER_SHOTS; i++) {
                    kmVec3Subtract(&d, &aliens[n].pos,
                                   &playerShots[i].pos);
                    if (kmVec3Length(&d) < .7
                            && playerShots[i].alive) {
                        aliens[n].alive = false;
                        playerShots[i].alive = false;
                        aliens[n].exploding = true;
                        resetExposion(aliens[n].explosion);
                    }
                }
            } 

            if (aliens[n].alive != true && aliens[n].exploding != true) {
                    deadAliens++;
                
            }
        }

        if (deadAliens == MAX_ALIENS) {
            resetAliens();
        }

		// draw explosions after ALL aliens
        for (int n = 0; n < MAX_ALIENS; n++) {
			if (aliens[n].exploding==true) {
				kmMat4Identity(&model);
				kmMat4Translation(&model, aliens[n].pos.x,
								  aliens[n].pos.y, aliens[n].pos.z);

				kmMat4Assign(&mvp, &vp);
				kmMat4Multiply(&mvp, &mvp, &model);
				glBindTexture(GL_TEXTURE_2D, expTex);
				drawPointCloud(aliens[n].explosion, &mvp);
				aliens[n].explosion->tick=aliens[n].explosion->tick+0.05;
				if (aliens[n].explosion->tick>1.25) {
					aliens[n].exploding=false;                   	
				} else {
					// update the explosion
					
					for (int i=0; i<aliens[n].explosion->totalPoints; i++) {
				
						float t;
						t=aliens[n].explosion->tick;
						if (i>aliens[n].explosion->totalPoints/2) t=t/2.0;
						aliens[n].explosion->pos[i*3]=aliens[n].explosion->vel[i*3] * t;
						aliens[n].explosion->pos[i*3+1]=aliens[n].explosion->vel[i*3+1] * t;
						aliens[n].explosion->pos[i*3+2]=aliens[n].explosion->vel[i*3+2] * t;
				
					}
				}
			}
		}

        // move camera
        kmMat4LookAt(&view, &pEye, &pCenter, &pUp);

        kmMat4Assign(&vp, &projection);
        kmMat4Multiply(&vp, &vp, &view);

        kmVec3Subtract(&viewDir,&pEye,&pCenter);
        kmVec3Normalize(&viewDir,&viewDir);

        // dump values
        glPrintf(100, 280, font1,"eye    %3.2f %3.2f %3.2f ", pEye.x, pEye.y, pEye.z);
        glPrintf(100, 296, font1,"centre %3.2f %3.2f %3.2f ", pCenter.x, pCenter.y,
                 pCenter.z);
        glPrintf(100, 320, font1,"mouse %i,%i %i ", mouse[0], mouse[1], mouse[2]);
        glPrintf(100, 340, font1,"frame %i %i ", frame, frame % 20);



        swapBuffers();

        gettimeofday(&ta, NULL);
        long j = (ta.tv_sec * 1e6 + ta.tv_usec);

        i = j - i;
        if (i < 0)
            i = 1000000;	// pass through - slower that 60fps
        if (i < 16000)
            usleep(16000 - i);

        // every 10 frames average the time taken and store
        // fps value for later printing with glprintf
        if (++num_frames % 10 == 0) {
            gettimeofday(&t2, NULL);
            float dtf =
                t2.tv_sec - t1.tv_sec + (t2.tv_usec -
                                         t1.tv_usec) * 1e-6;
            lfps = num_frames / dtf;
            num_frames = 0;
            t1 = t2;
        }
    }

    closeContext();

    return 0;
}
Esempio n. 20
0
/*********************************************
		per-frame logic goes here
**********************************************/
void App::updateMain(){

	//Get the mouse pointer pos in screen space
	SDL_GetMouseState(&iMouseX, &iMouseY); 
	
	//Throw away any bad frames
	if(fTimeScale == infinity || fTimeScale == 0.0f){
		return;
	}
	
	float fCamSpeed = fTimeScale * 10.0f;
	float fDragScale = 0.05f;

	if (!this->bGlobalDisableKeyMovement) {

		//Right button means we reset rotation and such
		//NOTE: I did have this as 'both left and right at once', which seemed
		//to make more sense, but it doesn't work great on systems that map this
		//to middle-mouse		
		if(mouseDown(3)){
			resetCam();
		}

		//Rotation for the wall
		/*
		float camTime = fUptime * 0.1f;

		float fRotateSpeed = fCamSpeed;
		fRot[1] += fRotateSpeed;
		fRot[0] = (sinf(camTime) * 5);
		fCameraY = cosf(camTime) * 5;
		
		fZoom = (sinf(camTime) * 15) + 27;
		*/
			
		//LOG("%f, %f\n", fRot[1], fZoom);
		
		//fZoom = -10;
		
		//Keyboard rotation
		if(keyDown(SDLK_RSHIFT) || keyDown(SDLK_LSHIFT)){
			fCamSpeed *= 10;
		}
		
		if(keyDown(SDLK_LEFT))	fRot[1] -= fCamSpeed;
		if(keyDown(SDLK_RIGHT))	fRot[1] += fCamSpeed;
		if(keyDown(SDLK_UP))	fRot[0] -= fCamSpeed;
		if(keyDown(SDLK_DOWN))	fRot[0] += fCamSpeed;

		if(keyDown(SDLK_w)) {
			fCameraZ -= fCamSpeed; 
			//fRot[0] = 0.0; fRot[1] = 0.0; fRot[2] = 0.0;
			fLookZ -= fCamSpeed;
		}
		
		if(keyDown(SDLK_s)) {
			fCameraZ += fCamSpeed; 
			//fRot[0] = 0.0; fRot[1] = 0.0; fRot[2] = 0.0;
			fLookZ += fCamSpeed;
		}
		if(keyDown(SDLK_a)) {
			fCameraX -= fCamSpeed;
			fLookX -= fCamSpeed;
		}
		if(keyDown(SDLK_d)) {
			fCameraX += fCamSpeed;
			fLookX += fCamSpeed;
		}
		
		if(keyDown(SDLK_SPACE))	resetCam();
		
		//If we're actively dragging with the mouse
		if(bDrag){
			
			//Figure out the drag vectors and stuff
			Vector2 drag = getMouse();
			Vector2 diff = (dragStart - drag) * fDragScale;
					
			//Left mouse button means we modify the rotation
			if(mouseDown(1)){
				fRot[1] -= diff.x;
				fRot[0] -= diff.y;			
			}
			
			//Middle mouse means we modify the zoom
			else if(mouseDown(2)){
				fZoom += diff.y;
			}
			
			dragVel = diff;
			dragStart = getMouse();
			
			
			
		}else{
			//fRot[1] -= dragVel.x;
			//fRot[0] -= dragVel.y;
		}
	}	

	updateSocket();
	
	//Hack! The shader system doesn't really play nice with the banner, so
	//we disable it here.
	if(!isConnected()){
		if(ps()->getType() <= PARTICLE_SYSTEM_POINTSPRITES)
			generateTestData();
		else
			fGUITimeout = 1.0f;
	}
	
	mParticleSystem->update();	
}
Esempio n. 21
0
/*********************************************
		Camera rotate
**********************************************/
void App::beginDrag(){
	dragStart = getMouse();
	bDrag = true;
}