Rolling Ball, Urgent help needed

        sphere.setLocalRotation( new Quaternion().fromAngles( xrot, yrot, zrot ) );
        sphere.updateGeometricState( 0, true );


I think is what you want.
if the openGL thread is already started you need the updateGeometricState() otherwise changes won't show ;)


However it would probably be optimal to create a quaternion once then use set.fromAngles() to update

your last suggestion should work well (rotate per step), if you make sure you rotate in the right coordinate system…



something like this (unoptimized):


        // get axis of rotation
        tmpVec.set(direction).crossLocal(worldUpVec);
        // transform to the right coordinate system
        ball.getLocalRotation().inverse().multLocal(tmpVec);
        // create per frame rotation
        tmpQuat.fromAngleAxis(omega * t, tmpVec);
        // rotate ball
        ball.getLocalRotation().multLocal(tmpQuat);

Thank you so much I implemented this and it worked kinda, just they rolled oposite to the way they should, i just replaced omegat with omega-t and it works, but I really don't understand how the code you gave me works so I couldn't come up with a better way do to reverse direction of roll.

I just screwed up the order of the cross product (since i didnt test this code), just do tmpVec.set(worldUpVec).crossLocal(direction) instead and you can keep the omega*t…



glad to hear it works!

thanks alot, any chance you could go through whats happening because i can't follow how this is working? also another unrelated question, do you know how to kill the java program when I close my jmonkey window, atm My physics engine doesn't stop when the graphics does. I can't work out where to add the listener to run system.exit()

I have not decided on the best method for myself, but the topic of shutting down the game cleanly has been discussed in these threads:



How to cleanly shut down StandardGame?

Threading and Standardgame - mid-thread

The problem has to do with threads hanging on. For simplicity you can make all threads other than the OpenGL thread a daemon thread (thread.setDaemon(true)) which means when all non-daemon threads terminate and all that's left is daemon threads the VM will terminate them and end the application.

our standard game is created in the Main method and an instance of our GameManager class is made, and that class manages data flow between physics and graphics parts of the program, so when we close our window our GameManager is still going (during a shot the game manager is in a loop that transfers object states between the two parts of the game) with no idea that the openGL thread is dead. but we don't "own" any of the other threads running including the event thread (which stays alive also) so i dont think we can set anything to be daemon because we dont have references to them. I know you don't like this darkfrog but is there a way that we can get an event from our StandardGame that tells us the window was closed?

We had previously discussed adding a destroy() method to GameState that would be invoked upon shutdown, but I don't think that was ever added.  That would be the best to handle this probably.