3

非常に低い fps (約 26) で実行されている太陽系があります。惑星をコメントアウトしてプログラムを実行すると、約 1500 ~ 2000 fps になります。惑星を追加すると、約 400 fps まで低下します。そして、私が追加する惑星が増えるにつれて、そこから下り坂になるだけです。写真のサイズはそれほど大きくありません。私が持っている最大のものは約150kbです。減らしても、fpsは同じように低下​​します。これが太陽系のコードです。

ベクターを使用した更新版

#include <Vrui/Application.h>
#include <iostream>
#include <vector>
#include "solarSystem.h"
#include "drawShape.h"
#include "planet.h"
#include "skybox.h"

using namespace std;

double orbitSpeed = 0.0;
double rotatSpeed = 0.0;
vector<Planet>planets;

/****************************************************
 *
 ****************************************************/
SolarSystem::SolarSystem(int& argc,char**& argv) 
:Vrui::Application(argc,argv)
{
    //Vrui::setNavigationTransformation(Vrui::Point::origin,Vrui::Scalar(15));
}

/****************************************************
 *
 ****************************************************/
void SolarSystem::frame(void)
{
    Vrui::scheduleUpdate(Vrui::getApplicationTime()); // Aim for 125 FPS
}

/****************************************************
 *
 ****************************************************/
void SolarSystem::createPlanets() const
{
    planets.push_back(Planet("images/Sun.jpg", 696, 696, 2500, 0.0, 0.0));
    planets.push_back(Planet("images/mercury.jpg", 200.44, 200.44, 57910.0, 45740.0,     0.0));
planets.push_back(Planet("images/venus.jpg", 600.05, 600.05, 108200.0, 107464.0, 177.3));
planets.push_back(Planet("images/earth.jpg", 600.37, 600.34, 149600.0, 147102.0, 23.5));
//planets.push_back(Planet("images/moon.jpg", 300.4, 300.4, 384.0, 363.0, 5.145));
planets.push_back(Planet("images/mars.jpg", 30000.39, 30000.37, 227940.0, 207425.0, 25.2));
planets.push_back(Planet("images/Jupiter.jpg", 69000.9, 65000.24, 778330.0, 740734.0, 3.1));
planets.push_back(Planet("images/neptune.jpg", 24.63, 24.08, 4504300.0, 4460608.0, 29.6));
planets.push_back(Planet("images/pluto.jpg", 10000.15, 10000.15, 5913520.0, 4475140.0, 29.6));
}

/****************************************************
 *
 ****************************************************/
void SolarSystem::displayOrbitPath() const
{
    
glDisable(GL_LIGHTING);
//Orbit Path
glColor3f(1.0f, 1.0f, 1.0f);
//Mercury //1.5849
drawCircle(91781.559, 72493.326, 1, 200);
//Venus
drawCircle(171486.0, 170319.6936, 1, 200);
//Earth     
drawCircle(237101.04, 233141.9598, 1, 200);
//Mars
drawCircle(361262.106, 328747.8825, 1, 200);
//Jupiter
drawCircle(1233575.217, 1173994.071, 1, 200);
//Saturn
drawCircle(1429400.0*1.5849, 1349353.0*1.5849, 1, 100);
//Uranus
drawCircle(2870990.0*1.5849, 2738637.0*1.5849, 1, 100);
//Neptune
drawCircle(7138865.07, 7069617.619, 1, 200);
//Pluto
drawCircle(5913520.0*1.5849, 4475140.0*1.5849, 1, 200);

}


/****************************************************
 *
 ****************************************************/
void SolarSystem::display(GLContextData& contextData) const
{   


displayOrbitPath();

glDisable(GL_LIGHTING);


for(std::vector<Planet>::iterator it = planets.begin(); 
it != planets.end(); 
++it)

{

double plOrbS = orbitSpeed;
double plRotS = rotatSpeed;

  it->displayPlanet(0, plRotS, 0.0,0.0);

}


orbitSpeed+=1;
if (orbitSpeed > 359)
orbitSpeed = 0.0;

    
rotatSpeed+=3;
if (rotatSpeed > 1436.0)
rotatSpeed = 0.0;
    
}

/****************************************************
 *
 ****************************************************/
int main(int argc,char* argv[])
    {

    SolarSystem app(argc, argv);
app.createPlanets();
app.run();

return 0; 
}

これは、fpsを大幅に低下させるものです

更新しました

プラネット.h

