Last active
August 29, 2015 14:26
-
-
Save FlandreDaisuki/28a90212063e7f3680d9 to your computer and use it in GitHub Desktop.
0730 code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <GL/glut.h> | |
#include <cstdio> | |
#include <cmath> | |
GLfloat rot = 0.0; | |
GLfloat PI = (GLfloat)3.14159265; | |
GLfloat seed_2 = 0.0; | |
enum EXAMPLE{ NORMAL, ROTATE, TRANSLATE, SCALE }; | |
EXAMPLE mode = SCALE; | |
void init(void) | |
{ | |
glClearColor(0.0, 0.0, 0.0, 0.0); | |
glShadeModel(GL_FLAT); | |
} | |
void display(void) | |
{ | |
glClear(GL_COLOR_BUFFER_BIT); | |
glColor3f(1.0, 1.0, 1.0); | |
glLoadIdentity(); | |
/* viewing transformation */ | |
gluLookAt(0.0, 0.0, 3.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0); | |
/* modeling transformation */ | |
switch (mode) | |
{ | |
case ROTATE: | |
glRotatef(rot, 0.0, 0.0, 1.0); | |
break; | |
case TRANSLATE: | |
glTranslatef((GLfloat)cos((float)seed_2 * PI), (GLfloat)sin((float)seed_2 * PI), 0.0); | |
break; | |
case SCALE: | |
glScalef((GLfloat)abs(cos((float)seed_2 * PI * 0.5) + 0.0001), (GLfloat)abs(sin((float)seed_2 * PI * 0.5) + 0.0001), 1.0); | |
break; | |
default: | |
break; | |
} | |
glutWireCube(1.0); | |
glFlush(); | |
} | |
void reshape(int w, int h) | |
{ | |
glViewport(0, 0, (GLsizei)w, (GLsizei)h); | |
glMatrixMode(GL_PROJECTION); | |
glLoadIdentity(); | |
glFrustum(-1.0, 1.0, -1.0, 1.0, 1.5, 20.0); | |
glMatrixMode(GL_MODELVIEW); | |
} | |
void timer(int p) | |
{ | |
switch (mode) | |
{ | |
case ROTATE: | |
(rot >= 360.0) ? (rot -= 359.0) : (rot += 1.0); | |
break; | |
case TRANSLATE: | |
case SCALE: | |
(seed_2 >= 2.0) ? (seed_2 -= (GLfloat)1.95) : (seed_2 += (GLfloat)0.05); | |
break; | |
default: | |
break; | |
} | |
glutPostRedisplay(); | |
glutTimerFunc(50, timer, 1); | |
} | |
int main(int argc, char** argv) | |
{ | |
glutInit(&argc, argv); | |
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); | |
glutInitWindowSize(500, 500); | |
glutInitWindowPosition(100, 100); | |
glutCreateWindow(argv[0]); | |
init(); | |
glutDisplayFunc(display); | |
glutTimerFunc(50, timer, 1); | |
glutReshapeFunc(reshape); | |
glutMainLoop(); | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <GL/glut.h> | |
#include <cstdio> | |
#include <cmath> | |
GLfloat rot = 0.0; | |
GLfloat PI = (GLfloat)3.14159265; | |
GLfloat seed_2 = 0.0; | |
void drawcubeRGB(GLfloat r = 1.0, GLfloat g = 1.0, GLfloat b = 1.0) | |
{ | |
glPushMatrix(); | |
glRotatef(rot, 0.0, 1.0, 0.0); | |
glRotatef(10, 1.0, 1.0, 0.0); | |
glColor3f(r, g, b); | |
glutWireCube(1.0); | |
glPopMatrix(); | |
} | |
void init(void) | |
{ | |
glClearColor(0.0, 0.0, 0.0, 0.0); | |
glShadeModel(GL_FLAT); | |
} | |
void display(void) | |
{ | |
glClear(GL_COLOR_BUFFER_BIT); | |
glColor3f(1.0, 1.0, 1.0); | |
glLoadIdentity(); | |
gluLookAt(0.0, 0.0, 7.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0); | |
glPushMatrix(); | |
drawcubeRGB(1.0, 1.0, 1.0); | |
glPopMatrix(); | |
glPushMatrix(); | |
glTranslatef(2.0, 0.0, 0.0); | |
drawcubeRGB(1.0, 0.0, 0.0); | |
glPopMatrix(); | |
glPushMatrix(); | |
glTranslatef(0.0, 2.0, 0.0); | |
drawcubeRGB(0.0, 1.0, 0.0); | |
glPushMatrix(); | |
glTranslatef(2.0, 2.0, 0.0); | |
drawcubeRGB(0.0, 0.0, 1.0); | |
glPopMatrix(); | |
glPopMatrix(); | |
glFlush(); | |
} | |
void reshape(int w, int h) | |
{ | |
glViewport(0, 0, (GLsizei)w, (GLsizei)h); | |
glMatrixMode(GL_PROJECTION); | |
glLoadIdentity(); | |
glFrustum(-1.0, 1.0, -1.0, 1.0, 1.5, 20.0); | |
glMatrixMode(GL_MODELVIEW); | |
} | |
void timer(int p) | |
{ | |
rot += (GLfloat)1.0; | |
glutPostRedisplay(); | |
glutTimerFunc(50, timer, 1); | |
} | |
int main(int argc, char** argv) | |
{ | |
glutInit(&argc, argv); | |
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); | |
glutInitWindowSize(500, 500); | |
glutInitWindowPosition(100, 100); | |
glutCreateWindow(argv[0]); | |
init(); | |
glutDisplayFunc(display); | |
glutTimerFunc(50, timer, 1); | |
glutReshapeFunc(reshape); | |
glutMainLoop(); | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <GL/glut.h> | |
#include <cstdio> | |
GLfloat delta = 0.0; | |
void glShearXbyYf(GLfloat delta) { | |
GLfloat m[] = { | |
1.0, 0.0, 0.0, 0.0, | |
delta, 1.0, 0.0, 0.0, | |
0.0, 0.0, 1.0, 0.0, | |
0.0, 0.0, 0.0, 1.0 }; | |
/* !important | |
glMultMatrix is column-major | |
m[0] m[4] m[8] m[12] v[0] | |
M(v) = m[1] m[5] m[9] m[13] × v[1] | |
m[2] m[6] m[10] m[14] v[2] | |
m[3] m[7] m[11] m[15] v[3] | |
*/ | |
glMultMatrixf(m); | |
} | |
void init(void) | |
{ | |
glClearColor(0.0, 0.0, 0.0, 0.0); | |
glShadeModel(GL_SMOOTH); | |
} | |
void display(void) | |
{ | |
glClear(GL_COLOR_BUFFER_BIT); | |
glColor3f(1.0, 1.0, 1.0); | |
glLoadIdentity(); | |
/* viewing transformation */ | |
gluLookAt(0.0, 0.0, 10.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0); | |
/* modeling transformation */ | |
glShearXbyYf(delta); | |
glRotatef(-90, 1.0, 0.0, 0.0); | |
glutWireCone(2.0, 6.0, 10, 10); | |
glutSwapBuffers(); | |
} | |
void timer(int p) | |
{ | |
delta += (GLfloat)0.02; | |
glutPostRedisplay(); | |
glutTimerFunc(50, timer, 1); | |
} | |
void reshape(int w, int h) | |
{ | |
glViewport(0, 0, (GLsizei)w, (GLsizei)h); | |
glMatrixMode(GL_PROJECTION); | |
glLoadIdentity(); | |
glFrustum(-1.0, 1.0, -1.0, 1.0, 1, 20.0); | |
glMatrixMode(GL_MODELVIEW); | |
} | |
int main(int argc, char** argv) | |
{ | |
glutInit(&argc, argv); | |
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB); | |
glutInitWindowSize(500, 500); | |
glutInitWindowPosition(100, 100); | |
glutCreateWindow(argv[0]); | |
init(); | |
glutDisplayFunc(display); | |
glutTimerFunc(50, timer, 1); | |
glutReshapeFunc(reshape); | |
glutMainLoop(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment