SlideShare a Scribd company logo
1 of 7
Download to read offline
Apply physics laws to the circles . When a circle hits one of the sides of the screen, its progress
should be altered in some way. While the circles currently move at a constant speed and have
randomized movement once they bounce off one edge of the screen, there are ways you can alter
this to make the animation more engaging. Some options you may wish to use for your work are
as follows, but you do not need to complete all of these. You can also try an idea of your own
instead.
Alter the speed of the circle.
Change the angle of trajectory so it follows physics laws instead of taking a randomized pattern.
(This means it would continue in the direction it was heading rather than moving backward.)
Add friction to specific surfaces, which would affect the circle and slow its progress once it
collided with the surface.
PLEASE USE GIVEN CODE BELOW WITH NO ADDITIONAL LIBRARIES
#include <GLFWglfw3.h>
#include "linmath.h"
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
#include <iostream>
#include <vector>
#include <windows.h>
#include <time.h>
using namespace std;
const float DEG2RAD = 3.14159 / 180;
void processInput(GLFWwindow* window);
enum BRICKTYPE { REFLECTIVE, DESTRUCTABLE };
enum ONOFF { ON, OFF };
class Brick
{
public:
float red, green, blue;
float x, y, width;
BRICKTYPE brick_type;
ONOFF onoff;
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;
};
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(Brick* brk)
{
if (brk->brick_type == REFLECTIVE)
{
if ((x > brk->x - brk->width && x <= brk->x + brk->width) && (y > brk->y - brk->width
&& y <= brk->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 <= brk->x + brk->width) && (y > brk->y - brk->width
&& y <= brk->y + brk->width))
{
brk->onoff = OFF;
}
}
}
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 < 1 - radius)
{
x += speed;
}
else
{
direction = GetDirection();
}
}
if (direction == 3 || direction == 7 || direction == 8) // down
{
if (y < 1 - radius) {
y += speed;
}
else
{
direction = GetDirection();
}
}
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 < 360; i++) {
float degInRad = i * DEG2RAD;
glVertex2f((cos(degInRad) * radius) + x, (sin(degInRad) * radius) + y);
}
glEnd();
}
};
vector<Circle> world;
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 < world.size(); i++)
{
world[i].CheckCollision(&brick);
world[i].CheckCollision(&brick2);
world[i].CheckCollision(&brick3);
world[i].CheckCollision(&brick4);
world[i].CheckCollision(&brick5);
world[i].CheckCollision(&brick6);
world[i].MoveOneStep();
world[i].DrawCircle();
}
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 (glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS)
glfwSetWindowShouldClose(window, true);
if (glfwGetKey(window, GLFW_KEY_SPACE) == GLFW_PRESS)
{
double r, g, b;
r = rand() / 10000;
g = rand() / 10000;
b = rand() / 10000;
Circle B(0, 0, 02, 2, 0.05, r, g, b);
world.push_back(B);
}
}
Apply physics laws to the circles- When a circle hits one of the sides.pdf

More Related Content

Similar to Apply physics laws to the circles- When a circle hits one of the sides.pdf

Tutorial Open GL (Listing Code)
Tutorial Open GL (Listing Code)Tutorial Open GL (Listing Code)
Tutorial Open GL (Listing Code)Aila Gema Safitri
 
#includefloat angle, move, scene, roadmove,turn, on=1; int i, st.docx
#includefloat angle, move, scene, roadmove,turn, on=1; int i, st.docx#includefloat angle, move, scene, roadmove,turn, on=1; int i, st.docx
#includefloat angle, move, scene, roadmove,turn, on=1; int i, st.docxajoy21
 
draw a sphere and use raytracing on the sphere in OpenGL glut. .pdf
 draw a sphere and use raytracing on the sphere in OpenGL glut. .pdf draw a sphere and use raytracing on the sphere in OpenGL glut. .pdf
draw a sphere and use raytracing on the sphere in OpenGL glut. .pdfaquacosmossystems
 
An object that moves in a circle A c++ program to check if the gi.pdf
An object that moves in a circle A c++ program to check if the gi.pdfAn object that moves in a circle A c++ program to check if the gi.pdf
An object that moves in a circle A c++ program to check if the gi.pdfdavid16271
 
Ujug07presentation
Ujug07presentationUjug07presentation
Ujug07presentationBill Adams
 
Image Compression Comparison Using Golden Section Transform, CDF 5/3 (Le Gall...
Image Compression Comparison Using Golden Section Transform, CDF 5/3 (Le Gall...Image Compression Comparison Using Golden Section Transform, CDF 5/3 (Le Gall...
Image Compression Comparison Using Golden Section Transform, CDF 5/3 (Le Gall...Jason Li
 
10CSL67 CG LAB PROGRAM 3
10CSL67 CG LAB PROGRAM 310CSL67 CG LAB PROGRAM 3
10CSL67 CG LAB PROGRAM 3Vanishree Arun
 
Robot Motion Source code
Robot Motion Source codeRobot Motion Source code
Robot Motion Source codeBrian Goggins
 
computer graphics slides by Talha shah
computer graphics slides by Talha shahcomputer graphics slides by Talha shah
computer graphics slides by Talha shahSyed Talha
 
The Ring programming language version 1.5.3 book - Part 65 of 184
The Ring programming language version 1.5.3 book - Part 65 of 184The Ring programming language version 1.5.3 book - Part 65 of 184
The Ring programming language version 1.5.3 book - Part 65 of 184Mahmoud Samir Fayed
 
CG OpenGL Shadows + Light + Texture -course 10
CG OpenGL Shadows + Light + Texture -course 10CG OpenGL Shadows + Light + Texture -course 10
CG OpenGL Shadows + Light + Texture -course 10fungfung Chen
 
The Ring programming language version 1.9 book - Part 65 of 210
The Ring programming language version 1.9 book - Part 65 of 210The Ring programming language version 1.9 book - Part 65 of 210
The Ring programming language version 1.9 book - Part 65 of 210Mahmoud Samir Fayed
 
Run Or Walk In The Rain? (Orthogonal Projected Area of Ellipsoid)
Run Or Walk In The Rain? (Orthogonal Projected Area of Ellipsoid)Run Or Walk In The Rain? (Orthogonal Projected Area of Ellipsoid)
Run Or Walk In The Rain? (Orthogonal Projected Area of Ellipsoid)iosrjce
 
D3 svg & angular
D3 svg & angularD3 svg & angular
D3 svg & angular500Tech
 
3D Transformation
3D Transformation3D Transformation
3D TransformationSwatiHans10
 
Pertemuan 2 analisis vektor dan kinematika
Pertemuan 2   analisis vektor dan kinematikaPertemuan 2   analisis vektor dan kinematika
Pertemuan 2 analisis vektor dan kinematikaatikah ardi
 

Similar to Apply physics laws to the circles- When a circle hits one of the sides.pdf (20)

Tutorial Open GL (Listing Code)
Tutorial Open GL (Listing Code)Tutorial Open GL (Listing Code)
Tutorial Open GL (Listing Code)
 
#includefloat angle, move, scene, roadmove,turn, on=1; int i, st.docx
#includefloat angle, move, scene, roadmove,turn, on=1; int i, st.docx#includefloat angle, move, scene, roadmove,turn, on=1; int i, st.docx
#includefloat angle, move, scene, roadmove,turn, on=1; int i, st.docx
 
draw a sphere and use raytracing on the sphere in OpenGL glut. .pdf
 draw a sphere and use raytracing on the sphere in OpenGL glut. .pdf draw a sphere and use raytracing on the sphere in OpenGL glut. .pdf
draw a sphere and use raytracing on the sphere in OpenGL glut. .pdf
 
An object that moves in a circle A c++ program to check if the gi.pdf
An object that moves in a circle A c++ program to check if the gi.pdfAn object that moves in a circle A c++ program to check if the gi.pdf
An object that moves in a circle A c++ program to check if the gi.pdf
 
Ujug07presentation
Ujug07presentationUjug07presentation
Ujug07presentation
 
Image Compression Comparison Using Golden Section Transform, CDF 5/3 (Le Gall...
Image Compression Comparison Using Golden Section Transform, CDF 5/3 (Le Gall...Image Compression Comparison Using Golden Section Transform, CDF 5/3 (Le Gall...
Image Compression Comparison Using Golden Section Transform, CDF 5/3 (Le Gall...
 
10CSL67 CG LAB PROGRAM 3
10CSL67 CG LAB PROGRAM 310CSL67 CG LAB PROGRAM 3
10CSL67 CG LAB PROGRAM 3
 
Robot Motion Source code
Robot Motion Source codeRobot Motion Source code
Robot Motion Source code
 
computer graphics slides by Talha shah
computer graphics slides by Talha shahcomputer graphics slides by Talha shah
computer graphics slides by Talha shah
 
tetris
tetristetris
tetris
 
The Ring programming language version 1.5.3 book - Part 65 of 184
The Ring programming language version 1.5.3 book - Part 65 of 184The Ring programming language version 1.5.3 book - Part 65 of 184
The Ring programming language version 1.5.3 book - Part 65 of 184
 
CG OpenGL Shadows + Light + Texture -course 10
CG OpenGL Shadows + Light + Texture -course 10CG OpenGL Shadows + Light + Texture -course 10
CG OpenGL Shadows + Light + Texture -course 10
 
Iyarkanitham
Iyarkanitham Iyarkanitham
Iyarkanitham
 
The Ring programming language version 1.9 book - Part 65 of 210
The Ring programming language version 1.9 book - Part 65 of 210The Ring programming language version 1.9 book - Part 65 of 210
The Ring programming language version 1.9 book - Part 65 of 210
 
Run Or Walk In The Rain? (Orthogonal Projected Area of Ellipsoid)
Run Or Walk In The Rain? (Orthogonal Projected Area of Ellipsoid)Run Or Walk In The Rain? (Orthogonal Projected Area of Ellipsoid)
Run Or Walk In The Rain? (Orthogonal Projected Area of Ellipsoid)
 
D3 svg & angular
D3 svg & angularD3 svg & angular
D3 svg & angular
 
OpenGL 3D Drawing
OpenGL 3D DrawingOpenGL 3D Drawing
OpenGL 3D Drawing
 
3D Transformation
3D Transformation3D Transformation
3D Transformation
 
Programming with OpenGL
Programming with OpenGLProgramming with OpenGL
Programming with OpenGL
 
Pertemuan 2 analisis vektor dan kinematika
Pertemuan 2   analisis vektor dan kinematikaPertemuan 2   analisis vektor dan kinematika
Pertemuan 2 analisis vektor dan kinematika
 

More from EricG3KColemanf

As of December 31-2022 - Oriole Company has assets of $41900 and stock.pdf
As of December 31-2022 - Oriole Company has assets of $41900 and stock.pdfAs of December 31-2022 - Oriole Company has assets of $41900 and stock.pdf
As of December 31-2022 - Oriole Company has assets of $41900 and stock.pdfEricG3KColemanf
 
As for how to build the tree- you can follow the steps selow- 1- Creat.pdf
As for how to build the tree- you can follow the steps selow- 1- Creat.pdfAs for how to build the tree- you can follow the steps selow- 1- Creat.pdf
As for how to build the tree- you can follow the steps selow- 1- Creat.pdfEricG3KColemanf
 
As the COVID-19 pandemic progresses- we are seeing dramatic increases.pdf
As the COVID-19 pandemic progresses- we are seeing dramatic increases.pdfAs the COVID-19 pandemic progresses- we are seeing dramatic increases.pdf
As the COVID-19 pandemic progresses- we are seeing dramatic increases.pdfEricG3KColemanf
 
As a manager- you need to have a firm understanding of the revenue cyc.pdf
As a manager- you need to have a firm understanding of the revenue cyc.pdfAs a manager- you need to have a firm understanding of the revenue cyc.pdf
As a manager- you need to have a firm understanding of the revenue cyc.pdfEricG3KColemanf
 
arise(s) from differences in customs- social norms- attitudes- assumpt.pdf
arise(s) from differences in customs- social norms- attitudes- assumpt.pdfarise(s) from differences in customs- social norms- attitudes- assumpt.pdf
arise(s) from differences in customs- social norms- attitudes- assumpt.pdfEricG3KColemanf
 
arrange the leaf nodes is such a way so that there is i) minimum numbe.pdf
arrange the leaf nodes is such a way so that there is i) minimum numbe.pdfarrange the leaf nodes is such a way so that there is i) minimum numbe.pdf
arrange the leaf nodes is such a way so that there is i) minimum numbe.pdfEricG3KColemanf
 
Assign the correct ICD-10-CM-PCS codes to the following exercises Iron.pdf
Assign the correct ICD-10-CM-PCS codes to the following exercises Iron.pdfAssign the correct ICD-10-CM-PCS codes to the following exercises Iron.pdf
Assign the correct ICD-10-CM-PCS codes to the following exercises Iron.pdfEricG3KColemanf
 
ART I - Data Transformations 1- Transform the following values into de.pdf
ART I - Data Transformations 1- Transform the following values into de.pdfART I - Data Transformations 1- Transform the following values into de.pdf
ART I - Data Transformations 1- Transform the following values into de.pdfEricG3KColemanf
 
Assets Debit Credit Cash 214-320 Investments 491-000 Taxes receivable-.pdf
Assets Debit Credit Cash 214-320 Investments 491-000 Taxes receivable-.pdfAssets Debit Credit Cash 214-320 Investments 491-000 Taxes receivable-.pdf
Assets Debit Credit Cash 214-320 Investments 491-000 Taxes receivable-.pdfEricG3KColemanf
 
Arnold Corporation has the following information for the current year-.pdf
Arnold Corporation has the following information for the current year-.pdfArnold Corporation has the following information for the current year-.pdf
Arnold Corporation has the following information for the current year-.pdfEricG3KColemanf
 
Artificial Intelligence Study the step-by-step codes for a one layer o.pdf
Artificial Intelligence Study the step-by-step codes for a one layer o.pdfArtificial Intelligence Study the step-by-step codes for a one layer o.pdf
Artificial Intelligence Study the step-by-step codes for a one layer o.pdfEricG3KColemanf
 
Assembly Language question- The Boolean variables b1 - b2- and b3 ar.pdf
Assembly Language question-   The Boolean variables b1 - b2- and b3 ar.pdfAssembly Language question-   The Boolean variables b1 - b2- and b3 ar.pdf
Assembly Language question- The Boolean variables b1 - b2- and b3 ar.pdfEricG3KColemanf
 
At December 31-2020 - Ivanhoe Company has $570-000 of $100 par value-.pdf
At December 31-2020 - Ivanhoe Company has $570-000 of $100 par value-.pdfAt December 31-2020 - Ivanhoe Company has $570-000 of $100 par value-.pdf
At December 31-2020 - Ivanhoe Company has $570-000 of $100 par value-.pdfEricG3KColemanf
 
at S40-000- A total of 15-750 poundt were used in producing the boudde.pdf
at S40-000- A total of 15-750 poundt were used in producing the boudde.pdfat S40-000- A total of 15-750 poundt were used in producing the boudde.pdf
at S40-000- A total of 15-750 poundt were used in producing the boudde.pdfEricG3KColemanf
 
At Eileen's death- Winthrop received the death benefit payable under E.pdf
At Eileen's death- Winthrop received the death benefit payable under E.pdfAt Eileen's death- Winthrop received the death benefit payable under E.pdf
At Eileen's death- Winthrop received the death benefit payable under E.pdfEricG3KColemanf
 
At December 31- balances in Manufacturing Overhead are Ivanhoe Company.pdf
At December 31- balances in Manufacturing Overhead are Ivanhoe Company.pdfAt December 31- balances in Manufacturing Overhead are Ivanhoe Company.pdf
At December 31- balances in Manufacturing Overhead are Ivanhoe Company.pdfEricG3KColemanf
 
Astronomy questions help 1) What planetary time association is conside.pdf
Astronomy questions help 1) What planetary time association is conside.pdfAstronomy questions help 1) What planetary time association is conside.pdf
Astronomy questions help 1) What planetary time association is conside.pdfEricG3KColemanf
 
