Skip to content

Commit

Permalink
Added more Body2D shapes
Browse files Browse the repository at this point in the history
  • Loading branch information
eduardodoria committed Sep 12, 2023
1 parent 4fdb5f3 commit 11354ff
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 23 deletions.
36 changes: 35 additions & 1 deletion engine/core/object/physics/Body2D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,44 @@ Body2D& Body2D::operator=(const Body2D& rhs){
}

int Body2D::createRectShape(float width, float height){
int index = scene->getSystem<PhysicsSystem>()->addRectShape2D(entity, width, height);
int index = scene->getSystem<PhysicsSystem>()->createRectShape2D(entity, width, height);
return index;
}

int Body2D::createPolygonShape2D(std::vector<Vector2> vertices){
int index = scene->getSystem<PhysicsSystem>()->createPolygonShape2D(entity, vertices);
return index;
}

int Body2D::createCircleShape2D(Vector2 center, float radius){
int index = scene->getSystem<PhysicsSystem>()->createCircleShape2D(entity, center, radius);
return index;
}

int Body2D::createTwoSidedEdgeShape2D(Vector2 vertice1, Vector2 vertice2){
int index = scene->getSystem<PhysicsSystem>()->createTwoSidedEdgeShape2D(entity, vertice1, vertice2);
return index;
}

int Body2D::createOneSidedEdgeShape2D(Vector2 vertice0, Vector2 vertice1, Vector2 vertice2, Vector2 vertice3){
int index = scene->getSystem<PhysicsSystem>()->createOneSidedEdgeShape2D(entity, vertice0, vertice1, vertice2, vertice3);
return index;
}

int Body2D::createLoopChainShape2D(std::vector<Vector2> vertices){
int index = scene->getSystem<PhysicsSystem>()->createLoopChainShape2D(entity, vertices);
return index;
}

int Body2D::createChainShape2D(std::vector<Vector2> vertices, Vector2 prevVertex, Vector2 nextVertex){
int index = scene->getSystem<PhysicsSystem>()->createChainShape2D(entity, vertices, prevVertex, nextVertex);
return index;
}

void Body2D::removeAllShapes(){
scene->getSystem<PhysicsSystem>()->removeAllShapes(entity);
}

