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