예제 #1
0
    def Assemble(self):
        if self.model is None:
            self.LogError('Cannot Assemble Asteroid, model failed to load')
            return
        self.model.modelScale = self.radius
        pi = math.pi
        identity = trinity.TriQuaternion()
        cleanRotation = trinity.TriQuaternion()
        preRotation = trinity.TriQuaternion()
        postRotation = trinity.TriQuaternion()
        rotKey = trinity.TriQuaternion()
        r = random.Random()
        r.seed(self.id)
        preRotation.SetYawPitchRoll(r.random() * pi,
                                    r.random() * pi,
                                    r.random() * pi)
        postRotation.SetYawPitchRoll(r.random() * pi,
                                     r.random() * pi,
                                     r.random() * pi)
        curve = trinity.TriRotationCurve()
        curve.extrapolation = trinity.TRIEXT_CYCLE
        duration = 50.0 * math.log(self.radius)
        rdur = r.random() * 50.0 * math.log(self.radius)
        duration += rdur
        for i in [0.0, 0.5, 1.0, 1.5, 2.0]:
            cleanRotation.SetYawPitchRoll(0.0, pi * i, 0.0)
            rotKey.SetIdentity()
            rotKey.MultiplyQuaternion(preRotation)
            rotKey.MultiplyQuaternion(cleanRotation)
            rotKey.MultiplyQuaternion(postRotation)
            curve.AddKey(duration * i, rotKey, identity, identity,
                         trinity.TRIINT_SLERP)

        curve.Sort()
        self.model.modelRotationCurve = curve
예제 #2
0
    def RotateSelected(self, yaw, pitch, roll):
        slimItems = self.GetSelObjects()
        if len(slimItems) == 0:
            return
        nq = trinity.TriQuaternion()
        nq.SetYawPitchRoll(yaw / 180.0 * pi, pitch / 180.0 * pi,
                           roll / 180.0 * pi)
        posCtr = trinity.TriVector()
        for slimItem in slimItems:
            posCtr += trinity.TriVector(slimItem.dunX, slimItem.dunY,
                                        slimItem.dunZ)

        posCtr.Scale(1.0 / len(slimItems))
        for slimItem in slimItems:
            q = trinity.TriQuaternion()
            rot = getattr(slimItem, 'dunRotation', None)
            if rot is not None:
                yaw, pitch, roll = rot
                q.SetYawPitchRoll(yaw / 180.0 * pi, pitch / 180.0 * pi,
                                  roll / 180.0 * pi)
            q.Multiply(nq)
            y, p, r = q.GetYawPitchRoll()
            y = y / pi * 180.0
            p = p / pi * 180.0
            r = r / pi * 180.0
            translation = trinity.TriVector(slimItem.dunX, slimItem.dunY,
                                            slimItem.dunZ)
            translation -= posCtr
            translation.TransformQuaternion(nq)
            translation += posCtr
            dungeonHelper.SetObjectPosition(slimItem.dunObjectID,
                                            translation.x, translation.y,
                                            translation.z)
            dungeonHelper.SetObjectRotation(slimItem.dunObjectID, y, p, r)
예제 #3
0
def GeoToTri(obj):
    if len(obj) == 3:
        return trinity.TriVector(*obj)
    if len(obj) == 4:
        if isinstance(obj[0], tuple):
            tempTuple = obj[0] + obj[1] + obj[2] + obj[3]
            return trinity.TriMatrix(*tempTuple)
        else:
            return trinity.TriQuaternion(*obj)
    else:
        raise TypeError('Unsupported type')
