Help us understand the problem. What is going on with this article?

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());
}
hideyukisaito
必要とあらばなんでもやる系フリーランス。Web のフロントエンド全般や Unity 等の 3DCG プラットフォームでのアプリケーション開発、DX 改善業務などなど。
http://github.com/hideyukisaito
uniba
ユニバ株式会社は、"さわれるインターネット(Embodied Virtuality)"の会社です。
http://uniba.jp
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away