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
Esempio 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
Esempio n. 3
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()