예제 #4
0
    def Assemble(self):
        if self.model is None:
            self.LogError('Cannot Assemble Asteroid, model failed to load')
            return
        if self.HasBlueInterface(self.model, 'IEveSpaceObject2'):
            self.model.modelScale = self.radius
            pi = math.pi
            id = trinity.TriQuaternion()
            cleanRotation = trinity.TriQuaternion()
            preRotation = trinity.TriQuaternion()
            postRotation = trinity.TriQuaternion()
            rotKey = trinity.TriQuaternion()
            preRotation.SetYawPitchRoll(random.random() * pi,
                                        random.random() * pi,
                                        random.random() * pi)
            postRotation.SetYawPitchRoll(random.random() * pi,
                                         random.random() * pi,
                                         random.random() * pi)
            curve = trinity.TriRotationCurve()
            curve.extrapolation = trinity.TRIEXT_CYCLE
            duration = 50.0 + random.random() * 50.0 * math.log(self.radius)
            for i in [0.0, 0.5, 1.0, 1.5, 2.0]:
                cleanRotation.SetYawPitchRoll(0.0, pi * i, 0.0)
                rotKey.SetIdentity()
                rotKey.MultiplyQuaternion(preRotation)
                rotKey.MultiplyQuaternion(cleanRotation)
                rotKey.MultiplyQuaternion(postRotation)
                curve.AddKey(duration * i, rotKey, id, id,
                             trinity.TRIINT_SLERP)

            curve.Sort()
            self.model.modelRotationCurve = curve
        else:
            self.model.rotation.SetYawPitchRoll(random.random() * 6.28,
                                                random.random() * 6.28,
                                                random.random() * 6.28)
            timecurves.ResetTimeCurves(self.model, self.id * 12345L)
            timecurves.ScaleTime(self.model, 5.0 + self.id % 20 / 20.0)
            self.model.scaling.SetXYZ(self.radius, self.radius, self.radius)
            self.model.boundingSphereRadius = 1.0
예제 #5
0
파일: route.py 프로젝트: R4M80MrX/eve-1
    def DrawRoute(self,
                  destinations,
                  usePoints=False,
                  drawLines=False,
                  blinking=True,
                  flattened=False,
                  rotationQuaternion=None):
        if not len(destinations):
            self.destinations = []
            if self.model:
                self.model.diplay = False
            return
        if self.model:
            self.model.display = True
        else:
            self.model = trinity.Load(self.resPath)
            self.model.name = '__mapRoute'
            self.model.scaling = (self.ballScale, self.ballScale,
                                  self.ballScale)
            if not blinking:
                self.model.curveSets.removeAt(0)
            if drawLines:
                self.lineSet = trinity.EveLineSet()
                self.lineSet.effect = trinity.Tr2Effect()
                self.lineSet.effect.effectFilePath = LINESET_EFFECT
        transCurve = trinity.TriVectorCurve()
        transCurve.extrapolation = trinity.TRIEXT_CYCLE
        if type(rotationQuaternion
                ) != trinity.TriQuaternion and rotationQuaternion is not None:
            rotationQuaternion = trinity.TriQuaternion(*rotationQuaternion)
        if usePoints:
            for index, point in enumerate(destinations):
                pos = trinity.TriVector(*point)
                if flattened:
                    pos.y = 0.0
                if rotationQuaternion is not None:
                    pos.TransformQuaternion(rotationQuaternion)
                pos.Scale(self.scale)
                transCurve.AddKey(index * self.timeBase, pos,
                                  trinity.TriVector(), trinity.TriVector(),
                                  trinity.TRIINT_LINEAR)

            if drawLines:
                numPoints = len(destinations)
                for index in xrange(numPoints):
                    index2 = (index + 1) % numPoints
                    p1 = geo2.Vector(*destinations[index]) * self.scale
                    p2 = geo2.Vector(*destinations[index2]) * self.scale
                    self.lineSet.AddLine(p1, self.lineColor, p2,
                                         self.lineColor)

                self.lineSet.SubmitChanges()
        else:
            map = sm.StartService('map')
            for index, destinationID in enumerate(destinations):
                destination = cfg.evelocations.Get(destinationID)
                pos = trinity.TriVector(destination.x, destination.y,
                                        destination.z)
                if flattened:
                    pos.y = 0.0
                if rotationQuaternion is not None:
                    pos.TransformQuaternion(rotationQuaternion)
                pos.Scale(self.scale)
                transCurve.AddKey(index * 2 * self.timeBase, pos,
                                  trinity.TriVector(), trinity.TriVector(),
                                  trinity.TRIINT_LINEAR)
                transCurve.AddKey((index * 2 + 1) * self.timeBase, pos,
                                  trinity.TriVector(), trinity.TriVector(),
                                  trinity.TRIINT_LINEAR)

        now = blue.os.GetSimTime()
        self.model.translationCurve = transCurve
        self.model.translationCurve.start = now
        if blinking:
            self.model.curveSets[0].scale = 2.0
            self.model.curveSets[0].PlayFrom(float(now / SEC))
        self.destinations = destinations