void Body2D::setShapeDensity(float density){
setShapeDensity(0, density);
}
Expand Down
9 changes: 8 additions & 1 deletion engine/core/object/physics/Body2D.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,14 @@ namespace Supernova{
Object getAttachedObject();

int createRectShape(float width, float height);

int createPolygonShape2D(std::vector<Vector2> vertices);
int createCircleShape2D(Vector2 center, float radius);
int createTwoSidedEdgeShape2D(Vector2 vertice1, Vector2 vertice2);
int createOneSidedEdgeShape2D(Vector2 vertice0, Vector2 vertice1, Vector2 vertice2, Vector2 vertice3);
int createLoopChainShape2D(std::vector<Vector2> vertices);
int createChainShape2D(std::vector<Vector2> vertices, Vector2 prevVertex, Vector2 nextVertex);

void removeAllShapes();

void setShapeDensity(float density);
void setShapeFriction(float friction);
Expand Down
14 changes: 7 additions & 7 deletions engine/core/script/binding/ECSClassesLua.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,13 @@ void LuaBinding::registerECSClasses(lua_State *L){
.addProperty("shouldCollide2D", [] (PhysicsSystem* self, lua_State* L) { return &self->shouldCollide2D; }, [] (PhysicsSystem* self, lua_State* L) { self->shouldCollide2D = L; })
.addFunction("createBody2D", &PhysicsSystem::createBody2D)
.addFunction("removeBody2D", &PhysicsSystem::removeBody2D)
.addFunction("addRectShape2D", &PhysicsSystem::addRectShape2D)
.addFunction("addPolygonShape2D", &PhysicsSystem::addPolygonShape2D)
.addFunction("addCircleShape2D", &PhysicsSystem::addCircleShape2D)
.addFunction("addTwoSidedEdgeShape2D", &PhysicsSystem::addTwoSidedEdgeShape2D)
.addFunction("addOneSidedEdgeShape2D", &PhysicsSystem::addOneSidedEdgeShape2D)
.addFunction("addLoopChainShape2D", &PhysicsSystem::addLoopChainShape2D)
.addFunction("addChainShape2D", &PhysicsSystem::addChainShape2D)
.addFunction("createRectShape2D", &PhysicsSystem::createRectShape2D)
.addFunction("createPolygonShape2D", &PhysicsSystem::createPolygonShape2D)
.addFunction("createCircleShape2D", &PhysicsSystem::createCircleShape2D)
.addFunction("createTwoSidedEdgeShape2D", &PhysicsSystem::createTwoSidedEdgeShape2D)
.addFunction("createOneSidedEdgeShape2D", &PhysicsSystem::createOneSidedEdgeShape2D)
.addFunction("createLoopChainShape2D", &PhysicsSystem::createLoopChainShape2D)
.addFunction("createChainShape2D", &PhysicsSystem::createChainShape2D)
.addFunction("removeAllShapes", &PhysicsSystem::removeAllShapes)
.addFunction("loadBody2D", &PhysicsSystem::loadBody2D)
.addFunction("destroyBody2D", &PhysicsSystem::destroyBody2D)
Expand Down
7 changes: 7 additions & 0 deletions engine/core/script/binding/ObjectClassesLua.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,13 @@ void LuaBinding::registerObjectClasses(lua_State *L){
.addConstructor <void (Scene*, Entity)> ()
.addFunction("getAttachedObject", &Body2D::getAttachedObject)
.addFunction("createRectShape", &Body2D::createRectShape)
.addFunction("createPolygonShape2D", &Body2D::createPolygonShape2D)
.addFunction("createCircleShape2D", &Body2D::createCircleShape2D)
.addFunction("createTwoSidedEdgeShape2D", &Body2D::createTwoSidedEdgeShape2D)
.addFunction("createOneSidedEdgeShape2D", &Body2D::createOneSidedEdgeShape2D)
.addFunction("createLoopChainShape2D", &Body2D::createLoopChainShape2D)
.addFunction("createChainShape2D", &Body2D::createChainShape2D)
.addFunction("removeAllShapes", &Body2D::removeAllShapes)
.addProperty("shapeDensity", &Body2D::getShapeDensity, &Body2D::setShapeDensity)
.addFunction("setShapeDensity",
luabridge::overload<float>(&Body2D::setShapeDensity),
Expand Down
14 changes: 7 additions & 7 deletions engine/core/subsystem/PhysicsSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ void PhysicsSystem::removeBody2D(Entity entity){
}
}

int PhysicsSystem::addRectShape2D(Entity entity, float width, float height){
int PhysicsSystem::createRectShape2D(Entity entity, float width, float height){
Body2DComponent* body = scene->findComponent<Body2DComponent>(entity);

if (body){
Expand All @@ -106,7 +106,7 @@ int PhysicsSystem::addRectShape2D(Entity entity, float width, float height){
return -1;
}

int PhysicsSystem::addPolygonShape2D(Entity entity, std::vector<Vector2> vertices){
int PhysicsSystem::createPolygonShape2D(Entity entity, std::vector<Vector2> vertices){
Body2DComponent* body = scene->findComponent<Body2DComponent>(entity);

if (body){
Expand Down Expand Up @@ -134,7 +134,7 @@ int PhysicsSystem::addPolygonShape2D(Entity entity, std::vector<Vector2> vertice
return -1;
}

int PhysicsSystem::addCircleShape2D(Entity entity, Vector2 center, float radius){
int PhysicsSystem::createCircleShape2D(Entity entity, Vector2 center, float radius){
Body2DComponent* body = scene->findComponent<Body2DComponent>(entity);

if (body){
Expand All @@ -159,7 +159,7 @@ int PhysicsSystem::addCircleShape2D(Entity entity, Vector2 center, float radius)
return -1;
}

int PhysicsSystem::addTwoSidedEdgeShape2D(Entity entity, Vector2 vertice1, Vector2 vertice2){
int PhysicsSystem::createTwoSidedEdgeShape2D(Entity entity, Vector2 vertice1, Vector2 vertice2){
Body2DComponent* body = scene->findComponent<Body2DComponent>(entity);

if (body){
Expand All @@ -185,7 +185,7 @@ int PhysicsSystem::addTwoSidedEdgeShape2D(Entity entity, Vector2 vertice1, Vecto
return -1;
}

int PhysicsSystem::addOneSidedEdgeShape2D(Entity entity, Vector2 vertice0, Vector2 vertice1, Vector2 vertice2, Vector2 vertice3){
int PhysicsSystem::createOneSidedEdgeShape2D(Entity entity, Vector2 vertice0, Vector2 vertice1, Vector2 vertice2, Vector2 vertice3){
Body2DComponent* body = scene->findComponent<Body2DComponent>(entity);

if (body){
Expand Down Expand Up @@ -213,7 +213,7 @@ int PhysicsSystem::addOneSidedEdgeShape2D(Entity entity, Vector2 vertice0, Vecto
return -1;
}

int PhysicsSystem::addLoopChainShape2D(Entity entity, std::vector<Vector2> vertices){
int PhysicsSystem::createLoopChainShape2D(Entity entity, std::vector<Vector2> vertices){
Body2DComponent* body = scene->findComponent<Body2DComponent>(entity);

if (body){
Expand Down Expand Up @@ -241,7 +241,7 @@ int PhysicsSystem::addLoopChainShape2D(Entity entity, std::vector<Vector2> verti
return -1;
}

int PhysicsSystem::addChainShape2D(Entity entity, std::vector<Vector2> vertices, Vector2 prevVertex, Vector2 nextVertex){
int PhysicsSystem::createChainShape2D(Entity entity, std::vector<Vector2> vertices, Vector2 prevVertex, Vector2 nextVertex){
Body2DComponent* body = scene->findComponent<Body2DComponent>(entity);

if (body){
Expand Down
14 changes: 7 additions & 7 deletions engine/core/subsystem/PhysicsSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,13 @@ namespace Supernova{
void createBody2D(Entity entity);
void removeBody2D(Entity entity);

int addRectShape2D(Entity entity, float width, float height);
int addPolygonShape2D(Entity entity, std::vector<Vector2> vertices);
int addCircleShape2D(Entity entity, Vector2 center, float radius);
int addTwoSidedEdgeShape2D(Entity entity, Vector2 vertice1, Vector2 vertice2);
int addOneSidedEdgeShape2D(Entity entity, Vector2 vertice0, Vector2 vertice1, Vector2 vertice2, Vector2 vertice3);
int addLoopChainShape2D(Entity entity, std::vector<Vector2> vertices);
int addChainShape2D(Entity entity, std::vector<Vector2> vertices, Vector2 prevVertex, Vector2 nextVertex);
int createRectShape2D(Entity entity, float width, float height);
int createPolygonShape2D(Entity entity, std::vector<Vector2> vertices);
int createCircleShape2D(Entity entity, Vector2 center, float radius);
int createTwoSidedEdgeShape2D(Entity entity, Vector2 vertice1, Vector2 vertice2);
int createOneSidedEdgeShape2D(Entity entity, Vector2 vertice0, Vector2 vertice1, Vector2 vertice2, Vector2 vertice3);
int createLoopChainShape2D(Entity entity, std::vector<Vector2> vertices);
int createChainShape2D(Entity entity, std::vector<Vector2> vertices, Vector2 prevVertex, Vector2 nextVertex);

void removeAllShapes(Entity entity);

Expand Down

0 comments on commit 11354ff

Please sign in to comment.