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
20 changes: 20 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
## Description

Briefly describe what this PR implements.

## Changes Made

-
-
-

## Implementation Details

Mention key design decisions if any.


## Checklist
**Type:**
- [ ] Bug Fix
- [ ] Feature
- [ ] Chore
21 changes: 5 additions & 16 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,23 +1,12 @@
cmake_minimum_required(VERSION 3.20)

project(AetherPhysics)
project(Aether_Test)

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

# Collect source files
file(GLOB_RECURSE ENGINE_SOURCES engine/*.cpp)
file(GLOB_RECURSE APP_SOURCES app/*.cpp)

# Create executable
add_executable(AetherPhysics
${ENGINE_SOURCES}
${APP_SOURCES}
add_executable(Aether_Test
app/main.cpp
engine/vec3.cpp
)

# Include directories
target_include_directories(AetherPhysics
PRIVATE
engine
)
target_include_directories(Aether_Test PRIVATE engine)
33 changes: 33 additions & 0 deletions app/main.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,39 @@
#include <iostream>
#include<chrono>
#include<thread>
#include "vec3.hpp"

using namespace std;
int main(){
cout << "Hello Worlds\n";

const float dt=1.0f/60.0f;
const Vec3 gravity(0.0f,-9.8f,0.0f);

Vec3 position(0.0f,10.0f,0.0f);
Vec3 velocity;

float simulation_time=0.0f;
float total_runtime=3.0f; // we will run the simulation for 3 seconds in the startung testing phase

auto last_time=std::chrono::high_resolution_clock::now();
float accumulator=0.0f;

while(simulation_time<total_runtime){
auto current_time=std::chrono::high_resolution_clock::now();
float frametime=std::chrono::duration<float>(current_time-last_time).count();
last_time=current_time;

accumulator+=frametime;
while(accumulator>=dt){
velocity=velocity+(gravity*dt);
position=position+(velocity*dt);

simulation_time+=dt;
accumulator-=dt;
}
std::cout<<"Time: "<<simulation_time<<" Y Position: "<< position.y<<std::endl;
std::this_thread::sleep_for(std::chrono::milliseconds(16));
}
return 0;
}
31 changes: 31 additions & 0 deletions engine/vec3.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#include "vec3.hpp"

Vec3::Vec3():x(0.0f),y(0.0f),z(0.0f){}

Vec3::Vec3(float x, float y, float z):x(x),y(y),z(z){}

Vec3 Vec3::operator+(const Vec3& other) const {
return Vec3(x+other.x, y+other.y, z+other.z);
}

Vec3 Vec3::operator-(const Vec3& other) const {
return Vec3(x-other.x, y-other.y,z-other.z);
}

Vec3 Vec3::operator*(float scalar) const {
return Vec3(x * scalar, y * scalar, z * scalar);
}

float Vec3::dot(const Vec3& other) const {
return x * other.x + y * other.y + z * other.z;
}

float Vec3::length() const {
return std::sqrt(dot(*this));
}

Vec3 Vec3::normalized() const {
float len = length();
if (len == 0.0f) return Vec3();
return (*this) * (1.0f / len);
}
17 changes: 17 additions & 0 deletions engine/vec3.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include <cmath>

class Vec3 {
public:
float x, y, z;

Vec3();
Vec3(float x, float y, float z);

Vec3 operator+(const Vec3& other) const;
Vec3 operator-(const Vec3& other) const;
Vec3 operator*(float scalar) const;

float dot(const Vec3& other) const;
float length() const;
Vec3 normalized() const;
};