mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-11-21 01:49:44 +00:00
use double precision for particles, emitters and 3D texts
Positions of particles, of static emitters and of text notes are worldvec3. gfx.particles, gfx.text3d, gfx.blockwraps, pathfinding and generation.create_fragment read positions from Lua as doubles: a float can not hold an odd block coordinate above 16.7M, the object went to a neighbour block.
This commit is contained in:
parent
cb39ed464a
commit
d012f0530b
14 changed files with 44 additions and 43 deletions
|
|
@ -83,7 +83,7 @@ void Decorator::addParticles(const Block& def, const glm::ivec3& pos) {
|
|||
);
|
||||
blockEmitters[pos] = renderer.particles->add(std::make_unique<Emitter>(
|
||||
level,
|
||||
glm::vec3{pos.x + 0.5, pos.y + 0.5, pos.z + 0.5},
|
||||
worldvec3 {pos.x + 0.5, pos.y + 0.5, pos.z + 0.5},
|
||||
*def.particles,
|
||||
treg.texture,
|
||||
treg.region,
|
||||
|
|
@ -205,7 +205,7 @@ void Decorator::updateRandom(
|
|||
);
|
||||
renderer.particles->add(std::make_unique<Emitter>(
|
||||
level,
|
||||
glm::vec3 {
|
||||
worldvec3 {
|
||||
pos.x + random.randFloat(),
|
||||
pos.y + 1.1,
|
||||
pos.z + random.randFloat()},
|
||||
|
|
@ -308,11 +308,11 @@ void Decorator::updateTextNotes() {
|
|||
renderer.texts->remove(textsIter->second);
|
||||
textsIter = playerTexts.erase(textsIter);
|
||||
} else {
|
||||
glm::vec3 position = player->getPosition();
|
||||
worldvec3 position = player->getPosition();
|
||||
if (auto entity = level.entities->get(player->getEntity())) {
|
||||
position = entity->getInterpolatedPosition();
|
||||
}
|
||||
note->setPosition(position + glm::vec3(0, 1, 0));
|
||||
note->setPosition(position + worldvec3(0, 1, 0));
|
||||
if (note->getText() != player->getName()) {
|
||||
note->setText(player->getName());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@
|
|||
|
||||
Emitter::Emitter(
|
||||
const Level& level,
|
||||
std::variant<glm::vec3, entityid_t> origin,
|
||||
EmitterOrigin origin,
|
||||
ParticlesPreset preset,
|
||||
const Texture* texture,
|
||||
const UVRegion& region,
|
||||
|
|
@ -50,15 +50,15 @@ static inline glm::vec3 generate_coord(ParticleSpawnShape shape) {
|
|||
|
||||
void Emitter::update(
|
||||
float delta,
|
||||
const glm::vec3& cameraPosition,
|
||||
const worldvec3& cameraPosition,
|
||||
std::vector<Particle>& particles
|
||||
) {
|
||||
const float spawnInterval = preset.spawnInterval;
|
||||
if (count == 0 || (count == -1 && spawnInterval < FLT_EPSILON)) {
|
||||
return;
|
||||
}
|
||||
glm::vec3 position {};
|
||||
if (auto staticPos = std::get_if<glm::vec3>(&origin)) {
|
||||
worldvec3 position {};
|
||||
if (auto staticPos = std::get_if<worldvec3>(&origin)) {
|
||||
position = *staticPos;
|
||||
} else if (auto entityId = std::get_if<entityid_t>(&origin)) {
|
||||
if (auto entity = level.entities->get(*entityId)) {
|
||||
|
|
@ -105,7 +105,7 @@ void Emitter::update(
|
|||
spawnOffset *= preset.spawnSpread;
|
||||
spawnOffset += preset.spawnOffset;
|
||||
|
||||
particle.position = position + spawnOffset;
|
||||
particle.position = position + worldvec3(spawnOffset);
|
||||
particle.lifetime *= 1.0f - preset.lifetimeSpread * random.randFloat();
|
||||
particle.velocity += glm::ballRand(1.0f) * preset.explosion;
|
||||
if (preset.randomSubUV < 1.0f) {
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ struct Particle {
|
|||
/// @brief Some random integer for visuals configuration.
|
||||
int random;
|
||||
/// @brief Global position
|
||||
glm::vec3 position;
|
||||
worldvec3 position;
|
||||
/// @brief Linear velocity
|
||||
glm::vec3 velocity;
|
||||
/// @brief Remaining life time
|
||||
|
|
@ -35,7 +35,7 @@ struct Particle {
|
|||
|
||||
class Texture;
|
||||
|
||||
using EmitterOrigin = std::variant<glm::vec3, entityid_t>;
|
||||
using EmitterOrigin = std::variant<worldvec3, entityid_t>;
|
||||
|
||||
class Emitter {
|
||||
const Level& level;
|
||||
|
|
@ -61,7 +61,7 @@ public:
|
|||
|
||||
Emitter(
|
||||
const Level& level,
|
||||
std::variant<glm::vec3, entityid_t> origin,
|
||||
EmitterOrigin origin,
|
||||
ParticlesPreset preset,
|
||||
const Texture* texture,
|
||||
const UVRegion& region,
|
||||
|
|
@ -79,7 +79,7 @@ public:
|
|||
/// @param particles destination particles vector
|
||||
void update(
|
||||
float delta,
|
||||
const glm::vec3& cameraPosition,
|
||||
const worldvec3& cameraPosition,
|
||||
std::vector<Particle>& particles
|
||||
);
|
||||
|
||||
|
|
|
|||
|
|
@ -38,10 +38,10 @@ static inline void update_particle(
|
|||
auto& angle = particle.angle;
|
||||
|
||||
vel += delta * preset.acceleration;
|
||||
if (preset.collision && chunks.isObstacleAt(pos + vel * delta)) {
|
||||
if (preset.collision && chunks.isObstacleAt(pos + worldvec3(vel * delta))) {
|
||||
vel *= 0.0f;
|
||||
}
|
||||
pos += vel * delta;
|
||||
pos += worldvec3(vel * delta);
|
||||
angle += particle.angularVelocity * delta;
|
||||
particle.lifetime -= delta;
|
||||
}
|
||||
|
|
@ -114,7 +114,8 @@ static inline glm::vec4 calc_lights(
|
|||
light = glm::max(
|
||||
light,
|
||||
MainBatch::sampleLight(
|
||||
particle.position - size * glm::vec3(x, y, z),
|
||||
particle.position -
|
||||
worldvec3(size * glm::vec3(x, y, z)),
|
||||
chunks,
|
||||
backlight
|
||||
)
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
#include "TextNote.hpp"
|
||||
|
||||
TextNote::TextNote(std::wstring text, NotePreset preset, glm::vec3 position)
|
||||
TextNote::TextNote(std::wstring text, NotePreset preset, worldvec3 position)
|
||||
: text(std::move(text)),
|
||||
preset(std::move(preset)),
|
||||
position(std::move(position)) {
|
||||
|
|
@ -30,11 +30,11 @@ void TextNote::updatePreset(const dv::value& data) {
|
|||
preset.deserialize(data);
|
||||
}
|
||||
|
||||
void TextNote::setPosition(const glm::vec3& position) {
|
||||
void TextNote::setPosition(const worldvec3& position) {
|
||||
this->position = position;
|
||||
}
|
||||
|
||||
const glm::vec3& TextNote::getPosition() const {
|
||||
const worldvec3& TextNote::getPosition() const {
|
||||
return position;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -7,13 +7,13 @@
|
|||
class TextNote {
|
||||
std::wstring text;
|
||||
NotePreset preset;
|
||||
glm::vec3 position;
|
||||
worldvec3 position;
|
||||
entityid_t entity = ENTITY_NONE;
|
||||
|
||||
glm::vec3 xAxis {1, 0, 0};
|
||||
glm::vec3 yAxis {0, 1, 0};
|
||||
public:
|
||||
TextNote(std::wstring text, NotePreset preset, glm::vec3 position);
|
||||
TextNote(std::wstring text, NotePreset preset, worldvec3 position);
|
||||
|
||||
void setText(std::wstring_view text);
|
||||
void setEntity(entityid_t eid);
|
||||
|
|
@ -25,8 +25,8 @@ public:
|
|||
|
||||
void updatePreset(const dv::value& data);
|
||||
|
||||
void setPosition(const glm::vec3& position);
|
||||
const glm::vec3& getPosition() const;
|
||||
void setPosition(const worldvec3& position);
|
||||
const worldvec3& getPosition() const;
|
||||
|
||||
const glm::vec3& getAxisX() const;
|
||||
const glm::vec3& getAxisY() const;
|
||||
|
|
|
|||
|
|
@ -35,16 +35,16 @@ void TextsRenderer::renderNote(
|
|||
) {
|
||||
const auto& text = note.getText();
|
||||
const auto& preset = note.getPreset();
|
||||
auto pos = note.getPosition();
|
||||
auto worldPos = note.getPosition();
|
||||
|
||||
entityid_t eid = note.getEntity();
|
||||
if (eid != ENTITY_NONE) {
|
||||
if (auto entity = level.entities->get(eid)) {
|
||||
pos += entity->getTransform().displayPos;
|
||||
worldPos += entity->getTransform().displayPos;
|
||||
}
|
||||
}
|
||||
|
||||
pos = util::to_local(pos, camera.getOrigin());
|
||||
glm::vec3 pos = util::to_local(worldPos, camera.getOrigin());
|
||||
const glm::vec3 cameraPos = camera.getLocalPosition();
|
||||
|
||||
if (util::distance2(pos, cameraPos) >
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue