Brush Entity Position Problem

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
gbrownie
Posts: 6
Joined: Thu Mar 12, 2015 10:15 pm

Brush Entity Position Problem

Post by gbrownie »

Hey everyone this one has been stumping me the past few days and I just cant seem to figure it out.

So I followed the example at: http://sourceforge.net/p/irrlicht/patches/211/

scroll down some and you'll see the zip brush ent v2 thats what I'm following.

So I downloaded that and ran it and the door opens perfectly fine. I then tried to make a function out of it and use it in my own project.

Code: Select all

 
void CQuake3EventHandler::doorTest()
{
    if (!Mesh )
    {
        printf("*****IQ3LevelMesh INVALID****\n");
        return;
    }
        ISceneManager *smgr = Game->Device->getSceneManager();
    tQ3EntityList &entityList= Mesh->getEntityList();
    IEntity search;
    
    IMesh *doormesh = 0;
    search.name = "func_door";
    
 
    // find all entities in the multi-list
    s32 index = entityList.binary_search(search);
 
    if (index >= 0) // Our level has only one door.
    {
        printf("BRUSH FOUND\n");
        doormesh = Mesh->getBrushEntityMesh(entityList[index]);
    }
    
    if(!doormesh)
    {
        printf("NO BRUSHES FOUND RET\n");
        return;
    }
    
    doorNode = smgr->addMeshSceneNode(doormesh);
    
       //Always returns X: 0.00 Y: 0.00 Z: 0.00
    printf("DOOR: X:%f Y: %f Z:%f\n", doorNode->getPosition().X, doorNode->getPosition().Y, doorNode->getPosition().Z);
 
}
 
The strangest part is that the door does show up, correctly positioned, and textured... take a look:
Image

Also, if I stop calling 'doorTest()' the doors disappear entirely and I've also tried to use other maps with the same result.

I made my own map with a door that is much larger than the example one. I then tested both the example map and the one I made in the example application. Both doors work perfectly.

But in my game all I can ever get is all 0's for the doors position? Am I doing something wrong?

EDIT: I'm loading doorTest() at the end of the LoadMap function and it correctly tells me if a map has brush entities or not. The only problem I seem to have is the position is all 0's.
Last edited by gbrownie on Sat Mar 14, 2015 1:50 am, edited 3 times in total.
mongoose7
Posts: 1227
Joined: Wed Apr 06, 2011 12:13 pm

Re: Brush Entity Position Problem

Post by mongoose7 »

(0, 0, 0) is the position of the *node*, not the mesh. If you want to find out where the mesh is, you might look at the bounding box.
gbrownie
Posts: 6
Joined: Thu Mar 12, 2015 10:15 pm

Re: Brush Entity Position Problem

Post by gbrownie »

But the example does it like this

Code: Select all

 
            ISceneNode *door = smgr->addMeshSceneNode(doormesh); //this would be the end of my function
             //...
            //This is how the example gets the position, the same why I'm trying to.
            const vector3df doorpos = door->getPosition(); 
           
            //This is code for the triggers (which of course rely on the above line)
            const f32 dist = camera->getPosition().getDistanceFrom(doorpos);
 
And if I should use bounding boxes then how could I get a vector3d position coordinate from it?
thanhle
Posts: 325
Joined: Wed Jun 12, 2013 8:09 am

Re: Brush Entity Position Problem

Post by thanhle »

Hi,
getPosition return the relative position to the parent node.

To get the abs position you would getAbsTransform()->getPosition() or getAbsolutePosition() for example.

Regards
thanh
gbrownie
Posts: 6
Joined: Thu Mar 12, 2015 10:15 pm

Re: Brush Entity Position Problem

Post by gbrownie »

I tried that and nothing changed.

Code: Select all

 
printf("DOOR: X:%f Y: %f Z:%f\n", doorNode->getAbsolutePosition().X, doorNode->getAbsolutePosition().Y, doorNode->getAbsolutePosition().Z);
 
Does the same thing as the pic in the op.
thanhle
Posts: 325
Joined: Wed Jun 12, 2013 8:09 am

Re: Brush Entity Position Problem

