def GetLookAtDirectionWithOffset(self): eyePos = geo2.Vec3AddD( self._eyePosition, self._eyeOffset) if self._eyeOffset else self._eyePosition atPos = geo2.Vec3AddD( self._atPosition, self._atOffset) if self._atOffset else self._atPosition return geo2.Vec3Direction(eyePos, atPos)
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
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
def IsValidLocation(self): ship = self.ballpark.GetBall(session.shipid) position = geo2.Vec3AddD((ship.x, ship.y, ship.z), self.GetPosition()) balls = [(item.typeID, (ball.x, ball.y, ball.z), ball.radius) for ball, item in self.ballpark.GetBallsAndItems()] balls += [(item.typeID, xyz, 0) for ball, item, xyz in self.ballpark.GetWarpinPoints()] return structures.IsValidLocation(self.typeID, position, balls)
def SetAbstractBall(self, animate=True, duration=0.6): bp = self._GetBallpark() if not bp: return pos = bp.GetCurrentEgoPos() if self.ball: pos = geo2.Vec3AddD(pos, GetBallPosition(self.ball)) ball = bp.AddClientSideBall(pos) self._SetBall(ball, animate, 0.0)
def _AddToAtOffset(self, offset): if IsInfVector3(offset) or IsNanVector3(offset): raise DestinyBallInvalid( 'Camera: Attempting to assign an invalid atOffset value: %s, %s' % (repr(offset), self)) if not self._atOffset: self._atOffset = offset else: self._atOffset = geo2.Vec3AddD(self._atOffset, offset)
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()
def IterViablePositions(shipID, typeID, radius, spaceComponentStaticData, ballpark): componentAttributes = spaceComponentStaticData.GetAttributes( typeID, DEPLOY_CLASS) minDistanceFromAPlanet = getattr(componentAttributes, 'minPlanetDistance', 0) shipPosition = ballpark.GetBallPosition(shipID) if not minDistanceFromAPlanet: deployAtRange = getattr(spaceComponentStaticData, 'deployAtRange', 0) + radius + ballpark.GetBallRadius(shipID) yield OffsetPositionInRandomDirection(shipPosition, deployAtRange) else: offsets = [0, -1 * GRIDSIZE_LEGACY, 1 * GRIDSIZE_LEGACY] shipPosition = AlignToLegacyGrid(shipPosition) for offset in itertools.product(offsets, repeat=3): yield geo2.Vec3AddD(shipPosition, offset)
def GetEyePosition(self): ret = self.camera._eyePosition if self.GetItemID() != session.shipid: ret = geo2.Vec3AddD(ret, self.atPositionDiff) return ret
def SetAtPosToFixedDistance(self): self.SetAtPosition( geo2.Vec3AddD( self._eyePosition, geo2.Vec3Scale(self.GetLookAtDirectionWithOffset(), -100.0)))
def OffsetEyePosition(self, eyePosition): if self._eyeOffset: eyePosition = geo2.Vec3AddD(eyePosition, self._eyeOffset) if self._eyeAndAtOffset: eyePosition = geo2.Vec3AddD(eyePosition, self._eyeAndAtOffset) return eyePosition
def OffsetAtPosition(self, atPosition): if self._atOffset: atPosition = geo2.Vec3AddD(atPosition, self._atOffset) if self._eyeAndAtOffset: atPosition = geo2.Vec3AddD(atPosition, self._eyeAndAtOffset) return atPosition
def GetZoomToPoint(self): offset = BaseSpaceCamera.GetZoomToPoint(self) speedOffset = self.GetSpeedOffset() if speedOffset: offset = geo2.Vec3AddD(offset, speedOffset) return offset