def _updateMatrix(self): vehiclePosition = Vector3( BigWorld.player().getVehicleAttached().position) vehiclePosition.y = self._planePosition.y diff = self._planePosition - vehiclePosition if diff.lengthSquared < _MINIMAL_AIMING_RADIUS_SQ: diff.normalise() self._planePosition = vehiclePosition + diff * _MINIMAL_AIMING_RADIUS self._clampToArenaBB() hitPoint = BigWorld.wg_collideSegment( BigWorld.player().spaceID, self._planePosition + Vector3(0.0, 1000.0, 0.0), self._planePosition + Vector3(0.0, -250.0, 0.0), 128, 8) aimPoint = Vector3(self._planePosition) if hitPoint is not None: aimPoint.y = hitPoint.closestPoint[1] r0, v0, g0 = BigWorld.player().gunRotator.getShotParams(aimPoint, True) hitPoint = BigWorld.wg_simulateProjectileTrajectory( r0, v0, g0, SERVER_TICK_LENGTH, SHELL_TRAJECTORY_EPSILON_CLIENT, 128) if hitPoint is not None: time = (aimPoint.x - r0.x) / v0.x self.__direction = v0 + g0 * time self.__direction.normalise() self._matrix = mathUtils.createRTMatrix( (self.__direction.yaw, -self.__direction.pitch, 0.0), hitPoint[1]) self.__aimMatrix.setTranslate(aimPoint) return
def getTurretJointMat(vehicleTypeDescriptor, vehicleMatrix, turretYaw=0.0): turretOffset = vehicleTypeDescriptor.chassis[ 'hullPosition'] + vehicleTypeDescriptor.hull['turretPositions'][0] turretJointMat = mathUtils.createRTMatrix(Vector3(turretYaw, 0, 0), turretOffset) turretJointMat.postMultiply(vehicleMatrix) return turretJointMat
def __assembleModel(self): resources = self.__resources self.__model = resources[self.__vDesc.name] self.__setupEmblems(self.__vDesc) if not self.__isVehicleDestroyed: self.__fashions = VehiclePartsTuple( BigWorld.WGVehicleFashion(False, _CFG['v_scale']), None, None, None) import VehicleAppearance VehicleAppearance.setupTracksFashion(self.__fashions.chassis, self.__vDesc, self.__isVehicleDestroyed) self.__model.setupFashions(self.__fashions) chassisFashion = self.__fashions.chassis chassisFashion.initialUpdateTracks(1.0, 10.0) VehicleAppearance.setupSplineTracks(chassisFashion, self.__vDesc, self.__model, self.__resources) else: self.__fashions = VehiclePartsTuple(None, None, None, None) self.updateCamouflage() yaw = self.__vDesc.gun.get('staticTurretYaw', 0.0) pitch = self.__vDesc.gun.get('staticPitch', 0.0) if yaw is None: yaw = 0.0 if pitch is None: pitch = 0.0 gunMatrix = mathUtils.createRTMatrix(Math.Vector3(yaw, pitch, 0.0), (0.0, 0.0, 0.0)) self.__model.node('gun', gunMatrix) return self.__model
def getComponents(self): res = [] vehicleDescr = self.typeDescriptor m = Math.Matrix() m.setIdentity() res.append((vehicleDescr.chassis, m)) hullOffset = vehicleDescr.chassis.hullPosition m = Math.Matrix() offset = -hullOffset m.setTranslate(offset) res.append((vehicleDescr.hull, m)) m = Math.Matrix() offset -= vehicleDescr.hull.turretPositions[0] m.setTranslate(offset) res.append((vehicleDescr.turret, m)) yaw = vehicleDescr.gun.staticTurretYaw pitch = vehicleDescr.gun.staticPitch offset -= vehicleDescr.turret.gunPosition if yaw is None: yaw = 0.0 if pitch is None: pitch = 0.0 m = Math.Matrix() gunMatrix = mathUtils.createRTMatrix(Math.Vector3(yaw, pitch, 0.0), offset) gunMatrix.postMultiply(m) res.append((vehicleDescr.gun, gunMatrix)) return res
def __assembleModel(self): resources = self.__resources self.__model = resources[self.__vDesc.name] self.__setupEmblems(self.__vDesc) if not self.__isVehicleDestroyed: self.__fashions = VehiclePartsTuple( BigWorld.WGVehicleFashion(False), None, None, None) model_assembler.setupTracksFashion(self.__fashions.chassis, self.__vDesc, self.__isVehicleDestroyed) self.__model.setupFashions(self.__fashions) chassisFashion = self.__fashions.chassis model_assembler.setupSplineTracks(chassisFashion, self.__vDesc, self.__model, self.__resources) self.wheelsAnimator = model_assembler.createWheelsAnimator( self.__model, self.__vDesc, None) self.trackNodesAnimator = model_assembler.createTrackNodesAnimator( self.__model, self.__vDesc, self.wheelsAnimator) else: self.__fashions = VehiclePartsTuple(None, None, None, None) self.wheelsAnimator = None self.trackNodesAnimator = None self.updateCamouflage() yaw = self.__vDesc.gun.staticTurretYaw pitch = self.__vDesc.gun.staticPitch if yaw is None: yaw = 0.0 if pitch is None: pitch = 0.0 gunMatrix = mathUtils.createRTMatrix(Math.Vector3(yaw, pitch, 0.0), (0.0, 0.0, 0.0)) self.__model.node('gun', gunMatrix) return self.__model
def setSelectingDirection(self, value = False): if value and self.__terrainRotatedArea is None: objectSize = Math.Vector2(10.0, 10.0) self.__rotateModelNode = self.__fakeModel.node('', mathUtils.createRTMatrix(Math.Vector3(-self.__fakeModel.yaw, 0.0, 0.0), Math.Vector3((-self.__size.x - objectSize.x) * 0.5, 0.0, (self.__size.y + objectSize.y) * 0.5))) self.__terrainRotatedArea = area = BigWorld.PyTerrainSelectedArea() area.setup(DEFAULT_ROTATE_MODEL, objectSize, OVER_TERRAIN_HEIGHT, self.__color) self.__rotateModelNode.attach(area) elif not value and self.__terrainRotatedArea is not None: self.__rotateModelNode.detach(self.__terrainRotatedArea) self.__terrainRotatedArea = None
def getTurretJointMat(vehicleTypeDescriptor, vehicleMatrix, turretYaw=0.0, overrideTurretLocalZ=None): turretOffset = getTurretJointOffset(vehicleTypeDescriptor) if overrideTurretLocalZ is not None: turretOffset.z = overrideTurretLocalZ turretJointMat = mathUtils.createRTMatrix(Vector3(turretYaw, 0, 0), turretOffset) turretJointMat.postMultiply(vehicleMatrix) return turretJointMat
def setSelectingDirection(self, value = False): if value and self.__terrainRotatedArea is None: objectSize = Math.Vector2(10.0, 10.0) self.__rotateModelNode = self.__fakeModel.node('', mathUtils.createRTMatrix(Math.Vector3(-self.__matrix.yaw, 0.0, 0.0), Math.Vector3((-self.__size.x - objectSize.x) * 0.5, 0.0, (self.__size.y + objectSize.y) * 0.5))) self.__terrainRotatedArea = area = BigWorld.PyTerrainSelectedArea() area.setup(DEFAULT_ROTATE_MODEL, objectSize, OVER_TERRAIN_HEIGHT, self.__color) self.__rotateModelNode.attach(area) elif not value and self.__terrainRotatedArea is not None: self.__rotateModelNode.detach(self.__terrainRotatedArea) self.__terrainRotatedArea = None return
def getGunJointMat(vehicleTypeDescriptor, turretMatrix, gunPitch, overrideTurretLocalZ=None): gunOffset = Vector3(vehicleTypeDescriptor.turret['gunPosition']) if overrideTurretLocalZ is not None: offset = getTurretJointOffset(vehicleTypeDescriptor) yOffset = math.tan(gunPitch) * offset.z gunOffset.y += yOffset gunMat = mathUtils.createRTMatrix(Vector3(0, gunPitch, 0), gunOffset) gunMat.postMultiply(turretMatrix) return gunMat
def __debugDrawChassisCollision(self, rotation, translation): if not constants.IS_DEVELOPMENT: return if not hasattr(self, '_Vehicle__debugServerChassis'): chassisModel = BigWorld.Model(self.typeDescriptor.chassis['hitTester'].bspModelName) BigWorld.player().addModel(chassisModel) motor = BigWorld.Servo(Math.Matrix()) chassisModel.addMotor(motor) self.__debugServerChassis = chassisModel from AvatarInputHandler import mathUtils chassisMatrix = mathUtils.createRTMatrix(rotation, translation) chassisMatrix.postMultiply(self.model.matrix) self.__debugServerChassis.motors[0].signal = chassisMatrix
def _update(self): worldMatrix = Matrix(self._cam.invViewMatrix) desiredPosition = self.__basisMProv.checkTurretDetachment( worldMatrix.translation) if desiredPosition is not None: self.__position = desiredPosition prevPos = Math.Vector3(self.__position) delta = self.__calcCurrentDeltaAdjusted() self.__updateSenses(delta) if self._targetRadiusSensor: self.__rotationRadius += self._targetRadiusSensor.currentVelocity * delta if self.__isVerticalVelocitySeparated: self._verticalMovementSensor.update(delta) else: self._verticalMovementSensor.currentVelocity = self._movementSensor.currentVelocity.y self._verticalMovementSensor.sensitivity = self._movementSensor.sensitivity if self._inertiaEnabled: self.__inertialMovement(delta) else: self.__simpleMovement(delta) self.__ypr += self.__yprVelocity * delta self.__position += self.__velocity * delta if self.__rotateAroundPointEnabled: self.__position = self.__getAlignedToPointPosition( mathUtils.createRotationMatrix(self.__ypr)) if self._alignerToLand.enabled and not self.__basisMProv.isBound: if abs(self.__velocity.y) > 0.1: self._alignerToLand.enable(self.__position, self._alignerToLand.ignoreTerrain) self.__position = self._alignerToLand.getAlignedPosition( self.__position) lookAtPosition = self.__basisMProv.lookAtPosition if lookAtPosition is not None: self.__ypr = self.__getLookAtYPR(lookAtPosition) if self.__cameraInterpolator.active: self.__ypr = self.__clampPR(self.__ypr) else: self.__ypr = self.__clampYPR(self.__ypr) self.__position = self._checkSpaceBounds(prevPos, self.__position) self._cam.invViewProvider.a = mathUtils.createRTMatrix( self.__ypr, self.__position) self._cam.invViewProvider.b = self.__basisMProv.matrix if self.__cameraInterpolator.active: self.__cameraInterpolator.tick() BigWorld.projection().fov = self.__calcFov() self.__resetSenses() return 0.0
def setSelectingDirection(self, value=False): if value and self.__terrainRotatedArea is None: objectSize = Math.Vector2(10.0, 10.0) self.__rotateModelNode = self.__fakeModel.node( '', mathUtils.createRTMatrix( Math.Vector3(-self.__matrix.yaw, 0.0, 0.0), Math.Vector3((-self.__size.x - objectSize.x) * 0.5, 0.0, (self.__size.y + objectSize.y) * 0.5))) self.__terrainRotatedArea = area = BigWorld.PyTerrainSelectedArea() area.setup(DEFAULT_ROTATE_MODEL, objectSize, self.__overTerrainHeight, self.__color) area.enableAccurateCollision(True) area.setYCutOffDistance(MARKER_HEIGHT) self.__rotateModelNode.attach(area) elif not value and self.__terrainRotatedArea is not None: self.__rotateModelNode.detach(self.__terrainRotatedArea) self.__terrainRotatedArea = None return
def create(self, fromPos, toPos): if None in (fromPos, toPos): return else: self.__direction = toPos - fromPos self.__length = self.__direction.length self.__direction.normalise() self.__numModelsPerEdgeState = {} for edgeState, modelSetting in g_borderVisualSettings.modelSettings.iteritems( ): dashLength = modelSetting.scale.x gap = modelSetting.spacing self.__numModelsPerEdgeState[edgeState] = max( 1, int((self.__length - 2 * dashLength) / (dashLength + gap)) + 1) maxNumModels = max(self.__numModelsPerEdgeState.values()) rotation = (self.__direction.yaw + math.pi * 0.5, self.__direction.pitch, 0.0) translation = fromPos + self.__direction * self.__length * 0.5 self.__rootMatrix = rootMatrix = mathUtils.createRTMatrix( rotation=rotation, translation=translation) self.__rootModel = rootModel = BigWorld.Model('') rootModel.addMotor(BigWorld.Servo(rootMatrix)) BigWorld.addModel(rootModel) self.__terrainModels = [None] * maxNumModels self.__attachNodes = [None] * maxNumModels self.__modelOffsets = [None] * maxNumModels for idx in range(0, maxNumModels): self.__terrainModels[ idx] = area = BigWorld.PyTerrainSelectedArea() self.__modelOffsets[idx] = offset = Matrix() self.__attachNodes[idx] = attachNode = rootModel.node( '', offset) attachNode.attach(area) area.setup(g_borderVisualSettings.modelPath, (1, 1), g_borderVisualSettings.overTerrainHeight, 4294967295L) area.doYCutOff(False) area.enableAccurateCollision(False) return
def update(self, deltaTime): self.__oscillator.constraints = mathUtils.matrixScale(self.__yprDeviationConstraints, SniperAimingSystem.__CONSTRAINTS_MULTIPLIERS) l_curYaw, l_curPitch = self.__worldYawPitchToTurret(self.__g_curYaw, self.__g_curPitch) stabilizationOn = math.fabs(self._matrix.roll) < self.__stailizationLimit and SniperAimingSystem.__FILTER_ENABLED if stabilizationOn: l_curYaw, l_curNewPitch = self.__clampToLimits(l_curYaw, l_curPitch) else: l_curNewPitch = l_curPitch if stabilizationOn: newLocal = l_curPitch + (l_curNewPitch - l_curPitch) newGunMat = AimingSystems.getPlayerGunMat(l_curYaw, newLocal) new__g_curPitch = newGunMat.pitch new__g_curPitch = self.__pitchfilter.update(new__g_curPitch, deltaTime) globalDelta = new__g_curPitch - self.__g_curPitch else: globalDelta = l_curNewPitch - self.__idealPitch yprDelta = Vector3(l_curYaw - self.__idealYaw, globalDelta, 0.0) self.__oscillator.deviation = yprDelta self.__oscillator.update(deltaTime) l_curYaw = self.__idealYaw + self.__oscillator.deviation.x if stabilizationOn: l_curPitch = l_curPitch + self.__oscillator.deviation.y else: l_curPitch = self.__idealPitch + self.__oscillator.deviation.y l_curYaw, l_newCurPitch = self.__clampToLimits(l_curYaw, l_curPitch) if not stabilizationOn: globalDelta = l_newCurPitch - self.__idealPitch l_curPitch = l_newCurPitch yprDelta = Vector3(l_curYaw - self.__idealYaw, globalDelta, 0.0) self.__oscillator.deviation = yprDelta currentGunMat = AimingSystems.getPlayerGunMat(l_curYaw, l_curPitch) self.__g_curYaw = currentGunMat.yaw self.__g_curPitch = currentGunMat.pitch stabilizedRoll = self.__getStabilizedRoll(l_curYaw, l_curPitch) stabRollMatrix = mathUtils.createRTMatrix(Vector3(currentGunMat.yaw, currentGunMat.pitch, stabilizedRoll), currentGunMat.translation) self._matrix.set(stabRollMatrix) return 0.0
def __update(self): worldMatrix = Matrix(self.__cam.invViewMatrix) desiredPosition = self.__basisMProv.checkTurretDetachment(worldMatrix.translation) if desiredPosition is not None: self.__position = desiredPosition prevPos = Math.Vector3(self.__position) delta = self.__calcCurrentDeltaAdjusted() self.__updateSenses(delta) self.__rotationRadius += self.__targetRadiusSensor.currentVelocity * delta if self.__isVerticalVelocitySeparated: self.__verticalMovementSensor.update(delta) else: self.__verticalMovementSensor.currentVelocity = self.__movementSensor.currentVelocity.y self.__verticalMovementSensor.sensitivity = self.__movementSensor.sensitivity if self.__inertiaEnabled: self.__inertialMovement(delta) else: self.__simpleMovement(delta) self.__ypr += self.__yprVelocity * delta self.__position += self.__velocity * delta if self.__rotateAroundPointEnabled: self.__position = self.__getAlignedToPointPosition(mathUtils.createRotationMatrix(self.__ypr)) if self.__alignerToLand.enabled and not self.__basisMProv.isBound: if abs(self.__velocity.y) > 0.1: self.__alignerToLand.enable(self.__position, self.__alignerToLand.ignoreTerrain) self.__position = self.__alignerToLand.getAlignedPosition(self.__position) lookAtPosition = self.__basisMProv.lookAtPosition if lookAtPosition is not None: self.__ypr = self.__getLookAtYPR(lookAtPosition) self.__ypr = self.__clampYPR(self.__ypr) self.__position = self.__checkSpaceBounds(prevPos, self.__position) self.__cam.invViewProvider.a = mathUtils.createRTMatrix(self.__ypr, self.__position) self.__cam.invViewProvider.b = self.__basisMProv.matrix BigWorld.projection().fov = self.__calcFov() self.__resetSenses() return 0.0
def getGunJointMat(vehicleTypeDescriptor, turretMatrix, gunPitch): gunOffset = vehicleTypeDescriptor.turret['gunPosition'] gunMat = mathUtils.createRTMatrix(Vector3(0, gunPitch, 0), gunOffset) gunMat.postMultiply(turretMatrix) return gunMat
def getTurretJointMat(vehicleTypeDescriptor, vehicleMatrix, turretYaw = 0.0): turretOffset = vehicleTypeDescriptor.chassis['hullPosition'] + vehicleTypeDescriptor.hull['turretPositions'][0] turretJointMat = mathUtils.createRTMatrix(Vector3(turretYaw, 0, 0), turretOffset) turretJointMat.postMultiply(vehicleMatrix) return turretJointMat
def __updateCameraLocation(self): position, yaw, pitch = self.__updateCalculateParams(self.__curTime) mat = mathUtils.createRTMatrix(Math.Vector3(yaw, pitch, 0.0), position) self.__camera.setWorldMatrix(mat) self.__updateDynamicFOV(self.__curTime)