Quantcast
Channel: beginners - openFrameworks
Viewing all articles
Browse latest Browse all 4929

Draw arc on the sphere surfaces passing between two points?

$
0
0

@Hirotaka_Niisato wrote:

Hi,
I want to draw the arc on the sphere surfaces between 2 points.
Now I use ofPolyline.quadBezierTo using start/stop point and middle point on the sphere point, but arc draw in the sphere.

source code is here. how would I do that?
Thank you.

void ofApp::setup(){
    ofSetFrameRate(30);
    ofEnableAlphaBlending();
    ofNoFill();

    City n1 = { "1", -33+45/60., -70 + 66/60. };
    City n2 = { "2", 36+74/60., -5 + 16/60. };
    cities.push_back( n1 );
    cities.push_back( n2 );
}

void ofApp::draw(){
    ofPushMatrix();
    ofTranslate(ofGetWidth()/2, ofGetHeight()/2);
    ofScale(-1, -1, 1);

    qTo.getRotate(angle, axis);
    ofRotate(angle, axis.x, axis.y, axis.z);
    ofDrawSphere(300);

    vector <ofVec3f> worlds;
for (int i = 0; i < cities.size(); i++) {
    ofQuaternion latRot, longRot, spinQuat;
    latRot.makeRotate(cities[i].latitude, 1, 0, 0);
    longRot.makeRotate(cities[i].longitude, 0, 1, 0);
    ofVec3f center = ofVec3f(0, 0, 300);
    spinQuat.makeRotate(180, 0, -1, 0);
    ofVec3f worldPoint = latRot * longRot * spinQuat * center;
    worlds.push_back(worldPoint);
    ofSetColor(0, 0, 255);
    ofDrawSphere(worldPoint, 2);
}

for (int i = 0; i < worlds.size() - 1; i++) {
    ofVec3f middlePoint = worlds[i].getMiddle(worlds[i+1]);

    // maybe  this is bad...
    float val = sqrtf(middlePoint.x*middlePoint.x + middlePoint.y*middlePoint.y + middlePoint.z*middlePoint.z);
    ofVec3f onSphereMiddlePoint;
    onSphereMiddlePoint.x = middlePoint.x*(300/val);
    onSphereMiddlePoint.y = middlePoint.y*(300/val);
    onSphereMiddlePoint.z = middlePoint.z*(300/val);

    ofDrawSphere(middlePoint, 2);
    ofDrawSphere(onSphereMiddlePoint, 2);

    ofPolyline poly;
    ofSetLineWidth(1);
    poly.quadBezierTo(worlds[i+1], onSphereMiddlePoint, worlds[i]);
    poly.draw();

}
ofSetColor(255);
ofPopMatrix();
}

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 4929

Trending Articles