HUD Compass

Hi,

What is the simplest way to create rotating HUD compass? I mean, when I move mouse horizontaly, my compass image is rotating in right dir. I use chase camera.
I tried using Picture class but it seems not to be best solution

@Skatty said: Hi,

What is the simplest way to create rotating HUD compass? I mean, when I move mouse horizontaly, my compass image is rotating in right dir. I use chase camera.
I tried using Picture class but it seems not to be best solution

Why does the picture class not work? That might help us tell you a better solution. Otherwise we may just give additional solutions that also don’t work.

I tried to move picture “root” by puting it into the Node. I added Picture to node, and node to rootNode but now I cannot see it. I tried change locations

@Skatty said: I tried to move picture "root" by puting it into the Node. I added Picture to node, and node to rootNode but now I cannot see it. I tried change locations

Did you add the node to your scene? It’s hard to help without seeing the actual code. This is a very simple thing so there must be something very simple wrong. The kind of thing that would be clear if we could see the four or five lines of code that does it.

Here it is:
[java] /HUD/
compassNode = new Node();
compass = new CompassControl(assetManager, this, game);
compass.init();
/End HUD/[/java]

CompassControl is my class with that compass image and functions to rotate it etc.
[java] public void init() {
pic = new Picture(“compass”);
setPicture();
pic.setWidth(128);
pic.setHeight(128);
pic.setPosition(game.getX()-128,game.getY()-128);
}[/java]
and now back in main class:
[java] compassNode.attachChild(compass.getPic());
rootNode.attachChild(compassNode); [/java]

Wait… this isn’t in the gui?

What do you mean? When I attach only compass to rootNode it’s vissible as 2D image correctly

@Skatty said: What do you mean? When I attach only compass to rootNode it's vissible as 2D image correctly

rootNode != guiNode … one is your 3D scene, the other is the appropriate place to attach HUD elements.

Oh, didn’t know that guiNode is in root of the application ;p thanks!

1 Like

How can i now get that really center to rotate compass? My node with image is rotating by whole screen. Can i change world trans?

@Skatty said: How can i now get that really center to rotate compass? My node with image is rotating by whole screen. Can i change world trans?

In JME you call Geometry.center() I believe.

If you need anything other than the absolute center, you either have to position the node yourself. Or, alternatively, the 2D Framework I added to tonegodGUI lets you set the origin of every quad within an AnimElement (and the animElement’s origin as well and all transforms are performed against the define origin. for each. They have a cascading effect if you setup parent linkage.

When I call center for my Node that doesnt help

@Skatty said: When I call center for my Node that doesnt help

Try it on the geometry (Geometry.center())

But I have only Picture and that Node

@Skatty said: But I have only Picture and that Node

public class Picture extends Geometry

1 Like

Still no effect ;/ what a bullshit

@Skatty said: Still no effect ;/ what a bullshit

Paste the entire block of code where you set this up and I’ll see if I can help ya through it. Can be frustrating for sure.

EDIT: Paste the image too if you would.

Image is just circle on alpha 128x128.
Here’s compass class. Tried over 20 ways to move, translate, etc pic or node but I just can’t get that root center -.-
[java]public void init() {
compassNode = new Node();
pic = new Picture(“compass”);
compassNode.attachChild(pic);
setPicture();
pic.setWidth(128);
pic.setHeight(128);
//compassNode.setLocalTranslation(-64,-64,0);
pic.move(game.getX()-128,game.getY()-128,0);
}

public void setPicture() {
    pic.setImage(assetManager, "Textures/GFX/Interface/GUI/compass.png", true);     
}

[…]
/**
* @param rotation the rotation to set
*/
public void rotatePLUS(float rotation) {
this.rotation = rotation;
compassNode.rotate(0, 0, currentRotation+rotation);
currentRotation = currentRotation+rotation;
}

public void rotateMINUS(float rotation) {
    this.rotation = rotation;
    compassNode.rotate(0, 0, currentRotation-rotation);
    currentRotation = currentRotation-rotation;
}

[…][/java]

Here ya go:

The first node does not center the picture, the second one does.

[java]
import com.jme3.app.SimpleApplication;
import com.jme3.math.Quaternion;
import com.jme3.math.Vector3f;
import com.jme3.renderer.RenderManager;
import com.jme3.scene.Node;
import com.jme3.ui.Picture;

/**
*

  • @author t0neg0d
    */
    public class CompassTest extends SimpleApplication {
    Node compassNode1 = new Node(“compass1”);
    Node compassNode2 = new Node(“compass2”);
    Picture compassPic1, compassPic2;
    Quaternion q1 = new Quaternion(), q2 = new Quaternion();
    float rot1 = 0, rot2 = 0;

    public static void main(String[] args) {
    CompassTest app = new CompassTest();
    app.start();
    }

    @Override
    public void simpleInitApp() {
    // This one is not centered
    compassPic1 = new Picture(“compassPic1”);
    compassPic1.setImage(assetManager, “Textures/compass.png”, true);
    compassPic1.setWidth(128);
    compassPic1.setHeight(128);
    compassNode1.attachChild(compassPic1);
    guiNode.attachChild(compassNode1);
    compassNode1.setLocalTranslation(200,200,0.5f);

     // This one is centered
     compassPic2 = new Picture("compassPic2");
     compassPic2.setImage(assetManager, "Textures/compass.png", true);
     compassPic2.setWidth(128);
     compassPic2.setHeight(128);
     compassNode2.attachChild(compassPic2);
     compassPic2.center();
     guiNode.attachChild(compassNode2);
     compassNode2.setLocalTranslation(500,200,0.5f);
    

    }

    @Override
    public void simpleUpdate(float tpf) {
    // Not centered
    rot1 += tpf;
    q1.fromAngleAxis(rot1, Vector3f.UNIT_Z);
    compassNode1.setLocalRotation(q1);

     // Centered
     rot2 += tpf;
     q2.fromAngleAxis(rot2, Vector3f.UNIT_Z);
     compassNode2.setLocalRotation(q2);
    

    }

    @Override
    public void simpleRender(RenderManager rm) {

    }
    }

[/java]

@Skatty
Did the above fix the issue you were seeing?