예제 #6
0
    def DrawRoute(self, destinations, usePoints = False, drawLines = False, blinking = True, flattened = False, rotationQuaternion = None):
        """
        Create a blinking ball and attach a translation curve to animate it
        along autopilot path
        
        flattened:      If set, eliminates the y-coordinate. Best used in conjunction with rotationQuaternion.
        rotationQuaternion: If set, transforms each destination point by the given quaternion.
        """
        if not len(destinations):
            self.destinations = []
            if self.model:
                self.model.diplay = False
            return
        if self.model:
            self.model.display = True
        else:
            self.model = trinity.Load(self.resPath)
            self.model.name = '__mapRoute'
            self.model.scaling = (self.ballScale, self.ballScale, self.ballScale)
            if not blinking:
                self.model.curveSets.removeAt(0)
            if drawLines:
                self.lineSet = trinity.EveLineSet()
                self.lineSet.effect = trinity.Tr2Effect()
                self.lineSet.effect.effectFilePath = LINESET_EFFECT
        transCurve = trinity.TriVectorCurve()
        transCurve.extrapolation = trinity.TRIEXT_CYCLE
        if type(rotationQuaternion) != trinity.TriQuaternion and rotationQuaternion is not None:
            rotationQuaternion = trinity.TriQuaternion(*rotationQuaternion)
        emptyVector = (0.0, 0.0, 0.0)
        if usePoints:
            for index, point in enumerate(destinations):
                pos = trinity.TriVector(*point)
                if flattened:
                    pos.y = 0.0
                if rotationQuaternion is not None:
                    pos.TransformQuaternion(rotationQuaternion)
                pos.Scale(self.scale)
                pythonPos = (pos.x, pos.y, pos.z)
                transCurve.AddKey(index * self.timeBase, pythonPos, emptyVector, emptyVector, trinity.TRIINT_LINEAR)

            if drawLines:
                numPoints = len(destinations)
                for index in xrange(numPoints):
                    index2 = (index + 1) % numPoints
                    p1 = geo2.Vector(*destinations[index]) * self.scale
                    p2 = geo2.Vector(*destinations[index2]) * self.scale
                    self.lineSet.AddLine(p1, self.lineColor, p2, self.lineColor)

                self.lineSet.SubmitChanges()
        else:
            map = sm.StartService('map')
            for index, destinationID in enumerate(destinations):
                destination = cfg.evelocations.Get(destinationID)
                pos = trinity.TriVector(destination.x, destination.y, destination.z)
                if flattened:
                    pos.y = 0.0
                if rotationQuaternion is not None:
                    pos.TransformQuaternion(rotationQuaternion)
                pos.Scale(self.scale)
                pythonPos = (pos.x, pos.y, pos.z)
                transCurve.AddKey(index * 2 * self.timeBase, pythonPos, emptyVector, emptyVector, trinity.TRIINT_LINEAR)
                transCurve.AddKey((index * 2 + 1.0) * self.timeBase, pythonPos, emptyVector, emptyVector, trinity.TRIINT_LINEAR)

        now = blue.os.GetSimTime()
        self.model.translationCurve = transCurve
        self.model.translationCurve.start = now
        if blinking:
            self.model.curveSets[0].scale = 2.0
            self.model.curveSets[0].PlayFrom(float(now / const.SEC))
        self.destinations = destinations