def attachModels(assembler, vehicleDesc, modelsSetParams, isTurretDetached, renderMode=None, overlayCollision=False): collisionState = renderMode in (TankRenderMode.CLIENT_COLLISION, TankRenderMode.SERVER_COLLISION, TankRenderMode.CRASH_COLLISION, TankRenderMode.ARMOR_WIDTH_COLLISION) if collisionState: partModels = getCollisionModelsFromDesc(vehicleDesc, renderMode) else: partModels = getPartModelsFromDesc(vehicleDesc, modelsSetParams) chassis, hull, turret, gun = partModels partNames = TankPartNames if overlayCollision: partNames = TankCollisionPartNames if not overlayCollision: assembler.addRootPart(chassis, TankPartNames.CHASSIS) else: assembler.addPart(chassis, TankPartNames.CHASSIS, TankCollisionPartNames.CHASSIS) if collisionState: trackPairs = vehicleDesc.chassis.trackPairs[1:] for idx, trackPair in enumerate(trackPairs): assembler.addPart(trackPair.hitTester.bspModelName, partNames.CHASSIS, 'trackPair' + str(idx + 1)) if collisionState and vehicleDesc.isWheeledVehicle: for i, wheel in enumerate(vehicleDesc.chassis.wheels.wheels): bspPath = '' if renderMode == TankRenderMode.CLIENT_COLLISION: bspPath = wheel.hitTesterManager.edClientBspModel elif renderMode in (TankRenderMode.SERVER_COLLISION, TankRenderMode.ARMOR_WIDTH_COLLISION): bspPath = wheel.hitTesterManager.edServerBspModel if bspPath: assembler.addNode(wheel.nodeName, partNames.CHASSIS, math_utils.createTranslationMatrix(wheel.position)) assembler.emplacePart(bspPath, wheel.nodeName, TankCollisionPartNames.WHEEL + str(i)) if collisionState and not overlayCollision: assembler.addNode('V', TankPartNames.CHASSIS, math_utils.createTranslationMatrix(vehicleDesc.chassis.hullPosition)) if not overlayCollision: assembler.emplacePart(hull, 'V', partNames.HULL) else: assembler.addPart(hull, 'V', partNames.HULL) turretJointName = vehicleDesc.hull.turretHardPoints[0] assembler.addNodeAlias(turretJointName, TankNodeNames.TURRET_JOINT) if not isTurretDetached: if collisionState and not overlayCollision: assembler.addNode(turretJointName, 'V', math_utils.createRTMatrix(Math.Vector3(0, vehicleDesc.hull.turretPitches[0], 0), vehicleDesc.hull.turretPositions[0])) assembler.addPart(turret, turretJointName, partNames.TURRET) if collisionState and not overlayCollision: assembler.addNode(TankNodeNames.GUN_JOINT, TankPartNames.TURRET, math_utils.createRTMatrix(Math.Vector3(0, vehicleDesc.turret.gunJointPitch, 0), vehicleDesc.turret.gunPosition)) assembler.addPart(gun, TankNodeNames.GUN_JOINT, partNames.GUN) if modelsSetParams.state == 'undamaged': for attachment in modelsSetParams.attachments: if attachment.attachmentLogic == 'prefab': continue assembler.addPart(attachment.modelName, attachment.attachNode, attachment.partNodeAlias, attachment.transform)
def getGunMatrixProvider(vehicleTypeDescriptor, turretMatrixProvider, gunPitchMatrixProvider): gunOffset = vehicleTypeDescriptor.activeGunShotPosition return MatrixProviders.product( gunPitchMatrixProvider, MatrixProviders.product(math_utils.createTranslationMatrix(gunOffset), turretMatrixProvider))
def onAddedMarker(self, combatMarker, transform): transform = transform.worldTransform matrixProduct = math_utils.MatrixProviders.product( transform, math_utils.createTranslationMatrix(combatMarker.offset)) data = { 'visible': True, 'areaRadius': combatMarker.areaRadius, 'disappearingRadius': combatMarker.disappearanceRadius, 'reverseDisappearing': combatMarker.reverseDisappearing, ComponentBitMask.MARKER_2D: [{ 'shape': combatMarker.shape, 'min-distance': 0.0, 'max-distance': 0.0, 'distance': 0.0, 'distanceFieldColor': combatMarker.distanceFieldColor, 'displayDistance': False }], 'matrixProduct': matrixProduct, 'bitMask': ComponentBitMask.MARKER_2D } combatMarker.marker = AreaMarker(data) combatMarker.markerID = self.__guiSessionProvider.shared.areaMarker.addMarker( combatMarker.marker)
def selectPlacement(self, placement): if self.__vehicle is None: return else: self.__placement = placement self.__lookAtProvider = None if placement == _VehicleBounder.SELECT_CHASSIS: self.matrix = self.__vehicle.matrix elif placement == _VehicleBounder.SELECT_TURRET: self.matrix = AimingSystems.getTurretMatrixProvider( self.__vehicle.typeDescriptor, self.__vehicle.matrix, self.__vehicle.appearance.turretMatrix) elif placement == _VehicleBounder.SELECT_GUN: turretMatrixProv = AimingSystems.getTurretMatrixProvider( self.__vehicle.typeDescriptor, self.__vehicle.matrix, self.__vehicle.appearance.turretMatrix) self.matrix = AimingSystems.getGunMatrixProvider( self.__vehicle.typeDescriptor, turretMatrixProv, self.__vehicle.appearance.gunMatrix) elif placement == _VehicleBounder.SELECT_LOOK_AT: self.matrix = math_utils.createIdentityMatrix() self.__lookAtProvider = math_utils.MatrixProviders.product( math_utils.createTranslationMatrix(self.__boundLocalPos), self.__vehicle.matrix) return
def __cameraUpdate(self, allowModeChange=True): curTime = BigWorld.time() deltaTime = curTime - self.__prevTime self.__prevTime = curTime if not self.__autoUpdateDxDyDz.x == self.__autoUpdateDxDyDz.y == self.__autoUpdateDxDyDz.z == 0.0: self.__rotateAndZoom(self.__autoUpdateDxDyDz.x, self.__autoUpdateDxDyDz.y, self.__autoUpdateDxDyDz.z) self.__aimingSystem.update(deltaTime) localTransform, impulseTransform = self.__updateOscillators(deltaTime) zoom = self.__aimingSystem.overrideZoom(self.__zoom) aimMatrix = cameras.getAimMatrix(self.__defaultAimOffset.x, self.__defaultAimOffset.y) camMat = Matrix(aimMatrix) rodMat = math_utils.createTranslationMatrix( -self.__dynamicCfg['pivotShift']) antiRodMat = math_utils.createTranslationMatrix( self.__dynamicCfg['pivotShift']) camMat.postMultiply(rodMat) camMat.postMultiply(localTransform) camMat.postMultiply(antiRodMat) camMat.postMultiply(self.__aimingSystem.matrix) camMat.invert() self.__cam.set(camMat) if zoom != self.__zoom: self.__zoom = zoom self.__applyZoom(self.__zoom) replayCtrl = BattleReplay.g_replayCtrl if replayCtrl.isPlaying and replayCtrl.isControllingCamera: aimOffset = replayCtrl.getAimClipPosition() binocularsOffset = aimOffset if not BigWorld.player().isForcedGuiControlMode() and GUI.mcursor( ).inFocus: GUI.mcursor().position = aimOffset else: aimOffset = self.__calcAimOffset(impulseTransform) binocularsOffset = self.__calcAimOffset() if replayCtrl.isRecording: replayCtrl.setAimClipPosition(aimOffset) self.__aimOffset = aimOffset self.__binoculars.setMaskCenter(binocularsOffset.x, binocularsOffset.y) player = BigWorld.player() if allowModeChange and (self.__isPositionUnderwater( self.__aimingSystem.matrix.translation) or player.isGunLocked and not player.isObserverFPV): self.__onChangeControlMode(False) return -1
def __playTrack(self): if self.__nextTrackName and self.__position: sound = SoundGroups.g_instance.getSound3D(math_utils.createTranslationMatrix(self.__position), self.__nextTrackName) sound.setCallback(self.__soundCallback) sound.play() self.__sounds.append(sound) self.__nextTrackName = None return
def __getVehicleMatrixProvider(self, cmd, vehicleID=None): if vehicleID is None: vehicleID = self.__getVehicleIDByCmd(cmd) vehicle = BigWorld.entities.get(vehicleID) if vehicle is None: position = BigWorld.player().arena.positions.get(vehicleID) if position is not None: maxDistance = 600.0 playerVehiclePosition = BigWorld.player().getOwnVehiclePosition() if Vector3(position).distSqrTo(playerVehiclePosition) > maxDistance * maxDistance: direction = position - playerVehiclePosition direction.normalise() return createTranslationMatrix(playerVehiclePosition + direction * maxDistance) return createTranslationMatrix(position) return else: return Matrix(vehicle.matrix)
def __createCube(self, position, size): modelName = self.CUBE_MODEL model, motor = self.__getModel(modelName) m = math_utils.createSRTMatrix(size, (0, 0, 0), position) m.preMultiply( math_utils.createTranslationMatrix(Vector3(0.0, -0.5, 0.0))) motor.signal = m return (modelName, model, motor)
def __updateOscillator(self, deltaTime): if StrategicCamera.isCameraDynamic(): self.__positionOscillator.update(deltaTime) self.__positionNoiseOscillator.update(deltaTime) else: self.__positionOscillator.reset() self.__positionNoiseOscillator.reset() self.__cam.target.a = math_utils.createTranslationMatrix(self.__positionOscillator.deviation + self.__positionNoiseOscillator.deviation)
def prepareCompoundAssembler(vehicleDesc, modelsSetParams, spaceID, isTurretDetached=False, lodIdx=_DEFAULT_LOD_INDEX, skipMaterials=False, renderState=None): if IS_DEVELOPMENT and modelsSetParams.state not in VehicleDamageState.MODEL_STATE_NAMES: raise SoftException('Invalid modelStateName %s, must be in %s' % (modelsSetParams.state, VehicleDamageState.MODEL_STATE_NAMES)) if spaceID is None: spaceID = BigWorld.player().spaceID assembler = BigWorld.CompoundAssembler() attachModels(assembler, vehicleDesc, modelsSetParams, isTurretDetached, renderState) if renderState == RenderStates.OVERLAY_COLLISION: attachModels(assembler, vehicleDesc, modelsSetParams, isTurretDetached, RenderStates.SERVER_COLLISION, True) cornerPoint = vehicleDesc.chassis.topRightCarryingPoint assembler.addNode(TankNodeNames.TRACK_LEFT_MID, TankPartNames.CHASSIS, math_utils.createTranslationMatrix((-cornerPoint[0], 0, 0))) assembler.addNode(TankNodeNames.TRACK_RIGHT_MID, TankPartNames.CHASSIS, math_utils.createTranslationMatrix((cornerPoint[0], 0, 0))) assembler.addNode(TankNodeNames.CHASSIS_MID_TRAIL, TankPartNames.CHASSIS) assembler.name = vehicleDesc.name assembler.spaceID = spaceID assembler.lodIdx = lodIdx assembler.skipMaterials = skipMaterials return assembler
def getTurretMatrixProvider(vehicleTypeDescriptor, vehicleMatrixProvider, turretYawMatrixProvider): turretOffset = vehicleTypeDescriptor.chassis.hullPosition + vehicleTypeDescriptor.hull.turretPositions[ 0] return MatrixProviders.product( turretYawMatrixProvider, MatrixProviders.product( math_utils.createTranslationMatrix(turretOffset), vehicleMatrixProvider))
def set(self, start, end): self.start = start self.end = end direction = end - start m = math_utils.createSRTMatrix( (self.__thickness, self.__thickness, direction.length), (direction.yaw, direction.pitch, 0), start + direction) m.preMultiply( math_utils.createTranslationMatrix(Vector3(0.0, 0.0, -0.5))) self.motor.signal = m
def __showMarker(self, lootID, position): self._addEntryEx(lootID, BattleRoyaleEntries.BATTLE_ROYALE_MARKER, _C_NAME.EQUIPMENTS, active=True, matrix=math_utils.createTranslationMatrix(position)) entryId = self._entries[lootID].getID() self._parentObj.setEntryParameters( entryId, doClip=False, scaleType=MINIMAP_SCALE_TYPES.NO_SCALE) self._invoke(entryId, MarkersAs3Descr.AS_ADD_MARKER, self.__getMarkerType())
def __createDirectedLine(self, pointA, pointB, width): modelName = self.CUBE_MODEL model, motor = self.__getModel(modelName) direction = pointB - pointA scale = (width, width, direction.length) rotation = (direction.yaw, direction.pitch, 0) translation = pointA + direction * 0.5 m = math_utils.createSRTMatrix(scale, rotation, translation) m.preMultiply( math_utils.createTranslationMatrix(Vector3(0.0, -0.5, 0.0))) motor.signal = m return (modelName, model, motor)
def __init__(self, beginExplosionPos, endExplosionPos, areaWidth, velocity): CallbackDelayer.__init__(self) self.model = BigWorld.Model('helpers/models/unit_cube.model') BigWorld.addModel(self.model) self.model.position = beginExplosionPos linearHomer = BigWorld.LinearHomer() self.model.addMotor(linearHomer) linearHomer.align = math_utils.createSRTMatrix((areaWidth, 5, 1), (0.0, 0, 0), Vector3(0, 0, 0)) linearHomer.acceleration = 0 linearHomer.velocity = velocity linearHomer.target = math_utils.createTranslationMatrix(endExplosionPos) linearHomer.proximityCallback = self.__onDeath
def computeTransform(confDict): matDict = { 'preRotate': math_utils.createIdentityMatrix(), 'postRotate': math_utils.createIdentityMatrix(), 'vect': math_utils.createIdentityMatrix() } if any( isinstance(confDict[confKey][0], tuple) for confKey in matDict.keys()): for confKey in matDict.keys(): if isinstance(confDict[confKey][0], tuple): keyframes = [] for keyframe in confDict[confKey]: timeStamp, value = keyframe if 'vect' in confKey: Mat = math_utils.createTranslationMatrix(value) else: Mat = math_utils.createRotationMatrix(value) keyframes.append((timeStamp, Mat)) MatAn = Math.MatrixAnimation() MatAn.keyframes = keyframes MatAn.time = 0.0 MatAn.loop = True elif 'vect' in confKey: MatAn = math_utils.createTranslationMatrix(confDict[confKey]) else: MatAn = math_utils.createRotationMatrix(confDict[confKey]) matDict[confKey] = MatAn matProd = math_utils.MatrixProviders.product(matDict['vect'], matDict['postRotate']) LightMat = math_utils.MatrixProviders.product(matDict['preRotate'], matProd) else: preRotate = math_utils.createRotationMatrix(confDict['preRotate']) postRotate = math_utils.createRotationMatrix(confDict['postRotate']) LightMat = math_utils.createTranslationMatrix(confDict['vect']) LightMat.postMultiply(postRotate) LightMat.preMultiply(preRotate) return LightMat
def attachModels(assembler, vehicleDesc, modelsSetParams, isTurretDetached, renderState=None, overlayCollision=False): collisionState = renderState == RenderStates.CLIENT_COLLISION or renderState == RenderStates.SERVER_COLLISION if collisionState: partModels = getCollisionModelsFromDesc(vehicleDesc, renderState) else: partModels = getPartModelsFromDesc(vehicleDesc, modelsSetParams) chassis, hull, turret, gun = partModels partNames = TankPartNames if overlayCollision: partNames = TankCollisionPartNames if not overlayCollision: assembler.addRootPart(chassis, TankPartNames.CHASSIS) else: assembler.addPart(chassis, TankPartNames.CHASSIS, TankCollisionPartNames.CHASSIS) if collisionState and vehicleDesc.isWheeledVehicle: for i, wheel in enumerate(vehicleDesc.chassis.wheels.wheels): bspPath = '' if renderState == RenderStates.CLIENT_COLLISION: bspPath = wheel.hitTester.edClientBspModel elif renderState == RenderStates.SERVER_COLLISION: bspPath = wheel.hitTester.edServerBspModel if bspPath: assembler.addNode(wheel.nodeName, partNames.CHASSIS, math_utils.createTranslationMatrix(wheel.position)) assembler.emplacePart(bspPath, wheel.nodeName, TankCollisionPartNames.WHEEL + str(i)) if collisionState and not overlayCollision: assembler.addNode('V', TankPartNames.CHASSIS, math_utils.createTranslationMatrix(vehicleDesc.chassis.hullPosition)) assembler.emplacePart(hull, 'V', partNames.HULL) turretJointName = vehicleDesc.hull.turretHardPoints[0] assembler.addNodeAlias(turretJointName, TankNodeNames.TURRET_JOINT) if not isTurretDetached: if collisionState and not overlayCollision: assembler.addNode(turretJointName, 'V', math_utils.createTranslationMatrix(vehicleDesc.hull.turretPositions[0])) assembler.addPart(turret, turretJointName, partNames.TURRET) if collisionState and not overlayCollision: assembler.addNode(TankNodeNames.GUN_JOINT, TankPartNames.TURRET, math_utils.createTranslationMatrix(vehicleDesc.turret.gunPosition)) assembler.addPart(gun, TankNodeNames.GUN_JOINT, partNames.GUN) if modelsSetParams.state == 'undamaged': for attachment in modelsSetParams.attachments: assembler.addPart(attachment.modelName, attachment.attachNode, attachment.partNodeAlias, attachment.transform)
def __create3DText(self, position, text, color, textSize): if self.reuse3DTexts: model, motor, component = self.reuse3DTexts.pop() else: attachment = GUI.Attachment() component = GUI.Text(text) attachment.component = component attachment.faceCamera = True motor = BigWorld.Servo( math_utils.createTranslationMatrix(position)) model = BigWorld.Model('') model.addMotor(motor) BigWorld.addModel(model, self.spaceID) model.root.attach(attachment) component.visible = True component.multiline = True component.explicitSize = True component.filterType = 'LINEAR' component.verticalAnchor = 'BOTTOM' component.text = text component.size = (0, textSize) component.colour = color motor.signal = math_utils.createTranslationMatrix(position) return (model, motor, component)
def __multipositionSpawn(self, go, multivisualizer, influenceZone, equipment, radius): for zonePosition in influenceZone.zonesPosition: localPosition = zonePosition - influenceZone.position if multivisualizer.rotateFromCenter: transform = math_utils.createRTMatrix( (localPosition.yaw, 0, 0), localPosition) else: transform = math_utils.createTranslationMatrix(localPosition) def postloadSetup(go): areaVisualizer = go.findComponentByType(AreaAbilityVisualizer) if areaVisualizer is not None: areaVisualizer.radius = equipment.zoneRadius eqComponent = go.createComponent( InfluenceZoneEquipmentComponent) eqComponent.setupEquipment(equipment) return CGF.loadGameObjectIntoHierarchy(multivisualizer.influencePrefab, go, transform, postloadSetup)
def lightsCreate(vehicleID, callPlace=''): try: vehicle = BigWorld.player().arena.vehicles[vehicleID] vEntity = BigWorld.entity(vehicleID) if vEntity is None: return vDesc = vEntity.typeDescriptor if vehicleID == BigWorld.player().playerVehicleID: print 'LampLights: Create at %s' % callPlace constNodesList = [ TankNodeNames.TRACK_LEFT_UP_FRONT, TankNodeNames.TRACK_LEFT_UP_REAR, TankNodeNames.TRACK_RIGHT_UP_FRONT, TankNodeNames.TRACK_RIGHT_UP_REAR ] compoundModel = vEntity.appearance.compoundModel nodeListML, nodeListNL = findWheelNodes(vehicleID, 'L') nodeListMR, nodeListNR = findWheelNodes(vehicleID, 'R') fakesDict[vehicleID] = fakeDict = {} fakeMotorsDict[vehicleID] = fakeMotorDict = {} sourcesDict = {TankPartNames.CHASSIS: None, TankPartNames.HULL: None} for tankPartName in sourcesDict.keys(): curSource = getattr(vDesc, tankPartName).models.undamaged modelSec = ResMgr.openSection(curSource) if modelSec is None: print 'LampLights: file not found:', curSource sourceSecStr = modelSec['nodefullVisual'].asString sourceSec = ResMgr.openSection(sourceSecStr + '.visual') if sourceSec is None: sourceSec = ResMgr.openSection(sourceSecStr + '.visual_processed') if sourceSec is None: print 'LampLights: visual not found for', curSource print callPlace else: sourcesDict[tankPartName] = sourceSec HullMat = math_utils.createIdentityMatrix() deHullMat = math_utils.createIdentityMatrix() if sourcesDict[TankPartNames.CHASSIS] is not None: deHullMat = nodeWatcher(sourcesDict[TankPartNames.CHASSIS], 'V') deHullMat.invert() for tankPartName in (TankPartNames.CHASSIS, TankPartNames.HULL): fakeDict[tankPartName] = BigWorld.Model('objects/fake_model.model') fakeDict[tankPartName + 'Root'] = BigWorld.Model('objects/fake_model.model') compoundModel.node(TankPartNames.HULL).attach( fakeDict[tankPartName + 'Root'], HullMat if 'hull' in tankPartName else deHullMat) if fakeMotorDict.get(tankPartName) not in tuple( fakeDict[tankPartName].motors): fakeMotorDict[tankPartName] = BigWorld.Servo( fakeDict[tankPartName + 'Root'].matrix) fakeDict[tankPartName].addMotor(fakeMotorDict[tankPartName]) if fakeDict[tankPartName] not in tuple(BigWorld.models()): BigWorld.addModel(fakeDict[tankPartName]) for idx, node in enumerate(nodeListNL): fakeDict[node] = BigWorld.Model('objects/fake_model.model') fakeDict[TankPartNames.CHASSIS].node('', nodeListML[idx]).attach( fakeDict[node]) for idx, node in enumerate(nodeListNR): fakeDict[node] = BigWorld.Model('objects/fake_model.model') fakeDict[TankPartNames.CHASSIS].node('', nodeListMR[idx]).attach( fakeDict[node]) for node in constNodesList: fakeDict[node] = BigWorld.Model('objects/fake_model.model') restoreMat = math_utils.createIdentityMatrix() transMat = None isChassis = False if sourcesDict[TankPartNames.HULL] is not None: transMat = nodeWatcher(sourcesDict[TankPartNames.HULL], node) if transMat is None and sourcesDict[ TankPartNames.CHASSIS] is not None: transMat = nodeWatcher(sourcesDict[TankPartNames.CHASSIS], node) if transMat is None: transMat = nodeWatcher(sourcesDict[TankPartNames.CHASSIS], node.replace('Up', '')) isChassis = True if transMat is None: print _config.ID + ': restore Matrix not found for node', node, 'in', vDesc.hull.models.undamaged print callPlace else: restoreMat.setTranslate(transMat.translation) fakeDict[TankPartNames.HULL if not isChassis else TankPartNames. CHASSIS].node('', restoreMat).attach(fakeDict[node]) fakeDict[TankPartNames.GUN + 'Root'] = BigWorld.Model('objects/fake_model.model') compoundModel.node(TankPartNames.GUN).attach( fakeDict[TankPartNames.GUN + 'Root']) fakeDict[TankPartNames.GUN] = BigWorld.Model( 'objects/fake_model.model') if fakeMotorDict.get(TankPartNames.GUN) not in tuple( fakeDict[TankPartNames.GUN].motors): fakeMotorDict[TankPartNames.GUN] = BigWorld.Servo( fakeDict[TankPartNames.GUN + 'Root'].matrix) fakeDict[TankPartNames.GUN].addMotor( fakeMotorDict[TankPartNames.GUN]) if fakeDict[TankPartNames.GUN] not in tuple(BigWorld.models()): BigWorld.addModel(fakeDict[TankPartNames.GUN]) fakeDict[TankPartNames.TURRET] = BigWorld.Model( 'objects/fake_model.model') fakeDict[TankPartNames.TURRET + 'Root'] = BigWorld.Model('objects/fake_model.model') fakeDict[TankPartNames.TURRET + 'RootRoot'] = BigWorld.Model('objects/fake_model.model') hull_bbox_min, hull_bbox_max, _ = vDesc.hull.hitTester.bbox turret_pos_on_hull = vDesc.hull.turretPositions[0] turret_bbox_max = vDesc.turret.hitTester.bbox[1] gun_pos_on_turret = vDesc.turret.gunPosition gun_pos_on_hull = gun_pos_on_turret + turret_pos_on_hull gun_bbox_max = vDesc.gun.hitTester.bbox[1] if hull_bbox_max.y >= turret_pos_on_hull.y + turret_bbox_max.y: observer_pos = Math.Vector3(0, hull_bbox_max.y, 0) node = TankPartNames.HULL elif gun_pos_on_turret.y + gun_bbox_max.y >= turret_bbox_max.y: observer_pos = Math.Vector3(0, gun_bbox_max.y, 0) node = TankPartNames.GUN else: observer_pos = Math.Vector3(0, turret_bbox_max.y, 0) node = TankPartNames.TURRET mat = Math.Matrix() mat.setTranslate(observer_pos) compoundModel.node(node).attach(fakeDict[TankPartNames.TURRET + 'RootRoot']) if fakeMotorDict.get(TankPartNames.TURRET + 'Root') not in tuple( fakeDict[TankPartNames.TURRET + 'Root'].motors): fakeMotorDict[TankPartNames.TURRET + 'Root'] = BigWorld.Servo( fakeDict[TankPartNames.TURRET + 'RootRoot'].matrix) fakeDict[TankPartNames.TURRET + 'Root'].addMotor( fakeMotorDict[TankPartNames.TURRET + 'Root']) if fakeDict[TankPartNames.TURRET + 'Root'] not in tuple( BigWorld.models()): BigWorld.addModel(fakeDict[TankPartNames.TURRET + 'Root']) fakeDict[TankPartNames.TURRET + 'Root'].node('', mat).attach( fakeDict[TankPartNames.TURRET]) hullLocalCenterY = (hull_bbox_min.y + hull_bbox_max.y) / 2.0 hullLocalCenterZ = (hull_bbox_min.z + hull_bbox_max.z) / 2.0 nodes = { 'hullLocalPt1': Math.Vector3(0.0, hullLocalCenterY, hull_bbox_max.z), 'hullLocalPt2': Math.Vector3(0.0, hullLocalCenterY, hull_bbox_min.z), 'hullLocalPt3': Math.Vector3(hull_bbox_max.x, gun_pos_on_hull.y, hullLocalCenterZ), 'hullLocalPt4': Math.Vector3(hull_bbox_min.x, gun_pos_on_hull.y, hullLocalCenterZ), 'hullGunLocal': gun_pos_on_hull } for node in nodes: fakeDict[node] = BigWorld.Model('objects/fake_model.model') fakeDict[TankPartNames.HULL].node( '', math_utils.createTranslationMatrix(nodes[node])).attach( fakeDict[node]) lightDBDict.setdefault(vehicleID, {}) for configDict in _config.configsDict.values(): for name in sorted(configDict.keys()): try: if name in ('enable', 'meta', 'attachToPlayer', 'attachToAlly', 'attachToEnemy'): continue confDict = configDict[name] needToAttach = \ confDict['attachToPlayer'] and vehicleID == BigWorld.player().playerVehicleID or \ confDict['attachToEnemy'] and vehicle['team'] != BigWorld.player().team or \ confDict['attachToAlly'] and vehicleID != BigWorld.player().playerVehicleID and \ vehicle['team'] == BigWorld.player().team if not needToAttach: continue nodeL = [] if '.' in name: nodeL.append(confDict['place']) elif confDict['place'] == 'leftFront': nodeL.append(TankNodeNames.TRACK_LEFT_UP_FRONT) elif confDict['place'] == 'rightFront': nodeL.append(TankNodeNames.TRACK_RIGHT_UP_FRONT) elif confDict['place'] == 'leftRear': nodeL.append(TankNodeNames.TRACK_LEFT_UP_REAR) elif confDict['place'] == 'rightRear': nodeL.append(TankNodeNames.TRACK_RIGHT_UP_REAR) elif confDict['place'] == 'hull': nodeL.append(TankPartNames.HULL) elif confDict['place'] == 'turret': nodeL.append(TankPartNames.TURRET) elif confDict['place'] == 'spot': nodeL.extend([TankPartNames.TURRET, TankPartNames.GUN]) nodeL.extend( ['hullLocalPt%s' % num for num in xrange(1, 5)]) nodeL.append('hullGunLocal') elif 'wheels' in confDict['place']: if 'left' in confDict['place']: nodeL.extend(nodeListNL) else: nodeL.extend(nodeListNR) nameTree = name.split('.')[:-1] namesList = [] for curKey in lightDBDict[vehicleID].keys(): curTree = curKey.split('.') if len(curTree) != len(nameTree) or any( upperName not in curTree[depth] for depth, upperName in enumerate(nameTree)): continue namesList.append(curKey + '.' + name.split('.')[-1]) if not namesList: namesList = [name] for fullName in namesList: for node in nodeL: curName = fullName + ':' + node if 'model' not in confDict['type']: if confDict['type'] == 'spotLight': LightSource = BigWorld.PySpotLight() LightSource.coneAngle = confDict['ca'] else: LightSource = BigWorld.PyOmniLight() if confDict['type'] != 'omniLight': LOG_ERROR( 'Unknown type of %s: %s. Set to omniLight' % (name, confDict['type'])) LightSource.innerRadius = confDict[ 'innerRadius'] LightSource.outerRadius = confDict[ 'outerRadius'] LightSource.castShadows = confDict['cs'] LightSource.multiplier = confDict['bright'] if isinstance(confDict['colour'][0], tuple): if confDict['type'] != 'spotLight': FrontLightShader = Math.Vector4Animation( ) FrontLightShader.duration = confDict[ 'dur'] FrontLightShader.keyframes = confDict[ 'colour'] LightSource.colorAnimator = FrontLightShader else: LightSource.colour = confDict[ 'colour'][0][1] else: LightSource.colour = confDict['colour'] else: LightSource = BigWorld.Model(confDict['path']) if '.' not in name: if node in fakeDict: fakeNode = fakeDict[node].node( '', computeTransform(confDict)) else: if curName not in fakeDict: fakeDict[curName] = BigWorld.Model( 'objects/fake_model.model') lightDBDict[vehicleID][curName.rsplit( '.', 1)[0]].node(node).attach( fakeDict[curName]) fakeNode = fakeDict[curName].node( '', computeTransform(confDict)) if 'model' not in confDict['type']: # noinspection PyUnboundLocalVariable LightSource.source = fakeNode elif not LightSource.attached: fakeNode.attach(LightSource) lightVisible( LightSource, _config.isLampsVisible and name in _config.modes['constant']) lightDBDict[vehicleID][curName] = LightSource except StandardError: traceback.print_exc() print name print callPlace print vDesc.name except StandardError: traceback.print_exc() print callPlace
def __cameraUpdate(self): if not (self.__autoUpdateDxDyDz.x == 0.0 and self.__autoUpdateDxDyDz.y == 0.0 and self.__autoUpdateDxDyDz.z == 0.0): self.__update(self.__autoUpdateDxDyDz.x, self.__autoUpdateDxDyDz.y, self.__autoUpdateDxDyDz.z) inertDt = deltaTime = self.measureDeltaTime() replayCtrl = BattleReplay.g_replayCtrl if replayCtrl.isPlaying: repSpeed = replayCtrl.playbackSpeed if repSpeed == 0.0: inertDt = 0.01 deltaTime = 0.0 else: inertDt = deltaTime = deltaTime / repSpeed self.__aimingSystem.update(deltaTime) virginShotPoint = self.__aimingSystem.getThirdPersonShotPoint() delta = self.__inputInertia.positionDelta sign = delta.dot(Vector3(0, 0, 1)) self.__inputInertia.update(inertDt) delta = (delta - self.__inputInertia.positionDelta).length if delta != 0.0: self.__cam.setScrollDelta(math.copysign(delta, sign)) FovExtended.instance().setFovByMultiplier( self.__inputInertia.fovZoomMultiplier) unshakenPos = self.__inputInertia.calcWorldPos( self.__aimingSystem.matrix) vehMatrix = Math.Matrix(self.__aimingSystem.vehicleMProv) vehiclePos = vehMatrix.translation fromVehicleToUnshakedPos = unshakenPos - vehiclePos deviationBasis = math_utils.createRotationMatrix( Vector3(self.__aimingSystem.yaw, 0, 0)) impulseDeviation, movementDeviation, oscillationsZoomMultiplier = self.__updateOscillators( deltaTime) relCamPosMatrix = math_utils.createTranslationMatrix(impulseDeviation + movementDeviation) relCamPosMatrix.postMultiply(deviationBasis) relCamPosMatrix.translation += fromVehicleToUnshakedPos upRotMat = math_utils.createRotationMatrix( Vector3( 0, 0, -impulseDeviation.x * self.__dynamicCfg['sideImpulseToRollRatio'] - self.__noiseOscillator.deviation.z)) upRotMat.postMultiply(relCamPosMatrix) self.__cam.up = upRotMat.applyVector(Vector3(0, 1, 0)) relTranslation = relCamPosMatrix.translation shotPoint = self.__calcFocalPoint(virginShotPoint, deltaTime) vehToShotPoint = shotPoint - vehiclePos self.__setCameraAimPoint(vehToShotPoint) self.__setCameraPosition(relTranslation) replayCtrl = BattleReplay.g_replayCtrl if replayCtrl.isPlaying and replayCtrl.isControllingCamera: aimOffset = replayCtrl.getAimClipPosition() if not BigWorld.player().isForcedGuiControlMode() and GUI.mcursor( ).inFocus: GUI.mcursor().position = aimOffset else: aimOffset = self.__calcAimOffset(oscillationsZoomMultiplier) if replayCtrl.isRecording: replayCtrl.setAimClipPosition(aimOffset) self.__cam.aimPointClipCoords = aimOffset self.__aimOffset = aimOffset if self.__shiftKeySensor is not None: self.__shiftKeySensor.update(1.0) if self.__shiftKeySensor.currentVelocity.lengthSquared > 0.0: self.shiftCamPos(self.__shiftKeySensor.currentVelocity) self.__shiftKeySensor.currentVelocity = Math.Vector3() return 0.0
def createCrosshairMatrix(offsetFromNearPlane): nearPlane = BigWorld.projection().nearPlane return math_utils.createTranslationMatrix( Vector3(0, 0, nearPlane + offsetFromNearPlane))
def notifyViewPointChanged(self, avatar, staticPosition=None): if staticPosition is not None: self.__setTarget( math_utils.createTranslationMatrix(staticPosition)) return
def new_setupModel(base, self, buildIdx): base(self, buildIdx) if not g_config.data['enabled']: return if g_config.collisionMode: vEntity = self._HangarVehicleAppearance__vEntity vDesc = self._HangarVehicleAppearance__vDesc compoundModel = vEntity.model self.collisionLoaded = True self.modifiedModelsDesc = {} failList = [] for partName in TankPartNames.ALL: modelName = '' try: modelName = getattr(vDesc, partName).hitTester.bspModelName model = BigWorld.Model(modelName) model.visible = False self.modifiedModelsDesc[partName] = { 'model': model, 'matrix': None } except StandardError: self.collisionLoaded = False failList.append(modelName if modelName else partName) if failList: print g_config.ID + ': collision load failed: models not found', failList if not self.collisionLoaded: return # Getting offset matrices hullOffset = math_utils.createTranslationMatrix( vDesc.chassis.hullPosition) self.modifiedModelsDesc[TankPartNames.CHASSIS][ 'matrix'] = fullChassisMP = math_utils.createIdentityMatrix() hullMP = math_utils.MatrixProviders.product( math_utils.createIdentityMatrix(), hullOffset) self.modifiedModelsDesc[TankPartNames.HULL][ 'matrix'] = fullHullMP = math_utils.MatrixProviders.product( hullMP, fullChassisMP) for idx in xrange(len(vDesc.hull.turretPositions)): if idx: print g_config.ID + ': WARNING: multiple turrets are present!', vDesc.name break turretOffset = math_utils.createTranslationMatrix( vDesc.hull.turretPositions[idx]) gunOffset = math_utils.createTranslationMatrix( vDesc.turret.gunPosition) # Getting local transform matrices turretMP = math_utils.MatrixProviders.product( math_utils.createIdentityMatrix(), turretOffset) gunMP = math_utils.MatrixProviders.product( math_utils.createIdentityMatrix(), gunOffset) # turretMP = math_utils.MatrixProviders.product(vEntity.appearance.turretMatrix, turretOffset) # gunMP = math_utils.MatrixProviders.product(vEntity.appearance.gunMatrix, gunOffset) # Getting full transform matrices relative to vehicle coordinate system self.modifiedModelsDesc[TankPartNames.TURRET][ 'matrix'] = fullTurretMP = math_utils.MatrixProviders.product( turretMP, fullHullMP) self.modifiedModelsDesc[TankPartNames.GUN][ 'matrix'] = math_utils.MatrixProviders.product( gunMP, fullTurretMP) for moduleDict in self.modifiedModelsDesc.itervalues(): motor = BigWorld.Servo( math_utils.MatrixProviders.product(moduleDict['matrix'], vEntity.matrix)) moduleDict['model'].addMotor(motor) if moduleDict['model'] not in tuple(vEntity.models): try: vEntity.addModel(moduleDict['model']) except StandardError: pass moduleDict['model'].visible = True addCollisionGUI(self) if g_config.collisionMode == 1: for moduleName in TankPartNames.ALL: # noinspection PyUnboundLocalVariable if compoundModel.node(moduleName) is not None: scaleMat = Math.Matrix() scaleMat.setScale((0.001, 0.001, 0.001)) compoundModel.node(moduleName, scaleMat) else: print g_config.ID + ': model rescale for', moduleName, 'failed'