Child node issues / Draw order
Child node issues / Draw order
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?
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?
I've been tinkering a bit more, and I'm still quite confused. If the trail is repositioned as so:
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?
Code: Select all
EngineBlast->setPosition(vector3df(0,-0.45f,10));
Why is this happening?
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?
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?
haha, I see, I had the same problem once...
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) !!!
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:
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
IrrExtensions:
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
you can create one with an 3d-editor...
or create a custom scene node...
or create a custom scene node...
while(!asleep) sheep++;
IrrExtensions:
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
IrrExtensions:
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java