Drawing a line to connect two objects

Pretty much the title. I just want to draw a line that connects the centre-point of two objects, then, however the objects move, the line stays connected to the same points. I can draw a line okay, but I am having trouble making it update when objects move. Any ideas?

I think this post about a quad will give you some direction. At the very least, the idea behind pointing the laser should apply to a line as well.



http://www.jmonkeyengine.com/jmeforum/index.php?topic=8131.msg63767#msg63767

Thank you! But the problem here is that the laser code seems to rely on getLocalTranslation(), which won't be possible, since the objects are physics objects, and it's the physics that is causing them to move (sorry, I really should have mentioned this earlier), not translations, so I won't get the correct result.



I've started looking at the PhysicsDebugger, because that kinda does something similar, but the code is proving very hard to decypher. It seems to use BufferUtils in order to draw lines? Have I got that right? I've just been creating new Line objects. Is there any advantage to either approach?



EDIT: Also, how does the PhysicsDebugger manage to draw lines that are seemingly not affected by light? Like the red gravity arrows?

hand said:

But the problem here is that the laser code seems to rely on getLocalTranslation(), which won't be possible, since the objects are physics objects, and it's the physics that is causing them to move (sorry, I really should have mentioned this earlier), not translations, so I won't get the correct result.

Are you sure? The DynamicPhysicsNode and StaticPhysicsNode both have local translations. It's true that they are controlled by the physics simulation, but that doesn't mean that information is not available to you!

You can use getWorldTranslation and/or getLocalTranslation for physics nodes as well (as nymon already said). You need to update the buffers of the line accordingly.



To switch off lighting you can set a light state (specific render state) which is OFF.

Ah, I've got it figured out now. I had a pretty fundamental misunderstanding for how the physics worked… Thank you both for your help!