Exemplo n.º 1
0
 def Orbit(self, yaw, pitch):
     dev = trinity.device
     self.Focus(self.pointOfInterest)
     up = geo2.Vector(0.0, 1.0, 0.0)
     t = geo2.Vector(self.localViewMatrix[1][0], self.localViewMatrix[1][1], self.localViewMatrix[1][2])
     if geo2.Vec3Dot(t, up) <= 0.0:
         pitch = -pitch
         yaw = -yaw
     pos = self.GetPosition()
     target = self.pointOfInterest
     view = geo2.Subtract(pos, target)
     view = geo2.Vec3Normalize(view)
     right = geo2.Vec3Cross(view, up)
     mat = self.localViewMatrix
     ipmat = geo2.MatrixTranslation(-target[0], -target[1], -target[2])
     pmat = geo2.MatrixTranslation(target[0], target[1], target[2])
     mat = geo2.MatrixInverse(mat)
     yrotMat = geo2.MatrixRotationAxis(up, yaw)
     rrotMat = geo2.MatrixRotationAxis(right, pitch)
     yrotMat = geo2.MatrixMultiply(yrotMat, rrotMat)
     mat = geo2.MatrixMultiply(mat, ipmat)
     mat = geo2.MatrixMultiply(mat, yrotMat)
     mat = geo2.MatrixMultiply(mat, pmat)
     self._position = geo2.MatrixDecompose(mat)[2]
     mat = geo2.MatrixInverse(mat)
     self.localViewMatrix = mat
Exemplo n.º 2
0
 def AddExplosion(self, uniqueName, explosionGfxID, spreadOut):
     if uniqueName not in self.districts:
         self.logger.error('Could not find district %s for planet with id %s', str(uniqueName), str(self.itemID))
     graphics = GetGraphic(explosionGfxID)
     if graphics is None:
         self.logger.error("Explosion graphicsID %s doesn't exist!", str(explosionGfxID))
         return
     fx = trinity.Load(graphics.graphicFile)
     if fx is None:
         self.logger.error("Explosion %s doesn't exist!", str(graphics.graphicFile))
         return
     if len(fx.curveSets) == 0:
         self.logger.error('Explosion %s has no curveSets! This is useless...', str(graphics.graphicFile))
         return
     direction = self.districts[uniqueName].centerNormal
     rotMatrix1 = geo2.MatrixRotationAxis((direction[1], direction[2], direction[0]), random.random() * spreadOut * self.districts[uniqueName].pinRadius)
     rotMatrix2 = geo2.MatrixRotationAxis(direction, random.uniform(0, 2.0 * math.pi))
     direction = geo2.Vec3TransformNormal(direction, rotMatrix1)
     direction = geo2.Vec3TransformNormal(direction, rotMatrix2)
     fx.translation = direction
     fx.scaling = (5000.0 / PLANET_SIZE_SCALE, 5000.0 / PLANET_SIZE_SCALE, 5000.0 / PLANET_SIZE_SCALE)
     v1 = geo2.Vec3Cross(geo2.Vec3Normalize(direction), (0.0, 1.0, 0.0))
     alpha = -math.acos(geo2.Vec3Dot(geo2.Vec3Normalize(direction), (0.0, 1.0, 0.0)))
     fx.rotation = geo2.QuaternionRotationAxis(v1, alpha)
     duration = fx.curveSets[0].GetMaxCurveDuration()
     self.districtExplosions.children.append(fx)
     uthread.new(self._RemoveExplosionFromDistrict, fx, duration)
Exemplo n.º 3
0
    def OrbitUpdateThread(self):
        try:
            while True:
                if self.orbitTarget is None:
                    break
                vLookAt = self.GetLookAtDirection()
                currPitch = self.GetAngleLookAtToUpDirection()
                self.eyePosition = geo2.Subtract(self.eyePosition, self.atPosition)
                yawLeft = self.orbitTarget[0]
                if yawLeft:
                    yaw = self.kOrbitSpeed * yawLeft / blue.os.fps
                    if math.fabs(yawLeft) < self.kOrbitStopAngle:
                        yaw = yawLeft
                    rotYaw = geo2.MatrixRotationAxis(self.upDirection, yaw)
                    self.eyePosition = geo2.Vec3Transform(self.eyePosition, rotYaw)
                    self.orbitTarget[0] -= yaw
                targetPitch = self.orbitTarget[1]
                pitchLeft = currPitch - targetPitch
                if pitchLeft:
                    pitch = self.kOrbitSpeed * pitchLeft / blue.os.fps
                    if math.fabs(pitchLeft) < self.kOrbitStopAngle:
                        pitch = pitchLeft
                    axis = geo2.Vec3Cross(vLookAt, self.upDirection)
                    rotPitch = geo2.MatrixRotationAxis(axis, pitch)
                    self.eyePosition = geo2.Vec3Transform(self.eyePosition, rotPitch)
                self.eyePosition = geo2.Add(self.eyePosition, self.atPosition)
                if not pitchLeft and not yawLeft:
                    break
                blue.synchro.Yield()

        finally:
            self.orbitUpdateThread = None
            self.orbitTarget = None
