jeonghopark
6/21/2015 - 10:35 PM

astroidDrawing

astroidDrawing

    for(int i=0; i<json.size(); i++) {
        
        orbit _orbitE;
        
        double _a = json[i]["a"].asDouble();
        double _ad = json[i]["ad"].asDouble();
        double _e = json[i]["e"].asDouble();
        double _q = json[i]["q"].asDouble();
        double _i = json[i]["i"].asDouble();
        double _om = json[i]["om"].asDouble();
        
        ofPolyline _orbitPath;
        
        for (int i=0; i<360; i++) {
            // http://mathworld.wolfram.com/SemilatusRectum.html
            double _r = _ad * (1 - (_e * _e)) / (1 + _e * cos(ofDegToRad(i)));
            
            float _size = 100;
            float _x1 = _r * cos(ofDegToRad(i)) * _size;
            float _y1 = _r * sin(ofDegToRad(i)) * _size;
            
            _orbitPath.addVertex( _x1, _y1 );
        }
        _orbitPath.setClosed(true);
        
        
        _orbitE.path = _orbitPath;
        _orbitE.inclination = _i;
        _orbitE.omega = _om;
        
        orbits[i] = _orbitE;
        
    }
    
    rotateZ = 0;
    
}




void ofApp::draw() {
    
    ofBackgroundGradient(ofColor(0,0,40), ofColor(0,0,10));
    
    ofSetColor(255);
    
    cam.begin();
    
    ofRotateZ( rotateZ );
    
    sun.draw();
    
    if (orbits.size()>0) {
        ofSetColor(255, 30);
        for(int i = 0; i<orbits.size(); i++) {
            ofPushMatrix();
            
            ofRotateY( orbits[i].inclination );
            ofRotateZ( orbits[i].omega );
            orbits[i].path.draw();
            
            ofPopMatrix();
        }
    }
    
    cam.end();
    
    
    
}