Ascientist inoculates mice- one at a time- with a disease germ until h.pdf
Ascientist inoculates mice- one at a time- with a disease germ until h.pdfAscientist inoculates mice- one at a time- with a disease germ until h.pdf
Ascientist inoculates mice- one at a time- with a disease germ until h.pdfEricG3KColemanf
 
Astronomy questions help please 5) According to the Maya- Venus' cyc.pdf
Astronomy questions help please   5) According to the Maya- Venus' cyc.pdfAstronomy questions help please   5) According to the Maya- Venus' cyc.pdf
Astronomy questions help please 5) According to the Maya- Venus' cyc.pdfEricG3KColemanf
 
asdoon- coum now many times 'a' and T appear in your sting.pdf
asdoon- coum now many times 'a' and T appear in your sting.pdfasdoon- coum now many times 'a' and T appear in your sting.pdf
asdoon- coum now many times 'a' and T appear in your sting.pdfEricG3KColemanf
 

More from EricG3KColemanf (20)

As of December 31-2022 - Oriole Company has assets of $41900 and stock.pdf
As of December 31-2022 - Oriole Company has assets of $41900 and stock.pdfAs of December 31-2022 - Oriole Company has assets of $41900 and stock.pdf
As of December 31-2022 - Oriole Company has assets of $41900 and stock.pdf
 
