TRying to make docker worky worky

This commit is contained in:
2024-07-12 17:42:54 +02:00
parent 46d37ab529
commit 796c34e9a0
4 changed files with 114 additions and 16 deletions
+6 -1
View File
@@ -3,6 +3,12 @@ project(gravity)
set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD 17)
# Use vcpkg
if(DEFINED ENV{VCPKG_ROOT} AND NOT DEFINED CMAKE_TOOLCHAIN_FILE)
set(CMAKE_TOOLCHAIN_FILE "$ENV{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake"
CACHE STRING "Vcpkg toolchain file")
endif()
# Find packages # Find packages
find_package(OpenGL REQUIRED) find_package(OpenGL REQUIRED)
find_package(GLEW REQUIRED) find_package(GLEW REQUIRED)
@@ -31,7 +37,6 @@ target_link_libraries(gravity PRIVATE
glm::glm glm::glm
) )
# On some systems, you might need to explicitly link against OpenGL
if(UNIX AND NOT APPLE) if(UNIX AND NOT APPLE)
target_link_libraries(gravity PRIVATE GL) target_link_libraries(gravity PRIVATE GL)
endif() endif()
+44
View File
@@ -0,0 +1,44 @@
FROM ubuntu:20.04
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update && apt-get install -y \
build-essential \
cmake \
git \
curl \
zip \
unzip \
tar \
pkg-config \
libx11-dev \
libxrandr-dev \
libxinerama-dev \
libxcursor-dev \
libxi-dev \
libgl1-mesa-dev \
libglu1-mesa-dev \
&& rm -rf /var/lib/apt/lists/*
# Install vcpkg
RUN git clone https://github.com/Microsoft/vcpkg.git /vcpkg \
&& /vcpkg/bootstrap-vcpkg.sh \
&& /vcpkg/vcpkg integrate install
# Set the working directory
WORKDIR /app
# Copy the project files
COPY . .
# Install dependencies using vcpkg
RUN /vcpkg/vcpkg install $(cat vcpkg.json | jq -r '.dependencies[]')
# Build the project
RUN mkdir build \
&& cd build \
&& cmake .. -DCMAKE_TOOLCHAIN_FILE=/vcpkg/scripts/buildsystems/vcpkg.cmake \
&& cmake --build .
# Set the entrypoint
CMD ["./build/gravity"]
+47
View File
@@ -66,3 +66,50 @@ The program uses OpenGL to render the 3D scene:
3. The scale of the celestial bodies and their distances are not to true scale to make visualization easier. 3. The scale of the celestial bodies and their distances are not to true scale to make visualization easier.
4. Relativistic effects are not considered; the simulation uses classical Newtonian mechanics. 4. Relativistic effects are not considered; the simulation uses classical Newtonian mechanics.
# How to Use & Installation
### Prerequisites
- C++ compiler with C++17 support
- CMake (version 3.10 or higher)
- OpenGL libraries
- GLFW3
- GLM (OpenGL Mathematics)
- vcpkg (for managing dependencies)
### Building from Source
1. Clone the repository:
```bash
git clone https://github.com/Quinta0/gravity.git
cd gravity
```
2. Install vcpkg and dependencies:
```bash
git clone https://github.com/Microsoft/vcpkg.git
./vcpkg/bootstrap-vcpkg.sh # On Windows, use bootstrap-vcpkg.bat
./vcpkg/vcpkg install
```
3. Create a build directory and navigate to it:
```bash
mkdir build
cd build
```
4. Generate the build files with CMake:
```bash
cmake .. -DCMAKE_TOOLCHAIN_FILE=../vcpkg/scripts/buildsystems/vcpkg.cmake
```
5. Build the project:
```bash
cmake --build .
```
6. Run the simulator:
```bash
./gravity
```
### Using Docker
If you prefer to use Docker, follow these steps:
1. Ensure Docker is installed on your system.
2. Build the Docker image:
+17 -15
View File
@@ -90,13 +90,13 @@ void Renderer::render(const Simulator& simulator) {
minMass = std::min(minMass, body.getMass()); minMass = std::min(minMass, body.getMass());
} }
std::cout << "Camera position: " << cameraPos.x << ", " << cameraPos.y << ", " << cameraPos.z << std::endl; //std::cout << "Camera position: " << cameraPos.x << ", " << cameraPos.y << ", " << cameraPos.z << std::endl;
std::cout << "Camera front: " << cameraFront.x << ", " << cameraFront.y << ", " << cameraFront.z << std::endl; //std::cout << "Camera front: " << cameraFront.x << ", " << cameraFront.y << ", " << cameraFront.z << std::endl;
for (size_t i = 0; i < bodies.size(); ++i) { for (size_t i = 0; i < bodies.size(); ++i) {
const auto& body = bodies[i]; const auto& body = bodies[i];
glm::dvec3 pos = body.getPosition(); glm::dvec3 pos = body.getPosition();
std::cout << "Body " << i << " position: " << pos.x << ", " << pos.y << ", " << pos.z << std::endl; //std::cout << "Body " << i << " position: " << pos.x << ", " << pos.y << ", " << pos.z << std::endl;
} }
// Calculate the log range // Calculate the log range
@@ -117,18 +117,18 @@ void Renderer::render(const Simulator& simulator) {
glm::dvec3 pos = body.getPosition(); glm::dvec3 pos = body.getPosition();
glm::vec3 renderPos(static_cast<float>(pos.x), static_cast<float>(pos.y), static_cast<float>(pos.z)); glm::vec3 renderPos(static_cast<float>(pos.x), static_cast<float>(pos.y), static_cast<float>(pos.z));
std::cout << "Rendering body " << i << " ("; // std::cout << "Rendering body " << i << " (";
switch(i) { // switch(i) {
case 0: std::cout << "Sun"; break; // case 0: std::cout << "Sun"; break;
case 1: std::cout << "Mercury"; break; // case 1: std::cout << "Mercury"; break;
case 2: std::cout << "Venus"; break; // case 2: std::cout << "Venus"; break;
case 3: std::cout << "Earth"; break; // case 3: std::cout << "Earth"; break;
case 4: std::cout << "Mars"; break; // case 4: std::cout << "Mars"; break;
default: std::cout << "Unknown"; break; // default: std::cout << "Unknown"; break;
} // }
std::cout << ") at position (" // std::cout << ") at position ("
<< pos.x << ", " << pos.y << ", " << pos.z // << pos.x << ", " << pos.y << ", " << pos.z
<< ") with scale " << scaleFactor << std::endl; // << ") with scale " << scaleFactor << std::endl;
// Set color based on body index // Set color based on body index
switch(i) { switch(i) {
@@ -325,6 +325,8 @@ void Renderer::processInput() {
cameraPos -= right * cameraSpeed; cameraPos -= right * cameraSpeed;
if (glfwGetKey(window, GLFW_KEY_D) == GLFW_PRESS) if (glfwGetKey(window, GLFW_KEY_D) == GLFW_PRESS)
cameraPos += right * cameraSpeed; cameraPos += right * cameraSpeed;
if (glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS)
glfwSetWindowShouldClose(window, true);
} }
void Renderer::cursorPosCallback(GLFWwindow* window, double xpos, double ypos) { void Renderer::cursorPosCallback(GLFWwindow* window, double xpos, double ypos) {