How can I rotate something on the HUD?

I’m making a loading scene, and have attached an image (Picture object) to the guiNode, and I’ve gotten it to display correctly. Now, I’d like to have it rotate clock-wise? I’ve tried messing around with the API, and looking through the Javadoc, but just couldn’t get it to work. Unfortunately I don’t know much about rotations (yet), since I’m still learning a lot of this darn math stuff. Anyways, if anyone has any good suggestions or ideas, I’d like to hear them, and I’d be more than happy enough to provide more details if necessary. Thanks in advance!

What’s wrong with node.rotate(tpf, 0, 0) ?



(Try different axis until you find the one you want)

Also make sure the camera’s Up vector is right. Not that I’ve done that mistake, no siree bob. :stuck_out_tongue:

@zarch > facepalm…Obviously I was too tired when I tried, because I was hoping to find that function, but I totally missed that version (I only saw the version that took a Quaternion.) Thanks for pointing out it does exist :smiley:



Now, this causes it to rotate, but also translates it, or it rotates it’s position. I actually wanted it to rotate in place (e.g. no translation.) How could I achieve this? :stuck_out_tongue:

@miguelg-fernandez said:
@zarch > *facepalm*...Obviously I was too tired when I tried, because I was hoping to find that function, but I totally missed that version (I only saw the version that took a Quaternion.) Thanks for pointing out it does exist :D

Now, this causes it to rotate, but also translates it, or it rotates it's position. I actually wanted it to rotate in place (e.g. no translation.) How could I achieve this? :P


I would really suggest reading the docs and drawing in a piece of paper. It normally helps me out (both advices).
@miguelg-fernandez said:
Now, this causes it to rotate, but also translates it


Sounds like you need to rotate around a different origin, I think a trip to the Scene Graph for Dummies is in order, going through that should help you understand both why your image is rotating the way it is, and how to make it behave how you want.

Not to mention the second basic tutorial…which uses that very rotate function I just pointed you to.

@thetoucher > Okay, so I went through that handy little presentation, and I think I understood the concepts relatively correctly. Unfortunately, I still can’t get it to behave the way I like. Considering what was said in slides 29-33 of the presentation, I put a node in between the Picture and the guiNode (sorry I don’t have the exact code at the moment), so I could rotate the Picture relative to this node, but the behavior hasn’t changed…



Got any hints? :smiley:

Move the geometry to 0,0,0

Rotate the geometry

Attach the geometry to a node

Translate the node to the position you want.



Now geometry rotation will not affect position.

If you’re trying to do what I think you’re trying to do, you will need to move your Picture -width/2 and -height/2 so the middle of the picture is aligned to with the origin of the parent node, then rotate the parent node.

@thetoucher > Just to be clear, I have an image on the HUD, and I want it to continuesly rotate clockwise without it moving (translating.) In my own research I also stumbled upon the idea you just gave me. I currently have it implemented “litterally” but it still isn’t working. The code I have in my update() method of my AppState is:

[java]

public void update(float tpf) {

thingToRoate.move(-25tpf, -25tpf, 0); // It is 50x50

nodeItIsAttachedTo.rotate(0, 0, 3*tpf);

}

[/java]



This causes it to translate in a circular path, and over time the radius of the path grows larger. Any ideas? Just in case you need it, here’s the initialization code for the AppState (AFAIK, this is the only other section of code that modifies the Picture)

[java]

public void initialize(AppStateManager stateManager, Application app) {

super.initialize(stateManager, app);



thingToRotate = new Picture(“thingToRotate”);

// set image, and dimensions here…

thingToRoate.setPosition(20, 20);



nodeItIsAttachedTo = new Node(“attachNode”);

nodeItIsAttachedTo.attachChild(thingToRotate);

guiNode.attachChild(nodeItIsAttachedTo);

}

[/java]



Ideas? Oh, and sorry for being a bit dense… :stuck_out_tongue:

@miguelg-fernandez said:
[java]
public void update(float tpf) {
thingToRoate.move(-25*tpf, -25*tpf, 0); // It is 50x50
nodeItIsAttachedTo.rotate(0, 0, 3*tpf);
}
[/java]

Well every update, thingToRotate is being moved -25*tpf px "sideways" and "up"... so get rid of that line.

and change the other block to :

[java]public void initialize(AppStateManager stateManager, Application app) {
super.initialize(stateManager, app);

thingToRotate = new Picture("thingToRotate");
// set image, and dimensions here...
thingToRoate.setPosition(-25, -25);

nodeItIsAttachedTo = new Node("attachNode");
nodeItIsAttachedTo.move(20+25, 20+25, 0);

nodeItIsAttachedTo.attachChild(thingToRotate);
guiNode.attachChild(nodeItIsAttachedTo);
}[/java]
1 Like