As for how to build the tree- you can follow the steps selow- 1- Creat.pdf
As for how to build the tree- you can follow the steps selow- 1- Creat.pdfAs for how to build the tree- you can follow the steps selow- 1- Creat.pdf
As for how to build the tree- you can follow the steps selow- 1- Creat.pdf
 
As the COVID-19 pandemic progresses- we are seeing dramatic increases.pdf
As the COVID-19 pandemic progresses- we are seeing dramatic increases.pdfAs the COVID-19 pandemic progresses- we are seeing dramatic increases.pdf
As the COVID-19 pandemic progresses- we are seeing dramatic increases.pdf
 
As a manager- you need to have a firm understanding of the revenue cyc.pdf
As a manager- you need to have a firm understanding of the revenue cyc.pdfAs a manager- you need to have a firm understanding of the revenue cyc.pdf
As a manager- you need to have a firm understanding of the revenue cyc.pdf
 
arise(s) from differences in customs- social norms- attitudes- assumpt.pdf
arise(s) from differences in customs- social norms- attitudes- assumpt.pdfarise(s) from differences in customs- social norms- attitudes- assumpt.pdf
arise(s) from differences in customs- social norms- attitudes- assumpt.pdf
 
arrange the leaf nodes is such a way so that there is i) minimum numbe.pdf
arrange the leaf nodes is such a way so that there is i) minimum numbe.pdfarrange the leaf nodes is such a way so that there is i) minimum numbe.pdf
arrange the leaf nodes is such a way so that there is i) minimum numbe.pdf
 
Assign the correct ICD-10-CM-PCS codes to the following exercises Iron.pdf
Assign the correct ICD-10-CM-PCS codes to the following exercises Iron.pdfAssign the correct ICD-10-CM-PCS codes to the following exercises Iron.pdf
Assign the correct ICD-10-CM-PCS codes to the following exercises Iron.pdf
 
ART I - Data Transformations 1- Transform the following values into de.pdf
ART I - Data Transformations 1- Transform the following values into de.pdfART I - Data Transformations 1- Transform the following values into de.pdf
ART I - Data Transformations 1- Transform the following values into de.pdf
 
Assets Debit Credit Cash 214-320 Investments 491-000 Taxes receivable-.pdf
Assets Debit Credit Cash 214-320 Investments 491-000 Taxes receivable-.pdfAssets Debit Credit Cash 214-320 Investments 491-000 Taxes receivable-.pdf
Assets Debit Credit Cash 214-320 Investments 491-000 Taxes receivable-.pdf
 
Arnold Corporation has the following information for the current year-.pdf
Arnold Corporation has the following information for the current year-.pdfArnold Corporation has the following information for the current year-.pdf
Arnold Corporation has the following information for the current year-.pdf
 
Artificial Intelligence Study the step-by-step codes for a one layer o.pdf
Artificial Intelligence Study the step-by-step codes for a one layer o.pdfArtificial Intelligence Study the step-by-step codes for a one layer o.pdf
Artificial Intelligence Study the step-by-step codes for a one layer o.pdf
 
Assembly Language question- The Boolean variables b1 - b2- and b3 ar.pdf
Assembly Language question-   The Boolean variables b1 - b2- and b3 ar.pdfAssembly Language question-   The Boolean variables b1 - b2- and b3 ar.pdf
Assembly Language question- The Boolean variables b1 - b2- and b3 ar.pdf
 
At December 31-2020 - Ivanhoe Company has $570-000 of $100 par value-.pdf
At December 31-2020 - Ivanhoe Company has $570-000 of $100 par value-.pdfAt December 31-2020 - Ivanhoe Company has $570-000 of $100 par value-.pdf
At December 31-2020 - Ivanhoe Company has $570-000 of $100 par value-.pdf
 
at S40-000- A total of 15-750 poundt were used in producing the boudde.pdf
at S40-000- A total of 15-750 poundt were used in producing the boudde.pdfat S40-000- A total of 15-750 poundt were used in producing the boudde.pdf
at S40-000- A total of 15-750 poundt were used in producing the boudde.pdf
 
At Eileen's death- Winthrop received the death benefit payable under E.pdf
At Eileen's death- Winthrop received the death benefit payable under E.pdfAt Eileen's death- Winthrop received the death benefit payable under E.pdf
At Eileen's death- Winthrop received the death benefit payable under E.pdf
 
At December 31- balances in Manufacturing Overhead are Ivanhoe Company.pdf
At December 31- balances in Manufacturing Overhead are Ivanhoe Company.pdfAt December 31- balances in Manufacturing Overhead are Ivanhoe Company.pdf
At December 31- balances in Manufacturing Overhead are Ivanhoe Company.pdf
 
Astronomy questions help 1) What planetary time association is conside.pdf
Astronomy questions help 1) What planetary time association is conside.pdfAstronomy questions help 1) What planetary time association is conside.pdf
Astronomy questions help 1) What planetary time association is conside.pdf
 
Ascientist inoculates mice- one at a time- with a disease germ until h.pdf
Ascientist inoculates mice- one at a time- with a disease germ until h.pdfAscientist inoculates mice- one at a time- with a disease germ until h.pdf
Ascientist inoculates mice- one at a time- with a disease germ until h.pdf
 
Astronomy questions help please 5) According to the Maya- Venus' cyc.pdf
Astronomy questions help please   5) According to the Maya- Venus' cyc.pdfAstronomy questions help please   5) According to the Maya- Venus' cyc.pdf
Astronomy questions help please 5) According to the Maya- Venus' cyc.pdf
 
asdoon- coum now many times 'a' and T appear in your sting.pdf
asdoon- coum now many times 'a' and T appear in your sting.pdfasdoon- coum now many times 'a' and T appear in your sting.pdf
asdoon- coum now many times 'a' and T appear in your sting.pdf
 

Recently uploaded

Sternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading RoomSternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading RoomSean M. Fox
 
Book Review of Run For Your Life Powerpoint
Book Review of Run For Your Life PowerpointBook Review of Run For Your Life Powerpoint
Book Review of Run For Your Life Powerpoint23600690
 
OSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsOSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsSandeep D Chaudhary
 
An Overview of the Odoo 17 Knowledge App
An Overview of the Odoo 17 Knowledge AppAn Overview of the Odoo 17 Knowledge App
An Overview of the Odoo 17 Knowledge AppCeline George
 
male presentation...pdf.................
male presentation...pdf.................male presentation...pdf.................
male presentation...pdf.................MirzaAbrarBaig5
 
PSYPACT- Practicing Over State Lines May 2024.pptx
PSYPACT- Practicing Over State Lines May 2024.pptxPSYPACT- Practicing Over State Lines May 2024.pptx
PSYPACT- Practicing Over State Lines May 2024.pptxMarlene Maheu
 
Personalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes GuàrdiaPersonalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes GuàrdiaEADTU
 
AIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.pptAIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.pptNishitharanjan Rout
 
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...EADTU
 
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSSpellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSAnaAcapella
 
Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...EduSkills OECD
 
Graduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptxGraduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptxneillewis46
 
Basic Civil Engineering notes on Transportation Engineering & Modes of Transport
Basic Civil Engineering notes on Transportation Engineering & Modes of TransportBasic Civil Engineering notes on Transportation Engineering & Modes of Transport
Basic Civil Engineering notes on Transportation Engineering & Modes of TransportDenish Jangid
 
An overview of the various scriptures in Hinduism
An overview of the various scriptures in HinduismAn overview of the various scriptures in Hinduism
An overview of the various scriptures in HinduismDabee Kamal
 
e-Sealing at EADTU by Kamakshi Rajagopal
e-Sealing at EADTU by Kamakshi Rajagopale-Sealing at EADTU by Kamakshi Rajagopal
e-Sealing at EADTU by Kamakshi RajagopalEADTU
 
SPLICE Working Group: Reusable Code Examples
SPLICE Working Group:Reusable Code ExamplesSPLICE Working Group:Reusable Code Examples
SPLICE Working Group: Reusable Code ExamplesPeter Brusilovsky
 
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...Nguyen Thanh Tu Collection
 

Recently uploaded (20)

Sternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading RoomSternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
 
Book Review of Run For Your Life Powerpoint
Book Review of Run For Your Life PowerpointBook Review of Run For Your Life Powerpoint
Book Review of Run For Your Life Powerpoint
 
OSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsOSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & Systems
 
An Overview of the Odoo 17 Knowledge App
An Overview of the Odoo 17 Knowledge AppAn Overview of the Odoo 17 Knowledge App
An Overview of the Odoo 17 Knowledge App
 
OS-operating systems- ch05 (CPU Scheduling) ...
OS-operating systems- ch05 (CPU Scheduling) ...OS-operating systems- ch05 (CPU Scheduling) ...
OS-operating systems- ch05 (CPU Scheduling) ...
 
male presentation...pdf.................
male presentation...pdf.................male presentation...pdf.................
male presentation...pdf.................
 
PSYPACT- Practicing Over State Lines May 2024.pptx
PSYPACT- Practicing Over State Lines May 2024.pptxPSYPACT- Practicing Over State Lines May 2024.pptx
PSYPACT- Practicing Over State Lines May 2024.pptx
 
Supporting Newcomer Multilingual Learners
Supporting Newcomer  Multilingual LearnersSupporting Newcomer  Multilingual Learners
Supporting Newcomer Multilingual Learners
 
Personalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes GuàrdiaPersonalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes Guàrdia
 
AIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.pptAIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.ppt
 
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
 
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSSpellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
 
Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...
 
Graduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptxGraduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptx
 
Basic Civil Engineering notes on Transportation Engineering & Modes of Transport
Basic Civil Engineering notes on Transportation Engineering & Modes of TransportBasic Civil Engineering notes on Transportation Engineering & Modes of Transport
Basic Civil Engineering notes on Transportation Engineering & Modes of Transport
 
Mattingly "AI and Prompt Design: LLMs with NER"
Mattingly "AI and Prompt Design: LLMs with NER"Mattingly "AI and Prompt Design: LLMs with NER"
Mattingly "AI and Prompt Design: LLMs with NER"
 
An overview of the various scriptures in Hinduism
An overview of the various scriptures in HinduismAn overview of the various scriptures in Hinduism
An overview of the various scriptures in Hinduism
 
e-Sealing at EADTU by Kamakshi Rajagopal
e-Sealing at EADTU by Kamakshi Rajagopale-Sealing at EADTU by Kamakshi Rajagopal
e-Sealing at EADTU by Kamakshi Rajagopal
 
SPLICE Working Group: Reusable Code Examples
SPLICE Working Group:Reusable Code ExamplesSPLICE Working Group:Reusable Code Examples
SPLICE Working Group: Reusable Code Examples
 
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
 

Apply physics laws to the circles- When a circle hits one of the sides.pdf

  • 1. Apply physics laws to the circles . When a circle hits one of the sides of the screen, its progress should be altered in some way. While the circles currently move at a constant speed and have randomized movement once they bounce off one edge of the screen, there are ways you can alter this to make the animation more engaging. Some options you may wish to use for your work are as follows, but you do not need to complete all of these. You can also try an idea of your own instead. Alter the speed of the circle. Change the angle of trajectory so it follows physics laws instead of taking a randomized pattern. (This means it would continue in the direction it was heading rather than moving backward.) Add friction to specific surfaces, which would affect the circle and slow its progress once it collided with the surface. PLEASE USE GIVEN CODE BELOW WITH NO ADDITIONAL LIBRARIES #include <GLFWglfw3.h> #include "linmath.h" #include <stdlib.h> #include <stdio.h> #include <conio.h> #include <iostream> #include <vector> #include <windows.h> #include <time.h> using namespace std; const float DEG2RAD = 3.14159 / 180; void processInput(GLFWwindow* window); enum BRICKTYPE { REFLECTIVE, DESTRUCTABLE }; enum ONOFF { ON, OFF }; class Brick { public: float red, green, blue; float x, y, width; BRICKTYPE brick_type; ONOFF onoff; Brick(BRICKTYPE bt, float xx, float yy, float ww, float rr, float gg, float bb) {
  • 2. brick_type = bt; x = xx; y = yy, width = ww; red = rr, green = gg, blue = bb; onoff = ON; }; 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; }
  • 3. void CheckCollision(Brick* brk) { if (brk->brick_type == REFLECTIVE) { if ((x > brk->x - brk->width && x <= brk->x + brk->width) && (y > brk->y - brk->width && y <= brk->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 <= brk->x + brk->width) && (y > brk->y - brk->width && y <= brk->y + brk->width)) { brk->onoff = OFF; } } } 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 < 1 - radius) { x += speed;
  • 4. } else { direction = GetDirection(); } } if (direction == 3 || direction == 7 || direction == 8) // down { if (y < 1 - radius) { y += speed; } else { direction = GetDirection(); } } 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 < 360; i++) { float degInRad = i * DEG2RAD; glVertex2f((cos(degInRad) * radius) + x, (sin(degInRad) * radius) + y); } glEnd(); } }; vector<Circle> world;
  • 5. 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 < world.size(); i++) { world[i].CheckCollision(&brick); world[i].CheckCollision(&brick2); world[i].CheckCollision(&brick3); world[i].CheckCollision(&brick4); world[i].CheckCollision(&brick5); world[i].CheckCollision(&brick6);
  • 6. world[i].MoveOneStep(); world[i].DrawCircle(); } 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 (glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS) glfwSetWindowShouldClose(window, true); if (glfwGetKey(window, GLFW_KEY_SPACE) == GLFW_PRESS) { double r, g, b; r = rand() / 10000; g = rand() / 10000; b = rand() / 10000; Circle B(0, 0, 02, 2, 0.05, r, g, b); world.push_back(B); } }