Skip to content

Instantly share code, notes, and snippets.

@dMaggot
Created December 24, 2009 04:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dMaggot/263001 to your computer and use it in GitHub Desktop.
Save dMaggot/263001 to your computer and use it in GitHub Desktop.
/*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glut.h>
#include <cmath>
#include <utility>
#include <vector>
#include <complex>
#define PRECISION 0.0001
using namespace std;
vector<pair<pair<float, float> , float> > circles;
complex<float> polarCenter(0.0f, 0.0f);
float polarRadius = 10.0f;
void driveCircle(int x, int y)
{
polarCenter.real((x - 300) / 3);
polarCenter.imag((300 - y) / 3);
return;
}
void circle(pair<pair<float, float> , float> c)
{
glBegin(GL_LINE_LOOP);
for (float i = 0; i < 2 * M_PI; i += PRECISION)
glVertex2f(c.second * cos(i) + c.first.first, c.second * sin(i) + c.first.second);
glEnd();
}
void display()
{
glClear(GL_COLOR_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glColor3f(1.0f, 1.0f, 1.0f);
complex<float> i(0.0f, 1.0f);
//circle(make_pair(make_pair(polarCenter.real(), polarCenter.imag()), polarRadius));
for (vector<pair<pair<float, float> , float> >::iterator k = circles.begin(); k < circles.end(); k++)
{
complex<float> newCircle(k->first.first, k->first.second);
float newRadius = k->second;
glColor3f(1.0f, 1.0f, 0.0f);
//circle(*k);
glColor3f(1.0f, 0.0f, 0.0f);
glBegin(GL_POINTS);
for (float k = 0.0f; k < 2 * M_PI; k += PRECISION)
{
complex<float> point(newRadius * cos(k), newRadius * sin(k));
float projLength = ((polarCenter - point - newCircle) * abs(point) / (i * point)).real();
complex<float> projection = point + newCircle + i * projLength * point / abs(point);
complex<float> pole = pow(30.0f, 2) / conj(projection - polarCenter) + polarCenter;
glVertex2f(pole.real(), pole.imag());
}
glEnd();
}
glutSwapBuffers();
}
void init()
{
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(-100.0f, 100.0f, -100.0f, 100.0f);
glMatrixMode(GL_MODELVIEW);
return;
}
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
glutInitWindowSize(600, 600);
glutCreateWindow("Projective Animation");
glutIdleFunc(display);
glutPassiveMotionFunc(driveCircle);
circles.push_back(make_pair(make_pair(0.0f, 0.0f), 10.0f));
circles.push_back(make_pair(make_pair(0.0f, 0.0f), 20.0f));
circles.push_back(make_pair(make_pair(0.0f, 0.0f), 30.0f));
circles.push_back(make_pair(make_pair(0.0f, 0.0f), 40.0f));
circles.push_back(make_pair(make_pair(0.0f, 0.0f), 50.0f));
circles.push_back(make_pair(make_pair(0.0f, 0.0f), 60.0f));
circles.push_back(make_pair(make_pair(0.0f, 0.0f), 70.0f));
circles.push_back(make_pair(make_pair(0.0f, 0.0f), 80.0f));
circles.push_back(make_pair(make_pair(0.0f, 0.0f), 90.0f));
circles.push_back(make_pair(make_pair(0.0f, 0.0f), 100.0f));
init();
glutMainLoop();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment