Exemplo n.º 1
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
Exemplo n.º 2
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
Exemplo n.º 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