mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-13 15:01:49 +00:00
add rigidbody:is_selectable, :set_selectable
This commit is contained in:
parent
04c367b476
commit
4b4026b028
6 changed files with 26 additions and 2 deletions
|
|
@ -39,6 +39,8 @@ local Rigidbody = {__index={
|
||||||
set_mass=function(self, v) return __rigidbody.set_mass(self.eid, v) end,
|
set_mass=function(self, v) return __rigidbody.set_mass(self.eid, v) end,
|
||||||
set_elasticity=function(self, v) return __rigidbody.set_elasticity(self.eid, v) end,
|
set_elasticity=function(self, v) return __rigidbody.set_elasticity(self.eid, v) end,
|
||||||
get_ground_vel=function(self) return __rigidbody.get_ground_vel(self.eid) end,
|
get_ground_vel=function(self) return __rigidbody.get_ground_vel(self.eid) end,
|
||||||
|
is_selectable=function (self) return __rigidbody.is_selectable(self.eid) end,
|
||||||
|
set_selectable=function (self, b) return __rigidbody.set_selectable(self.eid, b) end,
|
||||||
}}
|
}}
|
||||||
|
|
||||||
local function new_Rigidbody(eid)
|
local function new_Rigidbody(eid)
|
||||||
|
|
|
||||||
|
|
@ -199,6 +199,20 @@ static int l_get_ground_vel(lua::State* L) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int l_is_selectable(lua::State* L) {
|
||||||
|
if (auto entity = get_entity(L, 1)) {
|
||||||
|
return lua::pushboolean(L, entity->getRigidbody().hitbox.selectable);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int l_set_selectable(lua::State* L) {
|
||||||
|
if (auto entity = get_entity(L, 1)) {
|
||||||
|
entity->getRigidbody().selectable = lua::toboolean(L, 2);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
const luaL_Reg rigidbodylib[] = {
|
const luaL_Reg rigidbodylib[] = {
|
||||||
{"is_enabled", lua::wrap<l_is_enabled>},
|
{"is_enabled", lua::wrap<l_is_enabled>},
|
||||||
|
|
@ -226,5 +240,7 @@ const luaL_Reg rigidbodylib[] = {
|
||||||
{"get_elasticity", lua::wrap<l_get_elasticity>},
|
{"get_elasticity", lua::wrap<l_get_elasticity>},
|
||||||
{"set_elasticity", lua::wrap<l_set_elasticity>},
|
{"set_elasticity", lua::wrap<l_set_elasticity>},
|
||||||
{"get_ground_vel", lua::wrap<l_get_ground_vel>},
|
{"get_ground_vel", lua::wrap<l_get_ground_vel>},
|
||||||
|
{"is_selectable", lua::wrap<l_is_selectable>},
|
||||||
|
{"set_selectable", lua::wrap<l_set_selectable>},
|
||||||
{nullptr, nullptr}
|
{nullptr, nullptr}
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -175,9 +175,10 @@ std::optional<Entities::RaycastResult> Entities::rayCast(
|
||||||
glm::ivec3 foundNormal;
|
glm::ivec3 foundNormal;
|
||||||
|
|
||||||
for (auto [entity, eid, transform, body] : view.each()) {
|
for (auto [entity, eid, transform, body] : view.each()) {
|
||||||
|
const auto& hitbox = body.hitbox;
|
||||||
if (eid.uid == settings.ignoredUid || !body.enabled ||
|
if (eid.uid == settings.ignoredUid || !body.enabled ||
|
||||||
(settings.solidEntitiesOnly && !eid.def.solid) ||
|
(settings.solidEntitiesOnly && !eid.def.solid) ||
|
||||||
(!eid.def.selectable && !settings.includeNonSelectable)) {
|
(!hitbox.selectable && !settings.includeNonSelectable)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (settings.entitiesFilter) {
|
if (settings.entitiesFilter) {
|
||||||
|
|
@ -187,7 +188,6 @@ std::optional<Entities::RaycastResult> Entities::rayCast(
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const auto& hitbox = body.hitbox;
|
|
||||||
glm::ivec3 normal;
|
glm::ivec3 normal;
|
||||||
double distance;
|
double distance;
|
||||||
if (ray.intersectAABB(
|
if (ray.intersectAABB(
|
||||||
|
|
@ -330,6 +330,7 @@ void Entities::preparePhysics(float delta) {
|
||||||
? rigidbody.mass
|
? rigidbody.mass
|
||||||
: std::numeric_limits<float>::infinity();
|
: std::numeric_limits<float>::infinity();
|
||||||
rigidbody.hitbox.elasticity = rigidbody.elasticity;
|
rigidbody.hitbox.elasticity = rigidbody.elasticity;
|
||||||
|
rigidbody.hitbox.selectable = rigidbody.selectable;
|
||||||
hitboxes.emplace_back(&rigidbody.hitbox);
|
hitboxes.emplace_back(&rigidbody.hitbox);
|
||||||
if (!eid.def.solid) {
|
if (!eid.def.solid) {
|
||||||
continue;
|
continue;
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,7 @@ dv::value Rigidbody::serialize(bool saveVelocity, bool saveBodySettings) const {
|
||||||
}
|
}
|
||||||
bodymap["mass"] = mass;
|
bodymap["mass"] = mass;
|
||||||
bodymap["elasticity"] = elasticity;
|
bodymap["elasticity"] = elasticity;
|
||||||
|
bodymap["selectable"] = selectable;
|
||||||
}
|
}
|
||||||
return bodymap;
|
return bodymap;
|
||||||
}
|
}
|
||||||
|
|
@ -37,6 +38,7 @@ void Rigidbody::deserialize(const dv::value& root) {
|
||||||
root["damping"].asNumber(hitbox.linearDamping);
|
root["damping"].asNumber(hitbox.linearDamping);
|
||||||
root["mass"].asNumber(mass);
|
root["mass"].asNumber(mass);
|
||||||
root["elasticity"].asNumber(elasticity);
|
root["elasticity"].asNumber(elasticity);
|
||||||
|
root["selectable"].asBoolean(selectable);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <void (*callback)(const Entity&, size_t, entityid_t)>
|
template <void (*callback)(const Entity&, size_t, entityid_t)>
|
||||||
|
|
@ -55,6 +57,7 @@ void Rigidbody::initialize(
|
||||||
) {
|
) {
|
||||||
mass = def.mass;
|
mass = def.mass;
|
||||||
elasticity = def.elasticity;
|
elasticity = def.elasticity;
|
||||||
|
selectable = def.selectable;
|
||||||
sensors.resize(def.radialSensors.size() + def.boxSensors.size());
|
sensors.resize(def.radialSensors.size() + def.boxSensors.size());
|
||||||
for (auto& [i, box] : def.boxSensors) {
|
for (auto& [i, box] : def.boxSensors) {
|
||||||
SensorParams params {};
|
SensorParams params {};
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,7 @@ struct Rigidbody {
|
||||||
std::vector<Sensor> sensors;
|
std::vector<Sensor> sensors;
|
||||||
float mass;
|
float mass;
|
||||||
float elasticity;
|
float elasticity;
|
||||||
|
bool selectable;
|
||||||
|
|
||||||
dv::value serialize(bool saveVelocity, bool saveBodySettings) const;
|
dv::value serialize(bool saveVelocity, bool saveBodySettings) const;
|
||||||
void deserialize(const dv::value& root);
|
void deserialize(const dv::value& root);
|
||||||
|
|
|
||||||
|
|
@ -65,6 +65,7 @@ struct Hitbox {
|
||||||
float stepHeight = 0.5f;
|
float stepHeight = 0.5f;
|
||||||
float mass = 1.0f;
|
float mass = 1.0f;
|
||||||
float elasticity = 0.0f;
|
float elasticity = 0.0f;
|
||||||
|
bool selectable = true;
|
||||||
std::string material;
|
std::string material;
|
||||||
std::string groundMaterial;
|
std::string groundMaterial;
|
||||||
glm::vec3 groundVelocity {};
|
glm::vec3 groundVelocity {};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue