Skip to content

Instantly share code, notes, and snippets.

@hideyukisaito
Last active March 4, 2016 06:45
Show Gist options
  • Save hideyukisaito/891c311c2ab1f86d9f97 to your computer and use it in GitHub Desktop.
Save hideyukisaito/891c311c2ab1f86d9f97 to your computer and use it in GitHub Desktop.
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());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment