Camera rotation with RigidBodyControl rotation

Hi,



I want to make the camera match the rotation and the position of a RigidBodyControl object named ship. The first thing that sprang to mind was to simply set the Camera rotation and translation to a current rotation and translation of a ship in the simpleUpdate() method. The translation works. However, I ran into problems while setting the rotation, since Camera’s setRotation() method expects Quaternion and RigidBodyControl getPhysicsRotation() metrod returns Matrix3f. That alone suggested that my idea of doing this might be wrong, and that there might a better way.



On a side note, is there some specific reason why the RigidBodyControl rotations are done with matrices and not quaternions? Please excuse my ignorance. I’m quite new with this 3D business in practice. ( I’m a flatlander :slight_smile: )



Thanks

You can also use the rotation of the spatial that is controlled by the RigidBodyControl, its a quaternion. The difference is because bullet returns a Matrix and jME mostly uses Quaternions. You can convert one to the other or use getPhysicsRotationQuat().

Thanks for quick response. It works with spatial. I had doubts in my approach because I completely forgot that Bullet is another library.



So there is a getPhysicsRotationQuat(). I suppose it’s in a nightly or something like that, because I don’t have it. But that’s OK. Do you think it’s a good idea to maybe convert all Bullet’s Matrix3f to Quaternions (in a way that API exposes only Quaternions to the user, involving rotations)? That would make sense if, as you say, jME mostly uses Quaternions. In that scheme getPhysicsRotation() would that return Quaternion, and the methods that return matrix would end with Matrix, for example getPhysicsRotationMatrix().



What do you (and others) think about that? Would it break something in the framework? Is it worth it? Should I do it?

Thats why I added getPhysicsRotationQuat(), since there might be situations where you don’t want the overhead in converting the value, the Matrix3f format is kept. And as said, the objects are easily converted to one another.

I understand. This was just a small cosmetic note.



Also, I found that Spatial has two overloaded setLocalRotation(). One accepts Quaternion and the other Matrix3f (converting it to Quaternion). It’s basically the same thing, but the other way around. That looks OK too, but there is no such overload in Camera. I think it’s better that it’s one way all the way or the other, ie. conversions either in Bullet glue code, or in jME code.



Now, don’t get me wrong here. I’m not criticizing you guys or nagging. Far from it. I think you’re doing a great job. Just pointing out my observation. If any of it makes sense I’m willing to go through the code and amend it according to the convention we settle upon, while you keep doing the real magic. :slight_smile:

No offense taken, I think you are right that there should be setters for any kind of rotation value across the engine, maybe there should even rather be a getPhysicsRotationMatrix()…

OK. Sounds like a plan.

There you go :slight_smile: http://code.google.com/p/jmonkeyengine/source/detail?r=6749

1 Like

Wow. Lightning-fast. You didn’t even give me a chance to blink. :slight_smile: