void Framework::update(){ if ( !Loader::instance() ){ Loader::create( "data.bin" ); // Loader::create(); //こっちの行にすると、アーカイブなしでアクセス。 } //ローダ実行 Loader::instance()->update(); //ロード済みなら削除 for ( int i = 0; i < 100; ++i ){ if ( gFiles[ i ] ){ if ( gFiles[ i ]->isReady() ){ Loader::instance()->destroyFile( &gFiles[ i ] ); } } } ostringstream oss; //空いてるだけ全スロットロード for ( int i = 0; i < 100; ++i ){ if ( gFiles[ i ] == 0 ){ oss.str( "" ); oss << "data\\" << getRandom( 1000 ) << ".txt"; Loader::instance()->createFile( &gFiles[ i ], oss.str().c_str() ); } } oss.str( "" ); int framerate = frameRate(); oss << "Framerate: " << frameRate(); int c = ( framerate > 255 ) ? 255 : framerate; drawDebugString( 0, 0, oss.str().c_str(), 0xffff0000 | ( c << 8 ) | c ); int previousFrame = previousFrameInterval(); oss.str( "" ); oss << "PreviousFrame: " << previousFrameInterval(); c = ( previousFrame > 63 ) ? 0 : ( 255 - previousFrame * 4 ); drawDebugString( 0, 1, oss.str().c_str(), 0xffff0000 | ( c << 8 ) | c ); //止まってるのをわかりやすくする描画 double p[ 4 ][ 4 ]; p[ 0 ][ 2 ] = p[ 1 ][ 2 ] = p[ 2 ][ 2 ] = p[ 3 ][ 2 ] = 0.0; p[ 0 ][ 3 ] = p[ 1 ][ 3 ] = p[ 2 ][ 3 ] = p[ 3 ][ 3 ] = 1.0; p[ 0 ][ 0 ] = p[ 2 ][ 0 ] = ( gCount % 640 ) / 320.0 - 1.05; p[ 1 ][ 0 ] = p[ 3 ][ 0 ] = ( gCount % 640 ) / 320.0 - 0.95; p[ 0 ][ 1 ] = p[ 1 ][ 1 ] = -0.05; p[ 2 ][ 1 ] = p[ 3 ][ 1 ] = 0.05; drawTriangle3DH( p[ 0 ], p[ 1 ], p[ 2 ] ); drawTriangle3DH( p[ 3 ], p[ 1 ], p[ 2 ] ); ++gCount; if ( isEndRequested() ){ Loader::destroy(); } }
void EnvMap::onEndTestFrame() { //initial target is (0, 0, -1) static uint32_t targetIndex = 0; static const uint32_t numTargets = 5; static const vec3 targets[numTargets] = { vec3(0, 0, 1), vec3(0.1, 0.9, 0), //camera doesn't like looking directly up or down vec3(-0.1, -0.9, 0), vec3(1, 0, 0), vec3(-1, 0, 0) }; uint32_t frameId = frameRate().getFrameCount(); if (mChangeViewIt != mChangeViewFrames.end() && frameId >= *mChangeViewIt) { ++mChangeViewIt; mpCamera->setTarget(targets[targetIndex]); ++targetIndex; //wrap around so it doesn't crash if too many args are given if (targetIndex == numTargets) { targetIndex = 0; } } }
void GLWidget::clientDraw() { if(m_world->isRayCast()) { m_world->render(getCamera()); glDisable(GL_BLEND); drawFrontImagePlane(); } else { m_world->draw(getCamera()); } std::stringstream sst; if(AdeniumInterface::BakeFile.isOpened()) { sst.str(""); sst<<"bake file: "<<AdeniumInterface::BakeFile.fileName(); hudText(sst.str(), 2); sst.str(""); sst<<"frame: "<<AdeniumInterface::BakeFile.currentFrame(); hudText(sst.str(), 3); AdeniumInterface::ReadBakeFrame(m_world); sst.str(""); sst<<"world p: "<<m_world->currentTranslation(); hudText(sst.str(), 4); if(m_world->doneVelocityCaching()) hudText("all frames saved", 5); } else hudText("no bake loaded", 2); sst.str(""); sst<<"fps: "<<frameRate(); hudText(sst.str(), 1); }
void Framework::update(){ if ( gFirstFrame ){ gImage = new Image( "background.dds" ); gFirstFrame = false; } unsigned* vram = videoMemory(); int ww = width(); //window width int wh = height(); //window height //一旦全部真っ黒に for ( int i = 0; i < ww * wh; ++i ){ vram[ i ] = 0; } int iw = gImage->width(); //image width int ih = gImage->height(); //image height Vector2 offset; offset.x = static_cast< double >( iw ) / 2.0; offset.y = static_cast< double >( ih ) / 2.0; double rotation = static_cast< double >( gCount ); double sine = sin( rotation ); double cosine = cos( rotation ); Matrix22 matrix( cosine, -sine, sine, cosine ); //行列を作って //3点作る Vector2 a, b, c; rotate( &a, Vector2( 0, 0 ), offset, matrix ); //左上 rotate( &b, Vector2( iw, 0 ), offset, matrix ); //右上 rotate( &c, Vector2( 0, ih ), offset, matrix ); //左下 //b-a,c-aを計算 Vector2 ab, ac; ab.setSub( b, a ); ac.setSub( c, a ); //補間開始 double rcpWidth = 1.0 / static_cast< double >( iw ); double rcpHeight = 1.0 / static_cast< double >( ih ); for ( int y = 0; y < ih; ++y ){ double yf = static_cast< double >( y ) + 0.5; double v = yf * rcpHeight; for ( int x = 0; x < iw; ++x ){ double xf = static_cast< double >( x ) + 0.5; double u = xf * rcpWidth; Vector2 p; p.setInterporation( a, ab, ac, u, v ); p -= Vector2( 0.5, 0.5 ); //添え字へ int rx, ry; rx = round( p.x ); ry = round( p.y ); //範囲内なら貼り付け if ( rx >= 0 && rx < ww && ry >= 0 && ry < wh ){ vram[ ry * ww + rx ] = gImage->pixel( x, y ); } } } ++gCount; ostringstream oss; oss << frameRate(); drawDebugString( 0, 0, oss.str().c_str() ); }
bool VideoEncoderFFmpeg::encode(const VideoFrame &frame) { DPTR_D(VideoEncoderFFmpeg); AVFrame *f = NULL; if (frame.isValid()) { f = av_frame_alloc(); f->format = frame.format().pixelFormatFFmpeg(); f->width = frame.width(); f->height = frame.height(); // f->quality = d.avctx->global_quality; switch (timestampMode()) { case TimestampCopy: f->pts = int64_t(frame.timestamp()*frameRate()); // TODO: check monotically increase and fix if not. or another mode? break; case TimestampMonotonic: f->pts = d.nb_encoded+1; break; default: break; } // pts is set in muxer const int nb_planes = frame.planeCount(); for (int i = 0; i < nb_planes; ++i) { f->linesize[i] = frame.bytesPerLine(i); f->data[i] = (uint8_t*)frame.constBits(i); } if (d.avctx->width <= 0) { d.avctx->width = frame.width(); } if (d.avctx->height <= 0) { d.avctx->height = frame.width(); } } AVPacket pkt; av_init_packet(&pkt); pkt.data = (uint8_t*)d.buffer.constData(); pkt.size = d.buffer.size(); int got_packet = 0; int ret = avcodec_encode_video2(d.avctx, &pkt, f, &got_packet); av_frame_free(&f); if (ret < 0) { qWarning("error avcodec_encode_video2: %s" ,av_err2str(ret)); return false; //false } d.nb_encoded++; if (!got_packet) { qWarning("no packet got"); d.packet = Packet(); // invalid frame means eof return frame.isValid(); } // qDebug("enc avpkt.pts: %lld, dts: %lld.", pkt.pts, pkt.dts); d.packet = Packet::fromAVPacket(&pkt, av_q2d(d.avctx->time_base)); // qDebug("enc packet.pts: %.3f, dts: %.3f.", d.packet.pts, d.packet.dts); return true; }
void ImageStreamNode::run() { ros::Rate frameRate(10); //IplImage* img = cvLoadImage(pathToImageFile); cv::Mat src, dst; /// Load image //src = cv::imread(pathToImageFile, 1 ); /// Convert to grayscale /* cvtColor( src, src, CV_BGR2GRAY ); equalizeHist( src, dst ); cvtColor( dst, dst, CV_GRAY2BGR );*/ REXOS_INFO_STREAM("a" << std::endl); cv::Mat img = cv::imread(pathToImageFile, CV_LOAD_IMAGE_GRAYSCALE); REXOS_INFO_STREAM("b" << std::endl); //create a CLAHE object (Arguments are optional). cv::CLAHE* clahe = cv::createCLAHE(4.0, cv::Size(8, 8)); REXOS_INFO_STREAM("clahe ptr: " << (long) clahe << std::endl); //clahe->setClipLimit(4.0); clahe->apply(img, dst); /*if(img == 0){ REXOS_ERROR("Loading image failed"); exit(-2); }*//* while(ros::ok()) { ros::Time time = ros::Time::now(); cv_bridge::CvImage cvi; cvi.header.stamp = time; cvi.header.frame_id = "image"; cvi.encoding = sensor_msgs::image_encodings::BGR8; //cvi.image = img; cvi.image = dst; publisher.publish(cvi.toImageMsg()); frameRate.sleep(); ros::spinOnce(); }*/ }
bool VideoEncoderFFmpeg::encode(const VideoFrame &frame) { DPTR_D(VideoEncoderFFmpeg); AVFrame *f = NULL; if (frame.isValid()) { f = av_frame_alloc(); f->format = frame.format().pixelFormatFFmpeg(); f->width = frame.width(); f->height = frame.height(); // TODO: record last pts f->pts = int64_t(frame.timestamp()*frameRate()); // pts is set in muxer const int nb_planes = frame.planeCount(); for (int i = 0; i < nb_planes; ++i) { f->linesize[i] = frame.bytesPerLine(i); f->data[i] = (uint8_t*)frame.bits(i); } if (d.avctx->width <= 0) { d.avctx->width = frame.width(); } if (d.avctx->height <= 0) { d.avctx->height = frame.width(); } } AVPacket pkt; av_init_packet(&pkt); pkt.data = (uint8_t*)d.buffer.constData(); pkt.size = d.buffer.size(); int got_packet = 0; int ret = avcodec_encode_video2(d.avctx, &pkt, f, &got_packet); av_frame_free(&f); if (ret < 0) { //qWarning("error avcodec_encode_video2: %s" ,av_err2str(ret)); return false; //false } if (!got_packet) { qWarning("no packet got"); return false; //false } qDebug("enc avpkt.pts: %lld, dts: %lld.", pkt.pts, pkt.dts); d.packet = Packet::fromAVPacket(&pkt, av_q2d(d.avctx->time_base)); qDebug("enc packet.pts: %.3f, dts: %.3f.", d.packet.pts, d.packet.dts); return true; }
void Framework::update(){ if ( !gRootSequence ){ gRootSequence = new Sequence::Parent(); } //フレームレート調整 setFrameRate( 60 ); //一回呼べばいいのだが面倒なので呼んでしまう。 if ( gCounter % 60 == 0 ){ //60フレームに一回フレームレート表示 cout << " FrameRate:" << frameRate() << endl; } ++gCounter; gRootSequence->update(); //終了判定(qが押されたか、マウスで×ボタンが叩かれたか) if ( isKeyOn( 'q' ) ){ requestEnd(); } if ( isEndRequested() ){ SAFE_DELETE( gRootSequence ); } }
void Framework::update(){ if ( gFirstFrame ){ gImage = new Image( "background.dds" ); gFirstFrame = false; } unsigned* vram = videoMemory(); int ww = width(); //window width int wh = height(); //window height //一旦全部真っ黒に for ( int i = 0; i < ww * wh; ++i ){ vram[ i ] = 0; } int iw = gImage->width(); //image width int ih = gImage->height(); //image height Vector2 offset; offset.x = static_cast< double >( iw ) / 2.0; offset.y = static_cast< double >( ih ) / 2.0; double rotation = static_cast< double >( gCount ); double sine = sin( rotation ); double cosine = cos( rotation ); Matrix22 matrix( cosine, -sine, sine, cosine ); for ( int y = 0; y < ih; ++y ){ for ( int x = 0; x < iw; ++x ){ //回転先を計算 int rx, ry; rotate( &rx, &ry, x, y, offset, matrix ); //範囲内なら貼り付け if ( rx >= 0 && rx < ww && ry >= 0 && ry < wh ){ vram[ ry * ww + rx ] = gImage->pixel( x, y ); } } } ++gCount; ostringstream oss; oss << frameRate(); drawDebugString( 0, 0, oss.str().c_str() ); }
void GLWidget::clientDraw() { if(m_thread->numLoops() < WorldThread::NumSubsteps) { emit updatePhysics(); return; } std::stringstream sst; sst.str(""); sst<<"fps: "<<frameRate(); hudText(sst.str(), 1); #if DRGDRW if(m_isPhysicsRunning) m_interface->draw(m_world, getDrawer()); #else if(m_isPhysicsRunning) { emit updatePhysics(); m_interface->draw(m_world, getDrawer()); m_world->dbgDraw(); } #endif //else m_interface->drawFaulty(m_world, getDrawer()); }
void VisionNode::run() { if(!cam) throw std::runtime_error("Camera not initialized!"); ros::Rate frameRate(10); while(ros::ok()) { if(isCameraEnabled) { // Read image cam->getFrame(&camFrame); if(isFishEyeCorrectorEnabled == true){ camFrame = fishEyeCorrector.handleFrame(camFrame); } cv::Mat grayScaleFrame; if(isQrCodeReaderEnabled == true || isFudicialDetectorEnabled == true){ // convert to grayscale, because these readers / detecors need grayscale images cvtColor(camFrame, grayScaleFrame, CV_RGB2GRAY); } if(isQrCodeReaderEnabled == true){ qrCodeReader.handleFrame(grayScaleFrame, &camFrame); } if(cameraFeedPublisher.getNumSubscribers() != 0){ ros::Time time = ros::Time::now(); cv_bridge::CvImage cvi; cvi.header.stamp = time; cvi.header.frame_id = "image"; cvi.encoding = sensor_msgs::image_encodings::BGR8; cvi.image = camFrame; cameraFeedPublisher.publish(cvi.toImageMsg()); } } frameRate.sleep(); ros::spinOnce(); } }
void Framework::update(){ if ( !gCircles ){ gCircles = new Circle[ N*N ]; //初期配置 for ( int i = 0; i < N*N; ++i ){ gCircles[ i ].mPosition.set( static_cast< double >( ( ( i % N ) - N/2 ) * 4 ) + 0.001 * i, //ちょっとずらす static_cast< double >( ( ( i / N ) - N/2 ) * 4 ) ); } } //速度初期化 for ( int i = 0;i < N*N; ++i ){ //速度を原点方向で初期化 gCircles[ i ].mVelocity.setMul( gCircles[ i ].mPosition, -0.001 ); } int test; int hit; processCollision( &test, &hit ); //衝突検出関数 //更新 for ( int i = 0;i < N*N; ++i ){ gCircles[ i ].mPosition += gCircles[ i ].mVelocity; //描画 double p[ 4 ][ 2 ]; p[ 0 ][ 0 ] = p[ 1 ][ 0 ] = gCircles[ i ].mPosition.x - 0.5 + 160.0; p[ 2 ][ 0 ] = p[ 3 ][ 0 ] = gCircles[ i ].mPosition.x + 0.5 + 160.0; p[ 0 ][ 1 ] = p[ 2 ][ 1 ] = gCircles[ i ].mPosition.y - 0.5 + 120.0; p[ 1 ][ 1 ] = p[ 3 ][ 1 ] = gCircles[ i ].mPosition.y + 0.5 + 120.0; drawTriangle2D( p[ 0 ], p[ 1 ], p[ 2 ] ); drawTriangle2D( p[ 3 ], p[ 1 ], p[ 2 ] ); } ostringstream oss; oss << frameRate() << " " << test << " " << hit; drawDebugString( 0, 0, oss.str().c_str() ); }
void MencoderTranscoding::updateArguments() { QString fontFile = "/Users/doudou/workspaceQT/DLNA_server/exe/LucidaSansRegular.ttf"; QStringList arguments; if (range() != 0 && !range()->isNull()) { if (range()->getStartByte() > 0 && lengthInSeconds() > 0) { double start_position = double(range()->getStartByte())/double(range()->getSize())*double(lengthInSeconds()); arguments << "-ss" << QString("%1.0").arg(long(start_position)); } } else if (timeSeekStart() > 0) { arguments << "-ss" << QString("%1.0").arg(timeSeekStart()); } arguments << url(); if (format() == MPEG2_AC3) { // set container format to MPEG arguments << "-of" << "mpeg"; arguments << "-mpegopts" << "format=mpeg2:muxrate=500000:vbuf_size=1194:abuf_size=64"; // set audio options arguments << "-oac" << "lavc"; arguments << "-channels" << "6"; arguments << "-af" << "lavcresample=48000"; arguments << "-srate" << "48000"; // set video options arguments << "-ovc" << "lavc"; arguments << "-lavcopts" << "autoaspect=1:vcodec=mpeg2video:acodec=ac3:abitrate=448:keyint=25:vrc_maxrate=9800:vrc_buf_size=1835:vbitrate=5000"; // set font file arguments << "-font" << fontFile; // set subtitles options arguments << "-ass" << "-ass-color" << "ffffff00" << "-ass-border-color" << "00000000" << "-ass-font-scale" << "1.4"; arguments << "-ass-force-style" << QString("FontName=%1,Outline=1,Shadow=1,MarginV=10").arg(fontFile); // choose audio and subtitle language if (audioLanguages().contains("fre")) { arguments << "-aid" << QString("%1").arg(audioLanguages().indexOf("fre")); arguments << "-nosub"; } else { if (subtitleLanguages().contains("fre")) { arguments << "-noautosub" << "-sid" << QString("%1").arg(subtitleLanguages().indexOf("fre")); } else if (subtitleLanguages().contains("eng")) { arguments << "-noautosub" << "-sid" << QString("%1").arg(subtitleLanguages().indexOf("eng")); } } // set frame rate if (!frameRate().isEmpty()) { if (frameRate() == "23.976") { arguments << "-ofps" << "24000/1001"; } else if (frameRate() == "29.970") { arguments << "-ofps" << "30000/1001"; } else { // default framerate output arguments << "-ofps" << "25.000"; } } else { // default framerate output arguments << "-ofps" << "25.000"; } } else { logError(QString("Invalid format: %1").arg(format())); } if (range() != 0 && !range()->isNull()) { if (range()->getLength() > 0) { if (range()->getHighRange() >= 0 && lengthInSeconds() > 0) { // calculate the endpos in seconds double endpos = double(range()->getLength())/double(range()->getSize())*double(lengthInSeconds()); arguments << "-endpos" << QString("%1").arg(long(endpos)); } } else { // invalid length arguments << "-endpos 0"; } } else if (timeSeekEnd() > 0) { arguments << "-endpos" << QString("%1").arg(timeSeekEnd()); } // set output = pipe arguments << "-o" << "-"; // set option on loglevel (required to use seek time mode, option -ss) arguments << "-really-quiet"; arguments << "-msglevel" << "statusline=2"; setArguments(arguments); }
void Framework::update(){ if ( gFirstFrame ){ gImage = new Image( "background.dds" ); gFirstFrame = false; } unsigned* vram = videoMemory(); int ww = width(); //window width int wh = height(); //window height //一旦全部真っ黒に for ( int i = 0; i < ww * wh; ++i ){ vram[ i ] = 0; } int iw = gImage->width(); //image width int ih = gImage->height(); //image height //行列を作ろう double rotation = static_cast< double >( gCount ); //画像中心を原点に、拡大、回転、中心を戻す、の順。 Matrix23 translationMatrix1; Matrix23 scalingMatrix; Matrix23 rotationMatrix; Matrix23 translationMatrix2; //移動1(画像中心を原点に) translationMatrix1.setTranslation( Vector2( -iw/2, -ih/2 ) ); //拡大 Vector2 scale( sin( rotation )*2.0 + 1.0, cos( rotation )*2.0 + 1.0 ); scalingMatrix.setScaling( Vector2( scale.x, scale.y ) ); //回転 rotationMatrix.setRotation( rotation ); //戻す translationMatrix2.setTranslation( Vector2( iw/2, ih/2 ) ); //行列の統合(逆順) Matrix23 transform; transform = translationMatrix2; transform *= rotationMatrix; transform *= scalingMatrix; transform *= translationMatrix1; //3点作る Vector2 a, b, c; transform.multiply( &a, Vector2( 0, 0 ) ); transform.multiply( &b, Vector2( iw, 0 ) ); transform.multiply( &c, Vector2( 0, ih ) ); //b-a,c-aを計算 Vector2 ab, ac; ab.setSub( b, a ); ac.setSub( c, a ); //補間開始 double rcpWidth = 1.0 / static_cast< double >( iw ); double rcpHeight = 1.0 / static_cast< double >( ih ); for ( int y = 0; y < ih; ++y ){ double yf = static_cast< double >( y ) + 0.5; double v = yf * rcpHeight; for ( int x = 0; x < iw; ++x ){ double xf = static_cast< double >( x ) + 0.5; double u = xf * rcpWidth; Vector2 p; p.setInterporation( a, ab, ac, u, v ); p -= Vector2( 0.5, 0.5 ); //添え字へ int rx, ry; rx = round( p.x ); ry = round( p.y ); //範囲内なら貼り付け if ( rx >= 0 && rx < ww && ry >= 0 && ry < wh ){ vram[ ry * ww + rx ] = gImage->pixel( x, y ); } } } ++gCount; ostringstream oss; oss << frameRate(); drawDebugString( 0, 0, oss.str().c_str() ); }
// Boucle dans laquelle vit le jeu. void MainGame::gameLoop() { GLuint frameRate(1000 / 70); Uint32 startTicks(0), endTicks(0), elapsedTime(0), startFpsTicks(0), endFpsTicks(0); int steps(0); int physicalSteps(0); Engine::Shader* shader = new Engine::Shader(); PerlinNoise::initPerlinNoise(15); //Hard test /*for (int i = 0; i < _worldSize; i++) { for (int j = 0; j < _worldSize; j++) { int **heightMap; heightMap = new int*[CHUNK_SIZE + 2]; for (int i1 = 0; i1 < CHUNK_SIZE + 2; i1++) { heightMap[i1] = new int[CHUNK_SIZE + 2]; for (int j1 = 0; j1 < CHUNK_SIZE + 2; j1++) { heightMap[i1][j1] = int(1000 * PerlinNoise::getPerlinNoise(i1 + i*CHUNK_SIZE - 1, j1 + j*CHUNK_SIZE - 1, 10000) + 100 * PerlinNoise::getPerlinNoise(i1 + i*CHUNK_SIZE - 1, j1 + j*CHUNK_SIZE - 1, 200)); } } Engine::Chunk* chunk = new Engine::Chunk(glm::vec3(i*CHUNK_SIZE, j*CHUNK_SIZE, 0), heightMap); chunk->addStructure(new Ground(heightMap)); chunk->addStructure(new Rock(glm::vec3(2, 6, 0))); chunk->addStructure(new Rock(glm::vec3(7, 12, 0))); chunk->addStructure(new Tree(glm::vec3(6, 2, 0), rand()%2)); chunk->init(); _chunks.emplace_back(chunk); for (int i = 0; i < CHUNK_SIZE + 2; i++) { delete heightMap[i]; } delete heightMap; } }*/ //Soft test int **heightMap; heightMap = new int*[CHUNK_SIZE + 2]; for (int i1 = 0; i1 < CHUNK_SIZE + 2; i1++) { heightMap[i1] = new int[CHUNK_SIZE + 2]; for (int j1 = 0; j1 < CHUNK_SIZE + 2; j1++) { heightMap[i1][j1] = int(1000 * PerlinNoise::getPerlinNoise(i1 - 1, j1 - 1, 10000) + 100 * PerlinNoise::getPerlinNoise(i1 - 1, j1 - 1, 200)); } } Engine::Chunk* chunk = new Engine::Chunk(glm::vec3(0, 0, 0), heightMap); chunk->addStructure(new Ground(heightMap)); chunk->addStructure(new Source(glm::vec3(7, 7, 0), this)); chunk->init(); _chunks.emplace_back(chunk); for (int i = 0; i < CHUNK_SIZE + 2; i++) { delete heightMap[i]; } delete heightMap; //Définition et initialisation des matrices de projection glm::mat4 projection; glm::mat4 modelview; projection = glm::perspective(70.0, (double)WINDOW_WIDTH / WINDOW_HEIGHT, 1.0, 2000.0); modelview = glm::mat4(1.0); startFpsTicks = SDL_GetTicks(); //Boucle principale while (_gameState != GameState::EXIT) { startTicks = SDL_GetTicks(); //Gestion des inputs _inputManager.update(); _inputManager.processInput(); checkEnd(); _camera.update(_inputManager, modelview); //Nettoyage de l'écran glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); _scene.getShader().use(); glUniformMatrix4fv(glGetUniformLocation(_scene.getShader().getProgramID(), "modelview"), 1, GL_FALSE, value_ptr(modelview)); glUniformMatrix4fv(glGetUniformLocation(_scene.getShader().getProgramID(), "projection"), 1, GL_FALSE, value_ptr(projection)); //Hard test /*for (auto chunk : _chunks) { chunk->update(); chunk->draw(); }*/ //Soft test physicalSteps++; if (physicalSteps % 100 == 0 && physicalSteps < 601) { chunk->timeStep(); } chunk->update(); chunk->draw(); _scene.getShader().unuse(); //Actualisation de la fenêtre SDL_GL_SwapWindow(_scene.getWindow()); //Limitation des FPS endTicks = SDL_GetTicks(); elapsedTime = endTicks - startTicks; if (elapsedTime < frameRate) { SDL_Delay(frameRate - elapsedTime); } //Calcul des FPS toutes les 100 frames steps++; if (steps == 100) { endFpsTicks = SDL_GetTicks(); int fps = steps*1000 / (endFpsTicks - startFpsTicks); std::cout << "FPS : " << fps << std::endl; steps -= 100; startFpsTicks = SDL_GetTicks(); } } }
void Framework::update(){ if ( gCount == 0 ){ //描画クラスを1000頂点、100バッチで初期化 gPrimitiveRenderer = PrimitiveRenderer::create( 1000, 100 ); //テクスチャロード gTexture = Texture::create( "test.tga" ); while ( !gTexture.isReady() ){ ; //ロード待ち } } //元の頂点配列 Vector3 p[ 4 ]; Vector2 t[ 4 ]; unsigned c[ 4 ]; //わかりやすいように色 p[ 0 ].set( -1.f, -1.f, 0.f ); p[ 1 ].set( -1.f, 1.f, 0.f ); p[ 2 ].set( 1.f, -1.f, 0.f ); p[ 3 ].set( 1.f, 1.f, 0.f ); t[ 0 ].set( 0.f, 0.f ); t[ 1 ].set( 0.f, 1.f ); t[ 2 ].set( 1.f, 0.f ); t[ 3 ].set( 1.f, 1.f ); c[ 0 ] = 0xffff0000; //赤 c[ 1 ] = 0xff00ff00; //緑 c[ 2 ] = 0xff0000ff; //青 c[ 3 ] = 0xffffffff; //白 //ワールド変換(Z回転) Matrix34 wm; wm.setRotationZ( gCount * 2.f ); //ビュー行列を作ろう Vector3 eyePosition; eyePosition.x = sin( gCount / 2.f ) * 4.f; eyePosition.z = cos( gCount / 2.f ) * 4.f; eyePosition.y = 1.f; Vector3 eyeTarget( 0.f, 0.f, 0.f ); Matrix34 vm; vm.setViewTransform( eyePosition, eyeTarget, Vector3( 0.f, 1.f, 0.f ) ); //透視変換行列 Matrix44 pm; pm.setPerspectiveTransform( 60.f, static_cast< float >( width() ), static_cast< float >( height() ), 1.f, 100.f ); //まずVWを作る vm *= wm; //次にPVWを作る pm *= vm; //行列セット gPrimitiveRenderer.setTransform( pm ); //テクスチャセット gPrimitiveRenderer.setTexture( gTexture ); gPrimitiveRenderer.setBlendMode( Graphics::BLEND_LINEAR ); //カウントで何を描くか変えてみよう if ( gCount % 300 > 200 ){ //三角形 gPrimitiveRenderer.addTriangle( p[ 0 ], p[ 1 ], p[ 2 ], t[ 0 ], t[ 1 ], t[ 2 ], c[ 0 ], c[ 1 ], c[ 2 ] ); gPrimitiveRenderer.addTriangle( p[ 3 ], p[ 1 ], p[ 2 ], t[ 3 ], t[ 1 ], t[ 2 ], c[ 3 ], c[ 1 ], c[ 2 ] ); }else if ( gCount % 300 > 100 ){ //線 //線を足す for ( int i = 0; i < 4; ++i ){ for ( int j = i + 1; j < 4; ++j ){ gPrimitiveRenderer.addLine( p[ i ], p[ j ], t[ i ], t[ j ], c[ i ], c[ j ] ); } } }else{ //点 gPrimitiveRenderer.addPoint( p[ 0 ], t[ 0 ], c[ 0 ] ); gPrimitiveRenderer.addPoint( p[ 1 ], t[ 1 ], c[ 1 ] ); gPrimitiveRenderer.addPoint( p[ 2 ], t[ 2 ], c[ 2 ] ); gPrimitiveRenderer.addPoint( p[ 3 ], t[ 3 ], c[ 3 ] ); } //スプライトとか書いてみようか。 //アルファブレンド有効化 gPrimitiveRenderer.setBlendMode( Graphics::BLEND_LINEAR ); Vector2 p2[ 2 ]; p2[ 0 ].set( 0.f, 0.f ); //左上 p2[ 1 ].set( 128.f, 256.f ); //右下 gPrimitiveRenderer.addRectangle( p2[ 0 ], p2[ 1 ], t[ 0 ], t[ 3 ], ( ( gCount % 256 ) << 24 ) | 0xffffff ); //足し終わったので描く gPrimitiveRenderer.draw(); DebugScreen() << frameRate(); ++gCount; if ( isEndRequested() ){ gPrimitiveRenderer.release(); //グローバルなので開放処理が必要 gTexture.release(); } }
///////////////////////////////////////////////////////// // resetState // ///////////////////////////////////////////////////////// void GemMan :: resetState() { debug_post("GemMan::resetState entered"); m_clear_color[0] = 0.0; m_clear_color[1] = 0.0; m_clear_color[2] = 0.0; m_clear_color[3] = 0.0; m_clear_mask = GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT; m_mat_ambient[0] = 0.1f; m_mat_ambient[1] = 0.1f; m_mat_ambient[2] = 0.1f; m_mat_ambient[3] = 1.0f; m_mat_specular[0] = 1.0; m_mat_specular[1] = 1.0; m_mat_specular[2] = 1.0; m_mat_specular[3] = 1.0; m_mat_shininess = 100.0; s_lightState = 0; // window hints m_height = 500; m_width = 500; GemSettings::get("window.width", m_width); GemSettings::get("window.height", m_height); m_w=m_width; m_h=m_height; m_xoffset = 0; m_yoffset = 0; GemSettings::get("window.x", m_xoffset); GemSettings::get("window.y", m_yoffset); m_fullscreen = 0; GemSettings::get("window.fullscreen", m_fullscreen); m_border = 1; GemSettings::get("window.border", m_border); m_menuBar = 1; GemSettings::get("window.menubar", m_menuBar); m_title = "GEM"; GemSettings::get("window.title", m_title); m_buffer = 2; m_stereo=0; m_stereoSep = -15.f; m_stereoFocal = 0.f; m_stereoLine = true; // setup the perspective values m_perspect[0] = -1.f; // left m_perspect[1] = 1.f; // right m_perspect[2] = -1.f; // bottom m_perspect[3] = 1.f; // top m_perspect[4] = 1.f; // front m_perspect[5] = 20.f; // back // setup the lookat values m_lookat[0] = 0.f; // eye: x m_lookat[1] = 0.f; // y m_lookat[2] = 4.f; // z m_lookat[3] = 0.f; // center : x m_lookat[4] = 0.f; // y m_lookat[5] = 0.f; // z m_lookat[6] = 0.f; // up:: x m_lookat[7] = 1.f; // y m_lookat[8] = 0.f; // z // setup the fog m_fogMode = FOG_OFF; m_fogStart = 1.f; m_fogEnd = 20.f; m_fog = 0.5f; m_fogColor[0] = m_fogColor[1] = m_fogColor[2] = m_fogColor[3] = 1.f; // turn on the cursor m_cursor = 1; fps = 0; m_topmost = 0; t_float rate=20.; GemSettings::get("window.fps", rate); frameRate(rate); }
bool VideoEncoderFFmpeg::encode(const VideoFrame &frame) { DPTR_D(VideoEncoderFFmpeg); QScopedPointer<AVFrame, ScopedAVFrameDeleter> f; // hwupload AVPixelFormat pixfmt = AVPixelFormat(frame.pixelFormatFFmpeg()); if (frame.isValid()) { f.reset(av_frame_alloc()); f->format = pixfmt; f->width = frame.width(); f->height = frame.height(); // f->quality = d.avctx->global_quality; switch (timestampMode()) { case TimestampCopy: f->pts = int64_t(frame.timestamp()*frameRate()); // TODO: check monotically increase and fix if not. or another mode? break; case TimestampMonotonic: f->pts = d.nb_encoded+1; break; default: break; } // pts is set in muxer const int nb_planes = frame.planeCount(); for (int i = 0; i < nb_planes; ++i) { f->linesize[i] = frame.bytesPerLine(i); f->data[i] = (uint8_t*)frame.constBits(i); } if (d.avctx->width <= 0) { d.avctx->width = frame.width(); } if (d.avctx->height <= 0) { d.avctx->height = frame.width(); } #ifdef HAVE_AVHWCTX if (d.avctx->hw_frames_ctx) { // TODO: try to map to SourceSurface // checl valid sw_formats if (!d.hwframes_ref) { qWarning("no hw frame context for uploading"); return false; } if (pixfmt != d.hwframes->sw_format) { // reinit or got an unsupported format. assume parameters will not change, so it's the 1st init // check constraints bool init_frames_ctx = d.hwframes->sw_format == AVPixelFormat(-1); if (d.sw_fmts.contains(pixfmt)) { // format changed init_frames_ctx = true; } else { // convert to supported sw format pixfmt = d.sw_fmts[0]; f->format = pixfmt; VideoFrame converted = frame.to(VideoFormat::pixelFormatFromFFmpeg(pixfmt)); for (int i = 0; i < converted.planeCount(); ++i) { f->linesize[i] = converted.bytesPerLine(i); f->data[i] = (uint8_t*)frame.constBits(i); } } if (init_frames_ctx) { d.hwframes->sw_format = pixfmt; d.hwframes->width = frame.width(); d.hwframes->height = frame.height(); AV_ENSURE(av_hwframe_ctx_init(d.hwframes_ref), false); } } // upload QScopedPointer<AVFrame, ScopedAVFrameDeleter> hwf( av_frame_alloc()); AV_ENSURE(av_hwframe_get_buffer(d.hwframes_ref, hwf.data(), 0), false); //hwf->format = d.hwframes->format; // not necessary //hwf->width = f->width; //hwf->height = f->height; AV_ENSURE(av_hwframe_transfer_data(hwf.data(), f.data(), 0), false); AV_ENSURE(av_frame_copy_props(hwf.data(), f.data()), false); av_frame_unref(f.data()); av_frame_move_ref(f.data(), hwf.data()); } #endif //HAVE_AVHWCTX } AVPacket pkt; av_init_packet(&pkt); pkt.data = (uint8_t*)d.buffer.constData(); pkt.size = d.buffer.size(); int got_packet = 0; int ret = avcodec_encode_video2(d.avctx, &pkt, f.data(), &got_packet); if (ret < 0) { qWarning("error avcodec_encode_video2: %s" ,av_err2str(ret)); return false; //false } d.nb_encoded++; if (!got_packet) { qWarning("no packet got"); d.packet = Packet(); // invalid frame means eof return frame.isValid(); } // qDebug("enc avpkt.pts: %lld, dts: %lld.", pkt.pts, pkt.dts); d.packet = Packet::fromAVPacket(&pkt, av_q2d(d.avctx->time_base)); // qDebug("enc packet.pts: %.3f, dts: %.3f.", d.packet.pts, d.packet.dts); return true; }
int mainFenetre() { unsigned int frame_max = SDL_GetTicks() + FRAME_RATE, temps = 0; Input * pInput = NULL; //structure contenant les informations relatives aux inputs clavier SDL_Texture * pTextureDisplay = NULL; //Texture globale SDL_Rect camera = initRect(0, 0, 0, 0); // rect(x,y,w,h) Worms** wormsTab = NULL; char mapName[100]; Jeu* jeu = NULL; //init SDL + fenetre + renderer if (initSWR()) { //Initialisation des inputs pInput = initInput(); if (pInput == NULL) { fprintf(logFile, "mainFenetre : FAILURE, initInput.\n"); cleanUp(&pInput, &pTextureDisplay); return -1; } //InitSounds if (!initSDLMixer()){ fprintf(logFile, "initSDLMixer : FAILURE, init.\n"); cleanUp(&pInput, &pTextureDisplay); return -1; } strcpy(mapName, cMAP); /*Initialisation SDL_TTF*/ if (TTF_Init() == -1) { fprintf(logFile, "mainFenetre : FAILURE, initialisation de TTF_Init : %s.\n\n", TTF_GetError()); cleanUp(&pInput, &pTextureDisplay); return -1; } if (mainMenu(pInput, mapName) < 0) { fprintf(logFile, "mainFenetre : FAILURE, mainMenu .\n\n"); cleanUp(&pInput, &pTextureDisplay); return -1; } if (!pInput->quit) { if (mainInit() < 0) //set le nombre d'équipe et le nombre de worms par équipe { fprintf(logFile, "mainInit : FAILURE.\n"); cleanUp(&pInput, &pTextureDisplay); return -1; } /*Init game*/ jeu = nouveauJeu(mapName); if (jeu == NULL) { fprintf(logFile, "nouveauJeu : FAILURE.\n"); cleanUp(&pInput, &pTextureDisplay); return -1; } /*Init map*/ if (initialisionTerrain(&jeu->pMapTerrain, "../assets/pictures/FondMap1.png", jeu->nomMap) < 0) { fprintf(logFile, "mainFenetre : FAILURE, initialisationTerrain.\n"); cleanUp(&pInput, &pTextureDisplay); return -1; } /*Init global texture*/ pTextureDisplay = my_createTextureFromSurface(jeu->pMapTerrain->globalMapSurface); if (pTextureDisplay == NULL) { fprintf(logFile, "mainFenetre : FAILURE, createGlobalTexture.\n"); destroyMap(&jeu->pMapTerrain); cleanUp(&pInput, &pTextureDisplay); return -1; } /*Init sounds*/ if (loadSounds(BipExplo, 0) < 0) { fprintf(logFile, "mainFenetre : FAILURE, loadSounds.\n"); cleanUp(&pInput, &pTextureDisplay); return -1; } /*Init camera*/ initCameras(jeu->pMapTerrain, &camera, NULL); /*Initialisation du tableau global de worms*/ wormsTab = initWormsTab(jeu->equipes); if (wormsTab == NULL) { destroyMap(&jeu->pMapTerrain); cleanUp(&pInput, &pTextureDisplay); fprintf(logFile, "mainFenetre : FAILURE, allocating memory to the global array of worms pointer.\n\n"); return -1; } /*Init Display*/ initDisplay(jeu->pMapTerrain, pTextureDisplay); /*Initialisation des worms*/ while (!KaamInitGame(wormsTab, jeu->pMapTerrain->collisionMapSurface)) renderScreen(2, 0, jeu->pMapTerrain, 1, pTextureDisplay, &camera, NULL); } while (!(pInput->quit)) { //Récupération des inputs getInput(pInput); //Gestion des inputs if (!gestInput(pInput, jeu->pMapTerrain, pTextureDisplay, &camera, wormsTab)) { fprintf(logFile, "mainFenetre : FAILURE, gestInput.\n"); } //Update de l'écran if (pInput->raffraichissement) { renderScreen(2, 0, jeu->pMapTerrain, 1, pTextureDisplay, &camera, NULL); pInput->raffraichissement = 0; } updateTeamLife(jeu->equipes); isGameEnd(jeu->equipes); //Gestion du frame Rate frameRate(frame_max); frame_max = SDL_GetTicks() + FRAME_RATE; if ((SDL_GetTicks() - temps) >= 1000) { temps = SDL_GetTicks(); jeu->temps -= 1; } } endDisplay(); cleanSounds(); Mix_CloseAudio(); fprintf(logFile, "||| END OF THE GAME |||\n"); if (jeu != NULL) destroyMap(&jeu->pMapTerrain); destroyPolice(); if (wormsTab != NULL) free(wormsTab); wormsTab = NULL; } cleanUp(&pInput, &pTextureDisplay); fprintf(logFile, "mainFenetre : SUCCESS.\n"); if (jeu != NULL) { saveGame(jeu); destroyJeu(&jeu); } { time_t t1 = time(NULL); fprintf(logFile, "\n\nEnd of Session : %s", ctime(&t1)); fclose(logFile); }; return 0; }