Skip to content
Open
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
7 changes: 4 additions & 3 deletions include/physics_engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <vector>
#include <SFML/Graphics.hpp>
#include "physics_object.h"
#include "physics_circle.h"

class PhysicsEngine{
private:
Expand All @@ -12,9 +13,9 @@ class PhysicsEngine{
static bool(*collisionTable)(PhysicsObject*, PhysicsObject*) [4][4];

public:
void addObject(std::unique_ptr<PhysicsObject> obj);


void addCircle(float radius, ShapeID ID,
sf::Vector2f pos, sf::Vector2f vel, sf::Vector2f acc,
float angle, float ang_acc, float ang_vel, PhysicalAttributes attr, bool isStatic);
void update(sf::Time dt);
void draw(sf::RenderWindow& window);
};
Expand Down
Empty file added include/physics_engine.h~
Empty file.
23 changes: 23 additions & 0 deletions main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include <iostream>
#include <SFML/System.hpp>
using namespace std;

void func() {
for (int i = 0; i < 10; i++) {
cout << "Thread 1" << endl;
}
}

int main() {
sf::Thread thread1(&func), thread2(&func);
thread1.launch();
thread2.launch();

for(int i = 0; i < 10; i++) {
cout << "Main thread" << endl;
}

return 0;
}


27 changes: 27 additions & 0 deletions main.cpp~
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#include <iostream>
#include <SFML/System.hpp>
using namespace std;

void func() {
for (int i = 0; i < 10; i++) {
cout << "Thread 1" << endl;
}
}

int main() {
sf::Thread thread(&func);
// wait

//wait

//wait
thread.launch();

for(int i = 0; i < 10; i++) {
cout << "Main thread" << endl;
}

return 0;
}


Binary file added sfml-app
Binary file not shown.
16 changes: 15 additions & 1 deletion src/physics_engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,20 @@ namespace{

*PhysicsEngine::collisionTable[0][0] = circlecircleCollision;

void PhysicsEngine::addObject(std::unique_ptr<PhysicsObject> obj) {
void PhysicsEngine::addCircle(float radius, ShapeID ID,
sf::Vector2f pos, sf::Vector2f vel, sf::Vector2f acc,
float angle, float ang_acc, float ang_vel, const PhysicalAttributes &attr, bool isStatic) {
std::unique_ptr<Circle> obj = new Circle(radius, pos);

obj->setPosition(pos);
obj->setVelocity(vel);
obj->setAcceleration(acc);
obj->setAngle(angle);
obj->setAngularAcceleration(ang_acc);
obj->setAngularVelocity(ang_vel);
obj->setAttributes(attr);
obj->setIsStatic(isStatic);

objects.push_back(std::move(obj));
}

Expand All @@ -54,5 +67,6 @@ void PhysicsEngine::draw(sf::RenderWindow& window) {
for (auto& obj : objects)
obj->draw(window);
}