mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-13 15:01:49 +00:00
commit
cbb1ad5d9c
10 changed files with 89 additions and 50 deletions
|
|
@ -13,6 +13,7 @@ block.__perform_ticks = function(delta)
|
||||||
goto continue
|
goto continue
|
||||||
end
|
end
|
||||||
entry.timer = 0.0
|
entry.timer = 0.0
|
||||||
|
entry.pointer = entry.pointer % #entry
|
||||||
local event = entry.event
|
local event = entry.event
|
||||||
local tps = entry.tps
|
local tps = entry.tps
|
||||||
for i=1, steps do
|
for i=1, steps do
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,13 @@ void HandsRenderer::renderHands(
|
||||||
const auto& config = *skeleton.config;
|
const auto& config = *skeleton.config;
|
||||||
|
|
||||||
modelBatch.setLightsOffset(camera.position);
|
modelBatch.setLightsOffset(camera.position);
|
||||||
config.update(skeleton, glm::mat4(1.0f), glm::vec3());
|
config.update(skeleton, glm::mat4(1.0f), glm::vec3(), glm::vec3(1.0f));
|
||||||
config.render(assets, modelBatch, skeleton, glm::mat3(1.0f), glm::vec3());
|
config.render(
|
||||||
|
assets,
|
||||||
|
modelBatch,
|
||||||
|
skeleton,
|
||||||
|
glm::mat3(1.0f),
|
||||||
|
glm::vec3(),
|
||||||
|
glm::vec3(1.0f)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -134,16 +134,16 @@ void Skybox::draw(
|
||||||
DrawContext ctx = pctx.sub();
|
DrawContext ctx = pctx.sub();
|
||||||
ctx.setBlendMode(BlendMode::addition);
|
ctx.setBlendMode(BlendMode::addition);
|
||||||
|
|
||||||
auto p_shader = assets.get<Shader>("ui3d");
|
auto shader = assets.get<Shader>("ui3d");
|
||||||
p_shader->use();
|
shader->use();
|
||||||
p_shader->uniformMatrix("u_projview", camera.getProjView(false));
|
shader->uniformMatrix("u_projview", camera.getProjView(false));
|
||||||
p_shader->uniformMatrix("u_apply", glm::mat4(1.0f));
|
shader->uniformMatrix("u_apply", glm::mat4(1.0f));
|
||||||
batch3d->begin();
|
batch3d->begin();
|
||||||
|
|
||||||
float angle = daytime * glm::pi<float>() * 2.0f;
|
float angle = daytime * glm::pi<float>() * 2.0f;
|
||||||
float opacity = glm::pow(1.0f - fog, 7.0f);
|
float opacity = glm::pow(1.0f - fog, 7.0f);
|
||||||
|
|
||||||
float depthScale = 1e3;
|
float depthScale = 2e3;
|
||||||
for (auto& sprite : sprites) {
|
for (auto& sprite : sprites) {
|
||||||
batch3d->texture(assets.get<Texture>(sprite.texture));
|
batch3d->texture(assets.get<Texture>(sprite.texture));
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -79,6 +79,33 @@ void ModelViewer::act(float delta) {
|
||||||
camera.position = center - camera.front * distance;
|
camera.position = center - camera.front * distance;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static util::TextureRegion determine_texture_region(
|
||||||
|
const Assets& assets, const std::string& texture
|
||||||
|
) {
|
||||||
|
static std::array<std::string, 6> faces {
|
||||||
|
"blocks:dbg_north",
|
||||||
|
"blocks:dbg_south",
|
||||||
|
"blocks:dbg_top",
|
||||||
|
"blocks:dbg_bottom",
|
||||||
|
"blocks:dbg_west",
|
||||||
|
"blocks:dbg_east",
|
||||||
|
};
|
||||||
|
|
||||||
|
if (texture.length() < 2 || texture.at(0) != '$') {
|
||||||
|
return util::get_texture_region(assets, texture, "blocks:notfound");
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned char sideIndex = texture.at(1) - '0';
|
||||||
|
if (sideIndex < faces.size()) {
|
||||||
|
return util::get_texture_region(
|
||||||
|
assets,
|
||||||
|
faces.at(texture.at(1) - '0'),
|
||||||
|
"blocks:notfound"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return util::get_texture_region(assets, "blocks:notfound", "");
|
||||||
|
}
|
||||||
|
|
||||||
void ModelViewer::draw(const DrawContext& pctx, const Assets& assets) {
|
void ModelViewer::draw(const DrawContext& pctx, const Assets& assets) {
|
||||||
camera.setAspectRatio(size.x / size.y);
|
camera.setAspectRatio(size.x / size.y);
|
||||||
camera.updateVectors();
|
camera.updateVectors();
|
||||||
|
|
@ -104,26 +131,10 @@ void ModelViewer::draw(const DrawContext& pctx, const Assets& assets) {
|
||||||
ui3dShader.uniformMatrix("u_apply", glm::mat4(1.0f));
|
ui3dShader.uniformMatrix("u_apply", glm::mat4(1.0f));
|
||||||
ui3dShader.uniformMatrix("u_projview", camera.getProjView());
|
ui3dShader.uniformMatrix("u_projview", camera.getProjView());
|
||||||
batch->begin();
|
batch->begin();
|
||||||
|
|
||||||
for (const auto& mesh : model->meshes) {
|
for (const auto& mesh : model->meshes) {
|
||||||
util::TextureRegion region;
|
auto region = determine_texture_region(assets, mesh.texture);
|
||||||
if (!mesh.texture.empty() && mesh.texture[0] == '$') {
|
|
||||||
// todo: refactor
|
|
||||||
static std::array<std::string, 6> faces {
|
|
||||||
"blocks:dbg_north",
|
|
||||||
"blocks:dbg_south",
|
|
||||||
"blocks:dbg_top",
|
|
||||||
"blocks:dbg_bottom",
|
|
||||||
"blocks:dbg_west",
|
|
||||||
"blocks:dbg_east",
|
|
||||||
};
|
|
||||||
region = util::get_texture_region(
|
|
||||||
assets,
|
|
||||||
faces.at(mesh.texture.at(1) - '0'),
|
|
||||||
"blocks:notfound"
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
region = util::get_texture_region(assets, mesh.texture, "blocks:notfound");
|
|
||||||
}
|
|
||||||
batch->texture(region.texture);
|
batch->texture(region.texture);
|
||||||
batch->setRegion(region.region);
|
batch->setRegion(region.region);
|
||||||
for (const auto& vertex : mesh.vertices) {
|
for (const auto& vertex : mesh.vertices) {
|
||||||
|
|
|
||||||
|
|
@ -302,6 +302,7 @@ void Entities::updatePhysics(float delta) {
|
||||||
hitbox.friction = glm::abs(hitbox.gravityScale <= 1e-7f)
|
hitbox.friction = glm::abs(hitbox.gravityScale <= 1e-7f)
|
||||||
? 8.0f
|
? 8.0f
|
||||||
: (!grounded ? 2.0f : 10.0f);
|
: (!grounded ? 2.0f : 10.0f);
|
||||||
|
hitbox.scale = transform.size;
|
||||||
transform.setPos(hitbox.position);
|
transform.setPos(hitbox.position);
|
||||||
if (hitbox.grounded && !grounded) {
|
if (hitbox.grounded && !grounded) {
|
||||||
scripting::on_entity_grounded(
|
scripting::on_entity_grounded(
|
||||||
|
|
@ -358,7 +359,9 @@ void Entities::renderDebug(
|
||||||
if (frustum && !frustum->isBoxVisible(pos - size, pos + size)) {
|
if (frustum && !frustum->isBoxVisible(pos - size, pos + size)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
batch.box(hitbox.position, hitbox.halfsize * 2.0f, glm::vec4(1.0f));
|
batch.box(
|
||||||
|
hitbox.position, hitbox.getHalfSize() * 2.0f, glm::vec4(1.0f)
|
||||||
|
);
|
||||||
|
|
||||||
for (auto& sensor : rigidbody.sensors) {
|
for (auto& sensor : rigidbody.sensors) {
|
||||||
if (sensor.type != SensorType::AABB) continue;
|
if (sensor.type != SensorType::AABB) continue;
|
||||||
|
|
@ -410,10 +413,14 @@ void Entities::render(
|
||||||
}
|
}
|
||||||
const auto& pos = transform.pos;
|
const auto& pos = transform.pos;
|
||||||
const auto& size = transform.size;
|
const auto& size = transform.size;
|
||||||
if (!frustum || frustum->isBoxVisible(pos - size, pos + size)) {
|
if (frustum && !frustum->isBoxVisible(pos - size, pos + size)) {
|
||||||
const auto* rigConfig = skeleton.config;
|
continue;
|
||||||
rigConfig->render(assets, batch, skeleton, transform.rot, pos);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const auto* rigConfig = skeleton.config;
|
||||||
|
rigConfig->render(
|
||||||
|
assets, batch, skeleton, transform.rot, pos, size
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -23,19 +23,19 @@ struct Transform {
|
||||||
|
|
||||||
void refresh();
|
void refresh();
|
||||||
|
|
||||||
inline void setRot(glm::mat3 m) {
|
inline void setRot(const glm::mat3& m) {
|
||||||
rot = m;
|
rot = m;
|
||||||
dirty = true;
|
dirty = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void setSize(glm::vec3 v) {
|
inline void setSize(const glm::vec3& v) {
|
||||||
if (glm::distance2(displaySize, v) >= EPSILON) {
|
if (glm::distance2(displaySize, v) >= EPSILON) {
|
||||||
dirty = true;
|
dirty = true;
|
||||||
}
|
}
|
||||||
size = v;
|
size = v;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void setPos(glm::vec3 v) {
|
inline void setPos(const glm::vec3& v) {
|
||||||
if (glm::distance2(displayPos, v) >= EPSILON) {
|
if (glm::distance2(displayPos, v) >= EPSILON) {
|
||||||
dirty = true;
|
dirty = true;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -122,15 +122,21 @@ size_t SkeletonConfig::update(
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
static glm::mat4 build_matrix(const glm::mat3& rot, const glm::vec3& pos) {
|
static glm::mat4 build_matrix(
|
||||||
|
const glm::mat3& rot, const glm::vec3& pos, const glm::vec3& scale
|
||||||
|
) {
|
||||||
glm::mat4 combined(1.0f);
|
glm::mat4 combined(1.0f);
|
||||||
combined = glm::translate(combined, pos);
|
combined = glm::translate(combined, pos);
|
||||||
combined = combined * glm::mat4(rot);
|
combined = combined * glm::mat4(rot);
|
||||||
|
combined = glm::scale(combined, scale);
|
||||||
return combined;
|
return combined;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SkeletonConfig::update(
|
void SkeletonConfig::update(
|
||||||
Skeleton& skeleton, const glm::mat3& rotation, const glm::vec3& position
|
Skeleton& skeleton,
|
||||||
|
const glm::mat3& rotation,
|
||||||
|
const glm::vec3& position,
|
||||||
|
const glm::vec3& scale
|
||||||
) const {
|
) const {
|
||||||
if (skeleton.interpolation.isEnabled()) {
|
if (skeleton.interpolation.isEnabled()) {
|
||||||
const auto& interpolation = skeleton.interpolation;
|
const auto& interpolation = skeleton.interpolation;
|
||||||
|
|
@ -138,10 +144,10 @@ void SkeletonConfig::update(
|
||||||
0,
|
0,
|
||||||
skeleton,
|
skeleton,
|
||||||
root.get(),
|
root.get(),
|
||||||
build_matrix(rotation, interpolation.getCurrent())
|
build_matrix(rotation, interpolation.getCurrent(), scale)
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
update(0, skeleton, root.get(), build_matrix(rotation, position));
|
update(0, skeleton, root.get(), build_matrix(rotation, position, scale));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -150,9 +156,10 @@ void SkeletonConfig::render(
|
||||||
ModelBatch& batch,
|
ModelBatch& batch,
|
||||||
Skeleton& skeleton,
|
Skeleton& skeleton,
|
||||||
const glm::mat3& rotation,
|
const glm::mat3& rotation,
|
||||||
const glm::vec3& position
|
const glm::vec3& position,
|
||||||
|
const glm::vec3& scale
|
||||||
) const {
|
) const {
|
||||||
update(skeleton, rotation, position);
|
update(skeleton, rotation, position, scale);
|
||||||
|
|
||||||
if (!skeleton.visible) {
|
if (!skeleton.visible) {
|
||||||
return;
|
return;
|
||||||
|
|
|
||||||
|
|
@ -121,7 +121,8 @@ namespace rigging {
|
||||||
void update(
|
void update(
|
||||||
Skeleton& skeleton,
|
Skeleton& skeleton,
|
||||||
const glm::mat3& rotation,
|
const glm::mat3& rotation,
|
||||||
const glm::vec3& position
|
const glm::vec3& position,
|
||||||
|
const glm::vec3& scale
|
||||||
) const;
|
) const;
|
||||||
|
|
||||||
void render(
|
void render(
|
||||||
|
|
@ -129,7 +130,8 @@ namespace rigging {
|
||||||
ModelBatch& batch,
|
ModelBatch& batch,
|
||||||
Skeleton& skeleton,
|
Skeleton& skeleton,
|
||||||
const glm::mat3& rotation,
|
const glm::mat3& rotation,
|
||||||
const glm::vec3& position
|
const glm::vec3& position,
|
||||||
|
const glm::vec3& scale
|
||||||
) const;
|
) const;
|
||||||
|
|
||||||
Skeleton instance() const {
|
Skeleton instance() const {
|
||||||
|
|
|
||||||
|
|
@ -52,6 +52,7 @@ struct Hitbox {
|
||||||
glm::vec3 position;
|
glm::vec3 position;
|
||||||
glm::vec3 halfsize;
|
glm::vec3 halfsize;
|
||||||
glm::vec3 velocity;
|
glm::vec3 velocity;
|
||||||
|
glm::vec3 scale {1.0f, 1.0f, 1.0f};
|
||||||
float linearDamping = 0.5;
|
float linearDamping = 0.5;
|
||||||
float friction = 1.0f;
|
float friction = 1.0f;
|
||||||
float verticalDamping = 1.0f;
|
float verticalDamping = 1.0f;
|
||||||
|
|
@ -64,4 +65,8 @@ struct Hitbox {
|
||||||
AABB getAABB() const {
|
AABB getAABB() const {
|
||||||
return AABB(position-halfsize, position+halfsize);
|
return AABB(position-halfsize, position+halfsize);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
glm::vec3 getHalfSize() const {
|
||||||
|
return halfsize * scale;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -11,11 +11,10 @@
|
||||||
#define GLM_ENABLE_EXPERIMENTAL
|
#define GLM_ENABLE_EXPERIMENTAL
|
||||||
#include <glm/gtx/norm.hpp>
|
#include <glm/gtx/norm.hpp>
|
||||||
|
|
||||||
const float E = 0.03f;
|
inline const float E = 0.03f;
|
||||||
const float MAX_FIX = 0.1f;
|
inline const float MAX_FIX = 0.1f;
|
||||||
|
|
||||||
PhysicsSolver::PhysicsSolver(glm::vec3 gravity) : gravity(gravity) {
|
PhysicsSolver::PhysicsSolver(glm::vec3 gravity) : gravity(gravity) {}
|
||||||
}
|
|
||||||
|
|
||||||
void PhysicsSolver::step(
|
void PhysicsSolver::step(
|
||||||
const GlobalChunks& chunks,
|
const GlobalChunks& chunks,
|
||||||
|
|
@ -28,7 +27,7 @@ void PhysicsSolver::step(
|
||||||
float linearDamping = hitbox.linearDamping * hitbox.friction;
|
float linearDamping = hitbox.linearDamping * hitbox.friction;
|
||||||
float s = 2.0f/BLOCK_AABB_GRID;
|
float s = 2.0f/BLOCK_AABB_GRID;
|
||||||
|
|
||||||
const glm::vec3& half = hitbox.halfsize;
|
auto half = hitbox.getHalfSize();
|
||||||
glm::vec3& pos = hitbox.position;
|
glm::vec3& pos = hitbox.position;
|
||||||
glm::vec3& vel = hitbox.velocity;
|
glm::vec3& vel = hitbox.velocity;
|
||||||
float gravityScale = hitbox.gravityScale;
|
float gravityScale = hitbox.gravityScale;
|
||||||
|
|
@ -91,8 +90,8 @@ void PhysicsSolver::step(
|
||||||
}
|
}
|
||||||
|
|
||||||
AABB aabb;
|
AABB aabb;
|
||||||
aabb.a = hitbox.position - hitbox.halfsize;
|
aabb.a = hitbox.position - hitbox.getHalfSize();
|
||||||
aabb.b = hitbox.position + hitbox.halfsize;
|
aabb.b = hitbox.position + hitbox.getHalfSize();
|
||||||
for (size_t i = 0; i < sensors.size(); i++) {
|
for (size_t i = 0; i < sensors.size(); i++) {
|
||||||
auto& sensor = *sensors[i];
|
auto& sensor = *sensors[i];
|
||||||
if (sensor.entity == entity) {
|
if (sensor.entity == entity) {
|
||||||
|
|
@ -267,7 +266,7 @@ void PhysicsSolver::colisionCalc(
|
||||||
|
|
||||||
bool PhysicsSolver::isBlockInside(int x, int y, int z, Hitbox* hitbox) {
|
bool PhysicsSolver::isBlockInside(int x, int y, int z, Hitbox* hitbox) {
|
||||||
const glm::vec3& pos = hitbox->position;
|
const glm::vec3& pos = hitbox->position;
|
||||||
const glm::vec3& half = hitbox->halfsize;
|
auto half = hitbox->getHalfSize();
|
||||||
return x >= floor(pos.x-half.x) && x <= floor(pos.x+half.x) &&
|
return x >= floor(pos.x-half.x) && x <= floor(pos.x+half.x) &&
|
||||||
z >= floor(pos.z-half.z) && z <= floor(pos.z+half.z) &&
|
z >= floor(pos.z-half.z) && z <= floor(pos.z+half.z) &&
|
||||||
y >= floor(pos.y-half.y) && y <= floor(pos.y+half.y);
|
y >= floor(pos.y-half.y) && y <= floor(pos.y+half.y);
|
||||||
|
|
@ -276,7 +275,7 @@ bool PhysicsSolver::isBlockInside(int x, int y, int z, Hitbox* hitbox) {
|
||||||
bool PhysicsSolver::isBlockInside(int x, int y, int z, Block* def, blockstate state, Hitbox* hitbox) {
|
bool PhysicsSolver::isBlockInside(int x, int y, int z, Block* def, blockstate state, Hitbox* hitbox) {
|
||||||
const float e = 0.001f; // inaccuracy
|
const float e = 0.001f; // inaccuracy
|
||||||
const glm::vec3& pos = hitbox->position;
|
const glm::vec3& pos = hitbox->position;
|
||||||
const glm::vec3& half = hitbox->halfsize;
|
auto half = hitbox->getHalfSize();
|
||||||
const auto& boxes = def->rotatable
|
const auto& boxes = def->rotatable
|
||||||
? def->rt.hitboxes[state.rotation]
|
? def->rt.hitboxes[state.rotation]
|
||||||
: def->hitboxes;
|
: def->hitboxes;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue