def collideSegment(self, startPoint, endPoint, skipGun=False): res = None filterMethod = getattr(self.filter, 'segmentMayHitEntity', lambda: True) if not filterMethod(startPoint, endPoint, 0): return res else: matricesToCheck = [Matrix(self.model.matrix)] if not skipGun: matricesToCheck.append( Matrix(self.model.node(TankPartNames.GUN))) for matrix, desc in zip(matricesToCheck, self.__componentsDesc): toModel = matrix toModel.invert() collisions = desc.hitTester.localHitTest( toModel.applyPoint(startPoint), toModel.applyPoint(endPoint)) if collisions is None: continue for dist, _, hitAngleCos, matKind in collisions: if res is None or res.dist >= dist: matInfo = desc.materials.get(matKind) res = SegmentCollisionResult( dist, hitAngleCos, matInfo.armor if matInfo is not None else 0) return res
def collideSegment(self, startPoint, endPoint, skipGun=False): 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.itemTypeName == 'vehicleGun': continue hitTester = compDescr.hitTester if not hitTester.isBspModelLoaded(): hitTester.loadBspModel() collisions = 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 = SegmentCollisionResult( dist, hitAngleCos, matInfo.armor if matInfo is not None else 0) return res
def collideSegment(self, startPoint, endPoint, skipGun=False): filterMethod = getattr(self.filter, 'segmentMayHitEntity', self.segmentMayHitVehicle) if not filterMethod(startPoint, endPoint, 0): return else: worldToVehMatrix = Math.Matrix(self.model.matrix) worldToVehMatrix.invert() startPoint = worldToVehMatrix.applyPoint(startPoint) endPoint = worldToVehMatrix.applyPoint(endPoint) res = None for compDescr, compMatrix, isAttached in self.getComponents(): if not isAttached: continue 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 = SegmentCollisionResult( dist, hitAngleCos, matInfo.armor if matInfo is not None else 0) return res
def collideSegment(self, startPoint, endPoint, skipGun = False): worldToVehMatrix = Math.Matrix(self.model.matrix) worldToVehMatrix.invert() startPoint = worldToVehMatrix.applyPoint(startPoint) endPoint = worldToVehMatrix.applyPoint(endPoint) res = None collisions = self.__bspModel.collideSegment(startPoint, endPoint) if collisions is None: return res for dist, _, hitAngleCos, _ in collisions: if res is None or res[0] >= dist: res = SegmentCollisionResult(dist, hitAngleCos, 0) return res
def __collideSegment(self, startPoint, endPoint, skipGun=False, onlyNearest=False): filterMethod = getattr(self.filter, 'segmentMayHitEntity', self.segmentMayHitVehicle) if not filterMethod(startPoint, endPoint, 0): return else: res = [] worldToVehMatrix = Math.Matrix(self.model.matrix) worldToVehMatrix.invert() startPoint = worldToVehMatrix.applyPoint(startPoint) endPoint = worldToVehMatrix.applyPoint(endPoint) for compDescr, compMatrix, isAttached in self.getComponents(): if not isAttached: continue if skipGun and compDescr.itemTypeName == 'vehicleGun': continue collisions = compDescr.hitTester.localHitTest( compMatrix.applyPoint(startPoint), compMatrix.applyPoint(endPoint)) if collisions is None: continue for dist, _, hitAngleCos, matKind in collisions: matInfo = compDescr.materials.get(matKind) if onlyNearest: if not res or res and res[-1][0] >= dist: res.append( SegmentCollisionResult( dist, hitAngleCos, matInfo.armor if matInfo is not None else 0)) else: res.append( SegmentCollisionResultExt(dist, hitAngleCos, matInfo, compDescr.itemTypeName)) return res
def collideSegment(self, startPoint, endPoint, skipGun=False): res = None filterMethod = getattr(self.filter, 'segmentMayHitEntity', lambda: True) if not filterMethod(startPoint, endPoint, 0): return res modelsToCheck = (self.model, ) if skipGun else (self.model, self.__gunModel) for model, desc in zip(modelsToCheck, self.__componentsDesc): toModel = Matrix(model.matrix) toModel.invert() collisions = desc['hitTester'].localHitTest( toModel.applyPoint(startPoint), toModel.applyPoint(endPoint)) if collisions is None: continue for dist, _, hitAngleCos, matKind in collisions: if res is None or res.dist >= dist: matInfo = desc['materials'].get(matKind) res = SegmentCollisionResult( dist, hitAngleCos, matInfo.armor if matInfo is not None else 0) return res
def collideSegment(self, startPoint, endPoint, skipGun = False, optimized = True): filterMethod = getattr(self.filter, 'segmentMayHitEntity', self.segmentMayHitVehicle) if not filterMethod(startPoint, endPoint, 0): return else: res = None if optimized: worldToVehMatrix = Math.Matrix(self.model.matrix) worldToVehMatrix.invert() startPoint = worldToVehMatrix.applyPoint(startPoint) endPoint = worldToVehMatrix.applyPoint(endPoint) vehicleDescr = self.typeDescriptor chassis = vehicleDescr.chassis hull = vehicleDescr.hull compMatrix = Math.Matrix() compMatrix.setIdentity() tempCol = chassis['hitTester'].localHitTest(compMatrix.applyPoint(startPoint), compMatrix.applyPoint(endPoint)) if tempCol is not None: for dist, _, hitAngleCos, matKind in tempCol: if res is None or res[0] >= dist: matInfo = chassis['materials'].get(matKind) res = SegmentCollisionResult(dist, hitAngleCos, matInfo.armor if matInfo is not None else 0) hullOffset = chassis['hullPosition'] compMatrix.setIdentity() compMatrix.setTranslate(-hullOffset) tempCol = hull['hitTester'].localHitTest(compMatrix.applyPoint(startPoint), compMatrix.applyPoint(endPoint)) if tempCol is not None: for dist, _, hitAngleCos, matKind in tempCol: if res is None or res[0] >= dist: matInfo = hull['materials'].get(matKind) res = SegmentCollisionResult(dist, hitAngleCos, matInfo.armor if matInfo is not None else 0) if not self.isTurretDetached: turret = vehicleDescr.turret turretYaw = Math.Matrix(self.appearance.turretMatrix).yaw turretMatrix = Math.Matrix() turretMatrix.setTranslate(-hullOffset - hull['turretPositions'][0]) compMatrix.setIdentity() compMatrix.setRotateY(-turretYaw) turretMatrix.postMultiply(compMatrix) tempCol = turret['hitTester'].localHitTest(turretMatrix.applyPoint(startPoint), turretMatrix.applyPoint(endPoint)) if tempCol is not None: for dist, _, hitAngleCos, matKind in tempCol: if res is None or res[0] >= dist: matInfo = turret['materials'].get(matKind) res = SegmentCollisionResult(dist, hitAngleCos, matInfo.armor if matInfo is not None else 0) if not skipGun: gunPitch = Math.Matrix(self.appearance.gunMatrix).pitch gunMatrix = Math.Matrix() gunMatrix.setTranslate(-turret['gunPosition']) compMatrix.setIdentity() compMatrix.setRotateX(-gunPitch) gunMatrix.postMultiply(compMatrix) gunMatrix.preMultiply(turretMatrix) tempCol = vehicleDescr.gun['hitTester'].localHitTest(gunMatrix.applyPoint(startPoint), gunMatrix.applyPoint(endPoint)) if tempCol is not None: for dist, _, hitAngleCos, matKind in tempCol: if res is None or res[0] >= dist: matInfo = vehicleDescr.gun['materials'].get(matKind) res = SegmentCollisionResult(dist, hitAngleCos, matInfo.armor if matInfo is not None else 0) else: worldToVehMatrix = Math.Matrix(self.model.matrix) worldToVehMatrix.invert() startPoint = worldToVehMatrix.applyPoint(startPoint) endPoint = worldToVehMatrix.applyPoint(endPoint) for compDescr, compMatrix, isAttached in self.getComponents(): if not isAttached: continue 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 = SegmentCollisionResult(dist, hitAngleCos, matInfo.armor if matInfo is not None else 0) return res