Example #1
0
    def collideSegment(self, startPoint, endPoint, skipGun = False):
        if not segmentMayHitVehicle(self.typeDescriptor, startPoint, endPoint, self.position):
            return

        worldToVehMatrix = Math.Matrix(self.model.matrix)
        worldToVehMatrix.invert()
        startPoint = worldToVehMatrix.applyPoint(startPoint)
        endPoint = worldToVehMatrix.applyPoint(endPoint)
        res = None
        for compDescr, compMatrix in self.getComponents():
            if skipGun and compDescr.get('itemTypeName') == 'vehicleGun':
                continue
            collisions = compDescr['hitTester'].localHitTest(compMatrix.applyPoint(startPoint), compMatrix.applyPoint(endPoint))
            if collisions is None:
                continue
            for dist, _, hitAngleCos, matKind in collisions:
                if res is None or res[0] >= dist:
                    matInfo = compDescr['materials'].get(matKind)
                    res = (dist, hitAngleCos, matInfo.armor if matInfo is not None else 0)
        return res
Example #2
0
    def collideSegment(self, startPoint, endPoint, skipGun = False):
        if not segmentMayHitVehicle(self.typeDescriptor, startPoint, endPoint, self.position):
            return

        worldToVehMatrix = Math.Matrix(self.model.matrix)
        worldToVehMatrix.invert()
        startPoint = worldToVehMatrix.applyPoint(startPoint)
        endPoint = worldToVehMatrix.applyPoint(endPoint)
        res = None
        for compDescr, compMatrix in self.getComponents():
            if skipGun and compDescr.get('itemTypeName') == 'vehicleGun':
                continue
            collisions = compDescr['hitTester'].localHitTest(compMatrix.applyPoint(startPoint), compMatrix.applyPoint(endPoint))
            if collisions is None:
                continue
            for dist, _, hitAngleCos, matKind in collisions:
                if res is None or res[0] >= dist:
                    matInfo = compDescr['materials'].get(matKind)
                    res = (dist, hitAngleCos, matInfo.armor if matInfo is not None else 0)
        return res
Example #3
0
 def segmentMayHitVehicle(self, startPoint, endPoint):
     return segmentMayHitVehicle(self.typeDescriptor, startPoint, endPoint, self.position)
 def segmentMayHitVehicle(self, startPoint, endPoint):
     return segmentMayHitVehicle(self.typeDescriptor, startPoint, endPoint,
                                 self.position)
    def __getGunMarkerPosition(self, shotPos, shotVec, dispersionAngle):
        shotDescr = self.__avatar.vehicleTypeDescriptor.shot
        gravity = Math.Vector3(0.0, -shotDescr['gravity'], 0.0)
        maxDist = shotDescr['maxDistance']
        vehicles = []
        testStartPoint = shotPos
        testEndPoint = shotPos + shotVec * 10000.0
        for vehicleID in BigWorld.player().arena.vehicles.iterkeys():
            if vehicleID == self.__avatar.playerVehicleID:
                continue
            vehicle = BigWorld.entity(vehicleID)
            if vehicle is None or not vehicle.isStarted:
                continue
            if segmentMayHitVehicle(vehicle.typeDescriptor, testStartPoint,
                                    testEndPoint, vehicle.position):
                vehicles.append(vehicle)

        prevPos = shotPos
        prevVelocity = shotVec
        dt = 0.0
        maxDistCheckFlag = False
        while True:
            dt += SERVER_TICK_LENGTH
            checkPoints = computeProjectileTrajectory(
                prevPos, prevVelocity, gravity, SERVER_TICK_LENGTH,
                SHELL_TRAJECTORY_EPSILON_CLIENT)
            prevCheckPoint = prevPos
            bBreak = False
            for curCheckPoint in checkPoints:
                testRes = collideVehiclesAndStaticScene(
                    prevCheckPoint, curCheckPoint, vehicles)
                if testRes is not None:
                    collData = testRes[1]
                    dir = testRes[0] - prevCheckPoint
                    endPos = testRes[0]
                    bBreak = True
                    break
                pos = self.__avatar.arena.collideWithSpaceBB(
                    prevCheckPoint, curCheckPoint)
                if pos is not None:
                    collData = None
                    maxDistCheckFlag = True
                    dir = pos - prevCheckPoint
                    endPos = pos
                    bBreak = True
                    break
                prevCheckPoint = curCheckPoint

            if bBreak:
                break
            prevPos = shotPos + shotVec.scale(dt) + gravity.scale(
                dt * dt * 0.5)
            prevVelocity = shotVec + gravity.scale(dt)

        dir.normalise()
        distance = (endPos - shotPos).length
        markerDiameter = 2.0 * distance * dispersionAngle
        if maxDistCheckFlag:
            if endPos.distTo(shotPos) >= maxDist:
                dir = endPos - shotPos
                dir.normalise()
                endPos = shotPos + dir.scale(maxDist)
                distance = maxDist
                markerDiameter = 2.0 * distance * dispersionAngle
        replayCtrl = BattleReplay.g_replayCtrl
        if replayCtrl.isPlaying and replayCtrl.isClientReady:
            markerDiameter, endPos, dir = replayCtrl.getGunMarkerParams(
                endPos, dir)
        elif replayCtrl.isRecording:
            replayCtrl.setGunMarkerParams(markerDiameter, endPos, dir)
        return (endPos, dir, markerDiameter, collData)
    def __getGunMarkerPosition(self, shotPos, shotVec, dispersionAngle):
        shotDescr = self.__avatar.vehicleTypeDescriptor.shot
        gravity = Math.Vector3(0.0, -shotDescr["gravity"], 0.0)
        maxDist = shotDescr["maxDistance"]
        vehicles = []
        testStartPoint = shotPos
        testEndPoint = shotPos + shotVec * 10000.0
        for vehicleID in BigWorld.player().arena.vehicles.iterkeys():
            if vehicleID == self.__avatar.playerVehicleID:
                continue
            vehicle = BigWorld.entity(vehicleID)
            if vehicle is None or not vehicle.isStarted:
                continue
            if segmentMayHitVehicle(vehicle.typeDescriptor, testStartPoint, testEndPoint, vehicle.position):
                vehicles.append(vehicle)

        prevPos = shotPos
        prevVelocity = shotVec
        dt = 0.0
        maxDistCheckFlag = False
        while True:
            dt += SERVER_TICK_LENGTH
            checkPoints = computeProjectileTrajectory(
                prevPos, prevVelocity, gravity, SERVER_TICK_LENGTH, SHELL_TRAJECTORY_EPSILON_CLIENT
            )
            prevCheckPoint = prevPos
            bBreak = False
            for curCheckPoint in checkPoints:
                testRes = collideVehiclesAndStaticScene(prevCheckPoint, curCheckPoint, vehicles)
                if testRes is not None:
                    collData = testRes[1]
                    dir = testRes[0] - prevCheckPoint
                    endPos = testRes[0]
                    bBreak = True
                    break
                pos = self.__avatar.arena.collideWithSpaceBB(prevCheckPoint, curCheckPoint)
                if pos is not None:
                    collData = None
                    maxDistCheckFlag = True
                    dir = pos - prevCheckPoint
                    endPos = pos
                    bBreak = True
                    break
                prevCheckPoint = curCheckPoint

            if bBreak:
                break
            prevPos = shotPos + shotVec.scale(dt) + gravity.scale(dt * dt * 0.5)
            prevVelocity = shotVec + gravity.scale(dt)

        dir.normalise()
        distance = (endPos - shotPos).length
        markerDiameter = 2.0 * distance * dispersionAngle
        if maxDistCheckFlag:
            if endPos.distTo(shotPos) >= maxDist:
                dir = endPos - shotPos
                dir.normalise()
                endPos = shotPos + dir.scale(maxDist)
                distance = maxDist
                markerDiameter = 2.0 * distance * dispersionAngle
        replayCtrl = BattleReplay.g_replayCtrl
        if replayCtrl.isPlaying and replayCtrl.isClientReady:
            markerDiameter, endPos, dir = replayCtrl.getGunMarkerParams(endPos, dir)
        elif replayCtrl.isRecording:
            replayCtrl.setGunMarkerParams(markerDiameter, endPos, dir)
        return (endPos, dir, markerDiameter, collData)