Question
I AM RUNNING THE CODE BELOW IN OPENGL AND IT IS GIVING ME THE ERRORS ABOVE IN THE SCREENSHOT AFTER BUILD, PLEASE FIX CODE AND
I AM RUNNING THE CODE BELOW IN OPENGL AND IT IS GIVING ME THE ERRORS ABOVE IN THE SCREENSHOT AFTER BUILD, PLEASE FIX CODE AND RUN IT.
#include
using namespace std;
const float DEG2RAD = 3.14159 / 180;
void processInput(GLFWwindow* window);
enum BRICKTYPE { REFLECTIVE, DESTRUCTABLE, COLOR }; enum ONOFF { ON, OFF }; enum COL {green};
class Brick { public: float red, green, blue; float x, y, width; BRICKTYPE brick_type; ONOFF onoff; int hit_points;
Brick(BRICKTYPE bt, float xx, float yy, float ww, float rr, float gg, float bb) { brick_type = bt; x = xx; y = yy, width = ww; red = rr, green = gg, blue = bb; onoff = ON; if (brick_type == DESTRUCTABLE) { hit_points = 3; // initialize hit points for destructible bricks } };
void drawBrick() { if (onoff == ON) { double halfside = width / 6;
glColor3d(red, green, blue); glBegin(GL_POLYGON);
glVertex2d(x + halfside, y + halfside); glVertex2d(x + halfside, y - halfside); glVertex2d(x - halfside, y - halfside); glVertex2d(x - halfside, y + halfside);
glEnd(); } } };
class Circle { public: float red, green, blue; float radius; float x; float y; float speed = 0.01; //speed of circles int direction; // 1=up 2=right 3=down 4=left 5 = up right 6 = up left 7 = down right 8= down left
Circle(double xx, double yy, double rr, int dir, float rad, float r, float g, float b) { x = xx; y = yy; radius = rr; red = r; green = g; blue = b; radius = rad; direction = dir; }
void CheckCollision(Circle* other_circle, Brick* brk) { if (brk->brick_type == REFLECTIVE) { if ((x > brk->x - brk->width && x x + brk->width) && (y > brk->y - brk->width && y y + brk->width)) { direction = GetDirection(); x = x + 0.01; y = y + 0.02; } } else if (brk->brick_type == DESTRUCTABLE) { if ((x > brk->x - brk->width && x x + brk->width) && (y > brk->y - brk->width && y y + brk->width)) { brk->onoff = OFF; } } float distance = sqrt(pow(x - other_circle->x, 2) + pow(y - other_circle->y, 2)); if (distance radius) { // create new circle with combined size and position float new_x = (x + other_circle->x) / 2; float new_y = (y + other_circle->y) / 2; float new_radius = radius + other_circle->radius; Circle new_circle(new_x, new_y, new_radius, GetDirection(), new_radius, red, green, blue);
// remove the two colliding circles from the world for (auto iter = world.begin(); iter != world.end(); ++iter) { if (&(*iter) == this || &(*iter) == other_circle) { world.erase(iter); break; } }
// add the new circle to the world world.push_back(new_circle); } }
int GetDirection() { return (rand() % 8) + 1; }
void MoveOneStep() { if (direction == 1 || direction == 5 || direction == 6) // up { if (y > -1 + radius) { y -= speed; } else { direction = GetDirection(); } }
if (direction == 2 || direction == 5 || direction == 7) // right { if (x
if (direction == 3 || direction == 7 || direction == 8) // down { if (y
if (direction == 4 || direction == 6 || direction == 8) // left { if (x > -1 + radius) { x -= speed; } else { direction = GetDirection(); } } }
void DrawCircle() { glColor3f(red, green, blue); glBegin(GL_POLYGON); for (int i = 0; i
vector
int main(void) { srand(time(NULL));
if (!glfwInit()) { exit(EXIT_FAILURE); } glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 2); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0); GLFWwindow* window = glfwCreateWindow(480, 480, "Shingy Chiremba Week 8 Assignment", NULL, NULL); if (!window) { glfwTerminate(); exit(EXIT_FAILURE); } glfwMakeContextCurrent(window); glfwSwapInterval(1);
Brick brick(REFLECTIVE, 0.5, -0.33, 0.2, 1, 1, 0); Brick brick2(DESTRUCTABLE, -0.5, 0.33, 0.2, 0, 1, 0); Brick brick3(DESTRUCTABLE, -0.5, -0.33, 0.2, 0, 1, 1); Brick brick4(DESTRUCTABLE, 1, 1, 0.5, 0, 0.5, 0.5); Brick brick5(REFLECTIVE, 0.3, 0.3, 0.2, 1, 0.5, 0.5); Brick brick6(DESTRUCTABLE, 0.2, 0.2, 0.2, 0.8, 0.3, 0.3);
while (!glfwWindowShouldClose(window)) { //Setup View float ratio; int width, height; glfwGetFramebufferSize(window, &width, &height); ratio = width / (float)height; glViewport(0, 0, width, height); glClear(GL_COLOR_BUFFER_BIT);
processInput(window);
//Movement for (int i = 0; i
}
brick.drawBrick(); brick2.drawBrick(); brick3.drawBrick(); brick4.drawBrick(); brick5.drawBrick(); brick6.drawBrick();
glfwSwapBuffers(window); glfwPollEvents(); }
glfwDestroyWindow(window); glfwTerminate; exit(EXIT_SUCCESS); }
void processInput(GLFWwindow* window) { if (glfwGetMouseButton(window, GLFW_MOUSE_BUTTON_LEFT) == GLFW_PRESS) { double xpos, ypos; glfwGetCursorPos(window, &xpos, &ypos);
float red = static_cast
Circle new_circle(static_cast
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started