mirror of https://github.com/bjornbytes/lovr.git
WIP Collider:get/setEnabledAxes;
This commit is contained in:
parent
b6b13deea6
commit
9b3ace7094
|
@ -223,6 +223,59 @@ static int l_lovrColliderSetMassData(lua_State* L) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int l_lovrColliderGetEnabledAxes(lua_State* L) {
|
||||
Collider* collider = luax_checktype(L, 1, Collider);
|
||||
bool translation[3];
|
||||
bool rotation[3];
|
||||
lovrColliderGetEnabledAxes(collider, translation, rotation);
|
||||
|
||||
char string[3];
|
||||
size_t length;
|
||||
|
||||
length = 0;
|
||||
for (size_t i = 0; i < 3; i++) {
|
||||
if (translation[i]) {
|
||||
string[length++] = 'x' + i;
|
||||
}
|
||||
}
|
||||
lua_pushlstring(L, string, length);
|
||||
|
||||
length = 0;
|
||||
for (size_t i = 0; i < 3; i++) {
|
||||
if (rotation[i]) {
|
||||
string[length++] = 'x' + i;
|
||||
}
|
||||
}
|
||||
lua_pushlstring(L, string, length);
|
||||
|
||||
return 2;
|
||||
}
|
||||
|
||||
static int l_lovrColliderSetEnabledAxes(lua_State* L) {
|
||||
Collider* collider = luax_checktype(L, 1, Collider);
|
||||
bool translation[3] = { false, false, false };
|
||||
bool rotation[3] = { false, false, false };
|
||||
const char* string;
|
||||
size_t length;
|
||||
|
||||
string = lua_tolstring(L, 2, &length);
|
||||
for (size_t i = 0; i < length; i++) {
|
||||
if (string[i] >= 'x' && string[i] <= 'z') {
|
||||
translation[string[i] - 'x'] = true;
|
||||
}
|
||||
}
|
||||
|
||||
string = lua_tolstring(L, 3, &length);
|
||||
for (size_t i = 0; i < length; i++) {
|
||||
if (string[i] >= 'x' && string[i] <= 'z') {
|
||||
rotation[string[i] - 'x'] = true;
|
||||
}
|
||||
}
|
||||
|
||||
lovrColliderSetEnabledAxes(collider, translation, rotation);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int l_lovrColliderGetPosition(lua_State* L) {
|
||||
Collider* collider = luax_checktype(L, 1, Collider);
|
||||
float position[3];
|
||||
|
@ -598,6 +651,8 @@ const luaL_Reg lovrCollider[] = {
|
|||
{ "setMass", l_lovrColliderSetMass },
|
||||
{ "getMassData", l_lovrColliderGetMassData },
|
||||
{ "setMassData", l_lovrColliderSetMassData },
|
||||
{ "getEnabledAxes", l_lovrColliderGetEnabledAxes },
|
||||
{ "setEnabledAxes", l_lovrColliderSetEnabledAxes },
|
||||
{ "getPosition", l_lovrColliderGetPosition },
|
||||
{ "setPosition", l_lovrColliderSetPosition },
|
||||
{ "getOrientation", l_lovrColliderGetOrientation },
|
||||
|
|
|
@ -133,6 +133,8 @@ float lovrColliderGetMass(Collider* collider);
|
|||
void lovrColliderSetMass(Collider* collider, float mass);
|
||||
void lovrColliderGetMassData(Collider* collider, float centerOfMass[3], float* mass, float inertia[6]);
|
||||
void lovrColliderSetMassData(Collider* collider, float centerOfMass[3], float mass, float inertia[6]);
|
||||
void lovrColliderGetEnabledAxes(Collider* collider, bool translation[3], bool rotation[3]);
|
||||
void lovrColliderSetEnabledAxes(Collider* collider, bool translation[3], bool rotation[3]);
|
||||
void lovrColliderGetPosition(Collider* collider, float position[3]);
|
||||
void lovrColliderSetPosition(Collider* collider, float position[3]);
|
||||
void lovrColliderGetOrientation(Collider* collider, float orientation[4]);
|
||||
|
|
|
@ -641,6 +641,29 @@ void lovrColliderSetMassData(Collider* collider, float centerOfMass[3], float ma
|
|||
//
|
||||
}
|
||||
|
||||
void lovrColliderGetEnabledAxes(Collider* collider, bool translation[3], bool rotation[3]) {
|
||||
// TODO need bindings
|
||||
}
|
||||
|
||||
void lovrColliderSetEnabledAxes(Collider* collider, bool translation[3], bool rotation[3]) {
|
||||
JPH_AllowedDOFs dofs = 0;
|
||||
|
||||
for (size_t i = 0; i < 3; i++) {
|
||||
if (translation[i]) {
|
||||
dofs |= JPH_AllowedDOFs_TranslationX << i;
|
||||
}
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < 3; i++) {
|
||||
if (rotation[i]) {
|
||||
dofs |= JPH_AllowedDOFs_RotationX << i;
|
||||
}
|
||||
}
|
||||
|
||||
JPH_MotionProperties* motion = JPH_Body_GetMotionProperties(collider->body);
|
||||
JPH_MotionProperties_SetMassProperties(motion, dofs, NULL); // TODO need to synthesize mass
|
||||
}
|
||||
|
||||
void lovrColliderGetPosition(Collider* collider, float position[3]) {
|
||||
JPH_RVec3 p;
|
||||
JPH_Body_GetPosition(collider->body, &p);
|
||||
|
|
|
@ -658,6 +658,14 @@ void lovrColliderSetMassData(Collider* collider, float centerOfMass[3], float ma
|
|||
dBodySetMass(collider->body, &m);
|
||||
}
|
||||
|
||||
void lovrColliderGetEnabledAxes(Collider* collider, bool translation[3], bool rotation[3]) {
|
||||
lovrThrow("NYI");
|
||||
}
|
||||
|
||||
void lovrColliderSetEnabledAxes(Collider* collider, bool translation[3], bool rotation[3]) {
|
||||
lovrThrow("NYI");
|
||||
}
|
||||
|
||||
void lovrColliderGetPosition(Collider* collider, float position[3]) {
|
||||
const dReal* p = dBodyGetPosition(collider->body);
|
||||
vec3_set(position, p[0], p[1], p[2]);
|
||||
|
|
Loading…
Reference in New Issue