Adding a geometry to a node and keeping its offset

Hi Gang,



So I create a node that I intend to use as a pivot for spatial X. I move the node to the pivot point of spatial X. I then add spatial X to the node… But spatial X is now moved to the nodes new position.



So how do I add a spatial to a node and ensure it keeps its offset? Been trying a few things now, all to no avail.



I should point out that I am importing a .obj file, so I’m trying to find the best way to rotate the “gun” part of the tank at its base.



Thanks

Richard

set local translation of both of them to 0,0,0, then attach, then move the node

@nehon said:
set local translation of both of them to 0,0,0, then attach, then move the node

Thanks Nehon, but this is going to move the "gun" as well, right? I want the gun to stay where it is.

Is this the solution?


  • Move the node to the desired location (setLocalTranslation),

  • On object X, subtract(...) it's local translation from that of the node, and store this value in a temporary Vector3f.

  • Make object X a child of the node (which will move object X).

  • Now change object X's local translation by adding the Vector3f stored above.


Am I waaaay off the mark here?