diff --git a/direct/src/controls/ShipPilot2.py b/direct/src/controls/ShipPilot2.py index 553abcf162..fec676f968 100755 --- a/direct/src/controls/ShipPilot2.py +++ b/direct/src/controls/ShipPilot2.py @@ -27,11 +27,11 @@ class ShipPilot2(PhysicsWalker): notify = directNotify.newCategory("PhysicsWalker") wantDebugIndicator = base.config.GetBool( 'want-avatar-physics-indicator', 0) - + useBowSternSpheres = 1 useLifter = 0 useHeightRay = 0 - + # special methods def __init__(self, gravity = -32.1740, standableGround=0.707, hardLandingForce=16.0): @@ -43,7 +43,7 @@ class ShipPilot2(PhysicsWalker): self.__gravity=gravity self.__standableGround=standableGround self.__hardLandingForce=hardLandingForce - + self.needToDeltaPos = 0 self.physVelocityIndicator=None self.avatarControlForwardSpeed=0 @@ -60,7 +60,7 @@ class ShipPilot2(PhysicsWalker): self.__slideSpeed=0.0 self.__vel=Vec3(0.0) self.collisionsActive = 0 - + self.isAirborne = 0 self.highMark = 0 self.ship = None @@ -86,7 +86,7 @@ class ShipPilot2(PhysicsWalker): #self.setupShip() self.setupPhysics(ship) self.ship = ship - + #*# Debug: if not hasattr(ship, "acceleration"): self.ship.acceleration = 60 @@ -204,6 +204,7 @@ class ShipPilot2(PhysicsWalker): cBowSphereNode.addSolid(self.cBowSphere) self.cBowSphereNodePath = self.avatarNodePath.attachNewNode( cBowSphereNode) + #self.cBowSphereNodePath.show() cBowSphereNode.setFromCollideMask(self.cSphereBitMask) cBowSphereNode.setIntoCollideMask(BitMask32.allOff()) @@ -212,7 +213,7 @@ class ShipPilot2(PhysicsWalker): self.pusher.addCollider( self.cBowSphereNodePath, self.avatarNodePath) - + # Back sphere: self.cSternSphere = CollisionSphere( 0.0, self.backSphereOffset, -5.0, avatarRadius) @@ -220,6 +221,7 @@ class ShipPilot2(PhysicsWalker): cSternSphereNode.addSolid(self.cSternSphere) self.cSternSphereNodePath = self.avatarNodePath.attachNewNode( cSternSphereNode) + #self.cSternSphereNodePath.show() self.cSternSphereBitMask = bitmask cSternSphereNode.setFromCollideMask(self.cSphereBitMask) @@ -233,7 +235,7 @@ class ShipPilot2(PhysicsWalker): shipCollWall = self.avatarNodePath.hull.find("**/collision_hull") if not shipCollWall.isEmpty(): shipCollWall.stash() - + def takedownPhysics(self): assert self.debugPrint("takedownPhysics()") if 0: @@ -243,7 +245,7 @@ class ShipPilot2(PhysicsWalker): del self.phys if self.ship != None: self.ship.worldVelocity = Vec3.zero() - + def setupPhysics(self, avatarNodePath): assert self.debugPrint("setupPhysics()") if avatarNodePath is None: @@ -288,7 +290,7 @@ class ShipPilot2(PhysicsWalker): width is feet from port to starboard. length is feet from aft to bow. height is feet from bildge to deck (i.e. not including mast height). - + Set up the avatar collisions """ assert self.debugPrint("initializeCollisions()") @@ -318,7 +320,7 @@ class ShipPilot2(PhysicsWalker): del self.cSphereNodePath del self.pusher - + self.getAirborneHeight = None def setTag(self, key, value): @@ -413,11 +415,11 @@ class ShipPilot2(PhysicsWalker): assert self.debugPrint( "getCollisionsActive() returning=%s"%(self.collisionsActive,)) return self.collisionsActive - + def placeOnFloor(self): """ Make a reasonable effort to place the avatar on the ground. - For example, this is useful when switching away from the + For example, this is useful when switching away from the current walker. """ self.oneTimeCollide() @@ -491,7 +493,7 @@ class ShipPilot2(PhysicsWalker): ## onScreenDebug.add("w keel vec", ## keel.pPrintValues()) if 0: - onScreenDebug.add("posDelta4", + onScreenDebug.add("posDelta4", self.priorParentNp.getRelativeVector( render, self.avatarNodePath.getPosDelta(render)).pPrintValues()) @@ -551,14 +553,14 @@ class ShipPilot2(PhysicsWalker): self.sailsDeployed = -1.0 self.__speed = self.ship.acceleration * self.sailsDeployed else: - self.__speed=(forward and self.ship.acceleration or + self.__speed=(forward and self.ship.acceleration or reverse and -self.ship.reverseAcceleration) avatarSlideSpeed=self.ship.acceleration*0.5 #self.__slideSpeed=slide and ( - # (turnLeft and -avatarSlideSpeed) or + # (turnLeft and -avatarSlideSpeed) or # (turnRight and avatarSlideSpeed)) self.__slideSpeed=(forward or reverse) and ( - (slideLeft and -avatarSlideSpeed) or + (slideLeft and -avatarSlideSpeed) or (slideRight and avatarSlideSpeed)) self.__rotationSpeed=not slide and ( (turnLeft and self.ship.turnRate) or @@ -696,8 +698,8 @@ class ShipPilot2(PhysicsWalker): physVel = physObject.getVelocity() physVelLen = physVel.length() if (physVelLen!=0. - or self.__speed - or self.__slideSpeed + or self.__speed + or self.__slideSpeed or self.__rotationSpeed): distance = dt * self.__speed goForward = True @@ -705,11 +707,11 @@ class ShipPilot2(PhysicsWalker): goForward = False slideDistance = dt * self.__slideSpeed rotation = dt * self.__rotationSpeed - + # update pos: # Take a step in the direction of our previous heading. self.__vel=Vec3( - Vec3.forward() * distance + + Vec3.forward() * distance + Vec3.right() * slideDistance) # rotMat is the rotation matrix corresponding to @@ -740,8 +742,8 @@ class ShipPilot2(PhysicsWalker): assert base.controlForce.getLocalVector() == newVector assert base.controlForce.getPhysicsObject() assert base.controlForce.getPhysicsObject() == physObject - - + + #momentum = self.momentumForce.getLocalVector() #momentum *= 0.9 #self.momentumForce.setVector(momentum) @@ -762,7 +764,7 @@ class ShipPilot2(PhysicsWalker): #base.controlForce.setVector(Vec3.zero()) goForward = True - + #*# speed = physVel if (goForward): @@ -817,28 +819,28 @@ class ShipPilot2(PhysicsWalker): self.ship.worldVelocity.pPrintValues()) onScreenDebug.add("w worldVelocity len", "% 10.4f"%self.ship.worldVelocity.length()) - + # if hasattr(self.ship, 'sailBillow'): # self.ship.sailBillow = self.sailsDeployed if hasattr(self.ship, 'currentTurning'): self.ship.currentTurning = self.currentTurning - + return Task.cont - + def doDeltaPos(self): assert self.debugPrint("doDeltaPos()") self.needToDeltaPos = 1 - + def setPriorParentVector(self): assert self.debugPrint("doDeltaPos()") - + #print "self.__oldDt", self.__oldDt, "self.__oldPosDelta", self.__oldPosDelta if __debug__: onScreenDebug.add("__oldDt", "% 10.4f"%self.__oldDt) onScreenDebug.add("self.__oldPosDelta", self.__oldPosDelta.pPrintValues()) - + velocity = self.__oldPosDelta*(1/self.__oldDt)*4.0 # *4.0 is a hack assert self.debugPrint(" __oldPosDelta=%s"%(self.__oldPosDelta,)) assert self.debugPrint(" velocity=%s"%(velocity,)) @@ -846,7 +848,7 @@ class ShipPilot2(PhysicsWalker): if __debug__: if self.wantDebugIndicator: onScreenDebug.add("velocity", velocity.pPrintValues()) - + def reset(self): assert self.debugPrint("reset()") self.actorNode.getPhysicsObject().resetPosition( diff --git a/direct/src/extensions/NodePath-extensions.py b/direct/src/extensions/NodePath-extensions.py index 467e1d03ce..21c12034e9 100644 --- a/direct/src/extensions/NodePath-extensions.py +++ b/direct/src/extensions/NodePath-extensions.py @@ -34,7 +34,7 @@ else: self.hide() return 0 - + def showSiblings(self): """Show all the siblings of a node path""" for sib in self.getParent().getChildrenAsList(): @@ -108,7 +108,7 @@ from pandac import Point3 v1 = Point3.Point3(0) v2 = Point3.Point3(0) - self.calcTightBounds(v1,v2) + self.calcTightBounds(v1, v2) return v1, v2 def pPrintString(self, other = None): @@ -134,7 +134,7 @@ otherString = '\n' return ( "%s = {"%(self.getName()) + - otherString + + otherString + " 'Pos': (%s),\n" % pos.pPrintValues() + " 'Hpr': (%s),\n" % hpr.pPrintValues() + " 'Scale': (%s),\n" % scale.pPrintValues() + @@ -150,7 +150,7 @@ else: pos = self.getPos() otherString = '' - print (self.getName() + '.setPos(' + otherString + + print (self.getName() + '.setPos(' + otherString + formatString % pos[0] + ', ' + formatString % pos[1] + ', ' + formatString % pos[2] + @@ -165,7 +165,7 @@ else: hpr = self.getHpr() otherString = '' - print (self.getName() + '.setHpr(' + otherString + + print (self.getName() + '.setHpr(' + otherString + formatString % hpr[0] + ', ' + formatString % hpr[1] + ', ' + formatString % hpr[2] + @@ -180,7 +180,7 @@ else: scale = self.getScale() otherString = '' - print (self.getName() + '.setScale(' + otherString + + print (self.getName() + '.setScale(' + otherString + formatString % scale[0] + ', ' + formatString % scale[1] + ', ' + formatString % scale[2] + @@ -197,7 +197,7 @@ pos = self.getPos() hpr = self.getHpr() otherString = '' - print (self.getName() + '.setPosHpr(' + otherString + + print (self.getName() + '.setPosHpr(' + otherString + formatString % pos[0] + ', ' + formatString % pos[1] + ', ' + formatString % pos[2] + ', ' + @@ -219,7 +219,7 @@ hpr = self.getHpr() scale = self.getScale() otherString = '' - print (self.getName() + '.setPosHprScale(' + otherString + + print (self.getName() + '.setPosHprScale(' + otherString + formatString % pos[0] + ', ' + formatString % pos[1] + ', ' + formatString % pos[2] + ', ' + @@ -238,17 +238,17 @@ if other == None: transform = self.getTransform() else: - transform = self.getTransform(other) + transform = self.getTransform(other) if transform.hasPos(): pos = transform.getPos() if not pos.almostEqual(Vec3(0)): outputString = '%s.setPos(%s, %s, %s)' % (name, fmtStr, fmtStr, fmtStr) - print outputString % (pos[0], pos[1], pos[2]) + print outputString % (pos[0], pos[1], pos[2]) if transform.hasHpr(): hpr = transform.getHpr() if not hpr.almostEqual(Vec3(0)): outputString = '%s.setHpr(%s, %s, %s)' % (name, fmtStr, fmtStr, fmtStr) - print outputString % (hpr[0], hpr[1], hpr[2]) + print outputString % (hpr[0], hpr[1], hpr[2]) if transform.hasScale(): if transform.hasUniformScale(): scale = transform.getUniformScale() @@ -265,42 +265,42 @@ child.printTransform(other, sd, fRecursive) def iPos(self, other = None): - """ Set node path's pos to 0,0,0 """ + """ Set node path's pos to 0, 0, 0 """ if other: - self.setPos(other, 0,0,0) + self.setPos(other, 0, 0, 0) else: - self.setPos(0,0,0) + self.setPos(0, 0, 0) def iHpr(self, other = None): - """ Set node path's hpr to 0,0,0 """ + """ Set node path's hpr to 0, 0, 0 """ if other: - self.setHpr(other, 0,0,0) + self.setHpr(other, 0, 0, 0) else: - self.setHpr(0,0,0) + self.setHpr(0, 0, 0) def iScale(self, other = None): - """ SEt node path's scale to 1,1,1 """ + """ SEt node path's scale to 1, 1, 1 """ if other: - self.setScale(other, 1,1,1) + self.setScale(other, 1, 1, 1) else: - self.setScale(1,1,1) + self.setScale(1, 1, 1) def iPosHpr(self, other = None): - """ Set node path's pos and hpr to 0,0,0 """ + """ Set node path's pos and hpr to 0, 0, 0 """ if other: - self.setPosHpr(other,0,0,0,0,0,0) + self.setPosHpr(other, 0, 0, 0, 0, 0, 0) else: - self.setPosHpr(0,0,0,0,0,0) + self.setPosHpr(0, 0, 0, 0, 0, 0) def iPosHprScale(self, other = None): - """ Set node path's pos and hpr to 0,0,0 and scale to 1,1,1 """ + """ Set node path's pos and hpr to 0, 0, 0 and scale to 1, 1, 1 """ if other: - self.setPosHprScale(other, 0,0,0,0,0,0,1,1,1) + self.setPosHprScale(other, 0, 0, 0, 0, 0, 0, 1, 1, 1) else: - self.setPosHprScale(0,0,0,0,0,0,1,1,1) + self.setPosHprScale(0, 0, 0, 0, 0, 0, 1, 1, 1) # private methods - + def __lerp(self, functorFunc, duration, blendType, taskName=None): """ __lerp(self, functorFunc, float, string, string) @@ -313,7 +313,7 @@ from direct.task import Task from direct.showbase import LerpBlendHelpers from direct.task.TaskManagerGlobal import taskMgr - + # upon death remove the functorFunc def lerpUponDeath(task): # Try to break circular references @@ -325,7 +325,7 @@ del task.lerp except: pass - + # make the task function def lerpTaskFunc(task): from pandac.Lerp import Lerp @@ -345,7 +345,7 @@ return(done) else: return(cont) - + # make the lerp task lerpTask = Task.Task(lerpTaskFunc) lerpTask.init = 1 @@ -353,7 +353,7 @@ lerpTask.duration = duration lerpTask.blendType = LerpBlendHelpers.getBlend(blendType) lerpTask.uponDeath = lerpUponDeath - + if (taskName == None): # don't spawn a task, return one instead return lerpTask @@ -394,7 +394,7 @@ # bad args raise Exception("Error: NodePath.lerpColor: bad number of args") - + def lerpColorRGBA(self, r, g, b, a, time, blendType="noBlend", auto=None, task=None): """lerpColorRGBA(self, float, float, float, float, float, @@ -497,7 +497,7 @@ # bad args raise Exception("Error: NodePath.lerpColorScale: bad number of args") - + def lerpColorScaleRGBA(self, r, g, b, a, time, blendType="noBlend", auto=None, task=None): """lerpColorScaleRGBA(self, float, float, float, float, float, @@ -581,7 +581,7 @@ else: return self.__lerp(functorFunc, time, blendType) - + def lerpHpr(self, *posArgs, **keyArgs): """lerpHpr(self, *positionArgs, **keywordArgs) @@ -597,7 +597,7 @@ else: # bad args raise Exception("Error: NodePath.lerpHpr: bad number of args") - + def lerpHprHPR(self, h, p, r, time, other=None, blendType="noBlend", auto=None, task=None, shortest=1): """lerpHprHPR(self, float, float, float, float, string="noBlend", @@ -633,7 +633,7 @@ return self.__lerp(functorFunc, time, blendType, task) else: return self.__lerp(functorFunc, time, blendType) - + def lerpHprVBase3(self, hpr, time, other=None, blendType="noBlend", auto=None, task=None, shortest=1): """lerpHprVBase3(self, VBase3, float, string="noBlend", string=none, @@ -663,7 +663,7 @@ return self.__lerp(functorFunc, time, blendType, task) else: return self.__lerp(functorFunc, time, blendType) - + def lerpPos(self, *posArgs, **keyArgs): """lerpPos(self, *positionArgs, **keywordArgs) @@ -931,7 +931,7 @@ - + def place(self): base.startDirect(fWantTk = 1) from direct.tkpanels import Placer @@ -984,11 +984,11 @@ def posInterval(self, *args, **kw): from direct.interval import LerpInterval return LerpInterval.LerpPosInterval(self, *args, **kw) - + def hprInterval(self, *args, **kw): from direct.interval import LerpInterval return LerpInterval.LerpHprInterval(self, *args, **kw) - + def quatInterval(self, *args, **kw): from direct.interval import LerpInterval return LerpInterval.LerpQuatInterval(self, *args, **kw) @@ -1041,10 +1041,10 @@ from direct.interval import LerpInterval return LerpInterval.LerpColorScaleInterval(self, *args, **kw) - def attachCollisionSphere(self, name, cx,cy,cz,r, fromCollide, intoCollide): + def attachCollisionSphere(self, name, cx, cy, cz, r, fromCollide, intoCollide): from pandac import CollisionSphere from pandac import CollisionNode - coll = CollisionSphere.CollisionSphere(cx,cy,cz,r) + coll = CollisionSphere.CollisionSphere(cx, cy, cz, r) collNode = CollisionNode.CollisionNode(name) collNode.addSolid(coll) collNode.setFromCollideMask(fromCollide) @@ -1052,10 +1052,10 @@ collNodePath = self.attachNewNode(collNode) return collNodePath - def attachCollisionSegment(self, name, ax,ay,az, bx,by,bz, fromCollide, intoCollide): + def attachCollisionSegment(self, name, ax, ay, az, bx, by, bz, fromCollide, intoCollide): from pandac import CollisionSegment from pandac import CollisionNode - coll = CollisionSegment.CollisionSegment(ax,ay,az, bx,by,bz) + coll = CollisionSegment.CollisionSegment(ax, ay, az, bx, by, bz) collNode = CollisionNode.CollisionNode(name) collNode.addSolid(coll) collNode.setFromCollideMask(fromCollide) @@ -1063,10 +1063,10 @@ collNodePath = self.attachNewNode(collNode) return collNodePath - def attachCollisionRay(self, name, ox,oy,oz, dx,dy,dz, fromCollide, intoCollide): + def attachCollisionRay(self, name, ox, oy, oz, dx, dy, dz, fromCollide, intoCollide): from pandac import CollisionRay from pandac import CollisionNode - coll = CollisionRay.CollisionRay(ox,oy,oz, dx,dy,dz) + coll = CollisionRay.CollisionRay(ox, oy, oz, dx, dy, dz) collNode = CollisionNode.CollisionNode(name) collNode.addSolid(coll) collNode.setFromCollideMask(fromCollide) diff --git a/direct/src/extensions/VBase3-extensions.py b/direct/src/extensions/VBase3-extensions.py index 98be9f59c3..750a59e6ba 100755 --- a/direct/src/extensions/VBase3-extensions.py +++ b/direct/src/extensions/VBase3-extensions.py @@ -5,11 +5,11 @@ """ def __repr__(self): - return '%s(%s,%s,%s)' % ( - self.__class__.__name__,self[0],self[1],self[2]) + return '%s(%s, %s, %s)' % ( + self.__class__.__name__, self[0], self[1], self[2]) def pPrintValues(self): """ Pretty print """ - return "% 10.4f, % 10.4f, % 10.4f" % (self[0],self[1],self[2]) + return "% 10.4f, % 10.4f, % 10.4f" % (self[0], self[1], self[2]) diff --git a/direct/src/extensions/VBase4-extensions.py b/direct/src/extensions/VBase4-extensions.py index da9d9b6502..e70504c3ea 100755 --- a/direct/src/extensions/VBase4-extensions.py +++ b/direct/src/extensions/VBase4-extensions.py @@ -5,11 +5,11 @@ """ def __repr__(self): - return '%s(%s,%s,%s,%s)' % ( - self.__class__.__name__,self[0],self[1],self[2],self[3]) + return '%s(%s, %s, %s, %s)' % ( + self.__class__.__name__, self[0], self[1], self[2], self[3]) def pPrintValues(self): """ Pretty print """ - return '% 10.4f, % 10.4f, % 10.4f, % 10.4f' % (self[0],self[1],self[2],self[3]) + return '% 10.4f, % 10.4f, % 10.4f, % 10.4f' % (self[0], self[1], self[2], self[3])