示例#1
0
void idle(){ // idle method for opengl
	calculateFPS(); 
	particleSolve();
	//bhSolve();
	glutPostRedisplay(); // calls a redisplay for opengl

}
示例#2
0
void AVDirector::RunApplication(float fCullValue, HINSTANCE hIns, HWND parentHandle, bool isChild, AVRECT &windowRect, wchar_t *application)
{

	m_Application = new AVWinD3D((WNDPROC)AVDirector::WndProc, hIns, windowRect, parentHandle, application, isChild);
	m_Application->InitWinD3D(application, true, true, D3DCULL_CCW);

	MSG msg;
	ZeroMemory( &msg, sizeof( msg ) );

	_initMatrix(fCullValue);
	_initLight();
	SetFog(fCullValue - 100.f, fCullValue - 50.f);

	if(m_Application->isChild())
		return;

	while( msg.message != WM_QUIT )
	{
		if( PeekMessage( &msg, NULL, 0U, 0U, PM_REMOVE ) )
		{
			TranslateMessage( &msg );
			DispatchMessage( &msg );
		}
		else
		{
			RunToInnerSystem();
			tickTime();

			if(m_bIsFrameCheck)
				calculateFPS();
		}
	}
}
示例#3
0
void  MainGame::gameLoop()
{

	while (_gameState != GameState::EXIT)
	{
		//frame time measure
		float startTicks = SDL_GetTicks();
		processInput();

		_camera.update();
		drawGame();

		_time += 0.1f;
		calculateFPS();
		//print olny once every 10 frames
		static int frameCounter = 0;
		if (frameCounter == 10)
		{
			std::cout << _fps << std::endl;
			frameCounter = 0;
		}
		frameCounter++;

		float frameTicks = SDL_GetTicks() - startTicks;
		//limiting fps 
		if (1000.0f/_maxFPS >frameTicks)
		{
			SDL_Delay((1000.0f/_maxFPS)-frameTicks);
		}
	}

};
示例#4
0
void display()
{

  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
  glLoadIdentity();
  gluLookAt(0, 0, 20 + zoomValue, 0, 0, 0, 0, 1, 0);

  // multiply current matrix with arcball matrix
  glMultMatrixf( arcball.get() );

  GLUquadric *sphere = gluNewQuadric(); 
  glPolygonMode( GL_FRONT_AND_BACK, GL_FILL );
   calculateFPS();
  _time_inter = diff_seconds();
  animateObject(); 
  //draw_sun();
    if (mode==0) {
      moebius();
      glutPostRedisplay();
    }
    else {
      glCallList(MOEBIUS);
      glutPostRedisplay();
    }
 
  drawFPS();
  glutPostRedisplay(); 
  glutSwapBuffers();
}
    void Core::loop() {
        
        
        while (_isRunning) {
            
            _frameStartTime = _timer.now();
           //
            float dt = _timer.timeSinceLast();

            _inputProcessor->process();
            if (_inputManager->isPressed(KeyCode::QUIT)) {
                quit();
            } else {
                update(dt);
            }
            _entityManager->update();
            _entityManager->getSystemManager()->update(dt);
            draw(dt);
            
            calculateFPS(dt);
            
            //limitFPS();
            
        }
    }
示例#6
0
//This is the main game loop for our program
void MainGame::gameLoop() {

    //Will loop until we set _gameState to EXIT
    while (_gameState != GameState::EXIT) {
        //Used for frame time measuring
        float startTicks = SDL_GetTicks(); 

        processInput();
        _time += 0.01;

        _camera.update();

        drawGame();
        calculateFPS();

        //print only once every 10 frames
        static int frameCounter = 0;
        frameCounter++;
        if (frameCounter == 10) {
            std::cout << _fps << std::endl;
            frameCounter = 0;
        }

        float frameTicks = SDL_GetTicks() - startTicks;
        //Limit the FPS to the max FPS
        if (1000.0f / _maxFPS > frameTicks) {
            SDL_Delay((Uint32)(1000.0f / _maxFPS - frameTicks));
        }
    }
}
void displayd(void)
{
    glClear (GL_COLOR_BUFFER_BIT);

    glRectf (-25.0, -25.0, 25.0, 25.0);
	calculateFPS();
    glutSwapBuffers ();
}
示例#8
0
void gameloop(MemCardView* view) {
	while (true) {
		if (!get_input()) break;
		update(view);
		draw(view);
		calculateFPS();
	}
}
示例#9
0
	float Timing::end() {
		calculateFPS();

		float frameTicks = SDL_GetTicks() - _startTicks;
		if (1000.0f / _maxFPS > frameTicks) {
			SDL_Delay((Uint32)(1000.0f / _maxFPS - frameTicks));
		}

		return _fps;
	}
示例#10
0
文件: Timing.cpp 项目: Kirbk/STMC
	float FpsLimiter::end() {
		calculateFPS();

		float frameTicks = SDL_GetTicks() - _startTicks;

		if (1000.0f / _maxFps > frameTicks) {
			SDL_Delay(1000.0f / _maxFps - frameTicks);
		}

		return _fps;
	}
