Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Estabish a rendering order within a same entity  (Read 1674 times)

0 Members and 1 Guest are viewing this topic.

man'O'war

  • Newbie
  • *
  • Posts: 46
  • What needs to be done is done by those capable.
    • View Profile
Estabish a rendering order within a same entity
« on: March 02, 2017, 04:07:14 pm »
Hello,

I've recently started using the Quad Tree in order to render the objects of the scene, which makes it a bit dependent on the physical location of the objects, isn't it ?
Closer objects are drawn in front and  farther object are drawn into the back side.

Beside that, i've added a Layer attribute to the objects to create a discrepancy between them. Each one on its own level. ( layer ).
This is perform by creating as many quad_tree as the total number of existent layers.
Now before exposing the problem that i am facing: here is the render call sequence 

void Scene::draw(){
    //  decl: std::vector< quad_tree* > quad_heads;

    for( int i=0; i<static_cast<int>(GoLayer::LayerCount); i++){
        gdf::kernel::GameInfo::game_info->sf::RenderWindow::draw( *(quad_heads[i]) );
    }
}
 

Every QuadTree node's content holds a pointer to the GameObject to draw.
The QuadTree is generated when the Scene is updating all GameObject. ( Hierarchical Tree structure )
void Scene::update(sf::Time dt){
    // .......
    if( !root_.expired() ){

        for( int i=0; i<static_cast<int>(GoLayer::LayerCount); i++){
            // PS1
            quad_heads.resize( static_cast<int>(GoLayer::LayerCount) );
            quad_heads[i] = new quad_tree( AABB(sf::Vector2f(500,500), sf::Vector2f(500,500) ) );
        }

        root_.get()->update(dt);
    }
 

PS1: The reason here. Is that i am deleting and recreating the quad tree structure every iteration ( I don't know if it is the right way to do it )

When update method is invoked on the GameObject (root_). It will recursively build the QuadTree based on the Layer value of the GameObject accordingly.

void GameObject::update( sf::Time dt ){
    // .....
    scene()->quad_heads[ static_cast<int>(layer_) ]->insert( QuadTreeNode<GameObject>( position, this  /*pointer_to_go*/) );
}

 

What if i want to create a specific rendering logic,
For example, within the same entity ( Entity here refers to a sub-hierarchy of game objects ).
I want to make a specific rendering order totally independent from the positioning of the sub-gameobjects.

Here is a schematic

This diagram represents the physical location of the GameObject within the scene.



This diagram is the Hierarchical Tree for the same structure ( Used for updates )



As for this one, is the QuadTree generated.

In @Diag 1, the entity here covers all the objects within the blue dashed square. having as a parent object n°1.

Now the situation is : If the logic says: object n°3 must be on top of object n°1. and somehow, the texture/sprite of the object n°3 is big enough to interlace with n°1's texture. In this case using the QuadTree rendering policy, the object n°3 will be behind the object n°1 ( due to positioning criteria ).  Same for n°1 and n°5 ( with opposite context ).

My point is, i want to make beside the QuadTree rendering policy, a relative rendering order within the same Entity.

Hope the idea was clear.
Cordially.
« Last Edit: March 02, 2017, 04:13:34 pm by man'O'war »

Turbine

  • Full Member
  • ***
  • Posts: 100
    • View Profile
Re: Estabish a rendering order within a same entity
« Reply #1 on: March 04, 2017, 03:13:16 pm »
Just make your own rendering queue, of which the preceding drawing actions are always underneath subsequent drawing.

For example, have your own rendering object with depth and perhaps the object. Make a list for this object. You could then overload the comparison of this rendering object in order to sort it by the depth given. Loop through this ordered list.
« Last Edit: March 04, 2017, 03:14:49 pm by Turbine »

 

anything