I just fell over the OpenAi Chatgpt.. and nearly fell over.

One of the questions I asked it and the answer it gave me, now not being a coder I wouldn't know if it was giving me a recipe for sushi..

Arty are you in danger of becoming jobless LOL...???

I asked it the following : code in C++ for generating gears

Then it gave me

Here's an example code in C++ using OpenGL for generating a spur gear:

scss

Copy code

#include <GL/glut.h>

#include <cmath>

const double pi = 3.14159265358979323846;

// Number of gear teeth

const int teeth = 20;

// Pitch diameter of gear

const double pitch_diameter = 1.0;

// Angle between gear teeth

const double tooth_angle = 2 * pi / teeth;

// Width of gear tooth

const double tooth_width = 0.1;

// Depth of gear tooth

const double tooth_depth = 0.2;

// Number of vertices in gear

const int vertices = 2 * teeth;

// Gear vertex array

GLfloat gear_vertices[vertices][3];

void generate_gear()

{

for (int i = 0; i < teeth; i++) {

double angle = i * tooth_angle;

double x = (pitch_diameter / 2) * cos(angle);

double y = (pitch_diameter / 2) * sin(angle);

gear_vertices[2 * i][0] = x - (tooth_width / 2) * sin(angle);

gear_vertices[2 * i][1] = y + (tooth_width / 2) * cos(angle);

gear_vertices[2 * i][2] = 0.0;

gear_vertices[2 * i + 1][0] = x + (tooth_width / 2) * sin(angle);

gear_vertices[2 * i + 1][1] = y - (tooth_width / 2) * cos(angle);

gear_vertices[2 * i + 1][2] = 0.0;

}

}

void draw_gear()

{

glBegin(GL_TRIANGLE_STRIP);

for (int i = 0; i < vertices; i++) {

glVertex3fv(gear_vertices

*);*

}

glVertex3fv(gear_vertices[0]);

glVertex3fv(gear_vertices[1]);

glEnd();

glBegin(GL_TRIANGLE_FAN);

glVertex3f(0.0, 0.0, 0.0);

for (int i = 0; i <= vertices; i++) {

glVertex3fv(gear_vertices[i % vertices]);

}

glEnd();

}

void display()

{

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

glMatrixMode(GL_PROJECTION);

glLoadIdentity();

gluPerspective(60.0, 1.0, 0.1, 10.0);

glMatrixMode(GL_MODELVIEW);

glLoadIdentity();

glTranslatef(0.0, 0.0, -3.0);

glRotatef(45.0, 0.0, 1.0, 0.0);

glColor3f(1.0, 1.0, 0.0);

draw_gear();

glutSwapBuffers();

}

int main(int argc, char** argv)

{

generate_gear();

glutInit(&argc, argv);

glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);

glutInitWindowSize(640, 480);

glutCreateWindow("Gear");

glutDisplayFunc(display);

glEnable(GL_DEPTH_TEST);

glutMainLoop();

return 0;

}

This code uses the GLUT library for creating an OpenGL window and rendering the gear. The gear is defined by the number of teeth, pitch diameter, tooth angle, tooth width, and tooth depth. The generate_gear() function generates an array of vertices that define the gear shape, and the draw_gear() function uses OpenGL commands to draw the gear.

}

glVertex3fv(gear_vertices[0]);

glVertex3fv(gear_vertices[1]);

glEnd();

glBegin(GL_TRIANGLE_FAN);

glVertex3f(0.0, 0.0, 0.0);

for (int i = 0; i <= vertices; i++) {

glVertex3fv(gear_vertices[i % vertices]);

}

glEnd();

}

void display()

{

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

glMatrixMode(GL_PROJECTION);

glLoadIdentity();

gluPerspective(60.0, 1.0, 0.1, 10.0);

glMatrixMode(GL_MODELVIEW);

glLoadIdentity();

glTranslatef(0.0, 0.0, -3.0);

glRotatef(45.0, 0.0, 1.0, 0.0);

glColor3f(1.0, 1.0, 0.0);

draw_gear();

glutSwapBuffers();

}

int main(int argc, char** argv)

{

generate_gear();

glutInit(&argc, argv);

glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);

glutInitWindowSize(640, 480);

glutCreateWindow("Gear");

glutDisplayFunc(display);

glEnable(GL_DEPTH_TEST);

glutMainLoop();

return 0;

}

This code uses the GLUT library for creating an OpenGL window and rendering the gear. The gear is defined by the number of teeth, pitch diameter, tooth angle, tooth width, and tooth depth. The generate_gear() function generates an array of vertices that define the gear shape, and the draw_gear() function uses OpenGL commands to draw the gear.