示例#11
0
    float FPSLimiter::end() {
      calculateFPS();
      // Limit FPS to max FPS
      // Vsync should do this for us
  /*  float frameTicks = SDL_GetTicks() - _startTicks;
      if(1000.0f / _maxFPS > frameTicks) {
        SDL_Delay((Uint32)(1000.0f / _maxFPS - frameTicks));
      } */

      return _fps;
    }
示例#12
0
	float FpsLimiter::end()
	{
		calculateFPS();
		float frameTicks = SDL_GetTicks() - _startTicks;
		//Limit the FPS to the max FPS
		if (1000.0f / _maxFPS > frameTicks)
		{
			SDL_Delay(1000.0f / _maxFPS - frameTicks);
		}
		return _fps;
	}
示例#13
0
	void FpsLimiter::end()
	{
		calculateFPS();
		//Limit the FPS:
		float frameTicks = SDL_GetTicks() - _startTicks;
		if (1000.0f /*millisec*/ / _maxFPS > frameTicks)
		{
			//wait a little longer, delay the programs execution
			SDL_Delay(1000.0f / _maxFPS - frameTicks);//some windows does not accept a minimum number to delay programs
		}
	}
示例#14
0
文件: FPS.cpp 项目: AM1244/Blog
//-------------------------------------------------------------------------
//  This function is called when OpenGL\GLUT is not working on 
//  something else... It is mainly used for animation... 
//
//  It's like the timers but time intervals are dependent on how busy
//  the app is, instead of having a constant value set by the user.
//-------------------------------------------------------------------------
void idle (void)
{
    //  Animate the object
    animateObject();

    //  Calculate FPS
    calculateFPS();

    //  Call display function (draw the current frame)
    glutPostRedisplay ();
}
示例#15
0
// Return the current FPS
float FpsLimiter::endFrame() {
    calculateFPS();

    float frameTicks = SDL_GetTicks() - m_startTicks;
    // Limit the FPS to max FPS
    if (1000.0f / m_maxFPS > frameTicks) {
        SDL_Delay((1000.0f / m_maxFPS) - frameTicks);
    }

    return m_fps;

}
示例#16
0
    // end will return current FPS
    float FPSLimiter::end() {

        calculateFPS();

        float frameTicks = SDL_GetTicks() - m_startTicks;
        // limit FPS to maxFPS
        if (1000.0f/m_maxFPS > frameTicks) {
            SDL_Delay(1000.0f/m_maxFPS - frameTicks);
        }

        return m_fps;
    }
示例#17
0
	//will return current FPS
	float FpsLimiter::end()
	{
		calculateFPS();
		//print only once every 10 frames
		float frameTicks = SDL_GetTicks() - _startTicks;
		//Limit the FPS to the max FPS
		if (1000.f / _maxFPS > frameTicks)
		{
			SDL_Delay(1000.f / _maxFPS - frameTicks);

		}
		return _fps;
	}
示例#18
0
////////////////////////////////////////////////////////////////////////////////
//! Idle
////////////////////////////////////////////////////////////////////////////////
void idle(void){
	
	/*if(frameNum == 100){
        deleteVBOs( vbo_pos );
		FreeVariables();
		exit(0);
	}*/
	// Calculate FPS
	calculateFPS();

	glutPostRedisplay ();


}
示例#19
0
 float FpsLimiter::end()
 {
     
     calculateFPS();
     
     float frameticks = SDL_GetTicks() - m_startTicks;
     //Limit the FPS:
     if(1000.0f / m_MaxFPS > frameticks)
     {
         SDL_Delay(1000.0f / m_MaxFPS - frameticks);
     }
     
     return m_Fps;
 }
示例#20
0
void Engine::drawObjects()
{
	checkKeys();
	interaction();

	camera->lookAt(player->GetX(), player->GetY(), player->GetZ());
			
	drawAxes();
	player->draw();
			
	for(int i = 0; i < 3; i++) { surface[i]->draw(); }

	calculateFPS();
	interf->draw();
}
    void BasicRenderer::frame()
    {
        static bool timerStarted = false;

        if(!timerStarted)
        {
            m_timer.start();
            timerStarted = true;
        }

        handleInput();
        m_timer.perFrame();
        calculateFPS();
        updateScene();
        render();
    }
示例#22
0
	void Application::run()
	{
	    while(mWindow.isOpen()) {
	        handleEvents();
	        mWindow.clear();

	        mGame.update(mGameClock.getElapsedTime().asSeconds());

	        mGame.moveObserver(mObserverSpeedX*mGameClock.getElapsedTime().asSeconds(), mObserverSpeedY*mGameClock.getElapsedTime().asSeconds());
	        mGameClock.restart();

	        mWindow.pushGLStates();
	       	mGame.draw(mRenderer);
	       	mWindow.popGLStates();

	        mWindow.display();

	        calculateFPS();
	    }
	}
