Giter VIP home page Giter VIP logo

Comments (13)

Vogtinator avatar Vogtinator commented on July 26, 2024

It looks like you're using incorrect vertex winding. Backface culling works by only drawing faces with vertices in clockwise order, so e.g. left and right faces need to be drawn in opposite order.

from crafti.

Bluebotlabz avatar Bluebotlabz commented on July 26, 2024

Oh, I had a feeling it might be something like that, so what order should I draw it in? Since clockwise doesn't exactly apply to 3D space...

from crafti.

Bluebotlabz avatar Bluebotlabz commented on July 26, 2024

oh wait, I think I understand what you meant

from crafti.

Vogtinator avatar Vogtinator commented on July 26, 2024

When you look at the front of a face, the vertices have to be in clockwise order. That means that the backside automatically has them in CCW order. This is how it's determined what the front side of a face is.

from crafti.

Bluebotlabz avatar Bluebotlabz commented on July 26, 2024

Great, I just re-aranged my drawing order and it fixed the problem, thanks!

Also, just wondering, would it be possible to create particles from within a block renderer?

from crafti.

Vogtinator avatar Vogtinator commented on July 26, 2024

The block renderer methods are only called for dirty chunks, i.e. after a block was changed. That means the particles will only spawn after something explicitly triggered such a change, e.g. placing a block in the chunk. If that's fine for your use case, you can call addParticle in any render function.

If not, you could render them as animation, like the torch flame. That also has the benefit that it can immediately react to changes to the source block, unlike particles which are immutable from the outside.

from crafti.

Bluebotlabz avatar Bluebotlabz commented on July 26, 2024

Does the tick function not happen every tick?

Also, what is the difference between local_x and just x in blockrenderer functions?

from crafti.

Vogtinator avatar Vogtinator commented on July 26, 2024

Yes, every 10 frames. If you want to spawn particles in there, they'd need to have a lifetime of at most 10 frames, otherwise they'd start to accumulate. It's also possible to disable ticks ("World: static"), in which case the particles would be missing entirely.

from crafti.

Bluebotlabz avatar Bluebotlabz commented on July 26, 2024

So I'm guessing that animations are like ticks, except with configurable frame-steppiness (frames_per_step)

from crafti.

Bluebotlabz avatar Bluebotlabz commented on July 26, 2024

Lastly, just wondering

  • What is the difference between setBlock and changeBlock?
  • What is the difference between local_x and then just x in renderer functions?

Also, I'm trying to give TNT particles, but it doesn't seem to be working:

void TNTRenderer::explode(const int local_x, const int local_y, const int local_z, Chunk &c)
{
    c.setGlobalBlockRelative(local_x, local_y, local_z, BLOCK_AIR);

    Particle p;
    p.size = 14;
    p.tae = terrain_atlas[1][1].current;

    // Use the center quarter of the texture
    const int tex_width = p.tae.right - p.tae.left,
              tex_height = p.tae.bottom - p.tae.top;
    p.tae.left += tex_width / 4;
    p.tae.right -= tex_width / 4;
    p.tae.top += tex_height / 4;
    p.tae.bottom -= tex_height / 4;

    // Random value between 0 and max (not including max)
    const auto randMax = [](GLFix max) { return max * (rand() & 0xFF) / 0xFF; };

    // Get the center of the block contents (chunk relative coordinates)
    const auto aabb = global_block_renderer.getAABB(getBLOCK(c.getGlobalBlockRelative(local_x, local_y, local_z)), local_x * BLOCK_SIZE, local_y * BLOCK_SIZE, local_z * BLOCK_SIZE);
    auto center = VECTOR3{(aabb.low_x + aabb.high_x) / 2, (aabb.low_y + aabb.high_y) / 2, (aabb.low_z + aabb.high_z) / 2};
    center.x -= local_x;
    center.y -= local_y;
    center.z -= local_z;

    // Spawn four particles at the center with random velocity and offset
    for(int i = 0; i < 4; ++i)
    {
        p.vel = {randMax(10) - 5, randMax(5), randMax(10) - 5};
        p.pos = center;
        p.pos.x += randMax(100) - 50;
        p.pos.y += randMax(100) - 50;
        p.pos.z += randMax(100) - 50;
        c.addParticle(p);
    }

Thanks in advance

from crafti.

Vogtinator avatar Vogtinator commented on July 26, 2024

Also, what is the difference between local_x and just x in blockrenderer functions?

renderSpecialBlock and getAABB work with coordinates (GLFix), while the other methods work with block indexes within a chunk (int).

So I'm guessing that animations are like ticks, except with configurable frame-steppiness (frames_per_step)

The animation callback is run every frame, it's responsible for drawing whatever it needs to whenever it wants to.

What is the difference between setBlock and changeBlock?

setBlock is a bit lower level than changeBlock. The latter triggers the addedBlock and removedBlock notifications, which are important for some types of blocks.

from crafti.

Vogtinator avatar Vogtinator commented on July 26, 2024

I think

    center.x -= local_x;
    center.y -= local_y;
    center.z -= local_z;

is wrong. At that point, center is already in chunk-relative coordinates.

from crafti.

Bluebotlabz avatar Bluebotlabz commented on July 26, 2024

it seems to work now, (positioning is a little off, but that's something I can fix later)

thanks!

from crafti.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.