golf: update physics simulations
This commit is contained in:
parent
efc2147ad0
commit
f73acc5598
2 changed files with 22 additions and 19 deletions
|
@ -209,7 +209,7 @@ class GolfHoleBase:
|
|||
frameCount = 0
|
||||
lift = 0
|
||||
startTime = GolfGlobals.BALL_CONTACT_FRAME / 24
|
||||
startFrame = startTime * self.FPS
|
||||
startFrame = int(startTime * self.FPS)
|
||||
for frame in range(startFrame):
|
||||
self.simulate()
|
||||
self.setTimeIntoCycle(self.swingTime + float(frameCount) * self.DTAStep)
|
||||
|
@ -334,14 +334,13 @@ class GolfHoleBase:
|
|||
self.ballRayBody.setPosition(bp[0], bp[1], bp[2])
|
||||
self.skyRay.setPosition(bp[0], bp[1], 50.0)
|
||||
|
||||
def getOrderedContacts(self, count):
|
||||
c0 = self.space.getContactId(count, 0)
|
||||
c1 = self.space.getContactId(count, 1)
|
||||
def getOrderedContacts(self, entry):
|
||||
c0 = self.space.getCollideId(entry.getGeom1())
|
||||
c1 = self.space.getCollideId(entry.getGeom2())
|
||||
if c0 > c1:
|
||||
chold = c1
|
||||
c1 = c0
|
||||
c0 = chold
|
||||
return (c0, c1)
|
||||
return c1, c0
|
||||
else:
|
||||
return c0, c1
|
||||
|
||||
def postStep(self):
|
||||
if self.canRender:
|
||||
|
@ -352,11 +351,9 @@ class GolfHoleBase:
|
|||
skyRayHitPos = None
|
||||
ballRayHitPos = None
|
||||
bp = self.curGolfBall().getPosition()
|
||||
for count in range(self.colCount):
|
||||
c0, c1 = self.getOrderedContacts(count)
|
||||
x = self.space.getContactData(count * 3 + 0)
|
||||
y = self.space.getContactData(count * 3 + 1)
|
||||
z = self.space.getContactData(count * 3 + 2)
|
||||
for entry in self.colEntries:
|
||||
c0, c1 = self.getOrderedContacts(entry)
|
||||
x, y, z = entry.getContactPoint(0)
|
||||
if c0 == GolfGlobals.OOB_RAY_COLLIDE_ID or c1 == GolfGlobals.OOB_RAY_COLLIDE_ID:
|
||||
rayCount += 1
|
||||
if self.canRender:
|
||||
|
@ -382,10 +379,9 @@ class GolfHoleBase:
|
|||
self.greenIn = self.frame
|
||||
self.llv = self.curGolfBall().getLinearVel()
|
||||
elif GolfGlobals.BALL_COLLIDE_ID in [c0, c1] and GolfGlobals.HOLE_CUP_COLLIDE_ID in [c0, c1]:
|
||||
zCon = self.space.getContactData(count * 3 + 2)
|
||||
self.ballTouchedHoleFrame = self.frame
|
||||
ballUndersideZ = self.curGolfBall().getPosition()[2] - 0.05
|
||||
if zCon < ballUndersideZ:
|
||||
if z < ballUndersideZ:
|
||||
if not self.ballInHoleFrame:
|
||||
self.ballInHoleFrame = self.frame
|
||||
if self.ballFirstTouchedHoleFrame < self.ballLastTouchedGrass:
|
||||
|
@ -406,9 +402,6 @@ class GolfHoleBase:
|
|||
self.ballLastTouchedGrass = self.frame
|
||||
elif self.canRender:
|
||||
if c0 == GolfGlobals.TOON_RAY_COLLIDE_ID or c1 == GolfGlobals.TOON_RAY_COLLIDE_ID:
|
||||
x = self.space.getContactData(count * 3 + 0)
|
||||
y = self.space.getContactData(count * 3 + 1)
|
||||
z = self.space.getContactData(count * 3 + 2)
|
||||
self.toonRayCollisionCallback(x, y, z)
|
||||
if GolfGlobals.CAMERA_RAY_COLLIDE_ID in [c0, c1] and GolfGlobals.WINDMILL_BASE_COLLIDE_ID in [c0, c1]:
|
||||
self.translucentCurFrame.append(self.windmillFanNodePath)
|
||||
|
|
|
@ -60,6 +60,9 @@ class PhysicsWorldBase:
|
|||
self.refFPS = 60.0
|
||||
self.DTAStep = 1.0 / self.FPS
|
||||
self.refCon = 1.2
|
||||
self.collisionEventName = 'ode-collision-%s' % id(self)
|
||||
self.space.setCollisionEvent(self.collisionEventName)
|
||||
self.accept(self.collisionEventName, self.__handleCollision)
|
||||
|
||||
def delete(self):
|
||||
self.notify.debug('Max Collision Count was %s' % self.maxColCount)
|
||||
|
@ -106,6 +109,7 @@ class PhysicsWorldBase:
|
|||
self.space.destroy()
|
||||
self.world = None
|
||||
self.space = None
|
||||
self.ignore(self.collisionEventName)
|
||||
return
|
||||
|
||||
def setupSimulation(self):
|
||||
|
@ -194,8 +198,14 @@ class PhysicsWorldBase:
|
|||
endTime = globalClock.getRealTime() - startTime
|
||||
return task.cont
|
||||
|
||||
def __handleCollision(self, entry):
|
||||
self.colEntries.append(entry)
|
||||
|
||||
def simulate(self):
|
||||
self.colCount = self.space.autoCollide()
|
||||
self.colEntries = []
|
||||
self.space.autoCollide()
|
||||
eventMgr.doEvents()
|
||||
self.colCount = len(self.colEntries)
|
||||
if self.maxColCount < self.colCount:
|
||||
self.maxColCount = self.colCount
|
||||
self.notify.debug('New Max Collision Count %s' % self.maxColCount)
|
||||
|
|
Loading…
Reference in a new issue