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 <GLFW\glfw3.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 =.
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;