-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
DistortedDragon1o4
committed
Feb 28, 2022
0 parents
commit 6248548
Showing
13 changed files
with
1,239 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
build/ | ||
.vscode/ | ||
2D_Ball_Physics* |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
all: clean ball-physics ball-physics-windows move | ||
|
||
CFLAGS = -std=c++17 | ||
LDFLAGS = -lglfw -lGLU -lGL -ldl -lpthread -lX11 -lXrandr | ||
WDFLAGS = -lglfw3dll -lopengl32 -lwinpthread -static-libstdc++ -static-libgcc | ||
SRC = src/ | ||
|
||
ball-physics: $(SRC)main.cpp | ||
g++ $(CFLAGS) -o 2D_Ball_Physics $(SRC)main.cpp $(SRC)physics.cpp $(SRC)glad/glad -I include -I shaders $(LDFLAGS) | ||
|
||
move: | ||
mkdir build | ||
cp 2D_Ball_Physics build | ||
cp 2D_Ball_Physics.exe build | ||
|
||
install: | ||
mkdir build | ||
|
||
run: | ||
./build/2D_Ball_Physics | ||
|
||
ball-physics-windows: $(SRC)main.cpp | ||
x86_64-w64-mingw32-g++ $(CFLAGS) -o 2D_Ball_Physics.exe $(SRC)main.cpp $(SRC)physics.cpp $(SRC)glad/glad_windows -I include -I shaders $(WDFLAGS) | ||
|
||
run-windows: | ||
wine build/2D_Ball_Physics.exe | ||
|
||
clean: | ||
rm -r build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# 2D Ball Physics | ||
|
||
![GitHub license](https://img.shields.io/github/license/DistortedDragon1o4/2D-Ball-Physics.svg) | ||
![GitHub issues](https://img.shields.io/github/issues/DistortedDragon1o4/2D-Ball-Physics.svg) | ||
![GitHub stars](https://img.shields.io/github/stars/DistortedDragon1o4/ball-physics) | ||
|
||
This is a free and opensource 2D physics simulation made by me just for testing purposes only. | ||
|
||
:warning: | ||
This is for testing and experimentation only and I am not liable if you break anything while using this. | ||
|
||
## Downloading: | ||
|
||
|
||
![GitHub release](https://img.shields.io/github/release/DistortedDragon1o4/2D-Ball-Physics.svg) | ||
![GitHub forks](https://img.shields.io/github/forks/DistortedDragon1o4/ball-physics) | ||
|
||
You can download the executable for GNU/Linux and Windows from the GitHub Releases page. | ||
|
||
## Running: | ||
|
||
### For GNU/Linux based systems: | ||
|
||
Open a Terminal and run `./2D-Ball-Physics` in the directory where you have kept it. | ||
|
||
Make sure your graphics drivers are up to date. (You need atleast OpenGL 4.6 to be able to run it) | ||
|
||
### For Windows based systems: | ||
|
||
Download and install the glfw3.dll file from the releases page. | ||
|
||
Double click the exe to run it. | ||
|
||
(I dont have a windows system so cant confirm if it works) | ||
|
||
## Building from source: | ||
|
||
### For GNU/Linux based systems: | ||
|
||
#### Requirements: | ||
|
||
This project uses make, and you are required to have it installed. Also you will need the following build dependencies: | ||
- `libgl1-mesa-dev` | ||
- `libglfw3-dev` | ||
- `libglm-dev` | ||
|
||
#### Building the project: | ||
|
||
To build the project: | ||
`make build` | ||
|
||
To run the project: | ||
`make run` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#ifndef PHYSICS_CLASS_H | ||
#define PHYSICS_CLASS_H | ||
|
||
#define GLM_ENABLE_EXPERIMENTAL | ||
|
||
#define SEGMENTS 90 | ||
#define OBJ_RADIUS 0.03 | ||
|
||
#define PI atan(1) * 4 | ||
|
||
#include <vector> | ||
#include <math.h> | ||
#include <glm/glm.hpp> | ||
#include <glm/gtx/rotate_vector.hpp> | ||
|
||
class Physics { | ||
public: | ||
float mass; | ||
glm::vec2 gravity; | ||
glm::vec2 resultant; | ||
glm::vec2 velocity; | ||
glm::vec2 Pos; | ||
|
||
std::vector<float> mesh; | ||
std::vector<glm::vec2> points; | ||
std::vector<glm::vec2> normals; | ||
std::vector<glm::vec2> pointNormals; | ||
|
||
void generateMesh(); | ||
void generateMeshPoints(); | ||
void doPhysicsTick(); | ||
void generateNormals(); | ||
void fixClipping(int pointIndex); | ||
float getDistanceFromOBJ(int pointIndex); | ||
float getLineDistance(int pointIndex); | ||
}; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
R"( | ||
#version 460 core | ||
|
||
in vec4 FinalColor; | ||
|
||
out vec4 FragColor; | ||
|
||
void main() { | ||
FragColor = FinalColor; | ||
} | ||
)" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
R"( | ||
#version 460 core | ||
|
||
layout (location = 0) in vec3 aPos; | ||
|
||
uniform vec2 Pos; | ||
uniform vec4 Color; | ||
|
||
out vec4 FinalColor; | ||
|
||
void main() { | ||
//vec2 Pos = {sin(Data.x) * Data.y, cos(Data.x) * Data.y}; | ||
gl_Position = vec4(aPos.x + Pos.x, aPos.y + Pos.y, aPos.z, 1.0); | ||
FinalColor = Color; | ||
} | ||
)" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
R"( | ||
#version 460 core | ||
|
||
//in vec4 FinalColor; | ||
|
||
out vec4 FragColor; | ||
|
||
void main() { | ||
FragColor = vec4(0.0f, 0.0f, 0.0f, 1.0f); | ||
} | ||
)" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
R"( | ||
#version 460 core | ||
|
||
layout (location = 0) in vec2 aPos; | ||
|
||
//uniform vec4 Color; | ||
|
||
//out vec4 FinalColor; | ||
|
||
void main() { | ||
//vec2 Pos = {sin(Data.x) * Data.y, cos(Data.x) * Data.y}; | ||
gl_Position = vec4(aPos.x, aPos.y, 0.0f, 1.0f); | ||
FinalColor = Color; | ||
} | ||
)" |
Binary file not shown.
Binary file not shown.
Oops, something went wrong.