Ejemplo n.º 1
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
Ejemplo n.º 2
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
Ejemplo n.º 3
0
    def GetWarpCollisions(self, ball):
        space = sm.GetService('space')
        planets = space.planetManager.planets
        destination = self.destination
        source = (ball.x, ball.y, ball.z)
        self.direction = geo2.Vec3SubtractD(destination, source)
        direction = self.direction
        warpDistance = geo2.Vec3LengthD(direction)
        normDirection = geo2.Vec3NormalizeD(direction)
        self.normDirection = normDirection
        ballpark = sm.GetService('michelle').GetBallpark()
        collisions = []
        for planet in planets:
            planetBall = ballpark.GetBall(planet.id)
            if planetBall is None:
                log.LogWarn('Warping got a None planet ball.')
                continue
            planetRadius = planetBall.radius
            planetPosition = (planetBall.x, planetBall.y, planetBall.z)
            planetDir = geo2.Vec3SubtractD(planetPosition, source)
            if geo2.Vec3LengthSqD(
                    self.direction) < geo2.Vec3LengthSqD(planetDir):
                continue
            effectiveRadius = self.CalcEffectiveRadius(normDirection,
                                                       planetDir, planetRadius)
            if effectiveRadius is None:
                continue
            collisions.append((planetBall, effectiveRadius))
            blue.pyos.BeNice()

        return collisions
Ejemplo n.º 4
0
 def GetRayAndPointFromUI(self,
                          x,
                          y,
                          projection2view=None,
                          view2world=None):
     viewport = self.viewport
     mx = x - viewport.x
     my = y - viewport.y
     w = viewport.width
     h = viewport.height
     fx = float(mx * 2) / w - 1.0
     fy = float(my * 2) / h - 1.0
     fy *= -1
     projection2view = projection2view or geo2.MatrixInverse(
         self.projectionMatrix.transform)
     view2world = view2world or geo2.MatrixInverse(
         self.viewMatrix.transform)
     rayStart = (fx, fy, 0.0)
     rayStart = geo2.Vec3TransformCoord(rayStart, projection2view)
     rayStart = geo2.Vec3TransformCoord(rayStart, view2world)
     rayEnd = (fx, fy, 1.0)
     rayEnd = geo2.Vec3TransformCoord(rayEnd, projection2view)
     rayEnd = geo2.Vec3TransformCoord(rayEnd, view2world)
     rayDir = geo2.Vec3SubtractD(rayEnd, rayStart)
     return (geo2.Vec3NormalizeD(rayDir), rayStart)
Ejemplo n.º 5
0
 def ZoomToDistance(self, endCameraDistance, immediate=True):
     endCameraDistance = min(self.maxDistance,
                             max(self.minDistance, endCameraDistance))
     eyePositionNorm = geo2.Vec3NormalizeD(self._eyePosition)
     self._eyePosition = geo2.Vec3ScaleD(eyePositionNorm, endCameraDistance)
     if immediate:
         self._eyePositionCurrent = self._eyePosition
Ejemplo n.º 6
0
 def Update(self, center, range, closestPoints, width):
     self.AddLinesToScene()
     self.ClearLines()
     d0 = geo2.Vec3SubtractD(center, closestPoints[0])
     d1 = geo2.Vec3SubtractD(center, closestPoints[1])
     up = geo2.Vec3NormalizeD(geo2.Vec3CrossD(d1, d0))
     dir = geo2.Vec3NormalizeD(d0)
     pFar = geo2.Vec3AddD(center, geo2.Vec3ScaleD(dir, range))
     pNear = geo2.Vec3AddD(center, geo2.Vec3ScaleD(dir, -range))
     perp = geo2.Vec3NormalizeD(geo2.Vec3CrossD(dir, up))
     pRight = geo2.Vec3AddD(center, geo2.Vec3ScaleD(perp, range))
     pLeft = geo2.Vec3AddD(center, geo2.Vec3ScaleD(perp, -range))
     width *= LINE_WIDTH
     self.lineSet.AddSpheredLineCrt(pFar, DEFAULT_COLOR, pRight, DEFAULT_COLOR, center, width)
     self.lineSet.AddSpheredLineCrt(pRight, DEFAULT_COLOR, pNear, DEFAULT_COLOR, center, width)
     self.lineSet.AddSpheredLineCrt(pNear, DEFAULT_COLOR, pLeft, DEFAULT_COLOR, center, width)
     self.lineSet.AddSpheredLineCrt(pLeft, DEFAULT_COLOR, pFar, DEFAULT_COLOR, center, width)
     self.lineSet.SubmitChanges()
