Child node issues / Draw order

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
DavidR
Posts: 34
Joined: Sat Jul 15, 2006 5:12 pm

Child node issues / Draw order

Post by DavidR »

Not sure whether this really counts as an 'advanced' question, but hey, here it goes any how:

I have two objects, each one a flat plane (so they work like billboards, except I can rotate them) One is a 'spaceship', and the other is a 'trail' attached to the ship's engine.

I have made the trail a child of the ship, and it follows the ship perfectly. I have come across a rather odd draw order problem though. Sometimes, the tail will randomly be drawn on top of the ship (which I don't want) and some times it will draw correctly (underneath it).

In an attempt to make sure it always remained underneath it, I tried to make the trail 'deeper' under the ship (this is being viewed by a camera above the ship, so by pushing the Z of the trail it should go further underneath it). This seemed to have no effect, however: the X and Y values of the trail had an affect, but altering the Z coordinate of the trail had no effect at all. I assume this is something to do with the parent node, but I can't quite understand why (if I detach it from the parent, the Z coord does indeed change, and depth stops the draw issues).

I was determined to fix the problems via other means, so I messed with lots of other things (Altering the camera, turning off alpha/transparency on everything) and none of them made any difference. It all came back to the fact that the Z of the trail is equal to the ship's , so I'm getting Z-fighting, presumably.

But why am I unable to alter the Z coordinate? Does the child inherit some crazy property from the parent?
DavidR
Posts: 34
Joined: Sat Jul 15, 2006 5:12 pm

Post by DavidR »

I've been tinkering a bit more, and I'm still quite confused. If the trail is repositioned as so:

Code: Select all

EngineBlast->setPosition(vector3df(0,-0.45f,10));
calling getPosition(); returns a Z of 10 (as expected) even though the node's Z clearly has not changed - but calling getAbsolutePosition(); shows the Z to be dead-on 0 (and since the parent is at 0,0,0 the Z coordinate remains the same as the parent)

Why is this happening? :?
DavidR
Posts: 34
Joined: Sat Jul 15, 2006 5:12 pm

Post by DavidR »

Ok, after playing a bit more, I think I have found a potential bug.

My 'planes' are in fact made using addCubeSceneNode() with a Z scale of 0, so the cube is flat. This is stupid, but it works for quick tests etc.

However, I think the 0 Z scale is linked to this problem. I altered the Z scale of the ship's cube to 1 (so it became a cube rather than a plane) and immediately the relative Z position of the trail actually worked

This means, for some reason, applying relative translations to the child on the axis where the parent has 0 scale has no effect.

This is either a bug or something with an obvious cause, but being rather un-knowledgeable about how the parent-child system works, I can't say either way. Can someone enlighten me to why these translations are ignored unless I increase the Z scale of the parent?
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post by Acki »

haha, I see, I had the same problem once... :lol:
yes, it's because of the scale to 0 !!!
all actions (setPosition, setRotation and even setScale) on a parent node also act on its child nodes...
e.g. if the child is at position 10 relative to its parent and you scale the parent by 2 then the child moves to 20 (10 * 2 = 20)...
and if you scale the parent to 0 then the position of the child gets 0 (10 * 0 = 0) !!!
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
DavidR
Posts: 34
Joined: Sat Jul 15, 2006 5:12 pm

Post by DavidR »

Ah yes of course, I keep forgetting the parent->child relationship :oops:
Pyritie
Posts: 120
Joined: Fri Jan 16, 2009 12:59 pm
Contact:

Post by Pyritie »

It's usually best to use something like 0.01f for very small scales instead of 0. It can make things screw up every now and again.
Hive Workshop | deviantART

I've moved to Ogre.
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

It's probably better to use a plane instead of a cube.
Pyritie
Posts: 120
Joined: Fri Jan 16, 2009 12:59 pm
Contact:

Post by Pyritie »

That too. :P
Hive Workshop | deviantART

I've moved to Ogre.
DavidR
Posts: 34
Joined: Sat Jul 15, 2006 5:12 pm

Post by DavidR »

Yeah, a plane would be better - but how? There is no built in command for planes (and I can't get the hill plane to work properly for small sizes)
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post by Acki »

you can create one with an 3d-editor...
or create a custom scene node...
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

A small 4x4 hillplane mesh should work as expected. What's your problem with it?
Post Reply