|
|
|
Return to Code Snippets
by Ffeuuell » Wed Aug 15, 2007 6:30 pm
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 :-
- Code: Select all
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. - Code: Select all
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. - Code: Select all
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. - Code: Select all
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 !
-
Ffeuuell
-
- Posts: 10
- Joined: Wed Aug 08, 2007 2:20 am
by chombee » Thu Aug 16, 2007 6:45 am
Hey, thanks for this :) 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!
-
chombee
-
- Posts: 244
- Joined: Fri Jan 13, 2006 10:09 am
by zuck » Tue Feb 03, 2009 7:35 am
You need these changes if you want to use it with Panda 1.5.4:
camera.py
- Code: Select all
--- 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- Code: Select all
--- 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- Code: Select all
--- 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- Code: Select all
--- 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! 
Emanuele Bertoldi
-
zuck
-
- Posts: 115
- Joined: Wed Dec 10, 2008 12:37 pm
- Location: Udine, ITA
by chombee » Tue Feb 03, 2009 12:29 pm
Thanks!
-
chombee
-
- Posts: 244
- Joined: Fri Jan 13, 2006 10:09 am
by zuck » Tue Feb 03, 2009 1:14 pm
Hi chombee! Thanks for your work.
These changes are required to use vehicle and character classes into an external Panda3D application:
character
- Code: Select all
--- 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- Code: Select all
--- 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.
Emanuele Bertoldi
-
zuck
-
- Posts: 115
- Joined: Wed Dec 10, 2008 12:37 pm
- Location: Udine, ITA
by astelix » Thu Mar 12, 2009 10:53 am
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.
My Rig: P3D 1.7.0@WinXP & Kubuntu 10.04- Athlon 64 5200 X2 ~ Radeon 3200HD (integrated)
-

astelix
-
- Posts: 866
- Joined: Mon Mar 27, 2006 4:36 pm
- Location: Milano, ITA
by Douglas » Wed Apr 22, 2009 10:15 am
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.
http://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
-
Douglas
-
- Posts: 85
- Joined: Wed Dec 06, 2006 12:32 pm
by chombee » Sat May 16, 2009 9:15 am
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: http://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.
-
chombee
-
- Posts: 244
- Joined: Fri Jan 13, 2006 10:09 am
by astelix » Sat May 16, 2009 10:25 am
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
My Rig: P3D 1.7.0@WinXP & Kubuntu 10.04- Athlon 64 5200 X2 ~ Radeon 3200HD (integrated)
-

astelix
-
- Posts: 866
- Joined: Mon Mar 27, 2006 4:36 pm
- Location: Milano, ITA
Return to Code Snippets
Who is online
Users browsing this forum: No registered users and 0 guests
| | |