예제 #1
0
파일: dustPins.py 프로젝트: R4M80MrX/eve-1
 def SetModel(self, scale):
     graphic = cfg.invtypes.Get(self.pinKv.typeID).Graphic()
     self.model = None
     if graphic and graphic.graphicFile:
         graphicFile = str(graphic.graphicFile)
         graphicFile = graphicFile.replace(':/model',
                                           ':/dx9/model').replace(
                                               '.blue', '.red')
         self.model = trinity.Load(graphicFile)
     if not self.model or self.model.__bluetype__ != 'trinity.EveTransform':
         self.model = trinity.Load(
             'res:/dx9/model/worldobject/Orbital/UI/Terrestrial/Command/CommT_T1/CommT_T1.red'
         )
     if not self.model:
         return
     EXT = 1.026
     self.model.scaling = (scale, scale, scale)
     self.model.sortValueMultiplier = 0.5
     self.model.translation = (EXT * self.surfacePoint.x,
                               EXT * self.surfacePoint.y,
                               EXT * self.surfacePoint.z)
     plnSurfRotMat = geo2.MatrixRotationAxis(
         geo2.Vec3Cross(
             geo2.Vec3Normalize(self.surfacePoint.GetAsXYZTuple()),
             (0.0, 1.0, 0.0)), -math.acos(
                 geo2.Vec3Dot(
                     geo2.Vec3Normalize(self.surfacePoint.GetAsXYZTuple()),
                     (0.0, 1.0, 0.0))))
     rotQuat = geo2.QuaternionRotationMatrix(plnSurfRotMat)
     self.model.rotation = rotQuat
     self.model.name = '%s,%s' % (planetCommon.PINTYPE_NORMAL,
                                  self.pinKv.id)
     self.transform.children.append(self.model)
예제 #2
0
 def GetYawPitch(self):
     rotMatrix = geo2.MatrixTranspose(self.viewMatrix.transform)
     quat = geo2.QuaternionRotationMatrix(rotMatrix)
     yaw, pitch, roll = geo2.QuaternionRotationGetYawPitchRoll(quat)
     yaw = math.pi / 2 - yaw
     pitch = math.pi / 2 - pitch
     return (yaw, pitch)
예제 #3
0
 def AlignToDirection(self, direction):
     """Align the space object to a direction."""
     if not self.model:
         return
     zaxis = direction
     if geo2.Vec3LengthSqD(zaxis) > 0.0:
         zaxis = geo2.Vec3NormalizeD(zaxis)
         xaxis = geo2.Vec3CrossD(zaxis, (0, 1, 0))
         if geo2.Vec3LengthSqD(xaxis) == 0.0:
             zaxis = geo2.Vec3AddD(zaxis, mathCommon.RandomVector(0.0001))
             zaxis = geo2.Vec3NormalizeD(zaxis)
             xaxis = geo2.Vec3CrossD(zaxis, (0, 1, 0))
         xaxis = geo2.Vec3NormalizeD(xaxis)
         yaxis = geo2.Vec3CrossD(xaxis, zaxis)
     else:
         self.LogError('Space object', self.id, 'has invalid direction (',
                       direction, '). Unable to rotate it.')
         return
     mat = ((xaxis[0], xaxis[1], xaxis[2], 0.0), (yaxis[0], yaxis[1],
                                                  yaxis[2], 0.0),
            (-zaxis[0], -zaxis[1], -zaxis[2], 0.0), (0.0, 0.0, 0.0, 1.0))
     quat = geo2.QuaternionRotationMatrix(mat)
     if hasattr(self.model, 'modelRotationCurve'):
         if not self.model.modelRotationCurve:
             self.model.modelRotationCurve = trinity.TriRotationCurve(
                 0.0, 0.0, 0.0, 1.0)
         self.model.modelRotationCurve.value = quat
     else:
         self.model.rotationCurve = None
