Skip to content

Commit

Permalink
Some overload functions
Browse files Browse the repository at this point in the history
  • Loading branch information
eduardodoria committed Jan 2, 2024
1 parent 73c5f26 commit f9ff698
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 1 deletion.
7 changes: 7 additions & 0 deletions engine/core/math/Vector2.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "Vector2.h"

#include "Vector3.h"

using namespace Supernova;

const Vector2 Vector2::ZERO( 0, 0);
Expand Down Expand Up @@ -32,6 +34,11 @@ Vector2::Vector2( const int afCoordinate[2] ){
Vector2::Vector2( float* const r ): x( r[0] ), y( r[1] ){
}

Vector2::Vector2( const Vector3 vec3 ){
x = vec3.x;
y = vec3.y;
}

std::string Vector2::toString() const{
return "Vector2(" + std::to_string(x) + ", " + std::to_string(y) + ")";
}
Expand Down
4 changes: 4 additions & 0 deletions engine/core/math/Vector2.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ Supernova::Vector2 operator - (const float lhs, const Supernova::Vector2& rhs);

namespace Supernova {

class Vector3;

class Vector2
{
public:
Expand All @@ -41,6 +43,8 @@ namespace Supernova {

explicit Vector2( float* const r );

explicit Vector2( const Vector3 vec3 );

std::string toString() const;


Expand Down
4 changes: 4 additions & 0 deletions engine/core/object/physics/Body2D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ int Body2D::createRectShape(float width, float height){
return index;
}

int Body2D::createCenteredRectShape(float width, float height){
return createCenteredRectShape(width, height, Vector2(0, 0), 0);
}

int Body2D::createCenteredRectShape(float width, float height, Vector2 center, float angle){
int index = scene->getSystem<PhysicsSystem>()->createCenteredRectShape2D(entity, width, height, center, angle);
return index;
Expand Down
1 change: 1 addition & 0 deletions engine/core/object/physics/Body2D.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ namespace Supernova{
Object getAttachedObject();

int createRectShape(float width, float height);
int createCenteredRectShape(float width, float height);
int createCenteredRectShape(float width, float height, Vector2 center, float angle);
int createPolygonShape(std::vector<Vector2> vertices);
int createCircleShape(Vector2 center, float radius);
Expand Down
4 changes: 3 additions & 1 deletion engine/core/script/binding/ObjectClassesLua.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,9 @@ void LuaBinding::registerObjectClasses(lua_State *L){
.addConstructor <void (Scene*, Entity)> ()
.addFunction("getAttachedObject", &Body2D::getAttachedObject)
.addFunction("createRectShape", &Body2D::createRectShape)
.addFunction("createCenteredRectShape", &Body2D::createCenteredRectShape)
.addFunction("createCenteredRectShape",
luabridge::overload<float, float>(&Body2D::createCenteredRectShape),
luabridge::overload<float, float, Vector2, float>(&Body2D::createCenteredRectShape))
.addFunction("createPolygonShape", &Body2D::createPolygonShape)
.addFunction("createCircleShape", &Body2D::createCircleShape)
.addFunction("createTwoSidedEdgeShape", &Body2D::createTwoSidedEdgeShape)
Expand Down

0 comments on commit f9ff698

Please sign in to comment.