Skip to content

Commit

Permalink
IDK
Browse files Browse the repository at this point in the history
  • Loading branch information
DistortedDragon1o4 committed Feb 28, 2022
0 parents commit 6248548
Show file tree
Hide file tree
Showing 13 changed files with 1,239 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
build/
.vscode/
2D_Ball_Physics*
674 changes: 674 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

29 changes: 29 additions & 0 deletions Makefile
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
53 changes: 53 additions & 0 deletions README.md
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`
38 changes: 38 additions & 0 deletions include/physics.h
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
11 changes: 11 additions & 0 deletions shaders/ball_fragment.glsl
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;
}
)"
16 changes: 16 additions & 0 deletions shaders/ball_vertex.glsl
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;
}
)"
11 changes: 11 additions & 0 deletions shaders/env_fragment.glsl
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);
}
)"
15 changes: 15 additions & 0 deletions shaders/env_vertex.glsl
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 added src/glad/glad
Binary file not shown.
Binary file added src/glad/glad_windows
Binary file not shown.
Loading

0 comments on commit 6248548

Please sign in to comment.