예제 #4
0
 def AlignToDirection(self):
     destination = sm.StartService('space').warpDestinationCache[3]
     ballPark = sm.StartService('michelle').GetBallpark()
     egoball = ballPark.GetBall(ballPark.ego)
     direction = [
         egoball.x - destination[0], egoball.y - destination[1],
         egoball.z - destination[2]
     ]
     zaxis = direction
     if geo2.Vec3LengthSqD(zaxis) > 0.0:
         zaxis = geo2.Vec3NormalizeD(zaxis)
         xaxis = geo2.Vec3CrossD((0, 1, 0), zaxis)
         if geo2.Vec3LengthSqD(xaxis) == 0.0:
             zaxis = geo2.Vec3AddD(zaxis, mathCommon.RandomVector(0.0001))
             zaxis = geo2.Vec3NormalizeD(zaxis)
             xaxis = geo2.Vec3CrossD((0, 1, 0), zaxis)
         xaxis = geo2.Vec3NormalizeD(xaxis)
         yaxis = geo2.Vec3CrossD(zaxis, xaxis)
     else:
         self.transformFlags = effectconsts.FX_TF_POSITION_BALL | effectconsts.FX_TF_ROTATION_BALL
         self.Prepare()
         return
     mat = ((xaxis[0], xaxis[1], xaxis[2], 0.0), (yaxis[0], yaxis[1],
                                                  yaxis[2], 0.0),
            (zaxis[0], zaxis[1], zaxis[2], 0.0), (0.0, 0.0, 0.0, 1.0))
     quat = geo2.QuaternionRotationMatrix(mat)
     self.gfxModel.rotationCurve = None
     if self.gfxModel and hasattr(self.gfxModel, 'modelRotationCurve'):
         self.gfxModel.modelRotationCurve = trinity.TriRotationCurve(
             0.0, 0.0, 0.0, 1.0)
         self.gfxModel.modelRotationCurve.value = quat
     self.debugAligned = True
예제 #5
0
 def AlignToDirection(self, direction):
     zaxis = Vector3(direction)
     if zaxis.Length2() > 0.0:
         Up = Vector3([0.0, 1.0, 0.0])
         zaxis.Normalize()
         xaxis = zaxis ^ Up
         if xaxis.Length2() == 0.0:
             zaxis += Vector3().Randomize(0.0001)
             zaxis.Normalize()
             xaxis = zaxis ^ Up
         xaxis.Normalize()
         yaxis = xaxis ^ zaxis
     else:
         self.LogError('Space object', self.id,
                       'has zero dunDirection. I cannot rotate it.')
         return
     mat = ((xaxis[0], xaxis[1], xaxis[2], 0.0), (yaxis[0], yaxis[1],
                                                  yaxis[2], 0.0),
            (-zaxis[0], -zaxis[1], -zaxis[2], 0.0), (0.0, 0.0, 0.0, 1.0))
     quat = geo2.QuaternionRotationMatrix(mat)
     if self.model and self.HasBlueInterface(
             self.model, 'IEveSpaceObject2') and hasattr(
                 self.model, 'modelRotationCurve'):
         if not self.model.modelRotationCurve:
             self.model.modelRotationCurve = trinity.TriRotationCurve(
                 0.0, 0.0, 0.0, 1.0)
         self.model.modelRotationCurve.value = quat
     else:
         self.model.rotationCurve = None
예제 #6
0
 def SetAxis(self, xaxis, zaxis):
     self.xaxis = xaxis
     self.zaxis = zaxis
     yaxis = geo2.Vec3Normalize(geo2.Vec3Cross(zaxis, xaxis))
     self.rotation = geo2.QuaternionRotationMatrix((xaxis + (0,),
      yaxis + (0,),
      zaxis + (0,),
      (0, 0, 0, 1)))
예제 #7
0
 def PointToYawPitchDist(self, pos):
     upVector = (0, 1, 0)
     if trinity.IsRightHanded():
         rotMatrix = geo2.MatrixLookAtRH(pos, self.poi, upVector)
     else:
         rotMatrix = geo2.MatrixLookAtLH(pos, self.poi, upVector)
     rotMatrix = geo2.MatrixTranspose(rotMatrix)
     quat = geo2.QuaternionRotationMatrix(rotMatrix)
     yaw, pitch, roll = geo2.QuaternionRotationGetYawPitchRoll(quat)
     yaw = math.pi / 2 - yaw
     pitch = math.pi / 2 - pitch
     return (yaw, pitch, geo2.Vec3Distance(pos, self.poi))
예제 #8
0
파일: Warp.py 프로젝트: R4M80MrX/eve-1
 def AlignToDirection(self):
     destination = sm.StartService('space').warpDestinationCache[3]
     ballPark = sm.StartService('michelle').GetBallpark()
     egoball = ballPark.GetBall(ballPark.ego)
     direction = [egoball.x - destination[0], egoball.y - destination[1], egoball.z - destination[2]]
     zaxis = Vector3(direction)
     if zaxis.Length2() > 0.0:
         Up = Vector3([0.0, 1.0, 0.0])
         zaxis.Normalize()
         xaxis = Up ^ zaxis
         if xaxis.Length2() == 0.0:
             zaxis += Vector3().Randomize(0.0001)
             zaxis.Normalize()
             xaxis = Up ^ zaxis
         xaxis.Normalize()
         yaxis = zaxis ^ xaxis
     else:
         self.transformFlags = effects.FX_TF_POSITION_BALL | effects.FX_TF_ROTATION_BALL
         self.Prepare()
         return
     mat = ((xaxis[0],
       xaxis[1],
       xaxis[2],
       0.0),
      (yaxis[0],
       yaxis[1],
       yaxis[2],
       0.0),
      (zaxis[0],
       zaxis[1],
       zaxis[2],
       0.0),
      (0.0, 0.0, 0.0, 1.0))
     quat = geo2.QuaternionRotationMatrix(mat)
     self.gfxModel.rotationCurve = None
     if self.gfxModel and hasattr(self.gfxModel, 'modelRotationCurve'):
         self.gfxModel.modelRotationCurve = trinity.TriRotationCurve(0.0, 0.0, 0.0, 1.0)
         self.gfxModel.modelRotationCurve.value = quat
     self.debugAligned = True
예제 #9
0
    def _UpdateCameraAnimation(self,
                               alignToParent=False,
                               alignTargets=None,
                               loop=False,
                               clipName=None,
                               parent=None):
        def FindParametersInPostFx():
            blurScaleH = None
            blurScaleV = None
            blurFade = None
            exposure = None
            rj = self.GetRenderJob()
            if rj:
                for step in rj.steps:
                    if step.name == 'RJ_POSTPROCESSING':
                        if step.job:
                            for jobStep in step.job.steps:
                                if jobStep.name == 'PostProcess Blur':
                                    for fx in jobStep.PostProcess.stages:
                                        for param in fx.parameters:
                                            if param.name == 'ScalingFactor':
                                                if fx.name == 'Gaussian Horizontal Blur':
                                                    blurScaleH = param
                                                if fx.name == 'Gaussianl Vertical Blur':
                                                    blurScaleV = param
                                                if fx.name == '4x Up Filter and Add':
                                                    blurFade = param

                                if jobStep.name == 'PostProcess Exposure':
                                    for fx in jobStep.PostProcess.stages:
                                        for param in fx.parameters:
                                            if param.name == 'ScalingFactor':
                                                if fx.name == '4x Up Filter and Add':
                                                    exposure = param

            return (blurScaleH, blurScaleV, blurFade, exposure)

        transformTrack = None
        shakeSequencer = None
        duration = 0.0
        curveSetName = 'AnimatedCamera'
        scene = sm.GetService('sceneManager').GetRegisteredScene('default')
        viewStep, proj = self.GetViewAndProjection()
        camera = viewStep.camera
        for cset in scene.curveSets:
            if cset.name == curveSetName:
                transformTrack = cset.curves[0]
                if len(cset.curves) > 1:
                    shakeSequencer = cset.curves[1]

        duration = transformTrack.duration - 1 / 10.0
        oldFov = camera.fieldOfView
        ppJob.AddPostProcess('Blur', 'res:/fisfx/postprocess/blur.red')
        ppJob.AddPostProcess('Exposure', 'res:/fisfx/postprocess/exposure.red')
        blurScaleH, blurScaleV, blurFade, exposure = FindParametersInPostFx()
        ballpark = sm.GetService('michelle').GetBallpark()
        ball = ballpark.GetBall(session.shipid)
        if parent:
            ball = parent.translationCurve
        if alignTargets:
            ball = alignTargets[0]
        if viewStep:
            viewStep.view = trinity.TriView()
        startTime = blue.os.GetSimTime()
        if loop:
            endTime = startTime + 36000000000L
        else:
            endTime = startTime + duration * 10000000
        time = startTime
        globalSceneScale = 4.0 / 30.0 * ball.model.boundingSphereRadius
        lastWorldPos = None
        lastWorldRot = None
        while time < endTime and not self.resetCamera and not self.interrupt:
            time = blue.os.GetSimTime()
            weight1 = 0.0
            weight2 = 0.0
            if self.vectorTracks:
                currentTime = trinity.device.animationTime
                for cvt in self.vectorTracks:
                    if cvt == 'targetWeight1' or cvt == 'targetWeight2':
                        vecTrack = self.vectorTracks[cvt]
                        if cvt == 'targetWeight1':
                            weight1 = vecTrack.value
                        else:
                            weight2 = vecTrack.value

            if viewStep:
                trans = geo2.MatrixTranslation(
                    transformTrack.translation[0] * globalSceneScale,
                    transformTrack.translation[1] * globalSceneScale,
                    transformTrack.translation[2] * globalSceneScale)
                rot = geo2.MatrixRotationQuaternion(transformTrack.rotation)
                comp = geo2.MatrixMultiply(rot, trans)
                if alignToParent:
                    if not ball.model and lastWorldPos:
                        translation = lastWorldPos
                        rotation = lastWorldRot
                    else:
                        rotation = ball.GetQuaternionAt(time)
                        translation = ball.model.worldPosition
                    lastWorldPos = translation
                    lastWorldRot = rotation
                    transOffset = geo2.MatrixTranslation(
                        translation[0], translation[1], translation[2])
                    rotOffset = geo2.MatrixRotationQuaternion(
                        (rotation.x, rotation.y, rotation.z, rotation.w))
                    comp = geo2.MatrixMultiply(comp, rotOffset)
                    comp = geo2.MatrixMultiply(comp, transOffset)
                if alignTargets:
                    t1 = alignTargets[0].model.worldPosition
                    t2 = alignTargets[1].model.worldPosition
                    if True:
                        sphereOffset = alignTargets[
                            1].model.boundingSphereCenter
                        qr = alignTargets[
                            1].model.rotationCurve.GetQuaternionAt(time)
                        quatRotation = (qr.x, qr.y, qr.z, qr.w)
                        correctedOffset = geo2.QuaternionTransformVector(
                            quatRotation, sphereOffset)
                        t2 = geo2.Vec3Add(t2, correctedOffset)
                    rot = geo2.MatrixLookAtRH(t2, t1, (0.0, 1.0, 0.0))
                    rot = geo2.MatrixInverse(rot)
                    rot = (rot[0], rot[1], rot[2], (t1[0], t1[1], t1[2], 1.0))
                    comp = geo2.MatrixMultiply(comp, rot)
                    if weight1 > 0.0001:
                        shake = shakeSequencer.value
                        pos = (comp[3][0], comp[3][1], comp[3][2])
                        targetPos = (t2[0] + shake.x, t2[1] + shake.y,
                                     t2[2] + shake.z)
                        lookat = geo2.MatrixLookAtRH(pos, targetPos,
                                                     (0.0, 1.0, 0.0))
                        lookat = geo2.MatrixInverse(lookat)
                        qlookat = geo2.QuaternionRotationMatrix(lookat)
                        qorig = geo2.QuaternionRotationMatrix(comp)
                        qresult = geo2.Lerp(qorig, qlookat, weight1)
                        mresult = geo2.MatrixRotationQuaternion(qresult)
                        comp = (mresult[0], mresult[1], mresult[2], comp[3])
                if viewStep.view:
                    viewStep.view.transform = geo2.MatrixInverse(comp)
            if self.vectorTracks:
                currentTime = trinity.device.animationTime
                for cvt in self.vectorTracks:
                    if cvt == 'fov':
                        vecTrack = self.vectorTracks['fov']
                        fovValue = vecTrack.value
                        camera.fieldOfView = fovValue
                        proj.projection.PerspectiveFov(
                            fovValue, trinity.device.width /
                            float(trinity.device.height), camera.frontClip,
                            camera.backClip)
                    if cvt == 'blur':
                        vecTrack = self.vectorTracks['blur']
                        blurValue = vecTrack.value
                        if blurScaleH and blurScaleV and blurFade:
                            blurScaleH.value = blurValue
                            blurScaleV.value = blurValue
                            if blurValue > 0.01:
                                blurFade.value = 1.0
                            else:
                                blurFade.value = 0.0
                    if cvt == 'exposure':
                        vecTrack = self.vectorTracks['exposure']
                        exposureValue = vecTrack.value
                        if exposure:
                            exposure.value = exposureValue

                if 'fov' not in self.vectorTracks:
                    camera.fieldOfView = oldFov
                    proj.projection.PerspectiveFov(
                        oldFov,
                        trinity.device.width / float(trinity.device.height),
                        camera.frontClip, camera.backClip)
            blue.synchro.Yield()

        if exposure and blurFade:
            exposure.value = 0.0
            blurFade.value = 0.0
        if viewStep:
            viewStep.view = None
        camera.fieldOfView = oldFov
        if not self.interrupt:
            if not camera.fieldOfView == 1.0:
                self.LogWarn('Warning: Camera fov not 1, correcting...')
                camera.fieldOfView = 1.0
            proj.projection = camera.projectionMatrix
        self.playingClip = False
        if self.continuousType and not self.interrupt and not self.resetCamera:
            self.interrupt = False
            self.UpdateContinuous()
        self.resetCamera = False
        self.interrupt = False
        if clipName:
            self.LogInfo('Camera clip done:', clipName)