class Planet
{
public:
//Planet();
Planet(const char* fileName, double ER, double PR, 
    double orbitSMa, double orbitSmi, double angle);
~Planet() {};

void setOrbit(double orbitSpeed, double rotationSpeed, 
        double moonOrbitX, double moonOrbitY) ;

    
void displayPlanet(double orbitSpeed, double rotationSpeed, 
            double moonOrbitX, double moonOrbitY);



double getMajorAxis() {return majorAxis;};
double getMinorAxis() {return minorAxis;};
private:
const char* texture;
double equatRadius;
double polarRadius;
double orbitSemiMajor;
double orbitSemiMinor;
double majorAxis;
double minorAxis;   
double orbitAngle;
Images::RGBImage surfaceImage;
};

Planet.cpp 更新

#include "planet.h"


Planet::Planet(const char* fileName, double ER, double PR, double orbitSMa, double orbitSMi, double angle)
{
this->texture        = fileName;
this->equatRadius    = ER;
this->polarRadius    = PR;
this->orbitSemiMajor = orbitSMa;
this->orbitSemiMinor = orbitSMi;
this->majorAxis  = 0.0;
this->minorAxis  = 0.0;
this->orbitAngle = angle;

surfaceImage=Images::readImageFile(this->texture);

}

void Planet::setOrbit(double orbitSpeed, double rotationSpeed, 
          double moonOrbitX, double moonOrbitY) 
{
majorAxis = orbitSemiMajor * cos(orbitSpeed * 0.0055555556 * Math::Constants<double>::pi);
minorAxis = orbitSemiMinor * sin(orbitSpeed * 0.0055555556 * Math::Constants<double>::pi);

glTranslate(majorAxis+moonOrbitX, minorAxis+moonOrbitY, 0.0);
glRotatef(orbitAngle, 0.0, 1.0,1.0);
glRotatef(rotationSpeed, 0.0, 0.0, 1.0);

}

void Planet::displayPlanet(double orbitSpeed,double rotationSpeed, 
           double moonOrbitX, double moonOrbitY)
{

glEnable(GL_TEXTURE_2D);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
surfaceImage.glTexImage2D(GL_TEXTURE_2D,0,GL_RGB);

glPushMatrix();
setOrbit(orbitSpeed,rotationSpeed, moonOrbitX, moonOrbitY);
drawSolidPlanet(equatRadius, polarRadius, 1, 40, 40); 
glPopMatrix();

 }

上記のように、ベクトルを使用して惑星を作成しようとしましたが、プログラムを実行すると FPS が低くなり続けます。

コンピューターのスペックは次のとおりです。

ビデオカード: NVIDIA Quadro FX 580 4GB

コンピュータ: Intel Xeon(R) 3.2GHZ 12GB RAM

4

2 に答える 2

8
  1. リスト (例:std::vector<Planet>太陽系の惑星) を用意し、惑星を 1 回だけ作成します (太陽系に動きを持たせたい場合は、惑星を移動する必要があります。
  2. テクスチャは「一定」であるため、構築の一部としてのみテクスチャを読み取ります。
  3. SolarSystem::display() では、惑星のリストを使用して を呼び出しますdisplayPlanet
于 2013-06-05T16:14:08.080 に答える
3

Images::readImageFile はファイル I/O を実行しますか? もしそうなら、それをすべてのチックと呼ばないでください。一度バッファ/配列にロードしてから、表示するたびにポインタを取得します。残りの機能はディスプレイで実行できますが、ロードはできません。

表示されている目盛りごとに惑星を再作成しています。それらを作成関数で一度作成し、それらをベクトルまたは配列に配置してから、それらのバッファリングされたオブジェクトを呼び出します。

また、テスト コンピューターの仕様についても触れていません。実際のグラフィックス カードを搭載していないロー エンドのコンピューターは、やや複雑なテクスチャ モデルに苦労する可能性があります。

コメントから編集

// Within your Planet class add this where you have your texture stored:
Images::RGBImage surfaceImage;

// When the texture is setup in your constructor, add
surfaceImage=Images::readImageFile(this->texture);
// And remove it from the drawPlanet call

// Global or in a high visibility scope location
std::vector<Planet> planets;  

// Call this outside of your main run loop
void createPlanets()
{   
  planets.push_back(Planet("images/pluto.jpg", 10000.15, 10000.15, 5913520.0, 4475140.0, 29.6));
  ... // Each planet
}

// And in your main draw loop:
for(std::vector<Planet>::iterator iter = planets.begin(); 
    iter != planets.end(); 
    ++iter)
{
  double plOrbS = orbitSpeed;
  double plRotS = rotatSpeed;

  iter->displayPlanet(plOrbS, plRotS, 0.0,0.0);
}
于 2013-06-05T16:15:03.647 に答える