Reorder drawings – Change drawing order

About Monkey 2 Forums Monkey 2 Programming Help Reorder drawings – Change drawing order

This topic contains 4 replies, has 2 voices, and was last updated by  cocon 1 week, 2 days ago.

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #16242

    cocon
    Participant

    Have you found any code or used one to reorder entities based on distance?

    #16243

    AdamStrange
    Participant

    You would need to edit the mojo3d source for this.

    The file you need to look at is:

    mojo3d/render/renderer.monkey2

    and the function RenderRenderOps

     

    My advice would be to leave well alone, as Mark will certainly change things here at some stage. But if you are happy with a preserved version then tinker away 🙂

    #16244

    cocon
    Participant

    Thanks, I will have a peek. By the moment I use only mojo for drawing rects and stuff, up until I have a solid foundation for a codebase which later I can adapt faster to an engine.

    #16245

    AdamStrange
    Participant

    OK. Think I got my wires crossed. I thought you were talking about 3d stuff.

    In Mojo, everything is generally optimised on a first come first draw basis. so the only thing you need to do is run some form of depth system.

    let’s assume you have a series of entities (of your creation, boxes, circles, sprites, etc). And each entity has an x,y location

    You (the viewer) also need to have an x,y location – so you can depth sort

    First you need a list or array of the wanted entities to be drawn

    for each entity find the length from the viewer:

    xx = vx-ex[]

    yy = vy-ey[]

    length =Sqrt(xx*xx + yy*yy)

    then you just do a quick sort of the lengths – the bigger the length the further away from the viewer and the lower in the sortlist

    Lastly you draw the entities in the sortlist starting with the item furthest away

    #16246

    cocon
    Participant

    Although I was thinking about crazy algorithms for a moment, up until I looked that it’s a matter only of sorting based on a specific criteria, which is cool, it makes things very simple.

Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.