예제 #10
0
def CreateMiniCollisionObject(name, miniballs, minicapsules, miniboxes):
    t = trinity.EveRootTransform()
    sphere = blue.resMan.LoadObject('res:/Model/Global/Miniball.red')
    capsule = blue.resMan.LoadObject('res:/Model/Global/Minicapsule.red')
    box = blue.resMan.LoadObject('res:/Model/Global/Minibox.red')
    if len(miniballs) > 0:
        for miniball in miniballs:
            mball = sphere.CopyTo()
            mball.translation = (miniball.x, miniball.y, miniball.z)
            r = miniball.radius * 2
            mball.scaling = (r, r, r)
            t.children.append(mball)

    for minicapsule in minicapsules:
        mcapsule = capsule.CopyTo()
        pointA = (minicapsule.ax, minicapsule.ay, minicapsule.az)
        pointB = (minicapsule.bx, minicapsule.by, minicapsule.bz)
        dir = geo2.Vec3Subtract(pointA, pointB)
        length = geo2.Vec3Length(dir)
        mcapsule.translation = geo2.Vec3Scale(geo2.Vec3Add(pointA, pointB),
                                              0.5)
        radius = minicapsule.radius
        pitch = math.acos(dir[1] / length)
        yaw = math.atan2(dir[0], dir[2])
        quat = geo2.QuaternionRotationSetYawPitchRoll(yaw, pitch, 0)
        mcapsule.rotation = quat
        for each in mcapsule.children:
            if each.name == 'Cylinder':
                height = length * each.scaling[1]
                rscaling = geo2.Vec3Scale((each.scaling[0], each.scaling[2]),
                                          radius)
                each.scaling = (rscaling[0], height, rscaling[1])
            else:
                each.scaling = geo2.Vec3Scale(each.scaling, radius)
                each.translation = geo2.Vec3Scale(each.translation, length)

        t.children.append(mcapsule)

    for minibox in miniboxes:
        mbox = box.CopyTo()
        corner = (minibox.c0, minibox.c1, minibox.c2)
        xAxis = (minibox.x0, minibox.x1, minibox.x2)
        yAxis = (minibox.y0, minibox.y1, minibox.y2)
        zAxis = (minibox.z0, minibox.z1, minibox.z2)
        xyzAxis = geo2.Vec3Add(xAxis, geo2.Vec3Add(yAxis, zAxis))
        center = geo2.Vec3Add(corner, geo2.Vec3Scale(xyzAxis, 0.5))
        xNormalized = geo2.Vec3Normalize(xAxis)
        yNormalized = geo2.Vec3Normalize(yAxis)
        zNormalized = geo2.Vec3Normalize(zAxis)
        rotationMatrix = ((xNormalized[0], xNormalized[1], xNormalized[2], 0),
                          (yNormalized[0], yNormalized[1], yNormalized[2],
                           0), (zNormalized[0], zNormalized[1], zNormalized[2],
                                0), (0, 0, 0, 1))
        rot = geo2.QuaternionRotationMatrix(rotationMatrix)
        mbox.translation = center
        mbox.scaling = geo2.Vec3Transform(
            (1, 1, 1),
            geo2.MatrixScaling(geo2.Vec3Length(xAxis), geo2.Vec3Length(yAxis),
                               geo2.Vec3Length(zAxis)))
        mbox.rotation = geo2.QuaternionNormalize(rot)
        t.children.append(mbox)

    t.name = name
    return t