BallJoint:getAnchors; BallJoint:setAnchor;

This commit is contained in:
bjorn 2017-05-24 23:47:16 -07:00
parent 73e3282c47
commit 507ab7f4bb
3 changed files with 42 additions and 0 deletions

View File

@ -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 }
};

View File

@ -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);
}

View File

@ -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);