Exemplo n.º 4
0
 def Rotate(self, x = 0, y = 0):
     xAxis = self.GetXAxis()
     yAxis = self.GetYAxis()
     self.atPosition = geo2.Subtract(self.atPosition, self.eyePosition)
     rotY = geo2.MatrixRotationAxis(xAxis, y)
     self.atPosition = geo2.Vec3Transform(self.atPosition, rotY)
     rotX = geo2.MatrixRotationAxis(yAxis, x)
     self.atPosition = geo2.Vec3Transform(self.atPosition, rotX)
     self.atPosition = geo2.Add(self.atPosition, self.eyePosition)
Exemplo n.º 5
0
 def _RenderCallback(self):
     if self.oldCameraPos is None or self.oldCameraPos != self.camera.pos:
         self.oldCameraPos = self.camera.pos
         rightMat = geo2.MatrixRotationAxis(self.camera.rightVec,
                                            math.radians(-225))
         upMat = geo2.MatrixRotationAxis(self.camera.upVec,
                                         math.radians(-45))
         self.scene.sunDirection = geo2.Vec3Normalize(
             geo2.Vec3TransformNormal(
                 geo2.Vec3TransformNormal(self.camera.viewVec, rightMat),
                 upMat))
Exemplo n.º 6
0
 def _UpdateRotateOffset(self):
     if self._rotateOffset != (0.0, 0.0):
         yaw, pitch = self._rotateOffset
         rotMat = geo2.MatrixRotationAxis(self.upDirection, -yaw)
         eyeAtVec = geo2.Vec3Subtract(self._atPosition, self._eyePosition)
         vec = geo2.Vec3Transform(eyeAtVec, rotMat)
         axis = geo2.Vec3Normalize(geo2.Vec3Cross(vec, self.upDirection))
         rotMat = geo2.MatrixRotationAxis(axis, -pitch)
         vec = geo2.Vec3Transform(vec, rotMat)
         offset = geo2.Vec3Subtract(vec, eyeAtVec)
         self._AddToAtOffset(offset)
Exemplo n.º 7
0
 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)
Exemplo n.º 8
0
 def SetPitch(self, pitch):
     pitch = self.ClampPitch(pitch)
     axis = geo2.Vec3Cross(self.upDirection, self.GetLookAtDirection())
     rotMat = geo2.MatrixRotationAxis(axis, pitch)
     vec = (0, self.GetZoomDistance(), 0)
     self._eyePosition = geo2.Vec3Add(self._atPosition,
                                      geo2.Vec3Transform(vec, rotMat))
Exemplo n.º 9
0
 def Update(self):
     speedFactor = 0.2
     diff = geo2.Vec3Subtract(self.pointOfInterest, self._pointOfInterestCurrent)
     diffLength = geo2.Vec3Length(diff)
     if diffLength > 0.001:
         self._pointOfInterestCurrent = geo2.Vec3Add(self._pointOfInterestCurrent, geo2.Vec3Scale(diff, speedFactor))
     else:
         self._pointOfInterestCurrent = self.pointOfInterest
     if abs(self._yawSpeed) > 0.0001:
         yawChange = self._yawSpeed * speedFactor
         rotYaw = geo2.MatrixRotationAxis(self.upVector, yawChange)
         self._eyePositionCurrent = geo2.Vec3Transform(self._eyePositionCurrent, rotYaw)
         self._yawSpeed -= yawChange
     else:
         self._yawSpeed = 0.0
     if abs(self._pitchSpeed) > 0.0001:
         pitchChange = self._pitchSpeed * speedFactor
         viewVectorNormalized = geo2.Vec3Normalize(self._eyePositionCurrent)
         axis = geo2.Vec3Cross(viewVectorNormalized, self.upVector)
         rotPitch = geo2.MatrixRotationAxis(axis, pitchChange)
         self._eyePositionCurrent = geo2.Vec3Transform(self._eyePositionCurrent, rotPitch)
         self._pitchSpeed -= pitchChange
     else:
         self._pitchSpeed = 0.0
     if self._panSpeed:
         panDistance = geo2.Vec3Length(self._panSpeed)
         if panDistance > 0.001:
             toMove = geo2.Vec3Scale(self._panSpeed, 0.95)
             self.pointOfInterest = geo2.Add(self.pointOfInterest, toMove)
             self._panSpeed -= toMove
         else:
             self._panSpeed = None
     cameraDistance = self.GetZoomDistance()
     cameraDistanceDiff = self._translationFromPOI - cameraDistance
     if math.fabs(cameraDistanceDiff) > 0.001:
         usedDist = cameraDistanceDiff * 0.1
         viewVectorNormalized = geo2.Vec3Normalize(self._eyePositionCurrent)
         newDistance = min(self.maxDistance, max(self.minDistance, cameraDistance + usedDist))
         self._eyePositionCurrent = geo2.Vec3Scale(viewVectorNormalized, newDistance)
         self.translationFromParent = newDistance
     self.UpdateProjection()
     self.UpdateView()
     if self.callback:
         self.callback()
