Exemple #1
0
def createSRTMatrix(scale, rotation, translation):
    scaleMatrix = Matrix()
    scaleMatrix.setScale(scale)
    result = Matrix()
    result.setRotateYPR(rotation)
    result.translation = translation
    result.preMultiply(scaleMatrix)
    return result
Exemple #2
0
def createSRTMatrix(scale, rotation, translation):
    scaleMatrix = Matrix()
    scaleMatrix.setScale(scale)
    result = Matrix()
    result.setRotateYPR(rotation)
    result.translation = translation
    result.preMultiply(scaleMatrix)
    return result
    def decodeHitPoints(encodedPoints, collisionComponent):
        resultPoints = []
        maxHitEffectCode = None
        maxDamagedComponentName = None
        for encodedPoint in encodedPoints:
            compIdx, hitEffectCode, startPoint, endPoint = DamageFromShotDecoder.decodeSegment(
                encodedPoint, collisionComponent)
            if startPoint == endPoint or compIdx < 0:
                continue
            if hitEffectCode > maxHitEffectCode:
                maxHitEffectCode = hitEffectCode
                maxDamagedComponentName = TankPartIndexes.getName(compIdx)
            hitTestRes = collisionComponent.collideLocal(
                compIdx, startPoint, endPoint)
            bbox = collisionComponent.getBoundingBox(compIdx)
            if not hitTestRes or hitTestRes < 0.0:
                width, height, depth = (bbox[1] - bbox[0]) / 256.0
                directions = [
                    Math.Vector3(0.0, -height, 0.0),
                    Math.Vector3(0.0, height, 0.0),
                    Math.Vector3(-width, 0.0, 0.0),
                    Math.Vector3(width, 0.0, 0.0),
                    Math.Vector3(0.0, 0.0, -depth),
                    Math.Vector3(0.0, 0.0, depth)
                ]
                for direction in directions:
                    hitTestRes = collisionComponent.collideLocal(
                        compIdx, startPoint + direction, endPoint + direction)
                    if hitTestRes >= 0.0:
                        break

            if hitTestRes is None or hitTestRes < 0.0:
                newPoint = collisionComponent.collideLocalPoint(
                    compIdx, startPoint, MAX_FALLBACK_CHECK_DISTANCE)
                if newPoint.length > 0.0:
                    hitRay = endPoint - startPoint
                    hitTestRes = hitRay.length
                    endPoint = newPoint
                    startPoint = endPoint - hitRay
            if hitTestRes is None or hitTestRes < 0.0:
                continue
            minDist = hitTestRes
            hitDir = endPoint - startPoint
            hitDir.normalise()
            rot = Matrix()
            rot.setRotateYPR((hitDir.yaw, hitDir.pitch, 0.0))
            matrix = Matrix()
            matrix.setTranslate(startPoint + hitDir * minDist)
            matrix.preMultiply(rot)
            effectGroup = DamageFromShotDecoder.__hitEffectCodeToEffectGroup[
                hitEffectCode]
            componentName = TankPartIndexes.getName(compIdx)
            resultPoints.append(
                DamageFromShotDecoder.ShotPoint(componentName, matrix,
                                                effectGroup))

        return (maxHitEffectCode, resultPoints, maxDamagedComponentName)
Exemple #4
0
    def decodeHitPoints(encodedPoints, vehicleDescr):
        resultPoints = []
        maxHitEffectCode = None
        maxDamagedComponentName = None
        for encodedPoint in encodedPoints:
            compName, hitEffectCode, startPoint, endPoint = DamageFromShotDecoder.decodeSegment(
                encodedPoint, vehicleDescr)
            if startPoint == endPoint:
                continue
            if hitEffectCode > maxHitEffectCode:
                maxHitEffectCode = hitEffectCode
                maxDamagedComponentName = compName
            hitTester = getattr(vehicleDescr, compName).hitTester
            hitTestRes = hitTester.localHitTest(startPoint, endPoint)
            if not hitTestRes:
                width, height, depth = (hitTester.bbox[1] -
                                        hitTester.bbox[0]) / 256.0
                directions = [
                    Math.Vector3(0.0, -height, 0.0),
                    Math.Vector3(0.0, height, 0.0),
                    Math.Vector3(-width, 0.0, 0.0),
                    Math.Vector3(width, 0.0, 0.0),
                    Math.Vector3(0.0, 0.0, -depth),
                    Math.Vector3(0.0, 0.0, depth)
                ]
                for direction in directions:
                    hitTestRes = hitTester.localHitTest(
                        startPoint + direction, endPoint + direction)
                    if hitTestRes is not None:
                        break

                if hitTestRes is None:
                    continue
            minDist = hitTestRes[0][0]
            for i in xrange(1, len(hitTestRes)):
                dist = hitTestRes[i][0]
                if dist < minDist:
                    minDist = dist

            hitDir = endPoint - startPoint
            hitDir.normalise()
            rot = Matrix()
            rot.setRotateYPR((hitDir.yaw, hitDir.pitch, 0.0))
            matrix = Matrix()
            matrix.setTranslate(startPoint + hitDir * minDist)
            matrix.preMultiply(rot)
            effectGroup = DamageFromShotDecoder.__hitEffectCodeToEffectGroup[
                hitEffectCode]
            resultPoints.append(
                DamageFromShotDecoder.ShotPoint(compName, matrix, effectGroup))

        return (maxHitEffectCode, resultPoints, maxDamagedComponentName)
