void GameScene::drawBackground(QPainter *painter, const QRectF &) { float width=float(painter->device()->width()); float height=float(painter->device()->height()); painter->beginNativePainting(); setStates(); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glMatrixMode(GL_PROJECTION); qgluPerspective(60.0,width/height,0.01f,500.0f); glMatrixMode(GL_MODELVIEW); QMatrix4x4 view; view.translate(-camera->getEyePosition()); QMatrix4x4 rview; QPointF rot=camera->rotation(); rview.rotate(rot.x(),0,1,0); rview.rotate(rot.y(),cos(GMath::radians(rot.x())),0,sin(GMath::radians(rot.x()))); renderWorld(view,rview); defaultStates(); painter->endNativePainting(); //计算fps drawCount++; QTime currT=QTime::currentTime(); int mss=lastTime.msecsTo(currT); if(mss>=1000){ glFps=(drawCount/(mss*1.0f))*1000; drawCount=0; lastTime=currT; dataPanel->setFps(glFps); } //控制物品栏布局 if(backPackBar->isShow()){ int h=this->height()*0.7; int w=h*1.35; backPackBar->setGeometry((this->width()-w)/2,(this->height()-h)/2,w,h); backPackBar->setViewPos(QPoint(gView->pos().x() ,gView->pos().y()+(gView->frameSize().height()-gView->height()))); } if(itemBar){ //刷新物品栏位置大小 itemBar->resetSIze(this->width(),this->height(),40); } if(inOpWidget){ //刷新选项菜单位置和大小 int h=this->height()*0.8; int w=h; opWidget->setGeometry((this->width()-w)/2,(this->height()-h)/2,w,h); } }
void GraphicsScene::drawBackground(QPainter *painter, const QRectF &) { float width = float(painter->device()->width()); float height = float(painter->device()->height()); setSceneRect(0, 0, width, height); painter->beginNativePainting(); setStates(); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glMatrixMode(GL_PROJECTION); gluPerspective(60.0, width / height, 0.01, 15.0); glMatrixMode(GL_MODELVIEW); glTranslatef(0,0,-4); glScalef(1.5,1,-2); emit render(); defaultStates(); painter->endNativePainting(); }