lovr/src/api/l_physics_joints.c

446 lines
13 KiB
C
Raw Normal View History

2017-12-10 20:40:37 +00:00
#include "api.h"
#include "physics/physics.h"
2022-03-22 07:13:21 +00:00
#include "util.h"
2022-03-31 05:01:51 +00:00
#include <string.h>
void luax_pushjoint(lua_State* L, Joint* joint) {
2022-03-25 19:40:29 +00:00
switch (lovrJointGetType(joint)) {
case JOINT_BALL: luax_pushtype(L, BallJoint, joint); break;
case JOINT_DISTANCE: luax_pushtype(L, DistanceJoint, joint); break;
case JOINT_HINGE: luax_pushtype(L, HingeJoint, joint); break;
case JOINT_SLIDER: luax_pushtype(L, SliderJoint, joint); break;
2022-04-27 07:05:14 +00:00
default: lovrUnreachable();
}
}
Joint* luax_checkjoint(lua_State* L, int index) {
Proxy* p = lua_touserdata(L, index);
2019-09-07 22:07:07 +00:00
if (p) {
const uint64_t hashes[] = {
hash64("BallJoint", strlen("BallJoint")),
hash64("DistanceJoint", strlen("DistanceJoint")),
hash64("HingeJoint", strlen("HingeJoint")),
hash64("SliderJoint", strlen("SliderJoint"))
};
2022-03-23 00:56:26 +00:00
for (size_t i = 0; i < COUNTOF(hashes); i++) {
2019-09-07 22:07:07 +00:00
if (p->hash == hashes[i]) {
return p->object;
}
}
}
2019-09-07 22:07:07 +00:00
2020-08-19 19:12:06 +00:00
luax_typeerror(L, index, "Joint");
2019-09-07 22:07:07 +00:00
return NULL;
}
2019-02-17 22:52:22 +00:00
static int l_lovrJointDestroy(lua_State* L) {
Joint* joint = luax_checkjoint(L, 1);
lovrJointDestroyData(joint);
return 0;
}
static int l_lovrJointIsDestroyed(lua_State* L) {
Joint* joint = luax_checkjoint(L, 1);
bool destroyed = lovrJointIsDestroyed(joint);
lua_pushboolean(L, destroyed);
return 1;
}
2019-02-17 22:52:22 +00:00
static int l_lovrJointGetType(lua_State* L) {
Joint* joint = luax_checkjoint(L, 1);
2020-09-28 00:13:00 +00:00
luax_pushenum(L, JointType, lovrJointGetType(joint));
return 1;
}
2019-02-17 22:52:22 +00:00
static int l_lovrJointGetColliders(lua_State* L) {
Joint* joint = luax_checkjoint(L, 1);
2024-04-08 18:11:28 +00:00
Collider* a = lovrJointGetColliderA(joint);
Collider* b = lovrJointGetColliderB(joint);
luax_pushtype(L, Collider, a);
luax_pushtype(L, Collider, b);
return 2;
}
static void luax_pushjointstash(lua_State* L) {
lua_getfield(L, LUA_REGISTRYINDEX, "_lovrjointstash");
if (lua_isnil(L, -1)) {
lua_newtable(L);
lua_replace(L, -2);
// metatable
lua_newtable(L);
lua_pushliteral(L, "k");
lua_setfield(L, -2, "__mode");
lua_setmetatable(L, -2);
lua_pushvalue(L, -1);
lua_setfield(L, LUA_REGISTRYINDEX, "_lovrjointstash");
}
}
2019-02-17 22:52:22 +00:00
static int l_lovrJointGetUserData(lua_State* L) {
luax_checktype(L, 1, Joint);
luax_pushjointstash(L);
lua_pushvalue(L, 1);
lua_rawget(L, -2);
return 1;
}
2019-02-17 22:52:22 +00:00
static int l_lovrJointSetUserData(lua_State* L) {
luax_checktype(L, 1, Joint);
luax_pushjointstash(L);
lua_pushvalue(L, 1);
lua_pushvalue(L, 2);
lua_rawset(L, -3);
return 0;
}
2019-11-12 00:27:30 +00:00
static int l_lovrJointIsEnabled(lua_State* L) {
Joint* joint = luax_checkjoint(L, 1);
lua_pushboolean(L, lovrJointIsEnabled(joint));
return 1;
}
static int l_lovrJointSetEnabled(lua_State* L) {
Joint* joint = luax_checkjoint(L, 1);
bool enable = lua_toboolean(L, 2);
lovrJointSetEnabled(joint, enable);
return 0;
}
#define lovrJoint \
{ "destroy", l_lovrJointDestroy }, \
{ "isDestroyed", l_lovrJointIsDestroyed }, \
{ "getType", l_lovrJointGetType }, \
{ "getColliders", l_lovrJointGetColliders }, \
{ "getUserData", l_lovrJointGetUserData }, \
2019-11-12 00:27:30 +00:00
{ "setUserData", l_lovrJointSetUserData }, \
{ "isEnabled", l_lovrJointIsEnabled }, \
{ "setEnabled", l_lovrJointSetEnabled }
2019-02-17 22:52:22 +00:00
static int l_lovrBallJointGetAnchors(lua_State* L) {
2017-06-10 22:13:19 +00:00
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;
}
2019-02-17 22:52:22 +00:00
static int l_lovrBallJointSetAnchor(lua_State* L) {
2017-06-10 22:13:19 +00:00
BallJoint* joint = luax_checktype(L, 1, BallJoint);
float anchor[3];
luax_readvec3(L, 2, anchor, NULL);
lovrBallJointSetAnchor(joint, anchor);
return 0;
}
Get/set World and Joint simulation parameters Tightness parameter is amount of force is exerted on collider to resolve collisions and enforce joint operation. Low values make joints loose, high values make it tight and can cause collider to overshot the joint target. With tightness set to 0 the joint loses its function. Going above 1 puts even more energy into joint oscillations. Tightness parameter is called ERP in ODE manual. The responseTime affects the time constant of physics simulation, both for collisions and for joint inertia. Low responseTime values make simulation tight and fast, higher values make it sluggish. For collisions it affects how fast penetration is resolved, with higher values resulting in spongy objects with more surface penetration and slower collision resolving. For joints the responseTime is similar to inertia, with higher responseTime values resulting in slow oscillations. The oscillation frequency is also affected by collider mass, so responseTime can be used to tweak the joint to get desired frequency with specific collider mass. Values higher than 1 are often desirable, especially for very light objects. Unlike tightness, responseTime is tweaked in orders of magnitude with useful values (depending on mass) being between 10^-8 and 10^8. Both parameters can be applied to World for simulation-wide usage, or specified per-joint in case of distance and ball joints. Other joints don't allow customizing these parameters, and will use World settings instead..
2020-05-29 14:38:32 +00:00
static int l_lovrBallJointGetResponseTime(lua_State* L) {
Joint* joint = luax_checkjoint(L, 1);
float responseTime = lovrBallJointGetResponseTime(joint);
lua_pushnumber(L, responseTime);
return 1;
}
static int l_lovrBallJointSetResponseTime(lua_State* L) {
Joint* joint = luax_checkjoint(L, 1);
float responseTime = luax_checkfloat(L, 2);
2024-03-10 07:22:32 +00:00
lovrCheck(responseTime >= 0, "Negative response time causes simulation instability");
Get/set World and Joint simulation parameters Tightness parameter is amount of force is exerted on collider to resolve collisions and enforce joint operation. Low values make joints loose, high values make it tight and can cause collider to overshot the joint target. With tightness set to 0 the joint loses its function. Going above 1 puts even more energy into joint oscillations. Tightness parameter is called ERP in ODE manual. The responseTime affects the time constant of physics simulation, both for collisions and for joint inertia. Low responseTime values make simulation tight and fast, higher values make it sluggish. For collisions it affects how fast penetration is resolved, with higher values resulting in spongy objects with more surface penetration and slower collision resolving. For joints the responseTime is similar to inertia, with higher responseTime values resulting in slow oscillations. The oscillation frequency is also affected by collider mass, so responseTime can be used to tweak the joint to get desired frequency with specific collider mass. Values higher than 1 are often desirable, especially for very light objects. Unlike tightness, responseTime is tweaked in orders of magnitude with useful values (depending on mass) being between 10^-8 and 10^8. Both parameters can be applied to World for simulation-wide usage, or specified per-joint in case of distance and ball joints. Other joints don't allow customizing these parameters, and will use World settings instead..
2020-05-29 14:38:32 +00:00
lovrBallJointSetResponseTime(joint, responseTime);
return 0;
}
static int l_lovrBallJointGetTightness(lua_State* L) {
Joint* joint = luax_checkjoint(L, 1);
float tightness = lovrBallJointGetTightness(joint);
lua_pushnumber(L, tightness);
return 1;
}
static int l_lovrBallJointSetTightness(lua_State* L) {
Joint* joint = luax_checkjoint(L, 1);
float tightness = luax_checkfloat(L, 2);
2024-03-10 07:22:32 +00:00
lovrCheck(tightness >= 0, "Negative tightness factor causes simulation instability");
Get/set World and Joint simulation parameters Tightness parameter is amount of force is exerted on collider to resolve collisions and enforce joint operation. Low values make joints loose, high values make it tight and can cause collider to overshot the joint target. With tightness set to 0 the joint loses its function. Going above 1 puts even more energy into joint oscillations. Tightness parameter is called ERP in ODE manual. The responseTime affects the time constant of physics simulation, both for collisions and for joint inertia. Low responseTime values make simulation tight and fast, higher values make it sluggish. For collisions it affects how fast penetration is resolved, with higher values resulting in spongy objects with more surface penetration and slower collision resolving. For joints the responseTime is similar to inertia, with higher responseTime values resulting in slow oscillations. The oscillation frequency is also affected by collider mass, so responseTime can be used to tweak the joint to get desired frequency with specific collider mass. Values higher than 1 are often desirable, especially for very light objects. Unlike tightness, responseTime is tweaked in orders of magnitude with useful values (depending on mass) being between 10^-8 and 10^8. Both parameters can be applied to World for simulation-wide usage, or specified per-joint in case of distance and ball joints. Other joints don't allow customizing these parameters, and will use World settings instead..
2020-05-29 14:38:32 +00:00
lovrBallJointSetTightness(joint, tightness);
return 0;
}
const luaL_Reg lovrBallJoint[] = {
lovrJoint,
{ "getAnchors", l_lovrBallJointGetAnchors },
{ "setAnchor", l_lovrBallJointSetAnchor },
Get/set World and Joint simulation parameters Tightness parameter is amount of force is exerted on collider to resolve collisions and enforce joint operation. Low values make joints loose, high values make it tight and can cause collider to overshot the joint target. With tightness set to 0 the joint loses its function. Going above 1 puts even more energy into joint oscillations. Tightness parameter is called ERP in ODE manual. The responseTime affects the time constant of physics simulation, both for collisions and for joint inertia. Low responseTime values make simulation tight and fast, higher values make it sluggish. For collisions it affects how fast penetration is resolved, with higher values resulting in spongy objects with more surface penetration and slower collision resolving. For joints the responseTime is similar to inertia, with higher responseTime values resulting in slow oscillations. The oscillation frequency is also affected by collider mass, so responseTime can be used to tweak the joint to get desired frequency with specific collider mass. Values higher than 1 are often desirable, especially for very light objects. Unlike tightness, responseTime is tweaked in orders of magnitude with useful values (depending on mass) being between 10^-8 and 10^8. Both parameters can be applied to World for simulation-wide usage, or specified per-joint in case of distance and ball joints. Other joints don't allow customizing these parameters, and will use World settings instead..
2020-05-29 14:38:32 +00:00
{ "getResponseTime", l_lovrBallJointGetResponseTime},
{ "setResponseTime", l_lovrBallJointSetResponseTime},
{ "getTightness", l_lovrBallJointGetTightness},
{ "setTightness", l_lovrBallJointSetTightness},
{ NULL, NULL }
};
2017-05-25 06:51:27 +00:00
2019-02-17 22:52:22 +00:00
static int l_lovrDistanceJointGetAnchors(lua_State* L) {
2017-06-10 22:13:19 +00:00
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]);
2023-09-13 20:06:51 +00:00
lua_pushnumber(L, anchor2[0]);
lua_pushnumber(L, anchor2[1]);
lua_pushnumber(L, anchor2[2]);
2017-06-10 22:13:19 +00:00
return 6;
}
2019-02-17 22:52:22 +00:00
static int l_lovrDistanceJointSetAnchors(lua_State* L) {
2017-06-10 22:13:19 +00:00
DistanceJoint* joint = luax_checktype(L, 1, DistanceJoint);
float anchor1[3], anchor2[3];
int index = luax_readvec3(L, 2, anchor1, NULL);
luax_readvec3(L, index, anchor2, NULL);
lovrDistanceJointSetAnchors(joint, anchor1, anchor2);
2017-06-10 22:13:19 +00:00
return 0;
}
2019-02-17 22:52:22 +00:00
static int l_lovrDistanceJointGetDistance(lua_State* L) {
2017-06-10 22:13:19 +00:00
DistanceJoint* joint = luax_checktype(L, 1, DistanceJoint);
lua_pushnumber(L, lovrDistanceJointGetDistance(joint));
return 1;
}
2019-02-17 22:52:22 +00:00
static int l_lovrDistanceJointSetDistance(lua_State* L) {
2017-06-10 22:13:19 +00:00
DistanceJoint* joint = luax_checktype(L, 1, DistanceJoint);
float distance = luax_checkfloat(L, 2);
2017-06-10 22:13:19 +00:00
lovrDistanceJointSetDistance(joint, distance);
return 0;
}
Get/set World and Joint simulation parameters Tightness parameter is amount of force is exerted on collider to resolve collisions and enforce joint operation. Low values make joints loose, high values make it tight and can cause collider to overshot the joint target. With tightness set to 0 the joint loses its function. Going above 1 puts even more energy into joint oscillations. Tightness parameter is called ERP in ODE manual. The responseTime affects the time constant of physics simulation, both for collisions and for joint inertia. Low responseTime values make simulation tight and fast, higher values make it sluggish. For collisions it affects how fast penetration is resolved, with higher values resulting in spongy objects with more surface penetration and slower collision resolving. For joints the responseTime is similar to inertia, with higher responseTime values resulting in slow oscillations. The oscillation frequency is also affected by collider mass, so responseTime can be used to tweak the joint to get desired frequency with specific collider mass. Values higher than 1 are often desirable, especially for very light objects. Unlike tightness, responseTime is tweaked in orders of magnitude with useful values (depending on mass) being between 10^-8 and 10^8. Both parameters can be applied to World for simulation-wide usage, or specified per-joint in case of distance and ball joints. Other joints don't allow customizing these parameters, and will use World settings instead..
2020-05-29 14:38:32 +00:00
static int l_lovrDistanceJointGetResponseTime(lua_State* L) {
Joint* joint = luax_checkjoint(L, 1);
float responseTime = lovrDistanceJointGetResponseTime(joint);
lua_pushnumber(L, responseTime);
return 1;
}
static int l_lovrDistanceJointSetResponseTime(lua_State* L) {
Joint* joint = luax_checkjoint(L, 1);
float responseTime = luax_checkfloat(L, 2);
2024-03-10 07:22:32 +00:00
lovrCheck(responseTime >= 0, "Negative response time causes simulation instability");
Get/set World and Joint simulation parameters Tightness parameter is amount of force is exerted on collider to resolve collisions and enforce joint operation. Low values make joints loose, high values make it tight and can cause collider to overshot the joint target. With tightness set to 0 the joint loses its function. Going above 1 puts even more energy into joint oscillations. Tightness parameter is called ERP in ODE manual. The responseTime affects the time constant of physics simulation, both for collisions and for joint inertia. Low responseTime values make simulation tight and fast, higher values make it sluggish. For collisions it affects how fast penetration is resolved, with higher values resulting in spongy objects with more surface penetration and slower collision resolving. For joints the responseTime is similar to inertia, with higher responseTime values resulting in slow oscillations. The oscillation frequency is also affected by collider mass, so responseTime can be used to tweak the joint to get desired frequency with specific collider mass. Values higher than 1 are often desirable, especially for very light objects. Unlike tightness, responseTime is tweaked in orders of magnitude with useful values (depending on mass) being between 10^-8 and 10^8. Both parameters can be applied to World for simulation-wide usage, or specified per-joint in case of distance and ball joints. Other joints don't allow customizing these parameters, and will use World settings instead..
2020-05-29 14:38:32 +00:00
lovrDistanceJointSetResponseTime(joint, responseTime);
return 0;
}
static int l_lovrDistanceJointGetTightness(lua_State* L) {
Joint* joint = luax_checkjoint(L, 1);
float tightness = lovrDistanceJointGetTightness(joint);
lua_pushnumber(L, tightness);
return 1;
}
static int l_lovrDistanceJointSetTightness(lua_State* L) {
Joint* joint = luax_checkjoint(L, 1);
float tightness = luax_checkfloat(L, 2);
2024-03-10 07:22:32 +00:00
lovrCheck(tightness >= 0, "Negative tightness factor causes simulation instability");
Get/set World and Joint simulation parameters Tightness parameter is amount of force is exerted on collider to resolve collisions and enforce joint operation. Low values make joints loose, high values make it tight and can cause collider to overshot the joint target. With tightness set to 0 the joint loses its function. Going above 1 puts even more energy into joint oscillations. Tightness parameter is called ERP in ODE manual. The responseTime affects the time constant of physics simulation, both for collisions and for joint inertia. Low responseTime values make simulation tight and fast, higher values make it sluggish. For collisions it affects how fast penetration is resolved, with higher values resulting in spongy objects with more surface penetration and slower collision resolving. For joints the responseTime is similar to inertia, with higher responseTime values resulting in slow oscillations. The oscillation frequency is also affected by collider mass, so responseTime can be used to tweak the joint to get desired frequency with specific collider mass. Values higher than 1 are often desirable, especially for very light objects. Unlike tightness, responseTime is tweaked in orders of magnitude with useful values (depending on mass) being between 10^-8 and 10^8. Both parameters can be applied to World for simulation-wide usage, or specified per-joint in case of distance and ball joints. Other joints don't allow customizing these parameters, and will use World settings instead..
2020-05-29 14:38:32 +00:00
lovrDistanceJointSetTightness(joint, tightness);
return 0;
}
2017-06-10 22:13:19 +00:00
const luaL_Reg lovrDistanceJoint[] = {
lovrJoint,
2017-06-10 22:13:19 +00:00
{ "getAnchors", l_lovrDistanceJointGetAnchors },
{ "setAnchors", l_lovrDistanceJointSetAnchors },
{ "getDistance", l_lovrDistanceJointGetDistance },
{ "setDistance", l_lovrDistanceJointSetDistance },
Get/set World and Joint simulation parameters Tightness parameter is amount of force is exerted on collider to resolve collisions and enforce joint operation. Low values make joints loose, high values make it tight and can cause collider to overshot the joint target. With tightness set to 0 the joint loses its function. Going above 1 puts even more energy into joint oscillations. Tightness parameter is called ERP in ODE manual. The responseTime affects the time constant of physics simulation, both for collisions and for joint inertia. Low responseTime values make simulation tight and fast, higher values make it sluggish. For collisions it affects how fast penetration is resolved, with higher values resulting in spongy objects with more surface penetration and slower collision resolving. For joints the responseTime is similar to inertia, with higher responseTime values resulting in slow oscillations. The oscillation frequency is also affected by collider mass, so responseTime can be used to tweak the joint to get desired frequency with specific collider mass. Values higher than 1 are often desirable, especially for very light objects. Unlike tightness, responseTime is tweaked in orders of magnitude with useful values (depending on mass) being between 10^-8 and 10^8. Both parameters can be applied to World for simulation-wide usage, or specified per-joint in case of distance and ball joints. Other joints don't allow customizing these parameters, and will use World settings instead..
2020-05-29 14:38:32 +00:00
{ "getResponseTime", l_lovrDistanceJointGetResponseTime},
{ "setResponseTime", l_lovrDistanceJointSetResponseTime},
{ "getTightness", l_lovrDistanceJointGetTightness},
{ "setTightness", l_lovrDistanceJointSetTightness},
2017-06-10 22:13:19 +00:00
{ NULL, NULL }
};
2019-02-17 22:52:22 +00:00
static int l_lovrHingeJointGetAnchors(lua_State* L) {
2017-06-10 22:13:19 +00:00
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]);
2017-05-25 06:51:27 +00:00
return 6;
}
2019-02-17 22:52:22 +00:00
static int l_lovrHingeJointSetAnchor(lua_State* L) {
2017-06-10 22:13:19 +00:00
HingeJoint* joint = luax_checktype(L, 1, HingeJoint);
float anchor[3];
luax_readvec3(L, 2, anchor, NULL);
lovrHingeJointSetAnchor(joint, anchor);
2017-05-25 06:51:27 +00:00
return 0;
}
2019-02-17 22:52:22 +00:00
static int l_lovrHingeJointGetAxis(lua_State* L) {
2017-06-10 22:13:19 +00:00
HingeJoint* joint = luax_checktype(L, 1, HingeJoint);
float axis[3];
lovrHingeJointGetAxis(joint, axis);
lua_pushnumber(L, axis[0]);
lua_pushnumber(L, axis[1]);
lua_pushnumber(L, axis[2]);
2017-05-25 06:51:27 +00:00
return 3;
}
2019-02-17 22:52:22 +00:00
static int l_lovrHingeJointSetAxis(lua_State* L) {
2017-06-10 22:13:19 +00:00
HingeJoint* joint = luax_checktype(L, 1, HingeJoint);
float axis[3];
luax_readvec3(L, 2, axis, NULL);
lovrHingeJointSetAxis(joint, axis);
2017-05-25 06:51:27 +00:00
return 0;
}
2019-02-17 22:52:22 +00:00
static int l_lovrHingeJointGetAngle(lua_State* L) {
2017-06-10 22:13:19 +00:00
HingeJoint* joint = luax_checktype(L, 1, HingeJoint);
lua_pushnumber(L, lovrHingeJointGetAngle(joint));
2017-05-25 06:51:27 +00:00
return 1;
}
2019-02-17 22:52:22 +00:00
static int l_lovrHingeJointGetLowerLimit(lua_State* L) {
2017-06-10 22:13:19 +00:00
HingeJoint* joint = luax_checktype(L, 1, HingeJoint);
lua_pushnumber(L, lovrHingeJointGetLowerLimit(joint));
2017-05-25 22:20:55 +00:00
return 1;
}
2019-02-17 22:52:22 +00:00
static int l_lovrHingeJointSetLowerLimit(lua_State* L) {
2017-06-10 22:13:19 +00:00
HingeJoint* joint = luax_checktype(L, 1, HingeJoint);
float limit = luax_checkfloat(L, 2);
2017-06-10 22:13:19 +00:00
lovrHingeJointSetLowerLimit(joint, limit);
2017-05-25 22:20:55 +00:00
return 0;
}
2019-02-17 22:52:22 +00:00
static int l_lovrHingeJointGetUpperLimit(lua_State* L) {
2017-06-10 22:13:19 +00:00
HingeJoint* joint = luax_checktype(L, 1, HingeJoint);
lua_pushnumber(L, lovrHingeJointGetUpperLimit(joint));
2017-05-25 22:20:55 +00:00
return 1;
}
2019-02-17 22:52:22 +00:00
static int l_lovrHingeJointSetUpperLimit(lua_State* L) {
2017-06-10 22:13:19 +00:00
HingeJoint* joint = luax_checktype(L, 1, HingeJoint);
float limit = luax_checkfloat(L, 2);
2017-06-10 22:13:19 +00:00
lovrHingeJointSetUpperLimit(joint, limit);
2017-05-25 22:20:55 +00:00
return 0;
}
2019-02-17 22:52:22 +00:00
static int l_lovrHingeJointGetLimits(lua_State* L) {
2017-06-10 22:13:19 +00:00
HingeJoint* joint = luax_checktype(L, 1, HingeJoint);
lua_pushnumber(L, lovrHingeJointGetLowerLimit(joint));
lua_pushnumber(L, lovrHingeJointGetUpperLimit(joint));
2017-05-25 22:20:55 +00:00
return 2;
}
2019-02-17 22:52:22 +00:00
static int l_lovrHingeJointSetLimits(lua_State* L) {
2017-06-10 22:13:19 +00:00
HingeJoint* joint = luax_checktype(L, 1, HingeJoint);
float lower = luax_checkfloat(L, 2);
float upper = luax_checkfloat(L, 3);
2017-06-10 22:13:19 +00:00
lovrHingeJointSetLowerLimit(joint, lower);
lovrHingeJointSetUpperLimit(joint, upper);
2017-05-25 22:20:55 +00:00
return 0;
}
2017-05-25 06:51:27 +00:00
const luaL_Reg lovrHingeJoint[] = {
lovrJoint,
2017-05-25 06:51:27 +00:00
{ "getAnchors", l_lovrHingeJointGetAnchors },
{ "setAnchor", l_lovrHingeJointSetAnchor },
{ "getAxis", l_lovrHingeJointGetAxis },
{ "setAxis", l_lovrHingeJointSetAxis },
{ "getAngle", l_lovrHingeJointGetAngle },
2017-05-25 22:20:55 +00:00
{ "getLowerLimit", l_lovrHingeJointGetLowerLimit },
{ "setLowerLimit", l_lovrHingeJointSetLowerLimit },
{ "getUpperLimit", l_lovrHingeJointGetUpperLimit },
{ "setUpperLimit", l_lovrHingeJointSetUpperLimit },
{ "getLimits", l_lovrHingeJointGetLimits },
{ "setLimits", l_lovrHingeJointSetLimits },
2017-05-25 06:51:27 +00:00
{ NULL, NULL }
};
2017-05-25 07:48:02 +00:00
2019-02-17 22:52:22 +00:00
static int l_lovrSliderJointGetAxis(lua_State* L) {
2017-06-10 22:13:19 +00:00
SliderJoint* joint = luax_checktype(L, 1, SliderJoint);
float axis[3];
lovrSliderJointGetAxis(joint, axis);
lua_pushnumber(L, axis[0]);
lua_pushnumber(L, axis[1]);
lua_pushnumber(L, axis[2]);
2017-05-25 07:48:02 +00:00
return 3;
}
2019-02-17 22:52:22 +00:00
static int l_lovrSliderJointSetAxis(lua_State* L) {
2017-06-10 22:13:19 +00:00
SliderJoint* joint = luax_checktype(L, 1, SliderJoint);
float axis[3];
luax_readvec3(L, 2, axis, NULL);
lovrSliderJointSetAxis(joint, axis);
2017-05-25 07:48:02 +00:00
return 0;
}
2019-02-17 22:52:22 +00:00
static int l_lovrSliderJointGetPosition(lua_State* L) {
2017-06-10 22:13:19 +00:00
SliderJoint* joint = luax_checktype(L, 1, SliderJoint);
lua_pushnumber(L, lovrSliderJointGetPosition(joint));
2017-05-25 07:48:02 +00:00
return 1;
}
2019-02-17 22:52:22 +00:00
static int l_lovrSliderJointGetLowerLimit(lua_State* L) {
2017-06-10 22:13:19 +00:00
SliderJoint* joint = luax_checktype(L, 1, SliderJoint);
lua_pushnumber(L, lovrSliderJointGetLowerLimit(joint));
2017-05-25 22:20:55 +00:00
return 1;
}
2019-02-17 22:52:22 +00:00
static int l_lovrSliderJointSetLowerLimit(lua_State* L) {
2017-06-10 22:13:19 +00:00
SliderJoint* joint = luax_checktype(L, 1, SliderJoint);
float limit = luax_checkfloat(L, 2);
2017-06-10 22:13:19 +00:00
lovrSliderJointSetLowerLimit(joint, limit);
2017-05-25 22:20:55 +00:00
return 0;
}
2019-02-17 22:52:22 +00:00
static int l_lovrSliderJointGetUpperLimit(lua_State* L) {
2017-06-10 22:13:19 +00:00
SliderJoint* joint = luax_checktype(L, 1, SliderJoint);
lua_pushnumber(L, lovrSliderJointGetUpperLimit(joint));
2017-05-25 22:20:55 +00:00
return 1;
}
2019-02-17 22:52:22 +00:00
static int l_lovrSliderJointSetUpperLimit(lua_State* L) {
2017-06-10 22:13:19 +00:00
SliderJoint* joint = luax_checktype(L, 1, SliderJoint);
float limit = luax_checkfloat(L, 2);
2017-06-10 22:13:19 +00:00
lovrSliderJointSetUpperLimit(joint, limit);
2017-05-25 22:20:55 +00:00
return 0;
}
2019-02-17 22:52:22 +00:00
static int l_lovrSliderJointGetLimits(lua_State* L) {
2017-06-10 22:13:19 +00:00
SliderJoint* joint = luax_checktype(L, 1, SliderJoint);
lua_pushnumber(L, lovrSliderJointGetLowerLimit(joint));
lua_pushnumber(L, lovrSliderJointGetUpperLimit(joint));
2017-05-25 22:20:55 +00:00
return 2;
}
2019-02-17 22:52:22 +00:00
static int l_lovrSliderJointSetLimits(lua_State* L) {
2017-06-10 22:13:19 +00:00
SliderJoint* joint = luax_checktype(L, 1, SliderJoint);
float lower = luax_checkfloat(L, 2);
float upper = luax_checkfloat(L, 3);
2017-06-10 22:13:19 +00:00
lovrSliderJointSetLowerLimit(joint, lower);
lovrSliderJointSetUpperLimit(joint, upper);
2017-05-25 22:20:55 +00:00
return 0;
}
2017-05-25 07:48:02 +00:00
const luaL_Reg lovrSliderJoint[] = {
lovrJoint,
2017-05-25 07:48:02 +00:00
{ "getAxis", l_lovrSliderJointGetAxis },
{ "setAxis", l_lovrSliderJointSetAxis },
2017-05-25 22:20:55 +00:00
{ "getPosition", l_lovrSliderJointGetPosition },
{ "getLowerLimit", l_lovrSliderJointGetLowerLimit },
{ "setLowerLimit", l_lovrSliderJointSetLowerLimit },
{ "getUpperLimit", l_lovrSliderJointGetUpperLimit },
{ "setUpperLimit", l_lovrSliderJointSetUpperLimit },
{ "getLimits", l_lovrSliderJointGetLimits },
{ "setLimits", l_lovrSliderJointSetLimits },
2017-05-25 07:48:02 +00:00
{ NULL, NULL }
};