LoginSignup
3
3

More than 5 years have passed since last update.

oF で半球を描く

Last updated at Posted at 2016-02-28

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());
}
3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3