Exemple #5
0
    def decodeHitPoints(encodedPoints, vehicleDescr):
        resultPoints = []
        maxHitEffectCode = None
        for encodedPoint in encodedPoints:
            compName, hitEffectCode, startPoint, endPoint = DamageFromShotDecoder.decodeSegment(
                encodedPoint, vehicleDescr
            )
            if startPoint == endPoint:
                continue
            maxHitEffectCode = max(hitEffectCode, maxHitEffectCode)
            hitTester = getattr(vehicleDescr, compName)["hitTester"]
            hitTestRes = hitTester.localHitTest(startPoint, endPoint)
            if not hitTestRes:
                width, height, depth = (hitTester.bbox[1] - hitTester.bbox[0]) / 256.0
                directions = [
                    Math.Vector3(0.0, -height, 0.0),
                    Math.Vector3(0.0, height, 0.0),
                    Math.Vector3(-width, 0.0, 0.0),
                    Math.Vector3(width, 0.0, 0.0),
                    Math.Vector3(0.0, 0.0, -depth),
                    Math.Vector3(0.0, 0.0, depth),
                ]
                for direction in directions:
                    hitTestRes = hitTester.localHitTest(startPoint + direction, endPoint + direction)
                    if hitTestRes is not None:
                        break

                if hitTestRes is None:
                    continue
            minDist = hitTestRes[0][0]
            for i in xrange(1, len(hitTestRes)):
                dist = hitTestRes[i][0]
                if dist < minDist:
                    minDist = dist

            hitDir = endPoint - startPoint
            hitDir.normalise()
            rot = Matrix()
            rot.setRotateYPR((hitDir.yaw, hitDir.pitch, 0.0))
            matrix = Matrix()
            matrix.setTranslate(startPoint + hitDir * minDist)
            matrix.preMultiply(rot)
            effectGroup = DamageFromShotDecoder.__hitEffectCodeToEffectGroup[hitEffectCode]
            resultPoints.append(DamageFromShotDecoder.ShotPoint(compName, matrix, effectGroup))

        return (maxHitEffectCode, resultPoints)