Exemplo n.º 10
0
 def _UpdateYaw(self):
     yawRemaining = self.orbitTarget[0]
     if yawRemaining:
         if math.fabs(yawRemaining) < self.kOrbitStopAngle:
             yaw = yawRemaining
             yawRemaining = None
         else:
             yaw = yawRemaining * self._GetOrbitSpeed()
         rotYaw = geo2.MatrixRotationAxis(self.upDirection, yaw)
         self.SetEyePosition(geo2.Vec3Transform(self._eyePosition, rotYaw))
         self.orbitTarget[0] -= yaw
     return yawRemaining
Exemplo n.º 11
0
 def _EnforceMaximumDinstance(self, headSurfacePoint, uiPin):
     SAFETYFACTOR = 0.99
     ecuSurfacePoint = uiPin.surfacePoint
     distance = headSurfacePoint.GetDistanceToOther(ecuSurfacePoint)
     areaOfInfluence = uiPin.pin.GetAreaOfInfluence()
     if distance < areaOfInfluence * SAFETYFACTOR:
         return distance / areaOfInfluence
     ecuVector = ecuSurfacePoint.GetAsXYZTuple()
     v = headSurfacePoint.GetAsXYZTuple()
     normal = geo2.Vec3Cross(ecuVector, v)
     rotMat = geo2.MatrixRotationAxis(normal, areaOfInfluence * SAFETYFACTOR)
     newV = geo2.Multiply(rotMat, ecuVector)
     headSurfacePoint.SetXYZ(*newV[:3])
     return 1.0
Exemplo n.º 12
0
 def _UpdatePitch(self, currPitch, vLookAt):
     targetPitch = self.orbitTarget[1]
     pitchRemaining = currPitch - targetPitch
     if pitchRemaining:
         if math.fabs(pitchRemaining) < self.kOrbitStopAngle:
             pitch = pitchRemaining
             pitchRemaining = None
         else:
             pitch = pitchRemaining * self._GetOrbitSpeed()
         axis = geo2.Vec3Cross(vLookAt, self.upDirection)
         rotPitch = geo2.MatrixRotationAxis(axis, pitch)
         self.SetEyePosition(geo2.Vec3Transform(self._eyePosition,
                                                rotPitch))
     return pitchRemaining
Exemplo n.º 13
0
 def PlaceProbeAtDefaultPosition(self, headID):
     OFFSET = 0.08
     VEC_X = (-1, 0, 0)
     rotAngle = float(headID) / planetCommon.ECU_MAX_HEADS * 2 * math.pi
     ecuVector = self.planetUISvc.myPinManager.pinsByID[
         self.pin.id].surfacePoint.GetAsXYZTuple()
     normal = geo2.Vec3Cross(ecuVector, VEC_X)
     normal = geo2.Vector(*normal) * OFFSET
     posVec = geo2.Vec3Subtract(ecuVector, normal)
     posVec = geo2.Vec3Normalize(posVec)
     rotMat = geo2.MatrixRotationAxis(ecuVector, rotAngle)
     posVec = geo2.Multiply(rotMat, posVec)
     surfacePoint = SurfacePoint(*posVec)
     self.planetUISvc.myPinManager.PlaceExtractionHead(
         self.pin.id, headID, surfacePoint, self.currentRadius)
     self.UpdateHeadPosition(headID, surfacePoint)
