diff --git a/src/api/types/joints.c b/src/api/types/joints.c index f669e49f..e014ef89 100644 --- a/src/api/types/joints.c +++ b/src/api/types/joints.c @@ -63,6 +63,30 @@ const luaL_Reg lovrJoint[] = { { NULL, NULL } }; +int l_lovrBallJointGetAnchors(lua_State* L) { + BallJoint* ball = luax_checktype(L, 1, BallJoint); + float x1, y1, z1, x2, y2, z2; + lovrBallJointGetAnchors(ball, &x1, &y1, &z1, &x2, &y2, &z2); + lua_pushnumber(L, x1); + lua_pushnumber(L, y1); + lua_pushnumber(L, z1); + lua_pushnumber(L, x2); + lua_pushnumber(L, y2); + lua_pushnumber(L, z2); + return 6; +} + +int l_lovrBallJointSetAnchor(lua_State* L) { + BallJoint* ball = luax_checktype(L, 1, BallJoint); + float x = luaL_checknumber(L, 2); + float y = luaL_checknumber(L, 3); + float z = luaL_checknumber(L, 4); + lovrBallJointSetAnchor(ball, x, y, z); + return 0; +} + const luaL_Reg lovrBallJoint[] = { + { "getAnchors", l_lovrBallJointGetAnchors }, + { "setAnchor", l_lovrBallJointSetAnchor }, { NULL, NULL } }; diff --git a/src/physics/physics.c b/src/physics/physics.c index d962bc98..9bde2fd0 100644 --- a/src/physics/physics.c +++ b/src/physics/physics.c @@ -798,3 +798,19 @@ BallJoint* lovrBallJointCreate(Collider* a, Collider* b, float x, float y, float return joint; } + +void lovrBallJointGetAnchors(BallJoint* ball, float* x1, float* y1, float* z1, float* x2, float* y2, float* z2) { + float anchor[3]; + dJointGetBallAnchor(ball->id, anchor); + *x1 = anchor[0]; + *y1 = anchor[1]; + *z1 = anchor[2]; + dJointGetBallAnchor2(ball->id, anchor); + *x2 = anchor[0]; + *y2 = anchor[1]; + *z2 = anchor[2]; +} + +void lovrBallJointSetAnchor(BallJoint* ball, float x, float y, float z) { + dJointSetBallAnchor(ball->id, x, y, z); +} diff --git a/src/physics/physics.h b/src/physics/physics.h index 4ec8867a..3f0d17d8 100644 --- a/src/physics/physics.h +++ b/src/physics/physics.h @@ -180,3 +180,5 @@ void* lovrJointGetUserData(Joint* joint); void lovrJointSetUserData(Joint* joint, void* data); BallJoint* lovrBallJointCreate(Collider* a, Collider* b, float x, float y, float z); +void lovrBallJointGetAnchors(BallJoint* ball, float* x1, float* y1, float* z1, float* x2, float* y2, float* z2); +void lovrBallJointSetAnchor(BallJoint* ball, float x, float y, float z);