added based wireframe animations
This commit is contained in:
parent
05604fd4da
commit
549656a2d0
@ -1,62 +0,0 @@
|
|||||||
#include <iostream>
|
|
||||||
|
|
||||||
#ifdef _WIN32
|
|
||||||
#include <windows.h>
|
|
||||||
#endif
|
|
||||||
#include <gl/GL.h>
|
|
||||||
#include <gl/GLU.h>
|
|
||||||
#include <gl/GLUT.h>
|
|
||||||
|
|
||||||
|
|
||||||
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. */
|
|
||||||
}
|
|
@ -70,7 +70,11 @@
|
|||||||
</PostBuildEvent>
|
</PostBuildEvent>
|
||||||
</ItemDefinitionGroup>
|
</ItemDefinitionGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClCompile Include="FemboyGeometry.cpp" />
|
<ClCompile Include="geometry.cpp" />
|
||||||
|
<ClCompile Include="main.cpp" />
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<ClInclude Include="geometry.h" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||||
<ImportGroup Label="ExtensionTargets">
|
<ImportGroup Label="ExtensionTargets">
|
||||||
|
@ -15,8 +15,16 @@
|
|||||||
</Filter>
|
</Filter>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClCompile Include="FemboyGeometry.cpp">
|
<ClCompile Include="main.cpp">
|
||||||
|
<Filter>Source Files</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
<ClCompile Include="geometry.cpp">
|
||||||
<Filter>Source Files</Filter>
|
<Filter>Source Files</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<ClInclude Include="geometry.h">
|
||||||
|
<Filter>Header Files</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
157
FemboyGeometry/geometry.cpp
Normal file
157
FemboyGeometry/geometry.cpp
Normal file
@ -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();
|
||||||
|
}
|
41
FemboyGeometry/geometry.h
Normal file
41
FemboyGeometry/geometry.h
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
#include <windows.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <math.h>
|
||||||
|
#include <gl/GL.h>
|
||||||
|
#include <gl/GLU.h>
|
||||||
|
#include <gl/GLUT.h>
|
||||||
|
|
||||||
|
#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;
|
||||||
|
};
|
56
FemboyGeometry/main.cpp
Normal file
56
FemboyGeometry/main.cpp
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
#include <gl/GLUT.h>
|
||||||
|
#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;
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user