Anchored Arrows

Hi there,

I am trying to link two Geometry instances by means of an arrow. Ideally, the arrow geometry itself (shaft, foot, head) would update automatically as soon as either of the linked Geometries has updated its transform (locally or due to dependencies up the scene graph).

Does anyone have an idea how I could implement this elegantly in JME?

Thanks a bunch!

http://hub.jmonkeyengine.org/javadoc/com/jme3/scene/debug/Arrow.html

I’m impressed by your fast response. Thanks, Normen!

I have studied already quite a bit of the code base and of course, I have already stumbled across the debug arrow. What I would like to have, though, is an arrow that links to Spatials and if either of them updates its transforms, it also, automatically, updates its geometry. Any ideas?

/sigh… Here, untested, off the top of my head:

[java]public class ArrowUpdateControl implements Control{
Spatial spatial1, spatial2;

public ArrowUpdateControl(Spatial spatial1, Spatial spatial2){
    this.spatial1=spatial1;
    this.spatial2=spatial2;
}

public void update(float tpf){
    //we know our spatial is an Arrow
    Arrow arrow = (Arrow)spatial;
    arrow.setExtent(spatial2.getLocalTranslation().subtract(spatial1.getLocalTranslation());
    arrow.setLocalTranslation(spatial1.getLocalTranslation());
}
.....

}

//Usage:
Arrow arrow = new Arrow(Vector3f.ZERO);
arrow.addControl(new ArrowUpdateControl(spatial1, spatial2);
rootNode.attachChild(arrow);
[/java]

2 Likes

Great! I hadn’t seen / understood the meaning of Control(s) yet. I am confident I will make it through now.

Thanks and thanks again!