Rotating a node.child?

Hello all!



First of all, thanks for taking a look at this topic; I havent been into Jmonkey for too long and I'm still figuring things out. So, as we speak I'm trying to accomplish some little things in order to be able to work on an upcoming school project (a simple tank 3d shooter).



Now, I've come to the point where i have a model of a tank, which is subdivided in 4 parts. Now, I've already noticed that when loading a model as a node, i can get to the turret-thing by typing "battleTank.getChild(4)".



Now, this is what I'm trying to accomplish… I want to be able to rotate the tank's turret by mouse movement or by scroll wheel. As a test, i tried the following code, but it does not seem to work :).

battleTank.getChild(4).setLocalRotation(

                                        new Matrix3f(Math.cos(30),0,Math.sinh(30),0,1,0,Math.sin(30),0,Math.cos(30))

                              );



So basically, what I'm asking… Is there anyone who could put me in the right direction of rotating the tanks turret?



I also haven't been able to find out the right way of catching the scroll wheel action which will eventually trigger the rotation of the turret.





Well, i hope someone is able to help me a bit. For sure it will speed my understanding of jmonkey up!



Kind regards,

Ivo Jonker

In jME it is preferable to use quaternions for rotation, also, the math trigonometric functions accept radian measures only.

Your example code can be re-written like this:


// 2nd argument is rotation around Y-axis
battleTank.getChild(4).getLocalRotation().fromAngles(0, 30 * FastMath.DEG_TO_RAD, 0);

// update world transforms
battleTank.getChild(4).updateGeometricState(0, true);

Ooh, that's even better indeed! And improves readability by far!



I'm starting to wonder though. Is it possible to rotate around a certain specified point? Since the turrent's center is not exactly in the middle (object wise) i will be needing to apply a translation after every rotation (am i right?). I'm sure i'll be able to generate a suitable table for this, but i'm starting to asume there's the possibility to specify my own center?

Anyway… For now i'm helped a lot!



Time to figure out how to map the scroll wheel to the rotating action. i believe i've seen a tutorial covering this somewhere… any tips/hints are still welcome!



Thanks a lot!

All right, great! thanks :slight_smile: Accomplished exactly what i tried to accomplish :smiley:

atleast, swiched from mouse to keyboard control for now. Thanks a lot!