targetting 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
blackMasoon
Posts: 149
Joined: Wed Sep 09, 2009 4:57 pm
Contact:

targetting problem

Post by blackMasoon »

Hello everyone. I'm using irrlicght & Proton SDK for mobile 3D apps and I'm just curious about one problem... That method selects only one scene node out of my arraylist of them:

Code: Select all

 
void DrawPigLifesStat()
{
        
        for(int i = 0; i < number_of_pigs; ++i)
        {
                pigPosXY[i].X = GetIrrlichtManager()->GetScene()->getSceneCollisionManager()->getScreenCoordinatesFrom3DPosition(pig[i]->getPosition(),GetIrrlichtManager()->GetScene()->getActiveCamera()).X;
                pigPosXY[i].Y = GetIrrlichtManager()->GetScene()->getSceneCollisionManager()->getScreenCoordinatesFrom3DPosition(pig[i]->getPosition(),GetIrrlichtManager()->GetScene()->getActiveCamera()).Y;
 
                float scX = GetScreenSizeX()/2.0f;
                float scY = GetScreenSizeY()/2.0f;
 
                if(pigPosXY[i].X >= scX-10 && pigPosXY[i].X <= scX+10 && pigPosXY[i].Y >= scY-10 && pigPosXY[i].Y <= scY+10)
                {
                        
                        GetMessageManager()->SetEntityVariable(pigHeart, 1, "pos2d", CL_Vec2f(pigPosXY[i].X ,pigPosXY[i].Y));
                                                        
                }else
                        GetMessageManager()->SetEntityVariable(pigHeart, 1, "pos2d", CL_Vec2f(0,0));
                                
        }
}
 
 
That targetting condition works fine cause i have array list with 3 scene nodes and for one of them it always works... but why doesn't it work for the rest?
CuteAlien
Admin
Posts: 9929
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: targetting problem

Post by CuteAlien »

Ok , first you don't say _what_ goes wrong. Do you get wrong values? Did you debug it? Print it? Anything?
Then you don't give us sufficient code to reproduce anything. I mean you don't even show variable declarations or anything.
How the hell are we supposed to guess what is wrong? Maybe number_of_pigs is just 1? Or maybe your variable declaration is bad. Or maybe SetEntityVariable is totally broken... or.... we don't see your screen so we have no way of knowing.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
blackMasoon
Posts: 149
Joined: Wed Sep 09, 2009 4:57 pm
Contact:

Re: targetting problem

Post by blackMasoon »

ok so here are the declarations and initialization of those variables:

Code: Select all

 
core::array<IAnimatedMeshSceneNode*> pig;
core::array<vector3df> pigPos;
core::array<vector2di>pigPosXY;
int number_of_pigs = 3;
 
IAnimatedMesh* mesh = pScene->getMesh( (GetBaseAppPath() + "game/pig.x").c_str());
        core::vector2di vec_2d = vector2di(0,0);
 
 
        for(int i = 0; i < number_of_pigs; ++i)
        {
                pig.push_back(pScene->addAnimatedMeshSceneNode(mesh,0,666 ));
                vector3df vec = vector3df((rand() % 200) -100, -1.5, (rand() % 200) -100);
                pigPos.push_back(vec);
                pigPosXY.push_back(vec_2d);
        }
 
       for(int i = 0; i < number_of_pigs; ++i)
        {
                pig[i]->setPosition(pigPos[i]);
        }
 
 
And what I want is to display a 2d image in the 2d position od scenenode. It seems like the getScreenCoordinatesFrom3DPosition() method works only for the first scene node in my arraylist. It doesn't get the 2d coords of the rest nodes. why?
CuteAlien
Admin
Posts: 9929
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: targetting problem

Post by CuteAlien »

What do you get? You already save it into variables - just print the result out!
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
blackMasoon
Posts: 149
Joined: Wed Sep 09, 2009 4:57 pm
Contact:

Re: targetting problem

Post by blackMasoon »

As I said it only gets the coords of one node... Here's the log:

Code: Select all

 
pig0 pos: (524, 375)
pig1 pos: (-10000, -10000)
pig2 pos: (-10000, -10000)
pig0 pos: (523, 375)
pig1 pos: (-10000, -10000)
pig2 pos: (-10000, -10000)
pig0 pos: (523, 375)
pig1 pos: (-10000, -10000)
pig2 pos: (-10000, -10000)
pig0 pos: (523, 375)
pig1 pos: (-10000, -10000)
pig2 pos: (-10000, -10000)
 
 
There are three nodes... It counts the coords only for one even if other are in the viewfrustum of camera....
CuteAlien
Admin
Posts: 9929
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: targetting problem

Post by CuteAlien »

Seems this function returns indeed -10000 sometimes (no constants ... *sigh*). I see the check, but unfortunately I'm not sure right now what it means. Probably that the position is behind the camera as the documentation mentions something like that (although it says it would return -1000 then - which it does in other cases, but those are no such checks so I guess documentation is wrong here).

But it seems you can reduce this to a single test-case. What we need would be the exact camera-values (position, target, rotation, projectionMatrix, viewMatrix) your rendertargetsize (driver->getCurrentRenderTargetSize()) and one of the positions which you try to convert which go wrong.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Post Reply