Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 72 additions & 0 deletions .github/workflows/ci-cd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
name: C++ CI/CD

on: [push, pull_request]

jobs:
build-and-test:
runs-on: ubuntu-latest # You can also use windows-latest or macos-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Install Google Test (GTest)
run: |
sudo apt-get update
sudo apt-get install libgtest-dev cmake -y
cd /usr/src/gtest
sudo cmake .
sudo make
sudo cp lib/*.a /usr/lib

- name: Create Build Directory
shell: bash
working-directory: ${{github.workspace}}
run: mkdir build

- name: Configure CMake
shell: bash
working-directory: ${{github.workspace}}/build
run: cmake ..

- name: Build Project
shell: bash
working-directory: ${{github.workspace}}/build
run: cmake --build .

- name: Run Tests
shell: bash
working-directory: ${{github.workspace}}/build
run: ./run_test

# release:
# needs: build-and-test
# if: github.event_name == 'push' && github.ref == 'refs/heads/master'
# runs-on: ubuntu-latest

# steps:
# - name: Checkout code
# uses: actions/checkout@v4

# - name: Create Release
# id: create_release
# uses: actions/create-release@v1
# env:
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# with:
# tag_name: v${{ github.run_number }} # Example: v1, v2, etc. Or use a more sophisticated versioning
# release_name: Release v${{ github.run_number }}
# body: |
# Automated release based on successful CI/CD build.
# draft: false
# prerelease: false

# - name: Upload Release Asset
# uses: actions/upload-release-asset@v1
# env:
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# with:
# upload_url: ${{ steps.create_release.outputs.upload_url }}
# asset_path: ${{ github.workspace }}/build/my_app # Replace with the actual path to your build artifact
# asset_name: my_app_${{ github.run_number }} # Name for your release asset
# asset_content_type: application/octet-stream
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,9 @@
*.exe
*.out
*.app

# CMakes
build

# IDEs
.vscode
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ set(CMAKE_CXX_STANDARD_REQUIRED True)
include_directories(
sources
sources/math
sources/physic
includes
includes/math
includes/physic
)

file(GLOB_RECURSE SRCS
Expand Down
14 changes: 8 additions & 6 deletions includes/math/geometry.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@
#define GEOMETRY_HPP

#include <vector>
#include "object.hpp"
#include "vectors.hpp"
#include "quaternions.hpp"

// class Object;
class Object;

enum class GeometryType
{
Expand All @@ -15,6 +14,7 @@ enum class GeometryType

class Geometry
{
friend class Object;
protected:
Vec3 offset;
Quat4 rotation;
Expand All @@ -29,18 +29,20 @@ class Geometry

const Vec3 &GetLocalOffset() const { return offset; }
const Quat4 &GetLocalRotation() const { return rotation; }
Vec3 GetWorldCenter() const { return offset + object->GetPosition(); }
const Quat4 &GetWorldRotation() const { return (rotation * object->GetRotation()).Normalize(); }
Vec3 GetWorldCenter() const;
Quat4 GetWorldRotation() const;

void SetOwner(Object *obj) { object = obj; }

void SetLocalOffset(double _x, double _y, double _z)
{
this->offset.x = _x;
this->offset.y = _y;
this->offset.z = _z;
}
void SetLocalOffset(const Vec3 &new_offset)
void SetLocalOffset(const Vec3 &local_offset)
{
this->offset = new_offset;
offset = local_offset;
}
void SetLocalRotation(double _w, double _x, double _y, double _z)
{
Expand Down
16 changes: 12 additions & 4 deletions includes/math/quaternions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,26 @@ struct Quat4
{
double w, x, y, z;

Quat4() : w(0), x(0), y(0), z(0) {}
Quat4() : w(1), x(0), y(0), z(0) {}
Quat4(double _w, Vec3 axis) : w(_w)
{
Vec4 temp = Vec4(_w, axis.x, axis.y, axis.z).Normalize();
Vec4 temp = Vec4(_w, axis.x, axis.y, axis.z);
if (temp.IsZero())
temp.w = 1;
else
temp.Normalize();
w = temp.w;
x = temp.x;
y = temp.y;
z = temp.z;
}
Quat4(double _w, double _x, double _y, double _z)
{
Vec4 temp = Vec4(_w, _x, _y, _z).Normalize();
Vec4 temp = Vec4(_w, _x, _y, _z);
if (temp.IsZero())
temp.w = 1;
else
temp.Normalize();
w = temp.w;
x = temp.x;
y = temp.y;
Expand Down Expand Up @@ -57,7 +65,7 @@ struct Quat4

inline Quat4 operator+(Quat4 l, const Quat4 &r) { return l += r; }
inline Quat4 operator*(Quat4 l, const Quat4 &r) { return l *= r; }
inline Vec3 operator*(const Vec3& l, const Quat4 &Q)
inline Vec3 operator*(const Vec3 &l, const Quat4 &Q)
{
Quat4 P = Quat4(0, l);
Quat4 R = Q * P * -Q;
Expand Down
18 changes: 18 additions & 0 deletions includes/math/vectors.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ struct Vec3
}
constexpr Vec3 &Normalize()
{
if (this->IsZero())
{
return *this;
}
double length = sqrt(this->LengthSquared());
x /= length;
y /= length;
Expand Down Expand Up @@ -149,13 +153,27 @@ struct Vec4
}
constexpr Vec4 &Normalize()
{
if (this->IsZero())
return *this;
double length = sqrt(this->LengthSquared());
x /= length;
y /= length;
z /= length;
w /= length;
return *this;
}
bool IsZero() const
{
if (!(-EPSILON <= w && w <= EPSILON))
return false;
if (!(-EPSILON <= x && x <= EPSILON))
return false;
if (!(-EPSILON <= y && y <= EPSILON))
return false;
if (!(-EPSILON <= z && z <= EPSILON))
return false;
return true;
}
};

// Vector Product
Expand Down
31 changes: 0 additions & 31 deletions includes/object.hpp

This file was deleted.

24 changes: 24 additions & 0 deletions includes/physic/engine.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#ifndef ENGINE_HPP
#define ENGINE_HPP

#include "object.hpp"
#include "config.hpp"
#include <vector>
class Engine
{
private:
std::vector<Object> objectList;

public:
// Getting
const Object &GetObject(int id) const
{
return objectList[id];
}

// Adding
int AddObject(Object &&obj); // Change signature to take by value
void Step(double dt = 1.0 / FPS);
};

#endif
22 changes: 22 additions & 0 deletions includes/physic/force.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#ifndef FORCE_HPP
#define FORCE_HPP

#include "vectors.hpp"

struct Force
{
Vec3 offset;
Vec3 direction;

Force() : offset(Vec3()), direction(Vec3()) {}
Force(Vec3 direction) : offset(Vec3()), direction(direction) {}
Force(Vec3 offset, Vec3 direction) : offset(offset), direction(direction) {}

Force &operator+=(const Force &other)
{
direction += other.direction;
return *this;
}
};

#endif
Loading