Rotating around a given axis/vector?


I need to rotate some of my NodePaths around an axis given by a simple direction, i.e. a Vec3. I can’t seem to find any functions that does it, so I’ve tried doing it by using lookAt first to align the NodePath correctly, and then using setR. Should that work, or have I misunderstood lookAt? Is there an easier way to perform rotation about an arbitrary axis?

Edit: Now that I think of it, I really need to align the Z-axis of a NodePath to a given Vec3 - is that possible? It would actually just correspond to setting the up direction for the model.


I think nodepath.headsUp(nodepath, Vec3) will do it but if not you could also try setting the quaternion of your nodepath:

from pandac.PandaModules import Quat
quat = Quat()
quat.setAxisFromAngle(angle, Vec3(1, 0, 0))

Right, I will try that. Thank you for the swift reply!