code format

This commit is contained in:
Lexxy Fox 2023-11-01 10:15:55 -05:00
parent 04fac81a8e
commit 6200685e52
2 changed files with 288 additions and 305 deletions

View File

@ -12,13 +12,11 @@
/* Conversion to GLUT by Mark J. Kilgard */
#include <math.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "glut_wrap.h"
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
static GLint T0 = 0;
static GLint Frames = 0;
@ -28,7 +26,6 @@ static GLboolean Visible = GL_TRUE;
static GLboolean Animate = GL_TRUE;
static GLfloat viewDist = 40.0;
/**
Draw a gear wheel. You'll probably want to call this function when
@ -42,10 +39,10 @@ static GLfloat viewDist = 40.0;
**/
static void
gear(GLfloat inner_radius, GLfloat outer_radius, GLfloat width,
GLint teeth, GLfloat tooth_depth)
{
static void gear(
GLfloat inner_radius, GLfloat outer_radius, GLfloat width, GLint teeth,
GLfloat tooth_depth
) {
GLint i;
GLfloat r0, r1, r2;
GLfloat angle, da;
@ -69,7 +66,9 @@ gear(GLfloat inner_radius, GLfloat outer_radius, GLfloat width,
glVertex3f(r1 * cos(angle), r1 * sin(angle), width * 0.5);
if (i < teeth) {
glVertex3f(r0 * cos(angle), r0 * sin(angle), width * 0.5);
glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da), width * 0.5);
glVertex3f(
r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da), width * 0.5
);
}
}
glEnd();
@ -96,7 +95,9 @@ gear(GLfloat inner_radius, GLfloat outer_radius, GLfloat width,
glVertex3f(r1 * cos(angle), r1 * sin(angle), -width * 0.5);
glVertex3f(r0 * cos(angle), r0 * sin(angle), -width * 0.5);
if (i < teeth) {
glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da), -width * 0.5);
glVertex3f(
r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da), -width * 0.5
);
glVertex3f(r0 * cos(angle), r0 * sin(angle), -width * 0.5);
}
}
@ -108,8 +109,12 @@ gear(GLfloat inner_radius, GLfloat outer_radius, GLfloat width,
for (i = 0; i < teeth; i++) {
angle = i * 2.0 * M_PI / teeth;
glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da), -width * 0.5);
glVertex3f(r2 * cos(angle + 2 * da), r2 * sin(angle + 2 * da), -width * 0.5);
glVertex3f(
r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da), -width * 0.5
);
glVertex3f(
r2 * cos(angle + 2 * da), r2 * sin(angle + 2 * da), -width * 0.5
);
glVertex3f(r2 * cos(angle + da), r2 * sin(angle + da), -width * 0.5);
glVertex3f(r1 * cos(angle), r1 * sin(angle), -width * 0.5);
}
@ -132,12 +137,16 @@ gear(GLfloat inner_radius, GLfloat outer_radius, GLfloat width,
glVertex3f(r2 * cos(angle + da), r2 * sin(angle + da), -width * 0.5);
glNormal3f(cos(angle), sin(angle), 0.0);
glVertex3f(r2 * cos(angle + 2 * da), r2 * sin(angle + 2 * da), width * 0.5);
glVertex3f(r2 * cos(angle + 2 * da), r2 * sin(angle + 2 * da), -width * 0.5);
glVertex3f(
r2 * cos(angle + 2 * da), r2 * sin(angle + 2 * da), -width * 0.5
);
u = r1 * cos(angle + 3 * da) - r2 * cos(angle + 2 * da);
v = r1 * sin(angle + 3 * da) - r2 * sin(angle + 2 * da);
glNormal3f(v, -u, 0.0);
glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da), width * 0.5);
glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da), -width * 0.5);
glVertex3f(
r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da), -width * 0.5
);
glNormal3f(cos(angle), sin(angle), 0.0);
}
@ -157,25 +166,20 @@ gear(GLfloat inner_radius, GLfloat outer_radius, GLfloat width,
glVertex3f(r0 * cos(angle), r0 * sin(angle), width * 0.5);
}
glEnd();
}
static GLfloat view_rotx = 20.0, view_roty = 30.0, view_rotz = 0.0;
static GLint gear1, gear2, gear3;
static GLfloat angle = 0.0;
static void
cleanup(void)
{
static void cleanup(void) {
glDeleteLists(gear1, 1);
glDeleteLists(gear2, 1);
glDeleteLists(gear3, 1);
glutDestroyWindow(win);
}
static void
draw(void)
{
static void draw(void) {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
@ -227,14 +231,10 @@ draw(void)
}
}
static void
idle(void)
{
static void idle(void) {
static double t0 = -1.;
double dt, t = glutGet(GLUT_ELAPSED_TIME) / 1000.0;
if (t0 < 0.0)
t0 = t;
if (t0 < 0.0) t0 = t;
dt = t - t0;
t0 = t;
@ -244,9 +244,7 @@ idle(void)
glutPostRedisplay();
}
static void
update_idle_func(void)
{
static void update_idle_func(void) {
if (Visible && Animate)
glutIdleFunc(idle);
else
@ -255,9 +253,7 @@ update_idle_func(void)
/* change view angle, exit upon ESC */
/* ARGSUSED1 */
static void
key(unsigned char k, int x, int y)
{
static void key(unsigned char k, int, int) {
switch (k) {
case 'z':
view_rotz += 5.0;
@ -287,9 +283,7 @@ key(unsigned char k, int x, int y)
/* change view angle */
/* ARGSUSED1 */
static void
special(int k, int x, int y)
{
static void special(int k, int, int) {
switch (k) {
case GLUT_KEY_UP:
view_rotx += 5.0;
@ -310,9 +304,7 @@ special(int k, int x, int y)
}
/* new window size or exposure */
static void
reshape(int width, int height)
{
static void reshape(int width, int height) {
GLfloat h = (GLfloat)height / (GLfloat)width;
glViewport(0, 0, (GLint)width, (GLint)height);
@ -322,9 +314,7 @@ reshape(int width, int height)
glMatrixMode(GL_MODELVIEW);
}
static void
init(int argc, char *argv[])
{
static void init(int argc, char *argv[]) {
static GLfloat pos[4] = {5.0, 5.0, 10.0, 0.0};
static GLfloat red[4] = {0.8, 0.1, 0.0, 1.0};
static GLfloat green[4] = {0.0, 0.8, 0.2, 1.0};
@ -365,28 +355,22 @@ init(int argc, char *argv[])
printf("GL_VENDOR = %s\n", (char *)glGetString(GL_VENDOR));
printf("GL_EXTENSIONS = %s\n", (char *)glGetString(GL_EXTENSIONS));
fflush(stdout);
}
else if ( strcmp(argv[i], "-exit")==0) {
} else if (strcmp(argv[i], "-exit") == 0) {
autoexit = 30;
printf("Auto Exit after %i seconds.\n", autoexit);
fflush(stdout);
}
else if (strcmp(argv[i], "-noanim") == 0) {
} else if (strcmp(argv[i], "-noanim") == 0) {
Animate = GL_FALSE;
}
}
}
static void
visible(int vis)
{
static void visible(int vis) {
Visible = vis;
update_idle_func();
}
int main(int argc, char *argv[])
{
int main(int argc, char *argv[]) {
glutInitWindowSize(300, 300);
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE);
@ -403,4 +387,3 @@ int main(int argc, char *argv[])
glutMainLoop();
return 0; /* ANSI C requires main to return int. */
}