add entities.raycast & update docs structure
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
#include "../../../physics/Hitbox.hpp"
|
||||
#include "../../../window/Camera.hpp"
|
||||
#include "../../../content/Content.hpp"
|
||||
#include "../../../voxels/Chunks.hpp"
|
||||
#include "../../../engine.hpp"
|
||||
|
||||
using namespace scripting;
|
||||
@@ -53,11 +54,77 @@ static int l_set_skeleton(lua::State* L) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int l_raycast(lua::State* L) {
|
||||
auto start = lua::tovec<3>(L, 1);
|
||||
auto dir = lua::tovec<3>(L, 2);
|
||||
auto maxDistance = lua::tonumber(L, 3);
|
||||
auto ignore = lua::tointeger(L, 4);
|
||||
glm::vec3 end;
|
||||
glm::ivec3 normal;
|
||||
glm::ivec3 iend;
|
||||
|
||||
blockid_t block = BLOCK_VOID;
|
||||
|
||||
if (auto voxel = level->chunks->rayCast(start, dir, maxDistance, end, normal, iend)) {
|
||||
maxDistance = glm::distance(start, end);
|
||||
block = voxel->id;
|
||||
}
|
||||
if (auto ray = level->entities->rayCast(start, dir, maxDistance, ignore)) {
|
||||
if (lua::gettop(L) >= 5) {
|
||||
lua::pushvalue(L, 5);
|
||||
} else {
|
||||
lua::createtable(L, 0, 6);
|
||||
}
|
||||
|
||||
lua::pushvec3_arr(L, start + dir * ray->distance);
|
||||
lua::setfield(L, "endpoint");
|
||||
|
||||
lua::pushvec3_arr(L, ray->normal);
|
||||
lua::setfield(L, "normal");
|
||||
|
||||
lua::pushnumber(L, glm::distance(start, end));
|
||||
lua::setfield(L, "length");
|
||||
|
||||
lua::pushvec3_arr(L, iend);
|
||||
lua::setfield(L, "iendpoint");
|
||||
|
||||
lua::pushinteger(L, block);
|
||||
lua::setfield(L, "block");
|
||||
|
||||
lua::pushinteger(L, ray->entity);
|
||||
lua::setfield(L, "entity");
|
||||
return 1;
|
||||
} else if (block != BLOCK_VOID) {
|
||||
if (lua::gettop(L) >= 5) {
|
||||
lua::pushvalue(L, 5);
|
||||
} else {
|
||||
lua::createtable(L, 0, 5);
|
||||
}
|
||||
lua::pushvec3_arr(L, end);
|
||||
lua::setfield(L, "endpoint");
|
||||
|
||||
lua::pushvec3_arr(L, normal);
|
||||
lua::setfield(L, "normal");
|
||||
|
||||
lua::pushnumber(L, glm::distance(start, end));
|
||||
lua::setfield(L, "length");
|
||||
|
||||
lua::pushvec3_arr(L, iend);
|
||||
lua::setfield(L, "iendpoint");
|
||||
|
||||
lua::pushinteger(L, block);
|
||||
lua::setfield(L, "block");
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
const luaL_Reg entitylib [] = {
|
||||
{"exists", lua::wrap<l_exists>},
|
||||
{"spawn", lua::wrap<l_spawn>},
|
||||
{"despawn", lua::wrap<l_despawn>},
|
||||
{"get_skeleton", lua::wrap<l_get_skeleton>},
|
||||
{"set_skeleton", lua::wrap<l_set_skeleton>},
|
||||
{"raycast", lua::wrap<l_raycast>},
|
||||
{NULL, NULL}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user