Edited at

oF で半球を描く

More than 3 years have passed since last update.

https://www.opengl.org/discussion_boards/showthread.php/159402-half-sphere のコードを oF 用に書き直したものですが以下の課題があります。


  • てっぺんが穴空きになる

  • 頂点情報しか無い

もう少しベターな方法があればぜひ教えて下さい!

ofVbo mHemisphere;

void ofApp::setup()
{
const auto resolution_ = 256;
const auto radius_ = 100.0;

std::vector<ofVec3f> vertices_;

for (auto i = 0; i < resolution_; ++i)
{
for (auto j = 0; j < resolution_; ++j)
{
vertices_.emplace_back(ofVec3f(
radius_ * std::cos(j * 2 * M_PI / resolution_) * std::cos(i * M_PI / (2 * resolution_)),
radius_ * std::sin(-i * M_PI / (2 * resolution_)),
radius_ * std::sin(j * 2 * M_PI / resolution_) * std::cos(i * M_PI / (2 * resolution_))
));
}
}

ofMesh mesh_;

for (auto i = 0; i < resolution_ - 1; ++i)
{
for (auto j = 0; j < resolution_; ++j)
{
mesh_.addVertex(vertices_.at(i * resolution_ + j));
mesh_.addVertex(vertices_.at(i * resolution_ + (j + 1) % resolution_));
mesh_.addVertex(vertices_.at((i + 1) * resolution_ + (j + 1) % resolution_));
mesh_.addVertex(vertices_.at((i + 1) * resolution_ + j));
}
}

mHemisphere.setMesh(std::move(mesh_), GL_STATIC_DRAW);
}

void ofApp::draw()
{
ofTranslate(ofGetWidth() * 0.5, ofGetHeight() * 0.5);
ofRotate(ofGetElapsedTimef() * 30.0, 1.0, 0.0, 1.0);
mHemisphere.draw(GL_QUADS, 0, mVbo.getNumVertices());
}