Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

#include #include #include #include #define PI 3.14159 float n = 7; //Size of the image void drawGoldenTriangle() { float X = 50.0, Y = 68,

#include #include #include #include

#define PI 3.14159 float n = 7; //Size of the image

void drawGoldenTriangle() { float X = 50.0, Y = 68, Z = 0.0; // Center of the Triangle glColor3f(0.0, 0.0, 1.0); // Color of the Triange(Blue) glBegin(GL_TRIANGLES); //Use GL_POLYGON to draw the triangle glVertex3f(X, Y + n/2, Z); glVertex3f(X - n/2, Y - n/2, Z); // Movement of the Triangle(left and down) glVertex3f(X + n/2, Y - n/2, Z); // Movemnet of the Triangle(right and down)

glEnd(); }

void drawRedCross() { float X = 68.0, Y = 50.0, Z = 0.0; // Center of the Cross glColor3f(1.0, 0.0, 0.0); // Color of the Cross(Red)

glBegin(GL_POLYGON); //Use GL_POLYGON to draw the cross glVertex3f(X - (n/6), Y +(n/2), Z); // Movement of the Cross(left and up) glVertex3f(X - (n/6), Y -(n/2), Z); // Movement of the Cross(left and down) glVertex3f(X + (n/6), Y -(n/2), Z); // Movement of the Cross(right and down) glVertex3f(X + (n/6), Y +(n/2), Z); // Movement of the Cross(right and up) glEnd();

glBegin(GL_POLYGON); glVertex3f(X - (n/2), Y +(n/6), Z); // Movement of the Cross glVertex3f(X - (n/2), Y -(n/6), Z); // Movement of the Cross glVertex3f(X + (n/2), Y -(n/6), Z); // Movement of the Cross glVertex3f(X + (n/2), Y +(n/6), Z); // Movement of the Cross glEnd(); }

void drawShiningStar() {

float X = 32.0, Y = 47.0, Z = 0.0; //Center of the Star glColor3f(0.0, 1.0, 0.0); //Color of the Star(Green) glBegin(GL_TRIANGLES); glVertex3f(X, Y, Z); glVertex3f(X - n/2, Y + n/2, Z); // Movement of the Star(left and up) glVertex3f(X + n/2, Y + n/2, Z); // Movement of the Star(right and up) glEnd();

glBegin(GL_TRIANGLES); glVertex3f(X, Y, Z); glVertex3f(X - n/3, Y - n/4, Z); // Movement of the Star(left and down) glVertex3f(X, Y + n, Z); // Movement of the Star glEnd();

glBegin(GL_TRIANGLES); glVertex3f(X, Y, Z); glVertex3f(X + n/3, Y - n/4, Z); // Movement of the Star(right and down) glVertex3f(X, Y + n, Z); // Movement of the Star glEnd(); }

void drawBowingArrow() { float X = 50.0, Y = 47.0, Z = 0.0; //Center of the Arrow glColor3f(0.5, 0.35, 0.05); //Color of the Arrow(Orange) glBegin(GL_POLYGON); glVertex3f(X - (n/6), Y - n, Z); // Movement of the Arrow(left and down) glVertex3f(X + (n/6), Y - n, Z); // Movement of the Arrow(right and down) glVertex3f(X + (n/6), Y + n, Z); // Movement of the Arrow(right and up) glVertex3f(X - (n/6), Y + n, Z); // Movement of the Arrow(left and up) glEnd();

glBegin(GL_TRIANGLES); glVertex3f(X, Y + (3*n)/2, Z); glVertex3f(X - n/2, Y + n, Z); // Movement of the Arrow(left and up) glVertex3f(X + n/2, Y + n, Z); // Movement of the Arrow(right and up) glEnd(); }

void drawHugeDiamond() { float X = 50.0, Y = 32.0, Z = 0.0; //Center of the Diamond glColor3f(1.0, 1.0, 0.0); // Color of the Diamond(Yellow) glBegin(GL_POLYGON); glVertex3f(X - (n/2), Y, Z); // Movement of the Diamond(left) glVertex3f(X, Y + (n/2), Z); // Movement of the Diamond(up) glVertex3f(X + (n/2), Y, Z); // Movement of the Diamond(right) glVertex3f(X, Y - (n/2), Z); // Movement of the Diamond(down) glEnd(); }

void drawSpiningCircle() { float outercircle = (7*n)/2; //Radius of the whole circle float innercircle = (19*n)/6; // Radius of the inner circle float X = 50.0, Y = 50.0, Z = 0.0; // Coordinates of the center of the circle int numVertices = 90; // Number of vertices on circle float t = 0; // Angle parameter

glColor3f(0.5, 0.5, 0.5);//Color of the circle(grey) glBegin(GL_TRIANGLE_STRIP); for (int i = 0; i

glEnd(); }

void setup(void) {

glClearColor(1.0, 1.0, 1.0, 0.0); }

void resize(int w, int h) {

glViewport(0, 0, w, h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0.0, 100.0, 0.0, 100.0, -1.0, 1.0);

glMatrixMode(GL_MODELVIEW); glLoadIdentity(); }

void drawScene(void) //This will draw all shapes { glClear(GL_COLOR_BUFFER_BIT); drawGoldenTriangle(); drawRedCross(); drawShiningStar(); drawHugeDiamond(); drawBowingArrow(); drawSpiningCircle(); glFlush(); }

// Keyboard input processing routine. void keyInput(unsigned char key, int x, int y) { switch (key) { case 27: // Escape key glutDestroyWindow; exit (0); break; } glutPostRedisplay(); }

// Main routine. int main(int argc, char **argv) { glutInit(&argc, argv);

glutInitContextVersion(3, 1); glutInitContextProfile(GLUT_COMPATIBILITY_PROFILE);

glutInitDisplayMode(GLUT_SINGLE | GLUT_RGBA | GLUT_DEPTH); glutInitWindowSize(500, 500); glutInitWindowPosition(100, 100); glutCreateWindow("static.cpp"); glutDisplayFunc(drawScene); glutReshapeFunc(resize); glutKeyboardFunc(keyInput); glutMouseFunc(mouseControl);

setup();

glutMainLoop(); }

image text in transcribed

This image is the results to the above code.

This is an OpenGL code and I need additional code to insert in the code above for the instructions below. I need the following two images below just like my image above.

When the user left clicks the mouse on any of four shapes objects (triangle, cross, diamond, or star) on the screen, a black frame will be drawn around the shape, and a text message will appear at the bottom of the screen stating that the object is selected and press SPACE to spin. For example, if user clicks on the green star following image will be generated:

image text in transcribed

After the selection of a shape, the user presses the SPACE key. The brown arrow starts spinning clockwise around its center (black point) and randomly stops at a shape (after passing at least 3 and at most 15 shapes). The rotation is expected to be smooth, so the user will see a transition from one shape to another shape. Please set your FPS (frames per second) as 30. There will be 5-degree rotation change between each frame. And each time the user presses the key, arrow will point a random shape. The arrow will never stop between shapes. SPACE key will not work if a shape is not selected.

If the arrow stops at the selected shape, a You win! message appears at the bottom of the screen. If arrow stops at a different shape, the message will print You lose!. For example:

image text in transcribed

static.cpp Green Star is selected. Press "SPACE" to Spin! You Win! static.cpp Green Star is selected. Press "SPACE" to Spin! You Win

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Main Memory Database Systems

Authors: Frans Faerber, Alfons Kemper, Per-Åke Alfons

1st Edition

ISBN: 1680833243, 978-1680833249

More Books

Students also viewed these Databases questions