class CircularFlyer(BigWorld.UserDataObject):

    def __init__(self):
        BigWorld.UserDataObject.__init__(self)
        self.__prevTime = BigWorld.time()
        self.__angularVelocity = 2 * math.pi / self.rotationPeriod
        if not self.rotateClockwise:
            self.__angularVelocity *= -1
        self.__currentAngle = 0.0
        self.__updateCallbackId = None
        self.__model = None
        self.__modelMatrix = None
        self.__sound = None
        BigWorld.loadResourceListBG((self.modelName, self.pixieName), self.__onResourcesLoaded)
        return

    def __del__(self):
        self.__clear()

    def __clear(self):
        if self.__updateCallbackId is not None:
            BigWorld.cancelCallback(self.__updateCallbackId)
        self.__updateCallbackId = None
        if self.__sound is not None:
            self.__sound.stop()
            self.__sound = None
        if self.__model is not None:
            BigWorld.delModel(self.__model)
            self.__model = None
        return

    def __onResourcesLoaded(self, resourceRefs):
        if self.guid not in BigWorld.userDataObjects:
            return
        else:
            self.__clear()
            if self.modelName in resourceRefs.failedIDs:
                return
            try:
                self.__model = resourceRefs[self.modelName]
                self.__modelMatrix = Matrix()
                self.__modelMatrix.setIdentity()
                servo = BigWorld.Servo(self.__modelMatrix)
                self.__model.addMotor(servo)
                BigWorld.addModel(self.__model)
                if self.actionName != '':
                    action = self.__model.action(self.actionName)
                    if action is not None:
                        action()
                if self.pixieName != '' and self.pixieName not in resourceRefs.failedIDs:
                    pixieNode = self.__model.node(self.pixieHardPoint)
                    pixieNode.attach(resourceRefs[self.pixieName])
                if self.soundName != '':
                    self.__sound = SoundGroups.g_instance.playSoundModel(self.__model, self.soundName)
            except:
                LOG_CURRENT_EXCEPTION()
                self.__model = None
                return

            self.__prevTime = BigWorld.time()
            self.__update()
            return

    def __update(self):
        self.__updateCallbackId = None
        self.__updateCallbackId = BigWorld.callback(0.0, self.__update)
        curTime = BigWorld.time()
        dt = curTime - self.__prevTime
        self.__prevTime = curTime
        self.__currentAngle += self.__angularVelocity * dt
        if self.__currentAngle > 2 * math.pi:
            self.__currentAngle -= 2 * math.pi
        elif self.__currentAngle < -2 * math.pi:
            self.__currentAngle += 2 * math.pi
        radialPosition = Vector3(self.radius * math.sin(self.__currentAngle), 0, self.radius * math.cos(self.__currentAngle))
        modelYaw = self.__currentAngle
        if self.rotateClockwise:
            modelYaw += math.pi / 2
        else:
            modelYaw -= math.pi / 2
        localMatrix = Matrix()
        localMatrix.setRotateY(modelYaw)
        localMatrix.translation = radialPosition
        self.__modelMatrix.setRotateYPR((self.yaw, self.pitch, self.roll))
        self.__modelMatrix.translation = self.position
        self.__modelMatrix.preMultiply(localMatrix)
        return
