diff --git a/FemboyGeometry/FemboyGeometry.cpp b/FemboyGeometry/FemboyGeometry.cpp deleted file mode 100644 index 377e135..0000000 --- a/FemboyGeometry/FemboyGeometry.cpp +++ /dev/null @@ -1,62 +0,0 @@ -#include - -#ifdef _WIN32 -#include -#endif -#include -#include -#include - - -void display(void) -{ -/* clear all pixels */ - glClear (GL_COLOR_BUFFER_BIT); - -/* draw white polygon (rectangle) with corners at - * (0.25, 0.25, 0.0) and (0.75, 0.75, 0.0) - */ - glColor3f (1.0, 1.0, 1.0); - glBegin(GL_POLYGON); - glVertex3f (0.25, 0.25, 0.0); - glVertex3f (0.75, 0.25, 0.0); - glVertex3f (0.75, 0.75, 0.0); - glVertex3f (0.25, 0.75, 0.0); - glEnd(); - -/* don't wait! - * start processing buffered OpenGL routines - */ - glFlush (); -} - -void init (void) -{ -/* select clearing (background) color */ - glClearColor (0.0, 0.0, 0.0, 0.0); - -/* initialize viewing values */ - glMatrixMode(GL_PROJECTION); - glLoadIdentity(); - glOrtho(0.0, 1.0, 0.0, 1.0, -1.0, 1.0); -} - -/* - * Declare initial window size, position, and display mode - * (single buffer and RGBA). Open window with "hello" - * in its title bar. Call initialization routines. - * Register callback function to display graphics. - * Enter main loop and process events. - */ -int main(int argc, char** argv) -{ - glutInit(&argc, argv); - glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB); - glutInitWindowSize (250, 250); - glutInitWindowPosition (100, 100); - glutCreateWindow ("hello"); - init (); - glutDisplayFunc(display); - glutMainLoop(); - return 0; /* ISO C requires main to return int. */ -} diff --git a/FemboyGeometry/FemboyGeometry.vcxproj b/FemboyGeometry/FemboyGeometry.vcxproj index b42022b..a4412af 100644 --- a/FemboyGeometry/FemboyGeometry.vcxproj +++ b/FemboyGeometry/FemboyGeometry.vcxproj @@ -70,7 +70,11 @@ - + + + + + diff --git a/FemboyGeometry/FemboyGeometry.vcxproj.filters b/FemboyGeometry/FemboyGeometry.vcxproj.filters index a362d5b..f7fea58 100644 --- a/FemboyGeometry/FemboyGeometry.vcxproj.filters +++ b/FemboyGeometry/FemboyGeometry.vcxproj.filters @@ -15,8 +15,16 @@ - + + Source Files + + Source Files + + + Header Files + + \ No newline at end of file diff --git a/FemboyGeometry/geometry.cpp b/FemboyGeometry/geometry.cpp new file mode 100644 index 0000000..db0b1b4 --- /dev/null +++ b/FemboyGeometry/geometry.cpp @@ -0,0 +1,157 @@ +#include "geometry.h" + +GeometryPlayer::GeometryPlayer(int width, int height) + : m_width(width), m_height(height), m_theta(0.0f), m_tickCounter(0), m_rotCounter(0), m_mode(0) +{ + /* select clearing (background) color */ + glClearColor(0.0, 0.0, 0.0, 0.0); + + /* initialize viewing values */ + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glOrtho(-width/20.0, width/20.0, -height/20.0, height/20.0, -height/20.0, height/20.0); +} + +GeometryPlayer::~GeometryPlayer() +{ + glutDestroyWindow(glutGetWindow()); +} + +void GeometryPlayer::nextMode() +{ + m_tickCounter = 0; + m_rotCounter = 0; + m_theta = 0; + m_mode = (m_mode + 1) % NUM_MODES; +} + +void GeometryPlayer::animateBezier() +{ + /* draw based bezier curves */ + glPushMatrix(); + glRotatef(m_theta/4.0f, 0.0, 0.0, 1.0); + glColor3f(1.0, 0.0, 0.0); + glBegin(GL_LINES); + for (int x = 20; x >= 0; --x) + { + int y = 20 - x; + glVertex2i(x, 0); + glVertex2i(0, y); + glVertex2i(-x, 0); + glVertex2i(0, -y); + glVertex2i(-x, 0); + glVertex2i(0, y); + glVertex2i(x, 0); + glVertex2i(0, -y); + } + glEnd(); + glPopMatrix(); +} + +void GeometryPlayer::animateCone() +{ + /* draw based cone */ + float radius = 7.5f; + glPushMatrix(); + glRotatef(m_theta, 0.0, 1.0, 0.5); + glColor3f(1.0, 1.0, 0.0); + int circle_points = 10; + glutWireCone(radius, 15.0f, 10, circle_points); + glColor3f(1.0, 0.0, 1.0); + glBegin(GL_LINE_LOOP); + // draw wires through the circle + for (int i = 0; i < circle_points; i++) + { + float angle = 2*PI*i/circle_points; + float x = radius*cos(angle); + float y = radius*sin(angle); + // circumference should be drawn too, so alternate the order of the vertices + if (i % 2 == 0) + { + glVertex2f(x, y); + glVertex2f(-x, -y); + } + else + { + glVertex2f(-x, -y); + glVertex2f(x, y); + } + } + glEnd(); + glPopMatrix(); +} + +void GeometryPlayer::animateCube() +{ + /* draw based colorful cube */ + glPushMatrix(); + glRotatef(m_theta, 1.0, 0.5, 0.0); + glColor3f(0.0, 1.0, 1.0); + // MOAR WIRES + for (int i = 0; i < 5; ++i) + { + glutWireCube(i*2); + } + glPopMatrix(); +} + +void GeometryPlayer::animateGlobe() +{ + /* draw based wireframe sphere with rotation animation */ + glPushMatrix(); + glRotatef(m_theta, 0.0, 1.0, 0.0); + glColor3f(0.0, 1.0, 0.0); + glutWireSphere(10.0, 15, 15); + glPopMatrix(); +} + +void GeometryPlayer::animateTorus() +{ + /* draw based (ford) torus */ + glPushMatrix(); + glRotatef(60.0f, 1.0, 0.0, 0.0); + glRotatef(m_theta, 0.0, 0.0, 1.0); + glColor3f(0.0, 0.0, 1.0); + glutWireTorus(2.0, 10.0, 10, 15); + glPopMatrix(); +} + +void GeometryPlayer::display() +{ + /* clear all pixels */ + glClear(GL_COLOR_BUFFER_BIT); + + switch (m_mode) + { + case 0: + animateGlobe(); + break; + case 1: + animateCube(); + break; + case 2: + animateTorus(); + break; + case 3: + animateBezier(); + break; + case 4: + animateCone(); + break; + } + +/* don't wait! + * start processing buffered OpenGL routines + */ + glutSwapBuffers(); +} + +void GeometryPlayer::tick(int) +{ + m_theta += OMEGA; + ++m_tickCounter; + float angle = m_theta - m_rotCounter * 360.0f; + if (angle > 360.0f && ++m_rotCounter == 5) + nextMode(); + glutPostRedisplay(); +} diff --git a/FemboyGeometry/geometry.h b/FemboyGeometry/geometry.h new file mode 100644 index 0000000..fe9ff2b --- /dev/null +++ b/FemboyGeometry/geometry.h @@ -0,0 +1,41 @@ +#pragma once + +#ifdef _WIN32 +#include +#endif + +#include +#include +#include +#include + +#define PI 3.14159 +#define NUM_MODES 5 +#define OMEGA 4.0f + + +class GeometryPlayer +{ +public: + GeometryPlayer(int width, int height); + ~GeometryPlayer(); + + void nextMode(void); + void display(void); + void tick(int); + +protected: + void animateBezier(void); + void animateCone(void); + void animateCube(void); + void animateGlobe(void); + void animateTorus(void); + +private: + int m_width; + int m_height; + float m_theta; + int m_tickCounter; + int m_rotCounter; + int m_mode; +}; diff --git a/FemboyGeometry/main.cpp b/FemboyGeometry/main.cpp new file mode 100644 index 0000000..b0d500e --- /dev/null +++ b/FemboyGeometry/main.cpp @@ -0,0 +1,56 @@ +#include +#include "geometry.h" + +#define WIN_WIDTH 640 +#define WIN_HEIGHT 480 +#define FPS 60 +#define TITLE "FemboyGeometry (OpenGLel Edition)" + +GeometryPlayer* g_player = NULL; + +void mouse(int button, int state, int, int) +{ + if (state == GLUT_DOWN) + { + if (button == GLUT_LEFT_BUTTON) + g_player->nextMode(); + else if (button == GLUT_RIGHT_BUTTON) + delete g_player; + } +} + +void display(void) +{ + g_player->display(); +} + +void tick(int arg) +{ + g_player->tick(arg); + glutTimerFunc(1000.0/FPS, tick, 0); +} + +/* + * Declare initial window size, position, and display mode + * (single buffer and RGBA). Open window with "hello" + * in its title bar. Call initialization routines. + * Register callback function to display graphics. + * Enter main loop and process events. + */ +int main(int argc, char** argv) +{ + glutInit(&argc, argv); + glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); + glutInitWindowSize(WIN_WIDTH, WIN_HEIGHT); + glutInitWindowPosition(100, 100); + glutCreateWindow(TITLE); + + g_player = new GeometryPlayer(WIN_WIDTH, WIN_HEIGHT); + glutDisplayFunc(display); + glutMouseFunc(mouse); + tick(0); + + glutMainLoop(); + delete g_player; + return 0; +}