Normal mapping tutorial?

The following post was made by Mike Pippin to our (now defunct) Panda3D mailing list on I am posting it here to reply to it, and so that others may contribute assistance as well.


Can someone explain what this set of code does and how it controls the movement

def controlCamera(self, task):
# figure out how much the mouse has moved (in pixels)
md = (0) <--------------------------What does this line do…
x = md.getX()
y = md.getY()
if, 100, 100): <-----------------------------What does this line do…and the following 2
self.heading = self.heading - (x - 100)0.2
self.pitch = self.pitch - (y - 100)0.2
if (self.pitch < -45): self.pitch = -45
if (self.pitch > 45): self.pitch = 45,self.pitch,0)
dir = <-------------------------------What does this line do?..
elapsed = task.time - self.last
if (self.last == 0): elapsed = 0
if (self.mousebtn[0]): <------------------------------
self.focus = self.focus + dir * elapsed
30 | I get that this section has something to do with movement but I
if (self.mousebtn[1]) or (self.mousebtn[2]): | dont get where the elasped time falls into the picture…
self.focus = self.focus - dir * elapsed
30 <------------------------------ or how it actually works because I dont know what getMat() does - (dir5))
if ( < -49.0):
if ( > 49.0): 49)
if ( () < -49.0):
if ( > 49.0): 49)
if ( < 1.0): 1)
if ( > 49.0): 49)
self.focus = + (dir
self.last = task.time
return Task.cont

Thank you in advance for any help that anyone may be able to give me…

Many of these questions can be answered, at least superficially, from the generated API docs on this website. For instance:

From GraphicsWindow:

To illuminate that some more, from MouseData:

So returns the mouse position information for the first (usually the only) mouse associated with the window.

Similar research illuminates that, 100, 100) will move the mouse to the indicated position.

A bit of experience with linear algebra will be necessary to fully understand the line “dir =”. is a NodePath that contains the camera, and NodePath.getMat() returns the local transform space of the referenced node, expressed as a 4x4 matrix. Thus, returns the transform of the camera as a 4x4 matrix. (This only returns the local transform, not the net transform. This is probably a mistake on the part of the application writer, since the net transform is probably what was intended, but in the case of the camera it may not matter much, since often the local transform and the net transform are the same thing for the camera.)

Now, one property of a 4x4 transform matrix is that the upper 3x3 quadrant of this matrix contains the axes of the transform space. In particular, the second row contains the Y axis. So the reference “mat.getRow3(1)”, which returns the second 3-component row of the matrix, actually returns the Y axis, or the forward axis. So the complete line is returning the forward axis of the camera into the variable dir.

The remaining bit of code that you have called out is figuring out how much the mouse has moved since the last frame, and then applying a corresponding motion to the camera. It scales this motion by the elapsed time since last frame, since otherwise the camera would move faster when the frame rate is very fast, and slower when the frame rate is low.

Please feel free to ask further questions if these answers do not illuminate. I’m not personally familiar with the application these questions are referring to, but perhaps other people on this forum can give you further advice about it.