class CircularFlyer(BigWorld.UserDataObject):
    def __init__(self):
        BigWorld.UserDataObject.__init__(self)
        self.__prevTime = BigWorld.time()
        self.__angularVelocity = 2 * math.pi / self.rotationPeriod
        if not self.rotateClockwise:
            self.__angularVelocity *= -1
        self.__currentAngle = 0.0
        self.__updateCallbackId = None
        self.__model = None
        self.__modelMatrix = None
        self.__sound = None
        BigWorld.loadResourceListBG((self.modelName, self.pixieName),
                                    self.__onResourcesLoaded)
        return

    def __del__(self):
        self.__clear()

    def __clear(self):
        if self.__updateCallbackId is not None:
            BigWorld.cancelCallback(self.__updateCallbackId)
        self.__updateCallbackId = None
        if self.__sound is not None:
            self.__sound.stop()
            self.__sound.releaseMatrix()
            self.__sound = None
        if self.__model is not None:
            BigWorld.delModel(self.__model)
            self.__model = None
        return

    def __onResourcesLoaded(self, resourceRefs):
        if self.guid not in BigWorld.userDataObjects:
            return
        else:
            self.__clear()
            if self.modelName in resourceRefs.failedIDs:
                return
            try:
                self.__model = resourceRefs[self.modelName]
                self.__modelMatrix = Matrix()
                self.__modelMatrix.setIdentity()
                servo = BigWorld.Servo(self.__modelMatrix)
                self.__model.addMotor(servo)
                BigWorld.addModel(self.__model)
                if self.actionName != '':
                    action = self.__model.action(self.actionName)
                    if action is not None:
                        action()
                if self.pixieName != '' and self.pixieName not in resourceRefs.failedIDs:
                    pixieNode = self.__model.node(self.pixieHardPoint)
                    pixieNode.attach(resourceRefs[self.pixieName])
                if self.soundName != '':
                    self.__sound = SoundGroups.g_instance.getSound3D(
                        self.__modelMatrix, self.soundName)
            except:
                LOG_CURRENT_EXCEPTION()
                self.__model = None
                return

            self.__prevTime = BigWorld.time()
            self.__update()
            return

    def __update(self):
        self.__updateCallbackId = None
        self.__updateCallbackId = BigWorld.callback(0.0, self.__update)
        curTime = BigWorld.time()
        dt = curTime - self.__prevTime
        self.__prevTime = curTime
        self.__currentAngle += self.__angularVelocity * dt
        if self.__currentAngle > 2 * math.pi:
            self.__currentAngle -= 2 * math.pi
        elif self.__currentAngle < -2 * math.pi:
            self.__currentAngle += 2 * math.pi
        radialPosition = Vector3(self.radius * math.sin(self.__currentAngle),
                                 0,
                                 self.radius * math.cos(self.__currentAngle))
        modelYaw = self.__currentAngle
        if self.rotateClockwise:
            modelYaw += math.pi / 2
        else:
            modelYaw -= math.pi / 2
        localMatrix = Matrix()
        localMatrix.setRotateY(modelYaw)
        localMatrix.translation = radialPosition
        self.__modelMatrix.setRotateYPR((self.yaw, self.pitch, self.roll))
        self.__modelMatrix.translation = self.position
        self.__modelMatrix.preMultiply(localMatrix)
        return
 def __worldYawPitchToTurret(self, worldYaw, worldPitch):
     worldToTurret = Matrix(self.__vehicleMProv)
     worldToTurret.invert()
     worldToTurret.preMultiply(
         mathUtils.createRotationMatrix((worldYaw, worldPitch, 0.0)))
     return (worldToTurret.yaw, worldToTurret.pitch)
 def __worldYawPitchToTurret(self, worldYaw, worldPitch):
     worldToTurret = Matrix(self.__vehicleMProv)
     worldToTurret.invert()
     worldToTurret.preMultiply(mathUtils.createRotationMatrix((worldYaw, worldPitch, 0.0)))
     return (worldToTurret.yaw, worldToTurret.pitch)
    def decodeHitPoints(cls,
                        encodedPoints,
                        collisionComponent,
                        maxComponentIdx=TankPartIndexes.ALL[-1],
                        vehicleDesc=None):
        resultPoints = []
        for encodedPoint in encodedPoints:
            compIdx, hitEffectCode, startPoint, endPoint = DamageFromShotDecoder.decodeSegment(
                encodedPoint, collisionComponent, maxComponentIdx, vehicleDesc)
            if startPoint == endPoint or compIdx < 0:
                continue
            convertedCompIdx = DamageFromShotDecoder.convertComponentIndex(
                compIdx, vehicleDesc)
            hitTestRes = collisionComponent.collideLocal(
                convertedCompIdx, startPoint, endPoint)
            bbox = collisionComponent.getBoundingBox(convertedCompIdx)
            if not hitTestRes or hitTestRes < 0.0:
                width, height, depth = (bbox[1] - bbox[0]) / 256.0
                directions = [
                    Math.Vector3(0.0, -height, 0.0),
                    Math.Vector3(0.0, height, 0.0),
                    Math.Vector3(-width, 0.0, 0.0),
                    Math.Vector3(width, 0.0, 0.0),
                    Math.Vector3(0.0, 0.0, -depth),
                    Math.Vector3(0.0, 0.0, depth)
                ]
                for direction in directions:
                    hitTestRes = collisionComponent.collideLocal(
                        convertedCompIdx, startPoint + direction,
                        endPoint + direction)
                    if hitTestRes >= 0.0:
                        break

            if hitTestRes is None or hitTestRes < 0.0:
                newPoint = collisionComponent.collideLocalPoint(
                    convertedCompIdx, startPoint, MAX_FALLBACK_CHECK_DISTANCE)
                if newPoint.length > 0.0:
                    hitRay = endPoint - startPoint
                    hitTestRes = hitRay.length
                    endPoint = newPoint
                    startPoint = endPoint - hitRay
            if hitTestRes is None or hitTestRes < 0.0:
                continue
            minDist = hitTestRes
            hitDir = endPoint - startPoint
            hitDir.normalise()
            rot = Matrix()
            rot.setRotateYPR((hitDir.yaw, hitDir.pitch, 0.0))
            matrix = Matrix()
            matrix.setTranslate(startPoint + hitDir * minDist)
            matrix.preMultiply(rot)
            effectGroup = cls._HIT_EFFECT_CODE_TO_EFFECT_GROUP[hitEffectCode]
            componentName = TankPartIndexes.getName(compIdx)
            if not componentName and convertedCompIdx < 0:
                componentName = collisionComponent.getPartName(
                    convertedCompIdx)
            if not componentName:
                componentName = TankPartNames.CHASSIS
            resultPoints.append(
                DamageFromShotDecoder.ShotPoint(componentName, matrix,
                                                hitEffectCode, effectGroup))

        return resultPoints