示例#23
0
void Engine::paint()
{	
	 // std::cout << "PAINT" << std::endl;

	_program->bind();

	_program->enableAttributeArray(0);

	float values[] = {
        -1, -1,
        1, -1,
        -1, 1,
        1, 1
	};
	_program->setAttributeArray(0, GL_FLOAT, values, 2);
	

	_program->setUniformValue("t", (float)t);
	t = t +0.01;
	if(t > 1.0) t = 0;
	glViewport(0, 0, window()->width(), window()->height());

	glDisable(GL_DEPTH_TEST);

	glClearColor(0, 0, 0, 1);
	glClear(GL_COLOR_BUFFER_BIT);

	glEnable(GL_BLEND);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE);

	glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);

	_program->disableAttributeArray(0);
	_program->release();
	
	calculateFPS();
	_window->update();
	// std::cout << "PAINT2" << std::endl;
}
示例#24
0
void wyDirector::drawFrame() {
	// process auto release pool
	wyClearAutoReleasePool();

	// check frame rate setting, but neglect it if in screenshot mode
#ifndef WY_CFLAG_SCREENSHOT_MODE
	if(m_maxFrameRate > 0) {
		int64_t now = wyUtils::currentTimeMillis();
		m_savedDelta += now - m_lastFrameTime;
		m_lastFrameTime = now;
		if(m_savedDelta < m_minFrameInterval) {
			// sleep to save power
			usleep((m_minFrameInterval - m_savedDelta) * 1000);

			// recalculate saved delta
			now = wyUtils::currentTimeMillis();
			m_savedDelta += now - m_lastFrameTime;
			m_lastFrameTime = now;
			m_savedDelta %= m_minFrameInterval;
		} else {
			m_savedDelta %= m_minFrameInterval;
		}
	}
#endif

	// need check texture?
	if(m_needCheckTexture) {
		gTextureManager->invalidateAllTextures();
		m_needCheckTexture = false;
	}

	// set default state
	glDisableClientState(GL_VERTEX_ARRAY);
	glDisableClientState(GL_COLOR_ARRAY);
	glDisableClientState(GL_TEXTURE_COORD_ARRAY);
	glDisable(GL_TEXTURE_2D);

	// if we have next scene to set, reset delta time
	if(!m_UIPaused) {
		if(m_nextScene != NULL) {
			m_nextDeltaTimeZero = true;
		}
	}

	// calculate global delta
	calculateDeltaTime();

	// if in screenshot mode, use 60fps always
#ifdef WY_CFLAG_SCREENSHOT_MODE
	m_delta = 1.f / 60.f;
#endif

	if (!m_UIPaused) {
		// update scheduler and actions
		if(!m_paused) {
			gScheduler->tickLocked(m_delta * m_tickFactor);
		}

		// to avoid flicker, nextScene MUST be here: after tick and before draw
		if(m_nextScene != NULL) {
			gotoNextScene();
		}
	}

	if(!m_paused) {
		// draw the scene
		if(m_runningScene != NULL) {
			glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
			m_runningScene->visit();
		}

		/*
		 * can't move action tick before visit running scene. sometimes the internal
		 * state may not consistent because scheduler already updated before visit.
		 * an example is: move a particle system with an action, can see particle system
		 * shaked consistently.
		 */
        if(!m_UIPaused)
        	gActionManager->tick(m_delta * m_tickFactor);

#ifndef WY_CFLAG_SCREENSHOT_MODE
        // calcuate fps or not
		// but don't calculate fps if in screenshot mode
        if(m_calculateFPS)
        	calculateFPS();

		// show fps or not
		// but don't show fps if in screenshot mode
		if(m_displayFPS)
			showFPS();

		// make screenshot
		if(m_makeScreenshot) {
			m_makeScreenshot = false;

			// make screenshot
			wyUtils::makeScreenshot(m_screenshotPath, m_screenshotRect);

            // notify
			notifyDirectorScreenCaptured();
            
			// free path
			wyFree((void*)m_screenshotPath);
			m_screenshotPath = NULL;
		}
#endif // #ifndef WY_CFLAG_SCREENSHOT_MODE
	}

	// make screenshot
#ifdef WY_CFLAG_SCREENSHOT_MODE
    char fsPath[128];
    sprintf(fsPath, "/sdcard/WiEngine/%06d.png", sScreenshotFrameIndex++);
    const char* path = wyUtils::mapLocalPath(fsPath);
	wyUtils::makeScreenshot(path);
	wyFree((void*)path);
#endif // #ifdef WY_CFLAG_SCREENSHOT_MODE

	// process events
	gEventDispatcher->processEventsLocked();
}
示例#25
0
void GlslPainter::paint(QPainter *painter,
                        QRectF target,
                        QQuickWindow *window)
{
    // Need to reenable those after native painting has begun, otherwise we might
    // not be able to paint anything.
    bool stencilTestEnabled = glIsEnabled(GL_STENCIL_TEST);
    bool scissorTestEnabled = glIsEnabled(GL_SCISSOR_TEST);

    painter->beginNativePainting();

    if (stencilTestEnabled)
        glEnable(GL_STENCIL_TEST);
    if (scissorTestEnabled)
        glEnable(GL_SCISSOR_TEST);

    //////////////////////////////////////////////////////////////
    initTextures();
    //////////////////////////////////////////////////////////////

    // As seen on the telly
#ifdef __GNUC__
#warning DUPLICATED CODE
#endif

    const float textureCoordinates[] = {
        0, 1, // bottom left
        1, 1, // bottom right
        0, 0, // top left
        1, 0, // top right
    };

    const GLfloat targetVertex[] =
    {
        GLfloat(target.left()), GLfloat(target.bottom()),
        GLfloat(target.right()), GLfloat(target.bottom()),
        GLfloat(target.left()) , GLfloat(target.top()),
        GLfloat(target.right()), GLfloat(target.top())
    };
    //

    const int width = window->width();
    const int height = window->height();

    const QTransform transform = painter->deviceTransform();

    const GLfloat wfactor = 2.0 / width;
    const GLfloat hfactor = -2.0 / height;

    const GLfloat positionMatrix[4][4] = {
        {
            GLfloat(wfactor * transform.m11() - transform.m13()),
            GLfloat(hfactor * transform.m12() + transform.m13()),
            0.0,
            GLfloat(transform.m13())
        }, {
            GLfloat(wfactor * transform.m21() - transform.m23()),
            GLfloat(hfactor * transform.m22() + transform.m23()),
            0.0,
            GLfloat(transform.m23())
        }, {
            0.0,
            0.0,
            -1.0,
            0.0
        }, {
            GLfloat(wfactor * transform.dx() - transform.m33()),
            GLfloat(hfactor * transform.dy() + transform.m33()),
            0.0,
            GLfloat(transform.m33())
        }
    };

    _program->bind();

    _program->enableAttributeArray("targetVertex");
    _program->enableAttributeArray("textureCoordinates");
    _program->setAttributeArray("targetVertex", targetVertex, 2);
    _program->setAttributeArray("textureCoordinates", textureCoordinates, 2);
    _program->setUniformValue("positionMatrix", positionMatrix);

    if (_textureCount == 3) {
        glActiveTexture(GL_TEXTURE0);
        glBindTexture(GL_TEXTURE_2D, _textureIds[0]);
        glActiveTexture(GL_TEXTURE1);
        glBindTexture(GL_TEXTURE_2D, _textureIds[1]);
        glActiveTexture(GL_TEXTURE2);
        glBindTexture(GL_TEXTURE_2D, _textureIds[2]);
        glActiveTexture(GL_TEXTURE0);

        _program->setUniformValue("texY", 0);
        _program->setUniformValue("texU", 1);
        _program->setUniformValue("texV", 2);
    }
    _program->setUniformValue("colorMatrix", _colorMatrix);
    _program->setUniformValue("opacity", GLfloat(painter->opacity()));

    glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);

    _program->release();
    painter->endNativePainting();

#if !defined(Q_OS_WIN)
    // TODO: FPS optional
    calculateFPS();
    addFPSOverlay();
#endif
}
示例#26
0
文件: main.cpp 项目: AlphaO/Starfox
// Called when the window needs to be redrawn.
void callbackDisplay()
{
	handleKeyDown();
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	g_camera.update();
	g_shipCamera.update();

	GLuint fogFlag = glGetUniformLocation(g_program, "fogFlag");
	glUniform1i(fogFlag, 1);


	
	g_vessel->updateMovement();
	// Update movement of speed lines
	for (int i = 0; i < SPEED_LINE_COUNT; ++i) {
		if (speedLine[i]->m_position.z > 5.0f) {
			speedLine[i]->resetTranslation();
			speedLine[i]->resetPosition();
		}
		speedLine[i]->resetRotation();
		speedLine[i]->rotate(g_vessel->m_qRotation);
		vec3 linet = g_vessel->m_qRotation * vec3(0.0, 0.0, SPEED_LINE_SPEED);
		speedLine[i]->translate(linet.x, linet.y, linet.z);
	}	

	g_music->checkLoopTimer("starfox_theme.wav", MUSICGAIN);
	
	lightEffects le;
	le.numLights = LIGHTSOURCECOUNT + g_numLasers;
	le.ambientProducts = new vec4[le.numLights];//(vec4*)malloc(sizeof(vec4) * le.numLights);
	le.diffuseProducts = new vec4[le.numLights];//(vec4*)malloc(sizeof(vec4) * le.numLights);
	le.specularProducts = new vec4[le.numLights];//(vec4*)malloc(sizeof(vec4) * le.numLights);
	le.lightPositions = new vec4[le.numLights];//(vec4*)malloc(sizeof(vec4) * le.numLights);
	le.attenuations = new float[le.numLights];//(float*)malloc(sizeof(float) * le.numLights);
	 
	g_light = new Light[le.numLights];//(Light*)malloc(sizeof(Light) * le.numLights);

	g_light[0].m_position = vec3(0.0, 0.0, 0.0);
	g_light[0].m_lightAmbient = vec4(1.0, 1.0, 1.0, 1.0);
	g_light[0].m_lightDiffuse = vec4(1.0, 1.0, 1.0, 1.0);
	g_light[0].m_lightSpecular = vec4(1.0, 1.0, 1.0, 1.0);
	g_light[0].m_attenuation = 0.0000005;

	//g_light[1].m_position = tempShip->m_position;
	//g_light[1].m_lightAmbient = vec4(0.0, 0.0, 0.0, 1.0);
	//g_light[1].m_lightDiffuse = vec4(0.0, 0.6, 0.0, 1.0);
	//g_light[1].m_lightSpecular = vec4(0.0, 1.5, 0.0, 1.0);
	//g_light[1].m_attenuation = 0.0001;


	GLuint fogColor = glGetUniformLocation(g_program, "uFogColor");
	GLuint fogMinDist = glGetUniformLocation(g_program, "uFogMinDist");
	GLuint fogMaxDist = glGetUniformLocation(g_program, "uFogMaxDist");
	glUniform1f(fogMinDist, 1500.0f);
	glUniform1f(fogMaxDist, 1700.0f);
	glUniform4fv(fogColor, 1, vec4(0.0, 0.0, 0.0, 0.0));

	//tempShip->draw(g_drawType, g_camera, g_light, le);
	//tempShip->translate(-g_bulletV.x, -g_bulletV.y, -g_bulletV.z);

	int lightIndex = 1;
	for (int i = 0; i < MAX_LASERS; ++i) {
		if (g_lasers[i]->m_active) {
			g_light[lightIndex].m_position = g_lasers[i]->m_position;
			g_light[lightIndex].m_lightAmbient = vec4(0.0, 0.0, 0.0, 1.0);
			g_light[lightIndex].m_lightDiffuse = vec4(0.0, 0.6, 0.0, 1.0);
			g_light[lightIndex].m_lightSpecular = vec4(0.0, 1.5, 0.0, 1.0);
			g_light[lightIndex].m_attenuation = 0.001;
			++lightIndex;
			if (g_lasers[i]->dead()) {
				--g_numLasers;
				g_lasers[i]->kill();
			}
		}
	}

	for (int i = 0; i < MAX_LASERS; ++i) {
		if ((!g_lasers[i]->dead()) && g_lasers[i]->m_active) {
			g_lasers[i]->draw(g_drawType, g_camera, g_light, le);
			g_lasers[i]->laser_update();
		}
	}

	greenStar->draw(g_drawType, g_camera, g_light, le);
	if (g_vessel->m_shape->checkCollision(greenStar->m_shape)) {
		g_vessel->shake();
	}

	// Draw mama asteroid
	//gMamaAsteroid->draw(g_drawType, g_camera, g_light, le);
	//if (g_vessel->m_shape->checkCollision(gMamaAsteroid->m_shape)) {
	//	g_sound->playSound("ship_asteriod_impact.wav", 1.0, 1);
	//	std::cout << "BOOP3" << glutGet(GLUT_ELAPSED_TIME) <<  std::endl;
	//	g_vessel->shake();d
	//}

	// Draw all bloop asteroids
	for (int i = 0; i < BLOOPCOUNT; ++i) {
		if (asteroidAlive[i]) {
			bloop[i]->rotate(*(q[i % NUM_ASTEROID_ROTATIONS]));
			bloop[i]->draw(g_drawType, g_camera, g_light, le);
			if (g_vessel->m_shape->checkCollision(bloop[i]->m_shape)) {
				g_sound->playSound("ship_asteriod_impact.wav", 1.0, 1000);
				//asteroidAlive[i] = false;
				g_vessel->shake();
			}
			for (int j = 0; j < MAX_LASERS; ++j) {
				if (g_lasers[j]->m_active) {
					if (bloop[i]->m_shape->checkCollision(g_lasers[j]->m_shape)) {
						if (g_explosionIndex == 5)
							g_explosionIndex = 0;
						g_exp[g_explosionIndex]->playSound("ship_asteriod_impact.wav", 1.0, 500);
						//g_lasers[j]->kill();
						++g_explosionIndex;
						if (g_partExplodeIndex == MAXEXPLOSIONCOUNT)
							g_partExplodeIndex = 0;
						//g_explosion[g_partExplodeIndex]->getEngine()->createNewInstance(bloop[i]->m_position.x, bloop[i]->m_position.y, bloop[i]->m_position.z);
						//g_explosion[g_partExplodeIndex]->getEngine()->createNewInstance(2.0*bloop[i]->m_position.x, 1.155*-bloop[i]->m_position.y, 1.11*bloop[i]->m_position.z);
						g_explosion[g_partExplodeIndex]->getEngine()->createNewInstance(g_lasers[j]->m_position.x, -g_lasers[j]->m_position.y, g_lasers[j]->m_position.z);
						//g_explosion[g_partExplodeIndex]->getEngine()->createNewInstance(0.0, 0.0, -20.0);
						asteroidAlive[i] = false;
						g_partExplodeIndex++;
						g_score += 20;
					}	
				}
			}
		}
	}

	// Draw speed lines
	for (int i = 0; i < SPEED_LINE_COUNT; ++i) {
		speedLine[i]->draw(g_shipCamera, g_light, le);
	}
	glUniform1i(fogFlag, 0);
	starField->resetRotation();
	starField->rotate(g_camera.m_qRotation);
	starField->draw(g_drawType, g_shipCamera, g_light, le);
	glUniform1i(fogFlag, 1);

	// Draw the thrusters
	

	for (int i = 0; i < MAXEXPLOSIONCOUNT; i++) {
		g_explosion[i]->drawScene(&g_shipCamera,g_vessel->m_position);
	}

	vec3 pos = g_camera.m_position - g_camera.m_zAxis * 12.0f - g_camera.m_yAxis * 2.0f;
	//vec4 pos2 = Translate(0.0f, 1.0 * g_vessel->getVelocity().y / g_vessel->MAX_VELOCITY_Y, 0.0f) * pos;
	//pos = vec3(pos2.x, pos2.y, pos2.z);
	vec3 a = Quaternion(vec3(0.0f, -1.0f, 0.0f), 40.0f * (g_vessel->getVelocity().x / g_vessel->MAX_VELOCITY)) * vec3(0.0, 0.0, 1.0);
	vec3 b = Quaternion(vec3(1.0f, 0.0f, 0.0f), 50.0f * (g_vessel->getVelocity().y / g_vessel->MAX_VELOCITY_Y)) * vec3(0.0, 0.0, 1.0);
	vec4 ab = normalize(vec4(a.x + b.x, a.y + b.y, a.z + b.z, 0.0));
	vec3 ab1 = vec3(ab.x, ab.y, ab.z);
	if (g_shipAlive == 1) {
		xhair1->setPosition(-10 * (ab1));
		xhair2->setPosition(-100 * (ab1));
		glDisable(GL_DEPTH_TEST);
		xhair1->draw(MESH, g_shipCamera, g_light, le);
		xhair2->draw(MESH, g_shipCamera, g_light, le);
		glEnable(GL_DEPTH_TEST);
	}
	if (g_shipAlive == 1) {
		g_vessel->draw(g_drawType, g_shipCamera, g_light, le);
		thruster->drawScene(&g_shipCamera,g_vessel->m_position);
	}
	

	if (g_debug && g_shipAlive == 1) {
		glDisable(GL_DEPTH_TEST);
		g_menu->draw(g_drawType, g_shipCamera, g_light, le);
		debugDisplay();
		glEnable(GL_DEPTH_TEST);
	}

	glDisable(GL_DEPTH_TEST);
	g_shipExplosion->drawScene(&g_shipCamera,g_vessel->m_position);
	if (g_vessel->m_health == 10) {
		vec3 ff = vec3(10.4 * g_vessel->getVelocity().x / g_vessel->MAX_VELOCITY,0.0f, 0.0f);
		g_shipExplosion->getEngine()->createNewInstance(-ff.x, 10.0, -50.0);
		//g_vessel->shake();
	}
	glEnable(GL_DEPTH_TEST);

	if (g_vessel->m_health == 0) {
		g_shipAlive = 0;
	}

	delete [] le.ambientProducts;
	delete [] le.diffuseProducts;
	delete [] le.specularProducts;
	delete [] le.lightPositions;
	delete [] le.attenuations;
	delete [] g_light;

	std::cout << g_vessel->m_health << std::endl;
	calculateFPS();
	glutSwapBuffers();
}
示例#27
0
void GlutWindow::idle()
{
	camera.mouseMove();										// Update mouse movement
	calculateFPS();
	glutPostRedisplay();
}
示例#28
0
void renderScene(void) {
    mainPlane.manageHealth();
    
    //GLfloat lightpos[] = {-x,-z,-y};
    //glTranslatef(lightpos[0], lightpos[1], lightpos[2]);
    glColor3f(1, 1, 1);
    //glutSolidSphere(30, 20, 20);
    //glTranslatef(-lightpos[0], -lightpos[1], -lightpos[2]);
    //glLightfv(GL_LIGHT0, GL_POSITION, lightpos);
	if (deltaMove)
		moveMeFlat(deltaMove);
	if (deltaAngle) {
		angle += deltaAngle;
		orientMe(angle);
        //rotateMe(angle);
	}
    if (rotationAngleDelta) {
        rotationAngle+=rotationAngleDelta;
        rotationAngleDelta=0;
        rotateMe(rotationAngle);
    }
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    // Draw ground
    glPushMatrix();
    //glLoadIdentity();
    //glTranslatef(x, y, z);
    //glRotatef(rotationAngle+90, 0, 1, 0);
    explosives.drawExplosions();
    //glTranslatef(-x, -y, -z);
    glPopMatrix();
	
    float minX=200000,maxX=0,minY=20000,maxY=0;
    glBegin(GL_QUADS);
    for (int i = 20; i <tiles.size()-20; i++) {
        for (int j = 20; j <tiles.size()-20; j++) {
            if(tiles[i][j].xMax>maxX) maxX = tiles[i][j].xMax;
            if(tiles[i][j].yMax>maxY) maxY = tiles[i][j].yMax;
            if(tiles[i][j].x<minX) minX = tiles[i][j].x;
            if(tiles[i][j].y<minY) minY = tiles[i][j].y;
            if (tiles[i][j].z>-.7) {
                tiles[i][j].drawTile();
            }
            
            
        }
    }
    drawWater(maxX*40,maxY*40,minX*40,minY*40);
	glEnd();
    
    drawTrees();
    drawBuildings();
    advanceLevel();
    drawPlane();
    
    
    //drawSilos();
    drawCarrierGroup();
    
    
    calculateFPS();
	glutSwapBuffers();
    //std::cout<<"hello";
    indexer++;
    if (loadBuildings) {
        loadBuildings = 0;
        cDetector.buildings = &buildings;
    }
    cDetector.detectCollisions();
    //glLoadIdentity();
    
    
}
示例#29
0
void hleEnterVblank(u64 userdata, int cyclesLate) {
	int vbCount = userdata;

	DEBUG_LOG(HLE, "Enter VBlank %i", vbCount);

	isVblank = 1;

	// Fire the vblank listeners before we wake threads.
	__DisplayFireVblank();

	// Wake up threads waiting for VBlank
	for (size_t i = 0; i < vblankWaitingThreads.size(); i++) {
		if (--vblankWaitingThreads[i].vcountUnblock == 0) {
			__KernelResumeThreadFromWait(vblankWaitingThreads[i].threadID, 0);
			vblankWaitingThreads.erase(vblankWaitingThreads.begin() + i--);
		}
	}

	// Trigger VBlank interrupt handlers.
	__TriggerInterrupt(PSP_INTR_IMMEDIATE | PSP_INTR_ONLY_IF_ENABLED | PSP_INTR_ALWAYS_RESCHED, PSP_VBLANK_INTR, PSP_INTR_SUB_ALL);

	CoreTiming::ScheduleEvent(msToCycles(vblankMs) - cyclesLate, leaveVblankEvent, vbCount + 1);

	// TODO: Should this be done here or in hleLeaveVblank?
	if (framebufIsLatched) {
		DEBUG_LOG(HLE, "Setting latched framebuffer %08x (prev: %08x)", latchedFramebuf.topaddr, framebuf.topaddr);
		framebuf = latchedFramebuf;
		framebufIsLatched = false;
		gpu->SetDisplayFramebuffer(framebuf.topaddr, framebuf.pspFramebufLinesize, framebuf.pspFramebufFormat);
	}

	gpuStats.numFrames++;

	// Now we can subvert the Ge engine in order to draw custom overlays like stat counters etc.
	if (g_Config.bShowDebugStats && gpuStats.numDrawCalls) {
		DebugStats();
	}

	if (g_Config.bShowFPSCounter) {
		char stats[50];

		sprintf(stats, "%0.1f", calculateFPS());

		#ifdef USING_GLES2
			float zoom = 0.7f; /// g_Config.iWindowZoom;
			float soff = 0.7f;
		#else
			float zoom = 0.5f; /// g_Config.iWindowZoom;
			float soff = 0.5f;
		#endif
		PPGeBegin();
		PPGeDrawText(stats, 476 + soff, 4 + soff, PPGE_ALIGN_RIGHT, zoom, 0xCC000000);
		PPGeDrawText(stats, 476 + -soff, 4 -soff, PPGE_ALIGN_RIGHT, zoom, 0xCC000000);
		PPGeDrawText(stats, 476, 4, PPGE_ALIGN_RIGHT, zoom, 0xFF30FF30);
		PPGeEnd();
	}

	// Draw screen overlays before blitting. Saves and restores the Ge context.
	// Yeah, this has to be the right moment to end the frame. Give the graphics backend opportunity
	// to blit the framebuffer, in order to support half-framerate games that otherwise wouldn't have
	// anything to draw here.
	gstate_c.skipDrawReason &= ~SKIPDRAW_SKIPFRAME;

	bool throttle, skipFrame, skipFlip;
	
	DoFrameTiming(throttle, skipFrame, skipFlip);

	// Setting CORE_NEXTFRAME causes a swap.
	if (skipFrame) {
		gstate_c.skipDrawReason |= SKIPDRAW_SKIPFRAME;
		numSkippedFrames++;
	} else {
		numSkippedFrames = 0;
	}

	if (!skipFlip) {
		// Might've just quit / been paused.
		if (coreState == CORE_RUNNING) {
			coreState = CORE_NEXTFRAME;
		}
		CoreTiming::ScheduleEvent(0 - cyclesLate, afterFlipEvent, 0);

		gpu->CopyDisplayToOutput();
	}

	// Returning here with coreState == CORE_NEXTFRAME causes a buffer flip to happen (next frame).
	// Right after, we regain control for a little bit in hleAfterFlip. I think that's a great
	// place to do housekeeping.
}
void DrawSceneGL(void)												// 绘制场景
{
	calculateFPS();
	glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);			// 清除场景和深度缓存
	glLoadIdentity();												// 重置当前矩阵
	
	//glRasterPos2f(-640, -480);
	glPrint("FPS:%d", fps);
	//在此处添加代码进行绘制:

	// 设置视点
	gluLookAt(0.0f, 32.0f, 53.0f,
				0.0f, 27.0f, 0.0f,
				0.0f, 1.0f, 0.0f);

	
	//camera.Look();
	//camera.SetViewByMouse();

	//旋转场景
	glRotatef(angle_Y, 0.0f, 1.0f, 0.0f);

	// 绘制地面
	/*glDisable(GL_LIGHTING);
	glEnable(GL_TEXTURE_2D);
	glBindTexture(GL_TEXTURE_2D, groundTex);
	glColor3f(1.0f, 1.0f, 1.0f);
	glBegin(GL_QUADS);
		glTexCoord2f(0.0f, 0.0f); glVertex3f(-20.0f, 0.0f, 20.0f);
		glTexCoord2f(4.0f, 0.0f); glVertex3f( 20.0f, 0.0f, 20.0f);
		glTexCoord2f(4.0f, 4.0f); glVertex3f( 20.0f, 0.0f,-20.0f);
		glTexCoord2f(0.0f, 4.0f); glVertex3f(-20.0f, 0.0f,-20.0f);
	glEnd();*/

	//绘制场景
	//background3DS.Render();
	skybox.Render();

	// 显示Tower或Gundam
	glEnable(GL_LIGHTING);
	
	//glMatrixMode (GL_MODELVIEW);
    /*glLoadIdentity ();*/
	glScalef (0.3f,0.3f,0.3f);//Resize all unit below
    glTranslatef (0.0f, 50.0f, 0.0f);//Stage height
	glPushMatrix();
    glTranslatef (0.0f, 20.0f, 0.0f);//Raise self height
	actionJump(&noteWholeY,&g_NoteWholeJump);
    glTranslatef (20.0f, noteWholeY, 48.0f);
	glScalef (0.6f,0.6f,0.6f);
	note_Whole3DS.Render();
	glPopMatrix();

	//Note2
	glPushMatrix();
	glScalef (0.7f,0.7f,0.7f);
    glTranslatef (0.0f, 15.0f, 0.0f);//Raise self height
	actionJump(&noteHalfY,&g_NoteHalfJump);
    glTranslatef (48.0f, noteHalfY, 20.0f);
	note_Half3DS.Render();
	glPopMatrix();

	//Note4
	glPushMatrix();
	//glScalef (2.0f,2.0f,2.0f);
	actionJump(&noteQuaterY,&g_NoteFourthJump);
    glTranslatef (48.0f, noteQuaterY, -20.0f);
	noteFourth3DS.Render();
	glPopMatrix();

	//Note8
	glPushMatrix();
	glScalef (1.7f,1.7f,1.7f);
	actionJump(&noteEighthY,&g_NoteEightJump);
    glTranslatef (20.0f, noteEighthY, -48.0f);
	note_Eighth3DS.Render();
	glPopMatrix();

	//note 16
	glPushMatrix();
	glScalef (1.8f,1.8f,1.8f);
	actionJump(&noteSixteenthY,&g_NoteSixteenthJump);
    glTranslatef (-20.0f, noteSixteenthY, -48.0f);
	note_Sixteenth3DS.Render();
	glPopMatrix();

	//Note 32
	glPushMatrix();
	glScalef (1.8f,1.8f,1.8f);
	actionJump(&noteThirtySecondY,&g_NoteThirtySecondJump);
    glTranslatef (-48.0f, noteThirtySecondY, -20.0f);
	note_ThirtySecond3DS.Render();
	glPopMatrix();

	//Note 8 * 2
	glPushMatrix();
	actionJump(&noteEighthDoubleY,&g_NoteEight2Jump);
    glTranslatef (-48.0f, noteEighthDoubleY, 20.0f);
	noteEighth23DS.Render();
	glPopMatrix();

	/*glPushMatrix();
    glTranslatef (-40.0f, 0.0f, 40.0f);
	noteEighth3DS.Render();
	glPopMatrix();
	glPushMatrix();
    glTranslatef (40.0f, 0.0f, 40.0f);
	noteEighth23DS.Render();
	glPopMatrix();
	glPushMatrix();
    glTranslatef (-40.0f, 0.0f, -40.0f);
	noteFourth3DS.Render();
	glPopMatrix();*/
	/*if (showTower)
	{
		glDisable(GL_CULL_FACE);
		tower3DS.Render();
	}
	else
	{
		glEnable(GL_CULL_FACE);
		gundam3DS.Render();
	}*/

	angle_Y += 0.4f;


	glFlush ();														// 刷新GL命令队列
}