Question: VISUALSTUDIO:- I need little assistant with my codes, I have done every steps apart from the steps typed in CAPITAL. Using c++ creat a bouncing

VISUALSTUDIO:- I need little assistant with my codes, I have done every steps apart from the steps typed in CAPITAL.

Using c++ creat a bouncing green circle in a yellow window of 700x700 pixels size using shaders. You can use shades of the given colors below.

-Show the green circle in a 700x700 yellow window.

-The circle starts moving in an animation diagonally and bouncing back from the sides.

-There should be a red horizontal line of 1/4 width in the middle of the screen.

=THE CIRLE SHOULD ONLY TURN RED WHEN IT CROSSES THE RED HORIZONTAL LINE AND YOU SHOULD BE ABLE TO MOVE THE RED HORIZONTAL LINE UP and DOWN WITH THE USE OF THE KEYBOARD.

PLEASE Could u kindly check my code and edit it ONLY to the steps TYPED in capital.

MY CODES:

#include #include #include #include #include #include

//Variables GLsizei dimensions = 700; vec2 circle = { 100.0, 300.0 }; vec2 point1 = { 525.0,350.0 }; vec2 point2 = { 175.0, 350.0 }; GLdouble radius = 70.0; float incx = ((float)(rand() % 100 + 1) / 100); float incy = ((float)(rand() % 100 + 1) / 100); int grad = 0; int yint = 0; BOOLEAN isFilled = FALSE;

//Finds equation of line void eqLine(vec2 pt1, vec2 pt2) { int m = (int)((pt2.y - pt1.y) / (pt2.x - pt1.x)); int b = pt1.y - (m * pt1.x); //y = mx + b grad = m; yint = b; }

void init() { glClearColor(1.0, 1.0, 1.0, 0.0); glMatrixMode(GL_PROJECTION); gluOrtho2D(0, dimensions, 0, dimensions); glShadeModel(GL_FLAT); eqLine(point1, point2); }

//If the center of the ball cross the line BOOLEAN crossLine(vec2 center) { //y = mx + b int y = grad * center.x + yint; return center.y < y; //returns true if ball is on left }

//Draws Circle void circleFunc(vec2 B, GLdouble rad) { if (!isFilled) { glBegin(GL_POLYGON); for (GLdouble t = 0; t < 2 * pi(); t += 0.01) glVertex2d(B.x + rad * cos(t), B.y + rad * sin(t)); glEnd(); } else { glBegin(GL_LINE_LOOP); for (GLdouble t = 0; t < 2 * pi(); t += 0.01) glVertex2d(B.x + rad * cos(t), B.y + rad * sin(t)); glEnd(); } }

void display() { glClear(GL_COLOR_BUFFER_BIT);

glClearColor(1.0, 1.0, 0.0, 0.0);

glColor3f(1.0, 0.0, 0.0);

glLineWidth(0.25);

//Drawing Line glBegin(GL_LINES); glVertex2i(point1.x, point1.y); glVertex2i(point2.x, point2.y); glEnd();

//Drawing Circle if(crossLine(circle)) glColor3f(0.0, 1.0, 0.0); else glColor3f(1.0, 0.0, 0.0); circleFunc(circle, radius);

glutSwapBuffers(); }

void update(int n) { circle.x += incx; circle.y += incy;

if (circle.x - radius < 0 || circle.x + radius > dimensions) { incx *= -1; isFilled = !isFilled; }

if (circle.y - radius < 0 || circle.y + radius > dimensions) { incy *= -1; isFilled = !isFilled; }

glutPostRedisplay(); glutTimerFunc(5, update, 0); }

int main(int argc, char** argv) {

glutInit(&argc, argv); glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB); glutInitWindowSize(dimensions, dimensions); glutInitWindowPosition(500, 200); glutCreateWindow("Bouncing Ball!");

srand(time(NULL)); init();

glutDisplayFunc(display); glutTimerFunc(5, update, 0); glutMainLoop(); return 0; }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!