How to rotate an image in gui Node centeral?

how to rotate an image in gui Node centeral?

I want to rotate an image , but going out of the screen …
I can relocate it but its not interest …

You mean you want to rotate it about the y axis?

If so then you… rotate it… about the y axis. :slight_smile:

i think he wants to rotate around z axis cause Picture has its pivot point at 0, 0 ans this is why your image goes out of the screen. If you can confirm or add more details.

Anyway if you want to rotate around z and don’t want to recompute position each frame manually you can use a parent node where you can attach your image and calculate the right pivot point when attached (to center your image on the node center point) and then just rotate this parent node :wink:

I interpreted this as he WANTS it to go out of the screen.

At any rate… pick an axis to rotate around… then rotate around that axis.

“How do I rotate?”

…look at Spatial’s javadoc for a method called (unsurprisingly) “rotate”.

hey man I know it…
tell me some thing I dont know!

Offset it under a node. Rotate the node.

https://jmonkeyengine.github.io/wiki/tutorials/scenegraph/assets/fallback/index.html

i do it but not working

Your code looks fine from what I can see.

1 Like
private Node compassNode = new Node("compass node");
compassN.rotate(0, 0, FastMath.DEG_TO_RAD * -90);

and some where i added image to compassN …

you: “I have a problem”
me: “here is the solution”
you: “Not it’s a different problem”
me: “Here is a different solution.”
you: “No that doesn’t work.”
me: “can we see the code”
you: “Here is half the relevant code.”
me: tired of playing this game.

You either don’t center the child correctly or never add it or any of a half dozen things that are the simplest things in the world to fix… if we can SEE THE CODE.

i need centeral rotation please help me

in last picture i told that …

SHOW THE CODE.

You only showed half.

You must show the part where you add the child and center it. Because that’s the part you did wrong.

//==========================================================================
//       CAMERA locations
//==========================================================================
/**
 * next and pre camera location
 *
 * @param isNext <B>next or pre cam location</B>
 */
private void preNextCameraLocation(boolean isNext) {
    if (isNext) {
        switch (GameCameraState) {
            case "T":
                RightCamera();
                minimap.rotate(0, 0, FastMath.DEG_TO_RAD * -90);
                this.minimap.setLocalTranslation((float) (winWidth - w) - percentOfwinWidth(0.5f), percentOfwinWidth(0.5f), 0);
                this.minimap.setLocalTranslation((float) (winWidth - h) - percentOfwinWidth(0.5f), w + percentOfwinWidth(0.5f), 0);

                compassN.rotate(0, 0, FastMath.DEG_TO_RAD * -90);
                compassN.setLocalTranslation(percentOfwinWidth(0.5f), percentOfwinWidth(0.5f), 0);
                compassN.setLocalTranslation(0, h, 0);

                break;
            case "R":
                LeftCamera();
                minimap.rotate(0, 0, FastMath.DEG_TO_RAD * -180);
                this.minimap.setLocalTranslation((float) (winWidth) - percentOfwinWidth(0.5f), percentOfwinWidth(0.5f), 0);

                compassN.rotate(0, 0, FastMath.DEG_TO_RAD * -180);
                compassN.setLocalTranslation(percentOfwinWidth(0.5f), percentOfwinWidth(0.5f), 0);
                compassN.setLocalTranslation(h, 0, 0);

                break;
            case "L":
                TopCamera();
                minimap.rotate(0, 0, FastMath.DEG_TO_RAD * -90);
                this.minimap.setLocalTranslation((float) (winWidth - w) - percentOfwinWidth(0.5f), percentOfwinWidth(0.5f), 0);

                compassN.rotate(0, 0, FastMath.DEG_TO_RAD * -90);
                compassN.setLocalTranslation(0, (float) (winHeight + (-winHeight - h)), 0);

                break;
        }
    } else {
        switch (GameCameraState) {
            case "T":
                LeftCamera();
                minimap.rotate(0, 0, FastMath.DEG_TO_RAD * 90);
                this.minimap.setLocalTranslation((float) (winWidth) - percentOfwinWidth(0.5f), percentOfwinWidth(0.5f), 0);
                break;
            case "R":
                TopCamera();
                minimap.rotate(0, 0, FastMath.DEG_TO_RAD * 90);
                this.minimap.setLocalTranslation((float) (winWidth - w) - percentOfwinWidth(0.5f), percentOfwinWidth(0.5f), 0);
                break;
            case "L":
                RightCamera();
                minimap.rotate(0, 0, FastMath.DEG_TO_RAD * 180);
                this.minimap.setLocalTranslation((float) (winWidth - h) - percentOfwinWidth(0.5f), w + percentOfwinWidth(0.5f), 0);
                break;
        }
    }
}

/**
 * get the camPointer that shows on minimap
 */
private void PointerPosOnMiniMap() {

    float MpX = point.getLocalTranslation().getX(); // main point on map [x]
    float MpY = point.getLocalTranslation().getZ(); // main point on map [y]

    float MXpercent = (MpX / 1034) * 100;
    float MYpercent = (MpY / 1034) * 100;
    float x = (MXpercent / 100) * w;
    float y = (MYpercent / 100) * h;

    if ((Math.signum(MpX) == -1.0) && (Math.signum(MpY) == 1.0)) {

        minimapPoint.setLocalTranslation((w / 2) + (-x / 2), (h / 2) + (y / 2), 0);

    } else if ((Math.signum(MpX) == -1.0) && (Math.signum(MpY) == -1.0)) {

        minimapPoint.setLocalTranslation((w / 2) + (-x / 2), (h / 2) - (-y / 2), 0);

    } else if ((Math.signum(MpX) == 1.0) && (Math.signum(MpY) == -1.0)) {

        minimapPoint.setLocalTranslation((w / 2) - (x / 2), (h / 2) - (-y / 2), 0);

    } else if ((Math.signum(MpX) == 1.0) && (Math.signum(MpY) == 1.0)) {

        minimapPoint.setLocalTranslation((w / 2) - (x / 2), (h / 2) + (y / 2), 0);
    }

}

/**
 * this method add a compass on hud
 *
 * @param f
 * @param i
 */
private void initCompass(float f, int i) {
    Picture compass = new Picture("compass map image");

    w = 150;//(float) ((Wpercent / 100) * this.winWidth);
    h = 150;//(float) ((Hpercent / 100) * this.winHeight);
    compass.setWidth(w);
    compass.setHeight(h);

    compass.setImage(asset, "Interface/hud/compass.png", true);
    compassN.attachChild(compass);
    compassNode.attachChild(compassN);

    Picture axess = new Picture("axess");
    axess.setImage(asset, "Interface/hud/frame-compass.png", true);
    axess.setWidth(w);
    axess.setHeight(h);
    this.compassNode.attachChild(axess);

    this.compassNode.setLocalTranslation(percentOfwinWidth(0.5f), percentOfwinWidth(0.5f), 0);
    guiNode.attachChild(this.compassNode);
}

private Node compassNode = new Node("compass node");
private Node compassN = new Node("compass");

You see up there where you create the children and then never center them?

Try compass.center()
and maybe axess.center()

http://javadoc.jmonkeyengine.org/com/jme3/scene/Spatial.html#center--

Think about how much time we might all have saved if you’d include the code in the beginning, eh? You’d have had your answer the very first response.

1 Like

you are right thank you so much:blush: