add Transform and Rigidbody components (test)
This commit is contained in:
parent
f70e923c7c
commit
94dd69350d
@ -7,7 +7,7 @@ function on_hud_open()
|
|||||||
local pvel = {player.get_vel(pid)}
|
local pvel = {player.get_vel(pid)}
|
||||||
local eid = entity.spawn("base:drop")
|
local eid = entity.spawn("base:drop")
|
||||||
local throw_force = vec3.mul(player.get_dir(pid), DROP_FORCE)
|
local throw_force = vec3.mul(player.get_dir(pid), DROP_FORCE)
|
||||||
entity.set_vel(eid, vec3.add(throw_force, vec3.add(pvel, DROP_INIT_VEL)))
|
Rigidbody.set_vel(eid, vec3.add(throw_force, vec3.add(pvel, DROP_INIT_VEL)))
|
||||||
entity.set_rot(eid, mat4.rotate({0, 1, 0}, math.random() * 360))
|
Transform.set_rot(eid, mat4.rotate({0, 1, 0}, math.random() * 360))
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|||||||
@ -21,8 +21,10 @@ extern const luaL_Reg jsonlib [];
|
|||||||
extern const luaL_Reg mat4lib [];
|
extern const luaL_Reg mat4lib [];
|
||||||
extern const luaL_Reg packlib [];
|
extern const luaL_Reg packlib [];
|
||||||
extern const luaL_Reg playerlib [];
|
extern const luaL_Reg playerlib [];
|
||||||
|
extern const luaL_Reg rigidbodylib [];
|
||||||
extern const luaL_Reg timelib [];
|
extern const luaL_Reg timelib [];
|
||||||
extern const luaL_Reg tomllib [];
|
extern const luaL_Reg tomllib [];
|
||||||
|
extern const luaL_Reg transformlib [];
|
||||||
extern const luaL_Reg vec2lib [];
|
extern const luaL_Reg vec2lib [];
|
||||||
extern const luaL_Reg vec3lib [];
|
extern const luaL_Reg vec3lib [];
|
||||||
extern const luaL_Reg vec4lib [];
|
extern const luaL_Reg vec4lib [];
|
||||||
|
|||||||
@ -31,6 +31,20 @@ static int l_spawn(lua::State* L) {
|
|||||||
return lua::pushinteger(L, id);
|
return lua::pushinteger(L, id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int l_get_pos(lua::State* L) {
|
||||||
|
if (auto entity = get_entity(L, 1)) {
|
||||||
|
return lua::pushvec3_arr(L, entity->getTransform().pos);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int l_set_pos(lua::State* L) {
|
||||||
|
if (auto entity = get_entity(L, 1)) {
|
||||||
|
entity->getTransform().pos = lua::tovec3(L, 2);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static int l_get_vel(lua::State* L) {
|
static int l_get_vel(lua::State* L) {
|
||||||
if (auto entity = get_entity(L, 1)) {
|
if (auto entity = get_entity(L, 1)) {
|
||||||
return lua::pushvec3_arr(L, entity->getHitbox().velocity);
|
return lua::pushvec3_arr(L, entity->getHitbox().velocity);
|
||||||
@ -61,9 +75,19 @@ static int l_set_rot(lua::State* L) {
|
|||||||
|
|
||||||
const luaL_Reg entitylib [] = {
|
const luaL_Reg entitylib [] = {
|
||||||
{"spawn", lua::wrap<l_spawn>},
|
{"spawn", lua::wrap<l_spawn>},
|
||||||
{"get_vel", lua::wrap<l_get_vel>},
|
{NULL, NULL}
|
||||||
{"set_vel", lua::wrap<l_set_vel>},
|
};
|
||||||
|
|
||||||
|
const luaL_Reg transformlib [] = {
|
||||||
|
{"get_pos", lua::wrap<l_get_pos>},
|
||||||
|
{"set_pos", lua::wrap<l_set_pos>},
|
||||||
{"get_rot", lua::wrap<l_get_rot>},
|
{"get_rot", lua::wrap<l_get_rot>},
|
||||||
{"set_rot", lua::wrap<l_set_rot>},
|
{"set_rot", lua::wrap<l_set_rot>},
|
||||||
{NULL, NULL}
|
{NULL, NULL}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const luaL_Reg rigidbodylib [] = {
|
||||||
|
{"get_vel", lua::wrap<l_get_vel>},
|
||||||
|
{"set_vel", lua::wrap<l_set_vel>},
|
||||||
|
{NULL, NULL}
|
||||||
|
};
|
||||||
|
|||||||
@ -48,6 +48,10 @@ static void create_libs(lua::State* L) {
|
|||||||
openlib(L, "vec4", vec4lib);
|
openlib(L, "vec4", vec4lib);
|
||||||
openlib(L, "world", worldlib);
|
openlib(L, "world", worldlib);
|
||||||
|
|
||||||
|
// components
|
||||||
|
openlib(L, "Rigidbody", rigidbodylib);
|
||||||
|
openlib(L, "Transform", transformlib);
|
||||||
|
|
||||||
addfunc(L, "print", lua::wrap<l_print>);
|
addfunc(L, "print", lua::wrap<l_print>);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user