mirror of https://github.com/bjornbytes/lovr.git
rm Collider:get/setShapeOffset;
Maybe we can just use CompoundShape.
This commit is contained in:
parent
816f5fce1d
commit
851b12b292
|
@ -57,31 +57,6 @@ static int l_lovrColliderSetShape(lua_State* L) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int l_lovrColliderGetShapeOffset(lua_State* L) {
|
||||
Collider* collider = luax_checktype(L, 1, Collider);
|
||||
float position[3], orientation[4], angle, ax, ay, az;
|
||||
lovrColliderGetShapeOffset(collider, position, orientation);
|
||||
quat_getAngleAxis(orientation, &angle, &ax, &ay, &az);
|
||||
lua_pushnumber(L, position[0]);
|
||||
lua_pushnumber(L, position[1]);
|
||||
lua_pushnumber(L, position[2]);
|
||||
lua_pushnumber(L, angle);
|
||||
lua_pushnumber(L, ax);
|
||||
lua_pushnumber(L, ay);
|
||||
lua_pushnumber(L, az);
|
||||
return 7;
|
||||
}
|
||||
|
||||
static int l_lovrColliderSetShapeOffset(lua_State* L) {
|
||||
Collider* collider = luax_checktype(L, 1, Collider);
|
||||
int index = 2;
|
||||
float position[3], orientation[4];
|
||||
index = luax_readvec3(L, index, position, NULL);
|
||||
index = luax_readquat(L, index, orientation, NULL);
|
||||
lovrColliderSetShapeOffset(collider, position, orientation);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int l_lovrColliderGetJoints(lua_State* L) {
|
||||
Collider* collider = luax_checktype(L, 1, Collider);
|
||||
lua_newtable(L);
|
||||
|
@ -605,8 +580,6 @@ const luaL_Reg lovrCollider[] = {
|
|||
{ "getWorld", l_lovrColliderGetWorld },
|
||||
{ "getShape", l_lovrColliderGetShape },
|
||||
{ "setShape", l_lovrColliderSetShape },
|
||||
{ "getShapeOffset", l_lovrColliderGetShapeOffset },
|
||||
{ "setShapeOffset", l_lovrColliderSetShapeOffset },
|
||||
{ "getJoints", l_lovrColliderGetJoints },
|
||||
{ "getUserData", l_lovrColliderGetUserData },
|
||||
{ "setUserData", l_lovrColliderSetUserData },
|
||||
|
|
|
@ -89,8 +89,6 @@ World* lovrColliderGetWorld(Collider* collider);
|
|||
Joint* lovrColliderGetJoints(Collider* collider, Joint* joint);
|
||||
Shape* lovrColliderGetShape(Collider* collider, uint32_t child);
|
||||
void lovrColliderSetShape(Collider* collider, Shape* shape);
|
||||
void lovrColliderGetShapeOffset(Collider* collider, float position[3], float orientation[4]);
|
||||
void lovrColliderSetShapeOffset(Collider* collider, float position[3], float orientation[4]);
|
||||
const char* lovrColliderGetTag(Collider* collider);
|
||||
bool lovrColliderSetTag(Collider* collider, const char* tag);
|
||||
float lovrColliderGetFriction(Collider* collider);
|
||||
|
|
|
@ -443,11 +443,6 @@ void lovrColliderSetShape(Collider* collider, Shape* shape) {
|
|||
return;
|
||||
}
|
||||
|
||||
float position[3], orientation[4];
|
||||
const JPH_Shape* parent = JPH_BodyInterface_GetShape(collider->world->bodies, collider->id);
|
||||
bool hasOffset = JPH_Shape_GetSubType(parent) == JPH_ShapeSubType_RotatedTranslated;
|
||||
if (hasOffset) lovrColliderGetShapeOffset(collider, position, orientation);
|
||||
|
||||
lovrRelease(collider->shape, lovrShapeDestroy);
|
||||
collider->shape = shape;
|
||||
lovrRetain(shape);
|
||||
|
@ -459,41 +454,6 @@ void lovrColliderSetShape(Collider* collider, Shape* shape) {
|
|||
}
|
||||
|
||||
JPH_BodyInterface_SetShape(collider->world->bodies, collider->id, shape->shape, updateMass, JPH_Activation_Activate);
|
||||
|
||||
if (hasOffset) {
|
||||
lovrColliderSetShapeOffset(collider, position, orientation);
|
||||
}
|
||||
}
|
||||
|
||||
void lovrColliderGetShapeOffset(Collider* collider, float position[3], float orientation[4]) {
|
||||
const JPH_Shape* shape = JPH_BodyInterface_GetShape(collider->world->bodies, collider->id);
|
||||
|
||||
if (JPH_Shape_GetSubType(shape) != JPH_ShapeSubType_RotatedTranslated) {
|
||||
vec3_set(position, 0.f, 0.f, 0.f);
|
||||
quat_identity(orientation);
|
||||
return;
|
||||
}
|
||||
|
||||
JPH_Vec3 p;
|
||||
JPH_Quat q;
|
||||
JPH_RotatedTranslatedShape_GetPosition((JPH_RotatedTranslatedShape*) shape, &p);
|
||||
JPH_RotatedTranslatedShape_GetRotation((JPH_RotatedTranslatedShape*) shape, &q);
|
||||
vec3_fromJolt(position, &p);
|
||||
quat_fromJolt(orientation, &q);
|
||||
}
|
||||
|
||||
void lovrColliderSetShapeOffset(Collider* collider, float position[3], float orientation[4]) {
|
||||
const JPH_Shape* shape = JPH_BodyInterface_GetShape(collider->world->bodies, collider->id);
|
||||
|
||||
if (JPH_Shape_GetSubType(shape) == JPH_ShapeSubType_RotatedTranslated) {
|
||||
JPH_Shape_Destroy((JPH_Shape*) shape);
|
||||
}
|
||||
|
||||
JPH_Vec3* p = vec3_toJolt(position);
|
||||
JPH_Quat* q = quat_toJolt(orientation);
|
||||
shape = (JPH_Shape*) JPH_RotatedTranslatedShape_Create(p, q, collider->shape->shape);
|
||||
bool updateMass = collider->shape && collider->shape->type != SHAPE_MESH && collider->shape->type != SHAPE_TERRAIN;
|
||||
JPH_BodyInterface_SetShape(collider->world->bodies, collider->id, shape, updateMass, JPH_Activation_Activate);
|
||||
}
|
||||
|
||||
const char* lovrColliderGetTag(Collider* collider) {
|
||||
|
|
|
@ -506,25 +506,6 @@ void lovrColliderSetShape(Collider* collider, Shape* shape) {
|
|||
}
|
||||
}
|
||||
|
||||
void lovrColliderGetShapeOffset(Collider* collider, float position[3], float orientation[4]) {
|
||||
const dReal* p = dGeomGetOffsetPosition(collider->shape->id);
|
||||
position[0] = p[0];
|
||||
position[1] = p[1];
|
||||
position[2] = p[2];
|
||||
dReal q[4];
|
||||
dGeomGetOffsetQuaternion(collider->shape->id, q);
|
||||
orientation[0] = q[1];
|
||||
orientation[1] = q[2];
|
||||
orientation[2] = q[3];
|
||||
orientation[3] = q[0];
|
||||
}
|
||||
|
||||
void lovrColliderSetShapeOffset(Collider* collider, float position[3], float orientation[4]) {
|
||||
dGeomSetOffsetPosition(collider->shape->id, position[0], position[1], position[2]);
|
||||
dReal q[4] = { orientation[3], orientation[0], orientation[1], orientation[2] };
|
||||
dGeomSetOffsetQuaternion(collider->shape->id, q);
|
||||
}
|
||||
|
||||
Joint* lovrColliderGetJoints(Collider* collider, Joint* joint) {
|
||||
if (joint == NULL) {
|
||||
return collider->joints.length ? NULL : collider->joints.data[0];
|
||||
|
|
Loading…
Reference in New Issue