creating 3D arrow direction indicator

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
Default User
Posts: 8
Joined: Wed Sep 12, 2012 7:05 pm
Location: Saquarema, Brasil

creating 3D arrow direction indicator

Post by Default User »

Hello, I need help creating a 3D arrow direction indicator,
just like the ones we see in 3d modeller programs:
Image
Image
that colored 3 arrows which indicate the world orientation of XYZ vectors.

what i have done so far:

Code: Select all

 
    amesh = smgr->addArrowMesh("arrowx", video::SColor(255, 50, 50, 50),
            video::SColor(255, 255, 0, 0), 4, 3); //right now, only one arrow is enough
    snode = smgr->addMeshSceneNode(amesh);
    snode->setParent(camera);
    snode->setPosition(core::vector3df(0.f, 1.f, 0.f)); //put it above the camera, for testing purpose, so I know where to look
 
I'm trying to keep the object as a child of the camera, so every movement of the camera will keep it in the front of the screen. But the object is always far, right now in this sample code, the object is always far, no matter the how much I set the position, if I give a position of 0.3, its hidden, if I set the position to .5, is far, 1.0 too.
With this sample code, when I look to the sky I see this:
Image

My questions:
-Is this the best approach (expected result and faster runtime code), putting the arrow as child of the camera ?
(Creating a animator to always calculate the position of the arrow relative to the camera, looks expensive)
-There's another better way ?
-And how I set the object near the camera (in the sample code) ? Seems the scale and position are way too different from the normal RootSceneNode.

Thanks for any help...
CuteAlien
Admin
Posts: 9718
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: creating 3D arrow direction indicator

Post by CuteAlien »

You might want to search the forum, I think I've seen a post about that before somewhere (but yeah, could be a little hard to find). When I coded that I created an own scenenode for it and did the scaling and finding the view direction in OnRegisterSceneNode. Also didn't use it as child of the camera - first I had more than one camera anyway and I generally find the math just easier when both nodes just use absolute positions.

Scaling was something like distance of that node to the camera divided by the camera far value (was not 100% correct I think, but close enough you didn't notice usually).
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
Default User
Posts: 8
Joined: Wed Sep 12, 2012 7:05 pm
Location: Saquarema, Brasil

Re: creating 3D arrow direction indicator

Post by Default User »

CuteAlien wrote:You might want to search the forum, I think I've seen a post about that before somewhere (but yeah, could be a little hard to find). When I coded that I created an own scenenode for it and did the scaling and finding the view direction in OnRegisterSceneNode. Also didn't use it as child of the camera - first I had more than one camera anyway and I generally find the math just easier when both nodes just use absolute positions.

Scaling was something like distance of that node to the camera divided by the camera far value (was not 100% correct I think, but close enough you didn't notice usually).
Thanks for the reply, I've searched, found some topics nearly identical, but none offers a solution, one of them, the OP just figure it out and leaves the topic unanswered.
:roll:

Anyway, looks like the children nodes doesn't follow the parents orientation and position as I've firstly imagined. I've discovered that SceneNodes work with a internal matrix called AbsoluteTransformation, I'm using it in a Animator on the ArrowSceneNode:

Code: Select all

 
void animateNode(scene::ISceneNode* node, u32 timeMs) {
        core::vector3df mod(-5,5,10);
        node->getSceneManager()->getActiveCamera()->getAbsoluteTransformation().transformVect(mod);
        node->setPosition(mod);
    }
 
It now stays stationary to the view, its almost ok.

But how could I make it render these arrows in orthogonal projection?
and my great doubt, should a create a ISceneNode, IMesh or stay with ISceneNodeAnimator subclass for this?
(I think I can make it work on every class, which will bring more benefits in this case)

Another problem is when I strafe to the sides with the camera, the arrow mesh start to shake, as it is taking a micro delay to keep the pace with the camera.
Moving forward/Backward or rotating the camera is ok, not delays.
What could it be ? Is the animateNode method called every frame for sure ? or maybe its the precision of the matrix calculations?

Sorry about the english and the number of questions :roll: , but I really want to understand this engine, I dropped python and started to learn C++, and I found the Irrlicht engine the only which is good enough for games and free for commercial purposes.
CuteAlien
Admin
Posts: 9718
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: creating 3D arrow direction indicator

Post by CuteAlien »

Ah, I didn't really look at the first screenshot and thought about the other arrow (the one in the cube). Now it makes sense why you wanted to put it as child of the camera. Which could have worked - children do follow the parent scenenodes, the problem with cameras is that they are a little special. Unless you set ICammeraSceneNode::bindTargetAndRotation(true) the rotation of the camera-node and the direction in which the camera looks don't have to be identical (that makes sense in some strange cases).

I would make a SceneNode for this, although it could as well be done with a mesh. But this is a very special node-type so creating an own node-class for it makes you a little bit more flexible. Although writing an Animator that just ensures any node stay in that place might also make sense... well, it's just like that in programming sometimes - several solutions which all make some sense :-) None seems wrong to me.

The problem with the delay is likely that getAbsoluteTransformation is not yet updated. It's calculated from position+rotation+scaling before the rendering. So if you need the updated position earlier you have to force an update with ISceneNode::updateAbsolutePosition(). The delay is probably there in all movements, but that 1-frame-lag ss always more noticable no side-movements.
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