Ejemplo n.º 7
0
 def AddGfxResult(self, siteData, myPos):
     if self.suppressGfxReasons:
         return
     if not self.sensorSuiteService.siteController.IsSiteVisible(siteData):
         return
     if siteData.signalStrength >= 1.0:
         return
     if siteData.targetID in self.gfxActiveSensorResults:
         return
     direction = geo2.Vec3SubtractD(siteData.position, myPos)
     distToSite = geo2.Vec3LengthD(direction)
     deviation = siteData.deviation * 0.5
     a = min(distToSite, deviation)
     b = max(distToSite, deviation)
     tanA = a / b
     angle = math.atan(tanA)
     normalizedDir = geo2.Vec3NormalizeD(direction)
     self.AddGfxResultToScene(siteData.targetID, normalizedDir, angle)
Ejemplo n.º 8
0
    def __UpdateCompass(self):
        bp = self.michelle.GetBallpark()
        if bp is None:
            return
        camera = self.GetCamera()
        camRotation = geo2.QuaternionRotationGetYawPitchRoll(
            camera.rotationAroundParent)
        yaw, pitch, roll = camRotation
        cx, cy, cz = geo2.QuaternionTransformVector(
            camera.rotationAroundParent, (0, 0, -1.0))
        camLengthInPlane = geo2.Vec2Length((cx, cz))
        camAngle = math.atan2(cy, camLengthInPlane)
        self.compassTransform.rotation = -yaw + math.pi
        myPos = bp.GetCurrentEgoPos()
        if self.lastPose:
            lastCamRot, lastPos = self.lastPose
            isNewCamRotation = not AreVectorsEqual(lastCamRot, camRotation,
                                                   0.05)
            isNewPosition = not AreVectorsEqual(lastPos, myPos, 0.5)
            isNewPose = isNewPosition or isNewCamRotation
        else:
            isNewPosition = True
            isNewPose = True
        for siteID, indicator in self.siteIndicatorsBySiteID.iteritems():
            if indicator.isNew or isNewPose:
                toSiteVec = geo2.Vec3SubtractD(indicator.data.position, myPos)
                toSiteVec = geo2.Vec3NormalizeD(toSiteVec)
                if indicator.isNew or isNewPosition:
                    angle = math.atan2(-toSiteVec[2], toSiteVec[0])
                    indicator.SetRotation(angle + MATH_PI_2)
                sx, sy, sz = toSiteVec
                siteLengthInPlane = geo2.Vec2Length((sx, sz))
                siteAngle = math.atan2(sy, siteLengthInPlane)
                inclinationAngle = siteAngle - camAngle
                verticalAngle = min(inclinationAngle, MATH_PI_2)
                indicator.SetInclination(verticalAngle)
                indicator.isNew = False

        self.lastPose = (camRotation, myPos)
Ejemplo n.º 9
0
 def GetViewVector(self):
     t = geo2.MatrixInverse(self.viewMatrix.transform)
     ret = geo2.Vec3NormalizeD((t[2][0], t[2][1], t[2][2]))
     return ret
Ejemplo n.º 10
0
 def GetZAxis(self):
     t = self.viewMatrix.transform
     return geo2.Vec3NormalizeD((t[0][2], t[1][2], t[2][2]))
Ejemplo n.º 11
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()