Exemplo n.º 14
0
 def _EnforceMaximumDinstance(self, headSurfacePoint, uiPin):
     """
     If the distance between the points is greater than the maximum, we snap 
     headSurfacePoint to the max distance circle and return 1.0. Otherwise, we return
     the current distance factor [0.0-1.0]
     """
     SAFETYFACTOR = 0.99
     ecuSurfacePoint = uiPin.surfacePoint
     distance = headSurfacePoint.GetDistanceToOther(ecuSurfacePoint)
     areaOfInfluence = uiPin.pin.GetAreaOfInfluence()
     if distance < areaOfInfluence * SAFETYFACTOR:
         return distance / areaOfInfluence
     ecuVector = ecuSurfacePoint.GetAsXYZTuple()
     v = headSurfacePoint.GetAsXYZTuple()
     normal = geo2.Vec3Cross(ecuVector, v)
     rotMat = geo2.MatrixRotationAxis(normal,
                                      areaOfInfluence * SAFETYFACTOR)
     newV = geo2.Multiply(rotMat, ecuVector)
     headSurfacePoint.SetXYZ(*newV[:3])
     return 1.0
Exemplo n.º 15
0
 def Update(self):
     pointOfInterestOverrideValue = self.GetPointOfInterestOverrideValue()
     if pointOfInterestOverrideValue is not None:
         self._pointOfInterest = pointOfInterestOverrideValue
     elif self.followMarker:
         followMarker = self.followMarker()
         if followMarker:
             markerPosition = followMarker.GetDisplayPosition()
             if markerPosition is not None:
                 self._pointOfInterest = markerPosition
     speedFactor = 0.4
     diff = geo2.Vec3Subtract(self._pointOfInterest,
                              self._pointOfInterestCurrent)
     diffLength = geo2.Vec3Length(diff)
     if diffLength > 0.001:
         addVector = geo2.Vec3ScaleD(diff, speedFactor)
         newPosition = geo2.Vec3Add(self._pointOfInterestCurrent, addVector)
         if geo2.Vec3Equal(newPosition, self._pointOfInterestCurrent):
             newPosition = self._pointOfInterest
         self._pointOfInterestCurrent = newPosition
     else:
         self._pointOfInterestCurrent = self._pointOfInterest
     if abs(self._yawSpeed) > 0.0001:
         yawChange = self._yawSpeed * speedFactor
         rotYaw = geo2.MatrixRotationAxis(self.upVector, yawChange)
         self._eyePositionCurrent = geo2.Vec3Transform(
             self._eyePositionCurrent, rotYaw)
         currentPositionN = geo2.Vec3Normalize(self._eyePositionCurrent)
         self._eyePosition = geo2.Vec3Scale(
             currentPositionN, geo2.Vec3Length(self._eyePosition))
         self._yawSpeed -= yawChange
     else:
         self._yawSpeed = 0.0
     if abs(self._pitchSpeed) > 0.0001:
         pitchChange = self._pitchSpeed * speedFactor
         viewVectorNormalized = geo2.Vec3Normalize(self._eyePositionCurrent)
         axis = geo2.Vec3Cross(viewVectorNormalized, self.upVector)
         rotPitch = geo2.MatrixRotationAxis(axis, pitchChange)
         self._eyePositionCurrent = geo2.Vec3Transform(
             self._eyePositionCurrent, rotPitch)
         currentPositionN = geo2.Vec3NormalizeD(self._eyePositionCurrent)
         self._eyePosition = geo2.Vec3ScaleD(
             currentPositionN, geo2.Vec3Length(self._eyePosition))
         self._pitchSpeed -= pitchChange
     else:
         self._pitchSpeed = 0.0
     setCameraDistance = geo2.Vec3Length(self._eyePosition)
     currentCameraDistance = geo2.Vec3Length(self._eyePositionCurrent)
     cameraDistanceDiff = setCameraDistance - currentCameraDistance
     if math.fabs(cameraDistanceDiff) > 0.001:
         usedDist = cameraDistanceDiff * speedFactor * 0.5
         viewVectorNormalized = geo2.Vec3NormalizeD(
             self._eyePositionCurrent)
         newDistance = min(
             self.maxDistance,
             max(self.minDistance, currentCameraDistance + usedDist))
         self._eyePositionCurrent = geo2.Vec3ScaleD(viewVectorNormalized,
                                                    newDistance)
     self.UpdateProjection()
     self.UpdateView()
     if self.callback:
         self.callback()
Exemplo n.º 16
0
 def _GetTrackEyeOffsetDirection(self):
     pitch = math.pi - self.GetPitch()
     rotMat = geo2.MatrixRotationAxis(self.GetZAxis(), -pitch)
     return geo2.Vec3Transform(self.GetYAxis(), rotMat)