diff --git a/src/api/l_physics_joints.c b/src/api/l_physics_joints.c index 5f9148dbe..aaedfc9b9 100644 --- a/src/api/l_physics_joints.c +++ b/src/api/l_physics_joints.c @@ -79,6 +79,19 @@ static int l_lovrJointGetColliders(lua_State* L) { return 2; } +static int l_lovrJointGetAnchors(lua_State* L) { + Joint* joint = luax_checkjoint(L, 1); + float anchor1[3], anchor2[3]; + lovrJointGetAnchors(joint, anchor1, anchor2); + lua_pushnumber(L, anchor1[0]); + lua_pushnumber(L, anchor1[1]); + lua_pushnumber(L, anchor1[2]); + lua_pushnumber(L, anchor2[0]); + lua_pushnumber(L, anchor2[1]); + lua_pushnumber(L, anchor2[2]); + return 6; +} + static int l_lovrJointGetUserData(lua_State* L) { luax_checkjoint(L, 1); luax_pushstash(L, "lovr.joint.userdata"); @@ -143,6 +156,7 @@ static int l_lovrJointGetTorque(lua_State* L) { { "isDestroyed", l_lovrJointIsDestroyed }, \ { "getType", l_lovrJointGetType }, \ { "getColliders", l_lovrJointGetColliders }, \ + { "getAnchors", l_lovrJointGetAnchors }, \ { "getUserData", l_lovrJointGetUserData }, \ { "setUserData", l_lovrJointSetUserData }, \ { "getPriority", l_lovrJointGetPriority }, \ @@ -152,57 +166,16 @@ static int l_lovrJointGetTorque(lua_State* L) { { "getForce", l_lovrJointGetForce }, \ { "getTorque", l_lovrJointGetTorque } -static int l_lovrWeldJointGetAnchors(lua_State* L) { - WeldJoint* joint = luax_checktype(L, 1, WeldJoint); - float anchor1[3], anchor2[3]; - lovrWeldJointGetAnchors(joint, anchor1, anchor2); - lua_pushnumber(L, anchor1[0]); - lua_pushnumber(L, anchor1[1]); - lua_pushnumber(L, anchor1[2]); - lua_pushnumber(L, anchor2[0]); - lua_pushnumber(L, anchor2[1]); - lua_pushnumber(L, anchor2[2]); - return 6; -} - const luaL_Reg lovrWeldJoint[] = { lovrJoint, - { "getAnchors", l_lovrWeldJointGetAnchors }, { NULL, NULL } }; -static int l_lovrBallJointGetAnchors(lua_State* L) { - BallJoint* joint = luax_checktype(L, 1, BallJoint); - float anchor1[3], anchor2[3]; - lovrBallJointGetAnchors(joint, anchor1, anchor2); - lua_pushnumber(L, anchor1[0]); - lua_pushnumber(L, anchor1[1]); - lua_pushnumber(L, anchor1[2]); - lua_pushnumber(L, anchor2[0]); - lua_pushnumber(L, anchor2[1]); - lua_pushnumber(L, anchor2[2]); - return 6; -} - const luaL_Reg lovrBallJoint[] = { lovrJoint, - { "getAnchors", l_lovrBallJointGetAnchors }, { NULL, NULL } }; -static int l_lovrConeJointGetAnchors(lua_State* L) { - ConeJoint* joint = luax_checktype(L, 1, ConeJoint); - float anchor1[3], anchor2[3]; - lovrConeJointGetAnchors(joint, anchor1, anchor2); - lua_pushnumber(L, anchor1[0]); - lua_pushnumber(L, anchor1[1]); - lua_pushnumber(L, anchor1[2]); - lua_pushnumber(L, anchor2[0]); - lua_pushnumber(L, anchor2[1]); - lua_pushnumber(L, anchor2[2]); - return 6; -} - static int l_lovrConeJointGetAxis(lua_State* L) { ConeJoint* joint = luax_checktype(L, 1, ConeJoint); float axis[3]; @@ -229,26 +202,12 @@ static int l_lovrConeJointSetLimit(lua_State* L) { const luaL_Reg lovrConeJoint[] = { lovrJoint, - { "getAnchors", l_lovrConeJointGetAnchors }, { "getAxis", l_lovrConeJointGetAxis }, { "getLimit", l_lovrConeJointGetLimit }, { "setLimit", l_lovrConeJointSetLimit }, { NULL, NULL } }; -static int l_lovrDistanceJointGetAnchors(lua_State* L) { - DistanceJoint* joint = luax_checktype(L, 1, DistanceJoint); - float anchor1[3], anchor2[3]; - lovrDistanceJointGetAnchors(joint, anchor1, anchor2); - lua_pushnumber(L, anchor1[0]); - lua_pushnumber(L, anchor1[1]); - lua_pushnumber(L, anchor1[2]); - lua_pushnumber(L, anchor2[0]); - lua_pushnumber(L, anchor2[1]); - lua_pushnumber(L, anchor2[2]); - return 6; -} - static int l_lovrDistanceJointGetLimits(lua_State* L) { DistanceJoint* joint = luax_checktype(L, 1, DistanceJoint); float min, max; @@ -285,7 +244,6 @@ static int l_lovrDistanceJointSetSpring(lua_State* L) { const luaL_Reg lovrDistanceJoint[] = { lovrJoint, - { "getAnchors", l_lovrDistanceJointGetAnchors }, { "getLimits", l_lovrDistanceJointGetLimits }, { "setLimits", l_lovrDistanceJointSetLimits }, { "getSpring", l_lovrDistanceJointGetSpring }, @@ -293,19 +251,6 @@ const luaL_Reg lovrDistanceJoint[] = { { NULL, NULL } }; -static int l_lovrHingeJointGetAnchors(lua_State* L) { - HingeJoint* joint = luax_checktype(L, 1, HingeJoint); - float anchor1[3], anchor2[3]; - lovrHingeJointGetAnchors(joint, anchor1, anchor2); - lua_pushnumber(L, anchor1[0]); - lua_pushnumber(L, anchor1[1]); - lua_pushnumber(L, anchor1[2]); - lua_pushnumber(L, anchor2[0]); - lua_pushnumber(L, anchor2[1]); - lua_pushnumber(L, anchor2[2]); - return 6; -} - static int l_lovrHingeJointGetAxis(lua_State* L) { HingeJoint* joint = luax_checktype(L, 1, HingeJoint); float axis[3]; @@ -448,7 +393,6 @@ static int l_lovrHingeJointSetSpring(lua_State* L) { const luaL_Reg lovrHingeJoint[] = { lovrJoint, - { "getAnchors", l_lovrHingeJointGetAnchors }, { "getAxis", l_lovrHingeJointGetAxis }, { "getAngle", l_lovrHingeJointGetAngle }, { "getLimits", l_lovrHingeJointGetLimits }, @@ -467,19 +411,6 @@ const luaL_Reg lovrHingeJoint[] = { { NULL, NULL } }; -static int l_lovrSliderJointGetAnchors(lua_State* L) { - SliderJoint* joint = luax_checktype(L, 1, SliderJoint); - float anchor1[3], anchor2[3]; - lovrSliderJointGetAnchors(joint, anchor1, anchor2); - lua_pushnumber(L, anchor1[0]); - lua_pushnumber(L, anchor1[1]); - lua_pushnumber(L, anchor1[2]); - lua_pushnumber(L, anchor2[0]); - lua_pushnumber(L, anchor2[1]); - lua_pushnumber(L, anchor2[2]); - return 6; -} - static int l_lovrSliderJointGetAxis(lua_State* L) { SliderJoint* joint = luax_checktype(L, 1, SliderJoint); float axis[3]; @@ -622,7 +553,6 @@ static int l_lovrSliderJointSetSpring(lua_State* L) { const luaL_Reg lovrSliderJoint[] = { lovrJoint, - { "getAnchors", l_lovrSliderJointGetAnchors }, { "getAxis", l_lovrSliderJointGetAxis }, { "getPosition", l_lovrSliderJointGetPosition }, { "getLimits", l_lovrSliderJointGetLimits }, diff --git a/src/modules/physics/physics.c b/src/modules/physics/physics.c index dab30fc1c..31703bc25 100644 --- a/src/modules/physics/physics.c +++ b/src/modules/physics/physics.c @@ -1992,27 +1992,6 @@ TerrainShape* lovrTerrainShapeCreate(float* vertices, uint32_t n, float scaleXZ, // Joints -static void lovrJointGetAnchors(Joint* joint, float anchor1[3], float anchor2[3]) { - JPH_Body* body1 = JPH_TwoBodyConstraint_GetBody1((JPH_TwoBodyConstraint*) joint->constraint); - JPH_Body* body2 = JPH_TwoBodyConstraint_GetBody2((JPH_TwoBodyConstraint*) joint->constraint); - JPH_RMatrix4x4 centerOfMassTransform1; - JPH_RMatrix4x4 centerOfMassTransform2; - JPH_Body_GetCenterOfMassTransform(body1, ¢erOfMassTransform1); - JPH_Body_GetCenterOfMassTransform(body2, ¢erOfMassTransform2); - JPH_Matrix4x4 constraintToBody1; - JPH_Matrix4x4 constraintToBody2; - JPH_TwoBodyConstraint_GetConstraintToBody1Matrix((JPH_TwoBodyConstraint*) joint->constraint, &constraintToBody1); - JPH_TwoBodyConstraint_GetConstraintToBody2Matrix((JPH_TwoBodyConstraint*) joint->constraint, &constraintToBody2); - mat4_mulVec4(¢erOfMassTransform1.m11, &constraintToBody1.m41); - mat4_mulVec4(¢erOfMassTransform2.m11, &constraintToBody2.m41); - anchor1[0] = constraintToBody1.m41; - anchor1[1] = constraintToBody1.m42; - anchor1[2] = constraintToBody1.m43; - anchor2[0] = constraintToBody2.m41; - anchor2[1] = constraintToBody2.m42; - anchor2[2] = constraintToBody2.m43; -} - static JointNode* lovrJointGetNode(Joint* joint, Collider* collider) { return collider == lovrJointGetColliderA(joint) ? &joint->a : &joint->b; } @@ -2113,6 +2092,27 @@ Joint* lovrJointGetNext(Joint* joint, Collider* collider) { return lovrJointGetNode(joint, collider)->next; } +void lovrJointGetAnchors(Joint* joint, float anchor1[3], float anchor2[3]) { + JPH_Body* body1 = JPH_TwoBodyConstraint_GetBody1((JPH_TwoBodyConstraint*) joint->constraint); + JPH_Body* body2 = JPH_TwoBodyConstraint_GetBody2((JPH_TwoBodyConstraint*) joint->constraint); + JPH_RMatrix4x4 centerOfMassTransform1; + JPH_RMatrix4x4 centerOfMassTransform2; + JPH_Body_GetCenterOfMassTransform(body1, ¢erOfMassTransform1); + JPH_Body_GetCenterOfMassTransform(body2, ¢erOfMassTransform2); + JPH_Matrix4x4 constraintToBody1; + JPH_Matrix4x4 constraintToBody2; + JPH_TwoBodyConstraint_GetConstraintToBody1Matrix((JPH_TwoBodyConstraint*) joint->constraint, &constraintToBody1); + JPH_TwoBodyConstraint_GetConstraintToBody2Matrix((JPH_TwoBodyConstraint*) joint->constraint, &constraintToBody2); + mat4_mulVec4(¢erOfMassTransform1.m11, &constraintToBody1.m41); + mat4_mulVec4(¢erOfMassTransform2.m11, &constraintToBody2.m41); + anchor1[0] = constraintToBody1.m41; + anchor1[1] = constraintToBody1.m42; + anchor1[2] = constraintToBody1.m43; + anchor2[0] = constraintToBody2.m41; + anchor2[1] = constraintToBody2.m42; + anchor2[2] = constraintToBody2.m43; +} + uint32_t lovrJointGetPriority(Joint* joint) { return JPH_Constraint_GetConstraintPriority(joint->constraint); } @@ -2196,10 +2196,6 @@ WeldJoint* lovrWeldJointCreate(Collider* a, Collider* b, float anchor[3]) { return joint; } -void lovrWeldJointGetAnchors(WeldJoint* joint, float anchor1[3], float anchor2[3]) { - lovrJointGetAnchors((Joint*) joint, anchor1, anchor2); -} - // BallJoint BallJoint* lovrBallJointCreate(Collider* a, Collider* b, float anchor[3]) { @@ -2224,10 +2220,6 @@ BallJoint* lovrBallJointCreate(Collider* a, Collider* b, float anchor[3]) { return joint; } -void lovrBallJointGetAnchors(BallJoint* joint, float anchor1[3], float anchor2[3]) { - lovrJointGetAnchors((Joint*) joint, anchor1, anchor2); -} - // ConeJoint ConeJoint* lovrConeJointCreate(Collider* a, Collider* b, float anchor[3], float axis[3]) { @@ -2253,10 +2245,6 @@ ConeJoint* lovrConeJointCreate(Collider* a, Collider* b, float anchor[3], float return joint; } -void lovrConeJointGetAnchors(ConeJoint* joint, float anchor1[3], float anchor2[3]) { - lovrJointGetAnchors((Joint*) joint, anchor1, anchor2); -} - void lovrConeJointGetAxis(ConeJoint* joint, float axis[3]) { JPH_Vec3 resultAxis; JPH_ConeConstraintSettings* settings = (JPH_ConeConstraintSettings*) JPH_Constraint_GetConstraintSettings((JPH_Constraint*) joint->constraint); @@ -2309,10 +2297,6 @@ DistanceJoint* lovrDistanceJointCreate(Collider* a, Collider* b, float anchor1[3 return joint; } -void lovrDistanceJointGetAnchors(DistanceJoint* joint, float anchor1[3], float anchor2[3]) { - lovrJointGetAnchors((Joint*) joint, anchor1, anchor2); -} - void lovrDistanceJointGetLimits(DistanceJoint* joint, float* min, float* max) { *min = JPH_DistanceConstraint_GetMinDistance((JPH_DistanceConstraint*) joint->constraint); *max = JPH_DistanceConstraint_GetMaxDistance((JPH_DistanceConstraint*) joint->constraint); @@ -2364,10 +2348,6 @@ HingeJoint* lovrHingeJointCreate(Collider* a, Collider* b, float anchor[3], floa return joint; } -void lovrHingeJointGetAnchors(HingeJoint* joint, float anchor1[3], float anchor2[3]) { - lovrJointGetAnchors(joint, anchor1, anchor2); -} - void lovrHingeJointGetAxis(HingeJoint* joint, float axis[3]) { JPH_Vec3 resultAxis; JPH_HingeConstraintSettings* settings = (JPH_HingeConstraintSettings*) JPH_Constraint_GetConstraintSettings((JPH_Constraint*) joint->constraint); @@ -2509,10 +2489,6 @@ SliderJoint* lovrSliderJointCreate(Collider* a, Collider* b, float axis[3]) { return joint; } -void lovrSliderJointGetAnchors(SliderJoint* joint, float anchor1[3], float anchor2[3]) { - lovrJointGetAnchors(joint, anchor1, anchor2); -} - void lovrSliderJointGetAxis(SliderJoint* joint, float axis[3]) { JPH_Vec3 resultAxis; JPH_SliderConstraintSettings* settings = (JPH_SliderConstraintSettings*) JPH_Constraint_GetConstraintSettings((JPH_Constraint*) joint->constraint); diff --git a/src/modules/physics/physics.h b/src/modules/physics/physics.h index 8f6907306..f295809e4 100644 --- a/src/modules/physics/physics.h +++ b/src/modules/physics/physics.h @@ -292,6 +292,7 @@ JointType lovrJointGetType(Joint* joint); Collider* lovrJointGetColliderA(Joint* joint); Collider* lovrJointGetColliderB(Joint* joint); Joint* lovrJointGetNext(Joint* joint, Collider* collider); +void lovrJointGetAnchors(Joint* joint, float anchor1[3], float anchor2[3]); uint32_t lovrJointGetPriority(Joint* joint); void lovrJointSetPriority(Joint* joint, uint32_t priority); bool lovrJointIsEnabled(Joint* joint); @@ -300,26 +301,21 @@ float lovrJointGetForce(Joint* joint); float lovrJointGetTorque(Joint* joint); WeldJoint* lovrWeldJointCreate(Collider* a, Collider* b, float anchor[3]); -void lovrWeldJointGetAnchors(WeldJoint* joint, float anchor1[3], float anchor2[3]); BallJoint* lovrBallJointCreate(Collider* a, Collider* b, float anchor[3]); -void lovrBallJointGetAnchors(BallJoint* joint, float anchor1[3], float anchor2[3]); ConeJoint* lovrConeJointCreate(Collider* a, Collider* b, float anchor[3], float axis[3]); -void lovrConeJointGetAnchors(ConeJoint* joint, float anchor1[3], float anchor2[3]); void lovrConeJointGetAxis(ConeJoint* joint, float axis[3]); float lovrConeJointGetLimit(ConeJoint* joint); void lovrConeJointSetLimit(ConeJoint* joint, float angle); DistanceJoint* lovrDistanceJointCreate(Collider* a, Collider* b, float anchor1[3], float anchor2[3]); -void lovrDistanceJointGetAnchors(DistanceJoint* joint, float anchor1[3], float anchor2[3]); void lovrDistanceJointGetLimits(DistanceJoint* joint, float* min, float* max); void lovrDistanceJointSetLimits(DistanceJoint* joint, float min, float max); void lovrDistanceJointGetSpring(DistanceJoint* joint, float* frequency, float* damping); void lovrDistanceJointSetSpring(DistanceJoint* joint, float frequency, float damping); HingeJoint* lovrHingeJointCreate(Collider* a, Collider* b, float anchor[3], float axis[3]); -void lovrHingeJointGetAnchors(HingeJoint* joint, float anchor1[3], float anchor2[3]); void lovrHingeJointGetAxis(HingeJoint* joint, float axis[3]); float lovrHingeJointGetAngle(HingeJoint* joint); void lovrHingeJointGetLimits(HingeJoint* joint, float* min, float* max); @@ -337,7 +333,6 @@ void lovrHingeJointGetSpring(HingeJoint* joint, float* frequency, float* damping void lovrHingeJointSetSpring(HingeJoint* joint, float frequency, float damping); SliderJoint* lovrSliderJointCreate(Collider* a, Collider* b, float axis[3]); -void lovrSliderJointGetAnchors(SliderJoint* joint, float anchor1[3], float anchor2[3]); void lovrSliderJointGetAxis(SliderJoint* joint, float axis[3]); float lovrSliderJointGetPosition(SliderJoint* joint); void lovrSliderJointGetLimits(SliderJoint* joint, float* min, float* max);