Post by thanhle »

Ok I have read the original thread to understand what's going on.

Maybe there is bug with that code or try to use the information of a transformed bounding box centre as Mongoose suggested.

regards
thanh
gbrownie
Posts: 6
Joined: Thu Mar 12, 2015 10:15 pm

Re: Brush Entity Position Problem

Post by gbrownie »

I have tried writing down the coords of where the door is supposed to be then using setPosition() to pass it manually and everything works perfect. I set the position right after I added the node to the SMGR. (but of course, I need a dynamic way for it to load it from the map and not rely on supplied data)

And to go back to 1. For now, I just want to get the position of the door brush entity. I will then try to then get it to open and close.

The problem I'm facing is that the trigger checking function will only trip if I go to where 0, 0, 0, since this is the position it thinks the door is at.

This would be code to get the distance from the player.

Code: Select all

 
vector3df doorPos = doorNode->getPosition();
f32 dist = Player[0].getDistanceFrom(doorPos);
 
everything works fine but you have to be at 0, 0, 0 to trigger the door which makes no sense.


UPDATE: I got it working by playing around with the bounding box stuff as suggested:

Code: Select all

 
//accurately gives distance
f32 testDist = doorNode->getBoundingBox().getCenter().getDistanceFrom(camera->getPosition());
 
//accurate position
vector3df testPos = doorNode->getBoundingBox().getCenter();
 
Thanks everyone!
hendu
Posts: 2600
Joined: Sat Dec 18, 2010 12:53 pm

Re: [SOLVED] Brush Entity Position Problem

Post by hendu »

If you need the entity's position, you can use the getGroup function as is done later in the example for the start position. The example is indeed wrongly using 0,0,0 for the door pos.
gbrownie
Posts: 6
Joined: Thu Mar 12, 2015 10:15 pm

Re: [SOLVED] Brush Entity Position Problem

Post by gbrownie »

hendu wrote:If you need the entity's position, you can use the getGroup function as is done later in the example for the start position.
I tried that but I still get all 0's.

And I guess I got excited for nothing because although the values weren't 0 they still were just garbage values. I checked the values against my player and they were way off.

In hendu's example map 'irrent.pk3' the door should be around
X:81, Y:98, Z: 0

But my I keep getting:
X0.5 Y:32 Z: 15

using this print statement:

Code: Select all

 
        //Note: I've tried using both the doormesh and the door node for this. Both have the same result.
    printf("DOOR POS: X: %f Y: %f Z: %f\n", doormesh->getBoundingBox().getCenter().X, 
                                            doormesh->getBoundingBox().getCenter().Y, 
                                            doormesh->getBoundingBox().getCenter().Z);
 
I'm so confused, I don't feel like this should be so difficult.
:(
thanhle
Posts: 325
Joined: Wed Jun 12, 2013 8:09 am

Re: Brush Entity Position Problem

Post by thanhle »

Hi,
I think you need the transformed bounding box not the bounding box.

Regards
thanh
hendu
Posts: 2600
Joined: Sat Dec 18, 2010 12:53 pm

Re: Brush Entity Position Problem

Post by hendu »

Oh, I see the door doesn't have the origin key set. In that case you need to use the transformed box.
gbrownie
Posts: 6
Joined: Thu Mar 12, 2015 10:15 pm

Re: Brush Entity Position Problem

Post by gbrownie »

hendu wrote:Oh, I see the door doesn't have the origin key set. In that case you need to use the transformed box.
That gives me the same garbage like values:

Code: Select all

 
        doorNode = smgr->addMeshSceneNode(doormesh);
    vector3df doorOrigPos = doorNode->getTransformedBoundingBox().getCenter();  
    printf("DOOR POS: X: %f Y: %f Z: %f\n", doorOrigPos.X, 
                                            doorOrigPos.Y, 
                                            doorOrigPos.Z);
 
But, After reading your comment hendu, I have decided to manually set the origin key, and then setting the position of the doors when I load them to their origin key. Then I should be able to use doorNode->setPosition/getPosition normally. I'll post back if I have troubles with this (I'm sure I will lol :wink: )
Post Reply