Skip to content

Instantly share code, notes, and snippets.

@satoruhiga
Created August 18, 2011 18:44
Show Gist options
  • Save satoruhiga/1154806 to your computer and use it in GitHub Desktop.
Save satoruhiga/1154806 to your computer and use it in GitHub Desktop.
Strip Sphere
#include "testApp.h"
//--------------------------------------------------------------
void testApp::setup()
{
ofSetFrameRate(60);
ofSetVerticalSync(true);
ofBackground(0);
ofSetColor(255);
}
//--------------------------------------------------------------
void testApp::update()
{
}
//--------------------------------------------------------------
void testApp::draw()
{
glEnable(GL_DEPTH_TEST);
glTranslated(ofGetWidth() / 2, ofGetHeight() / 2, 0);
float roll = ofMap(mouseX, 0, ofGetWidth(), 0, 30, true);
int res = 512;
glRotatef(ofGetElapsedTimef() * 60, 0, 1, 0);
glRotatef(60, 1, 0, 0);
glColor4f(1, 0, 0, 1);
glBegin(GL_QUAD_STRIP);
for (int i = 0; i <= res; i++)
{
float f = ofMap(i, 0, res, 0, 1, true);
float x1 = sin(f * TWO_PI * roll) * sin(f * PI) * 200;
float y1 = cos(f * TWO_PI * roll) * sin(f * PI) * 200;
float z1 = sin(f * PI + HALF_PI) * 200;
float ff = f + 0.05;
float x2 = sin(f * TWO_PI * roll) * sin(ff * PI) * 200;
float y2 = cos(f * TWO_PI * roll) * sin(ff * PI) * 200;
float z2 = sin(ff * PI + HALF_PI) * 200;
glVertex3f(x1, y1, z1);
glVertex3f(x2, y2, z2);
}
glEnd();
glColor4f(0, 1, 0, 1);
glBegin(GL_QUAD_STRIP);
for (int i = 0; i <= res; i++)
{
float f = ofMap(i, 0, res, 0, 1, true);
float x1 = sin(f * TWO_PI * roll + PI) * sin(f * PI) * 200;
float y1 = cos(f * TWO_PI * roll + PI) * sin(f * PI) * 200;
float z1 = sin(f * PI + HALF_PI) * 200;
float ff = f + 0.05;
float x2 = sin(f * TWO_PI * roll + PI) * sin(ff * PI) * 200;
float y2 = cos(f * TWO_PI * roll + PI) * sin(ff * PI) * 200;
float z2 = sin(ff * PI + HALF_PI) * 200;
glVertex3f(x1, y1, z1);
glVertex3f(x2, y2, z2);
}
glEnd();
}
//--------------------------------------------------------------
void testApp::keyPressed(int key)
{
}
//--------------------------------------------------------------
void testApp::keyReleased(int key)
{
}
//--------------------------------------------------------------
void testApp::mouseMoved(int x, int y)
{
}
//--------------------------------------------------------------
void testApp::mouseDragged(int x, int y, int button)
{
}
//--------------------------------------------------------------
void testApp::mousePressed(int x, int y, int button)
{
}
//--------------------------------------------------------------
void testApp::mouseReleased(int x, int y, int button)
{
}
//--------------------------------------------------------------
void testApp::windowResized(int w, int h)
{
}
//--------------------------------------------------------------
void testApp::gotMessage(ofMessage msg)
{
}
//--------------------------------------------------------------
void testApp::dragEvent(ofDragInfo dragInfo)
{
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment