PandaSteer 2

Thanks for PandaSteer2, chombee.
Your code is clean, well commented and you make it look simple. Those are hallmarks of a good programmer. I am new to Python & learnt a few tricks from you.

Happened to glance at your draw.py module, thought it would be handy for positioning and suchlike, but could not resist tweaking.

Fixed a couple of trivial bugs :-

def drawAxes(..):
...
        self.drawLine(Vec3(0,0,0), Vec3(0,size[1],0), color, thickness,np)
        self.drawLine(Vec3(0,0,0), Vec3(0,0,size[2[]), color, thickness,np)

    class World(DirectObject):
        """The test environment."""
       import direct.directbase.DirectStart	# to get global "base"

The “thickness” parameters are no good, because of the way setThickness() works. The last call before create() sets the thickness of ALL lines. You may as well use setThickness() directly.

d = Draw()
d.drawXYCircle(color=(0.667,0.33,0,1))
...
d.setThickness(3)     # set thickness of ALL lines
node = d.create() # A special GeomNode that draws the shapes.

Implemented your idea for drawing relative to a given nodepath by using its transform matrix. But I suspect the drawing stays fixed if the nodepath moves. Proper way is probably to attach your Draw() object to the nodepath and let Panda take care of moving it.

    def drawLine(self,startPoint,endPoint,color=defaultHue,thickness=None,np=None):
        """Draw a line from startPoint to endPoint using the given color.
        color: 3-tuple of floats between 0 and 1: r,g,b	(alpha is unused?)
        thickness: float
        np:	nodepath to use for coordinate frame. Line will be draw relative to
            this node. Default (None) uses render's global coords
        """
        if np:
            # change start & end points as if they were relative to np
            mat=np.getNetTransform().getMat()
            startPoint=mat.xformPoint(startPoint)
            endPoint=mat.xformPoint(endPoint)

        self.setColor(*color)
##        self.setThickness(thickness)	# wrong! LAST call sets thickness for ALL lines
        self.moveTo(startPoint)
        self.drawTo(endPoint)

(Naturally all other methods need to pass np to drawLine().)

Wrote a new method drawLattice().
Later realised that it could replace all of drawRectangle(), drawXYGrid() & drawCuboid(). Did not bother to change them, but added examples to your demo.

    def drawLattice(self,xRange,yRange,zRange,color=(1,1,1),np=None):
        '''draw 3 dimensional grid of lines
        XRange,yRange,zRange are each a TUPLE of floats :
            (10,17,22)		draws grid lines at the three given coordinates
            range(-10,11,5) draws regular grid lines at -10,-5,0,5,10
            (0,)			draws a flat grid, collapsing one dimension
                            Note the comma - tuple with 1 item only
            First & last elements define endpoints of lines. 
            Interesting effects if points are out of order.
        '''
        for x in xRange:
            for y in yRange:	# draw lines in Z direction
                self.drawLine(Vec3(x,y,zRange[0]), 
                              Vec3(x,y,zRange[len(zRange)-1]), color, 1,np)
            for z in zRange:	# draw lines in Y direction
                self.drawLine(Vec3(x,yRange[0],z), 
                              Vec3(x,yRange[len(yRange)-1],z), color, 1,np)
        for z in zRange:
            for y in yRange:	# draw lines in X direction
                self.drawLine(Vec3(xRange[0],y,z), 
                              Vec3(xRange[len(xRange)-1],y,z), color, 1,np)

    class World(DirectObject):
        """The test environment."""
        import direct.directbase.DirectStart		# to get global "base"
        def __init__(self):
...
            # Draw some lattices .............................................
            hue=(0,0.3,0.4)
            # 3x3x3 cube at (0,-50,0)
            d.drawLattice(range(0,11,5),range(-50,-39,5),range(0,11,5),hue)
            # single flat YZ grid at x=-50 with uneven Y lines
            d.drawLattice((-50,),(-10,-8,0,8,9,10),range(10,21),hue)
            # box - same as drawCuboid()
            d.drawLattice((-50,50),(-50,50),(-25,-1),hue)
            # set of disconnected XY grids
            d.drawLattice(xRange=range(-50,-29,2),
                          yRange=range(-50,-29,2),
                          zRange=(0,10,20,30,0),	# repeat first number at end to suppress Z lines
                          color=hue)

            # rotated & positioned as if under a nodepath
            rot=render.attachNewNode('rotatedNP')
            rot.setPosHpr(-10,-20,5,  120,0,45)
            hue=(0.6,1,0.4)
            d.drawAxes(size=(3,4,5),color=hue,np=rot)
            d.drawLattice((2,4),range(2,7,2),range(2,9,2),color=hue,np=rot)

A hack for drawSphere() might be to draw a circle and attach it to a nodepath with setBillboardPointEye().
But I have not tried it – gotta start using PandaSteer2 !

Hey, thanks for this :slight_smile: Looks like good stuff. I’ll be taking a peek when I get back to programming with pandasteer, whenever that may be (but sometime).

Hope you enjoy the rest of it!

You need these changes if you want to use it with Panda 1.5.4:

camera.py

--- camera.py-revBASE.svn001.tmp.py	mar feb  3 13:01:31 2009
+++ camera.py	dom feb  1 23:19:02 2009
@@ -221,7 +221,7 @@
         vec*=newDist#set length to clamped value
         camera.setFluidPos(vec)#move the camera to new distance
         #Move the segment end but keep it a little behind and below the camera.
-        self.segment.node().getSolid(0).setPointB(
+        self.segment.node().modifySolid(0).setPointB(
             self.target.getRelativePoint(camera, P.Point3(0,-2,-1)))
 #end EdgeScreenTracker 

vehicle.py

--- vehicle.py-revBASE.svn000.tmp.py	mar feb  3 13:03:52 2009
+++ vehicle.py	dom feb  1 23:18:24 2009
@@ -698,7 +698,7 @@
 
         # Update the Vehicles's CollisionTube, varying the length of the tube
         # according to the Vehicle's speed.
-        tube=self.tubenp.node().getSolid(0)
+        tube=self.tubenp.node().modifySolid(0)
         tube.setPointB(Point3(
                    tube.getPointA()+Point3(0,15.*self._velocity.length(),0)))

pandaSteer.py

--- pandaSteer.py-revBASE.svn000.tmp.py	mar feb  3 13:04:58 2009
+++ pandaSteer.py	dom feb  1 23:23:37 2009
@@ -166,7 +166,7 @@
         
         mpos=base.mouseWatcherNode.getMouse()
         # Makes the ray's origin the camera and make the ray point to mpos
-        self.picker.node().getSolid(0).setFromLens(
+        self.picker.node().modifySolid(0).setFromLens(
             base.camNode,mpos.getX(),mpos.getY())
         # We don't want to traverse now, so wait for panda to do it then move.
         taskMgr.doMethodLater(.02,self.setDestination,'setDest')

scene.py

--- vehicle.py-revBASE.svn001.tmp.py	mar feb  3 13:06:12 2009
+++ vehicle.py	dom feb  1 23:18:24 2009
@@ -698,7 +698,7 @@
 
         # Update the Vehicles's CollisionTube, varying the length of the tube
         # according to the Vehicle's speed.
-        tube=self.tubenp.node().getSolid(0)
+        tube=self.tubenp.node().modifySolid(0)
         tube.setPointB(Point3(
                    tube.getPointA()+Point3(0,15.*self._velocity.length(),0)))

Bye! :wink:

Thanks!

Hi chombee! Thanks for your work.

These changes are required to use vehicle and character classes into an external Panda3D application:

character

--- character.py-revBASE.svn000.tmp.py	mar feb  3 18:44:18 2009
+++ character.py	mar feb  3 17:56:42 2009
@@ -26,7 +26,6 @@
 # Character, and set the variable names accordingly.
 
 # Panda3D imports
-import direct.directbase.DirectStart
 from pandac import PandaModules as P
 from direct.fsm import FSM
 from direct.actor.Actor import Actor

vehicle

--- vehicle.py-revBASE.svn002.tmp.py	mar feb  3 18:45:27 2009
+++ vehicle.py	mar feb  3 17:58:48 2009
@@ -38,7 +38,7 @@
 def traverse(task):
     cTrav.traverse(render)
     return Task.cont
-collisionTraverse=taskMgr.add(traverse,"collisionTraverse task of vehicle.py")
+    
 # CollisionHandler used for Vehicles avoiding static obstacles
 obstacleHandler = CollisionHandlerQueue()
 # CollisionHandler used to detect Vehicles colliding with eachother
@@ -193,6 +193,8 @@
         self.callout.setBillboardAxis()
         self.callout.hide()
         self.callout.setLightOff(1)
+        
+        collisionTraverse=taskMgr.add(traverse,"collisionTraverse task of vehicle.py")

Now you can import character module without a double Panda window.

To ease the seek&find to other people hitting this thread, I packed all the latest files (till today) of this really amazing demo in a convenient zipped file with the addition of the zuck fixes above and uploaded into my website. You may download the package here:

chombee-pandasteer_2.65b.zip (9.9 MB)

PS: chombee, it would be nice, if you can, to put this package on the top of this thread and mark it as last version, just to avoid confusion.

How is this code doing? What would you like to add? What is on your todo list? I have been thinking a lot about making a python lib for doing Prolog stuff. I have also thought about doing a path finder using Monte-Carlo methods.
en.wikipedia.org/wiki/Computer_G … lo_methods
I am using most of my free time now making my mmORPG but it might be fun to help here and help my program at the same time.
Douglas

Hey wow, thanks for doing that astelix. I’ve been away from Panda for a long time, but I just tried your pandasteer download with the latest release of panda on the latest version of ubuntu, and it works. For some reason I was getting only 6 FPS and I remember the demo being much faster, but that is probably due to the graphics configuration of my current machine.

I’ve uploaded the latest code, from the download you put together, to my github account. I think this should be a good place for permanent storage: github.com/seanh/PandaSteer

PandaSteer was developed in a svn repository not a git one, so to get the history on github would take some work that I don’t have time for, but I think it’s worthwhile just to host the latest code without history somewhere more permanent.

Douglas, I haven’t worked on this code for a long time but IIRC as an implementation of steering behaviours it was more or less done. (The terrain-based demos I had begun to add into it were less complete.) Astelix’s download is the latest one.

heya chombee nice to see you around here again - I can’t recall very well but as I wrote in the previous post I just stuck into the fixes I found here without much else so can’t say if I broken something to make it slower than before but could be. Feel free to add my mirror 'cos is a stable account since is my personal website
cya