Skip to content

Instantly share code, notes, and snippets.

@aaronsherwood
Created August 10, 2013 03:30
Show Gist options
  • Save aaronsherwood/6198935 to your computer and use it in GitHub Desktop.
Save aaronsherwood/6198935 to your computer and use it in GitHub Desktop.
openFrameworks custom arc drawing. used to draw arcs similar to flight patterns, using my own data.
//
// mapArc.cpp
//
// Created by Aaron Sherwood on 3/29/13.
// Copyright 2013. All rights reserved.
//
#include <iostream>
#include "mapArc.h"
//--------------------------------------------------------------
mapArc::mapArc(){
go = false;
up = -1.0472;
down = 1.0472;
minSpeed=2; //set lower for faster
maxSpeed=20; //set higher for slower
}
//--------------------------------------------------------------
void mapArc::init(ofVec3f s, ofVec3f f){
start = s;
finish = f;
ad = finish-start;
angle = atan2(ad.y, ad.x);
if (angle<=0) angle += 2*PI;
arcDirection;
if (start.y<=finish.y&&start.x>=finish.x) {
arcDirection=down;
} else if (start.y<=finish.y&&start.x<=finish.x){
arcDirection=up;
} else if (start.y>=finish.y&&start.x<=finish.x){
arcDirection=down;
} else if (start.y>=finish.y&&start.x>=finish.x){
arcDirection=up;
}
anchor.x=ad.length()*cos(angle+arcDirection)+start.x;
anchor.y=ad.length()*sin(angle+arcDirection)+start.y;
ofVec3f originVec=start-anchor;
originAngle=atan2(originVec.y,originVec.x);
if (originAngle<0) originAngle += 2*PI;
startAngle=originAngle;
go=true;
}
//--------------------------------------------------------------
void mapArc::incrementAngle() {
archCoords.x=ad.length()*cos(originAngle)+anchor.x;
archCoords.y=ad.length()*sin(originAngle)+anchor.y;
if (go) {
arc.addVertex(archCoords.x, archCoords.y);
}
if (arcDirection==down){
if (originAngle>=startAngle+down-.1) {
go=false;
}
float dest=ofClamp((startAngle+down)-originAngle,0,startAngle);
originAngle+=dest/ofMap((startAngle+down), 0,7, minSpeed, maxSpeed,true);
}
if (arcDirection==up){
if (originAngle<=startAngle+up+.1) {
go=false;
}
float dest=ofClamp(originAngle-(startAngle+up),0,startAngle);
originAngle-=dest/ofMap(startAngle+up, 0., 7, minSpeed, maxSpeed,true);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment