def handleToonExited(self, toonId): DistributedPartyTeamActivity.handleToonExited(self, toonId) if toonId == base.localAvatar.doId: self.cameraMoveIval.pause() if toonId not in self.fallenToons: if toonId in self.toonIdsToAnimIntervals and self.toonIdsToAnimIntervals[ toonId] is not None: self.toonIdsToAnimIntervals[toonId].finish() toon = self.getAvatar(toonId) targetH = fitDestAngle2Src(toon.getH(self.root), 180.0) targetPos = self.hopOffPositions[self.getTeam(toonId)][ self.getIndex(toonId, self.getTeam(toonId))] hopOffAnim = Sequence( Func(toon.startPosHprBroadcast, 0.1), toon.hprInterval(0.2, VBase3(targetH, 0.0, 0.0), other=self.root), Func(toon.b_setAnimState, 'jump', 1.0), Wait(0.4), PartyUtils.arcPosInterval(0.75, toon, targetPos, 5.0, self.root), Func(toon.stopPosHprBroadcast), Func(toon.sendCurrentPosition), Func(self.hopOffFinished, toonId)) self.toonIdsToAnimIntervals[toonId] = hopOffAnim self._hopOffFinishedSV.set(False) self.toonIdsToAnimIntervals[toonId].start() else: self._hopOffFinishedSV.set(True) del self.toonIdsToAnimIntervals[toonId] return
def handleToonExited(self, toonId): DistributedPartyTeamActivity.handleToonExited(self, toonId) # clean up local toon stuff if toonId == base.localAvatar.doId: self.cameraMoveIval.pause() # make toon jump off the dock if needed if toonId not in self.fallenToons: # finish any existing interval for that toon if toonId in self.toonIdsToAnimIntervals and \ self.toonIdsToAnimIntervals[toonId] is not None: self.toonIdsToAnimIntervals[toonId].finish() toon = self.getAvatar(toonId) # clamp targetHeading to minimize spin targetH = fitDestAngle2Src(toon.getH(self.root), 180.0) targetPos = self.hopOffPositions[self.getTeam(toonId)][self.getIndex(toonId, self.getTeam(toonId))] hopOffAnim = Sequence( Func( toon.startPosHprBroadcast, 0.1 ), toon.hprInterval( 0.2, VBase3( targetH, 0.0, 0.0 ), other=self.root ), Func( toon.b_setAnimState, "jump", 1.0 ), Wait( 0.4 ), PartyUtils.arcPosInterval( 0.75, toon, targetPos, 5.0, self.root ), Func( toon.stopPosHprBroadcast ), # make sure toon ends up on the ground on remote clients Func( toon.sendCurrentPosition ), Func( self.hopOffFinished, toonId ), ) self.toonIdsToAnimIntervals[toonId] = hopOffAnim self._hopOffFinishedSV.set(False) self.toonIdsToAnimIntervals[toonId].start() # local toons not on the dock are put back into the walk state else: self._hopOffFinishedSV.set(True) del self.toonIdsToAnimIntervals[toonId]
def handleToonExited(self, toonId): DistributedPartyTeamActivity.handleToonExited(self, toonId) if toonId == base.localAvatar.doId: self.cameraMoveIval.pause() if toonId not in self.fallenToons: if toonId in self.toonIdsToAnimIntervals and self.toonIdsToAnimIntervals[toonId] is not None: self.toonIdsToAnimIntervals[toonId].finish() toon = self.getAvatar(toonId) targetH = fitDestAngle2Src(toon.getH(self.root), 180.0) targetPos = self.hopOffPositions[self.getTeam(toonId)][self.getIndex(toonId, self.getTeam(toonId))] hopOffAnim = Sequence( Func(toon.startPosHprBroadcast, 0.1), toon.hprInterval(0.2, VBase3(targetH, 0.0, 0.0), other=self.root), Func(toon.b_setAnimState, "jump", 1.0), Wait(0.4), PartyUtils.arcPosInterval(0.75, toon, targetPos, 5.0, self.root), Func(toon.stopPosHprBroadcast), Func(toon.sendCurrentPosition), Func(self.hopOffFinished, toonId), ) self.toonIdsToAnimIntervals[toonId] = hopOffAnim self._hopOffFinishedSV.set(False) self.toonIdsToAnimIntervals[toonId].start() else: self._hopOffFinishedSV.set(True) del self.toonIdsToAnimIntervals[toonId] return
def handleToonJoined(self, toonId): DistributedPartyTeamActivity.handleToonJoined(self, toonId) self.toonIdsToAnimIntervals[toonId] = None if toonId == base.localAvatar.doId: base.cr.playGame.getPlace().fsm.request("activity") camera.wrtReparentTo(self.root) self.cameraMoveIval = LerpPosHprInterval( camera, 1.5, PartyGlobals.TugOfWarCameraPos, PartyGlobals.TugOfWarCameraInitialHpr, other=self.root ) self.cameraMoveIval.start() self.localToonPosIndex = self.getIndex(base.localAvatar.doId, self.localToonTeam) self.notify.debug("posIndex: %d" % self.localToonPosIndex) toon = self.getAvatar(toonId) targetPos = self.dockPositions[self.localToonTeam][self.localToonPosIndex] if toon.getZ(self.root) < PartyGlobals.TugOfWarToonPositionZ: toon.setZ(self.root, PartyGlobals.TugOfWarToonPositionZ) targetH = fitDestAngle2Src(toon.getH(self.root), PartyGlobals.TugOfWarHeadings[self.localToonTeam]) travelVector = targetPos - toon.getPos(self.root) duration = travelVector.length() / 5.0 if self.toonIdsToAnimIntervals[toonId] is not None: self.toonIdsToAnimIntervals[toonId].finish() self.toonIdsToAnimIntervals[toonId] = Sequence( Func(toon.startPosHprBroadcast, 0.1), Func(toon.b_setAnimState, "run"), LerpPosHprInterval(toon, duration, targetPos, VBase3(targetH, 0.0, 0.0), other=self.root), Func(toon.stopPosHprBroadcast), Func(toon.b_setAnimState, "neutral"), ) self.toonIdsToAnimIntervals[toonId].start() return
def adjust_angle(self,angle,dt): targetH = angle oldH = self.getH() targetH = fitDestAngle2Src(oldH,targetH) magnitude = abs(targetH-oldH)+90.0 if magnitude>92.5: if (targetH-oldH)<0: self.setH((self.getH()-(magnitude*2.5*dt))%360) else: self.setH((self.getH()+(magnitude*2.5*dt))%360) else: self.setH((self.getH()+(targetH-oldH))%360)
def adjust_angle(self,angle,dt): targetH = angle oldH = self.collNP.getH() targetH = fitDestAngle2Src(oldH,targetH) magnitude = abs(targetH-oldH)+90.0 if magnitude>92.5: if (targetH-oldH)<0: self.collNP.setH((self.collNP.getH()-(magnitude*2.5*dt))%360) else: self.collNP.setH((self.collNP.getH()+(magnitude*2.5*dt))%360) else: self.collNP.setH((self.collNP.getH()+(targetH-oldH))%360)
def updateRotation(self, dt): oldH = self.head.getH() self.head.headsUp(self.destinationNode) newH = self.head.getH() self.head.setH(oldH) newH = fitDestAngle2Src(oldH, newH) if newH - oldH < 0.0: change = -dt * 90.0 else: change = dt * 90.0 if abs(newH - oldH) < abs(change): self.head.setH(newH) self.destinationNode.setPos(self.head, 0, 1, 0) else: self.head.setH(self.head.getH() + change)
def handleToonJoined(self, toonId): DistributedPartyTeamActivity.handleToonJoined(self, toonId) self.toonIdsToAnimIntervals[toonId] = None if toonId == base.localAvatar.doId: base.cr.playGame.getPlace().fsm.request("activity") # set camera to a 3rd person view of play area camera.wrtReparentTo(self.root) self.cameraMoveIval = LerpPosHprInterval( camera, 1.5, PartyGlobals.TugOfWarCameraPos, PartyGlobals.TugOfWarCameraInitialHpr, other=self.root, ) self.cameraMoveIval.start() self.localToonPosIndex = self.getIndex(base.localAvatar.doId, self.localToonTeam) self.notify.debug("posIndex: %d" % self.localToonPosIndex) toon = self.getAvatar(toonId) targetPos = self.dockPositions[self.localToonTeam][ self.localToonPosIndex] # prevent toons from clipping through the dock by warping them to dock height if toon.getZ(self.root) < PartyGlobals.TugOfWarToonPositionZ: toon.setZ(self.root, PartyGlobals.TugOfWarToonPositionZ) targetH = fitDestAngle2Src( toon.getH(self.root), PartyGlobals.TugOfWarHeadings[self.localToonTeam]) travelVector = targetPos - toon.getPos(self.root) duration = travelVector.length() / 5.0 if self.toonIdsToAnimIntervals[toonId] is not None: self.toonIdsToAnimIntervals[toonId].finish() self.toonIdsToAnimIntervals[toonId] = Sequence( Func(toon.startPosHprBroadcast, 0.1), Func(toon.b_setAnimState, "run"), LerpPosHprInterval(toon, duration, targetPos, VBase3(targetH, 0.0, 0.0), other=self.root), Func(toon.stopPosHprBroadcast), Func(toon.b_setAnimState, "neutral"), ) self.toonIdsToAnimIntervals[toonId].start()
def handleToonJoined(self, toonId): DistributedPartyTeamActivity.handleToonJoined(self, toonId) self.toonIdsToAnimIntervals[toonId] = None if toonId == base.localAvatar.doId: base.cr.playGame.getPlace().fsm.request('activity') camera.wrtReparentTo(self.root) self.cameraMoveIval = LerpPosHprInterval( camera, 1.5, PartyGlobals.TugOfWarCameraPos, PartyGlobals.TugOfWarCameraInitialHpr, other=self.root) self.cameraMoveIval.start() self.localToonPosIndex = self.getIndex(base.localAvatar.doId, self.localToonTeam) self.notify.debug('posIndex: %d' % self.localToonPosIndex) toon = self.getAvatar(toonId) targetPos = self.dockPositions[self.localToonTeam][ self.localToonPosIndex] if toon.getZ(self.root) < PartyGlobals.TugOfWarToonPositionZ: toon.setZ(self.root, PartyGlobals.TugOfWarToonPositionZ) targetH = fitDestAngle2Src( toon.getH(self.root), PartyGlobals.TugOfWarHeadings[self.localToonTeam]) travelVector = targetPos - toon.getPos(self.root) duration = travelVector.length() / 5.0 if self.toonIdsToAnimIntervals[toonId] is not None: self.toonIdsToAnimIntervals[toonId].finish() self.toonIdsToAnimIntervals[toonId] = Sequence( Func(toon.startPosHprBroadcast, 0.1), Func(toon.b_setAnimState, 'run'), LerpPosHprInterval(toon, duration, targetPos, VBase3(targetH, 0.0, 0.0), other=self.root), Func(toon.stopPosHprBroadcast), Func(toon.b_setAnimState, 'neutral')) self.toonIdsToAnimIntervals[toonId].start() return
def SetupModel(self, VUTProject): source = osr.SpatialReference() source.ImportFromEPSG(4326) target = osr.SpatialReference() target.ImportFromEPSG(int(self.OutEPSG)) transform = osr.CoordinateTransformation(source, target) BBxMin = float(self.VRTBoundingBox.split(':')[0].split(',')[0]) BByMin = float(self.VRTBoundingBox.split(':')[0].split(',')[1]) BBxMax = float(self.VRTBoundingBox.split(':')[1].split(',')[0]) BByMax = float(self.VRTBoundingBox.split(':')[1].split(',')[1]) XLenght = BBxMax - BBxMin YLenght = BByMax - BByMin NewBBxMax = BBxMax + XLenght / 2 NewBBxMin = BBxMin - XLenght / 2 NewBByMax = BByMax + YLenght / 2 NewBByMin = BByMin - YLenght / 2 pointMax = ogr.Geometry(ogr.wkbPoint) pointMax.AddPoint(NewBBxMax, NewBByMax) pointMax.Transform(transform) pointMin = ogr.Geometry(ogr.wkbPoint) pointMin.AddPoint(NewBBxMin, NewBByMin) pointMin.Transform(transform) self.BoundingBoxStr = '-te ' + str(pointMin.GetX()) + ' ' + str( pointMin.GetY()) + ' ' + str(pointMax.GetX()) + ' ' + str( pointMax.GetY()) + ' ' self.Moves = Sequence() Line = LineSegs('Path') with open(VUTProject, 'r') as File: Counter = 0 i = 0 PrevCourse = None PrevPos = None PrevHPr = None for line in File: if Counter < 6: pass else: line = line.split() lat = float(line[0]) lon = float(line[1]) ele = float(line[2]) course = float(line[4]) pitch = float(line[5]) roll = float(line[6]) if course < 180: course = -course elif course > 180: course = abs(course - 360) point = ogr.Geometry(ogr.wkbPoint) point.AddPoint(lon, lat) point.Transform(transform) if i == 0: FirstPos = (point.GetX() - self.Origin[0], point.GetY() - self.Origin[1], ele) FirstHpr = (course, pitch, roll) self.cam.setPos(FirstPos) self.cam.setHpr(FirstHpr) Line.move_to(point.GetX() - self.Origin[0], point.GetY() - self.Origin[1], ele) elif i == 1: self.Moves.append( LerpPosHprInterval( self.cam, 1, (point.GetX() - self.Origin[0], point.GetY() - self.Origin[1], ele), (fitDestAngle2Src(PrevCourse, course), pitch, roll), startPos=FirstPos, startHpr=FirstHpr, name='Interval', other=self.render)) Line.draw_to(point.GetX() - self.Origin[0], point.GetY() - self.Origin[1], ele) else: self.Moves.append( LerpPosHprInterval( self.cam, 1, (point.GetX() - self.Origin[0], point.GetY() - self.Origin[1], ele), (fitDestAngle2Src(PrevCourse, course), pitch, roll), startPos=PrevPos, startHpr=PrevHPr, name='Interval', other=self.render)) Line.draw_to(point.GetX() - self.Origin[0], point.GetY() - self.Origin[1], ele) i = i + 1 PrevCourse = course PrevPos = (point.GetX() - self.Origin[0], point.GetY() - self.Origin[1], ele) PrevHPr = (course, pitch, roll) Counter = Counter + 1 Line.setColor(1, 0.5, 0.5, 1) Line.setThickness(3) node = Line.create(False) nodePath = self.render.attachNewNode(node)