Quaternion question

Greetings,
I’m trying to find/create a method for panda that allows me to return a rotation that looks along forward with the the head upwards along upwards

Something like this:

def LookRotation (forward, upwards):  
# Look along forward with the head upwards along upwards
# Returns Quat

Can anyone help me with this? :slight_smile:

np = NodePath('np')
np.lookAt(forward, upwards)
return np.getQuat()

David

But lookAt takes first a node and then a point3 right?

Is there anyway to do this with two point3 or vec3?

lookAt() has many forms. One of them, yes, takes a NodePath as the first parameter. Another one takes just a Point3 and an optional Vec3.

David

Thanks David, what I’m trying to do is to rewrite this open source script written for the Unity3D engine in C#: unifycommunity.com/wiki/inde … Controller

see video here of the effect: youtube.com/watch?v=z8vZeztp8X4

But I haven’t got to work yet. Any ideas if there is some other similar way to achieve this “head look at point” effect in Panda?

Have you seen the “looking and gripping” demo?

The animation in the video is actually a little more sophisticated than that demo, because the actor is also flexing his upper torso a bit to follow the target. To do this (in any engine) requires integration with the animation subsystem, which is considerably more complicated than simply rotating a joint around. You can do it in Panda, too, but you’ll need a fairly deep understanding of how animation, joints, and transforms work.

David

yeah I saw that demo, it’s just too simple to be used with what I’m doing. This is the only calculation it does right?:

self.eveNeck.setP(restrain(mpos.getX()) * 50)
self.eveNeck.setH(restrain(mpos.getY()) * 20)

Btw. Is there somewhere a detailed documentation on the panda lookat() method?

Yeah, you could try something like this:

self.eveNeck.lookAt(target)

but that won’t work unless you first expose the parent joint of eveNeck (whatever it is) and reparent the self.eveNeck joint to that exposed node, so that the global transform is correct for self.eveNeck.

Have you seen the API reference for NodePath? It lists all of the lookAt() functions in a row there.